/* ============ FONT ============ */
/* Comic Neue (assets/fonts, SIL Open Font License): a free Comic Sans look-alike, so phones get the same look */
@font-face { font-family: 'Comic Neue'; font-weight: 400; font-style: normal; font-display: swap; src: url(assets/fonts/ComicNeue-Regular.ttf) format('truetype'); }
@font-face { font-family: 'Comic Neue'; font-weight: 700; font-style: normal; font-display: swap; src: url(assets/fonts/ComicNeue-Bold.ttf) format('truetype'); }
@font-face { font-family: 'Comic Neue'; font-weight: 400; font-style: italic; font-display: swap; src: url(assets/fonts/ComicNeue-Italic.ttf) format('truetype'); }

/* ============ RESET & BASE ============ */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --paper: #f5f0e8;
  --ink: #2c2c2c;
  --ink-light: #555;
  --ink-red: #d14a5a;
  --ink-blue: #4a7fd1;
  --ink-green: #5ab874;
  --shadow: rgba(44, 44, 44, 0.15);
  /* Comic Sans where it's installed (Windows, macOS); everywhere else (phones) the bundled look-alike, Comic Neue */
  --font: 'Comic Sans MS', 'Comic Neue', sans-serif;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--paper);
  font-family: var(--font);
  color: var(--ink);
  user-select: none;
  -webkit-user-select: none;
  cursor: crosshair;
}

/* In play the game draws its own, bigger crosshair (Game.drawCrosshair) */
body.playing canvas#game { cursor: none; }

canvas#game {
  display: block;
  width: 100vw;
  height: 100vh;
  image-rendering: high-contrast;
}

/* ============ UI OVERLAY ============ */
#ui {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  pointer-events: none;
  padding: 20px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
  z-index: 10;
}

#ui > div {
  background: rgba(245, 240, 232, 0.85);
  border: 2px solid var(--ink);
  border-radius: 12px;
  padding: 8px 16px;
  font-size: 18px;
  box-shadow: 3px 3px 0 var(--shadow);
  backdrop-filter: blur(4px);
}

#health-bar {
  width: 250px;
  height: 30px;
  background: rgba(245, 240, 232, 0.9);
  border: 2px solid var(--ink);
  border-radius: 15px;
  padding: 3px;
  box-shadow: 3px 3px 0 var(--shadow);
  backdrop-filter: blur(4px);
}

#health-bar { position: relative; }

#shield-value {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 13px;
  font-weight: bold;
  color: var(--ink);
  text-shadow: 0 0 3px #f5f0e8, 0 0 3px #f5f0e8;
}

#shield-fill {
  position: absolute;
  left: 3px;
  top: 3px;
  width: 0;
  height: 9px;
  background: var(--ink-blue);
  opacity: 0.9;
  border-radius: 5px;
  border: 1px solid var(--ink);
  transition: width 0.15s ease;
}

#health-fill {
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, var(--ink-green), var(--ink-blue));
  border-radius: 12px;
  transition: width 0.3s ease;
}

#score {
  font-weight: bold;
  font-size: 22px;
}

#wave-info, #enemy-count {
  font-size: 16px;
  opacity: 0.8;
}

/* ============ DOODLE BUTTON ============ */
.doodle-btn {
  display: inline-block;
  padding: 14px 40px;
  font-family: var(--font);
  font-size: 20px;
  font-weight: bold;
  color: var(--paper);
  background: var(--ink);
  border: 3px solid var(--ink);
  border-radius: 255px 15px 225px 15px / 15px 225px 15px 255px;
  cursor: pointer;
  box-shadow: 4px 4px 0 rgba(0,0,0,0.2);
  transition: transform 0.1s, box-shadow 0.1s;
  outline: none;
}

.doodle-btn:hover {
  transform: translate(-1px, -1px);
  box-shadow: 5px 5px 0 rgba(0,0,0,0.25);
  background: var(--ink-blue);
}

.doodle-btn:active {
  transform: translate(2px, 2px);
  box-shadow: 1px 1px 0 rgba(0,0,0,0.2);
}

/* ============ SCREENS ============ */
#start-screen {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 20px;
  z-index: 20;
}

#start-screen .doodle-btn { width: 260px; } /* all the menu buttons the same width */

#start-screen h1 {
  font-size: 64px;
  font-family: var(--font);
  text-shadow: 3px 3px 0 var(--shadow);
}

