/* THAW — The Lab level chrome plus a phase-change puzzle board.
   Retro-arcade dark, with an ice/steam palette on top of the Lab tokens. */

@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%; }

/* ---------- tokens ---------- */

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

  --ice: #a8e0ff;
  --ice-hi: #d6efff;
  --water: #2cc4e8;
  --water-deep: #1583b5;
  --steam: #c9cfdf;
  --heat: #ff7043;
  --heater: #ff5722;

  --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);
  --glow-cyan: 0 0 14px rgba(69, 240, 255, 0.35);
  --space-gutter: clamp(16px, 4vw, 48px);
}

/* ---------- base ---------- */

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

html { color-scheme: dark; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(1100px 480px at 50% -10%, rgba(168, 224, 255, 0.07), transparent 70%),
    radial-gradient(800px 380px at 90% 110%, rgba(255, 112, 67, 0.05), transparent 70%),
    var(--bg);
  color: var(--text);
  font-family: var(--body);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

::selection { background: rgba(168, 224, 255, 0.3); }
[hidden] { display: none !important; }

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

.skip-link {
  position: absolute;
  left: 12px; top: -48px;
  z-index: 200;
  background: var(--cyan);
  color: #05050d;
  padding: 10px 16px;
  border-radius: 6px;
  font-family: var(--mono);
  font-weight: 700;
  text-decoration: none;
  transition: transform 0.2s var(--ease-out);
}
.skip-link:focus-visible { transform: translateY(60px); }

:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
  box-shadow: 0 0 0 5px rgba(69, 240, 255, 0.15);
}

a { color: var(--cyan); }

kbd {
  font-family: var(--mono);
  font-size: 0.8em;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 1px 5px;
  color: var(--text);
}

/* ---------- header ---------- */

.site-header {
  padding: 26px var(--space-gutter) 10px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.lab-link {
  align-self: flex-start;
  font-family: var(--pixel);
  font-size: 10px;
  color: var(--dim);
  text-decoration: none;
  padding: 6px 2px;
  transition: color 0.15s, text-shadow 0.15s;
}
.lab-link:hover { color: var(--cyan); text-shadow: var(--glow-cyan); }

.level {
  margin: 0;
  font-family: var(--pixel);
  font-size: 9px;
  letter-spacing: 3px;
  color: var(--gold);
}

.wordmark {
  margin: 6px 0 4px;
  font-family: var(--pixel);
  font-size: clamp(26px, 5vw, 40px);
  letter-spacing: 6px;
  color: var(--ice-hi);
  text-shadow: 0 0 18px rgba(168, 224, 255, 0.6), 3px 3px 0 var(--magenta);
}

.tagline {
  margin: 0;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--dim);
}

.cursor { color: var(--ice); animation: blink 1.1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }

/* ---------- layout ---------- */

main {
  flex: 1;
  width: 100%;
  max-width: 1160px;
  margin: 0 auto;
  padding: 16px var(--space-gutter) 72px;
}

.play-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 24px;
  align-items: start;
}

.game-panel { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.side { display: flex; flex-direction: column; gap: 16px; min-width: 0; }

/* ---------- topbar ---------- */

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
}

.level-title { min-width: 0; flex: 1 1 260px; }
.level-of { margin: 0; font-family: var(--pixel); font-size: 8px; letter-spacing: 2px; color: var(--gold); }
.level-name {
  margin: 8px 0 6px;
  font-family: var(--pixel);
  font-size: clamp(13px, 2.4vw, 17px);
  letter-spacing: 2px;
  color: var(--ice-hi);
  text-shadow: 0 0 10px rgba(168, 224, 255, 0.35);
}
.level-hint { margin: 0; font-size: 13px; color: var(--dim); }

