:root {
  --bg: #04070a;
  --bg-2: #0a1218;
  --phosphor: #3dff9a;
  --phosphor-dim: #1d7a4c;
  --core: #4fd1ff;
  --core-dim: #1b5770;
  --text: #d7f5e6;
  --muted: #6c8a7c;
  --warn: #ffcc4d;
  --down: #ff5d5d;
  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --dock-h: 34vh;
  --glow: 61,255,154;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body { background: var(--bg); color: var(--text); font-family: var(--mono); font-size: 15px; line-height: 1.55; overflow: hidden; }
body::after { content: ""; position: fixed; inset: 0; pointer-events: none; z-index: 50; background: repeating-linear-gradient(to bottom, rgba(255,255,255,.035) 0 1px, transparent 1px 3px); }
a { color: var(--core); }
:focus-visible { outline: 2px solid var(--core); outline-offset: 3px; }
.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; }
#about-copy:focus-within { position: fixed; left: 16px; right: 16px; bottom: 16px; width: auto; height: auto; clip: auto; overflow: visible; white-space: normal; margin: 0; padding: 16px; background: var(--bg-2); border: 1px solid var(--core-dim); z-index: 70; }

/* Top-right links */
.top-links { position: fixed; top: 12px; right: 16px; z-index: 60; display: flex; gap: 12px; }
.top-links a { font-size: 12px; color: var(--muted); border: 1px solid var(--phosphor-dim); padding: 4px 10px; border-radius: 3px; text-decoration: none; background: var(--bg); }
.top-links a:hover { color: var(--text); }