#start-screen p {
  font-size: 22px;
  opacity: 0.7;
  text-align: center;
  line-height: 1.6;
}

#game-over {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 16px;
  background: rgba(245, 240, 232, 0.9);
  z-index: 20;
}

#game-over h2 {
  font-size: 48px;
  font-family: var(--font);
}

#final-score {
  font-size: 28px;
}

/* ============ GAME OVER OVERLAY ============ */
#game-over::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: var(--paper);
  z-index: -1;
}

/* ============ HIDE ON START ============ */
body.playing #start-screen,
body.playing #game-over {
  display: none;
}

body:not(.playing) #game-over {
  display: none;
}


/* ============ XP BAR, GOLD, INVENTORY ============ */
#ui { flex-wrap: wrap; }

#gold {
  font-weight: bold;
  font-size: 20px;
}

#xp-wrap {
  position: fixed;
  left: 0;
  bottom: 0;
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 20px 12px;
  pointer-events: none;
  z-index: 10;
}

#level-label {
  font-weight: bold;
  font-size: 18px;
  min-width: 56px;
}

#xp-bar {
  flex: 1;
  height: 14px;
  background: rgba(245, 240, 232, 0.9);
  border: 2px solid var(--ink);
  border-radius: 8px;
  padding: 2px;
}

#xp-fill {
  width: 0%;
  height: 100%;
  background: var(--ink-green);
  border-radius: 5px;
  transition: width 0.15s ease;
}

#powerup-list {
  position: fixed;
  left: 20px;
  bottom: 48px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-width: 60vw;
  z-index: 10;
}

.inv {
  position: relative;
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  background: rgba(245, 240, 232, 0.9);
  border: 2px solid var(--ink);
  border-radius: 10px;
  cursor: pointer;
}

.inv:hover { transform: translateY(-2px); background: var(--paper); }

.inv b {
  position: absolute;
  right: -4px;
  bottom: -6px;
  font-size: 12px;
  background: var(--ink);
  color: var(--paper);
  border-radius: 8px;
  padding: 0 5px;
}

/* ============ LEVEL-UP / SHOP OVERLAYS ============ */
.overlay {
  position: fixed;
  inset: 0;
  display: none;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 18px;
  background: rgba(245, 240, 232, 0.94);
  z-index: 30;
  cursor: default;
  padding: 20px;
}

.overlay h2 {
  font-size: 40px;
  text-shadow: 3px 3px 0 var(--shadow);
}

.overlay .hint, .overlay .gold-line {
  font-size: 18px;
  opacity: 0.7;
}

.overlay .gold-line { opacity: 1; font-weight: bold; font-size: 24px; }

.cards {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 18px;
}

.card {
  --rarity: var(--ink);
  width: 210px;
  min-height: 250px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 16px 14px;
  text-align: center;
  font-family: var(--font);
  color: var(--ink);
  background: var(--paper);
  border: 3px solid var(--rarity);
  border-radius: 255px 15px 225px 15px / 15px 225px 15px 255px;
  box-shadow: 4px 4px 0 var(--shadow);
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.1s;
}

.card:hover:not(:disabled):not(.static) {
  transform: translate(-2px, -3px) rotate(-0.6deg);
  box-shadow: 6px 7px 0 var(--shadow);
}

.card:disabled { opacity: 0.45; cursor: not-allowed; }

.card .key { font-size: 13px; opacity: 0.5; }
.card .icon { font-size: 44px; line-height: 1.1; display: flex; justify-content: center; }
.pu-icon { display: block; flex-shrink: 0; }
.chip .pu-icon { display: inline-block; vertical-align: -3px; }
.card .name { font-size: 20px; font-weight: bold; }
.card .rarity { font-size: 12px; text-transform: uppercase; letter-spacing: 1px; color: var(--rarity); font-weight: bold; }
.card .desc { font-size: 15px; line-height: 1.35; flex: 1; }
.card .tags { font-size: 12px; opacity: 0.6; }
.card .owned { font-size: 13px; color: var(--ink-blue); }
.card .price { font-size: 18px; font-weight: bold; }


/* ============ POWERUP INFO WINDOW ============ */
#info-body {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: flex-start;
  gap: 28px;
  max-width: 900px;
}

.card.static { cursor: default; width: 250px; }