.action-row { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---------- buttons ---------- */

.btn {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 14px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  font-family: var(--mono);
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: 0.5px;
  cursor: pointer;
  transition: transform 0.12s var(--ease-out), border-color 0.12s, box-shadow 0.12s, color 0.12s;
}
.btn:hover { border-color: var(--cyan); box-shadow: 0 0 12px rgba(69, 240, 255, 0.22); transform: translateY(-1px); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; box-shadow: none; }
.btn-primary { background: var(--cyan); border-color: var(--cyan); color: #05050d; }
.btn-primary:hover { box-shadow: 0 0 18px rgba(69, 240, 255, 0.5); }
.btn-ghost { background: transparent; }
.btn-big { font-family: var(--pixel); font-size: 10px; padding: 14px 18px; }

/* ---------- HUD ---------- */

.hud { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; }
.hud > div {
  min-width: 0;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.hud span { display: block; margin-bottom: 6px; font-family: var(--pixel); font-size: 8px; letter-spacing: 1px; color: var(--dim); }
.hud strong { display: block; font-family: var(--mono); font-size: 1.15rem; color: var(--gold); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hud .pips { letter-spacing: 2px; }
.hud .pips-heat { color: var(--heat); }
.hud .pips-cold { color: var(--cyan); }
.hud .phase-out { font-family: var(--pixel); font-size: 10px; line-height: 1.9; }
.phase-out[data-phase="ice"] { color: var(--ice-hi); }
.phase-out[data-phase="water"] { color: var(--water); }
.phase-out[data-phase="steam"] { color: var(--steam); }

/* ---------- stage ---------- */

.stage { display: flex; flex-direction: column; gap: 12px; }

/* The board and the result overlay share one grid cell, so the cell grows
   to fit the overlay on short boards (phones) instead of spilling over the HUD. */
.canvas-wrap {
  position: relative;
  display: grid;
  padding: 8px;
  background: linear-gradient(180deg, var(--surface), rgba(18, 18, 29, 0.5));
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: inset 0 0 40px rgba(168, 224, 255, 0.04), 0 0 28px rgba(69, 240, 255, 0.05);
}

#board {
  grid-area: 1 / 1;
  align-self: start;
  display: block;
  width: 100%;
  aspect-ratio: 10 / 6;
  background: #07070e;
  border-radius: 6px;
  touch-action: manipulation;
  cursor: pointer;
}

/* ---------- overlay ---------- */

.overlay {
  grid-area: 1 / 1;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 16px;
  text-align: center;
  border-radius: 6px;
  background: rgba(10, 10, 18, 0.86);
  backdrop-filter: blur(2px);
  animation: overlay-in 0.25s var(--ease-out) both;
}
@keyframes overlay-in { from { opacity: 0; transform: scale(0.98); } }

.overlay-title {
  margin: 0;
  font-family: var(--pixel);
  font-size: clamp(16px, 4.5vw, 26px);
  letter-spacing: 3px;
  color: var(--green);
  text-shadow: 0 0 16px rgba(65, 255, 139, 0.55), 2px 2px 0 var(--magenta);
}
.overlay[data-kind="lost"] .overlay-title { color: var(--red); text-shadow: 0 0 16px rgba(255, 85, 96, 0.55), 2px 2px 0 var(--magenta); }
.overlay-sub { margin: 0; font-family: var(--mono); font-size: 12px; letter-spacing: 1px; color: var(--dim); }
.overlay-stars { margin: 0; font-size: 26px; letter-spacing: 6px; color: var(--gold); text-shadow: 0 0 12px rgba(255, 200, 87, 0.45); }
.overlay-stats { margin: 0; font-family: var(--mono); font-size: 13px; color: var(--text); }
.final-badge { margin: 0; font-family: var(--pixel); font-size: 9px; letter-spacing: 1px; color: var(--gold); }
.overlay-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 4px; }

/* ---------- pad + tools ---------- */

.pad {
  display: grid;
  grid-template-columns: 64px 1fr 1fr 64px;
  gap: 8px;
}

.pad-btn, .tool-btn {
  min-height: 56px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  font-family: var(--pixel);
  font-size: 11px;
  letter-spacing: 1px;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.1s var(--ease-out), border-color 0.12s, box-shadow 0.12s, background 0.12s;
}
.pad-btn { color: var(--cyan); font-size: 16px; }
.pad-btn:hover, .tool-btn:hover { border-color: var(--cyan); box-shadow: 0 0 12px rgba(69, 240, 255, 0.22); }
.pad-btn:active, .tool-btn:active { transform: scale(0.96); }
.tool-btn:disabled { opacity: 0.4; cursor: not-allowed; box-shadow: none; }
.tool-heat { color: var(--heat); }
.tool-cold { color: var(--cyan); }
.tool-heat[aria-pressed="true"] {
  border-color: var(--heat);
  background: rgba(255, 112, 67, 0.14);
  box-shadow: 0 0 0 2px rgba(255, 112, 67, 0.25), 0 0 18px rgba(255, 112, 67, 0.35);
}
.tool-cold[aria-pressed="true"] {
  border-color: var(--cyan);
  background: rgba(69, 240, 255, 0.12);
  box-shadow: 0 0 0 2px rgba(69, 240, 255, 0.25), 0 0 18px rgba(69, 240, 255, 0.35);
}

/* Aim panel: hint text, a CANCEL button while armed and, on touch screens,
   a 3x3 aim pad with 48px targets (board tiles can be under 24px). */
.aim-panel {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px 12px;
}
.aim-line { flex: 1 1 220px; margin: 0; min-height: 20px; font-family: var(--mono); font-size: 12px; color: var(--dim); text-align: center; }
.aim-line[data-tool="heat"] { color: var(--heat); }
.aim-line[data-tool="cold"] { color: var(--cyan); }
.aim-cancel[hidden] { display: none; }

.aim-pad { display: none; }
.aim-btn {
  width: 48px;
  height: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--aim, var(--cyan));
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.1s var(--ease-out), border-color 0.12s, box-shadow 0.12s;
}
.aim-pad[data-tool="heat"] { --aim: var(--heat); }
.aim-pad[data-tool="cold"] { --aim: var(--cyan); }
.aim-btn:not(:disabled) { border-color: var(--aim, var(--cyan)); box-shadow: 0 0 10px rgba(69, 240, 255, 0.12); }
.aim-btn:active { transform: scale(0.94); }
.aim-btn:disabled { opacity: 0.3; cursor: not-allowed; }
.aim-self { font-size: 14px; }

.status {
  min-height: 22px;
  margin: 0;
  font-family: var(--mono);
  font-size: 13px;
  color: var(--dim);
  text-align: center;
}
.status[data-tone="warn"] { color: var(--gold); }

/* ---------- side panels ---------- */

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.panel-title {
  margin: 0;
  font-family: var(--pixel);
  font-size: 10px;
  letter-spacing: 1px;
  color: var(--gold);
  text-shadow: 0 0 8px rgba(255, 200, 87, 0.4);
}

.note { margin: 0; font-size: 13px; color: var(--dim); line-height: 1.55; }
.flavor { margin: 0; font-family: var(--mono); font-size: 11.5px; color: var(--gold); opacity: 0.9; line-height: 1.55; }

.legend { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.legend li { display: flex; align-items: center; gap: 10px; font-family: var(--mono); font-size: 11.5px; color: var(--text); }
/* Swatches are canvases painted with the board's own tile art (render.js). */
.sw { flex: 0 0 auto; display: block; width: 20px; height: 20px; border-radius: 3px; box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.18); }

.facts { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.facts li { padding-left: 12px; border-left: 2px solid var(--line); }
.facts p { margin: 0 0 4px; font-size: 13px; color: var(--text); line-height: 1.55; }
.facts a { font-family: var(--mono); font-size: 11px; color: var(--cyan); text-decoration: none; }
.facts a:hover { text-decoration: underline; }

/* ---------- level dialog ---------- */

/* The head (title, stars, CLOSE) stays put; only the level list scrolls,
   so CLOSE is always one tap away on phones. A backdrop tap also closes. */
.dialog {
  width: min(640px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  max-height: calc(100dvh - 48px);
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0;
  overflow: hidden;
}
.dialog[open] { display: flex; flex-direction: column; }
.dialog::backdrop { background: rgba(5, 5, 12, 0.76); }
.dialog-head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px 12px 20px;
  border-bottom: 1px solid var(--line);
}
.dialog-heading { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 16px; min-width: 0; }
.dialog-close { flex: 0 0 auto; }
.dialog-body { min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 14px 20px 20px; }
.dialog-title { margin: 0; font-family: var(--pixel); font-size: 12px; color: var(--gold); }
.dialog-stars { margin: 0; font-family: var(--mono); font-size: 14px; color: var(--gold); }

.level-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 8px;
  margin-top: 14px;
}
.level-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  min-height: 92px;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  transition: border-color 0.12s, box-shadow 0.12s, transform 0.12s var(--ease-out);
}
.level-card:hover:not(:disabled) { border-color: var(--cyan); box-shadow: 0 0 12px rgba(69, 240, 255, 0.22); transform: translateY(-1px); }
.level-card[aria-current="true"] { border-color: var(--ice); box-shadow: inset 0 0 0 1px var(--ice); }
.level-card:disabled { opacity: 0.45; cursor: not-allowed; }
.level-card .num { font-family: var(--pixel); font-size: 8px; color: var(--gold); }
.level-card .name { font-family: var(--pixel); font-size: 9px; line-height: 1.5; color: var(--ice-hi); }
.level-card .stars { font-size: 14px; letter-spacing: 2px; color: var(--gold); }
.level-card .detail { font-family: var(--mono); font-size: 11px; color: var(--dim); }

