/* Krabsy look for the tower defense: deep-navy panels, teal / coral / amber accents,
   Fredoka One for headings and buttons, Nunito for reading text.
   Layout: the canvas fills the window and every UI element floats on top of it
   (top HUD, bottom dock, overlays). */

/* Site fonts, self-hosted (copied from homepage/lib/fonts). */
@font-face {
  font-family: 'Fredoka One';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('../fonts/fredoka-one-400-latin.woff2') format('woff2');
}
@font-face {
  font-family: 'Nunito';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('../fonts/nunito-400-latin-ext.woff2') format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+1E00-1E9F, U+20A0-20C4;
}
@font-face {
  font-family: 'Nunito';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('../fonts/nunito-400-latin.woff2') format('woff2');
}

:root {
  --navy: #0d1b3a;
  --navy-2: #16294f;
  --navy-3: #22396a;
  --teal: #2ee6c0;
  --teal-deep: #17a98c;
  --coral: #ff8585;
  --coral-deep: #cc5c5c;
  --amber: #ffcf5e;
  --amber-deep: #c99a2c;
  --text: #ffffff;
  --text-soft: #b9c7e6;
  --panel: rgba(13, 27, 58, 0.93);
  --line: rgba(46, 230, 192, 0.45);
  --display: 'Fredoka One', 'Nunito', system-ui, sans-serif;
  --body: 'Nunito', system-ui, sans-serif;
  --ui: 1;              /* UI scale for big screens, set by main.js */
}

/* Everything the player reads or taps grows on big screens (the 3D canvas does not). */
#top-hud, #bottom-dock, #coach, #wave-banner, .overlay-panel, .menu-panel { zoom: var(--ui); }

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--navy);
  font-family: var(--body);
  color: var(--text);
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.hidden { display: none !important; }

#game-wrapper, #game-container, #canvas-frame {
  position: absolute;
  inset: 0;
}
#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: default;
  touch-action: none;
}
#game-container.placing #game-canvas { cursor: crosshair; }

/* ── Building blocks ─────────────────────────────────────── */

.panel {
  background: var(--panel);
  border: 2px solid var(--line);
  border-radius: 20px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

button { font-family: inherit; color: inherit; border: none; cursor: pointer; }

.btn {
  font-family: var(--display);
  font-size: 18px;
  line-height: 1.1;
  border-radius: 16px;
  padding: 12px 22px;
  transition: transform 0.08s ease, box-shadow 0.08s ease, filter 0.15s ease;
}
.btn:hover { transform: translateY(-2px); }
.btn:active { transform: translateY(2px); }
.btn-teal  { background: var(--teal);  color: var(--navy); box-shadow: 0 5px 0 var(--teal-deep); }
.btn-amber { background: var(--amber); color: var(--navy); box-shadow: 0 5px 0 var(--amber-deep); }
.btn-coral { background: var(--coral); color: var(--navy); box-shadow: 0 5px 0 var(--coral-deep); }
.btn-teal:active, .btn-amber:active, .btn-coral:active { box-shadow: 0 2px 0 rgba(0, 0, 0, 0.3); }
.btn-ghost {
  background: transparent;
  color: var(--text);
  border: 2px solid rgba(255, 255, 255, 0.35);
  padding: 10px 20px;
}
.btn-ghost:hover { border-color: var(--teal); color: var(--teal); }
.btn.disabled, .btn:disabled { filter: grayscale(0.8) brightness(0.7); cursor: not-allowed; transform: none; }

/* Verb form colours (house standard): base amber, 2nd form teal, 3rd form coral. */
.form-base { color: var(--amber); }
.form-past { color: var(--teal); }
.form-part { color: var(--coral); }

/* ── Coin ────────────────────────────────────────────────── */

.coin-icon, .coin-fly {
  display: inline-block;
  position: relative;
  font-size: 18px;
  width: 1em;
  height: 1em;
  border-radius: 50%;
  background: radial-gradient(circle at 32% 26%, #fff6bd 0%, #ffcf5e 40%, #e8ab1c 72%, #9a6e00 100%);
  box-shadow:
    inset 0 -0.14em 0.16em rgba(110, 70, 0, 0.55),
    inset 0 0.1em 0.12em rgba(255, 255, 220, 0.85),
    0 0.08em 0.14em rgba(0, 0, 0, 0.35);
  flex-shrink: 0;
}
.coin-icon::after, .coin-fly::after {
  content: "★";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.55em;
  color: #a87708;
}
.coin-icon.coin-icon-sm { font-size: 14px; }

/* ── Top HUD ─────────────────────────────────────────────── */

#top-hud {
  position: absolute;
  top: 12px;
  left: 12px;
  right: 12px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
  pointer-events: none;
  z-index: 5;
}
.hud-group { display: flex; align-items: center; gap: 8px; pointer-events: auto; }

.hud-chip, .round-btn {
  background: var(--panel);
  border: 2px solid var(--line);
  border-radius: 999px;
  font-family: var(--display);
  color: var(--text);
}
.hud-chip {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 7px 15px;
  font-size: 18px;
  white-space: nowrap;
}
.hud-coins { color: var(--amber); }
.hud-phase { color: var(--teal); }
.hud-coins.pop { animation: coin-pop 0.35s ease-out; }
@keyframes coin-pop {
  0% { transform: scale(1); }
  40% { transform: scale(1.18); }
  100% { transform: scale(1); }
}

.heart { font-size: 16px; line-height: 1; display: inline-block; }
.heart.filled { color: var(--coral); }
.heart.empty { color: rgba(255, 255, 255, 0.22); }
#lives-compact { display: none; color: var(--coral); }
.hud-lives.hurt { animation: hearts-hurt 0.45s ease-out; }
@keyframes hearts-hurt {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(3px); }
}

.round-btn {
  width: 40px;
  height: 40px;
  font-size: 17px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.1s ease, border-color 0.15s ease;
}
.round-btn:hover { transform: scale(1.08); border-color: var(--teal); }
#end-game-btn:hover { border-color: var(--coral); color: var(--coral); }

#wave-banner {
  position: absolute;
  top: 17%;
  left: 50%;
  transform: translateX(-50%);
  pointer-events: none;
  font-family: var(--display);
  font-size: 52px;
  color: #fff;
  text-shadow: 0 4px 0 rgba(13, 27, 58, 0.75), 0 0 24px rgba(13, 27, 58, 0.6);
  white-space: nowrap;
  opacity: 0;
  z-index: 6;
}
#wave-banner.boss { color: var(--coral); }
#wave-banner.show { animation: wave-banner 2s ease-out forwards; }
@keyframes wave-banner {
  0%   { opacity: 0; transform: translateX(-50%) scale(0.3) rotate(-4deg); }
  14%  { opacity: 1; transform: translateX(-50%) scale(1.15) rotate(1deg); }
  22%  { transform: translateX(-50%) scale(1); }
  75%  { opacity: 1; }
  100% { opacity: 0; transform: translateX(-50%) scale(1.04) translateY(-14px); }
}

