:root {
  --bg: #0a0d11;
  --text: #cfd6dd;
  --muted: #6b7785;
  --phos: #7dffa0;
  --phos-dim: #2e8a4c;
  --amber: #ffb347;
  --err: #ff7a66;
  --horizon: #5fb4ff;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  color: var(--text);
  font-family: 'Rajdhani', system-ui, sans-serif;
  background:
    radial-gradient(ellipse 60% 50% at 30% 45%, #1a2129 0%, transparent 70%),
    repeating-linear-gradient(90deg, rgba(255,255,255,.015) 0 1px, transparent 1px 80px),
    var(--bg);
}

/* ---------- top bar ---------- */
.topbar {
  display: flex; justify-content: space-between; align-items: center; gap: 16px;
  padding: 12px 24px; border-bottom: 1px solid #1f262e;
  text-transform: uppercase; letter-spacing: .2em; font-size: 14px; font-weight: 700;
}
.brand span, .topbar-meta { color: var(--muted); font-weight: 500; }

/* ---------- layout ---------- */
.room {
  flex: 1; width: 100%; max-width: 1600px; margin: 0 auto;
  display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
  gap: 32px; align-items: center; padding: 24px 32px 40px;
}
@media (max-width: 1100px) {
  .room { grid-template-columns: 1fr; padding: 16px; }
  .topbar-meta { display: none; }
}

/* ---------- gate ---------- */
.gate-bay { position: relative; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.gate-bay::before {
  content: ''; position: absolute; left: 50%; top: 45%; width: 90%; aspect-ratio: 1;
  transform: translate(-50%, -50%); border-radius: 50%;
  background: radial-gradient(circle, rgba(95,180,255,.35), transparent 65%);
  filter: blur(30px); opacity: 0; transition: opacity 1s; pointer-events: none;
}
.gate-bay[data-status="active"]::before { opacity: 1; }
.gate-mount { position: relative; width: min(100%, 76vh); aspect-ratio: 1; }
.gate-svg { display: block; width: 100%; height: 100%; overflow: visible; }
.gate-caption {
  position: relative; letter-spacing: .3em; font-weight: 700; font-size: 15px;
  color: var(--muted); text-transform: uppercase; min-height: 1.4em; text-align: center;
}
.gate-bay[data-status="dialing"] .gate-caption { color: var(--amber); }
.gate-bay[data-status="active"] .gate-caption { color: var(--horizon); }
.gate-bay[data-status="failed"] .gate-caption { color: var(--err); }

.ring-face { stroke: #15181b; stroke-width: 2; }
.dividers line { stroke: rgba(0,0,0,.45); stroke-width: 3; }
.ring-glyph {
  fill: none; stroke: #a3acb5; stroke-width: 7;
  stroke-linecap: round; stroke-linejoin: round; transition: stroke .4s;
}
.glyph-cell.encoded .ring-glyph { stroke: #ffc070; filter: url(#f-glow); }
.lip { stroke: #111; stroke-width: 1.5; }
.frame { stroke: #121417; stroke-width: 2; }
.frame-marks line { stroke: rgba(0,0,0,.5); stroke-width: 3; }
.rivet { fill: #7a828a; stroke: #22262a; stroke-width: 2; }
.housing { fill: #3b4046; stroke: #16191c; stroke-width: 3; }
.housing-inner { fill: #24282c; }
.lamp { fill: #4a2410; stroke: #140802; stroke-width: 2; transition: fill .12s; }
.chevron.lit .lamp, .chevron.engage .lamp, .chevron.locked .lamp { fill: #ff9a30; filter: url(#f-glow); }
.lamp-g { transition: transform .22s ease-in-out; }
.chevron.top.engage .lamp-g, .chevron.top.locked .lamp-g { transform: translateY(9px); }
.gate-svg.fail .chevron .lamp { animation: fail-flick .14s steps(2) 8; }
@keyframes fail-flick { 50% { fill: #4a2410; filter: none; } }

/* event horizon */
.puddle { opacity: 0; visibility: hidden; transition: opacity .8s ease, visibility 0s .8s; }
.gate-svg.active .puddle { opacity: 1; visibility: visible; transition: opacity .8s ease; }
.ripple {
  fill: none; stroke: rgba(220,245,255,.35); stroke-width: 6;
  transform-box: fill-box; transform-origin: center;
  animation: ripple 4s linear infinite;
}
.ripple.r2 { animation-delay: -1.33s; }
.ripple.r3 { animation-delay: -2.66s; }
@keyframes ripple {
  from { transform: scale(.05); opacity: .9; }
  to { transform: scale(1); opacity: 0; }
}
.surge {
  opacity: 0; pointer-events: none; mix-blend-mode: screen;
  transform-box: fill-box; transform-origin: center;
}
.gate-svg.kawoosh .surge { animation: surge 2.2s cubic-bezier(.2,.8,.2,1) forwards; }
@keyframes surge {
  0% { transform: scale(.15); opacity: 0; }
  12% { opacity: 1; }
  30% { transform: scale(1.35); opacity: 1; }
  55% { transform: scale(1.2); opacity: .9; }
  100% { transform: scale(.85); opacity: 0; }
}

/* ramp */
.ramp-deck { fill: url(#g-deck); stroke: #0b0d10; stroke-width: 2; }
.ramp-glow { opacity: 0; transition: opacity .8s; pointer-events: none; }
.gate-svg.active .ramp-glow { opacity: 1; }
.ramp-plates path { stroke: rgba(0,0,0,.55); stroke-width: 2; fill: none; }
.ramp-lip { stroke: #5c636a; stroke-width: 3; }
.ramp-rail { fill: #4a5057; stroke: #15181b; stroke-width: 1.5; }
.ramp-rail-face { fill: #22262b; }
.ramp-light { fill: #2c3238; transition: fill .4s; }
.gate-svg.active .ramp-light { fill: #8fd0ff; filter: url(#f-glow); }
.gate-svg.probing .ramp-light {
  animation: ramp-chase .9s linear infinite;
  animation-delay: calc(var(--i) * .11s);
}
@keyframes ramp-chase {
  0%, 18% { fill: #fff1c9; }
  40%, 100% { fill: #4a6f8c; }
}

/* probe */
.probe { pointer-events: none; }
.p-shadow { fill: rgba(0,0,0,.55); }
.wheel rect { fill: #17191c; stroke: #050607; stroke-width: 1.5; }
.wheel.mid rect { fill: #111316; }
.wheel.front rect { fill: #0b0c0e; }
.tread { stroke: #2d3237; stroke-dasharray: 2 4; }
.wheel.front .tread { stroke: #1d2024; }
.probe.driving .tread { animation: tread .22s linear infinite; }
@keyframes tread { to { stroke-dashoffset: 6; } }
.p-deck { fill: #a3aa98; stroke: #3a3f37; stroke-width: 1.5; }
.p-chassis { fill: #7d8476; stroke: #2b2f2a; stroke-width: 2; }
.p-panel { fill: #5c6257; stroke: #353a33; stroke-width: 1.5; }
.p-vents { stroke: #343831; stroke-width: 2.5; stroke-linecap: round; }
.p-tail { fill: #ff4a3a; filter: url(#f-glow); }
.p-bumper { fill: #2a2d30; stroke: #121416; stroke-width: 1.5; }
.p-stripes path { fill: #d9ab35; }
.p-mast { fill: #575d55; stroke: #2a2e29; stroke-width: 1.5; }
.p-head { fill: #6f7669; stroke: #2a2e29; stroke-width: 2; }
.p-head-band { fill: #3c4139; }
.p-antenna { stroke: #1c1f22; stroke-width: 2.5; stroke-linecap: round; }
.p-antenna-tip { fill: #d9ab35; }
.p-beacon { fill: #6b3a10; }
.probe.driving .p-beacon { animation: beacon .7s linear infinite; }
@keyframes beacon { 0%, 49% { fill: #ffb347; } 50%, 100% { fill: #6b3a10; } }

/* probe hitting the horizon */
.splash { pointer-events: none; mix-blend-mode: screen; }
.splash-ring { fill: none; stroke: rgba(230,248,255,.9); stroke-width: 6; }
.splash-streaks line { stroke: #e8f8ff; stroke-width: 3; stroke-linecap: round; }

/* ---------- CRT shell ---------- */
.console { display: flex; justify-content: center; }
.crt {
  position: relative; width: min(100%, 660px);
  padding: 30px 30px 52px; border-radius: 28px;
  background: linear-gradient(160deg, #d2cbbb, #aca594 60%, #8f8878);
  box-shadow: inset 0 2px 0 rgba(255,255,255,.45), inset 0 -6px 12px rgba(0,0,0,.35), 0 30px 60px rgba(0,0,0,.6);
}
.crt-label {
  position: absolute; left: 34px; bottom: 17px;
  font-size: 12px; letter-spacing: .25em; font-weight: 700; color: #6d675a;
  text-shadow: 0 1px 0 rgba(255,255,255,.4);
}
.crt-led {
  position: absolute; right: 36px; bottom: 19px; width: 10px; height: 10px; border-radius: 50%;
  background: #3a5a3f; box-shadow: inset 0 1px 2px rgba(0,0,0,.5);
}
.crt-led.idle { background: #59f07f; box-shadow: 0 0 8px #59f07f; }
.crt-led.dialing, .crt-led.connecting { background: var(--amber); box-shadow: 0 0 8px var(--amber); animation: blink .6s steps(2) infinite; }
.crt-led.active { background: var(--horizon); box-shadow: 0 0 10px var(--horizon); }
.crt-led.failed { background: var(--err); box-shadow: 0 0 8px var(--err); }

.crt-screen {
  position: relative; overflow: hidden; border-radius: 22px / 26px;
  background: radial-gradient(ellipse at center, #0f2416 0%, #06110a 70%, #030805 100%);
  box-shadow: inset 0 0 60px rgba(0,0,0,.9), inset 0 0 14px rgba(120,255,160,.15),
    0 0 0 10px #1b1d1c, 0 0 0 12px #5d584d;
  color: var(--phos); font-family: 'VT323', ui-monospace, monospace; font-size: 19px; line-height: 1.15;
  text-shadow: 0 0 4px rgba(125,255,160,.7), 0 0 10px rgba(125,255,160,.25);
}
.crt-screen::before {
  content: ''; position: absolute; inset: 0; z-index: 2; pointer-events: none;
  background: repeating-linear-gradient(to bottom, rgba(0,0,0,.28) 0 1px, transparent 1px 3px);
}
.crt-screen::after {
  content: ''; position: absolute; inset: 0; z-index: 3; pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 60%, rgba(0,0,0,.55) 100%);
  animation: flicker 5s infinite;
}
@keyframes flicker { 0%, 100% { opacity: 1; } 48% { opacity: .92; } 50% { opacity: 1; } 52% { opacity: .96; } }

.crt-content {
  position: relative; z-index: 1; padding: 18px 22px;
  display: flex; flex-direction: column; gap: 8px;
  animation: power-on 1s ease-out;
}
@keyframes power-on {
  0% { transform: scale(1, .004); filter: brightness(5); }
  35% { transform: scale(1, .004); filter: brightness(5); }
  65% { transform: scale(1, 1); filter: brightness(2); }
  100% { filter: none; }
}

/* ---------- CRT content ---------- */
.row { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.head { border-bottom: 1px solid var(--phos-dim); padding-bottom: 4px; }
.lbl { opacity: .6; }
.amber { color: var(--amber); }
.status-grid { display: grid; grid-template-columns: auto 1fr; gap: 2px 20px; }
.status-grid .power { grid-column: 1 / -1; display: flex; align-items: center; gap: 10px; }
.st-dialing, .st-connecting { color: var(--amber); }
.st-active { color: #b8f0ff; text-shadow: 0 0 6px rgba(95,180,255,.8); }
.st-failed { color: var(--err); }
.bar { flex: 1; height: 10px; border: 1px solid var(--phos-dim); padding: 1px; }
.bar span { display: block; height: 100%; background: var(--phos); box-shadow: 0 0 6px var(--phos); transition: width .2s linear; }
.bar span.low { background: var(--amber); box-shadow: 0 0 6px var(--amber); }

button {
  font: inherit; color: inherit; text-shadow: inherit; background: transparent;
  border: 1px solid var(--phos-dim); padding: 1px 10px; cursor: pointer;
}
button:hover:not(:disabled), button:focus-visible { background: var(--phos); color: #021a0a; text-shadow: none; outline: none; }
button:disabled { opacity: .3; cursor: default; }

.tabs { display: flex; gap: 8px; }
.tab.active { background: rgba(125,255,160,.15); border-color: var(--phos); }
.view { height: 178px; display: flex; flex-direction: column; gap: 6px; }
.hidden { display: none; }
.detail { font-size: 17px; opacity: .85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.glyph { width: 1em; height: 1em; flex: none; }
.glyph path { fill: none; stroke: currentColor; stroke-width: 8; stroke-linecap: round; stroke-linejoin: round; }

.book-wrap { flex: 1; min-height: 0; display: flex; gap: 8px; }
.feed { flex: none; width: 176px; margin: 0; display: flex; flex-direction: column; gap: 3px; }
.feed canvas {
  display: block; width: 176px; height: 99px; border: 1px solid var(--phos-dim);
  image-rendering: pixelated; background: #030805;
  box-shadow: 0 0 8px rgba(125,255,160,.15);
}
.feed canvas.still { border-color: var(--phos); }
.feed figcaption { font-size: 14px; line-height: 1.1; opacity: .8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.book {
  flex: 1; min-width: 0; list-style: none; margin: 0; padding: 0; overflow-y: auto;
  border: 1px solid var(--phos-dim); scrollbar-width: thin; scrollbar-color: var(--phos-dim) transparent;
}
.book li {
  display: grid; grid-template-columns: 8ch 10ch 1fr 2ch; gap: 8px; align-items: center;
  padding: 1px 8px; cursor: pointer; white-space: nowrap;
}
.book li:hover { background: rgba(125,255,160,.1); }
.book li.sel { background: var(--phos); color: #021a0a; text-shadow: none; }
.book .glyphs { display: flex; gap: 4px; font-size: 17px; }
.book .flag { text-align: right; }

.keypad { display: grid; grid-template-columns: repeat(13, 1fr); gap: 4px; align-content: start; flex: 1; }
.key {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 3px 0 1px; aspect-ratio: 1 / 1.1;
}
.key .glyph { width: 62%; height: auto; aspect-ratio: 1; }
.key small { font-size: 12px; line-height: 1; opacity: .7; }
.key.used { opacity: .3; }
.key.origin { color: var(--amber); border-color: rgba(255,179,71,.5); }

.buffer-row { display: flex; align-items: center; gap: 12px; }
.buffer { display: grid; grid-template-columns: repeat(7, 44px); gap: 6px; }
.slot { position: relative; height: 44px; border: 1px dashed var(--phos-dim); display: grid; place-items: center; }
.slot span { display: grid; place-items: center; }
.slot .glyph { width: 28px; height: 28px; }
.slot i { position: absolute; top: 0; left: 3px; font-size: 12px; font-style: normal; opacity: .55; }
.slot.filled { border-style: solid; }
.buffer.editable .slot.filled { cursor: pointer; }
.buffer.editable .slot.filled:hover { border-color: var(--err); color: var(--err); }
.back { align-self: stretch; padding: 0 10px; }
.slot:nth-child(7).filled { color: var(--amber); }
.slot.encoding { animation: blink .5s steps(2) infinite; border-color: var(--amber); }
.slot.locked { background: var(--amber); color: #1a0e00 !important; border-color: var(--amber); text-shadow: none; box-shadow: 0 0 12px rgba(255,179,71,.6); }
.slot.failed { border-color: var(--err); color: var(--err) !important; animation: blink .2s steps(2) 6; }
@keyframes blink { 50% { opacity: .25; } }

.cmds { display: flex; flex-wrap: wrap; gap: 8px; }
.cmds button { flex: 1; padding: 4px 6px; }

.log {
  height: 150px; overflow-y: auto; border-top: 1px solid var(--phos-dim); padding-top: 4px;
  font-size: 17px; scrollbar-width: thin; scrollbar-color: var(--phos-dim) transparent;
}
.log .line { white-space: pre-wrap; animation: type .35s steps(24) both; }
.log .ts { opacity: .45; }
.log .warn { color: var(--amber); }
.log .error { color: var(--err); }
.log .good { color: #d8ffe3; }
@keyframes type { from { clip-path: inset(0 100% 0 0); } to { clip-path: inset(0 0 0 0); } }

.foot { border-top: 1px solid var(--phos-dim); padding-top: 6px; font-size: 16px; flex-wrap: wrap; }
.opts { display: flex; gap: 6px; }

@media (max-width: 560px) {
  .crt { padding: 16px 12px 44px; border-radius: 18px; }
  .crt-content { padding: 12px; font-size: 17px; }
  .book li { grid-template-columns: 8ch 1fr 2ch; }
  .book .glyphs { display: none; }
  .feed, .feed canvas { width: 128px; }
  .feed canvas { height: 72px; }
  .buffer { grid-template-columns: repeat(7, minmax(0, 1fr)); flex: 1; }
  .keypad { grid-template-columns: repeat(8, 1fr); overflow-y: auto; }
  .head span:last-child { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .crt-content, .crt-screen::after, .log .line { animation: none; }
}
