/* SHADOW TYPE — The Lab. Drifting-word typing game. Self-contained, no CDN. */

@font-face {
  font-family: "Press Start 2P";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("/press-start-2p.woff2") format("woff2");
}
@font-face {
  font-family: "Press Start 2P Fallback";
  src: local("Courier New");
  size-adjust: 166.64%;
  ascent-override: 60%;
  descent-override: 0%;
  line-gap-override: 0%;
}

:root {
  --bg: #0a0a12;
  --surface: #12121d;
  --surface-2: #1a1a2a;
  --line: #28283c;
  --text: #e9e9f2;
  --dim: #9aa0b5;
  --cyan: #45f0ff;
  --magenta: #ff3d8b;
  --gold: #ffc857;
  --green: #41ff8b;
  --red: #ff5560;

  --pixel: "Press Start 2P", "Press Start 2P Fallback", "Courier New", monospace;
  --body: -apple-system, "Segoe UI", system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, monospace;

  --radius: 8px;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --dur-fast: 150ms;
  --dur-normal: 320ms;
  --glow-cyan: 0 0 14px rgba(69, 240, 255, 0.35);
  --gutter: clamp(14px, 4vw, 40px);
}

*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; }

html { color-scheme: dark; -webkit-text-size-adjust: 100%; }

body {
  min-height: 100svh;
  background:
    radial-gradient(1200px 540px at 50% -12%, rgba(69, 240, 255, 0.06), transparent 70%),
    radial-gradient(900px 460px at 82% 116%, rgba(255, 61, 139, 0.05), transparent 70%),
    var(--bg);
  color: var(--text);
  font-family: var(--body);
  font-size: clamp(15px, 0.94rem + 0.3vw, 17px);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  overflow: hidden; /* the field is the viewport */
}

a { color: var(--cyan); }
button { font: inherit; color: inherit; }

::selection { background: rgba(69, 240, 255, 0.3); }

:focus-visible {
  outline: 3px solid var(--cyan);
  outline-offset: 3px;
  box-shadow: 0 0 0 6px rgba(69, 240, 255, 0.2);
  border-radius: 2px;
}

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  margin: -1px; padding: 0; border: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

[hidden] { display: none !important; }

/* ---------- back-to-lab link ---------- */
.lab-link {
  position: fixed;
  left: 12px; top: 10px;
  z-index: 60;
  font-family: var(--pixel);
  font-size: 9px;
  letter-spacing: 0.06em;
  color: var(--dim);
  text-decoration: none;
  padding: 8px 6px;
  transition: color var(--dur-fast), text-shadow var(--dur-fast), transform var(--dur-fast) var(--ease-out);
}
.lab-link:hover,
.lab-link:focus-visible { color: var(--cyan); text-shadow: var(--glow-cyan); transform: translateX(-2px); }

/* ---------- the playfield ---------- */
.stage {
  position: fixed;
  inset: 0;
  overflow: hidden;
}

