:root {
  --bg: #000;
  --ink: rgba(255, 255, 255, 0.9);
  --ink-dim: rgba(255, 255, 255, 0.62);
  --ink-faint: rgba(255, 255, 255, 0.34);
  --line: rgba(255, 255, 255, 0.14);
  --panel: rgba(3, 3, 8, 0.82);
  --magenta: #ff3ea5;

  --font-ui: 'Inter Tight', system-ui, sans-serif;
  --font-display: 'Instrument Serif', Georgia, serif;
  --font-mono: 'JetBrains Mono', ui-monospace, monospace;

  --gutter: clamp(16px, 2.8vw, 40px);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --fast: 180ms;
  --normal: 420ms;
  --slow: 900ms;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; background: var(--bg); color: var(--ink); overflow: hidden; }
body { font-family: var(--font-ui); -webkit-font-smoothing: antialiased; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
button:focus-visible { outline: 1px solid var(--ink); outline-offset: 4px; border-radius: 4px; }

#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; cursor: grab; touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }

/* ---- corners: name, skip, one line of context ---- */
.hud { position: fixed; left: 0; right: 0; display: flex; justify-content: space-between; align-items: center; padding: 0 var(--gutter); pointer-events: none; z-index: 5; }
.hud.top { top: var(--gutter); }
.hud.bottom { bottom: var(--gutter); }
#owner { font-size: 13px; font-weight: 500; letter-spacing: 0.01em; }
#context, #skip, #leave { font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.18em; text-transform: uppercase; color: var(--ink-faint); }
#skip { pointer-events: auto; opacity: 0; visibility: hidden; transition: opacity var(--normal), visibility 0s var(--normal), color var(--fast); }
#skip.show { opacity: 1; visibility: visible; transition: opacity var(--normal), color var(--fast); }
#skip:hover { color: var(--ink); }
#leave { display: none; pointer-events: auto; transition: color var(--fast); }
#leave.show { display: block; }
#leave:hover { color: var(--ink); }

/* ---- hero: the portrait moment ---- */
#hero { position: fixed; left: var(--gutter); top: 50%; width: min(46vw, 640px); transform: translateY(calc(-50% + 14px)); display: flex; flex-direction: column; align-items: flex-start; gap: 22px; opacity: 0; visibility: hidden; pointer-events: none; transition: opacity var(--slow) var(--ease-out), transform var(--slow) var(--ease-out), visibility 0s var(--slow); z-index: 4; }
#hero.show { opacity: 1; visibility: visible; pointer-events: auto; transform: translateY(-50%); transition: opacity var(--slow) var(--ease-out), transform var(--slow) var(--ease-out); }
#hero h1 { font-family: var(--font-display); font-weight: 400; font-size: clamp(64px, 9.5vw, 156px); line-height: 0.88; letter-spacing: -0.03em; color: #fff; }
#hero p { max-width: 34ch; font-size: clamp(15px, 1.25vw, 18px); line-height: 1.5; color: var(--ink-dim); }
#enter { display: inline-flex; align-items: center; gap: 12px; margin-top: 6px; padding: 13px 22px; border-radius: 999px; border: 1px solid rgba(255, 255, 255, 0.4); font-size: 15px; font-weight: 500; color: #fff; transition: background var(--fast), color var(--fast), border-color var(--fast); }
#enter span { transition: transform var(--fast) var(--ease-out); }
#enter:hover { background: #fff; color: #000; border-color: #fff; }
#enter:hover span { transform: translateX(4px); }

/* ---- scan your own: status, your name, your mind ---- */
#scan { position: fixed; left: var(--gutter); top: 50%; width: min(46vw, 640px); transform: translateY(calc(-50% + 14px)); display: flex; flex-direction: column; align-items: flex-start; gap: 22px; opacity: 0; visibility: hidden; pointer-events: none; transition: opacity var(--slow) var(--ease-out), transform var(--slow) var(--ease-out), visibility 0s var(--slow); z-index: 4; }
#scan.show { opacity: 1; visibility: visible; pointer-events: auto; transform: translateY(-50%); transition: opacity var(--slow) var(--ease-out), transform var(--slow) var(--ease-out); }
#scan .status { font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.18em; text-transform: uppercase; color: var(--ink-faint); min-height: 14px; }
#scan .status:empty { display: none; }
#scan .name, #scan .done { display: none; flex-direction: column; align-items: flex-start; gap: 18px; }
#scan.name .name, #scan.done .done { display: flex; }
#scan label, #scan .done p { max-width: 34ch; font-size: clamp(15px, 1.25vw, 18px); line-height: 1.5; color: var(--ink-dim); }
#scan .field { display: flex; align-items: center; gap: 14px; border-bottom: 1px solid rgba(255, 255, 255, 0.4); padding-bottom: 6px; transition: border-color var(--fast); }
#scan .field:focus-within { border-color: #fff; }
#scan input { width: min(40vw, 420px); background: none; border: 0; outline: 0; font-family: var(--font-display); font-size: clamp(40px, 5vw, 72px); line-height: 1; letter-spacing: -0.02em; color: #fff; caret-color: var(--magenta); }
#scan input::placeholder { color: rgba(255, 255, 255, 0.22); }
#scan .field button { font-size: 28px; color: var(--ink-dim); transition: color var(--fast), transform var(--fast) var(--ease-out); }
#scan .field button:hover { color: #fff; transform: translateX(4px); }
#scan h1 { font-family: var(--font-display); font-weight: 400; font-size: clamp(64px, 9.5vw, 156px); line-height: 0.88; letter-spacing: -0.03em; color: #fff; overflow-wrap: anywhere; }
#scan .row { display: flex; gap: 22px; margin-top: 6px; }
#scan .row button { font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.18em; text-transform: uppercase; color: var(--ink-faint); transition: color var(--fast); }
#scan .row button:hover { color: var(--ink); }

/* ---- index ---- */
#index { position: fixed; left: var(--gutter); top: 50%; transform: translate(-12px, -50%); display: flex; flex-direction: column; gap: 2px; z-index: 6; opacity: 0; visibility: hidden; transition: opacity var(--normal) var(--ease-out), transform var(--normal) var(--ease-out), visibility 0s var(--normal); }
#index.show { opacity: 1; visibility: visible; transform: translate(0, -50%); transition: opacity var(--normal) var(--ease-out), transform var(--normal) var(--ease-out); }
#index .group { display: flex; flex-direction: column; }
#index .head { display: flex; align-items: center; gap: 10px; padding: 7px 0; font-size: 13px; color: var(--ink-dim); transition: color var(--fast); }
#index .head i { width: 7px; height: 7px; border-radius: 50%; background: var(--c); box-shadow: 0 0 10px var(--c); }
#index em { font-style: normal; font-family: var(--font-mono); font-size: 10px; color: var(--ink-faint); }
#index .items { display: flex; flex-direction: column; padding-left: 17px; max-height: 0; overflow: hidden; transition: max-height var(--normal) var(--ease-out); }
#index .group:hover .items, #index .group:focus-within .items { max-height: 260px; }
#index .group:hover .head, #index .group:focus-within .head { color: var(--ink); }
#index .items button { display: flex; justify-content: space-between; gap: 18px; min-width: 168px; text-align: left; padding: 4px 0; font-size: 13px; color: var(--ink-dim); transition: color var(--fast), transform var(--fast) var(--ease-out); }
#index .items button:hover { color: #fff; transform: translateX(3px); }
#index .items button.active { color: var(--c); }
#index .scan { display: flex; align-items: center; gap: 10px; margin-top: 14px; padding: 7px 0; font-size: 13px; color: var(--magenta); }
#index .scan i { width: 7px; height: 7px; border-radius: 50%; border: 1px solid var(--magenta); }

/* ---- names on the map ---- */
#labels { position: fixed; inset: 0; pointer-events: none; opacity: 0; visibility: hidden; z-index: 3; }
#labels > * { position: absolute; left: 0; top: 0; white-space: nowrap; will-change: transform; transition: opacity var(--fast); }
.cell-label { display: flex; align-items: baseline; gap: 6px; height: 18px; padding: 0 2px; pointer-events: auto; font-size: 12px; line-height: 18px; color: rgba(255, 255, 255, 0.8); text-shadow: 0 0 6px #000, 0 0 2px #000; }
.cell-label em { font-style: normal; font-family: var(--font-mono); font-size: 9px; letter-spacing: 0.06em; color: var(--ink-faint); }
.cell-label em:empty { display: none; }
.cell-label.hot { color: #fff; font-weight: 500; }
.cell-label.hot em { color: var(--c); }
.section-title { font-family: var(--font-display); font-size: 24px; line-height: 28px; color: var(--c); text-shadow: 0 0 10px #000; }
.year-tick { font-family: var(--font-mono); font-size: 9px; line-height: 12px; letter-spacing: 0.14em; color: var(--ink-faint); }

/* ---- details beside an open cell ---- */
#leader { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; opacity: 0; transition: opacity var(--normal); z-index: 5; }
#leader.show { opacity: 1; }
#leader line { stroke: var(--c, #fff); stroke-width: 1; stroke-opacity: 0.7; }
#card { position: fixed; right: var(--gutter); top: 50%; transform: translateY(-50%); width: min(340px, calc(100vw - 2 * var(--gutter))); padding: 18px 20px 16px; display: flex; flex-direction: column; gap: 9px; background: var(--panel); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); border-left: 1px solid var(--c); opacity: 0; visibility: hidden; transition: opacity var(--normal) var(--ease-out), visibility 0s var(--normal); z-index: 6; }
#card.show { opacity: 1; visibility: visible; transition: opacity var(--normal) var(--ease-out); }
#card header { display: flex; justify-content: space-between; align-items: center; }
#card .kicker { font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.18em; text-transform: uppercase; color: var(--c); }
#card .close { font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--ink-faint); transition: color var(--fast); }
#card .close:hover { color: #fff; }
#card .title { font-family: var(--font-display); font-weight: 400; font-size: clamp(38px, 4.2vw, 56px); line-height: 0.95; letter-spacing: -0.02em; color: #fff; }
#card .media { margin: 2px 0 4px; aspect-ratio: 16 / 9; overflow: hidden; border-radius: 6px; background: #0a0a12; }
#card .media img { width: 100%; height: 100%; object-fit: cover; display: block; opacity: 0.92; }
#card .media.logo { display: grid; place-items: center; }
#card .media.logo img { width: auto; height: auto; max-width: 62%; max-height: 52%; object-fit: contain; border-radius: 4px; }
#card .media.white img { filter: brightness(0) invert(1); opacity: 0.8; }
#card .role { font-size: 13px; color: var(--ink); }
#card .role:empty, #card .points:empty { display: none; }
#card .line { font-size: 15px; line-height: 1.5; color: var(--ink-dim); }
#card .stat { font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--ink); }
#card .points { list-style: none; display: flex; flex-direction: column; gap: 6px; padding-top: 2px; }
#card .points li { position: relative; padding-left: 14px; font-size: 13px; line-height: 1.45; color: var(--ink-dim); }
#card .points li::before { content: ''; position: absolute; left: 0; top: 0.6em; width: 5px; height: 5px; border-radius: 50%; background: var(--c); }
#card .related { display: flex; flex-wrap: wrap; gap: 6px; padding-top: 6px; }
#card .related button { display: flex; align-items: center; gap: 7px; padding: 5px 11px; border-radius: 999px; border: 1px solid var(--line); font-size: 12px; color: var(--ink-dim); transition: color var(--fast), border-color var(--fast); }
#card .related button::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: var(--c); }
#card .related button:hover { color: #fff; border-color: rgba(255, 255, 255, 0.4); }
#card .timeline { display: flex; justify-content: space-between; gap: 8px; padding-top: 12px; margin-top: 4px; border-top: 1px solid var(--line); }
#card .timeline button { font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.06em; color: var(--ink-dim); transition: color var(--fast); }
#card .timeline button:hover:not(:disabled) { color: #fff; }
#card .timeline button:disabled { color: var(--ink-faint); cursor: default; }

/* ---- actions: replay the years, step out to the head ---- */
#actions { position: fixed; right: var(--gutter); bottom: var(--gutter); display: flex; gap: 22px; opacity: 0; visibility: hidden; transition: opacity var(--normal), visibility 0s var(--normal); z-index: 5; }
#actions.show { opacity: 1; visibility: visible; transition: opacity var(--normal); }
#actions button { font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.18em; text-transform: uppercase; color: var(--ink-faint); transition: color var(--fast); }
#actions button:hover { color: var(--ink); }
#actions button.active { color: var(--ink); }

/* ---- the year, while the mind grows ---- */
#year { position: fixed; right: var(--gutter); bottom: calc(var(--gutter) - 6px); font-family: var(--font-display); font-size: clamp(56px, 7vw, 96px); line-height: 1; letter-spacing: -0.02em; color: #fff; opacity: 0; pointer-events: none; transition: opacity var(--slow) var(--ease-out); z-index: 4; }
#year.show { opacity: 1; }

#toast { position: fixed; left: 50%; top: calc(var(--gutter) + 36px); transform: translate(-50%, -8px); padding: 8px 14px; border-radius: 999px; background: var(--panel); border: 1px solid var(--line); font-size: 13px; opacity: 0; pointer-events: none; transition: opacity var(--normal), transform var(--normal) var(--ease-out); z-index: 8; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }

.noscript { position: fixed; inset: 0; display: grid; place-items: center; padding: var(--gutter); text-align: center; }

@media (max-width: 720px) {
  #hero, #scan { top: auto; bottom: calc(var(--gutter) + 28px); width: auto; right: var(--gutter); transform: translateY(14px); }
  #hero.show, #scan.show { transform: none; }
  #scan input { width: 100%; font-size: 40px; }
  #scan h1 { font-size: 56px; }
  /* phones: the index is one row of section names; tapping one opens its newest cell */
  #index { top: calc(var(--gutter) + 30px); right: var(--gutter); transform: none; flex-direction: row; flex-wrap: wrap; gap: 0 14px; }
  #index.show { transform: none; }
  #index .items { display: none; }
  #index .head, #index .scan { padding: 5px 0; font-size: 12px; }
  #index .scan { margin-top: 0; }
  #card { left: var(--gutter); right: var(--gutter); top: auto; bottom: calc(var(--gutter) + 30px); transform: none; width: auto; max-height: 62vh; overflow: auto; padding: 14px 16px 12px; gap: 7px; }
  #card .title { font-size: 34px; }
  #card .media { aspect-ratio: 21 / 9; }
  #actions { bottom: calc(var(--gutter) - 2px); gap: 16px; }
  .hud.bottom { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 1ms !important; }
}
