/* =====================================================================
   Typing Defender — fixed "neon terminal" theme.
   Like the other arcade canvas games (Space Invaders, Asteroids, Neon
   Dash), this page deliberately ignores the center's light/dark mode and
   its shared glass chrome (no glass.css, no mode bootstrap). Every colour
   is a hard copy of the game's own canvas palette: void-navy base, cyan
   grid, phosphor-green typed letters, amber highlights, crimson breach.
   The whole c-* chrome block lives here (it is NOT inherited).
   ===================================================================== */
:root {
  --tdf-void:   #060a14;   /* terminal black-navy base */
  --tdf-void2:  #0b1226;
  --tdf-panel:  #0e1830;
  --tdf-cyan:   #37e0ff;   /* grid / primary glow */
  --tdf-cyan2:  #1a9fd6;
  --tdf-green:  #4dffa0;   /* typed letters / success */
  --tdf-amber:  #ffd166;   /* highlight text / combo */
  --tdf-mag:    #ff4fd8;   /* accent */
  --tdf-red:    #ff5566;   /* breach / danger */
  --tdf-line:   rgba(55, 224, 255, .28);
  --tdf-text:   #dff6ff;
  --tdf-muted:  #7fb0c8;
}

html, body { height: 100%; }
body.tdf-page {
  margin: 0;
  height: 100vh;
  height: 100dvh;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  touch-action: manipulation;
  background:
    radial-gradient(120% 90% at 50% 0%, var(--tdf-void2) 0%, var(--tdf-void) 70%);
  color: var(--tdf-text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
body.tdf-page *,
body.tdf-page *::before,
body.tdf-page *::after { box-sizing: border-box; }

/* ---------- App frame ---------- */
.c-app {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* ---------- Top bar ---------- */
.c-bar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 10px 18px;
  flex-wrap: wrap;
  padding: 12px clamp(12px, 3vw, 28px);
  padding-top: max(12px, env(safe-area-inset-top));
  background: rgba(11, 18, 38, .62);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border-bottom: 2px solid var(--tdf-cyan2);
  z-index: 20;
}
.c-bar__brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.c-bar__brand svg { filter: drop-shadow(0 0 6px rgba(55, 224, 255, .5)); }
.c-bar__title {
  margin: 0;
  font-size: clamp(18px, 3.2vw, 25px);
  font-weight: 800;
  letter-spacing: .12em;
  text-transform: uppercase;
  white-space: nowrap;
  color: var(--tdf-cyan);
  text-shadow: 0 0 12px rgba(55, 224, 255, .6), 0 0 30px rgba(55, 224, 255, .3);
}
.c-bar__stats { display: flex; align-items: center; gap: 8px 18px; margin-left: auto; }
.c-bar__controls { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.stat { font-size: 14px; font-weight: 700; letter-spacing: .04em; white-space: nowrap; color: var(--tdf-muted); }
.stat b { color: var(--tdf-cyan); font-size: 16px; font-variant-numeric: tabular-nums; }

/* ---------- Buttons (neon outline chips) ---------- */
.c-btn {
  appearance: none;
  cursor: pointer;
  font: inherit;
  font-size: 14px;
  font-weight: 800;
  letter-spacing: .05em;
  text-transform: uppercase;
  text-decoration: none;
  display: inline-block;
  padding: 9px 16px;
  border-radius: 12px;
  border: 2px solid var(--tdf-line);
  background: rgba(14, 24, 48, .7);
  color: var(--tdf-text);
  box-shadow: 0 3px 0 rgba(3, 6, 12, .55);
  transition: transform .06s ease, background .15s ease, box-shadow .15s ease, border-color .15s ease;
}
.c-btn:hover { background: rgba(24, 44, 70, .9); border-color: var(--tdf-cyan2); }
.c-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(3, 6, 12, .55); }
.c-btn:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(55, 224, 255, .45); }
.c-btn--primary {
  background: linear-gradient(140deg, var(--tdf-cyan), var(--tdf-cyan2));
  border-color: rgba(55, 224, 255, .8);
  color: #04141c;
  text-shadow: none;
  box-shadow: 0 3px 0 rgba(3, 6, 12, .55), 0 0 18px rgba(55, 224, 255, .4);
}
.c-btn--primary:hover { background: linear-gradient(140deg, #7cf0ff, var(--tdf-cyan)); }

/* ---------- Table / stage ---------- */
.c-table {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(10px, 2.4vh, 22px);
}
.tdf-stage {
  position: relative;
  /* portrait play field capped by viewport height; aspect matches the
     canvas logical size (560 / 680) so the letterboxed canvas scales right. */
  width: min(94vw, calc((100vh - 150px) * 0.8235), 560px);
  aspect-ratio: 560 / 680;
  border-radius: 16px;
  overflow: hidden;
  background: radial-gradient(120% 120% at 50% 30%, #0a1428 0%, #04070f 80%);
  border: 2px solid var(--tdf-cyan2);
  box-shadow: 0 0 26px rgba(26, 159, 214, .35), inset 0 0 60px rgba(2, 5, 12, .85);
  touch-action: none;
}
#screen {
  display: block; width: 100%; height: 100%;
  touch-action: none;
}

/* ---------- On-screen keyboard (coarse pointers only) ---------- */
.tdf-kbd {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 4;
  display: flex; flex-direction: column; align-items: center; gap: 5px;
  padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
  background: linear-gradient(180deg, rgba(6, 10, 20, 0), rgba(6, 10, 20, .82) 30%);
  touch-action: manipulation;
}
.tdf-kbd[hidden] { display: none; }
.tdf-kbd__row { display: flex; gap: 4px; justify-content: center; }
.tdf-key {
  appearance: none;
  cursor: pointer;
  width: clamp(22px, 8.4vw, 40px);
  height: clamp(28px, 10.5vw, 44px);
  border-radius: 8px;
  border: 1.5px solid var(--tdf-line);
  background: rgba(14, 26, 48, .82);
  color: var(--tdf-text);
  font: 800 clamp(12px, 4vw, 17px)/1 ui-monospace, "Segoe UI", monospace;
  box-shadow: 0 2px 0 rgba(3, 6, 12, .6);
  touch-action: manipulation;
  -webkit-user-select: none; user-select: none;
}
.tdf-key:active { background: rgba(55, 224, 255, .3); border-color: var(--tdf-cyan); transform: translateY(1px); }
@media (hover: hover) and (pointer: fine) {
  /* desktop: physical keyboard rules — hide the on-screen one */
  .tdf-kbd { display: none; }
}

/* ---------- Ready / pause / game-over overlays ---------- */
.tdf-overlay {
  position: absolute; inset: 0; z-index: 5;
  display: flex; align-items: center; justify-content: center;
  padding: 18px;
  background: rgba(3, 6, 14, .66);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
  touch-action: manipulation;
}
.tdf-overlay[hidden] { display: none; }
.tdf-card {
  max-width: 300px;
  text-align: center;
  padding: 22px 24px 20px;
  border-radius: 16px;
  background: linear-gradient(160deg, var(--tdf-panel), #071022);
  border: 2px solid var(--tdf-cyan2);
  box-shadow: 0 0 30px rgba(26, 159, 214, .3), 0 22px 50px rgba(0, 0, 0, .6);
  color: var(--tdf-text);
  animation: tdfPop .3s ease;
  touch-action: manipulation;
}
@keyframes tdfPop { from { transform: scale(.88); opacity: 0; } }
.tdf-card__big { font-size: 40px; line-height: 1.1; }
.tdf-card__big svg { width: 84px; height: 84px; display: block; margin: 0 auto; filter: drop-shadow(0 0 8px rgba(55,224,255,.4)); }
.tdf-card__big svg[hidden] { display: none; }
.tdf-card h2 {
  margin: 6px 0;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--tdf-cyan);
  text-shadow: 0 0 12px rgba(55, 224, 255, .5);
}
.tdf-card p { margin: 0 0 14px; color: var(--tdf-muted); font-size: 13.5px; line-height: 1.55; }
.tdf-card p b { color: var(--tdf-amber); }
.tdf-card .c-btn { font-size: 14px; }
.tdf-card kbd, .c-modal kbd {
  display: inline-block;
  min-width: 18px;
  padding: 1px 6px;
  margin: 0 1px;
  font: 700 12px/1.5 ui-monospace, "Segoe UI", monospace;
  text-align: center;
  color: var(--tdf-cyan);
  background: rgba(55, 224, 255, .1);
  border: 1px solid var(--tdf-cyan2);
  border-radius: 6px;
  box-shadow: 0 2px 0 rgba(3, 6, 12, .5);
}
.c-win__actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

/* ---------- Rules modal ----------
   The full-screen overlay itself scrolls, never the card, so no scrollbar
   gutter ever sits inside the panel (see AGENTS.md). */
.c-modal {
  position: fixed; inset: 0; z-index: 50;
  display: flex; padding: 16px;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.c-modal[hidden] { display: none; }
.c-modal__backdrop {
  position: fixed; inset: 0;
  background: rgba(2, 4, 10, .68);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
}
.c-modal__panel {
  position: relative; z-index: 1;
  margin: auto;                    /* centres, and a too-tall card scrolls in from the top */
  width: min(92vw, 480px);
  background: linear-gradient(160deg, var(--tdf-panel), #06101f);
  color: var(--tdf-text);
  border-radius: 16px;
  border: 2px solid var(--tdf-cyan2);
  box-shadow: 0 0 30px rgba(26, 159, 214, .3), 0 24px 60px rgba(0, 0, 0, .65);
}
.c-modal__head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--tdf-line);
}
.c-modal__head h2 {
  margin: 0; font-size: 18px; font-weight: 800;
  text-transform: uppercase; letter-spacing: .08em;
  color: var(--tdf-cyan); text-shadow: 0 0 10px rgba(55, 224, 255, .5);
}
.c-modal__x {
  appearance: none; border: 0; background: none;
  color: var(--tdf-muted); font-size: 26px; line-height: 1;
  cursor: pointer; padding: 0 4px;
}
.c-modal__x:hover { color: var(--tdf-amber); }
.c-modal__body { padding: 8px 20px 4px; font-size: 14px; line-height: 1.55; }
.c-modal__body h3 {
  margin: 16px 0 6px; font-size: 13px;
  text-transform: uppercase; letter-spacing: .08em;
  color: var(--tdf-amber);
}
.c-modal__body ul { margin: 0; padding-left: 20px; }
.c-modal__body li { margin: 4px 0; }
.c-modal__body b { color: var(--tdf-amber); }
.c-modal__lead { margin: 12px 0; }
.c-modal__note {
  margin: 14px 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(77, 255, 160, .1);
  border: 1px solid var(--tdf-line);
  font-size: 13px;
  color: var(--tdf-muted);
}
.c-modal__foot { display: flex; justify-content: flex-end; padding: 12px 20px 16px; }
.c-modal .c-btn { border-color: var(--tdf-line); box-shadow: 0 3px 0 rgba(0, 0, 0, .4); }
.c-modal .c-btn--primary { border-color: rgba(55, 224, 255, .8); }

/* ---------- Responsive ---------- */
@media (max-width: 700px), (max-height: 620px) {
  .c-bar { gap: 5px 12px; padding: 7px clamp(10px, 3vw, 18px); padding-top: max(7px, env(safe-area-inset-top)); }
  .c-bar__brand { gap: 8px; }
  .c-bar__title { font-size: 16px; letter-spacing: .08em; }
  .c-bar__stats { gap: 4px 12px; margin-left: auto; }
  .stat { font-size: 12px; }
  .stat b { font-size: 13px; }
  .c-btn { padding: 8px 10px; font-size: 12px; }
  .c-bar__controls { gap: 6px; }
  .c-bar__controls .c-btn { padding: 9px 10px; white-space: nowrap; }
  .tdf-stage { width: min(96vw, calc((100vh - 120px) * 0.8235)); }
}
@media (max-width: 700px) {
  .c-bar__controls { flex: 1 1 100%; flex-wrap: nowrap; }
  .c-bar__controls .c-btn { flex: 1 1 auto; min-width: 0; padding: 9px 6px; overflow: hidden; text-overflow: ellipsis; }
}
@media (max-width: 380px) {
  .c-bar { gap: 5px 8px; }
  .c-bar__title { font-size: 15px; }
  .stat { font-size: 11px; }
  .stat b { font-size: 12px; }
  .c-bar__controls { gap: 4px; }
  .c-bar__controls .c-btn { font-size: clamp(10px, 3.2vw, 12px); padding: 9px 4px; letter-spacing: .01em; }
}

@media (prefers-reduced-motion: reduce) {
  .c-btn, .tdf-card { transition: none; animation: none; }
}