/* ---------- footer ---------- */

.site-footer {
  border-top: 1px solid var(--line);
  padding: 22px var(--space-gutter);
  text-align: center;
  color: var(--dim);
  font-size: 13px;
}
.site-footer p { margin: 4px 0; }
.site-footer a { color: var(--cyan); text-decoration: none; }
.site-footer a:hover { text-decoration: underline; text-shadow: var(--glow-cyan); }

/* ---------- toasts ---------- */

.toasts {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(440px, calc(100vw - 32px));
  pointer-events: none;
}
.toast {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-left: 3px solid var(--red);
  color: var(--text);
  padding: 12px 14px;
  border-radius: 8px;
  font-size: 13.5px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
  animation: toast-in 0.22s var(--ease-out) both;
}
.toast-info { border-left-color: var(--cyan); }
.toast.out { opacity: 0; transform: translateY(6px); transition: opacity 0.25s, transform 0.25s; }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } }

/* ---------- Turkish labels ---------- */

/* Press Start 2P draws İ, Ğ, Ü and Ö at lowercase height ("BöLüM", "SOğUK"),
   so Turkish labels switch to the bold mono stack, sized up to match. */
:lang(tr) :is(.level, .level-of, .level-name, .hud span, .hud .phase-out, .tool-btn, .btn-big,
  .overlay-title, .final-badge, .panel-title, .dialog-title, .level-card .name) {
  font-family: var(--mono);
  font-weight: 700;
  letter-spacing: 1px;
}
:lang(tr) .level { font-size: 12px; letter-spacing: 3px; }
:lang(tr) .level-of { font-size: 11px; letter-spacing: 2px; }
:lang(tr) .level-name { font-size: clamp(16px, 3vw, 21px); }
:lang(tr) .hud span { font-size: 11px; }
:lang(tr) .hud .phase-out { font-size: 14px; line-height: 1.35; }
:lang(tr) .tool-btn { font-size: 14px; }
:lang(tr) .btn-big { font-size: 13px; }
:lang(tr) .overlay-title { font-size: clamp(20px, 5.5vw, 32px); }
:lang(tr) .final-badge { font-size: 12px; }
:lang(tr) .panel-title { font-size: 13px; }
:lang(tr) .dialog-title { font-size: 15px; }
:lang(tr) .level-card .name { font-size: 12px; }

