/* LABYRINTH — Level 55
   Retro-arcade chrome shared with The Lab; a focused two-column workshop with
   the maze canvas as the hero and a compact control rail. Dark only. */

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

*, *::before, *::after { box-sizing: border-box; }
html { color-scheme: dark; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(1200px 500px at 50% -10%, rgba(69, 240, 255, 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(69, 240, 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: rect(0 0 0 0);
  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); }

/* ---------- 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(20px, 4.5vw, 34px);
  letter-spacing: 3px;
  color: var(--text);
  text-shadow: 0 0 16px rgba(69, 240, 255, 0.55), 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(--cyan); 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: 20px var(--space-gutter) 72px;
}

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

.stage { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.controls { display: flex; flex-direction: column; gap: 16px; min-width: 0; }

/* ---------- mode tabs ---------- */

.mode-tabs { display: inline-flex; gap: 6px; }

/* ---------- canvas ---------- */

.canvas-wrap {
  display: flex;
  justify-content: center;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  min-height: 200px;
  /* Scroll rather than clip when an enforced min cell makes the grid overflow. */
  overflow: auto;
  box-shadow: inset 0 0 60px rgba(69, 240, 255, 0.03);
}

#mazeCanvas {
  display: block;
  image-rendering: auto;
  border-radius: 4px;
  touch-action: none;
}
#mazeCanvas:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 3px;
}

/* ---------- dpad (touch controls) ---------- */

.dpad {
  display: none;
  grid-template-columns: repeat(3, 56px);
  grid-template-rows: repeat(2, 56px);
  gap: 8px;
  justify-content: center;
}
.dpad-btn {
  width: 56px; height: 56px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--cyan);
  font-size: 18px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.12s, box-shadow 0.12s, transform 0.1s;
}
.dpad-btn:hover { border-color: var(--cyan); }
.dpad-btn:active { transform: scale(0.94); box-shadow: var(--glow-cyan); }
.dpad-up { grid-column: 2; grid-row: 1; }
.dpad-left { grid-column: 1; grid-row: 2; }
.dpad-right { grid-column: 3; grid-row: 2; }
.dpad-down { grid-column: 2; grid-row: 2; }

/* ---------- legend ---------- */

.legend {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px 16px;
}
.legend-title {
  margin: 0 0 10px;
  font-family: var(--pixel);
  font-size: 9px;
  letter-spacing: 1px;
  color: var(--gold);
}
.legend-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
}
.legend-list li {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--dim);
}
.swatch {
  width: 14px; height: 14px;
  border-radius: 3px;
  flex: 0 0 auto;
}
.sw-wall { background: transparent; border: 2px solid var(--cyan); border-radius: 0; }
.sw-start { background: rgba(65, 255, 139, 0.4); border: 1.5px solid var(--green); }
.sw-goal { background: rgba(255, 61, 139, 0.4); border: 1.5px solid var(--magenta); }
.sw-visited { background: rgba(255, 61, 139, 0.35); }
.sw-frontier { background: rgba(255, 200, 87, 0.6); }
.sw-path { background: rgba(65, 255, 139, 0.7); }
.sw-player { background: var(--cyan); border-radius: 50%; box-shadow: 0 0 8px rgba(69, 240, 255, 0.6); }

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

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 16px;
}
.panel:last-child { margin-bottom: 0; }
.panel-title {
  margin: 0;
  font-family: var(--pixel);
  font-size: 10px;
  letter-spacing: 1px;
  color: var(--cyan);
  text-shadow: 0 0 8px rgba(69, 240, 255, 0.4);
}

.field { display: flex; flex-direction: column; gap: 6px; }
.field-label {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 1px;
  color: var(--dim);
}

select {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--control-line);
  color: var(--text);
  border-radius: 6px;
  padding: 9px 10px;
  font-family: var(--mono);
  font-size: 13px;
  cursor: pointer;
  transition: border-color 0.12s;
}
select:hover { border-color: #74749a; }

.toggle-line {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text);
  cursor: pointer;
}
.toggle-line input { accent-color: var(--cyan); width: 16px; height: 16px; }

.field-row { display: flex; align-items: center; gap: 10px; }
.field-row .field-label { flex: 0 0 60px; }
input[type="range"] { flex: 1; accent-color: var(--cyan); min-width: 0; }

/* ---------- buttons & chips ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--text);
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.5px;
  padding: 10px 12px;
  min-height: 42px;
  border-radius: 6px;
  cursor: pointer;
  text-decoration: none;
  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.5; 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-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.btn-grid.two { grid-template-columns: 1fr 1fr; }

.chip {
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--dim);
  font-family: var(--mono);
  font-size: 11.5px;
  letter-spacing: 1px;
  padding: 8px 16px;
  min-height: 42px;
  border-radius: 999px;
  cursor: pointer;
  transition: border-color 0.12s, color 0.12s, box-shadow 0.12s;
}
.chip:hover { border-color: var(--cyan); color: var(--text); }
.chip.is-active {
  border-color: var(--cyan);
  color: var(--cyan);
  background: rgba(69, 240, 255, 0.08);
  box-shadow: inset 0 0 0 1px rgba(69, 240, 255, 0.35);
}

/* ---------- stat grids ---------- */

.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 0;
}
.stat-grid.three { grid-template-columns: repeat(3, 1fr); }
.stat-grid > div {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  text-align: center;
}
.stat-grid dt {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 1px;
  color: var(--dim);
}
.stat-grid dd {
  margin: 4px 0 0;
  font-family: var(--mono);
  font-size: 18px;
  color: var(--gold);
}

.seed-line {
  margin: 0;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 1px;
  color: var(--dim);
}
.seed-line output { color: var(--cyan); }

.hint { margin: 0; font-size: 12px; color: var(--dim); line-height: 1.5; }
.won-line { margin: 0; font-family: var(--mono); font-size: 13px; color: var(--dim); min-height: 1.2em; }
.won-line.is-win { color: var(--green); text-shadow: 0 0 10px rgba(65, 255, 139, 0.4); }

.chrome-row { display: flex; }
.chrome-row .btn { flex: 1; }
.btn[aria-pressed="true"] { color: var(--gold); border-color: var(--gold); }

.privacy-note {
  margin: 4px 0 0;
  text-align: center;
  font-size: 12px;
  color: var(--dim);
}

/* ---------- 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-success { border-left-color: var(--green); }
.toast.out { opacity: 0; transform: translateY(6px); transition: opacity 0.25s, transform 0.25s; }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } }

/* ---------- 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 a { color: var(--cyan); text-decoration: none; }
.site-footer a:hover { text-decoration: underline; text-shadow: var(--glow-cyan); }

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

@media (max-width: 880px) {
  .layout { grid-template-columns: 1fr; }
  .controls { order: 2; }
  .stage { order: 1; }
}

/* Show the dpad on coarse pointers (touch) AND on narrow viewports, since
   pointer media describes the device, not screen size — some touch devices
   report pointer: fine, and mobile users still need on-screen controls. */
@media (pointer: coarse), (max-width: 880px) {
  .dpad { display: grid; }
}
@media (pointer: coarse) {
  .chip { padding: 10px 18px; }
}

@media (max-width: 420px) {
  .btn-grid { grid-template-columns: 1fr; }
  .stat-grid.three { grid-template-columns: repeat(3, 1fr); }
  .dpad { grid-template-columns: repeat(3, 48px); grid-template-rows: repeat(2, 48px); }
  .dpad-btn { width: 48px; height: 48px; }
  .wordmark { letter-spacing: 1px; }
}

/* ---------- 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; }
}