#coach {
  position: absolute;
  top: 70px;
  left: 50%;
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100% - 24px);
  font-family: var(--display);
  font-size: 19px;
  line-height: 1.25;
  text-align: center;
  color: var(--navy);
  background: var(--amber);
  border-radius: 16px;
  padding: 9px 20px;
  box-shadow: 0 5px 0 var(--amber-deep), 0 10px 24px rgba(0, 0, 0, 0.3);
  pointer-events: none;
  z-index: 6;
  animation: coach-in 0.3s ease-out;
}
@keyframes coach-in {
  0% { opacity: 0; transform: translateX(-50%) translateY(-10px); }
  100% { opacity: 1; transform: translateX(-50%) translateY(0); }
}
.hint-pulse { animation: hint-pulse 1s ease-in-out infinite !important; }
#tower-buttons.hint-pulse { border-radius: 20px; }
#forge-panel.hint-pulse { animation: hint-pulse 1s ease-in-out infinite !important; }
@keyframes hint-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 207, 94, 0.9); }
  50% { box-shadow: 0 0 0 12px rgba(255, 207, 94, 0); }
}
#speed-btn { font-family: var(--display); font-size: 15px; }
#speed-btn.fast { background: var(--teal); color: var(--navy); border-color: var(--teal); }

.star { color: rgba(255, 255, 255, 0.2); }
.star.on { color: var(--amber); text-shadow: 0 0 10px rgba(255, 207, 94, 0.55); }
.stars-big { font-size: 54px; line-height: 1.1; letter-spacing: 6px; margin-top: 4px; }
.stars-big .star.on { animation: star-pop 0.5s ease-out backwards; }
.stars-big .star.on:nth-child(2) { animation-delay: 0.25s; }
.stars-big .star.on:nth-child(3) { animation-delay: 0.5s; }
@keyframes star-pop {
  0% { transform: scale(0) rotate(-40deg); opacity: 0; }
  70% { transform: scale(1.3) rotate(8deg); opacity: 1; }
  100% { transform: scale(1) rotate(0); }
}

/* ── Bottom dock ─────────────────────────────────────────── */

#bottom-dock {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  pointer-events: none;
  z-index: 5;
}
#bottom-dock > * { pointer-events: auto; }
#dock-row {
  display: flex;
  align-items: stretch;
  justify-content: center;
  gap: 10px;
  max-width: 100%;
  padding: 0 10px;
}
#tower-buttons { display: flex; gap: 8px; }

.tower-btn {
  position: relative;
  width: 76px;
  background: var(--panel);
  border: 2px solid var(--line);
  border-radius: 16px;
  padding: 5px 5px 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  transition: transform 0.1s ease, border-color 0.15s ease, filter 0.15s ease;
}
.tower-btn:hover { transform: translateY(-4px); border-color: var(--teal); }
.tower-btn.active {
  border-color: var(--amber);
  background: var(--navy-3);
  transform: translateY(-6px);
  box-shadow: 0 0 0 3px rgba(255, 207, 94, 0.3);
}
.tower-btn.build-here { border-color: var(--amber); animation: hint-pulse 1.2s ease-in-out infinite; }
.tower-btn.disabled { filter: grayscale(0.9) brightness(0.65); cursor: not-allowed; transform: none; }
.tower-thumb {
  width: 50px;
  height: 50px;
  border-radius: 12px;
  background: radial-gradient(circle at 50% 60%, var(--navy-3), var(--navy-2));
}
.tower-btn-name {
  font-family: var(--display);
  font-size: 12.5px;
  line-height: 1.1;
  text-align: center;
  min-height: 28px;
  display: flex;
  align-items: center;
}
/* Three tiny bars per card: damage, range, speed (1–5), plus a special icon. */
.tower-btn { -webkit-touch-callout: none; touch-action: manipulation; }
.tower-stats { position: relative; display: flex; flex-direction: column; gap: 2px; width: 100%; padding: 2px 4px 1px; }
.ts-row { display: flex; align-items: center; gap: 3px; height: 9px; }
.ts-icon { font-size: 8px; width: 11px; text-align: center; line-height: 1; filter: saturate(0.8); }
.ts-bar { display: flex; gap: 2px; flex: 1; }
.ts-bar i { flex: 1; height: 5px; border-radius: 2px; background: rgba(255, 255, 255, 0.14); }
.ts-bar i.on { background: var(--teal); }
.tower-btn.disabled .ts-bar i.on { background: rgba(255, 255, 255, 0.45); }
.ts-special { position: absolute; top: 2px; right: 1px; font-size: 14px; pointer-events: none; }

/* Compact dock: only the tower picture and the price. Hovering the dock with a mouse
   opens it (name and stat bars); touch players long-press a card instead. */
.tower-btn-name, .tower-btn .tower-stats { display: none; }
#bottom-dock.open .tower-btn-name { display: flex; }
#bottom-dock.open .tower-btn .tower-stats { display: flex; }
#tower-pop .tower-stats { width: 150px; align-self: center; margin-top: 4px; }
#tower-pop .ts-row { height: 12px; }
#tower-pop .ts-icon { font-size: 11px; width: 15px; }
#tower-pop .ts-bar i { height: 7px; }

/* Description popup above a hovered / long-pressed card. */
#tower-pop {
  position: absolute;
  transform: translate(-50%, -100%);
  width: max-content;
  max-width: 230px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  text-align: center;
  background: var(--panel);
  border: 2px solid var(--teal);
  border-radius: 14px;
  padding: 8px 12px;
  font-size: 13.5px;
  color: var(--text-soft);
  pointer-events: none;
  z-index: 7;
}
#tower-pop b { font-family: var(--display); font-weight: 400; font-size: 16px; color: var(--text); }

.tower-btn-cost {
  display: flex;
  align-items: center;
  gap: 4px;
  font-family: var(--display);
  font-size: 14px;
  color: var(--amber);
}
.tower-btn-hotkey {
  position: absolute;
  top: -8px;
  left: -8px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--teal);
  color: var(--navy);
  font-family: var(--display);
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}

#start-wave-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-width: 120px;
  padding: 8px 16px;
}
.dock-btn-label { font-size: 18px; white-space: nowrap; }
.dock-btn-sub { font-family: var(--body); font-size: 12px; opacity: 0.8; }
/* ── Tower info ──────────────────────────────────────────── */

#tower-info {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 16px;
  max-width: calc(100% - 20px);
}
.ti-thumb { width: 60px; height: 60px; border-radius: 12px; background: var(--navy-2); flex-shrink: 0; }
.ti-header { display: flex; flex-direction: column; gap: 3px; min-width: 190px; }
.ti-title { display: flex; align-items: center; gap: 8px; font-family: var(--display); font-size: 18px; }
.ti-level {
  font-size: 12px;
  background: var(--navy-3);
  color: var(--teal);
  border-radius: 999px;
  padding: 2px 9px;
}
.ti-desc { font-size: 13px; color: var(--text-soft); }
.ti-stats { display: flex; flex-wrap: wrap; gap: 3px 12px; font-size: 12.5px; color: var(--text-soft); }
.ti-stats b { color: var(--text); font-weight: 400; font-family: var(--display); }
.ti-stat-flag { color: var(--teal); }
.ti-actions { display: flex; gap: 8px; }
.ti-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-width: 118px;
  padding: 8px 12px;
  font-size: 15px;
}
.ti-btn-desc { font-family: var(--body); font-size: 11.5px; max-width: 130px; text-align: center; }
.ti-btn-cost { display: flex; align-items: center; gap: 4px; font-size: 14px; }
.ti-btn.maxed {
  font-family: var(--display);
  color: var(--text-soft);
  border: 2px dashed rgba(255, 255, 255, 0.25);
  border-radius: 16px;
}

