/* The gate page's stylesheet. Self-contained because everything else on the host is behind
   the gate. Every colour below is a value from design/tokens.json; an eight-digit hex is a
   token colour at an opacity and nothing else. test/gate.test.ts checks every literal. */

@font-face { font-family: 'Catamaran'; font-style: normal; font-weight: 400 800; font-display: swap; src: url('/gate/fonts/catamaran-variable.woff2') format('woff2-variations'); }
@font-face { font-family: 'Lato'; font-style: normal; font-weight: 400; font-display: swap; src: url('/gate/fonts/lato-regular.woff2') format('woff2'); }
@font-face { font-family: 'Lato'; font-style: normal; font-weight: 700; font-display: swap; src: url('/gate/fonts/lato-bold.woff2') format('woff2'); }

:root {
  /* Palette — one definition each */
  --color-blue-l1: #508791; --color-blue-l2: #DCF0F0; --color-blue-l3: #2D3237; --color-blue-deep: #3E6D75; --color-blue-lift: #8FBFC8;
  --color-green-l1: #969632; --color-green-l2: #F0F5E6; --color-green-l3: #32371E; --color-green-mark: #82822C; --color-green-lift: #C2C25A;
  --color-grey-primary: #323232; --color-grey-medium: #646464; --color-grey-light: #C8C8C8; --color-white: #FFFFFF;
  --color-gold-l1: #BE8C00; --color-gold-l2: #FAF0C8; --color-red-l1: #963228;
  --color-slate-bg: #F5F7F5; --color-slate-surface: #FFFFFF; --color-slate-surface-2: #E9F1F0; --color-slate-text: #2F3434; --color-slate-text-2: #5E6664; --color-slate-text-3: #646B68; --color-slate-rule: #D8DEDC;
  --color-night-bg: #1B1F22; --color-night-surface: #232729; --color-night-surface-2: #263239; --color-night-tint: #2A3C40; --color-night-text: #E6E9E6; --color-night-text-2: #AEB5B2; --color-night-text-3: #9DA5A2; --color-night-rule: #343A3E;
  --color-ink-base: #2D3237; --color-ink-deep: #232729; --color-ink-text: #F2F5F3; --color-ink-text-2: #B7BFBC;
  --color-ink-rule: #FFFFFF24; --color-ink-glass: #2D3237D9; --color-ink-glass-2: #232729B3;
  --shadow-panel: 0 1px 0 #2F34340D, 0 14px 34px -20px #2F343459;

  /* Roles */
  --surface-page: var(--color-slate-bg);
  --surface-default: var(--color-slate-surface);
  --surface-raised: var(--color-slate-surface-2);
  --surface-tinted: var(--color-blue-l2);
  --text-body: var(--color-slate-text);
  --text-muted: var(--color-slate-text-2);
  --text-quiet: var(--color-slate-text-3);
  --interactive: var(--color-blue-l1);
  --interactive-text: var(--color-blue-deep);
  --interactive-fill: var(--color-blue-deep);
  --interactive-fill-text: var(--color-white);
  --sequence: var(--color-green-mark);
  --border: var(--color-slate-rule);

  --font-heading: 'Catamaran', Arial, Helvetica, sans-serif;
  --font-body: 'Lato', Georgia, serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --step--1: clamp(.82rem, .8rem + .1vw, .88rem);
  --step-0: clamp(1rem, .97rem + .15vw, 1.08rem);
  --step-1: clamp(1.25rem, 1.18rem + .35vw, 1.42rem);
  --step-4: clamp(2.44rem, 1.97rem + 2.35vw, 3.38rem);
  --step-5: clamp(2.8rem, 2.1rem + 3.5vw, 4.5rem);
  --space-3xs: .25rem; --space-2xs: .5rem; --space-xs: .75rem; --space-s: 1rem; --space-m: 1.5rem; --space-l: 2.25rem; --space-xl: 3.5rem;
  --gutter: clamp(1rem, 5vw, 4rem);
  --radius-interactive: 3px;
  --radius: 6px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --surface-page: var(--color-night-bg);
    --surface-default: var(--color-night-surface);
    --surface-raised: var(--color-night-surface-2);
    --surface-tinted: var(--color-night-tint);
    --text-body: var(--color-night-text);
    --text-muted: var(--color-night-text-2);
    --text-quiet: var(--color-night-text-3);
    --interactive: var(--color-blue-lift);
    --interactive-text: var(--color-blue-lift);
    --interactive-fill: var(--color-blue-lift);
    --interactive-fill-text: var(--color-night-bg);
    --sequence: var(--color-green-lift);
    --border: var(--color-night-rule);
    --shadow-panel: 0 1px 0 #1B1F224D, 0 14px 34px -20px #1B1F22B3;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --surface-page: var(--color-night-bg);
  --surface-default: var(--color-night-surface);
  --surface-raised: var(--color-night-surface-2);
  --surface-tinted: var(--color-night-tint);
  --text-body: var(--color-night-text);
  --text-muted: var(--color-night-text-2);
  --text-quiet: var(--color-night-text-3);
  --interactive: var(--color-blue-lift);
  --interactive-text: var(--color-blue-lift);
  --interactive-fill: var(--color-blue-lift);
  --interactive-fill-text: var(--color-night-bg);
  --sequence: var(--color-green-lift);
  --border: var(--color-night-rule);
  --shadow-panel: 0 1px 0 #1B1F224D, 0 14px 34px -20px #1B1F22B3;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body.gate {
  min-height: 100vh; display: flex; flex-direction: column;
  font-family: var(--font-body); font-size: var(--step-0); line-height: 1.6;
  color: var(--text-body); background: var(--surface-page);
  -webkit-font-smoothing: antialiased; overflow-x: hidden;
}
a { color: var(--interactive-text); }
button { font-family: inherit; }
h1 { font-family: var(--font-heading); font-weight: 800; font-size: var(--step-5); line-height: 1.02; letter-spacing: -.02em; margin: 0; color: var(--text-body); }
h1 em { font-style: normal; position: relative; white-space: nowrap; }
h1 em::after { content: ""; position: absolute; left: 0; right: 0; bottom: .04em; height: .08em; background: var(--sequence); transform: scaleX(0); transform-origin: left; animation: gate-sweep .8s .4s cubic-bezier(.2,.7,.2,1) forwards; }
@keyframes gate-sweep { to { transform: scaleX(1); } }