/* Terminal: full screen during boot */
.terminal { position: fixed; inset: 0; display: flex; flex-direction: column; justify-content: flex-start; padding: clamp(16px, 6vw, 80px); padding-top: clamp(16px, 14vh, 140px); color: var(--phosphor); text-shadow: 0 0 2px rgba(var(--glow),.9), 0 0 8px rgba(var(--glow),.45), 0 0 18px rgba(var(--glow),.18); z-index: 10; }
.term-out { max-width: 900px; width: 100%; margin: 0 auto; overflow-y: auto; white-space: pre-wrap; word-break: break-word; }
.term-line { min-height: 1.55em; }
.term-line.tag-sleep, .term-line.tag-warn { color: var(--warn); }
.term-line.tag-down { color: var(--down); }
.term-echo { color: var(--text); }
.cursor { display: inline-block; width: .6em; height: 1.1em; margin-left: 1px; background: var(--phosphor); vertical-align: text-bottom; animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.term-form { display: none; max-width: 900px; width: 100%; margin: 8px auto 0; align-items: center; gap: 8px; }
.term-form input { flex: 1; min-width: 0; background: transparent; border: 0; color: var(--phosphor); font: inherit; caret-color: var(--phosphor); text-shadow: inherit; }
.term-form input:focus { outline: none; }
.term-form:focus-within { outline: 1px dashed var(--phosphor-dim); outline-offset: 4px; }
.chips { display: none; flex-wrap: wrap; gap: 8px; max-width: 900px; width: 100%; margin: 10px auto 0; }
.chips button { font: inherit; font-size: 12px; color: var(--phosphor); background: rgba(var(--glow),.06); border: 1px solid var(--phosphor-dim); border-radius: 3px; padding: 6px 10px; cursor: pointer; }

/* Skip */
.skip { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 60; font: inherit; font-size: 12px; color: var(--muted); background: var(--bg); border: 1px solid var(--phosphor-dim); padding: 6px 14px; border-radius: 3px; cursor: pointer; }

/* Core act: terminal docks to the bottom */
body.is-core .skip, html.xp-docked .skip { display: none; }
body.is-core .terminal, html.xp-docked .terminal { inset: auto 0 0 0; height: var(--dock-h); justify-content: flex-start; padding: 12px 16px; background: rgba(4,7,10,.94); border-top: 1px solid var(--phosphor-dim); font-size: 13px; z-index: 30; }
body.is-core .term-out, html.xp-docked .term-out { flex: 1; }
body.is-core .term-form, html.xp-docked .term-form { display: flex; }
/* Dock with transform only, so it never registers as layout shift */
body.is-core .terminal { animation: dock-in .6s cubic-bezier(.2,.8,.2,1) both; }
html.xp-docked .terminal { animation: none; }
@keyframes dock-in { from { transform: translateY(calc(var(--dock-h) - 100vh)); } }

/* Core window */
.core-window { position: fixed; inset: 0 0 var(--dock-h) 0; display: none; z-index: 20; background: radial-gradient(ellipse at center, #07202b 0%, var(--bg) 65%); }
body.is-core .core-window { display: block; animation: tear-in .7s steps(1, end) both, flash-in .7s ease both; }
@keyframes tear-in { 0% { clip-path: inset(48% 0 48% 0); } 20% { clip-path: inset(10% 0 70% 0); } 35% { clip-path: inset(60% 0 5% 0); } 50% { clip-path: inset(30% 0 30% 0); } 70% { clip-path: inset(5% 0 15% 0); } 100% { clip-path: inset(0); } }
@keyframes flash-in { from { opacity: 0; filter: brightness(2.5) hue-rotate(40deg); } to { opacity: 1; filter: none; } }
.core-bar { position: absolute; top: 12px; left: 16px; z-index: 5; display: flex; gap: 10px; align-items: center; font-size: 12px; color: var(--core); letter-spacing: .12em; }
.core-bar button { font: inherit; letter-spacing: normal; color: var(--muted); background: none; border: 1px solid var(--core-dim); border-radius: 3px; padding: 3px 8px; cursor: pointer; }
.core-bar button[aria-pressed="true"] { color: var(--core); border-color: var(--core); }
.core-stage { position: absolute; inset: 0; }
.core-stage canvas { display: block; width: 100%; height: 100%; }
.track-choice { position: absolute; left: 50%; bottom: 100px; transform: translateX(-50%); width: calc(100% - 32px); display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; }
.track-choice button { font: inherit; font-weight: 600; color: var(--bg); background: var(--core); border: 1px solid var(--core); border-radius: 3px; padding: 10px 18px; cursor: pointer; }
.track-choice button + button { color: var(--core); background: transparent; }

/* Project rings: HTML buttons orbiting the core */
@property --spin { syntax: '<angle>'; inherits: true; initial-value: 0deg; }
.rings { position: absolute; left: 50%; top: 50%; width: 0; height: 0; --r: min(34vmin, 300px); animation: orbit 120s linear infinite; z-index: 4; }
.rings:hover, .rings:focus-within { animation-play-state: paused; }
@keyframes orbit { to { --spin: 360deg; } }
.ring-node { --a: calc(var(--i) / var(--n) * 360deg + var(--spin)); position: absolute; left: 0; top: 0; transform: translate(-50%, -50%) rotate(var(--a)) translateX(var(--r)) rotate(calc(-1 * var(--a))); font: inherit; font-size: 13px; white-space: nowrap; color: var(--core); background: rgba(4,20,28,.8); border: 1px solid var(--core-dim); border-radius: 999px; padding: 6px 14px; cursor: pointer; }
.ring-node:hover, .ring-node[aria-current="true"] { color: #fff; border-color: var(--c, var(--core)); box-shadow: 0 0 18px var(--c, var(--core)); }

/* Project window: text-mode, real HTML inside */
.panel { position: absolute; right: 16px; top: 56px; bottom: 16px; width: min(420px, calc(100% - 32px)); overflow-y: auto; background: var(--bg-2); border: 3px double var(--phosphor); padding: 0 14px 14px; z-index: 6; color: var(--phosphor); }
.tui-title { position: sticky; top: 0; display: flex; align-items: center; background: var(--bg-2); padding: 6px 0; white-space: nowrap; overflow: hidden; }
.tui-title h2 { font-size: 15px; color: #fff; margin: 0; font-weight: 600; }
.tui-fill { flex: 1; overflow: hidden; color: var(--phosphor-dim); }
.tui-fill::before { content: "══════════════════════════════════════════════════════════════════════════"; }
.panel .close { flex: none; margin-left: 6px; font: inherit; font-size: 14px; background: none; border: 0; color: var(--phosphor); cursor: pointer; }
.panel .ascii { font: 9px/1 var(--mono); letter-spacing: 0; color: var(--phosphor); margin: 8px 0; overflow: hidden; white-space: pre; min-height: 20em; }
.panel p { font-size: 13px; color: var(--text); }
.panel ul { list-style: none; display: flex; flex-wrap: wrap; gap: 0 10px; margin: 10px 0; font-size: 12px; color: var(--phosphor); }
.panel li + li::before { content: "· "; color: var(--phosphor-dim); }
.panel .links { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 12px; }
.panel .links a { font-size: 13px; color: var(--phosphor); text-decoration: none; }
.panel .links a::before { content: "[ "; }
.panel .links a::after { content: " ]"; }
.panel .links a:hover, .panel .links a:focus-visible { background: var(--phosphor); color: var(--bg); }

/* Phones: tappable chips replace typing */
@media (max-width: 640px) {
  :root { --dock-h: 36vh; }
  body { font-size: 13px; }
  body.is-core .chips, html.xp-docked .chips { display: flex; }
  body.is-core .term-form, html.xp-docked .term-form { display: none; }
  .rings { --r: 36vw; }
  .ring-node { font-size: 11px; padding: 4px 10px; }
  .panel { top: auto; left: 8px; right: 8px; bottom: 8px; width: auto; max-height: calc(100% - 96px); }
  .track-choice { bottom: 88px; }
  .core-bar > span { display: none; }
  .core-bar { right: 128px; flex-wrap: wrap; }
  .panel { background: var(--bg-2); overscroll-behavior: contain; }
  .panel .ascii { font-size: 7px; min-height: 13em; }
}

/* ---------- CRT ---------- */
body::before { content: ""; position: fixed; inset: 0; pointer-events: none; z-index: 51; border-radius: 22px; box-shadow: inset 0 0 0 2px #000, inset 0 0 90px rgba(0,0,0,.85); background: radial-gradient(ellipse at center, transparent 58%, rgba(0,0,0,.5) 100%); }
.crt-band { position: fixed; left: 0; right: 0; top: 0; height: 22vh; pointer-events: none; z-index: 52; background: linear-gradient(to bottom, transparent, rgba(255,255,255,.04) 50%, transparent); transform: translateY(-22vh); animation: crt-band 8s linear infinite; }
@keyframes crt-band { to { transform: translateY(100vh); } }
main { animation: crt-flicker 5s steps(1, end) infinite; }
@keyframes crt-flicker { 0%, 100% { opacity: 1; } 31% { opacity: .975; } 33% { opacity: 1; } 68% { opacity: .98; } 70% { opacity: 1; } }
.crt-power { position: fixed; inset: 0; z-index: 90; pointer-events: none; background: #000; animation: crt-power-bg .7s ease-out .05s both; }
.crt-power::after { content: ""; position: absolute; inset: 0; background: #fff; transform: scale(0, .003); animation: crt-power-line .7s ease-out .05s both; }
@keyframes crt-power-bg { 0%, 55% { opacity: 1; } 100% { opacity: 0; } }
@keyframes crt-power-line { 0% { transform: scale(0, .003); opacity: 1; } 25% { transform: scale(1, .003); opacity: 1; } 55% { transform: scale(1, 1); opacity: .85; } 100% { transform: scale(1, 1); opacity: 0; } }
.crt-power.off { animation: crt-off-bg .34s ease-in both; }
.crt-power.off::after { animation: crt-off-line .34s ease-in both; }
@keyframes crt-off-bg { 0% { opacity: 0; } 30%, 100% { opacity: 1; } }
@keyframes crt-off-line { 0% { transform: scale(1, 1); opacity: .9; } 55% { transform: scale(1, .004); opacity: 1; } 85% { transform: scale(.004, .004); opacity: 1; } 100% { transform: scale(0, 0); opacity: 0; } }
.glitch { animation: crt-glitch .25s steps(2, end) 1; }
@keyframes crt-glitch { 0% { transform: translateX(2px); filter: drop-shadow(-2px 0 #ff00c8) drop-shadow(2px 0 #00e5ff); } 50% { transform: translateX(-2px); } 100% { transform: none; filter: none; } }

/* AI lines, banner, prompt, screensaver */
.term-line.ai { color: var(--core); text-shadow: 0 0 8px rgba(79,209,255,.45); }
.term-line.ai-thinking { opacity: .6; }
.term-line.banner { color: var(--phosphor); line-height: 1.15; white-space: pre; }
.term-form [data-term-prompt] { white-space: nowrap; color: var(--phosphor); }
.saver { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 8; background: #000; }

@media (prefers-reduced-motion: reduce) { main, .crt-band { animation: none; } }