/* ── Forge card (always visible) ─────────────────────────── */

/* Default: a strip above the dock (phones, portrait, narrow windows). */
#forge-panel {
  position: relative;
  width: min(600px, calc(100% - 16px));
  padding: 9px 12px 10px;
  border-color: var(--amber);
  overflow: hidden;
}
.forge-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.forge-title { font-family: var(--display); font-size: 17px; color: var(--amber); white-space: nowrap; }
.forge-ore { font-family: var(--display); font-size: 16px; white-space: nowrap; }
.forge-sub { font-size: 12.5px; color: var(--text-soft); min-height: 17px; margin-top: 1px; }
.forge-sub .streak { color: var(--coral); font-family: var(--display); }

.forge-question {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  flex-wrap: wrap;
  gap: 4px 6px;
  margin: 6px 0 8px;
  font-family: var(--display);
  font-size: 21px;
  line-height: 1.2;
  text-align: center;
  min-height: 52px;
}
.q-arrow { color: rgba(255, 255, 255, 0.4); padding-top: 3px; }
.q-slot { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.q-word {
  min-width: 58px;
  padding: 3px 9px;
  border-radius: 10px;
  border: 2px solid transparent;
}
.q-slot.blank .q-word { color: rgba(255, 255, 255, 0.3); border: 2px dashed rgba(255, 255, 255, 0.22); }
.q-slot.ask .q-word {
  color: var(--navy);
  background: var(--amber);
  box-shadow: 0 0 0 4px rgba(255, 207, 94, 0.28);
  animation: ask-pulse 1.3s ease-in-out infinite;
}
@keyframes ask-pulse {
  0%, 100% { box-shadow: 0 0 0 4px rgba(255, 207, 94, 0.28); }
  50% { box-shadow: 0 0 0 8px rgba(255, 207, 94, 0.12); }
}
.q-slot.shown .q-word { background: rgba(255, 255, 255, 0.08); }
/* Grammar terms: small print, only after the answer. */
.q-caption { font-family: var(--body); font-size: 10px; color: var(--text-soft); min-height: 12px; white-space: nowrap; }
.q-sentence { font-size: 19px; font-family: var(--display); }
.q-gap {
  display: inline-block;
  min-width: 52px;
  padding: 0 8px;
  border-radius: 9px;
  background: var(--amber);
  color: var(--navy);
}
.q-empty { font-family: var(--body); font-size: 15px; color: var(--text-soft); align-self: center; }

.forge-answers { display: flex; gap: 8px; justify-content: center; }
.forge-answer {
  position: relative;
  flex: 1 1 0;
  min-width: 0;
  padding: 11px 6px;
  border-radius: 14px;
  background: var(--navy-3);
  border: 2px solid rgba(255, 255, 255, 0.2);
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.35);
  font-family: var(--display);
  font-size: 19px;
  overflow-wrap: anywhere;
  transition: transform 0.08s ease, border-color 0.15s ease;
}
.forge-answer:hover:not(.locked) { transform: translateY(-2px); border-color: var(--teal); }
.forge-answer:active:not(.locked) { transform: translateY(2px); }
.forge-answer .key {
  position: absolute;
  top: 3px;
  left: 7px;
  font-size: 10px;
  color: var(--text-soft);
  display: none;
}
.forge-answer.locked { cursor: default; opacity: 0.45; }
.forge-answer.correct { opacity: 1; background: var(--teal); border-color: var(--teal); color: var(--navy); }
.forge-answer.wrong { opacity: 1; background: var(--coral); border-color: var(--coral); color: var(--navy); }
.forge-answer.correct .key, .forge-answer.wrong .key { color: rgba(13, 27, 58, 0.6); }
/* "+5" rising out of the right answer, in step with the coins flying off it. */
.gain-pop {
  position: absolute;
  right: 12px;
  top: 50%;
  font-family: var(--display);
  font-size: 22px;
  color: var(--amber);
  text-shadow: 0 2px 0 var(--navy), 0 0 10px rgba(13, 27, 58, 0.8);
  pointer-events: none;
  animation: gain-pop 0.9s ease-out forwards;
}
@keyframes gain-pop {
  0% { opacity: 0; transform: translateY(-50%) scale(0.5); }
  25% { opacity: 1; transform: translateY(-80%) scale(1.25); }
  100% { opacity: 0; transform: translateY(-190%) scale(1); }
}

.forge-feedback {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 24px;
  margin-top: 6px;
  font-family: var(--display);
  font-size: 15px;
}
.forge-feedback.ok { color: var(--teal); }
.forge-feedback.bad { color: var(--coral); }
.forge-feedback.bad { flex-wrap: wrap; }
.forge-teach { flex-basis: 100%; text-align: center; font-family: var(--body, inherit); margin-top: 2px; font-size: 13px; font-weight: 600; line-height: 1.35; color: rgba(255,255,255,.82); }
/* Shrinking bar: how long the card stays locked after a wrong answer. */
.forge-lock { height: 4px; border-radius: 2px; background: rgba(255, 255, 255, 0.08); margin-top: 4px; overflow: hidden; }
#forge-lock-bar { height: 100%; width: 0; background: var(--coral); border-radius: 2px; }

/* Wide landscape screens: the card sits in the bottom-left corner, wide and short
   (chain side by side, answers in a row). The map uses the whole screen behind it;
   the levels keep that corner free (js/level.js cornerFree) and the camera moves the
   map only if a road or building spot would still be covered (renderer._frameCamera).
   The tower dock sits to the right of the card. */
@media (min-width: 760px) and (orientation: landscape) {
  #forge-panel { position: fixed; left: 12px; bottom: 12px; width: 390px; padding: 9px 12px 9px; }
  #bottom-dock { left: 410px; bottom: 12px; }
  .forge-answer .key { display: block; top: 3px; left: 7px; font-size: 10px; }
}
/* Short landscape windows (phone sideways, small iframe): a smaller card. */
@media (min-width: 760px) and (orientation: landscape) and (max-height: 520px) {
  #forge-panel { width: 316px; padding: 7px 9px 7px; left: 8px; bottom: 8px; }
  #bottom-dock { left: 332px; bottom: 8px; }
  #coach { font-size: 15px; padding: 6px 12px; top: 60px; }
  .forge-sub { display: none; }
  .forge-question { font-size: 17px; margin: 3px 0 5px; min-height: 42px; }
  .q-word { min-width: 44px; padding: 2px 7px; }
  .forge-answer { padding: 7px 6px; font-size: 17px; }
  .forge-feedback { min-height: 18px; margin-top: 3px; font-size: 13px; }
}

#forge-panel.shake { animation: panel-shake 0.45s ease-out; }
@keyframes panel-shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-9px); }
  40% { transform: translateX(8px); }
  60% { transform: translateX(-5px); }
  80% { transform: translateX(3px); }
}
#forge-panel.celebrate { animation: panel-celebrate 0.45s ease-out; }
@keyframes panel-celebrate {
  0% { transform: scale(1); }
  40% { transform: scale(1.035); }
  100% { transform: scale(1); }
}
.confetti {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 10px;
  height: 10px;
  border-radius: 3px;
  pointer-events: none;
  animation: confetti-fly 0.9s ease-out forwards;
}
@keyframes confetti-fly {
  0%   { opacity: 1; transform: translate(0, 0) rotate(0deg) scale(1); }
  100% { opacity: 0; transform: translate(var(--dx), calc(var(--dy) + 120px)) rotate(var(--rot)) scale(0.5); }
}

