/* ============================================================
   Fish Kingdom Defense — UI theme
   Kingdom Rush-style chunky "stone tablet / sunken kingdom" look.
   Deep-sea blues + teal panels, sand-gold & coral accents.
   ============================================================ */

/* ---------- Pixel font (self-hosted: game runs on a LAN) ---------- */

@font-face {
  font-family: 'Press Start 2P';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('/fonts/press-start-2p-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
    U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193,
    U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Press Start 2P';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('/fonts/press-start-2p-latin-ext.woff2') format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF,
    U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020,
    U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

/* ---------- Palette ---------- */

:root {
  --abyss-0: #02121f;           /* deepest water */
  --abyss-1: #03283f;
  --abyss-2: #0a3d5a;
  --teal-0: #0d4a63;            /* panel base */
  --teal-1: #14607e;            /* panel light edge */
  --teal-2: #1d7f9b;            /* hover / secondary accent */
  --foam:   #d8eef7;            /* main text */
  --foam-dim: #9cc3d4;          /* secondary text */
  --foam-faint: #6f9fb4;        /* tertiary text */
  --gold-0: #f2c14e;            /* sand gold */
  --gold-1: #c99a2e;            /* gold dark edge */
  --gold-2: #8a6616;            /* gold deepest edge */
  --gold-ink: #3a2b05;          /* text on gold */
  --aqua-0: #63c8de;            /* default button */
  --aqua-1: #3a90ab;            /* aqua dark edge */
  --aqua-2: #256072;            /* aqua deepest edge */
  --aqua-ink: #06222e;
  --coral-0: #ff7f5c;           /* coral / danger */
  --coral-1: #c74e31;
  --coral-2: #8a3018;
  --kelp-0: #6fce7a;            /* repair / equipped green */
  --kelp-1: #3f9a4d;
  --pixel: 'Press Start 2P', monospace;
  --body: "Trebuchet MS", "Segoe UI", "PingFang SC", "Hiragino Sans GB", sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--body);
  /* Layered deep-sea gradient: faint light shafts over a dark vignette. */
  background:
    radial-gradient(1200px 500px at 50% -10%, rgba(84, 176, 205, .14), transparent 60%),
    radial-gradient(900px 700px at 85% 110%, rgba(20, 96, 126, .25), transparent 60%),
    linear-gradient(180deg, var(--abyss-1) 0%, var(--abyss-0) 70%, #010b14 100%);
  background-attachment: fixed;
  color: var(--foam);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.screen { display: none; flex-direction: column; align-items: center; gap: 16px; padding: 20px; width: 100%; }
.screen.active { display: flex; }
.hidden { display: none !important; }
/* Host-only controls start hidden and are revealed once we know who's host. */
/* Host-only controls start hidden in the HTML; renderLobby unhides them for
   the host (a bare display:none here would defeat that toggle). */

/* ---------- Headings: chunky pixel type with a carved shadow ---------- */

h1 {
  font-family: var(--pixel);
  font-size: 1.5rem; line-height: 1.6;
  text-align: center; letter-spacing: .02em;
  color: var(--foam);
  text-shadow: 0 3px 0 var(--abyss-0), 0 6px 16px rgba(0,0,0,.55);
}
h1 .vs { color: var(--gold-0); }
h2 {
  font-family: var(--pixel);
  font-size: 1.05rem; line-height: 1.7;
  text-shadow: 0 2px 0 var(--abyss-0), 0 4px 12px rgba(0,0,0,.5);
  text-align: center;
}
.tagline { color: var(--foam-dim); text-align: center; max-width: 520px; font-size: .95rem; line-height: 1.45; }
.sub { color: var(--foam-dim); font-size: .85rem; }
.error { color: #ff9d8a; min-height: 1.2em; text-align: center; font-weight: bold; text-shadow: 0 1px 2px rgba(0,0,0,.5); }
.row { display: flex; gap: 10px; align-items: center; }

/* ---------- Controls ---------- */

input {
  padding: 12px; border-radius: 10px; border: 2px solid var(--teal-1);
  font-size: 1rem; font-family: var(--body);
  text-align: center; background: var(--abyss-0); color: var(--foam); width: 100%;
  box-shadow: inset 0 3px 6px rgba(0,0,0,.45);
  outline: none; transition: border-color .12s, box-shadow .12s;
}
input::placeholder { color: var(--foam-faint); }
input:focus {
  border-color: var(--gold-0);
  box-shadow: inset 0 3px 6px rgba(0,0,0,.45), 0 0 0 3px rgba(242,193,78,.25);
}
#join-code { text-transform: uppercase; letter-spacing: .3em; font-weight: bold; }
.join-row { display: flex; gap: 8px; }
.join-row input { width: 110px; }
.join-row button { flex: 1; }
.field-label { font-size: .85rem; color: var(--foam-dim); align-self: flex-start; }

/* Chunky arcade buttons: a dark base edge reads as the side of the button,
   hover lifts it, press sinks it into the frame. */
button {
  padding: 12px 18px; border: none; border-radius: 10px; cursor: pointer;
  font-size: .95rem; font-weight: bold; font-family: var(--body);
  color: var(--aqua-ink); background: linear-gradient(180deg, #7fd4e8, var(--aqua-0));
  box-shadow:
    inset 0 2px 0 rgba(255,255,255,.35),
    0 5px 0 var(--aqua-2),
    0 8px 14px rgba(0,0,0,.35);
  transition: transform .06s, box-shadow .06s, filter .12s;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
button:hover:not(:disabled) {
  filter: brightness(1.09);
  transform: translateY(-2px);
  box-shadow:
    inset 0 2px 0 rgba(255,255,255,.35),
    0 7px 0 var(--aqua-2),
    0 11px 18px rgba(0,0,0,.4);
}
button:active:not(:disabled) {
  transform: translateY(3px);
  box-shadow:
    inset 0 2px 0 rgba(255,255,255,.2),
    0 2px 0 var(--aqua-2),
    0 4px 8px rgba(0,0,0,.35);
}
button:disabled { opacity: .45; cursor: not-allowed; }

/* Primary action: sand gold. */
button.big {
  font-family: var(--pixel);
  font-size: .95rem; line-height: 1.5;
  padding: 14px 22px;
  color: var(--gold-ink);
  background: linear-gradient(180deg, #ffd76e, var(--gold-0));
  box-shadow:
    inset 0 2px 0 rgba(255,255,255,.5),
    0 6px 0 var(--gold-2),
    0 10px 16px rgba(0,0,0,.4);
}
button.big:hover:not(:disabled) {
  box-shadow:
    inset 0 2px 0 rgba(255,255,255,.5),
    0 8px 0 var(--gold-2),
    0 13px 20px rgba(0,0,0,.45);
}
button.big:active:not(:disabled) {
  box-shadow:
    inset 0 2px 0 rgba(255,255,255,.3),
    0 2px 0 var(--gold-2),
    0 4px 8px rgba(0,0,0,.4);
}

/* Quiet text-ish buttons still get a pill so touch targets stay fat. */
button.small {
  background: rgba(216,238,247,.08); color: var(--foam-dim);
  box-shadow: inset 0 0 0 1px rgba(216,238,247,.18), 0 3px 0 rgba(0,0,0,.3);
  font-weight: normal; padding: 10px 14px;
}
button.small:hover:not(:disabled) { color: var(--foam); background: rgba(216,238,247,.14); }
button.small:active:not(:disabled) { transform: translateY(2px); box-shadow: inset 0 0 0 1px rgba(216,238,247,.18), 0 1px 0 rgba(0,0,0,.3); }
button.small-btn { padding: 8px 12px; font-size: .82rem; }

/* Danger / reset: coral red. */
button.danger {
  color: #fff; text-shadow: 0 1px 1px rgba(0,0,0,.35);
  background: linear-gradient(180deg, #ff9678, var(--coral-0));
  box-shadow:
    inset 0 2px 0 rgba(255,255,255,.3),
    0 5px 0 var(--coral-2),
    0 8px 14px rgba(0,0,0,.35);
}
button.danger:hover:not(:disabled) {
  box-shadow:
    inset 0 2px 0 rgba(255,255,255,.3),
    0 7px 0 var(--coral-2),
    0 11px 18px rgba(0,0,0,.4);
}
button.danger:active:not(:disabled) {
  box-shadow:
    inset 0 2px 0 rgba(255,255,255,.15),
    0 2px 0 var(--coral-2),
    0 4px 8px rgba(0,0,0,.35);
}
button.danger.confirming { background: linear-gradient(180deg, #ff6a4a, #e8502f); animation: boss-pulse 1.1s ease-in-out infinite; }

/* ---------- Panels: stone tablet with layered pixel-style borders ---------- */

.panel {
  display: flex; flex-direction: column; gap: 12px; width: 320px;
  background: linear-gradient(180deg, var(--teal-0), var(--abyss-2));
  padding: 20px; border-radius: 14px;
  /* stacked rings simulate a thick carved border */
  box-shadow:
    inset 0 2px 0 rgba(255,255,255,.12),
    inset 0 -3px 0 rgba(0,0,0,.3),
    0 0 0 3px var(--abyss-0),
    0 0 0 5px var(--teal-1),
    0 0 0 7px rgba(1, 11, 20, .9),
    0 14px 30px rgba(0,0,0,.5);
}

/* ---------- Character ---------- */

.tabs {
  display: flex; gap: 6px; background: rgba(1,11,20,.55); padding: 6px; border-radius: 12px;
  box-shadow: inset 0 2px 6px rgba(0,0,0,.5), 0 0 0 2px rgba(20,96,126,.5);
}
.tab { background: transparent; color: var(--foam-dim); box-shadow: none; padding: 9px 24px; }
.tab:hover:not(:disabled) { box-shadow: none; transform: none; color: var(--foam); }
.tab.active {
  color: var(--gold-ink); background: linear-gradient(180deg, #ffd76e, var(--gold-0));
  box-shadow: inset 0 2px 0 rgba(255,255,255,.5), 0 3px 0 var(--gold-2);
}

.note { font-size: .76rem; color: var(--foam-faint); line-height: 1.35; }

/* Character select. auto-fit means a new character just wraps onto the grid
   without anyone touching the CSS. */
.character-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px; width: min(680px, 94vw); max-height: 62vh; overflow-y: auto; padding: 8px;
}
.character-card {
  display: flex; flex-direction: column; align-items: center; gap: 5px;
  background: linear-gradient(180deg, rgba(20,96,126,.55), rgba(3,40,63,.75));
  padding: 14px 12px; border-radius: 12px;
  border: 3px solid var(--teal-1); cursor: pointer; text-align: center;
  box-shadow: inset 0 2px 0 rgba(255,255,255,.08), 0 4px 0 rgba(1,11,20,.8);
  transition: transform .08s, border-color .12s, background .12s;
}
.character-card:hover {
  border-color: var(--teal-2);
  transform: translateY(-2px);
}
.character-card.selected {
  border-color: var(--gold-0);
  background: linear-gradient(180deg, rgba(242,193,78,.22), rgba(3,40,63,.8));
  box-shadow: inset 0 2px 0 rgba(255,255,255,.12), 0 4px 0 var(--gold-2), 0 0 14px rgba(242,193,78,.35);
}
.character-card .face { font-size: 2.4rem; line-height: 1; }
/* Hand-drawn faces sit in the same box as the emoji they replace.
   Pixel art stays crisp rather than being smoothed into mush. */
.face-img {
  width: 2.4rem; height: 2.4rem; object-fit: contain; display: block;
  image-rendering: pixelated;
}
.character-card .cname { font-weight: bold; }
.character-card .ctag { font-size: .78rem; color: var(--foam-dim); line-height: 1.3; }

.modal-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; justify-content: center; }

.avatar-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.avatar-option {
  font-size: 1.9rem; text-align: center; padding: 8px; border-radius: 10px;
  background: rgba(216,238,247,.08); cursor: pointer; border: 3px solid var(--teal-1);
  transition: transform .08s, border-color .12s;
}
.avatar-option:hover { transform: translateY(-2px); border-color: var(--teal-2); }
.avatar-option.selected {
  border-color: var(--gold-0); background: rgba(242,193,78,.18);
  box-shadow: 0 0 10px rgba(242,193,78,.3);
}

/* The "current character" summary card on the menu. Same look, roomier. */
#character-card {
  flex-direction: row; gap: 14px; padding: 14px 24px; cursor: default;
}
#character-card:hover { transform: none; border-color: var(--teal-1); }
.character-card .face { font-size: 2.6rem; }
.character-card .face-img { width: 2.8rem; height: 2.8rem; }
.character-card .name { font-size: 1.25rem; font-weight: bold; }
.character-card .meta { color: var(--foam-dim); font-size: .85rem; }
.character-card .wallet { color: var(--gold-0); font-weight: bold; font-size: 1.1rem; }

#lobby-players { list-style: none; text-align: center; font-size: 1.05rem; }
#lobby-players li {
  padding: 7px 18px; margin: 4px 0;
  background: rgba(216,238,247,.06); border-radius: 999px;
  box-shadow: inset 0 0 0 1px rgba(216,238,247,.12);
}
#lobby-code { color: var(--gold-0); letter-spacing: .2em; font-family: var(--pixel); font-size: .9em; }

/* ---------- Game screen ---------- */

#screen-game { gap: 8px; padding: 8px; height: 100vh; height: 100dvh; justify-content: flex-start; }

/* Compact game HUD: a carved bar with pill stats. */
.topbar {
  display: flex; align-items: center; gap: 14px; width: 100%; max-width: 1400px;
  background: linear-gradient(180deg, rgba(13,74,99,.9), rgba(3,40,63,.92));
  padding: 7px 14px; border-radius: 12px;
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,.1),
    0 0 0 2px var(--abyss-0),
    0 0 0 3px rgba(20,96,126,.7),
    0 6px 14px rgba(0,0,0,.45);
}
.topbar .stat {
  font-size: 1.05rem; font-weight: bold; color: var(--gold-0); min-width: 110px;
  background: rgba(1,11,20,.6); padding: 5px 14px; border-radius: 999px;
  box-shadow: inset 0 2px 4px rgba(0,0,0,.55), inset 0 0 0 1px rgba(242,193,78,.3);
  text-align: center;
}
.wave-block {
  text-align: center; min-width: 150px;
  background: rgba(1,11,20,.6); padding: 4px 16px; border-radius: 999px;
  box-shadow: inset 0 2px 4px rgba(0,0,0,.55), inset 0 0 0 1px rgba(99,200,222,.25);
}
#hud-wave { font-family: var(--pixel); font-size: .8rem; line-height: 1.6; color: var(--foam); }
/* Boss-wave text is longer ("☠ Wave 5 — BOSS" + a busy sub). Never let it
   wrap -- a second line grows the pill and the whole stage jumps. */
#hud-wave, .wave-block .sub { white-space: nowrap; }
/* Every fifth wave brings a boss -- make that impossible to miss. */
#hud-wave.boss-wave { color: var(--coral-0); animation: boss-pulse 1.1s ease-in-out infinite; }
@keyframes boss-pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: .55; }
}
@media (prefers-reduced-motion: reduce) {
  #hud-wave.boss-wave { animation: none; }
}
.core-block { flex: 1; max-width: 340px; }
.core-block .sub { font-size: .78rem; font-weight: bold; letter-spacing: .04em; }
/* Repair only appears when the kingdom is hurt and you're standing at it, so
   it should catch the eye the moment it shows up. */
.small-btn.repair {
  color: #08300f; background: linear-gradient(180deg, #8ce096, var(--kelp-0));
  box-shadow: inset 0 2px 0 rgba(255,255,255,.4), 0 4px 0 #2a6b35, 0 7px 12px rgba(0,0,0,.35);
  white-space: nowrap;
}
.small-btn.repair:disabled { background: #6f9a76; }
.core-block .bar {
  height: 13px; background: rgba(1,11,20,.75); border-radius: 7px; overflow: hidden; margin-top: 4px;
  box-shadow: inset 0 2px 4px rgba(0,0,0,.6), inset 0 0 0 1px rgba(216,238,247,.12);
}
#hud-core-fill {
  height: 100%; width: 100%;
  background: linear-gradient(180deg, #9cf07a 0%, var(--kelp-0) 50%, var(--kelp-1) 100%);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.4);
  transition: width .2s;
}
.topbar .row { margin-left: auto; }
.topbar .small-btn {
  background: rgba(216,238,247,.1); color: var(--foam);
  box-shadow: inset 0 0 0 1px rgba(216,238,247,.2), 0 3px 0 rgba(0,0,0,.35);
}
.topbar .small-btn:hover:not(:disabled) { background: rgba(216,238,247,.18); }
.topbar .small-btn:active:not(:disabled) { transform: translateY(2px); box-shadow: inset 0 0 0 1px rgba(216,238,247,.2), 0 1px 0 rgba(0,0,0,.35); }

.stage {
  position: relative; flex: 1; min-height: 0;
  display: flex; align-items: center; justify-content: center; width: 100%;
}
#canvas {
  border-radius: 14px;
  box-shadow:
    0 0 0 3px var(--abyss-0),
    0 0 0 5px rgba(20,96,126,.65),
    0 14px 34px rgba(0,0,0,.6);
  /* Fill the stage exactly; the backing store is resized to match in JS, so
     portrait screens get a tall window of the world, not a letterbox. */
  width: 100%; height: 100%; display: block; cursor: crosshair;
}

/* Phones (and narrow windows generally): keep the HUD compact so the water
   gets the room. */
@media (max-width: 700px) {
  .topbar { gap: 8px; padding: 6px 10px; flex-wrap: wrap; border-radius: 10px; }
  .topbar .stat { min-width: 0; font-size: .9rem; padding: 4px 12px; }
  .wave-block { min-width: 0; padding: 3px 12px; }
  #hud-wave { font-size: .62rem; }
  .core-block { max-width: none; min-width: 140px; }
  .topbar .row { margin-left: 0; }
  .topbar .small-btn { padding: 9px 11px; } /* keep touch targets fat */
  #hud-room { display: none; }
  .joystick { width: 108px; height: 108px; }
  .joystick-knob { width: 48px; height: 48px; }
  .action-btn { width: 68px; height: 68px; }
  .action-btn .glyph { font-size: 1.4rem; }
  .build-panel { max-width: 92vw; bottom: 8px; }
  .stick-zone { left: 10px; bottom: 10px; }
  .action-zone { right: 10px; bottom: 10px; }
}

.hero-status {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%);
  background: linear-gradient(180deg, rgba(13,74,99,.95), rgba(3,40,63,.95));
  padding: 16px 30px; border-radius: 14px;
  font-family: var(--pixel); font-size: .95rem; line-height: 1.7; text-align: center;
  color: var(--foam); pointer-events: none;
  box-shadow:
    0 0 0 3px var(--abyss-0),
    0 0 0 5px var(--teal-1),
    0 16px 36px rgba(0,0,0,.6);
}

/* ---------- On-screen controls ---------- */

/* Both control clusters float over the canvas so the map keeps the screen.
   touch-action:none stops iPadOS scrolling the page while you steer. */
.stick-zone, .action-zone {
  position: absolute; bottom: 18px; touch-action: none; user-select: none;
  -webkit-user-select: none;
}
.stick-zone { left: 18px; }
.action-zone { right: 18px; display: flex; flex-direction: column; align-items: flex-end; gap: 10px; }

/* Virtual joystick: frosted glass ring that lights up gold while held. */
.joystick {
  width: 132px; height: 132px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, rgba(99,200,222,.22), rgba(3,40,63,.5) 70%);
  border: 3px solid rgba(216,238,247,.35);
  box-shadow:
    inset 0 3px 10px rgba(0,0,0,.45),
    inset 0 -2px 6px rgba(255,255,255,.08),
    0 6px 14px rgba(0,0,0,.4);
  display: flex; align-items: center; justify-content: center;
  touch-action: none; transition: background .12s, border-color .12s;
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}
.joystick.active {
  background: radial-gradient(circle at 35% 30%, rgba(242,193,78,.25), rgba(3,40,63,.6) 70%);
  border-color: rgba(242,193,78,.75);
  box-shadow:
    inset 0 3px 12px rgba(0,0,0,.5),
    0 0 16px rgba(242,193,78,.35),
    0 6px 14px rgba(0,0,0,.4);
}
.joystick-knob {
  width: 58px; height: 58px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #a8e2f2, var(--aqua-0) 60%, var(--aqua-1));
  border: 3px solid rgba(255,255,255,.65);
  pointer-events: none;
  box-shadow: inset 0 -4px 6px rgba(0,0,0,.3), 0 4px 10px rgba(0,0,0,.45);
}
.joystick.active .joystick-knob {
  background: radial-gradient(circle at 35% 30%, #ffe08a, var(--gold-0) 60%, var(--gold-1));
  border-color: rgba(255,255,255,.8);
}

/* Action buttons: big translucent discs with a carved rim. Pressed state is
   unmistakable — the disc sinks and its rim glows. */
.action-buttons { display: flex; gap: 12px; align-items: flex-end; }
.action-btn {
  position: relative; overflow: hidden;
  width: 84px; height: 84px; border-radius: 50%; padding: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 1px;
  border: 3px solid rgba(255,255,255,.4);
  box-shadow:
    inset 0 2px 0 rgba(255,255,255,.35),
    inset 0 -5px 8px rgba(0,0,0,.3),
    0 6px 0 rgba(1,11,20,.85),
    0 10px 16px rgba(0,0,0,.45);
  touch-action: none;
}
.action-btn:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow:
    inset 0 2px 0 rgba(255,255,255,.35),
    inset 0 -5px 8px rgba(0,0,0,.3),
    0 8px 0 rgba(1,11,20,.85),
    0 13px 20px rgba(0,0,0,.5);
}
.action-btn:active:not(:disabled) {
  transform: translateY(4px);
  filter: brightness(1.12);
  box-shadow:
    inset 0 2px 6px rgba(0,0,0,.35),
    0 2px 0 rgba(1,11,20,.85),
    0 0 16px rgba(255,255,255,.25);
}
.action-btn .glyph { font-size: 1.7rem; line-height: 1; filter: drop-shadow(0 2px 2px rgba(0,0,0,.4)); }
.action-btn .label { font-size: .72rem; font-weight: bold; text-shadow: 0 1px 2px rgba(0,0,0,.35); }
.action-btn .count { font-size: .68rem; opacity: .9; }
.action-btn.build { background: radial-gradient(circle at 35% 30%, #ffe08a, var(--gold-0) 55%, var(--gold-1)); color: var(--gold-ink); }
.action-btn.build.armed {
  background: radial-gradient(circle at 35% 30%, #a8ecab, var(--kelp-0) 55%, var(--kelp-1));
  box-shadow:
    0 0 0 4px rgba(111,206,122,.45),
    inset 0 2px 0 rgba(255,255,255,.35),
    inset 0 -5px 8px rgba(0,0,0,.3),
    0 6px 0 rgba(1,11,20,.85),
    0 10px 16px rgba(0,0,0,.45);
}
.action-btn.build.maxed { background: radial-gradient(circle at 35% 30%, #c9ba68, #a8974a 55%, #7a6c33); }
.action-btn.skill { background: radial-gradient(circle at 35% 30%, #a8e2f2, var(--aqua-0) 55%, var(--aqua-1)); }
/* Fills back up from the bottom as the ability recharges. */
.action-btn.skill::after {
  content: ""; position: absolute; left: 0; bottom: 0; width: 100%;
  height: var(--cooldown, 0%); background: rgba(1,11,20,.6); pointer-events: none;
}
.action-btn.skill.cooling .glyph { opacity: .45; }

/* The equipped skills sit in a row above Build. They're smaller than the build
   button so a full bar still fits across a phone screen. */
.skill-buttons {
  display: flex; gap: 8px; justify-content: flex-end;
  margin-bottom: 10px; flex-wrap: wrap;
  /* Sized so a full bar stays on one line rather than dropping its last
     button onto a row of its own. Holds five at 58px wide, which leaves room
     if MAX_EQUIPPED_SKILLS is ever raised again. Wraps below that, which is
     what a narrow phone in portrait wants. */
  max-width: 340px;
}
.skill-buttons .action-btn { width: 58px; height: 58px; }
.skill-buttons .action-btn .glyph { font-size: 1.25rem; }
/* Names are long ("Mirror Shoal") and the button is small -- the emoji is the
   real identifier, so the label is a quiet second. */
.skill-buttons .action-btn .label {
  font-size: .48rem; max-width: 54px; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap;
}
.skill-buttons .action-btn .cooldown { font-size: .8rem; }

/* Each skill keeps its own colour, so muscle memory works by position AND
   by hue rather than by reading the label mid-fight. */
.action-btn.skill-shock     { background: radial-gradient(circle at 35% 30%, #a8e2f2, #63c8de 55%, #3a90ab); }
.action-btn.skill-freeze    { background: radial-gradient(circle at 35% 30%, #d6f2ff, #a8e4ff 55%, #6fb8d8); }
.action-btn.skill-fire      { background: radial-gradient(circle at 35% 30%, #ffd0a0, #ffb066 55%, #d07f3a); }
.action-btn.skill-knockback { background: radial-gradient(circle at 35% 30%, #b2e2f4, #86d0e8 55%, #5498b4); }
.action-btn.skill-charm     { background: radial-gradient(circle at 35% 30%, #d8ffc8, #b6ff9c 55%, #7fc964); }
.action-btn.skill-mirror    { background: radial-gradient(circle at 35% 30%, #eee4ff, #d9c9ff 55%, #a28fd0); }

/* On a phone a full-width row of skills ends up sitting over the joystick,
   where a left thumb sets off a skill by accident. Narrow screens get smaller
   buttons in a block on the right, three to a row, well clear of the stick. */
@media (max-width: 560px) {
  .skill-buttons { max-width: 158px; }
  .skill-buttons .action-btn { width: 46px; height: 46px; border-width: 2px; }
  .skill-buttons .action-btn .glyph { font-size: 1.05rem; }
  .skill-buttons .action-btn .label { display: none; }
  .skill-buttons .action-btn .cooldown { font-size: .7rem; }
}
.action-btn .cooldown {
  position: absolute; font-size: .95rem; font-weight: bold; color: var(--foam);
  text-shadow: 0 1px 3px rgba(0,0,0,.85);
}

/* Tower picker, opened by holding Build */
.tower-menu {
  position: absolute; right: 0; bottom: 104px;
  display: flex; flex-direction: column; gap: 8px;
  background: linear-gradient(180deg, rgba(13,74,99,.97), rgba(3,40,63,.97));
  padding: 12px; border-radius: 14px;
  box-shadow:
    0 0 0 3px var(--abyss-0),
    0 0 0 5px rgba(242,193,78,.55),
    0 14px 30px rgba(0,0,0,.6);
  min-width: 190px;
}
.tower-menu-title { font-size: .8rem; color: var(--foam-dim); text-align: center; }
.tower-menu .tower-card { flex-direction: row; align-items: center; gap: 8px; text-align: left; }
.tower-menu .tower-card .emoji { font-size: 1.5rem; }
.tower-menu .tower-card .tname { flex: 1; }

/* ---------- Tower actions ---------- */

.build-panel {
  position: absolute; left: 50%; bottom: 18px; transform: translateX(-50%);
  display: flex; gap: 10px; align-items: center; justify-content: center;
  background: linear-gradient(180deg, rgba(13,74,99,.95), rgba(3,40,63,.95));
  border-radius: 14px; padding: 12px; flex-wrap: wrap;
  box-shadow:
    0 0 0 3px var(--abyss-0),
    0 0 0 5px rgba(99,200,222,.4),
    0 12px 26px rgba(0,0,0,.55);
  max-width: 60vw;
}
.build-hint { color: var(--foam-dim); font-size: .9rem; }
.build-title { font-weight: bold; margin-right: 6px; text-align: center; }

.tower-card {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 14px; border-radius: 10px;
  background: rgba(216,238,247,.08);
  cursor: pointer; border: 2px solid rgba(216,238,247,.18); min-width: 112px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.08), 0 3px 0 rgba(0,0,0,.35);
  transition: transform .08s, border-color .12s, background .12s;
}
.tower-card:hover:not(.disabled) {
  border-color: var(--gold-0); background: rgba(242,193,78,.15);
  transform: translateY(-2px);
}
.tower-card.selected {
  border-color: var(--gold-0); background: rgba(242,193,78,.18);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.12), 0 3px 0 rgba(0,0,0,.35), 0 0 10px rgba(242,193,78,.3);
}
.tower-card.disabled { opacity: .4; cursor: not-allowed; }
.tower-card .emoji { font-size: 1.6rem; }
.tower-card .tname { font-size: .85rem; font-weight: bold; }
.tower-card .tdesc { font-size: .72rem; color: var(--foam-dim); }
.tower-card .cost { color: var(--gold-0); font-size: .85rem; font-weight: bold; }

/* ---------- Modals & overlays ---------- */

.overlay {
  position: fixed; inset: 0; z-index: 10;
  background: rgba(1, 11, 20, .78);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px;
}
.overlay h2 { font-size: 1.4rem; text-shadow: 0 3px 0 var(--abyss-0), 0 6px 16px rgba(0,0,0,.6); text-align: center; }

.modal {
  background: linear-gradient(180deg, var(--teal-0), var(--abyss-2));
  padding: 26px; border-radius: 16px; width: min(560px, 94vw);
  max-height: 92vh; overflow-y: auto; display: flex; flex-direction: column;
  gap: 13px; align-items: center;
  /* thick carved tablet border */
  box-shadow:
    inset 0 2px 0 rgba(255,255,255,.12),
    inset 0 -4px 0 rgba(0,0,0,.3),
    0 0 0 3px var(--abyss-0),
    0 0 0 5px var(--teal-1),
    0 0 0 7px rgba(1, 11, 20, .9),
    0 20px 44px rgba(0,0,0,.6);
}
.modal h2 { font-size: 1rem; }
.modal-wallet {
  font-size: 1.1rem; font-weight: bold; color: var(--gold-0);
  background: rgba(1,11,20,.55); padding: 6px 18px; border-radius: 999px;
  box-shadow: inset 0 2px 4px rgba(0,0,0,.5), inset 0 0 0 1px rgba(242,193,78,.3);
}

#upgrade-list { display: flex; flex-direction: column; gap: 10px; width: 100%; }
.upgrade-row {
  display: flex; align-items: center; gap: 12px;
  background: rgba(216,238,247,.07); padding: 11px 14px; border-radius: 11px;
  box-shadow: inset 0 0 0 1px rgba(216,238,247,.1), 0 3px 0 rgba(0,0,0,.3);
}
.upgrade-row .emoji { font-size: 1.7rem; filter: drop-shadow(0 2px 2px rgba(0,0,0,.4)); }
.upgrade-row .info { flex: 1; }
.upgrade-row .uname { font-weight: bold; }
.upgrade-row .udesc { font-size: .8rem; color: var(--foam-dim); }
.pips { display: flex; gap: 3px; margin-top: 4px; }
.pip { width: 22px; height: 6px; border-radius: 3px; background: rgba(216,238,247,.18); box-shadow: inset 0 1px 2px rgba(0,0,0,.4); }
.pip.on { background: linear-gradient(180deg, #ffd76e, var(--gold-0)); box-shadow: 0 0 5px rgba(242,193,78,.5); }

/* Uncapped upgrades: a level number, and a bar that fills toward the next
   block of ten rather than toward a ceiling that doesn't exist. */
.upgrade-row .ulevel {
  font-size: .75rem; color: var(--gold-0); font-weight: bold; margin-left: 6px;
}
.ubar {
  display: inline-block; vertical-align: middle; width: 110px; height: 6px;
  border-radius: 3px; background: rgba(216,238,247,.18); overflow: hidden;
  box-shadow: inset 0 1px 2px rgba(0,0,0,.4);
}
.ufill { display: block; height: 100%; background: linear-gradient(180deg, #ffd76e, var(--gold-0)); }
.unext { font-size: .72rem; color: var(--foam-faint); margin-left: 8px; }

/* Skill pool */
#skill-list { display: flex; flex-direction: column; gap: 9px; width: 100%; }
.skill-row {
  display: flex; align-items: center; gap: 12px;
  background: rgba(216,238,247,.07); padding: 11px 14px; border-radius: 11px;
  border: 2px solid rgba(216,238,247,.12);
  box-shadow: 0 3px 0 rgba(0,0,0,.3);
}
.skill-row.equipped {
  border-color: var(--kelp-0); background: rgba(111,206,122,.12);
  box-shadow: 0 3px 0 rgba(0,0,0,.3), 0 0 10px rgba(111,206,122,.25);
}
/* Not bought yet: dimmed, but the description stays readable so you can see
   what you'd be buying. */
.skill-row.locked .emoji { filter: grayscale(1); opacity: .6; }
.skill-row .emoji { font-size: 1.7rem; filter: drop-shadow(0 2px 2px rgba(0,0,0,.4)); }
.skill-row.locked .emoji { filter: grayscale(1) drop-shadow(0 2px 2px rgba(0,0,0,.4)); }
.skill-row .info { flex: 1; }
.skill-row .uname { font-weight: bold; }
.skill-row .udesc { font-size: .8rem; color: var(--foam-dim); }
.skill-row .umeta { font-size: .72rem; color: var(--foam-faint); margin-top: 2px; }
.skill-row button.equipped {
  color: #08300f; background: linear-gradient(180deg, #8ce096, var(--kelp-0));
  box-shadow: inset 0 2px 0 rgba(255,255,255,.4), 0 4px 0 #2a6b35, 0 7px 12px rgba(0,0,0,.35);
}
.modal-wallet .slots { margin-left: 14px; font-size: .8rem; color: var(--foam-dim); }

#leaderboard-list { display: flex; flex-direction: column; gap: 8px; width: 100%; }
.leader-row {
  display: flex; align-items: center; gap: 12px;
  background: rgba(216,238,247,.07); padding: 10px 14px; border-radius: 11px;
  box-shadow: inset 0 0 0 1px rgba(216,238,247,.1), 0 3px 0 rgba(0,0,0,.3);
}
.leader-row .rank { font-weight: bold; color: var(--gold-0); min-width: 28px; font-family: var(--pixel); font-size: .8rem; }
.leader-row .face { font-size: 1.5rem; }
.leader-row .face-img { width: 1.7rem; height: 1.7rem; }
.leader-row .lname { flex: 1; font-weight: bold; }
.leader-row .lstat { color: var(--foam-dim); font-size: .85rem; }

.toast {
  position: fixed; bottom: 28px; left: 50%; transform: translateX(-50%);
  background: linear-gradient(180deg, rgba(13,74,99,.97), rgba(3,40,63,.97));
  color: var(--gold-0);
  padding: 12px 22px; border-radius: 12px; font-weight: bold; z-index: 20;
  pointer-events: none;
  box-shadow:
    0 0 0 2px var(--abyss-0),
    0 0 0 4px rgba(242,193,78,.6),
    0 10px 22px rgba(0,0,0,.55);
}

/* ---------- Kingdom Wiki ---------- */
/* The wiki is a wider tablet than the other modals: it holds a whole
   bestiary. Everything below is additive and .wiki-scoped. */

.wiki-modal { width: min(880px, 96vw); align-items: stretch; }
.wiki-modal h2, .wiki-modal .modal-wallet, .wiki-modal .modal-actions { align-self: center; }
.wiki-tabs { flex-wrap: wrap; justify-content: center; align-self: center; }
#wiki-body { display: flex; flex-direction: column; gap: 14px; width: 100%; }
.wiki-intro { text-align: center; }

/* Card grid: roomy columns on a desktop, two across on a phone. */
.wiki-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px; width: 100%;
}
.wiki-card {
  position: relative;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 14px 12px; border-radius: 12px; text-align: center;
  background: linear-gradient(180deg, rgba(20,96,126,.55), rgba(3,40,63,.75));
  border: 3px solid var(--teal-1);
  box-shadow: inset 0 2px 0 rgba(255,255,255,.08), 0 4px 0 rgba(1,11,20,.8);
}
.wiki-card.clickable { cursor: pointer; transition: transform .08s, border-color .12s, background .12s; }
.wiki-card.clickable:hover { border-color: var(--teal-2); transform: translateY(-2px); }
.wiki-card.selected {
  border-color: var(--gold-0);
  background: linear-gradient(180deg, rgba(242,193,78,.22), rgba(3,40,63,.8));
  box-shadow: inset 0 2px 0 rgba(255,255,255,.12), 0 4px 0 var(--gold-2), 0 0 14px rgba(242,193,78,.35);
}

/* Corner ribbons: gold for the fish you're playing, coral for bosses. */
.wiki-badge {
  position: absolute; top: -10px; right: -8px;
  font-size: .62rem; font-weight: bold; letter-spacing: .04em;
  padding: 3px 9px; border-radius: 999px;
  color: var(--gold-ink);
  background: linear-gradient(180deg, #ffd76e, var(--gold-0));
  box-shadow: 0 2px 0 var(--gold-2), 0 4px 8px rgba(0,0,0,.4);
}
.wiki-badge.boss {
  color: #fff; text-shadow: 0 1px 1px rgba(0,0,0,.35);
  background: linear-gradient(180deg, #ff9678, var(--coral-0));
  box-shadow: 0 2px 0 var(--coral-2), 0 4px 8px rgba(0,0,0,.4);
}

/* Big sprites. The same class sizes the emoji fallback (font-size) and the
   pixel art (width/height), so either form fills the same box. */
.wiki-sprite, .wiki-face {
  width: 3.2rem; height: 3.2rem; object-fit: contain; display: block;
  font-size: 2.6rem; line-height: 3.2rem;
  image-rendering: pixelated;
  filter: drop-shadow(0 2px 2px rgba(0,0,0,.4));
}
/* Overrides the smaller menu face size without touching that rule. */
.wiki-face.face-img { width: 3.2rem; height: 3.2rem; }

.wiki-card-name { font-weight: bold; }
.wiki-card-desc { font-size: .78rem; color: var(--foam-dim); line-height: 1.35; }
.wiki-lv { font-size: .74rem; color: var(--foam-dim); line-height: 1.4; }

/* Mini stat bars on hero cards. */
.wiki-stats { width: 100%; display: flex; flex-direction: column; gap: 4px; margin-top: 2px; }
.wiki-stat { display: flex; align-items: center; gap: 6px; font-size: .68rem; color: var(--foam-dim); }
.wiki-stat .k { min-width: 28px; text-align: left; font-weight: bold; }
.wiki-stat .v { min-width: 30px; text-align: right; }
.wiki-meter {
  flex: 1; height: 6px; border-radius: 3px; overflow: hidden;
  background: rgba(216,238,247,.16);
  box-shadow: inset 0 1px 2px rgba(0,0,0,.4);
}
.wiki-meter i { display: block; height: 100%; background: linear-gradient(180deg, #ffd76e, var(--gold-0)); }

/* Behaviour/ability chips on enemy and tower cards. */
.wiki-tags { display: flex; flex-wrap: wrap; gap: 4px; justify-content: center; }
.wiki-tag {
  font-size: .66rem; padding: 3px 9px; border-radius: 999px;
  color: var(--foam); background: rgba(99,200,222,.14);
  box-shadow: inset 0 0 0 1px rgba(99,200,222,.3);
}

/* Detail page under the hero grid: a carved groove the upgrade shop sits in. */
.wiki-detail {
  width: 100%; display: flex; flex-direction: column; gap: 12px;
  padding: 16px; border-radius: 12px;
  background: rgba(1,11,20,.5);
  box-shadow: inset 0 3px 8px rgba(0,0,0,.55), inset 0 0 0 1px rgba(216,238,247,.12);
}
.wiki-detail-head { display: flex; align-items: center; gap: 14px; text-align: left; }
.wiki-detail-head .wiki-sprite, .wiki-detail-head .wiki-face,
.wiki-detail-head .wiki-face.face-img { width: 4rem; height: 4rem; font-size: 3.4rem; line-height: 4rem; }
.wiki-detail-meta { display: flex; flex-direction: column; gap: 3px; }
.wiki-detail-name { font-weight: bold; font-size: 1.05rem; }
.wiki-upgrades { display: flex; flex-direction: column; gap: 9px; }

.wiki-subhead {
  font-family: var(--pixel); font-size: .68rem; letter-spacing: .06em;
  color: var(--gold-0); text-align: left; margin-top: 2px;
}
.wiki-path { display: flex; flex-direction: column; gap: 3px; width: 100%; text-align: left; }
.wiki-skill-list { display: flex; flex-direction: column; gap: 9px; width: 100%; }

@media (max-width: 640px) {
  .wiki-modal { padding: 16px; }
  .wiki-grid { grid-template-columns: repeat(2, 1fr); gap: 9px; }
  .wiki-card { padding: 10px 8px; }
  .wiki-sprite, .wiki-face, .wiki-face.face-img { width: 2.6rem; height: 2.6rem; font-size: 2.1rem; line-height: 2.6rem; }
  .wiki-detail-head .wiki-sprite, .wiki-detail-head .wiki-face,
  .wiki-detail-head .wiki-face.face-img { width: 3.2rem; height: 3.2rem; font-size: 2.7rem; line-height: 3.2rem; }
}

/* Character select cards now wear the wiki hero-card look (wiki-card,
   wiki-face, wiki-stats). These rules only adapt the grid that holds them:
   roomier columns for the richer cards, and a lift on the picked fish so the
   gold frame reads as "raised above the rest". */
.character-grid {
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
}
#screen-character .wiki-card.selected {
  transform: translateY(-3px);
}

@media (max-width: 640px) {
  .character-grid { grid-template-columns: repeat(2, 1fr); gap: 9px; }
}

/* Solo mode: everything about friends, codes and accounts disappears.
   main.js puts .solo on <body> when the game runs without a server. */
body.solo .mp-only { display: none !important; }
body.solo #lobby-code { display: none; }
body.solo #hud-room { display: none; }
