/* Communication Bottleneck. Layout: title with the three encoders; the training timeline (transport, phase jumps,
   scrubber, phase note); the network stage beside hidden codes, completion and code space; then the training curves
   and the settings. Every changing text has a fixed size, so nothing moves while the timeline plays. */
:root {
  color-scheme: dark;
  --bg: #080c14;
  --panel: #0d131e;
  --panel-2: #131b29;
  --line: #1b2536;
  --line-2: #2a3850;
  --fg: #e3e9f3;
  --muted: #8c98ad;
  --dim: #58647a;
  --cyan: #00f5ff;
  --crimson: #ff2a55;
  --amber: #ffb547;
  --green: #3dfc9b;
  --display: "Literata", "Iowan Old Style", Georgia, serif;
  --sans: "Instrument Sans", "Segoe UI", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
  --r: 6px;
}
[hidden] { display: none !important; }
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--fg); font: 14px/1.45 var(--sans); }
button, select, input { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }

.app { display: grid; gap: 12px; padding-block: 12px 20px;
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
.top { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px 24px; }
.eyebrow { font: 500 11px/1.2 var(--mono); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
h1 { margin: 4px 0 0; font: 600 24px/1.15 var(--display); text-wrap: balance; }
h1 span { display: block; margin-top: 3px; font: 400 13px/1.3 var(--sans); color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font: 12.5px var(--sans); padding: 5px 11px; border-radius: 999px; border: 1px solid var(--line-2); background: var(--panel); cursor: pointer; transition: border-color .15s, color .15s; }
.chip:hover { border-color: var(--cyan); }
.chip.on { border-color: var(--cyan); color: var(--cyan); background: rgba(0,245,255,.07); }
.note { margin: 0; font-size: 13.5px; color: #c6cfdf; max-width: 130ch; }
.note b { color: var(--fg); }

select, .btn { background: var(--panel-2); border: 1px solid var(--line-2); border-radius: var(--r); padding: 5px 9px; min-height: 32px; max-width: 100%; }
.btn { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; transition: border-color .15s; white-space: nowrap; }
.btn:hover { border-color: var(--cyan); }
.btn svg { width: 14px; height: 14px; flex: none; }
.btn.icon { padding: 5px 8px; }
.btn.sm { min-height: 26px; padding: 2px 9px; font-size: 12px; }
.btn.primary { background: rgba(0,245,255,.09); border-color: rgba(0,245,255,.5); color: var(--cyan); }
.seg { display: inline-flex; border: 1px solid var(--line-2); border-radius: var(--r); overflow: hidden; flex: none; }
.segb { background: var(--panel-2); border: 0; padding: 4px 10px; font: 12px var(--mono); cursor: pointer; color: var(--muted); white-space: nowrap; }
.segb + .segb { border-left: 1px solid var(--line-2); }
.segb.on { background: rgba(0,245,255,.12); color: var(--cyan); }

.card { border: 1px solid var(--line); border-radius: 8px; background: rgba(13,19,30,.92); padding: 10px 12px 12px; display: grid; gap: 8px; min-width: 0; align-content: start; }
.card-h { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px 12px; }
.sec-h { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; margin: 0; font: 500 11px var(--mono); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.sec-h em { font-style: normal; text-transform: none; letter-spacing: 0; color: var(--dim); }
.cap { margin: 0; font: 11.5px/1.45 var(--mono); color: var(--dim); }
.cap .k { font-size: 13px; }
.k.c1 { color: var(--green); } .k.c2 { color: var(--cyan); } .k.c3 { color: var(--crimson); }
.tag { white-space: nowrap; font: 500 11.5px var(--mono); color: var(--muted); padding: 3px 8px; border-radius: 4px; border: 1px solid var(--line-2); font-variant-numeric: tabular-nums; }
.tag:empty { visibility: hidden; }
.tag.good { color: var(--green); border-color: rgba(61,252,155,.5); }
.tag.warn { color: var(--amber); border-color: rgba(255,181,71,.5); }
.tag.bad { color: var(--crimson); border-color: rgba(255,42,85,.5); }
canvas { display: block; width: 100%; border-radius: 6px; border: 1px solid var(--line); background: #05080e; }

/* timeline */
.tr-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; }
.spacer { flex: 1; }
.phase-btns { display: flex; flex-wrap: wrap; gap: 6px; }
.phase-btns .btn { font-size: 12.5px; min-height: 30px; }
.phase-btns .btn.on { border-color: var(--cyan); color: var(--cyan); }
.clock { font: 500 12.5px var(--mono); color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; min-width: 26ch; text-align: right; }
.clock b { color: var(--cyan); font-weight: 600; display: inline-block; min-width: 4ch; text-align: right; }
.clock .trained { display: inline-block; min-width: 13ch; color: var(--amber); }
.scrub { position: relative; height: 40px; }
#cvStrip { position: absolute; inset: 0 0 auto 0; height: 26px; }
#scrub { position: absolute; left: 0; right: 0; bottom: 0; width: 100%; }
input[type=range] { -webkit-appearance: none; appearance: none; background: transparent; height: 18px; margin: 0; }
input[type=range]::-webkit-slider-runnable-track { height: 4px; border-radius: 2px; background: var(--line-2); }
input[type=range]::-moz-range-track { height: 4px; border-radius: 2px; background: var(--line-2); }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 15px; height: 15px; margin-top: -5.5px; border-radius: 50%; background: var(--fg); border: 2px solid var(--bg); box-shadow: 0 0 0 1px var(--cyan), 0 0 10px rgba(0,245,255,.6); }
input[type=range]::-moz-range-thumb { width: 13px; height: 13px; border-radius: 50%; background: var(--fg); border: 2px solid var(--bg); }
.phase-note { display: grid; grid-template-columns: 230px minmax(0, 1fr); gap: 4px 14px; align-items: start; min-height: calc(2 * 1.45em + 2px); font-size: 13px; color: #c6cfdf; }
.phase-note b { color: var(--cyan); font-weight: 600; white-space: nowrap; }
.phase-note span { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; height: calc(2 * 1.45em); }

/* stage */
.main { display: grid; grid-template-columns: minmax(0, 1fr) 390px; gap: 12px; align-items: start; }
.stage-wrap { position: relative; }
#cvStage { height: 560px; cursor: crosshair; background: radial-gradient(110% 90% at 50% 50%, #0b1424 0%, #04070c 72%); }
.tip { position: absolute; pointer-events: none; z-index: 2; padding: 7px 9px; border-radius: 6px; border: 1px solid var(--line-2); background: rgba(8,12,20,.95); font: 12px/1.5 var(--mono); white-space: nowrap; box-shadow: 0 6px 18px rgba(0,0,0,.5); }
.tip b { color: var(--cyan); font-weight: 600; }
.stage-foot { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px 12px; font: 12px var(--mono); font-variant-numeric: tabular-nums; }
.stage-foot div { display: grid; gap: 1px; min-width: 0; }
.stage-foot span { color: var(--dim); font-size: 10.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stage-foot b { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stage-foot .ok { color: var(--green); } .stage-foot .no { color: var(--crimson); } .stage-foot .run { color: var(--cyan); }

/* side */
.side { display: grid; gap: 12px; min-width: 0; }
.codes { display: grid; gap: 3px; font: 12.5px var(--mono); font-variant-numeric: tabular-nums; }
.codes .cr { display: grid; grid-template-columns: 88px auto minmax(0, 1fr) 44px; gap: 10px; align-items: center; padding: 3px 7px; border-radius: 4px; border: 1px solid transparent; }
.codes .cr span { color: var(--muted); white-space: nowrap; }
.codes .cr .bits { display: inline-flex; gap: 4px; }
.codes .cr .bits i { width: 13px; height: 13px; border-radius: 50%; border: 1.5px solid rgba(0,245,255,.6); }
.codes .cr .bits i.on { background: var(--cyan); box-shadow: 0 0 7px rgba(0,245,255,.8); }
.codes .cr code { font: inherit; color: var(--fg); }
.codes .cr em { font-style: normal; color: var(--dim); text-align: right; }
.codes .cr.clash { border-color: rgba(255,181,71,.45); background: rgba(255,181,71,.07); }
.codes .cr.clash code { color: var(--amber); }
.codes.solved .cr { border-color: rgba(61,252,155,.3); background: rgba(61,252,155,.05); }
.codes.solved .cr code { color: var(--green); text-shadow: 0 0 8px rgba(61,252,155,.4); }

.acc { display: grid; gap: 8px; }
.acc-bar { position: relative; height: 12px; border-radius: 6px; background: var(--panel-2); border: 1px solid var(--line); overflow: hidden; }
.acc-bar i { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 6px; background: linear-gradient(90deg, rgba(0,245,255,.4), var(--cyan)); }
.acc-row { display: grid; gap: 4px; font: 11.5px var(--mono); }
.acc-row .ar { display: grid; grid-template-columns: 70px minmax(0, 1fr) 40px; gap: 8px; align-items: center; }
.acc-row .ar span { color: var(--muted); }
.acc-row .ar b { text-align: right; font-weight: 500; }
.acc-row .ar .t { height: 6px; border-radius: 3px; background: var(--panel-2); overflow: hidden; }
.acc-row .ar .t i { display: block; height: 100%; background: var(--cyan); opacity: .75; }
.acc-row.many { grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 14px; }

.tele-grid { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 12px; align-items: start; }
.tele-grid.stack { grid-template-columns: minmax(0, 1fr); }
.ham { display: grid; gap: 2px; font: 10.5px var(--mono); align-content: start; }
.ham div { width: 20px; height: 20px; display: grid; place-items: center; border-radius: 3px; font-variant-numeric: tabular-nums; }
.ham .h0 { background: rgba(255,42,85,.3); color: #ffd0da; }
.ham .h1 { background: rgba(255,181,71,.22); color: var(--amber); }
.ham .h2 { background: rgba(61,252,155,.16); color: var(--green); }
.ham .hd { background: var(--panel-2); color: var(--dim); }
.ham .hl { color: var(--dim); background: none; }
.kv { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 3px 10px; font: 12px var(--mono); font-variant-numeric: tabular-nums; }
.kv span { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kv b { font-weight: 500; text-align: right; white-space: nowrap; }
.kv .good { color: var(--green); } .kv .bad { color: var(--crimson); } .kv .exc { color: var(--cyan); }

/* lower */
.lower { display: grid; grid-template-columns: minmax(0, 1fr) 390px; gap: 12px; align-items: start; }
#cvCurve { height: 230px; }
.ctl { display: grid; gap: 8px; }
.ctl .row { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 13px; }
.ctl .row b { font: 500 12.5px var(--mono); color: var(--cyan); font-variant-numeric: tabular-nums; }
.ctl select { min-height: 28px; padding: 2px 6px; font-size: 12.5px; }
.seed { display: inline-flex; align-items: center; gap: 8px; }
.seed b { font: 500 12.5px var(--mono); color: var(--muted) !important; }
.switch { display: inline-flex; align-items: center; gap: 9px; cursor: pointer; font-size: 13px; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch i { width: 32px; height: 18px; border-radius: 9px; background: var(--line-2); position: relative; transition: background .15s; flex: none; }
.switch i::after { content: ""; position: absolute; left: 3px; top: 3px; width: 12px; height: 12px; border-radius: 50%; background: var(--fg); transition: transform .15s; }
.switch input:checked + i { background: var(--cyan); }
.switch input:checked + i::after { transform: translateX(14px); }
.switch:has(input:focus-visible) { outline: 2px solid var(--cyan); outline-offset: 2px; border-radius: 4px; }
#ctlCap { min-height: calc(3 * 1.45em); }

@media (max-width: 1100px) {
  .main, .lower { grid-template-columns: minmax(0, 1fr); }
  .side { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
}
@media (max-width: 720px) {
  h1 { font-size: 20px; }
  #cvStage { height: 430px; }
  .phase-note { grid-template-columns: minmax(0, 1fr); }
  .phase-note span { -webkit-line-clamp: 4; height: calc(4 * 1.45em); }
  .clock { text-align: left; }
  .stage-foot { grid-template-columns: minmax(0, 1fr); }
}
.pg-embedded .top > div:first-child { display: none; }
@media (prefers-reduced-motion: reduce) { .btn, .chip, .switch i, .switch i::after { transition: none; } }