/* ── Overlays ────────────────────────────────────────────── */

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(8, 16, 36, 0.62);
  z-index: 20;
  padding: 16px;
}
.overlay-light { background: rgba(8, 16, 36, 0.25); cursor: pointer; }
.overlay-panel {
  text-align: center;
  padding: 26px 34px 28px;
  max-width: 520px;
  width: 100%;
  max-height: 100%;
  overflow-y: auto;
}
.overlay-light .overlay-panel { width: auto; }
.overlay-title { font-family: var(--display); font-size: 36px; line-height: 1.15; }
.overlay-title.small { font-size: 26px; }
.overlay-title.coral { color: var(--coral); }
.overlay-title.amber { color: var(--amber); }
.overlay-subtitle {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 18px;
  color: var(--text-soft);
  margin-top: 8px;
}
.overlay-light .overlay-subtitle { font-family: var(--display); font-size: 24px; color: var(--amber); }
.overlay-best { font-family: var(--display); font-size: 16px; color: var(--amber); margin-top: 6px; }
.overlay-hint { font-size: 13px; color: var(--text-soft); margin-top: 12px; }
.overlay-actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; margin-top: 22px; }

.recap { margin-top: 16px; text-align: center; }
.recap-score { font-size: 15px; color: var(--text-soft); }
.recap-title { font-family: var(--display); font-size: 16px; margin-top: 12px; color: var(--teal); }
.recap-list { display: flex; flex-direction: column; gap: 5px; margin-top: 8px; }
.recap-line {
  font-family: var(--display);
  font-size: 17px;
  background: rgba(255, 255, 255, 0.07);
  border-radius: 10px;
  padding: 5px 12px;
}
.recap-arrow { color: rgba(255, 255, 255, 0.4); }
.recap-perfect { font-family: var(--display); font-size: 18px; color: var(--amber); margin-top: 10px; }

/* ── Start menu ──────────────────────────────────────────── */

.menu-fullscreen {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at 50% 30%, rgba(34, 57, 106, 0.72), rgba(13, 27, 58, 0.93));
  z-index: 30;
  padding: 16px;
  overflow-y: auto;
}
.menu-panel { text-align: center; max-width: 720px; width: 100%; margin: auto; }
.menu-title {
  font-family: var(--display);
  font-size: clamp(40px, 8vw, 68px);
  line-height: 1.05;
  color: var(--teal);
  text-shadow: 0 5px 0 rgba(0, 0, 0, 0.3);
}
.menu-subtitle { font-size: 18px; color: var(--text); margin-top: 10px; }
.menu-chain { font-family: var(--display); font-size: 22px; margin-top: 10px; color: rgba(255, 255, 255, 0.45); }
.menu-hint { font-size: 12.5px; color: var(--text-soft); margin-top: 22px; }

#loading-note { font-size: 18px; color: var(--text-soft); padding: 28px 0; }
#menu-start { display: flex; flex-direction: column; align-items: center; margin-top: 22px; }
.menu-play { min-width: 220px; font-size: 1.25rem; }
.menu-topics { margin-top: 4px; }
/* Level screen (kit levels()): our map pictures are wide, so let them fill the tile. */
.kg-levels .kg-ltile.has-pic { padding-top: 26px; }
.kg-levels .kg-ltile-pic img { width: 88%; border-radius: 6px; }
.kg-levels .lv-training { margin-top: 14px; width: 100%; }


/* ── Danger, defeat, victory: readable without text ────────── */

#danger-vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 4;
  opacity: 0;
  transition: opacity 0.6s ease;
  background: radial-gradient(ellipse at center, rgba(255, 70, 70, 0) 55%, rgba(255, 70, 70, 0.32) 85%, rgba(200, 20, 20, 0.55) 100%);
}
#danger-vignette.on { animation: danger-breathe 1.2s ease-in-out infinite; }
@keyframes danger-breathe {
  0%, 100% { opacity: 0.35; }
  50% { opacity: 0.85; }
}
#danger-vignette.defeat {
  animation: none;
  opacity: 1;
  transition: opacity 1.5s ease;
  background: radial-gradient(ellipse at center, rgba(13, 27, 58, 0.15) 30%, rgba(13, 27, 58, 0.75) 100%);
}
.hud-lives.danger { border-color: var(--coral); animation: hearts-pulse 0.6s ease-in-out infinite alternate; }
@keyframes hearts-pulse {
  from { box-shadow: 0 0 0 0 rgba(255, 133, 133, 0.0); transform: scale(1); }
  to { box-shadow: 0 0 18px 4px rgba(255, 133, 133, 0.6); transform: scale(1.06); }
}
#game-canvas.defeated { filter: grayscale(0.75) brightness(0.8); transition: filter 1.6s ease; }
#game-canvas { transition: filter 0.4s ease; }

/* A heart flies from the castle to the HUD and breaks there. */
.heart-fly {
  position: absolute;
  top: 0; left: 0;
  font-size: 34px;
  color: var(--coral);
  text-shadow: 0 2px 0 rgba(13, 27, 58, 0.7);
  pointer-events: none;
  z-index: 9;
  will-change: transform, opacity;
}

.end-icon { font-size: 64px; line-height: 1; margin-bottom: 6px; }
.end-icon.broken { animation: end-icon-in 0.6s cubic-bezier(.2, 1.6, .5, 1) backwards; }
@keyframes end-icon-in {
  from { transform: scale(0.2) rotate(-20deg); opacity: 0; }
  to { transform: scale(1) rotate(0); opacity: 1; }
}
.wave-dots { display: flex; justify-content: center; gap: 6px; margin: 10px 0 2px; flex-wrap: wrap; }
.wdot { width: 14px; height: 14px; border-radius: 50%; background: rgba(255, 255, 255, 0.15); }
.wdot.done { background: var(--teal); }
.wdot.lost { background: var(--coral); box-shadow: 0 0 0 3px rgba(255, 133, 133, 0.35); }

/* Stars slam in one by one (sound in ui.js). */
.stars-big { font-size: 64px; }
.stars-big .star.on { animation: star-slam 0.45s cubic-bezier(.2, 1.8, .45, 1) backwards; }
.stars-big .star.on:nth-child(1) { animation-delay: 0.35s; }
.stars-big .star.on:nth-child(2) { animation-delay: 0.68s; }
.stars-big .star.on:nth-child(3) { animation-delay: 1.01s; }
@keyframes star-slam {
  0% { transform: scale(3) rotate(-30deg); opacity: 0; }
  60% { transform: scale(0.85) rotate(4deg); opacity: 1; }
  100% { transform: scale(1) rotate(0); opacity: 1; }
}

/* Not enough coins: the tower card shakes. */
.tower-btn.nope { animation: card-nope 0.35s ease-out; }
@keyframes card-nope {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-7px); border-color: var(--coral); }
  45% { transform: translateX(6px); border-color: var(--coral); }
  70% { transform: translateX(-4px); }
}

@media (prefers-reduced-motion: reduce) {
  #danger-vignette.on, .hud-lives.danger { animation: none; }
  #danger-vignette.on { opacity: 0.6; }
}