.field {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

/* a drifting word, absolutely positioned, transform-only motion */
.word {
  position: absolute;
  top: 0; left: 0;
  font-family: var(--pixel);
  font-size: var(--word-size, 16px);
  letter-spacing: 0.04em;
  white-space: nowrap;
  color: var(--dim);
  text-shadow: 0 0 10px rgba(154, 160, 181, 0.18);
  will-change: transform, opacity;
  transform-origin: center;
  user-select: none;
}

.word.is-targeted {
  text-shadow: 0 0 16px rgba(69, 240, 255, 0.45);
}

/* matched prefix highlight */
.word b {
  font-weight: 400;
  color: var(--green);
  text-shadow: 0 0 14px rgba(65, 255, 139, 0.6);
}

.word i {
  font-style: normal;
  color: var(--text);
}

.word.is-targeted i {
  color: var(--cyan);
}

/* the very next character to type */
.word u {
  text-decoration: none;
  color: var(--gold);
  text-shadow: 0 0 16px rgba(255, 200, 87, 0.7);
  border-bottom: 2px solid var(--gold);
}

@keyframes word-clear {
  0%   { transform: var(--clear-from); opacity: 0.9; }
  100% { transform: var(--clear-to); opacity: 0; }
}
.word.is-cleared {
  animation: word-clear 360ms var(--ease-out) forwards;
}

/* danger flash when a word nears the edge */
.word.is-danger {
  color: var(--red);
  text-shadow: 0 0 16px rgba(255, 85, 96, 0.6);
}

/* ---------- HUD ---------- */
.hud {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 40;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 8px clamp(10px, 3vw, 22px) 8px clamp(86px, 18vw, 150px);
  background: linear-gradient(180deg, rgba(10, 10, 18, 0.92), rgba(10, 10, 18, 0.55) 70%, transparent);
  font-family: var(--pixel);
  font-size: clamp(8px, 1.7vw, 11px);
  line-height: 1;
  pointer-events: none;
}

.hud__lives {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.heart {
  display: block;
  width: clamp(13px, 3vw, 18px);
  height: clamp(13px, 3vw, 18px);
  color: var(--red);
  filter: drop-shadow(0 0 6px rgba(255, 85, 96, 0.5));
  transition: opacity var(--dur-normal) var(--ease-out), transform var(--dur-normal) var(--ease-out);
}
.heart.is-lost { opacity: 0.16; transform: scale(0.7); filter: grayscale(1); }

.hud__stats {
  display: flex;
  align-items: baseline;
  gap: clamp(10px, 3vw, 26px);
}
.stat { display: inline-flex; align-items: baseline; gap: 0.5em; white-space: nowrap; }
.stat__label { color: var(--cyan); font-size: 0.82em; }
.stat__value { color: var(--text); font-variant-numeric: tabular-nums; }
.stat--combo .stat__value { color: var(--gold); text-shadow: 0 0 12px rgba(255, 200, 87, 0.4); }
.stat--combo.is-hot .stat__value { color: var(--magenta); text-shadow: 0 0 16px rgba(255, 61, 139, 0.6); }

.combo-pop {
  animation: combo-pop 280ms var(--ease-out);
}
@keyframes combo-pop {
  0% { transform: scale(1); }
  40% { transform: scale(1.45); }
  100% { transform: scale(1); }
}

/* ---------- typing line (mobile keyboard anchor) ---------- */
.input-dock {
  position: fixed;
  left: 50%;
  bottom: clamp(10px, 3vw, 22px);
  transform: translateX(-50%);
  z-index: 40;
  width: min(92vw, 460px);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: rgba(18, 18, 29, 0.86);
  border: 1px solid var(--line);
  border-top-color: rgba(69, 240, 255, 0.32);
  border-radius: var(--radius);
  box-shadow: 0 10px 34px rgba(0, 0, 0, 0.5), inset 0 0 0 1px rgba(255, 255, 255, 0.02);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.input-dock__prompt {
  font-family: var(--pixel);
  font-size: 11px;
  color: var(--cyan);
  text-shadow: var(--glow-cyan);
}
.input-dock__field {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: 0;
  color: var(--text);
  font-family: var(--mono);
  font-size: clamp(15px, 4vw, 18px);
  letter-spacing: 0.06em;
  caret-color: var(--cyan);
}
.input-dock__field::placeholder { color: var(--dim); opacity: 0.7; }
.input-dock__field:focus { outline: none; }
.input-dock.is-error { border-color: var(--red); animation: shake 220ms var(--ease-out); }
@keyframes shake {
  0%, 100% { transform: translateX(-50%); }
  25% { transform: translate(calc(-50% - 6px)); }
  75% { transform: translate(calc(-50% + 6px)); }
}

/* ---------- overlays (start / pause / game-over) ---------- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 64px var(--gutter) 40px;
  background: radial-gradient(ellipse 80% 60% at 50% 40%, rgba(10, 10, 18, 0.78), rgba(10, 10, 18, 0.94));
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  overflow-y: auto;
  animation: fade-in var(--dur-normal) var(--ease-out);
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.panel {
  width: min(100%, 540px);
  display: grid;
  justify-items: center;
  gap: clamp(16px, 3.4vw, 26px);
  text-align: center;
}

.panel__kicker {
  font-family: var(--pixel);
  font-size: clamp(8px, 1.8vw, 10px);
  letter-spacing: 0.22em;
  color: var(--magenta);
  text-shadow: 0 0 12px rgba(255, 61, 139, 0.4);
}

.title {
  position: relative;
  display: inline-block;
  font-family: var(--pixel);
  font-weight: 400;
  font-size: clamp(26px, 9vw, 58px);
  letter-spacing: 0.04em;
  line-height: 1.12;
  color: var(--text);
  text-shadow: 0 0 22px rgba(69, 240, 255, 0.45), 4px 4px 0 var(--magenta);
}
.title::before,
.title::after {
  content: attr(data-text);
  position: absolute;
  left: 0; top: 0;
  width: 100%;
  pointer-events: none;
}
.title::before { color: var(--cyan); text-shadow: 0 0 8px rgba(69, 240, 255, 0.6); animation: glitch-a 3.4s steps(2, end) infinite; }
.title::after { color: var(--magenta); text-shadow: 0 0 8px rgba(255, 61, 139, 0.6); animation: glitch-b 4s steps(2, end) infinite; }
@keyframes glitch-a {
  0%, 92%, 100% { clip-path: inset(0 0 100% 0); transform: translate(0, 0); }
  93% { clip-path: inset(0 0 55% 0); transform: translate(-2px, -1px); }
  96% { clip-path: inset(40% 0 20% 0); transform: translate(2px, 1px); }
}
@keyframes glitch-b {
  0%, 90%, 100% { clip-path: inset(100% 0 0 0); transform: translate(0, 0); }
  91% { clip-path: inset(60% 0 10% 0); transform: translate(2px, 1px); }
  95% { clip-path: inset(20% 0 50% 0); transform: translate(-2px, -1px); }
}

.panel__lede {
  max-width: 34rem;
  color: var(--dim);
  font-size: clamp(0.92rem, 0.86rem + 0.4vw, 1.08rem);
}
.panel__lede b { color: var(--gold); font-weight: 600; }
.panel__lede .k {
  font-family: var(--mono);
  color: var(--cyan);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0.05em 0.4em;
}

/* primary "press start" button */
.start-btn {
  font-family: var(--pixel);
  font-size: clamp(11px, 2.6vw, 14px);
  color: var(--bg);
  background: var(--cyan);
  border: 0;
  padding: 1rem 1.7rem;
  cursor: pointer;
  box-shadow: 0 0 0 3px var(--bg), 0 0 0 5px var(--cyan), 0 0 30px rgba(69, 240, 255, 0.45);
  transition: transform var(--dur-fast) var(--ease-out), box-shadow var(--dur-fast) var(--ease-out);
}
.start-btn:hover { transform: translateY(-3px); box-shadow: 0 0 0 3px var(--bg), 0 0 0 5px var(--cyan), 0 0 44px rgba(69, 240, 255, 0.66); }
.start-btn:active { transform: translateY(1px); }
.start-btn:focus-visible { outline: 3px solid var(--gold); outline-offset: 7px; }
.start-btn .cursor { display: inline-block; animation: blink 1.1s steps(2, jump-none) infinite; }
@keyframes blink { 50% { opacity: 0; } }

/* secondary / ghost button */
.ghost-btn {
  font-family: var(--pixel);
  font-size: clamp(9px, 2vw, 11px);
  color: var(--dim);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0.85rem 1.1rem;
  cursor: pointer;
  transition: color var(--dur-fast), border-color var(--dur-fast), transform var(--dur-fast) var(--ease-out), box-shadow var(--dur-fast);
}
.ghost-btn:hover,
.ghost-btn:focus-visible { color: var(--cyan); border-color: var(--cyan); transform: translateY(-2px); box-shadow: 0 0 14px rgba(69, 240, 255, 0.2); }

/* ---------- language toggle (segmented) ---------- */
.lang-toggle {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
  background: var(--surface);
}
.lang-toggle__btn {
  font-family: var(--pixel);
  font-size: 9px;
  letter-spacing: 0.08em;
  color: var(--dim);
  background: transparent;
  border: 0;
  padding: 0.7rem 1rem;
  min-height: 40px;
  cursor: pointer;
  transition: color var(--dur-fast), background-color var(--dur-fast);
}
.lang-toggle__btn + .lang-toggle__btn { border-left: 1px solid var(--line); }
.lang-toggle__btn:hover { color: var(--text); }
.lang-toggle__btn[aria-pressed="true"] {
  color: var(--bg);
  background: var(--cyan);
  text-shadow: none;
}

/* ---------- start/end layout helpers ---------- */
.panel__controls { display: grid; gap: 16px; justify-items: center; }
.panel__row { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; align-items: center; }

/* final stats grid (game over) */
.scoreboard {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  width: 100%;
  max-width: 420px;
}
.scoreboard__cell {
  display: grid;
  gap: 6px;
  padding: 14px 12px;
  background: linear-gradient(180deg, var(--surface-2), var(--surface) 70%);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.scoreboard__cell--wide { grid-column: 1 / -1; }
.scoreboard__cell--hero {
  grid-column: 1 / -1;
  border-color: rgba(255, 200, 87, 0.4);
  box-shadow: 0 0 24px rgba(255, 200, 87, 0.12);
}
.scoreboard__label {
  font-family: var(--pixel);
  font-size: 8px;
  letter-spacing: 0.12em;
  color: var(--cyan);
}
.scoreboard__cell--hero .scoreboard__label { color: var(--gold); }
.scoreboard__value {
  font-family: var(--pixel);
  font-size: clamp(15px, 4vw, 22px);
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.scoreboard__cell--hero .scoreboard__value {
  font-size: clamp(26px, 9vw, 44px);
  color: var(--gold);
  text-shadow: 0 0 18px rgba(255, 200, 87, 0.4);
}
.scoreboard__best { font-family: var(--mono); font-size: 0.78rem; color: var(--dim); }
.scoreboard__best b { color: var(--green); font-weight: 600; }

.go-banner {
  font-family: var(--pixel);
  font-size: clamp(20px, 7vw, 40px);
  color: var(--red);
  letter-spacing: 0.08em;
  text-shadow: 0 0 20px rgba(255, 85, 96, 0.5), 3px 3px 0 rgba(0, 0, 0, 0.6);
}

/* ---------- CRT / scanline texture ---------- */
.crt {
  position: fixed;
  inset: 0;
  z-index: 70;
  pointer-events: none;
}
.crt::before {
  content: "";
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(0deg, rgba(0, 0, 0, 0.16) 0 1px, transparent 1px 3px);
  opacity: 0.5;
}
.crt::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at center, transparent 58%, rgba(0, 0, 0, 0.42) 100%);
  box-shadow:
    inset 0 0 130px rgba(69, 240, 255, 0.05),
    inset 6px 0 30px rgba(255, 61, 139, 0.04),
    inset -6px 0 30px rgba(69, 240, 255, 0.05);
}

/* faint floating-particle wash behind words for depth */
.stage::before {
  content: "";
  position: absolute;
  inset: -10%;
  background-image:
    radial-gradient(2px 2px at 18% 30%, rgba(69, 240, 255, 0.16), transparent 60%),
    radial-gradient(2px 2px at 72% 64%, rgba(255, 61, 139, 0.12), transparent 60%),
    radial-gradient(1px 1px at 44% 82%, rgba(255, 200, 87, 0.14), transparent 60%),
    radial-gradient(1px 1px at 88% 18%, rgba(65, 255, 139, 0.12), transparent 60%);
  animation: drift-wash 26s ease-in-out infinite alternate;
  pointer-events: none;
}
@keyframes drift-wash {
  from { transform: translate3d(-1.5%, -1%, 0); }
  to   { transform: translate3d(1.5%, 1%, 0); }
}

/* ---------- responsive ---------- */
@media (max-width: 440px) {
  .hud { padding-left: clamp(64px, 22vw, 92px); }
  .stat__label { display: none; } /* keep numbers legible on tiny screens */
  .stat--combo .stat__label { display: inline; }
}
@media (max-width: 360px) {
  .hud__stats { gap: 9px; }
}
@media (min-height: 560px) and (max-width: 760px) {
  .input-dock { bottom: calc(env(safe-area-inset-bottom, 0px) + 12px); }
}

/* ---------- reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  .title::before,
  .title::after,
  .start-btn .cursor,
  .stage::before { animation: none !important; }
  .title::before, .title::after { opacity: 0 !important; }
  .start-btn:hover,
  .ghost-btn:hover,
  .lab-link:hover,
  .lab-link:focus-visible { transform: none; }
  .word.is-cleared { animation-duration: 1ms; }
  .combo-pop { animation: none; }
  .overlay { animation: none; }
}
