:root {
  --bg: #0e0c19;
  --panel: #131022;
  --panel2: #181429;
  --line: #2a2541;
  --line2: #3b3366;
  --ink: #ece9f7;
  --muted: #9d97b8;
  --dim: #645e82;
  --teal: #6ee2cf;
  --violet: #b79cf0;
  --amber: #f0a85a;
  --rose: #ff6b81;
  --mono: "JetBrains Mono", ui-monospace, Consolas, monospace;
  --sans: "Space Grotesk", "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); }
/* the whole game lives in #term: the full window, or the screen of the arcade cabinet */
#term { position: fixed; inset: 0; overflow: hidden; background: var(--bg); container-type: inline-size; container-name: term; }
body.cabinet #term { position: absolute; inset: 0; border-radius: inherit; }
body { font: 16px/1.55 var(--mono); overflow: hidden; }
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }

.mint-phosphor {
  --bg: #061a13; --panel: #0a2118; --panel2: #0e2a1e; --line: #254b3a; --line2: #3c6852;
  --ink: #dffae7; --muted: #a4cbb4; --dim: #6d9d82; --teal: #7ef3b1; --violet: #b5e5b5;
}

/* ---------- boot ---------- */
.boot {
  position: absolute; inset: 0; z-index: 30;
  display: grid; place-content: safe center; padding: 24px; overflow-y: auto;
  background: radial-gradient(ellipse at 50% 45%, #17132b, var(--bg) 70%);
  transition: opacity .6s ease;
}
.boot.fade { opacity: 0; pointer-events: none; }
.title { max-width: 560px; margin-bottom: 18px; }
.title .kicker { margin: 0; font: 600 13px/1.4 var(--mono); letter-spacing: .3em; color: var(--violet); }
.title h1 { margin: 4px 0 2px; font: 700 clamp(36px, 7cqw, 58px)/1 var(--sans); letter-spacing: .08em; }
.title .sub { margin: 0 0 12px; color: var(--muted); }
.title .sub em { color: var(--teal); font-style: normal; }
.title .pitch { margin: 0; color: var(--ink); font: 17px/1.6 var(--sans); max-width: 480px; }
.oops { position: absolute; left: 16px; right: 16px; bottom: 16px; z-index: 50; background: #2a0f18; border: 1px solid var(--rose); border-radius: 10px; padding: 12px 14px; display: grid; gap: 4px; color: var(--ink); font-size: 15px; }
.oops pre { margin: 4px 0 0; white-space: pre-wrap; color: #ffc2cc; max-height: 30vh; overflow: auto; user-select: all; }
.boot pre {
  margin: 0; min-width: min(560px, 86cqw); min-height: 9em; opacity: .75; font-size: 14.5px !important;
  font: 16px/1.7 var(--mono); color: var(--muted); white-space: pre-wrap;
}
.boot pre b { color: var(--ink); font-weight: 600; }
.boot pre i { color: var(--amber); font-style: normal; }
.boot pre u { color: var(--violet); text-decoration: none; }
.boot-go {
  justify-self: start; margin-top: 18px;
  background: none; border: 1px solid var(--teal); color: var(--teal);
  padding: 8px 16px; border-radius: 6px; letter-spacing: .04em;
  animation: pulse 2.4s ease-in-out infinite;
}
.boot-go:hover, .boot-go:focus-visible { background: rgba(110,226,207,.08); outline: none; }
@keyframes pulse { 50% { box-shadow: 0 0 0 4px rgba(110,226,207,.08); } }

/* ---------- shell ---------- */
.os { position: absolute; inset: 0; display: flex; flex-direction: column; animation: fadein .7s ease; }
@keyframes fadein { from { opacity: 0; } }

.bar {
  display: flex; align-items: center; gap: 16px;
  padding: 8px 14px; border-bottom: 1px solid var(--line);
  background: linear-gradient(#141126, #110e1f);
  font-size: 14px;
}
.bar-left { display: flex; gap: 12px; align-items: baseline; min-width: 0; }
.brand { font-family: var(--sans); font-weight: 700; letter-spacing: .14em; }
.host { color: var(--dim); white-space: nowrap; }
.relay {
  flex: 1; display: flex; justify-content: center; align-items: center; gap: 8px;
  color: var(--muted); min-width: 0; white-space: nowrap; overflow: hidden;
}
.relay-name { color: var(--violet); }
#relay-text { overflow: hidden; text-overflow: ellipsis; }
.relay-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--violet); box-shadow: 0 0 8px var(--violet); flex: none; }
.relay.knock .relay-dot { animation: knocknow .9s ease; }
@keyframes knocknow { 0%, 100% { transform: scale(1); } 30% { transform: scale(1.9); background: var(--ink); } }
.bar-right { display: flex; gap: 6px; }
.chip {
  background: var(--panel2); border: 1px solid var(--line); color: var(--muted);
  padding: 4px 10px; border-radius: 999px; font-size: 14px;
}
.chip:hover, .chip:focus-visible { color: var(--ink); border-color: var(--line2); outline: none; }
.chip[aria-pressed="true"] { color: var(--teal); border-color: rgba(110,226,207,.4); }
.chip.ghost { background: none; }

.desk { flex: 1; display: grid; grid-template-columns: minmax(250px, 320px) 1fr; gap: 10px; padding: 10px; min-height: 0; }
.desk.with-decoder { grid-template-columns: minmax(250px, 300px) 1fr minmax(280px, 340px); }

.pane {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  display: flex; flex-direction: column; min-height: 0; min-width: 0; overflow: hidden;
}
.pane-title {
  display: flex; justify-content: space-between; align-items: center;
  padding: 7px 12px; border-bottom: 1px solid var(--line);
  font: 600 13px/1.4 var(--sans); letter-spacing: .14em; text-transform: uppercase; color: var(--muted);
}
.pane-title .muted { letter-spacing: .04em; text-transform: none; font-family: var(--mono); color: var(--dim); }
.x { background: none; border: 0; color: var(--muted); font-size: 18px; line-height: 1; padding: 0 2px; }

/* ---------- files ---------- */
.files { display: grid; grid-template-rows: auto minmax(120px, 42%) 1fr; }
.tree { overflow: auto; padding: 6px 0; font-size: 15px; }
.node {
  display: flex; align-items: center; gap: 6px; width: 100%;
  background: none; border: 0; text-align: left; padding: 3px 12px; color: var(--ink);
  white-space: nowrap;
}
.node:hover, .node:focus-visible { background: var(--panel2); outline: none; }
.node.sel { background: rgba(110,226,207,.08); color: var(--teal); }
.node .ic { width: 1.1em; text-align: center; color: var(--dim); flex: none; }
.node.dir .ic { color: var(--violet); }
.node.locked { color: var(--amber); }
.node.locked .ic { color: var(--amber); }
.node.fresh { animation: fresh 1.6s ease; }
@keyframes fresh { 0% { background: rgba(110,226,207,.25); } }
.node .tag { margin-left: auto; font-size: 12px; color: var(--dim); letter-spacing: .06em; }

.viewer { border-top: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.viewer-head { padding: 6px 12px; font-size: 13px; color: var(--dim); border-bottom: 1px solid var(--line); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewer-body { overflow: auto; padding: 12px; font-size: 14.5px; line-height: 1.6; }
.viewer-body pre { margin: 0; white-space: pre-wrap; word-break: break-word; }
.viewer-body pre.hexdump { word-break: break-all; color: var(--muted); }

.lockform { display: grid; gap: 10px; }
.lockform p { margin: 0; }
.lockform .row { display: flex; gap: 8px; }
.lockform input, .dec input, .dec select, .dec textarea {
  flex: 1; min-width: 0; background: #0b0916; border: 1px solid var(--line); color: var(--ink);
  border-radius: 6px; padding: 7px 9px; font: 15px var(--mono);
}
.lockform input:focus, .dec input:focus, .dec select:focus, .dec textarea:focus { outline: none; border-color: var(--teal); }
.btn, .lockform button, .dec button, .sheet-card button {
  background: var(--panel2); border: 1px solid var(--line2); color: var(--ink);
  border-radius: 6px; padding: 7px 12px; font-size: 14.5px;
}
.btn:hover, .lockform button:hover, .dec button:hover, .sheet-card button:hover { border-color: var(--teal); color: var(--teal); }
.lockform .err { color: var(--rose); font-size: 14px; min-height: 1.2em; }
.shake { animation: shake .35s ease; }
@keyframes shake { 20%, 60% { transform: translateX(-5px); } 40%, 80% { transform: translateX(5px); } }
.hintbox { border-left: 2px solid var(--amber); padding: 4px 10px; color: var(--muted); font-size: 14px; }

/* ---------- terminal ---------- */
.term { background: #0c0a17; }
.log { flex: 1; overflow-y: auto; padding: 12px 14px 4px; font-size: 15.5px; line-height: 1.6; }
.log .ln { white-space: pre-wrap; word-break: break-word; min-height: 1.6em; }
.log .in { color: var(--ink); }
.log .in .p { color: var(--teal); }
.log .out { color: #cfcae3; }
.log .sys { color: var(--muted); }
.log .err { color: var(--rose); }
.log .ok { color: var(--teal); }
.log .warn { color: var(--amber); }
.log .null { color: var(--violet); }
.log .null::before { content: "nullref  "; color: var(--dim); }
.log a.cmdlink { color: var(--teal); text-decoration: underline dotted; cursor: pointer; }
.prompt { display: flex; gap: 8px; align-items: center; padding: 8px 14px 12px; border-top: 1px solid #1b1730; }
.ps1 { color: var(--teal); white-space: nowrap; font-size: 15.5px; }
#cmd {
  flex: 1; min-width: 0; background: none; border: 0; color: var(--ink);
  font: 15.5px var(--mono); caret-color: var(--teal); outline: none; padding: 4px 0;
}

/* ---------- decoder ---------- */
.dec { padding: 12px; display: grid; gap: 10px; overflow: auto; font-size: 14.5px; }
.dec > label { display: flex; justify-content: space-between; align-items: center; gap: 8px; color: var(--muted); }
.dec > label select { flex: 0 1 60%; padding: 4px 6px; font-size: 14px; }
.dec textarea { resize: vertical; min-height: 70px; word-break: break-all; }
.dec-ops { display: flex; flex-wrap: wrap; gap: 6px; }
.dec-ops button.on { border-color: var(--teal); color: var(--teal); }
.dec-opt label { display: flex; align-items: center; gap: 8px; color: var(--muted); margin-bottom: 6px; }
.dec-opt label.check { gap: 6px; }
.dec-opt input[type=range] { flex: 1; accent-color: var(--teal); }
.dec-opt input[type=checkbox] { flex: none; accent-color: var(--teal); }
.dec-out {
  margin: 0; min-height: 60px; max-height: 200px; overflow: auto; padding: 8px 9px;
  background: #0b0916; border: 1px dashed var(--line2); border-radius: 6px;
  white-space: pre-wrap; word-break: break-all; color: var(--teal);
}
.dec-out.bad { color: var(--dim); }
.dec-actions { display: flex; gap: 6px; }
.dec .ghost, .sheet-card .ghost { background: none; }

/* ---------- tabs (mobile) ---------- */
.tabs { display: none; }

/* ---------- sheets ---------- */
.sheet { position: absolute; inset: 0; z-index: 20; display: grid; place-items: center; background: rgba(8,6,16,.72); padding: 20px; animation: fadein .4s ease; }
.sheet-card { background: var(--panel); border: 1px solid var(--line2); border-radius: 12px; padding: 22px; width: min(440px, 100%); display: grid; gap: 10px; }
.sheet-card h2 { margin: 0; font: 700 18px var(--sans); }
.sheet-card p { margin: 0; }
.sheet-card .danger { border-color: rgba(255,107,129,.5); color: var(--rose); }
.ending-card { width: min(520px, 100%); padding: 30px; text-align: left; }
.ending-card .kicker { font-size: 13px; letter-spacing: .3em; color: var(--violet); }
.ending-card h1 { margin: 2px 0 8px; font: 700 34px/1.1 var(--sans); letter-spacing: .01em; }
.ending-card .row { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }

/* ---------- atmosphere ---------- */
.crt {
  pointer-events: none; position: absolute; inset: 0; z-index: 40;
  background:
    repeating-linear-gradient(to bottom, rgba(0,0,0,0) 0 2px, rgba(0,0,0,.08) 2px 3px),
    radial-gradient(ellipse at center, rgba(0,0,0,0) 60%, rgba(0,0,0,.35));
}
.os.glitch .desk { animation: glitch .45s steps(3) 2; }
@keyframes glitch { 33% { transform: translateX(2px); filter: hue-rotate(40deg); } 66% { transform: translateX(-2px); } }

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

/* ---------- small screens: one app at a time ---------- */
@container term (max-width: 860px) {
  .host { display: none; }
  .bar { gap: 8px; padding: 8px 10px; }
  .relay { justify-content: flex-start; }
  #btn-decoder { display: none; }
  .desk, .desk.with-decoder { grid-template-columns: 1fr; padding: 8px; }
  .desk > .pane { display: none; }
  .desk[data-tab="term"] #pane-term,
  .desk[data-tab="files"] #pane-files,
  .desk[data-tab="decoder"] #pane-decoder { display: flex; }
  .desk[data-tab="files"] #pane-files { display: grid; }
  #pane-decoder[hidden] { display: none !important; }
  .desk[data-tab="decoder"] #pane-decoder[hidden] { display: flex !important; }
  .decoder .x { display: none; }
  .tabs {
    display: flex; border-top: 1px solid var(--line); background: #110e1f;
    padding-bottom: env(safe-area-inset-bottom);
  }
  .tabs button { flex: 1; background: none; border: 0; padding: 12px 4px; color: var(--muted); font: 600 14px var(--sans); letter-spacing: .1em; text-transform: uppercase; }
  .tabs button.on { color: var(--teal); box-shadow: inset 0 2px 0 var(--teal); }
  .tabs button.ping::after { content: ""; display: inline-block; width: 6px; height: 6px; margin-left: 6px; border-radius: 50%; background: var(--violet); vertical-align: middle; box-shadow: 0 0 6px var(--violet); }
  .log { font-size: 14.5px; }
}