body.game-inactive #top-hud,
body.game-inactive #bottom-dock { display: none; }

/* ── DOM effect layers (flying coins, life-lost flash) ───── */

#fx-dom-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 8;
}
.coin-fly {
  position: absolute;
  top: 0; left: 0;
  font-size: 24px;
  margin: -12px 0 0 -12px;
  will-change: transform;
}
#screen-flash {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  z-index: 7;
  background: radial-gradient(ellipse at center,
    rgba(255, 60, 60, 0) 35%,
    rgba(255, 60, 60, 0.5) 70%,
    rgba(200, 0, 0, 0.9) 100%);
}

/* ── Smaller screens ─────────────────────────────────────── */

/* Tablets and small laptops. */
@media (max-width: 1100px) {
  .tower-thumb { width: 46px; height: 46px; }
  .tower-btn { width: 72px; }
  #start-wave-btn { min-width: 104px; padding: 8px 12px; }
  .dock-btn-label { font-size: 17px; }
  .hotkey { display: none; }
}

/* Short windows (a game iframe on a laptop): keep panels compact. */
@media (max-height: 640px) {
  .tower-btn-name { display: none; }
}

/* Phones. */
@media (max-width: 640px) {
  #top-hud { top: 8px; left: 8px; right: 8px; gap: 5px; }
  .hud-group { gap: 5px; }
  .hud-chip { font-size: 15px; padding: 6px 10px; }
  .hud-center { display: none; }
  #lives-container { display: none; }
  #lives-compact { display: inline; }
  .round-btn { width: 34px; height: 34px; font-size: 14px; }
  #wave-banner { font-size: 34px; }
  #coach { top: 54px; font-size: 16px; padding: 7px 14px; }
  .stars-big { font-size: 42px; }

  #bottom-dock { bottom: 8px; gap: 8px; }
  #dock-row { gap: 6px; width: 100%; padding: 0 8px; }
  #tower-buttons { gap: 5px; }
  .tower-btn, #bottom-dock.open .tower-btn { width: 56px; padding: 4px 3px 5px; }
  .tower-thumb, #bottom-dock.open .tower-thumb { width: 40px; height: 40px; }
  .tower-btn-cost { font-size: 13px; gap: 2px; }
  #bottom-dock.open .tower-btn-name, #bottom-dock.open .tower-btn .tower-stats { display: none; }
  .tower-btn-hotkey { display: none; }
  #start-wave-btn { flex: 1; min-width: 0; padding: 8px 6px; }
  .dock-btn-label { font-size: 15px; white-space: normal; text-align: center; line-height: 1.1; }
  .forge-sub { display: none; }
  #forge-panel { padding: 7px 10px 8px; }
  .forge-question { margin: 4px 0 6px; }
  .forge-answer { padding: 9px 6px; }
  .forge-feedback { min-height: 20px; margin-top: 4px; font-size: 14px; }

  #tower-info { flex-wrap: wrap; justify-content: center; gap: 8px; padding: 10px; }
  .ti-thumb { display: none; }
  .ti-header { min-width: 0; align-items: center; text-align: center; }

  .overlay-panel { padding: 20px 16px 22px; }
  .overlay-title { font-size: 28px; }
  .menu-hint { display: none; }
}

/* The question card fades in with a glow (level 1: when the money first runs out). */
#forge-panel.reveal { animation: forge-reveal 0.9s ease-out; }
@keyframes forge-reveal {
  0% { opacity: 0; transform: translateY(12px); }
  60% { opacity: 1; transform: translateY(-3px); }
  100% { opacity: 1; transform: none; }
}
/* Tutorial: the upgrade button in the tower panel pulses. */
#tower-info.hint-upgrade [data-action="upgrade"] { animation: hint-pulse 1s ease-in-out infinite; }

/* Archer first: other cards carry a padlock until an archer stands. */
.tower-lock { display: none; position: absolute; top: 4px; left: 50%; transform: translateX(-50%); pointer-events: none; filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.6)); }
.tower-btn.locked .tower-lock { display: block; }
.tower-btn.locked .tower-thumb { opacity: 0.45; }
#tower-pop .pop-lock { color: var(--amber); font-family: var(--display); margin-top: 2px; }
.tower-btn.locked.disabled { filter: none; }
.tower-btn.locked .tower-btn-cost { opacity: 0.5; }

/* Training: its menu card stands out; buttons the coach is not asking for are dimmed. */
#start-wave-btn.gated { opacity: 0.4; filter: grayscale(0.6); cursor: not-allowed; }