.info-panel {
  min-width: 240px;
  max-width: 320px;
  font-size: 16px;
  line-height: 1.5;
  text-align: left;
}

.info-panel h3 { font-size: 20px; margin-bottom: 4px; }
.info-panel section { margin-bottom: 14px; }
.info-panel .muted { opacity: 0.6; font-size: 14px; }
.info-panel .row { display: flex; justify-content: space-between; gap: 12px; }
.info-panel .row b { color: var(--ink-blue); }


/* ============ HIDE THE HUD IN MENUS ============ */
body:not(.playing) #ui,
body:not(.playing) #powerup-list,
body:not(.playing) #xp-wrap {
  display: none;
}

/* ============ POWERUP CODEX ============ */
.overlay.codex {
  justify-content: flex-start;
  gap: 12px;
  padding: 22px 24px 18px;
  z-index: 40;
  background: var(--paper); /* opaque so the menu doesn't ghost through */
}

.codex-controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 12px;
}

.codex-controls input,
.codex-controls select {
  font-family: var(--font);
  font-size: 16px;
  color: var(--ink);
  padding: 7px 14px;
  background: var(--paper);
  border: 2px solid var(--ink);
  border-radius: 12px;
  outline: none;
}

.codex-controls input { width: 280px; }
.codex-controls input:focus,
.codex-controls select:focus { border-color: var(--ink-blue); }

.chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  max-width: 1100px;
}

.chip {
  font-family: var(--font);
  font-size: 13px;
  color: var(--ink);
  padding: 3px 10px;
  background: var(--paper);
  border: 2px solid var(--ink-light);
  border-radius: 14px;
  cursor: pointer;
}

.chip:hover { border-color: var(--ink); }
.chip.active { background: var(--ink); color: var(--paper); border-color: var(--ink); }

#codex-grid {
  flex: 1;
  min-height: 0;
  width: 100%;
  max-width: 1300px;
  overflow-y: auto;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-content: flex-start;
  gap: 16px;
  padding: 10px 8px 14px;
}

#codex-grid .empty { font-size: 20px; opacity: 0.6; padding-top: 40px; }

.card.codex-card { min-height: 0; }
.card .effects { font-size: 13px; color: var(--ink-blue); line-height: 1.3; }
.card .requires { font-size: 12px; opacity: 0.75; line-height: 1.3; }


/* ============ CODEX TABS AND SYNERGY MAP ============ */
.codex-tabs { display: flex; gap: 8px; }
.chip.tab { font-size: 16px; padding: 5px 18px; }

#codex-cards-view, #codex-map-view {
  flex: 1;
  min-height: 0;
  width: 100%;
  max-width: 1500px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

#codex-map-view { display: none; }

.map-body {
  flex: 1;
  min-height: 0;
  width: 100%;
  display: flex;
  gap: 14px;
}

#map-scroll {
  flex: 1;
  min-width: 0;
  overflow: auto;
  border: 2px solid var(--ink);
  border-radius: 14px;
  background: #faf6ee;
}

#map-panel {
  width: 310px;
  flex-shrink: 0;
  overflow-y: auto;
  padding: 14px 16px;
  border: 2px solid var(--ink);
  border-radius: 14px;
  background: var(--paper);
  text-align: left;
  font-size: 15px;
  line-height: 1.45;
}

