:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --ring: rgba(11, 11, 11, 0.10);
  --accent: #2a78d6;
  --good: #006300;
  --bad: #d03b3b;
  --warn-bg: #fff4d6;
  --cell: 34px;
  --cell-h: 40px;
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --ink: #ffffff;
  --ink-2: #c3c2b7;
  --muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --ring: rgba(255, 255, 255, 0.10);
  --accent: #3987e5;
  --good: #0ca30c;
  --bad: #e66767;
  --warn-bg: #3a3113;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
}
h1 { font-size: 17px; margin: 0; }
h2 { font-size: 13px; margin: 0 0 6px; color: var(--ink-2); text-transform: uppercase; letter-spacing: 0.04em; }

header {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--ring);
  position: sticky; top: 0; z-index: 20;
}
header .spacer { flex: 1; }
.btngroup { display: inline-flex; gap: 4px; padding: 0 8px; border-left: 1px solid var(--grid); }
.btngroup:first-of-type { border-left: none; }
.schedhead {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px 0;
  margin-bottom: 10px;
}
.schedhead h2 { margin: 0 12px 0 0; }
.schedhead .btngroup:first-of-type { border-left: none; padding-left: 0; }
label.ctl { display: inline-flex; align-items: center; gap: 5px; color: var(--ink-2); font-size: 13px; }
select, button, input[type="number"] {
  font: inherit; color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--axis); border-radius: 6px;
  padding: 4px 8px;
}
input[type="number"] { width: 58px; }
button { cursor: pointer; }
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
button:disabled { opacity: 0.45; cursor: default; }

main { display: grid; grid-template-columns: 1fr 320px; gap: 14px; padding: 14px 16px; align-items: start; }
main > div { min-width: 0; }
@media (max-width: 1000px) { main { grid-template-columns: 1fr; } }

.panel {
  background: var(--surface);
  border: 1px solid var(--ring); border-radius: 10px;
  padding: 12px 14px;
}
.blurb { color: var(--ink-2); margin: 6px 0 0; max-width: 72ch; }

/* ---- schedule grid ---- */
#gridwrap { overflow-x: auto; padding-bottom: 6px; }
#grid { position: relative; }
.timeaxis { display: flex; margin-left: 130px; }
.timeaxis span {
  width: var(--cell); flex: none; text-align: left; font-size: 10px;
  color: var(--muted); font-variant-numeric: tabular-nums;
  border-left: 1px solid var(--grid); padding-left: 2px;
}
.rankrow { display: flex; align-items: stretch; height: var(--cell-h); }
.rankhead {
  width: 130px; flex: none; display: flex; flex-direction: column; justify-content: center;
  padding: 0 8px; cursor: pointer; border-radius: 6px 0 0 6px;
  border: 1px solid transparent; font-size: 12px;
}
.rankhead .rname { font-weight: 600; }
.rankhead .rmeta { color: var(--muted); font-size: 11px; }
.rankrow.selected .rankhead { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, transparent); }
.lane {
  position: relative; flex: none;
  border-top: 1px solid var(--grid); border-bottom: 1px solid var(--grid);
  background-image: repeating-linear-gradient(to right, var(--grid) 0 1px, transparent 1px var(--cell));
}
.op {
  position: absolute; top: 4px; height: calc(var(--cell-h) - 9px);
  border-radius: 4px; border: 1.5px solid;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 600; cursor: default; user-select: none;
  box-shadow: 0 0 0 2px var(--surface);
}
.op.hatch {
  background-image: repeating-linear-gradient(45deg, transparent 0 4px, rgba(0,0,0,0.13) 4px 6px);
}
/* committed idles look like empty grid (bubbles are blank space, as in the
   papers) — they remain invisible hit targets for hover/click */
.op.idle { border: 1px solid transparent; background: transparent; box-shadow: none; }
.op.dim { opacity: 0.22; }
.op .stg, .opbtn .stg {
  font-size: 8px; font-weight: 700; opacity: 0.75;
  align-self: flex-start; margin: 1px 1px 0 0; line-height: 1;
}
.stg-demo { font-size: 9px; vertical-align: super; }
.rankrow .op { cursor: pointer; }