/* A new tower arrives: intro card at the start of its level. */
.intro-panel { max-width: 340px; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.intro-kicker { font-family: var(--display); color: var(--amber); font-size: 18px; letter-spacing: 0.5px; }
.intro-thumb { width: 120px; height: 120px; border-radius: 22px; background: radial-gradient(circle at 50% 60%, var(--navy-3), var(--navy-2)); }
.intro-desc { color: var(--text-soft); font-size: 16px; }
#intro-stats .tower-stats { width: 170px; margin: 4px auto 2px; }
#intro-stats .ts-row { height: 13px; }
#intro-stats .ts-icon { font-size: 12px; width: 17px; }
#intro-stats .ts-bar i { height: 8px; }
#intro-stats .ts-special { display: none; }
/* NEW tag on the level's new tower card until it has been built once. */
.tower-new { display: none; position: absolute; bottom: -9px; left: 50%; transform: translateX(-50%); background: var(--amber); color: var(--navy); font-family: var(--display); font-size: 11px; line-height: 1; padding: 3px 7px; border-radius: 999px; white-space: nowrap; pointer-events: none; }
.tower-btn.is-new .tower-new { display: block; }
#forge-panel.invisible { visibility: hidden; }

/* Training: big bouncing arrow at the next thing to press. Anchored at its tip. */
#tut-arrow { position: fixed; z-index: 30; pointer-events: none; display: none; transform: translate(-50%, -100%) scale(var(--s, 1)); transform-origin: 50% 100%; filter: drop-shadow(0 3px 4px rgba(0, 0, 0, 0.45)); }
#tut-arrow.on { display: block; }
#tut-arrow.left { transform: translate(-50%, -100%) rotate(90deg) scale(var(--s, 1)); }
#tut-arrow.right { transform: translate(-50%, -100%) rotate(-90deg) scale(var(--s, 1)); }
#tut-arrow .tut-arrow-bob { animation: tut-bob 0.8s ease-in-out infinite; }
#tut-arrow svg { display: block; }
@keyframes tut-bob {
  0%, 100% { transform: translateY(-10px); }
  50% { transform: translateY(0); }
}
@media (prefers-reduced-motion: reduce) { #tut-arrow .tut-arrow-bob { animation: none; } }
/* Corner card: a fixed height, so a longer answer never re-fits the camera. */
@media (min-width: 760px) and (orientation: landscape) {
  #forge-panel { height: 232px; }
}
@media (min-width: 760px) and (orientation: landscape) and (max-height: 520px) {
  #forge-panel { height: 172px; }
}
.forge-answer.long { font-size: 16px; }
.forge-answer.xlong { font-size: 13.5px; }
.forge-answer.long, .forge-answer.xlong { overflow-wrap: normal; word-break: normal; }
/* Phones (card above the dock): a steady height, so the map never jumps. */
/* Phones (card above the dock): slim and a steady height, so the map never jumps
   (owner 2026-12-01: no title row, the questions-left count in the corner). */
@media (max-width: 640px) {
  #forge-panel { min-height: 0; height: 148px; padding: 6px 8px 6px; }
  #forge-panel.has-teach .forge-answers { display: none; }
  #forge-panel .forge-head { position: absolute; top: 6px; right: 9px; }
  #forge-panel .forge-title { display: none; }
  #forge-panel .forge-question { margin: 1px 30px 6px; min-height: 0; font-size: 18px; }
  #forge-panel .q-caption { min-height: 0; }
  #forge-panel .forge-answer { padding: 8px 6px; }
  #forge-panel .forge-feedback { min-height: 0; margin-top: 4px; font-size: 13.5px; line-height: 1.2; }
}
/* Empty card: only a label at its bottom edge, the box itself see-through. */
#forge-panel.empty { background: none !important; border-color: transparent !important; box-shadow: none !important; pointer-events: none; overflow: visible; }
#forge-panel.empty > :not(.forge-question) { display: none !important; }
#forge-panel.empty .forge-question { position: absolute; left: 0; bottom: 0; margin: 0; min-height: 0; justify-content: flex-start; }
#forge-panel.empty .q-empty {
  display: inline-flex; align-items: center; gap: 6px; max-width: 100%;
  font-family: var(--font-body, Nunito, sans-serif); font-weight: 800; font-size: 14px; line-height: 1.2; text-align: left;
  color: var(--k-ink); background: var(--k-surface, #fff); border: 3px solid var(--k-ink); border-radius: 999px;
  box-shadow: 0 4px 0 var(--k-ink); padding: 6px 14px 6px 10px; pointer-events: auto;
}
#forge-panel.empty .q-empty b { font-family: var(--font-display); font-weight: 400; font-size: 17px; }
@media (max-width: 640px) {
  #forge-panel.empty .forge-question { left: 50%; transform: translateX(-50%); width: max-content; max-width: 100%; bottom: 2px; }
}
@media (min-width: 760px) and (orientation: landscape) and (max-height: 520px) {
  .forge-answer.long { font-size: 14px; padding-left: 3px; padding-right: 3px; }
  .forge-answer.xlong { font-size: 12px; padding-left: 3px; padding-right: 3px; }
}

/* "Did you like it?" row on the end screens (mountRating, global tracking rule):
   its inline text colour is for light pages; here it sits on the navy panel. */

/* ══ Game UI kit look (owner, 2026-11-29; docs/game-ui-kit.md) ═════════════════════════
   The kit stylesheet (/lib/game-ui/krabsy-game-ui.css) is loaded before this file. This
   block moves the game's own pieces to the kit look: colours only from the tokens, white
   "sticker" cards with a navy outline and a solid bottom edge, right = turquoise, wrong
   and highlight = violet, no animated shadows. Sizes and layout stay the game's own
   ("layout free"). Gold coins are world material and keep their gold. */

:root {
  --navy: var(--k-ink);
  --navy-2: var(--k-ink-4);
  --navy-3: var(--k-main-8);
  --teal: var(--k-acc);
  --teal-deep: var(--k-acc-dk);
  --coral: var(--k-main);
  --coral-deep: var(--k-main-lo);
  --amber: var(--k-main);
  --amber-deep: var(--k-main-lo);
  --text: var(--k-ink);
  --text-soft: var(--k-ink-72);
  --panel: var(--k-surface);
  --line: var(--k-ink);
  --display: var(--font-display);
  --body: var(--font-body);
}

.panel {
  background: var(--k-surface);
  color: var(--k-ink);
  border: var(--kg-line, 3px) solid var(--k-ink);
  border-radius: var(--radius-lg, 22px);
  box-shadow: 0 6px 0 var(--k-ink);
}

/* Old button classes still used inside the tower panel: kit primary / secondary. */
.btn-teal, .btn-amber, .btn-coral { background: var(--k-btn-bg); color: #fff; border: 3px solid var(--k-ink); box-shadow: 0 5px 0 var(--k-ink); }
.btn-ghost { background: var(--k-surface); color: var(--k-ink); border: 3px solid var(--k-ink); box-shadow: 0 5px 0 var(--k-ink); }
.btn-ghost:hover { background: var(--k-acc-16); color: var(--k-ink); border-color: var(--k-ink); }
.btn-teal:active, .btn-amber:active, .btn-coral:active, .btn-ghost:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--k-ink); }

/* Verb forms: base navy, 2nd form violet, 3rd form turquoise shade. */
.form-base { color: var(--k-ink); }
.form-past { color: var(--k-main-lo); }
.form-part { color: var(--k-acc-dk); }

/* Coin: plain gold disc with a rim (no symbol character). */
.coin-icon::after, .coin-fly::after { content: ""; inset: 18%; border-radius: 50%; border: 0.07em solid rgba(150, 105, 0, 0.55); }

/* Top bar: kit pills and icon buttons. */
#top-hud { align-items: flex-start; }
.hud-group { align-items: flex-start; }
.hud-coins, .hud-lives { gap: 6px; }
.hud-lives .kg-ico { width: 22px; height: 22px; }
.hud-wave { gap: 8px; padding: 0 16px 0 12px; }
.hud-phase { display: inline-flex; }
.hud-phase .kg-ico { width: 24px; height: 24px; }
#speed-btn { font-family: var(--font-display); font-size: 17px; }
#speed-btn.fast { background: var(--k-acc); color: var(--k-ink); border-color: var(--k-ink); }
.hud-lives.danger { background: var(--k-main); color: #fff; border-color: var(--k-ink); animation: kg-danger 0.7s ease-in-out infinite alternate; }
.hud-lives.danger .kg-ico { background: #fff; border-radius: 50%; }
@keyframes kg-danger { from { transform: scale(1); } to { transform: scale(1.07); } }
.hud-coins.pop { animation: kg-bump 0.35s ease-out; }

/* Coach line and hint pulses: violet, a scale pulse instead of an animated shadow. */
#coach { color: #fff; background: var(--k-main); border: 3px solid var(--k-ink); box-shadow: 0 5px 0 var(--k-ink); }
.hint-pulse, #forge-panel.hint-pulse, .tower-btn.build-here, #tower-info.hint-upgrade [data-action="upgrade"] { outline: 3px solid var(--k-main); outline-offset: 3px; }
@keyframes hint-pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.05); } }
#wave-banner { color: #fff; text-shadow: 0 4px 0 var(--k-ink); }
#wave-banner.boss { color: var(--k-main-45); }

