:root {
  --bg: #0b0d10;
  --panel: #111419;
  --panel-2: #161a21;
  --line: #222833;
  --text: #e6e9ef;
  --muted: #8a93a3;
  --accent: #5eead4;
  --accent-dim: rgba(94, 234, 212, 0.14);
  --danger: #f87171;
  --warn: #fbbf24;
  --radius: 14px;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", "Cascadia Code", Menlo, Consolas, monospace;
  --sans: ui-sans-serif, -apple-system, "Segoe UI", "Inter", Roboto, "Helvetica Neue", Arial, sans-serif;
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
}

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

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

body {
  margin: 0;
  min-height: 100dvh;
  background:
    radial-gradient(1200px 600px at 50% -10%, rgba(94, 234, 212, 0.08), transparent 60%),
    linear-gradient(var(--bg), var(--bg));
  color: var(--text);
  font: 16px/1.6 var(--sans);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* faint grid, static */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.025) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: radial-gradient(ellipse at 50% 30%, #000 30%, transparent 75%);
}

.shell {
  position: relative;
  isolation: isolate;
  max-width: 760px;
  margin: 0 auto;
  padding: 28px 20px 40px;
  display: flex;
  flex-direction: column;
  gap: 40px;
  min-height: 100dvh;
}

main { display: flex; flex-direction: column; gap: 28px; flex: 1; min-width: 0; }
main > * { min-width: 0; }

/* top bar */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-family: var(--mono);
  font-size: 14px;
}
.brand { font-weight: 600; letter-spacing: -0.01em; }
.tld { color: var(--accent); }

.status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  color: var(--muted);
  font-size: 13px;
}
.dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--warn);
  box-shadow: 0 0 0 0 rgba(251, 191, 36, 0.6);
  animation: pulse 2s var(--ease-out) infinite;
}
@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 rgba(251, 191, 36, 0.55); }
  70%  { box-shadow: 0 0 0 8px rgba(251, 191, 36, 0); }
  100% { box-shadow: 0 0 0 0 rgba(251, 191, 36, 0); }
}

/* hero */
.hero { padding-top: 24px; }
.eyebrow {
  margin: 0 0 12px;
  font-family: var(--mono);
  font-size: 13px;
  color: var(--accent);
  letter-spacing: 0.02em;
}
h1 {
  margin: 0 0 14px;
  font-size: clamp(34px, 6vw, 52px);
  line-height: 1.05;
  letter-spacing: -0.03em;
  font-weight: 650;
  text-wrap: balance;
}
.lede {
  margin: 0;
  max-width: 58ch;
  color: var(--muted);
  font-size: 17px;
  text-wrap: pretty;
}