/* ---------- responsive ---------- */

@media (max-width: 960px) {
  .play-layout { grid-template-columns: 1fr; }
  .side { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; }
}

@media (max-width: 640px) {
  .side { grid-template-columns: 1fr; }
  .hud { grid-template-columns: repeat(6, minmax(0, 1fr)); }
  .hud > div { grid-column: span 2; }
  .hud > div:nth-child(n + 4) { grid-column: span 3; }
  .topbar { padding: 12px; }
  .action-row { width: 100%; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .action-row .btn { padding: 8px 4px; font-size: 11px; }
  .canvas-wrap { padding: 4px; }
  .overlay { gap: 6px; padding: 12px 8px; }
  .overlay-stars { font-size: 22px; }
}

@media (pointer: coarse) {
  /* The idle line lists keyboard keys; on touch screens it would only leave
     an empty gap above the status line. */
  .aim-line:not([data-tool]) { display: none; }
  .aim-pad:not([hidden]) {
    display: grid;
    grid-template-columns: repeat(3, 48px);
    gap: 6px;
  }
}

@media (max-width: 380px) {
  .pad { grid-template-columns: 52px 1fr 1fr 52px; gap: 6px; }
  .tool-btn { font-size: 9px; }
  :lang(tr) .tool-btn { font-size: 12px; }
  .tool-btn kbd { display: none; }
  .wordmark { letter-spacing: 3px; }
}

/* Small phones: the board is only ~170px tall, so keep the result card
   compact and the panel does not jump as far when it appears. */
@media (max-width: 360px) {
  .overlay { gap: 4px; padding: 8px 6px; }
  .overlay-title { font-size: 15px; letter-spacing: 2px; }
  :lang(tr) .overlay-title { font-size: 18px; }
  .overlay-sub, .overlay-stats { font-size: 11px; letter-spacing: 0; }
  .overlay-stars { font-size: 18px; letter-spacing: 4px; }
  .final-badge { font-size: 8px; }
  :lang(tr) .final-badge { font-size: 11px; }
  .overlay-actions { gap: 6px; margin-top: 2px; }
  .overlay-actions .btn { min-height: 40px; padding: 8px 10px; }
  .overlay-actions .btn-big { font-size: 9px; }
  :lang(tr) .overlay-actions .btn-big { font-size: 12px; }
}

/* ---------- reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  .cursor { animation: none; }
}