/* Tower dock. */
.tower-btn { border: 3px solid var(--k-ink); box-shadow: 0 5px 0 var(--k-ink); background: var(--k-surface); color: var(--k-ink); }
.tower-btn:hover { border-color: var(--k-ink); background: var(--k-acc-16); }
.tower-btn.active { border-color: var(--k-ink); background: var(--k-main-15); box-shadow: 0 5px 0 var(--k-ink); }
.tower-thumb { background: radial-gradient(circle at 50% 60%, var(--k-main-8), var(--k-main-15)); }
.tower-btn-cost { color: var(--k-ink); }
.tower-btn-hotkey { background: var(--k-ink); color: #fff; }
.ts-icon { width: 13px; }
.ts-icon .kg-ico { width: 12px; height: 12px; }
.ts-bar i { background: var(--k-ink-8); }
.ts-bar i.on { background: var(--k-acc); }
.tower-btn.disabled .ts-bar i.on { background: var(--k-ink-45); }
.ts-special .kg-ico { width: 18px; height: 18px; }
.tower-new { background: var(--k-main); color: #fff; }
#tower-pop { border: 3px solid var(--k-ink); box-shadow: 0 5px 0 var(--k-ink); color: var(--k-ink-72); }
#tower-pop b { color: var(--k-ink); }
#tower-pop .pop-lock { color: var(--k-main-lo); }
#tower-pop .ts-icon .kg-ico { width: 14px; height: 14px; }

/* Tower panel. */
.ti-thumb { background: var(--k-main-8); }
.ti-level { background: var(--k-main-15); color: var(--k-main-lo); }
.ti-stat-flag { color: var(--k-main-lo); }
.ti-btn.maxed { color: var(--k-ink-72); border-color: var(--k-ink-22); }

/* Question card (kit piece 4): card, blanks and answer chips. */
#forge-panel { border-color: var(--k-ink); }
.forge-title { color: var(--k-ink); }
.forge-ore { display: inline-flex; align-items: center; gap: 4px; color: var(--k-ink); }
.forge-sub .streak { color: var(--k-main-lo); display: inline-flex; align-items: center; gap: 3px; }
.q-arrow { display: inline-flex; align-items: center; color: var(--k-ink-45); }
.q-arrow .kg-ico { width: 0.8em; height: 0.8em; opacity: 0.55; }
.q-slot.blank .q-word { color: transparent; background: var(--k-ink-4); border: none; border-bottom: 4px solid var(--k-ink-22); }
.q-slot.ask .q-word { color: var(--k-main-lo); background: var(--k-main-15); box-shadow: none; border: none; border-bottom: 4px solid var(--k-main); animation: kg-ask 1.3s ease-in-out infinite; }
@keyframes kg-ask { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.06); } }
.q-slot.shown .q-word { background: var(--k-ink-4); }
.q-gap { background: var(--k-main-15); color: var(--k-main-lo); border-bottom: 4px solid var(--k-main); }
.forge-answer { background: var(--k-surface); color: var(--k-ink); border: 3px solid var(--k-ink); box-shadow: 0 5px 0 var(--k-ink); }
.forge-answer:hover:not(.locked) { border-color: var(--k-ink); background: var(--k-main-8); }
.forge-answer:active:not(.locked) { box-shadow: 0 1px 0 var(--k-ink); }
.forge-answer .key { color: var(--k-ink-72); }
.forge-answer.locked { opacity: 0.4; }
.forge-answer.correct { background: var(--k-acc); border-color: var(--k-ink); color: var(--k-ink); box-shadow: 0 5px 0 var(--k-ink); }
.forge-answer.wrong { background: var(--k-main-15); border-color: var(--k-main); color: var(--k-main-lo); box-shadow: 0 5px 0 var(--k-main); }
.forge-answer.correct .key, .forge-answer.wrong .key { color: var(--k-ink-72); }
.gain-pop { color: var(--k-main-lo); text-shadow: 0 2px 0 #fff; }
.forge-feedback.ok { color: var(--k-acc-dk); }
.forge-feedback.bad { color: var(--k-main-lo); }
.forge-teach { color: var(--k-ink-72); }
.forge-lock { background: var(--k-ink-8); }
#forge-lock-bar { background: var(--k-main); }

/* Full screens: navy scrim, white card. */
.overlay { background: transparent; }
.overlay::before { content: ""; position: absolute; inset: 0; background: var(--k-ink); opacity: var(--kg-scrim, 0.66); }
.overlay-light::before { opacity: 0.25; }
.overlay > * { position: relative; }
.overlay-title.coral, .overlay-title.amber { color: var(--k-ink); }
.overlay-light .overlay-subtitle, .overlay-best { color: var(--k-main-lo); }
.end-shells { justify-content: center; margin: 6px 0 2px; }
.end-icon .kg-ico { width: 64px; height: 64px; }
.end-icon.broken .kg-ico { opacity: 0.4; }
.wdot { background: var(--k-ink-8); border: 2px solid var(--k-ink-22); }
.wdot.done { background: var(--k-acc); border-color: var(--k-ink); }
.wdot.lost { background: var(--k-main); border-color: var(--k-ink); box-shadow: none; }
.star { color: inherit; text-shadow: none; display: inline-flex; }
.star .kg-ico { width: 1em; height: 1em; }
.stars-big .star .kg-ico { width: 54px; height: 54px; }
.recap-title { color: var(--k-ink-72); font-family: var(--font-body); font-weight: 800; font-size: 14px; }
.recap-line { background: var(--k-main-8); }
.recap-arrow { color: var(--k-ink-45); display: inline-flex; vertical-align: middle; }
.recap-perfect { color: var(--k-main-lo); }
.kg-menu-state { margin-left: auto; }
#quit-overlay .kg-menu { margin-top: 14px; }
.intro-kicker { color: var(--k-main-lo); }
.intro-thumb { background: radial-gradient(circle at 50% 60%, var(--k-main-8), var(--k-main-15)); }

/* Start menu: one white card on the navy scrim. */
.menu-fullscreen { background: var(--k-ink); }
.menu-panel { background: var(--k-surface); color: var(--k-ink); border: 3px solid var(--k-ink); border-radius: var(--radius-lg, 22px); box-shadow: 0 6px 0 var(--k-ink); padding: 22px 18px 20px; }
.menu-title { color: var(--k-ink); text-shadow: none; }
.menu-subtitle { color: var(--k-ink); }
.menu-chain { color: var(--k-ink-45); display: flex; align-items: center; justify-content: center; gap: 6px; }

/* Low lives and defeat: violet edge (never red), navy on defeat. */
#danger-vignette { background: radial-gradient(ellipse at center, rgba(107, 92, 231, 0) 55%, rgba(107, 92, 231, 0.3) 85%, rgba(75, 64, 162, 0.55) 100%); }
#danger-vignette.defeat { background: radial-gradient(ellipse at center, rgba(29, 35, 80, 0.15) 30%, rgba(29, 35, 80, 0.75) 100%); }
.heart-fly .kg-ico { width: 34px; height: 34px; }
.heart-fly { text-shadow: none; }

/* Phones: smaller kit pieces in the top bar (five things must fit 390 px). */
@media (max-width: 640px) {
  #top-hud .kg-pill, #top-hud .kg-progress, #top-hud .kg-iconbtn { height: 40px; font-size: 15px; }
  #top-hud .kg-iconbtn { width: 44px; height: 44px; }
  #top-hud .kg-pill { padding: 0 10px 0 8px; }
  .hud-wave { padding: 0 10px 0 8px; }
  .hud-center { display: flex; }
}
/* Narrow phones (360 px): the wave shows as icon + "3 / 9", tighter gaps, so menu, coins,
   lives, wave, whole-map and speed still fit with nothing cut off. */
@media (max-width: 400px) {
  #top-hud, .hud-group { gap: 4px; }
  #top-hud .kg-pill, #top-hud .kg-progress, #top-hud .kg-iconbtn { height: 38px; font-size: 14px; }
  #top-hud .kg-iconbtn { width: 44px; height: 44px; }
  #top-hud .kg-pill { padding: 0 8px 0 6px; }
  .hud-wave { padding: 0 8px 0 6px; gap: 5px; }
  .hud-wave-word { display: none; }
}
#loading-note { display: flex; flex-direction: column; align-items: center; gap: 4px; color: var(--k-ink-72); }
#loading-note .kg-bar { width: min(280px, 80%); margin-top: 6px; }

/* ── End screens: everything on screen (owner, 2026-11-30) ─────────────────────────
   Short content (3 practice words at most, numbers in two small boxes, new best only
   when beaten), buttons side by side and pinned to the bottom of the card if it ever
   has to scroll. Low and wide frames (phone sideways): the two blocks side by side. */
.end-panel { max-width: 460px; padding: 18px 18px 12px; }
.end-panel .end-icon { margin-bottom: 2px; }
.end-panel .end-icon .kg-ico { width: 52px; height: 52px; }
.end-panel .overlay-title { font-size: 30px; }
.end-panel .stars-big { margin-top: 2px; line-height: 1; }
.end-panel .stars-big .star .kg-ico { width: 46px; height: 46px; }
.end-panel .wave-dots { margin-top: 8px; }
.end-panel .end-shells { margin: 4px 0 0; }
.end-stats { margin-top: 10px; }
.end-best { margin-top: 8px; display: flex; justify-content: center; }
.end-best.hidden { display: none; }
.end-panel .recap { margin-top: 10px; }
.end-panel .recap-title { margin-top: 0; }
.end-panel .recap-list { margin-top: 6px; gap: 4px; }
.end-panel .recap-line { font-size: 16px; padding: 4px 10px; }
.end-panel .recap-perfect { margin-top: 4px; }
.end-panel .kg-rate { margin-top: 10px; }
.end-actions {
  position: sticky; bottom: -12px; z-index: 1;
  margin: 12px -18px -12px; padding: 10px 18px 12px;
  background: var(--k-surface);
  border-radius: 0 0 var(--radius-lg, 22px) var(--radius-lg, 22px);
}
.end-actions > .kg-btn { flex: 1 1 120px; }
.end-actions > .end-next { flex-basis: 100%; }
.end-actions > .end-next.hidden { display: none; }

@media (max-width: 640px) {
  .end-panel { padding: 14px 14px 10px; }
  .end-panel .end-icon .kg-ico { width: 42px; height: 42px; }
  .end-panel .overlay-title { font-size: 26px; }
  .end-panel .stars-big .star .kg-ico { width: 40px; height: 40px; }
  .end-actions { margin: 10px -14px -10px; padding: 8px 14px 10px; bottom: -10px; }
  .end-actions > .kg-btn { min-height: 48px; font-size: 1rem; padding-left: 10px; padding-right: 10px; }
}

@media (orientation: landscape) and (max-height: 520px) {
  .end-panel { max-width: 780px; display: grid; grid-template-columns: 0.8fr 1.2fr; gap: 6px 18px; align-items: center; padding: 12px 16px 10px; }
  .end-panel .end-icon .kg-ico { width: 38px; height: 38px; }
  .end-panel .overlay-title { font-size: 24px; }
  .end-panel .stars-big .star .kg-ico { width: 34px; height: 34px; }
  .end-stats { margin-top: 0; }
  .end-panel .recap { margin-top: 6px; }
  .end-panel .recap-line { font-size: 14px; padding: 2px 8px; }
  .end-panel .kg-rate { margin-top: 6px; }
  .end-actions { position: static; margin: 8px 0 0; padding: 0; background: none; }
  .end-actions > .kg-btn { min-height: 44px; font-size: 0.95rem; margin-bottom: 5px; }
}
/* Rating faces on the white end card: the question in navy (it was white for the old navy panel). */
@media (orientation: landscape) and (max-height: 520px) {
  .end-actions > .end-next { flex-basis: 0; flex-grow: 1.4; }
  .end-stats .kg-stat { padding: 3px 6px; }
  .end-stats .kg-stat-v { font-size: 1.2rem; }
  .end-panel .recap-title { font-size: 12px; }
}

/* Loading (owner 2026-11-30): the kit's loading screen covers the start; the start card stays
   hidden until the game is ready (no bare title splash). */
#menu-overlay.booting .menu-panel, #menu-overlay:not(.booting) #boot-load { display: none; }
#boot-load { margin: auto; }

/* No touch gesture may scroll the wrapper page around the game frame (owner 2026-11-30: on a
   phone the frame slid under the site bar). Nothing pans by default; only panels that really
   scroll allow a vertical swipe, and never hand it on to the page. */
html, body { overscroll-behavior: none; touch-action: none; }
.overlay-panel, .menu-fullscreen, .kg-screen, .kg-start-side, .kg-start-wrap {
  touch-action: pan-y; overscroll-behavior: contain;
}

/* Phone review 2026-11-30. Wide hint targets at the screen edge (start button, question
   card): the ring sits inside and blinks instead of growing, so the frame edge never cuts it. */
#start-wave-btn.hint-pulse, #forge-panel.hint-pulse {
  outline-offset: -5px; animation: hint-ring 1s ease-in-out infinite !important;
}
@keyframes hint-ring { 0%, 100% { outline-color: var(--k-main); } 50% { outline-color: transparent; } }
@media (prefers-reduced-motion: reduce) { #start-wave-btn.hint-pulse, #forge-panel.hint-pulse { animation: none !important; } }
/* Coins and hearts in flight stay under the pause screen. */
body.paused #fx-dom-layer { visibility: hidden; }
.forge-right-word { font-family: var(--font-display); color: var(--k-ink); margin-left: 4px; }
.menu-panel { position: relative; }
.menu-sound { position: absolute; top: 12px; right: 12px; }
/* Touch phones: no keyboard / mouse hints. */
@media (pointer: coarse) { .menu-hint { display: none; } }
/* Short landscape (phone sideways): the start card fits without scrolling. */
@media (orientation: landscape) and (max-height: 480px) {
  .menu-panel { padding: 12px 14px 14px; }
  .menu-title { font-size: 40px; }
  .menu-subtitle { font-size: 15px; }
  .menu-chain { margin: 4px 0 0; font-size: 20px; }
  #menu-start { margin-top: 10px; }
  .menu-topics .kg-label { margin: 6px 0 4px; }
}

.end-actions .kg-btn { white-space: nowrap; }
@media (pointer: coarse) { .forge-answer .key, .tower-btn-hotkey { display: none; } }

/* Upright phone (owner 2026-12-01): the board is turned (road top to bottom) and the top bar
   becomes a narrow column on the left, so the spawn at the top stays visible. The camera
   keeps the road, the spawn and the castles clear of the column (renderer _frameCamera). */
body.hud-side #top-hud { flex-direction: column; right: auto; bottom: auto; align-items: flex-start; gap: 6px; }
body.hud-side .hud-group { flex-direction: column; align-items: flex-start; gap: 6px; }
body.hud-side .hud-center { display: flex; }
body.hud-side #top-hud .kg-pill, body.hud-side #top-hud .kg-progress { height: 36px; font-size: 14px; padding: 0 8px 0 6px; }
body.hud-side .hud-wave-word { display: none; }
body.hud-side .hud-wave { gap: 4px; }
