/* TX-2 console: grey-green enamel, cream silk-screen, incandescent lamps. Fits one viewport. */
:root {
  --enamel: #34403b; --enamel-hi: #44524c; --enamel-lo: #252e2a; --well: #1a201d;
  --silk: #e9dfc5; --silk-dim: #a99f86; --lamp-off: #3b2c16; --lamp: #ffb43a; --lamp-glow: #ff9d1a;
  --red: #b8392c; --green-lamp: #8dff6a; --mono: ui-monospace, "SF Mono", "Cascadia Mono", "DejaVu Sans Mono", Menlo, monospace;
  --sans: "Helvetica Neue", Helvetica, Arial, "PingFang SC", "Noto Sans CJK SC", sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #111613; color: var(--silk); font: 13px/1.35 var(--sans); }
button, input, select, textarea { font: inherit; color: inherit; }
#app { height: 100dvh; display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }

/* Header bar */
.bar { display: flex; align-items: center; gap: 12px; padding: 6px 12px; overflow: hidden; background: linear-gradient(#3d4a44, #2b3531); border-bottom: 2px solid #161b18; box-shadow: 0 2px 6px #0008; }
.brand { display: flex; align-items: baseline; gap: 10px; flex: none; }
.plate { font: 700 20px/1 var(--sans); letter-spacing: .12em; padding: 4px 10px; color: #1f2622; background: linear-gradient(#efe6cd, #cfc4a6); border-radius: 3px; box-shadow: inset 0 -2px #a99f86, 0 1px 2px #000; }
.sub { font-size: 10px; letter-spacing: .25em; color: var(--silk-dim); }
.status { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; font-family: var(--mono); font-size: 12px; overflow: hidden; white-space: nowrap; }
.bar-actions { display: flex; gap: 6px; }
.readout { font-family: var(--mono); padding: 2px 6px; background: #0d110f; border: 1px solid #000; border-radius: 2px; color: #ffcf7a; box-shadow: inset 0 1px 3px #000; }
.readout.dim { color: var(--silk-dim); }
.readout.small { font-size: 11px; }

/* Lamps */
.lamp { width: 14px; height: 14px; border-radius: 50%; display: inline-block; flex: none; background: radial-gradient(circle at 35% 35%, #5a4528, var(--lamp-off)); box-shadow: inset 0 0 2px #000, 0 0 0 2px #1a1a16; }
.lamp.on { background: radial-gradient(circle at 35% 35%, #fff4c9, var(--lamp) 45%, #c46a00); box-shadow: 0 0 8px 2px var(--lamp-glow), 0 0 0 2px #1a1a16; }
.lamp.red.on { background: radial-gradient(circle at 35% 35%, #ffd6cc, #ff4a2e 45%, #8a1508); box-shadow: 0 0 8px 2px #ff3b1c, 0 0 0 2px #1a1a16; }
.lamp.green.on { background: radial-gradient(circle at 35% 35%, #f0ffe0, var(--green-lamp) 45%, #2f8a12); box-shadow: 0 0 8px 2px #6aff3a, 0 0 0 2px #1a1a16; }
.lamp.small { width: 10px; height: 10px; }

/* Keys and switches */
.key { cursor: pointer; padding: 6px 10px; border: 0; border-radius: 3px; font: 600 11px/1 var(--sans); letter-spacing: .08em; color: #1f2622; background: linear-gradient(#f3ead2, #cbbf9f); box-shadow: 0 2px 0 #7d735c, 0 3px 4px #0008; touch-action: manipulation; user-select: none; }
.key:active, .key.held { transform: translateY(2px); box-shadow: 0 0 0 #7d735c, 0 1px 2px #0008; }
.key.red { background: linear-gradient(#e0614f, #a52a1d); color: #fff1e6; box-shadow: 0 2px 0 #5e140c, 0 3px 4px #0008; }
.key.dark { background: linear-gradient(#56645d, #3a4540); color: var(--silk); box-shadow: 0 2px 0 #1b211e, 0 3px 4px #0008; }
.key.lit { background: linear-gradient(#ffe6a6, #ffb43a); box-shadow: 0 2px 0 #8a5a10, 0 0 10px #ff9d1a88; }
.key.small { padding: 4px 8px; font-size: 10px; }
.key:disabled { opacity: .45; cursor: default; }

.toggles { display: flex; flex-wrap: nowrap; gap: 2px; }
.toggles .group { display: flex; gap: 2px; padding: 3px 4px 2px; border-radius: 3px; }
.toggles .group:nth-child(odd) { background: #ffffff0c; }
.tg { width: 15px; height: 26px; position: relative; cursor: pointer; flex: none; border-radius: 3px; background: linear-gradient(#141815, #2a302c); box-shadow: inset 0 1px 2px #000; touch-action: manipulation; }
.tg::after { content: ""; position: absolute; left: 3px; right: 3px; height: 13px; top: 11px; border-radius: 3px 3px 5px 5px; background: linear-gradient(90deg, #8d877a, #f0ead8 45%, #9d9686); box-shadow: 0 2px 2px #000a; transition: top .08s; }
.tg.on::after { top: 2px; border-radius: 5px 5px 3px 3px; }
.tg.meta::after { background: linear-gradient(90deg, #8a3a2a, #ff8c6a 45%, #9a3a28); }
.bitlabels { display: flex; gap: 2px; font: 8px var(--mono); color: var(--silk-dim); }

/* Scope */
.deck { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 10px; padding: 10px; min-height: 0; }
.scope-bay { display: flex; flex-direction: column; gap: 6px; width: min(calc(100dvh - 110px), 60vw); min-width: 0; }
.bezel { padding: 12px; border-radius: 14px; background: radial-gradient(circle at 30% 20%, #4a5852, #222b27); box-shadow: inset 0 0 0 2px #121614, inset 0 4px 8px #ffffff12, 0 6px 14px #000a; }
.crt { position: relative; aspect-ratio: 1; border-radius: 9% / 9%; overflow: hidden; background: #030604; box-shadow: inset 0 0 40px #000, 0 0 0 3px #090c0a; }
.crt canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
#glow { filter: blur(6px) brightness(1.6); mix-blend-mode: screen; }
#overlay { cursor: crosshair; touch-action: none; }
.glass { position: absolute; inset: 0; pointer-events: none; background: radial-gradient(ellipse at 35% 25%, #ffffff10, transparent 40%), radial-gradient(ellipse at center, transparent 60%, #000a 100%); }
.effects .glass { background: radial-gradient(ellipse at 35% 25%, #ffffff14, transparent 40%), repeating-linear-gradient(transparent 0 2px, #00000018 2px 3px), radial-gradient(ellipse at center, transparent 58%, #000c 100%); }
.boot { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; padding: 20px; color: #c8ff7a; font-family: var(--mono); text-shadow: 0 0 8px #6aff3a; pointer-events: none; white-space: pre-line; }
.boot.hidden { display: none; }
.scope-strip { display: flex; align-items: center; gap: 8px; padding: 4px 6px; background: var(--enamel-lo); border-radius: 4px; }
.spacer { flex: 1; }

/* Side panel with tabs */
.panel { display: grid; grid-template-rows: auto minmax(0, 1fr); min-height: 0; min-width: 0; background: linear-gradient(var(--enamel-hi), var(--enamel)); border-radius: 8px; box-shadow: inset 0 0 0 1px #ffffff10, 0 6px 14px #0009; overflow: hidden; }
.tabs { display: flex; gap: 2px; padding: 6px 6px 0; background: var(--enamel-lo); overflow-x: auto; scrollbar-width: none; }
.tabs button { flex: 1 0 auto; padding: 8px 12px; border: 0; border-radius: 6px 6px 0 0; background: #1f2622; color: var(--silk-dim); font: 600 12px var(--sans); letter-spacing: .06em; cursor: pointer; }
.tabs button.active { background: var(--enamel-hi); color: var(--silk); }
.pages { min-height: 0; overflow: auto; padding: 10px; overscroll-behavior: contain; }
.page { display: none; flex-direction: column; gap: 10px; min-height: 100%; }
.page.active { display: flex; }
.subtabs { display: flex; gap: 4px; }
.subtabs button { padding: 4px 10px; border-radius: 12px; border: 1px solid #ffffff22; background: transparent; color: var(--silk-dim); cursor: pointer; font-size: 12px; }
.subtabs button.active { background: var(--silk); color: #1f2622; }
.sub-page { display: none; flex-direction: column; gap: 10px; }
.sub-page.active { display: flex; }

/* Sections */
fieldset { margin: 0; padding: 8px 10px 10px; border: 1px solid #ffffff1c; border-radius: 6px; background: #00000014; min-width: 0; }
legend { padding: 0 6px; font: 700 10px var(--sans); letter-spacing: .2em; color: var(--silk-dim); text-transform: uppercase; }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.label { font: 600 10px var(--sans); letter-spacing: .12em; color: var(--silk-dim); text-transform: uppercase; }
.hint { color: var(--silk-dim); font-size: 12px; }
input[type=text], input[type=number], select, textarea { background: #0d110f; border: 1px solid #000; border-radius: 3px; padding: 5px 7px; color: #ffcf7a; font-family: var(--mono); box-shadow: inset 0 1px 3px #000; }
input.octal { width: 9.5em; }
textarea { width: 100%; resize: vertical; min-height: 60px; }
input[type=range] { accent-color: #ffb43a; }
label.check { display: inline-flex; gap: 6px; align-items: center; cursor: pointer; }

/* Registers */
.regs { display: grid; grid-template-columns: auto 1fr auto; gap: 3px 8px; align-items: center; font-family: var(--mono); }
.regs .name { font: 700 11px var(--sans); color: var(--silk); width: 1.6em; }
.lamprow { display: flex; gap: 2px; flex-wrap: nowrap; overflow: hidden; }
.lamprow .q { display: flex; gap: 2px; padding: 0 3px; }
.lamprow .q:nth-child(odd) { background: #ffffff08; border-radius: 2px; }
.lamprow .lamp { width: 8px; height: 8px; box-shadow: inset 0 0 1px #000; }
.lamprow .lamp.on { box-shadow: 0 0 4px 1px var(--lamp-glow); }
.regs .val { color: #ffcf7a; font-size: 12px; }
.alarms { display: grid; grid-template-columns: repeat(auto-fill, minmax(62px, 1fr)); gap: 6px; }
.alarm { display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 5px 2px; border-radius: 4px; background: #00000030; cursor: pointer; font: 600 9px var(--sans); letter-spacing: .08em; user-select: none; }
.alarm .sup { font-size: 8px; color: var(--silk-dim); }
.alarm.suppressed .sup { color: #ffcf7a; }
.units { display: flex; flex-wrap: wrap; gap: 4px 10px; font: 10px var(--mono); color: var(--silk-dim); }
.units span { display: inline-flex; align-items: center; gap: 4px; }

/* Tape */
.library { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 8px; }
.tape-card { display: flex; flex-direction: column; gap: 6px; padding: 8px; border-radius: 6px; background: linear-gradient(#f2e9cf, #dccfab); color: #2a2a22; box-shadow: 0 2px 4px #0008; }
.tape-card h4 { margin: 0; font-size: 13px; }
.tape-card .kind { font-size: 10px; letter-spacing: .1em; color: #6c6047; }
.tape-card p { margin: 0; font-size: 11.5px; color: #4a4434; }
.tape-card .row { margin-top: auto; }
.tape-card .key { background: linear-gradient(#56645d, #3a4540); color: var(--silk); box-shadow: 0 2px 0 #1b211e; }
.strip { width: 100%; height: 74px; display: block; border-radius: 3px; background: #0c0f0d; }
.progress { height: 6px; background: #0d110f; border-radius: 3px; overflow: hidden; }
.progress > div { height: 100%; width: 0; background: linear-gradient(90deg, #ffb43a, #ffd88a); }
.mono-out { font: 11px/1.4 var(--mono); white-space: pre; overflow: auto; max-height: 40vh; padding: 6px; background: #0d110f; border-radius: 3px; color: #d8cfb4; }
table.blocks { border-collapse: collapse; font: 11px var(--mono); }
table.blocks td, table.blocks th { padding: 2px 8px; border-bottom: 1px solid #ffffff14; text-align: left; }

/* Typewriter */
.paper-wrap { flex: 1; min-height: 120px; display: flex; flex-direction: column; border-radius: 4px; overflow: hidden; box-shadow: 0 3px 8px #000a; }
.platen { height: 10px; background: linear-gradient(#111, #3a3a3a 40%, #111); }
.paper { flex: 1; overflow: auto; padding: 10px 14px; background: repeating-linear-gradient(#f6f0de 0 22px, #ece4cc 22px 23px); color: #1c1c1c; font: 15px/23px "Courier New", Courier, var(--mono); white-space: pre-wrap; word-break: break-all; }
.paper .red { color: #c0281c; }
.paper .special { font-size: 10px; color: #7a6a4a; border: 1px solid #b8a880; border-radius: 2px; padding: 0 2px; margin: 0 1px; }
.paper .caret { position: absolute; width: 1ch; height: 1em; margin-top: 4px; background: #1c1c1c55; animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.lw-keys { display: flex; flex-wrap: wrap; gap: 4px; }

/* External register box and knobs */
.pushbox { display: grid; grid-template-columns: repeat(9, minmax(0, 1fr)); gap: 4px; }
.pb { aspect-ratio: 1.15; min-width: 0; border: 0; border-radius: 50% 50% 46% 46%; cursor: pointer; font: 600 9px var(--mono); color: #2a2a22; background: radial-gradient(circle at 40% 30%, #fff8e4, #d8ccaa 60%, #a89c7c); box-shadow: 0 3px 0 #6c624c, 0 4px 5px #0008; touch-action: none; user-select: none; position: relative; }
.pb.on { transform: translateY(3px); box-shadow: 0 0 0 #6c624c, 0 0 10px #ffb43a; background: radial-gradient(circle at 40% 30%, #fff1c0, #ffbf4a 60%, #c27a10); }
.pb .tag { position: absolute; left: 0; right: 0; bottom: -2px; font: 700 8px var(--sans); color: #9c2a1c; }
.knobs { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.knob { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.knob .dial { width: min(70px, 18vw); aspect-ratio: 1; border-radius: 50%; cursor: ns-resize; touch-action: none; background: radial-gradient(circle at 40% 35%, #5d6a63, #222a26 70%); box-shadow: 0 0 0 4px #121614, 0 4px 8px #000a, inset 0 2px 3px #ffffff22; position: relative; }
.knob .dial::after { content: ""; position: absolute; left: 50%; top: 8%; width: 4px; height: 30%; margin-left: -2px; border-radius: 2px; background: var(--silk); transform-origin: 50% 140%; transform: rotate(var(--angle, 0deg)); }

/* Toast */
.toast { position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%); padding: 8px 14px; border-radius: 4px; background: #000d; color: var(--silk); font-size: 13px; opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 10; max-width: 90vw; }
.toast.show { opacity: 1; }

/* Portrait / phones: scope on top, panel fills the rest. */
@media (max-aspect-ratio: 1/1) {
  .deck { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); padding: 6px; gap: 6px; }
  .scope-bay { width: min(100%, calc(48dvh - 30px)); margin: 0 auto; }
  .bezel { padding: 6px; border-radius: 10px; }
  .sub, .bar .readout.dim { display: none; }
  .bar { gap: 6px; padding: 5px 6px; }
  .status { gap: 5px; font-size: 11px; }
  .bar-actions .key { padding: 5px 6px; font-size: 10px; }
  .plate { font-size: 16px; }
  .key { padding: 6px 8px; }
  .pages { padding: 8px; }
}
@media (max-width: 520px) {
  .lamprow { display: none; }
  .regs { grid-template-columns: auto 1fr; }
  .tg { width: 13px; height: 22px; }
  .tg::after { height: 11px; top: 9px; }
  .toggles { flex-wrap: wrap; }
}
@media (max-width: 520px) {
  .pb { aspect-ratio: 1.6; font-size: 8px; }
  .pushbox { gap: 3px; }
  .knob .dial { width: min(54px, 16vw); }
}
@media (max-width: 520px) { .regs { grid-template-columns: repeat(2, auto 1fr); } }