/* memory-over-time strip above each lane; bars grow down toward the lane */
.memrow { display: flex; height: 15px; margin-top: 3px; }
.memrow::before { content: "mem"; width: 130px; flex: none; font-size: 8px;
  color: var(--muted); text-align: right; padding-right: 8px; align-self: end; }
.memlane { position: relative; flex: none; }
.membar {
  position: absolute; bottom: 0; width: 32px;
  background: color-mix(in srgb, var(--accent) 45%, transparent);
}
.membar.atcap { background: color-mix(in srgb, var(--bad) 70%, transparent); }
.op.dep-up { outline: 2.5px solid var(--bad); outline-offset: 1px; z-index: 5; }
.op.dep-down { outline: 2.5px solid var(--good); outline-offset: 1px; z-index: 5; }
.op.ghost { opacity: 0.5; border-style: dashed; box-shadow: none; z-index: 6;
  -webkit-touch-callout: none; -webkit-user-select: none; touch-action: manipulation; }
.op.ghost.follow { opacity: 0.4; }
.op.ghost.follow:hover { opacity: 0.95; box-shadow: 0 0 0 2px var(--accent); }
.op.ghost.conflict {
  background: transparent; border: 1.5px dashed var(--muted); color: var(--muted);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; opacity: 0.6;
  position: absolute; top: 4px; height: calc(var(--cell-h) - 9px); border-radius: 4px;
}
.op.ghost.conflict:hover { opacity: 1; border-color: var(--ink-2); color: var(--ink-2); box-shadow: none; }
.frontier {
  position: absolute; top: 1px; bottom: 1px; width: 0;
  border-left: 2px solid var(--accent); z-index: 4;
}
.slot {
  position: absolute; top: 4px; height: calc(var(--cell-h) - 9px);
  width: calc(var(--cell) - 4px);
  border: 1.5px dashed var(--accent); border-radius: 4px;
  display: flex; align-items: center; justify-content: center;
  color: var(--accent); font-weight: 700; cursor: pointer;
  opacity: 0.55; z-index: 5; user-select: none;
}
.slot:hover, .slot.active { opacity: 1; background: color-mix(in srgb, var(--accent) 12%, transparent); }
.slot.future { opacity: 0; border-style: dotted; }
.slot.future:hover { opacity: 0.8; }
.slot.future:hover::after { content: "+"; }
.op.idle { cursor: pointer; }
.op.idle:hover { border-color: var(--accent); border-style: dashed; }

/* free-edit mode */
.op.crit { outline: 2.5px solid var(--ink); outline-offset: 1px; z-index: 7; }
.op.shoved { animation: shovedflash 1.2s 3; }
@keyframes shovedflash {
  0%, 100% { outline: 0 solid transparent; }
  50% { outline: 3px solid var(--bad); outline-offset: 1px; }
}
.op.future { opacity: 0.13; transition: opacity 0.25s; }
.op.running { outline: 2.5px solid var(--accent); outline-offset: 1px; z-index: 7;
  transition: outline-color 0.15s; }