/* Header / footer */
.gate-head, .gate-foot { display: flex; align-items: center; justify-content: space-between; gap: var(--space-s); padding: var(--space-s) var(--gutter); background: var(--color-ink-base); color: var(--color-ink-text); }
.gate-brand { display: inline-flex; align-items: center; gap: var(--space-xs); color: inherit; text-decoration: none; }
.gate-brand img { display: block; color: var(--color-ink-text); }
.gate-brand__name { font-family: var(--font-heading); font-weight: 700; font-size: var(--step-1); letter-spacing: -.01em; }
.gate-pill { font-family: var(--font-mono); font-size: .7rem; letter-spacing: .15em; text-transform: uppercase; color: var(--color-ink-text); border: 1px solid var(--color-ink-rule); padding: .15em .6em; border-radius: var(--radius-interactive); }
.gate-foot { margin-top: auto; font-size: var(--step--1); color: var(--color-ink-text-2); }
.gate-foot a { color: var(--color-ink-text); }

/* Copy + form */
.gate-main { width: 100%; max-width: 1100px; margin: 0 auto; padding: clamp(2.5rem, 7vh, 5rem) var(--gutter) clamp(3rem, 8vh, 6rem); display: flex; flex-direction: column; align-items: center; gap: clamp(2rem, 5vh, 3.5rem); }
.gate-copy { display: flex; flex-direction: column; align-items: center; text-align: center; max-width: 46rem; }
.gate-eyebrow { display: inline-flex; align-items: center; gap: .6em; margin: 0 0 var(--space-m); font-family: var(--font-heading); font-weight: 700; font-size: .78rem; letter-spacing: .14em; text-transform: uppercase; color: var(--interactive-text); border: 1px solid var(--border); background: var(--surface-default); padding: .45em 1em .45em .8em; border-radius: var(--radius-interactive); }
.gate-eyebrow__dot { width: .55em; height: .55em; border-radius: 50%; background: var(--interactive); box-shadow: 0 0 0 0 var(--interactive); animation: gate-pulse 2s infinite; }
@keyframes gate-pulse { 70% { box-shadow: 0 0 0 .6em transparent; } 100% { box-shadow: 0 0 0 0 transparent; } }
.gate-lead { margin: var(--space-m) 0 0; max-width: 38rem; color: var(--text-muted); font-size: var(--step-0); }
.gate-form { width: 100%; max-width: 26rem; margin: var(--space-l) auto 0; text-align: left; }
.gate-form > * + * { margin-top: var(--space-s); }
.gate-form label { display: block; font-family: var(--font-heading); font-weight: 700; margin-bottom: var(--space-2xs); }
.gate-form input { width: 100%; padding: .75rem .85rem; font: inherit; font-size: var(--step-1); letter-spacing: .05em; color: var(--text-body); background: var(--surface-default); border: 1px solid var(--border); border-radius: var(--radius-interactive); }
.gate-form input:focus-visible { outline: 2px solid var(--interactive-text); outline-offset: 1px; }
.gate-form__error { margin: 0 0 var(--space-s); padding-left: var(--space-s); border-left: 3px solid var(--color-red-l1); color: var(--text-body); }
.gate-form__note { margin: var(--space-s) 0 0; color: var(--text-quiet); font-size: var(--step--1); }
.gate-btn { display: inline-flex; align-items: center; justify-content: center; width: 100%; gap: var(--space-2xs); padding: var(--space-xs) var(--space-m); border-radius: var(--radius-interactive); font-family: var(--font-heading); font-weight: 700; font-size: var(--step-0); line-height: 1.2; cursor: pointer; border: 2px solid var(--interactive-fill); background: var(--interactive-fill); color: var(--interactive-fill-text); transition: background-color .15s ease, color .15s ease, border-color .15s ease, transform .15s ease; }
.gate-btn:hover { transform: translateY(-1px); background: var(--color-ink-base); border-color: var(--color-ink-base); color: var(--color-ink-text); }
.gate-btn:active { transform: translateY(1px); }
.gate-btn:focus-visible { outline: 2px solid var(--interactive-text); outline-offset: 2px; }