/* terminal */
.terminal {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  overflow: hidden;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.03) inset, 0 20px 40px -24px rgba(0, 0, 0, 0.7);
}
.term-bar {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--panel-2);
}
.term-bar span { width: 10px; height: 10px; border-radius: 50%; background: #2a313d; }
.term-bar code { margin-left: 8px; font-family: var(--mono); font-size: 12px; color: var(--muted); }

.log {
  list-style: none;
  margin: 0;
  padding: 16px 18px 18px;
  font-family: var(--mono);
  font-size: 13.5px;
  line-height: 1.85;
  min-height: calc(7 * 1.85em + 34px); /* reserve space: no layout shift while lines appear */
}
.log li { display: grid; grid-template-columns: 4.6em minmax(0, 1fr); }
.log li > span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.log li::before { font-weight: 600; white-space: pre; }
.log li[data-kind="cmd"] { grid-template-columns: 1.6em minmax(0, 1fr); }
.log li[data-kind="cmd"]::before  { content: "$"; color: var(--accent); }
.log li[data-kind="ok"]::before   { content: "[ ok ]"; color: var(--accent); }
.log li[data-kind="wait"]::before { content: "[ .. ]"; color: var(--warn); }
.log li[data-kind="ok"], .log li[data-kind="wait"] { color: #c3c9d4; }

/* ---------- intro sequence (JS adds .js to <html>) ---------- */
.js .hero,
.js .terminal,
.js .game,
.js .foot {
  opacity: 0;
  transform: translateY(10px);
}
.js .terminal { transform: translateY(12px) scale(0.98); transform-origin: 50% 0; }
.js .game, .js .foot { visibility: hidden; }

.js .hero.in,
.js .terminal.in,
.js .game.in,
.js .foot.in {
  opacity: 1;
  transform: none;
  visibility: visible;
  transition:
    opacity 360ms var(--ease-out),
    transform 480ms var(--ease-out),
    visibility 0s;
}

/* lines keep their space while hidden: no layout shift */
.js .log li { visibility: hidden; }
.js .log li.in { visibility: visible; }

.log li[data-kind="run"]::before { content: "[ .. ]"; color: var(--muted); }
.log li[data-kind="ok"].flip::before { animation: flip 260ms var(--ease-out); }
@keyframes flip { from { opacity: 0.2; } to { opacity: 1; } }

.skip {
  position: fixed;
  right: 16px;
  bottom: 16px;
  margin: 0;
  font: 12px var(--mono);
  color: var(--muted);
  opacity: 0;
  transition: opacity 300ms var(--ease-out);
  pointer-events: none;
}
.skip.in { opacity: 1; }

.cursor {
  display: inline-block;
  width: 0.55em;
  height: 1.05em;
  margin-left: 4px;
  vertical-align: -0.15em;
  background: var(--warn);
  animation: blink 1.1s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* game */
.game-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
h2 { margin: 0; font-size: 15px; font-weight: 600; letter-spacing: -0.01em; }
.score {
  margin: 0;
  display: flex;
  gap: 18px;
  font-family: var(--mono);
  font-size: 13px;
  color: var(--muted);
}
.score b { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }

.stage {
  position: relative;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  overflow: hidden;
  aspect-ratio: 720 / 200;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}
canvas { position: absolute; inset: 0; display: block; width: 100%; height: 100%; }

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 10px;
  text-align: center;
  background: rgba(11, 13, 16, 0.55);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  opacity: 1;
  transition: opacity 200ms var(--ease-out);
}
.overlay[hidden] { display: grid; opacity: 0; pointer-events: none; }
.overlay-title { margin: 0; font-family: var(--mono); font-size: 14px; font-weight: 600; }
.overlay-title.breach { color: var(--danger); }

.btn {
  min-height: 44px;
  min-width: 120px;
  padding: 0 20px;
  border: 1px solid rgba(94, 234, 212, 0.45);
  border-radius: 10px;
  background: var(--accent-dim);
  color: var(--accent);
  font: 600 15px/1 var(--mono);
  cursor: pointer;
  transition: background-color 150ms ease, transform 120ms var(--ease-out);
}
.btn:active { transform: scale(0.97); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
@media (hover: hover) and (pointer: fine) {
  .btn:hover { background: rgba(94, 234, 212, 0.22); }
}

.hint { margin: 0; font-size: 12.5px; color: var(--muted); }
kbd {
  padding: 1px 6px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: var(--panel-2);
  font: 12px var(--mono);
  color: var(--text);
}

/* footer */
.foot {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  font-family: var(--mono);
  font-size: 13px;
  color: var(--muted);
}
.foot a {
  color: var(--text);
  text-decoration: none;
  border-bottom: 1px solid var(--line);
  padding: 10px 0; /* larger tap area */
  margin: -10px 0;
  transition: border-color 150ms ease, color 150ms ease;
}
.foot a:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 2px; }
@media (hover: hover) and (pointer: fine) {
  .foot a:hover { color: var(--accent); border-color: var(--accent); }
}

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

::selection { background: rgba(94, 234, 212, 0.3); }

@media (max-width: 520px) {
  .shell { gap: 28px; padding-top: 20px; }
  .log { font-size: 12.5px; min-height: 0; }
  .log li > span { white-space: normal; }
  .stage { aspect-ratio: 360 / 220; }
  .foot { flex-direction: column; gap: 14px; }
  .foot > span[aria-hidden] { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .dot, .cursor { animation: none; }
  .js .hero, .js .terminal, .js .game, .js .foot { opacity: 1; transform: none; visibility: visible; transition: none; }
  .js .log li { visibility: visible; }
  .skip { display: none; }
  .overlay, .btn { transition: none; }
}