#playcursor {
  position: absolute; top: 14px; bottom: 0; width: 0; z-index: 8;
  border-left: 2px solid var(--accent); pointer-events: none;
  transition: left 0.38s linear;
}
.op.violation { outline: 2.5px solid var(--bad); outline-offset: 1px; z-index: 7; }
.op.lifted { opacity: 0.45; border-style: dashed; box-shadow: 0 0 0 3px var(--accent); }
.op.strand { box-shadow: 0 0 0 2.5px var(--accent); z-index: 6; }
.strandbar {
  margin: 8px 0 0 130px; display: flex; align-items: center; gap: 6px;
  font-size: 12.5px; color: var(--ink-2);
}
.slot.dropcell { opacity: 0.15; border-style: dotted; z-index: 2; }
.slot.dropcell:hover { opacity: 0.9; background: color-mix(in srgb, var(--accent) 18%, transparent); }
.edittray {
  margin: 10px 0 6px 130px; padding: 8px; border: 1px dashed var(--axis);
  border-radius: 8px; display: flex; flex-wrap: wrap; align-items: center; gap: 2px;
}
.violations { margin: 6px 0 0 130px; font-size: 12.5px; color: var(--bad); }
.violations .beat { color: var(--good); }
.popover {
  position: fixed; z-index: 30; min-width: 230px; max-width: 460px;
  background: var(--surface); border: 1px solid var(--axis); border-radius: 10px;
  padding: 8px 12px; box-shadow: 0 6px 24px rgba(0,0,0,0.22);
}
.popover .kindgroup { display: flex; align-items: center; flex-wrap: wrap; }
.popover .kindlabel { min-width: 70px; }
.opbtn.pulse { animation: pulse 0.9s 2; }
@keyframes pulse {
  0%, 100% { transform: scale(1); box-shadow: none; }
  50% { transform: scale(1.15); box-shadow: 0 0 0 3px var(--accent); }
}
.cfgrow {
  display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: center;
  padding: 8px 16px; background: var(--surface);
  border-bottom: 1px solid var(--ring);
}
.rankrow.selected .frontier::after {
  content: "▶"; position: absolute; left: 1px; top: 50%;
  transform: translateY(-50%); font-size: 9px; color: var(--accent);
}

/* ---- picker ---- */
#picker .opbtn {
  display: inline-flex; align-items: center; gap: 4px;
  margin: 2px; padding: 3px 7px; border-radius: 5px; font-weight: 600; font-size: 12px;
  border-width: 1.5px; border-style: solid;
}
#picker .opbtn.notready { opacity: 0.4; }
#picker .opbtn.notready:hover { opacity: 0.8; }
#picker .kindgroup { margin: 6px 0; }
#picker .kindlabel { font-size: 11px; color: var(--muted); margin-right: 4px; }
.hint { font-size: 12px; color: var(--ink-2); margin-top: 8px; min-height: 2.6em; }

/* ---- stats ---- */
table.stats { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
table.stats td, table.stats th { padding: 3px 6px; text-align: right; font-size: 12.5px; border-bottom: 1px solid var(--grid); }
table.stats th { color: var(--muted); font-weight: 500; text-align: right; }
table.stats td:first-child, table.stats th:first-child { text-align: left; white-space: nowrap; }
table.stats .parcol { color: var(--muted); border-left: 1px solid var(--grid); }
.phase { font-size: 10px; padding: 1px 6px; border-radius: 8px; border: 1px solid var(--axis); color: var(--ink-2); }
.phase.warmup { border-color: var(--accent); color: var(--accent); }
.phase.steady { border-color: var(--good); color: var(--good); }
.phase.drain { border-color: #c98500; color: #c98500; }
.beat { color: var(--good); font-weight: 700; }
.miss { color: var(--bad); }

/* ---- log / toast ---- */
#log { max-height: 180px; overflow-y: auto; font-size: 12.5px; }
#log .entry { padding: 3px 0; border-bottom: 1px solid var(--grid); color: var(--ink-2); }
#log .entry.err { color: var(--bad); }
#log .entry.event { color: var(--ink); }
.status { font-size: 13px; margin-top: 8px; min-height: 1.4em; color: var(--ink-2); }
.status.err { color: var(--bad); font-weight: 600; }
.status.shake { animation: shake 0.3s; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

.banner {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  margin-top: 14px; padding: 12px 16px; border-radius: 10px;
  border: 1.5px solid var(--axis); background: var(--surface);
}
.banner.won { border-color: var(--good); }
.banner.missed { border-color: #c98500; }
.banner span { flex: 1; min-width: 200px; }

.goal { margin: 8px 0 0; font-weight: 600; color: var(--ink); }
.goal::before { content: "🎯 "; }
kbd {
  border: 1px solid var(--axis); border-bottom-width: 2px; border-radius: 4px;
  padding: 0 4px; font-size: 11px; background: var(--surface);
}
footer { padding: 8px 16px 20px; color: var(--muted); font-size: 12px; }
footer a { color: var(--accent); }
.footlinks { float: right; }
.papers { margin: 6px 0 0; font-size: 12.5px; color: var(--muted); }
.papers a { color: var(--accent); text-decoration: none; }
.papers a:hover { text-decoration: underline; }