/* The instrument — a panel, so it may carry a shadow */
.visual { width: 100%; max-width: 1000px; }
.panel { position: relative; background: var(--color-ink-base); color: var(--color-ink-text); border-radius: var(--radius); padding: var(--space-s) var(--space-s) var(--space-xs); box-shadow: var(--shadow-panel); overflow: hidden; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-xs); margin-bottom: var(--space-xs); }
.panel-title { font-family: var(--font-mono); font-size: .7rem; letter-spacing: .12em; color: var(--color-ink-text-2); text-transform: uppercase; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tools { display: flex; gap: var(--space-3xs); flex-wrap: wrap; justify-content: flex-end; }
.tools button { width: 30px; height: 30px; border-radius: var(--radius-interactive); border: 1px solid var(--color-ink-rule); background: transparent; color: var(--color-ink-text-2); cursor: pointer; display: grid; place-items: center; transition: background-color .15s, color .15s, border-color .15s; }
.tools button:hover { color: var(--color-ink-text); border-color: var(--color-blue-lift); }
.tools button.on { background: var(--color-blue-deep); border-color: var(--color-blue-deep); color: var(--color-white); }
.tools button:focus-visible { outline: 2px solid var(--color-blue-lift); outline-offset: 1px; }
.tools svg { width: 15px; height: 15px; }
.stage { position: relative; height: clamp(320px, 52vw, 600px); border-radius: var(--radius); overflow: hidden; background: var(--color-night-bg); cursor: grab; touch-action: none; }
.stage:active { cursor: grabbing; }
.stage:focus-visible { outline: 2px solid var(--color-blue-lift); outline-offset: -2px; }
.stage.placing { cursor: crosshair; }
.stage.walking, .stage.driving { cursor: default; }
.stage canvas { display: block; width: 100% !important; height: 100% !important; }
.stage__alt { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; margin: -1px; }
.scene { position: absolute; inset: 0; display: grid; place-items: center; }
.scene__still { display: block; width: 100%; height: 100%; object-fit: cover; }
.nogl { position: absolute; left: var(--space-s); right: var(--space-s); bottom: var(--space-s); margin: 0; padding: var(--space-xs) var(--space-s); background: var(--color-ink-glass); border: 1px solid var(--color-ink-rule); border-radius: var(--radius); font-size: var(--step--1); color: var(--color-ink-text); text-align: center; }
.hint { position: absolute; left: 12px; top: 12px; font-family: var(--font-mono); font-size: .66rem; letter-spacing: .04em; color: var(--color-ink-text-2); background: var(--color-ink-glass); border: 1px solid var(--color-ink-rule); padding: 6px 9px; border-radius: var(--radius); pointer-events: none; transition: opacity .4s; }
.hint.hide { opacity: 0; }
.compass { position: absolute; right: 12px; bottom: 12px; width: 44px; height: 44px; border-radius: 50%; background: var(--color-ink-glass); border: 1px solid var(--color-ink-rule); display: grid; place-items: center; pointer-events: none; }
.compass svg { width: 30px; height: 30px; transition: transform .1s linear; }
.compass__ring { stroke: var(--color-ink-rule); }
.compass__n { fill: var(--color-red-l1); }
.compass__s { fill: var(--color-ink-text-2); }
.compass__t { fill: var(--color-ink-text); font-family: var(--font-mono); }
.compass.gold .compass__n { fill: var(--color-gold-l1); }
.info { position: absolute; left: 12px; bottom: 12px; max-width: min(300px, calc(100% - 80px)); background: var(--color-ink-glass); border: 1px solid var(--color-blue-deep); border-radius: var(--radius); padding: 11px 13px 12px; }
.info__x { position: absolute; top: 4px; right: 4px; width: 24px; height: 24px; border: none; background: transparent; color: var(--color-ink-text-2); cursor: pointer; border-radius: var(--radius-interactive); }
.info__x:hover { color: var(--color-ink-text); }
.info__k { font-family: var(--font-mono); font-size: .66rem; letter-spacing: .12em; color: var(--color-ink-text-2); text-transform: uppercase; }
.info__n { font-family: var(--font-heading); font-size: var(--step-0); font-weight: 700; color: var(--color-ink-text); margin: 2px 0 6px; }
.info__row { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: .78rem; color: var(--color-ink-text-2); }
.info__row b { color: var(--color-ink-text); font-weight: 700; }
.info__status { margin-top: 8px; }
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: var(--radius-interactive); font-size: .7rem; font-weight: 700; color: var(--color-ink-text); border: 1px solid var(--color-ink-rule); }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--color-ink-text-2); }
.badge.b-live::before { background: var(--color-blue-lift); }
.badge.b-wait::before { background: var(--color-gold-l1); }
.badge.b-stop::before { background: var(--color-red-l1); }
.badge.b-go::before { background: var(--color-green-lift); }
.hud { position: absolute; right: 12px; top: 12px; background: var(--color-ink-glass); border: 1px solid var(--color-blue-deep); border-radius: var(--radius); padding: 10px 12px; font-family: var(--font-mono); font-size: .66rem; color: var(--color-ink-text-2); line-height: 1.8; min-width: 200px; max-width: min(300px, calc(100% - 24px)); }
.hud__t { font-size: .64rem; letter-spacing: .12em; color: var(--color-ink-text-2); text-transform: uppercase; margin-bottom: 4px; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.hud__mode { color: var(--color-white); background: var(--color-blue-deep); padding: 1px 7px; border-radius: var(--radius-interactive); font-weight: 700; }
.hud kbd { display: inline-block; min-width: 16px; text-align: center; padding: 0 5px; border-radius: var(--radius-interactive); border: 1px solid var(--color-ink-rule); color: var(--color-ink-text); font-family: inherit; font-size: .62rem; line-height: 16px; }
.hud__msg { color: var(--color-ink-text); margin-top: 4px; min-height: 1.2em; }
.dpad { position: absolute; right: 12px; bottom: 12px; display: grid; grid-template-columns: repeat(3, 42px); grid-template-rows: repeat(3, 42px); gap: 4px; z-index: 3; }
.dpad button { border-radius: var(--radius-interactive); border: 1px solid var(--color-ink-rule); background: var(--color-ink-glass-2); color: var(--color-ink-text); font-size: 15px; cursor: pointer; display: grid; place-items: center; touch-action: none; user-select: none; -webkit-user-select: none; }
.dpad button:active, .dpad button.down { background: var(--color-blue-deep); border-color: var(--color-blue-deep); }
.dpad .e { visibility: hidden; }
.stamp { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; pointer-events: none; background: #1B1F2299; }
.stamp__t, .stamp__b { display: block; font-family: var(--font-heading); text-transform: uppercase; color: var(--color-gold-l1); letter-spacing: .2em; }
.stamp__t { font-size: var(--step-0); }
.stamp__b { font-size: var(--step-4); font-weight: 800; border: 4px solid var(--color-gold-l1); padding: .1em .4em; border-radius: var(--radius); transform: rotate(-6deg); animation: gate-stamp .5s cubic-bezier(.2,.7,.2,1) both; }
@keyframes gate-stamp { from { transform: rotate(-6deg) scale(2.2); opacity: 0; } to { transform: rotate(-6deg) scale(1); opacity: 1; } }
.stage.photo .hint, .stage.photo .hud, .stage.photo .compass, .stage.photo .dpad, .stage.photo .info { display: none; }
.panel-foot { display: flex; gap: var(--space-s); flex-wrap: wrap; margin-top: var(--space-xs); font-family: var(--font-mono); font-size: .66rem; letter-spacing: .04em; color: var(--color-ink-text-2); }
.panel-foot b { color: var(--color-ink-text); font-weight: 700; }
[hidden] { display: none !important; }

@media (max-width: 640px) {
  .panel { padding: var(--space-xs) var(--space-xs) var(--space-2xs); }
  .hud { min-width: 0; max-width: calc(100% - 24px); line-height: 1.6; }
  .hud__keys { display: none; }
  .dpad { grid-template-columns: repeat(3, 38px); grid-template-rows: repeat(3, 38px); }
  .info { max-width: calc(100% - 24px); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-delay: 0s !important; transition-duration: .01ms !important; }
  .gate-eyebrow__dot { box-shadow: none; }
}