#map-panel h3 { font-size: 22px; }
#map-panel h4 { margin: 14px 0 4px; font-size: 16px; border-bottom: 2px solid var(--shadow); }
#map-panel .muted { opacity: 0.65; font-size: 14px; margin: 4px 0; }
#map-panel .panel-head { display: flex; gap: 12px; align-items: center; margin-bottom: 6px; }
#map-panel .panel-icon { font-size: 40px; }
#map-panel .panel-rarity { font-size: 12px; font-weight: bold; text-transform: uppercase; letter-spacing: 1px; }
#map-panel .req { margin: 6px 0; }
#map-panel .req-title { font-size: 14px; font-weight: bold; margin-top: 8px; }
.panel-chips { display: flex; flex-wrap: wrap; gap: 5px; margin: 4px 0; }
.chip.small { font-size: 12px; padding: 2px 8px; }
.map-controls-sep, .chips .sep { font-size: 14px; opacity: 0.6; align-self: center; margin-left: 8px; }
.chip.toggle:not(.active) { opacity: 0.45; }
.chip.legend-unlock.active { border-color: #555; }
.chip.legend-stat.active { border-color: var(--ink-blue); color: var(--ink-blue); }

.synergy-svg { display: block; font-family: var(--font); }
.synergy-svg .lane { fill: #f5f0e8; }
.synergy-svg .lane.alt { fill: #efe8da; }
.synergy-svg .lane-label { font-size: 17px; font-weight: bold; }
.synergy-svg .col-label { font-size: 13px; fill: #888; }

.synergy-svg .edge { fill: none; transition: opacity 0.15s; }
.synergy-svg .edge-unlock { stroke: #555; stroke-width: 1.6; opacity: 0.28; }
.synergy-svg .edge-stat { stroke: #4a7fd1; stroke-width: 1.6; stroke-dasharray: 6 5; opacity: 0.4; }
.synergy-svg .edge.hl { opacity: 1; stroke-width: 2.6; }
.synergy-svg .edge.dim { opacity: 0.05; }
.synergy-svg .edge.off { display: none; }
.synergy-svg .arrow-unlock { fill: #555; }
.synergy-svg .arrow-stat { fill: #4a7fd1; }

.synergy-svg .map-node { cursor: pointer; }
.synergy-svg .node-box { fill: var(--paper); stroke-width: 2.4; }
.synergy-svg .node-text { font-size: 13px; fill: var(--ink); pointer-events: none; }
.synergy-svg .map-node:hover .node-box { fill: #fff; }
.synergy-svg .map-node.dim { opacity: 0.22; }
.synergy-svg .map-node.sel .node-box { fill: #fff3c4; stroke-width: 4; }
.synergy-svg .map-node.need .node-box { fill: #d9f0df; }
.synergy-svg .map-node.unlocks .node-box { fill: #ffe3cc; }
.synergy-svg .map-node.stat .node-box { fill: #dce8fa; }

/* ============ LEVEL-UP SELECTION ============ */
.card.selected,
.card.selected:hover:not(:disabled):not(.static) {
  transform: translateY(-8px);
  box-shadow: 0 0 0 4px var(--rarity), 6px 10px 0 var(--shadow);
  background: #fffaf0;
}

.doodle-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
  box-shadow: 4px 4px 0 rgba(0,0,0,0.2);
  background: var(--ink);
}

#levelup-confirm { min-width: 300px; }

/* ============ BOSS BAR ============ */
#boss-bar {
  position: fixed;
  top: 78px;
  left: 50%;
  transform: translateX(-50%);
  width: min(560px, calc(100vw - 32px));
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  pointer-events: none;
  z-index: 10;
}

#boss-name {
  font-weight: bold;
  font-size: 20px;
  color: var(--ink-red);
  text-shadow: 2px 2px 0 var(--paper);
}

#boss-track {
  width: 100%;
  height: 16px;
  background: rgba(245, 240, 232, 0.9);
  border: 2px solid var(--ink);
  border-radius: 9px;
  padding: 2px;
  box-shadow: 3px 3px 0 var(--shadow);
}

#boss-fill {
  height: 100%;
  width: 100%;
  background: var(--ink-red);
  border-radius: 6px;
  transition: width 0.15s ease;
}

body:not(.playing) #boss-bar { display: none !important; }

.pause-body { display: flex; flex-wrap: wrap; gap: 28px; align-items: flex-start; justify-content: center; width: min(1040px, 94vw); }
.pause-buttons { display: flex; flex-direction: column; gap: 12px; align-items: stretch; min-width: min(280px, 80vw); }
.pause-collection { flex: 1 1 420px; min-width: 0; max-width: 680px; display: grid; gap: 8px; }
.pause-collection h3 { margin: 0; font-size: 20px; }
.pause-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px;
  max-height: 52vh; overflow-y: auto; padding: 4px 6px 8px 2px;
}
.pause-grid .owned {
  display: grid; justify-items: center; gap: 2px; padding: 6px 4px; cursor: pointer;
  background: rgba(251, 248, 242, 0.95); border: 2.5px solid var(--rarity); border-radius: 10px 8px 11px 7px;
  font: inherit; font-size: 12px; line-height: 1.15; color: var(--ink); text-align: center;
}
.pause-grid .owned:hover, .pause-grid .owned:focus-visible { transform: translateY(-2px); outline: none; box-shadow: 2px 3px 0 var(--shadow); }
.pause-grid .empty { grid-column: 1 / -1; opacity: 0.6; font-size: 15px; }
.pause-buttons .doodle-btn { padding: 12px 28px; }

.shop-buttons { display: flex; gap: 14px; flex-wrap: wrap; justify-content: center; }
.shop-buttons .doodle-btn { padding: 12px 28px; }

/* ============ SETTINGS ============ */
#settings-screen { background: var(--paper); } /* solid, so the menu's buttons don't show through */
.settings-panel {
  display: flex; flex-direction: column; gap: 18px; width: min(460px, 92vw);
  background: var(--paper); border: 3px solid var(--ink); border-radius: 14px 10px 16px 9px;
  box-shadow: 6px 8px 0 var(--shadow); padding: 22px 26px;
}
.setting { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.setting-label { font-size: 22px; font-weight: bold; }
.setting-options { display: flex; gap: 8px; flex-wrap: wrap; }
.setting-options .chip { font-size: 18px; padding: 6px 16px; }
#settings-volume { flex: 1; min-width: 160px; max-width: 240px; accent-color: var(--ink); }

/* ============ MULTIPLAYER LEADERBOARD ============ */
#leaderboard {
  position: relative;
  z-index: 1;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  max-width: min(960px, calc(100vw - 32px));
  max-height: 64vh;
  overflow-y: auto;
}

#scoreboard {
  border-collapse: collapse;
  font-size: 16px;
  background: var(--paper, #fbf8f2);
  border: 2.5px solid #2c2c2c;
  border-radius: 6px;
}

#scoreboard th, #scoreboard td {
  padding: 6px 12px;
  text-align: right;
}

#scoreboard th {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #666;
  border-bottom: 2px solid #2c2c2c;
}

#scoreboard td.name, #scoreboard th:nth-child(2) { text-align: left; font-weight: bold; }
#scoreboard td.rank { text-align: center; }
#scoreboard tr.you td { background: rgba(74, 127, 209, 0.12); }

.swatch {
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-right: 6px;
  border: 2px solid #2c2c2c;
  border-radius: 50%;
  vertical-align: -1px;
}

#awards {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}

.award {
  width: 168px;
  padding: 10px;
  text-align: center;
  background: var(--paper, #fbf8f2);
  border: 2.5px solid #2c2c2c;
  border-radius: 4px 10px 6px 12px;
  box-shadow: 3px 3px 0 rgba(44, 44, 44, 0.25);
}

.award.silly { border-style: dashed; transform: rotate(-1deg); }
.award:nth-child(even).silly { transform: rotate(1.2deg); }
.award-icon { font-size: 28px; }
.award-title { font-weight: bold; font-size: 16px; }
.award-desc { font-size: 12px; color: #666; margin-bottom: 6px; }
.award-who { font-weight: bold; }
.award-value { font-size: 13px; color: #4a7fd1; }

/* ============ ONLINE ============ */
#net-status {
  position: fixed; top: 76px; left: 50%; transform: translateX(-50%); z-index: 35; display: none;
  padding: 8px 18px; font-size: 18px; font-weight: bold; color: var(--paper); background: var(--ink-red);
  border-radius: 12px; box-shadow: 3px 3px 0 var(--shadow); pointer-events: none;
}
#rejoin-btn { background: var(--ink-green); border-color: var(--ink-green); }
.overlay.online { justify-content: flex-start; padding-top: 40px; overflow-y: auto; z-index: 40; background: var(--paper); }
.online-main { display: flex; flex-direction: column; align-items: center; gap: 16px; width: min(760px, 100%); }
.online-row { display: flex; gap: 16px; width: 100%; flex-wrap: wrap; }
.online-row .online-panel { flex: 1 1 280px; }
.online-panel {
  display: flex; flex-direction: column; gap: 10px; padding: 16px 20px;
  background: var(--paper); border: 3px solid var(--ink); border-radius: 14px 10px 16px 9px;
  box-shadow: 6px 8px 0 var(--shadow);
}
.online-panel.wide { width: 100%; }
.online-panel h3 { font-size: 22px; display: flex; align-items: center; gap: 10px; }
.online-panel input, .online-name input {
  font-family: var(--font); font-size: 17px; color: var(--ink); padding: 7px 14px;
  background: var(--paper); border: 2px solid var(--ink); border-radius: 12px; outline: none;
  user-select: text; -webkit-user-select: text; cursor: text;
}
.online-panel input:focus, .online-name input:focus { border-color: var(--ink-blue); }
.online-name { display: flex; align-items: center; gap: 12px; font-size: 20px; font-weight: bold; }
.online-name input { width: 220px; }
.code-input { text-transform: uppercase; letter-spacing: 4px; font-weight: bold; }
.online-field { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.doodle-btn.small { padding: 8px 24px; font-size: 17px; align-self: flex-start; }
.online-status { min-height: 1.4em; font-size: 17px; color: var(--ink-red); text-align: center; }
.online-status.ok { color: var(--ink-light); }
.lobby-list { display: flex; flex-direction: column; gap: 8px; max-height: 32vh; overflow-y: auto; }
.lobby-row {
  display: flex; align-items: center; gap: 12px; padding: 8px 12px; flex-wrap: wrap;
  border: 2px dashed rgba(44, 44, 44, 0.35); border-radius: 10px;
}
.lobby-row .lobby-name { font-weight: bold; flex: 1; min-width: 120px; }
.lobby-row .lobby-host, .lobby-row .lobby-count { color: var(--ink-light); font-size: 15px; }
.lobby-row input { width: 150px; padding: 4px 10px; font-size: 15px; }
.lobby-empty { color: var(--ink-light); font-style: italic; }
.room-panel { width: min(520px, 100%); }
.room-code { font-size: 20px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.room-code strong { font-size: 32px; letter-spacing: 6px; }
.room-players { list-style: none; display: flex; flex-direction: column; gap: 8px; }
.room-players li { display: flex; align-items: center; gap: 8px; font-size: 18px; }
.room-players .who { font-weight: bold; }
.room-players .tag { font-size: 13px; color: var(--ink-light); }
.room-players .conn { margin-left: auto; font-size: 14px; color: var(--ink-light); }
.room-players .conn.connected { color: var(--ink-green); }
.room-players .conn.failed { color: var(--ink-red); }
.room-buttons { display: flex; gap: 16px; flex-wrap: wrap; justify-content: center; }

/* ============ TOUCHSCREENS AND SMALL SCREENS ============ */
/* body.touch is set by Touch (src/touch.js) once a finger is used */
.hint-touch, .hint-twin { display: none; }
body.touch .hint-touch { display: block; }
body.touch.twin .hint-touch { display: none; }
body.touch.twin .hint-twin { display: block; }
body.touch .hint-keys { display: none; }
/* On touchscreens the powerup icons would cover the boss bar and catch thumbs: they're in the pause menu instead */
body.touch #powerup-list { display: none; }
/* Blurring what's behind the HUD boxes is costly on phones and barely visible */
body.touch #ui > div, body.touch #health-bar { backdrop-filter: none; }
body.touch .card .key { display: none; }
html, body { overscroll-behavior: none; }
body.touch canvas { touch-action: none; }

#touch-controls { position: fixed; inset: 0; pointer-events: none; z-index: 12; display: none; }
body.touch.playing #touch-controls { display: block; }
.touch-btn {
  position: absolute; pointer-events: auto; font-family: var(--font); font-weight: bold; color: var(--ink);
  background: rgba(245, 240, 232, 0.85); border: 2.5px solid var(--ink); border-radius: 14px;
  box-shadow: 3px 3px 0 var(--shadow); touch-action: none; -webkit-tap-highlight-color: transparent;
}
.touch-btn:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--shadow); }
#touch-pause { top: max(10px, env(safe-area-inset-top)); right: max(10px, env(safe-area-inset-right)); width: 46px; height: 46px; font-size: 20px; }
#touch-dash {
  right: max(28px, calc(env(safe-area-inset-right) + 16px)); bottom: 56px; width: 78px; height: 78px; font-size: 32px;
  border-radius: 50%;
}
#touch-trade { left: 50%; transform: translateX(-50%); bottom: 64px; padding: 10px 24px; font-size: 20px; }
#touch-trade:active { transform: translateX(-50%) translate(2px, 2px); }

/* The HUD makes room for the pause button */
body.touch #ui { padding-right: 70px; }


/* Phones (and other short screens): everything a bit smaller, and long menus scroll */
@media (max-height: 540px) {
  #ui { padding: 8px max(10px, env(safe-area-inset-left)); gap: 6px; }
  #ui > div { padding: 3px 9px; font-size: 14px; border-radius: 10px; }
  #score { font-size: 15px; }
  #gold { font-size: 15px; }
  #health-bar { width: 150px; height: 22px; }
  #shield-value { font-size: 11px; }
  .inv { width: 28px; height: 28px; font-size: 16px; border-radius: 8px; }
  #powerup-list { gap: 4px; bottom: 34px; }
  #xp-wrap { padding: 4px max(12px, env(safe-area-inset-left)) 6px; }
  #level-label { font-size: 14px; min-width: 40px; }
  #xp-bar { height: 10px; }

  #start-screen { gap: 10px; }
  #start-screen h1 { font-size: 36px; }
  #start-screen p { font-size: 14px; line-height: 1.4; }
  #start-screen .doodle-btn { width: 220px; }
  .doodle-btn { padding: 8px 22px; font-size: 16px; }

  .overlay { justify-content: flex-start; overflow-y: auto; padding: 12px; gap: 10px; }
  .overlay h2 { font-size: 26px; }
  .overlay .hint { font-size: 14px; }
  .cards { gap: 10px; }
  .card { width: 160px; min-height: 0; padding: 10px; gap: 4px; }
  .card .icon { transform: scale(0.75); margin: -6px 0; }
  .card .name { font-size: 16px; }
  .card .desc { font-size: 12px; }
  .card .tags, .card .owned { display: none; }
  .settings-panel { padding: 14px 18px; gap: 12px; }
  .setting-label { font-size: 18px; }
  #game-over { gap: 8px; justify-content: flex-start; overflow-y: auto; padding: 12px; }
  #game-over h2 { font-size: 30px; }
  #final-score { font-size: 18px; }
  #leaderboard { max-height: none; overflow: visible; }
  #scoreboard { font-size: 13px; }
  #scoreboard th, #scoreboard td { padding: 3px 8px; }
  .award { width: 130px; padding: 6px; }
  .overlay.online { padding-top: 12px; }
  .online-panel { padding: 10px 14px; }
  #net-status { top: 48px; font-size: 14px; }
  #boss-bar { top: 44px; }
}

/* Phones held upright (and other narrow screens) */
@media (max-width: 540px) {
  #ui { padding: 6px 8px; gap: 5px; }
  body.touch #ui { padding-right: 60px; }
  #ui > div { padding: 3px 8px; font-size: 13px; }
  #score, #gold { font-size: 14px; }
  #enemy-count { display: none; }
  #health-bar { width: 120px; height: 20px; }
  #touch-pause { width: 42px; height: 42px; }
  #boss-bar { top: 70px; }

  #start-screen { gap: 10px; padding: 0 16px; }
  #start-screen h1 { font-size: 38px; text-align: center; }
  #start-screen p { font-size: 14px; line-height: 1.4; }
  #start-screen .doodle-btn { width: min(260px, 80vw); }
  .doodle-btn { padding: 10px 22px; font-size: 17px; }

  .overlay { justify-content: flex-start; overflow-y: auto; padding: 14px 16px; gap: 10px; }
  .overlay h2 { font-size: 26px; text-align: center; }
  .cards { gap: 8px; }
  .card { width: calc(50vw - 24px); min-height: 0; padding: 10px; gap: 4px; }
  .card .icon { transform: scale(0.75); margin: -6px 0; }
  .card .name { font-size: 16px; text-align: center; }
  .card .desc { font-size: 12px; }
  .card .tags, .card .owned { display: none; }
  .shop-buttons, .room-buttons { flex-direction: column; align-items: stretch; width: min(300px, 90vw); }
  #game-over { gap: 8px; justify-content: flex-start; overflow-y: auto; padding: 14px 10px; }
  #game-over h2 { font-size: 32px; }
  #final-score { font-size: 17px; text-align: center; }
  #leaderboard { max-height: none; overflow: visible; max-width: 100%; }
  #scoreboard { font-size: 12px; display: block; overflow-x: auto; max-width: 100%; }
  #scoreboard th, #scoreboard td { padding: 3px 5px; }
  .award { width: calc(50vw - 20px); padding: 6px; }
  .online-name { flex-direction: column; gap: 4px; }
  .room-code strong { font-size: 26px; letter-spacing: 4px; }
  .settings-panel { padding: 14px 16px; }
  #net-status { top: 70px; font-size: 14px; }
}
