:root {
  color-scheme: dark;
  --bg: #0b1020;
  --bg-deep: #070a14;
  --panel: #0f1529;
  --raised: #171f3a;
  --line: #26304f;
  --ink: #e6edf3;
  --ink-2: #9fb0c3;
  --ink-3: #6f8094;
  --accent: #64ffda;
  --attract: #3987e5;
  --repel: #e66767;
  --panel-w: 348px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg-deep); color: var(--ink);
  font: 12px/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
#world { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: crosshair; }
#world.panning { cursor: grabbing; }

#hud { position: fixed; left: 10px; top: 8px; padding: 5px 9px; border-radius: 6px; background: rgba(7,10,20,.72); pointer-events: none; }
#hud-title { font-size: 18px; letter-spacing: -0.02em; font-weight: 600; }
.accent { color: var(--accent); }
#hud-stats { color: var(--ink-2); margin-top: 2px; white-space: pre-wrap; }
#hud-help { color: var(--ink-3); margin-top: 2px; }

#panel { position: fixed; right: 0; top: 0; bottom: 0; width: var(--panel-w); background: var(--panel);
  border-left: 1px solid var(--line); overflow-y: auto; overscroll-behavior: contain; padding: 0 0 40px; scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
#panel.closed { display: none; }
#panel-toggle { position: fixed; right: 10px; top: 8px; z-index: 5; }
#motion { position: fixed; left: 10px; bottom: 10px; max-width: min(320px, calc(100vw - 20px)); }
#motion-note { margin: 0 0 6px; padding: 5px 9px; border-radius: 6px; background: rgba(7,10,20,.85); color: var(--ink); }
#motion-note[hidden] { display: none; }

button, select { font: inherit; color: var(--ink); background: var(--raised); border: 1px solid var(--line); border-radius: 5px; padding: 4px 9px; cursor: pointer; }
button:hover, select:hover { border-color: var(--ink-3); }
button:focus-visible, select:focus-visible, input:focus-visible, summary:focus-visible, .cell:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
button.on { background: var(--accent); border-color: var(--accent); color: #06221b; font-weight: 600; }
button[disabled] { opacity: .4; cursor: default; }

.transport { position: sticky; top: 0; z-index: 2; display: flex; flex-wrap: wrap; gap: 5px; padding: 8px 88px 8px 12px; background: var(--panel); border-bottom: 1px solid var(--line); }
.transport + details { border-top: 0; }
details { border-top: 1px solid var(--line); }
summary { cursor: pointer; padding: 8px 12px; font-weight: 600; font-size: 13px; list-style-position: inside; user-select: none; }
summary:hover { background: var(--raised); }
.body { padding: 2px 12px 12px; }

.hint { color: var(--ink-3); margin: 4px 0 8px; }
.hint.warn { color: #fab219; }
.blurb { color: var(--ink-2); margin: 8px 0 0; min-height: 3em; }
.sub { color: var(--ink-2); font-weight: 600; margin: 12px 0 4px; }

.preset-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; }
.preset-grid button { text-align: left; padding: 4px 7px; }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; margin-bottom: 8px; }
.seg button { padding: 4px 2px; }
.row-btns { display: flex; flex-wrap: wrap; gap: 4px; margin: 6px 0; }

.slider { display: grid; grid-template-columns: 1fr auto; column-gap: 8px; margin: 5px 0; align-items: baseline; }
.slider .val { color: var(--ink); font-variant-numeric: tabular-nums; }
.slider label { color: var(--ink-2); }
.slider input[type=range] { grid-column: 1 / 3; width: 100%; margin: 2px 0 0; accent-color: var(--accent); height: 16px; }
.select-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; margin: 5px 0; }
.select-row label { color: var(--ink-2); }
.check { display: flex; align-items: center; gap: 6px; margin: 5px 0; color: var(--ink-2); }
.check input { accent-color: var(--accent); margin: 0; }

canvas.widget { display: block; width: 100%; border-radius: 5px; background: var(--bg); touch-action: none; }
#graph { height: 280px; cursor: default; }
.graph-read { min-height: 2.9em; color: var(--ink-2); margin: 5px 0 2px; }

.matrix { display: grid; gap: 2px; margin: 8px 0 4px; }
.matrix .head { display: flex; align-items: center; justify-content: center; font-weight: 700; color: #fff; border-radius: 3px; height: 24px; }
.matrix .blank { height: 24px; }
.matrix .rowname { color: var(--ink-3); font-size: 11px; display: flex; align-items: center; justify-content: flex-end; padding-right: 3px; }
.cell { height: 24px; border-radius: 3px; display: flex; align-items: center; justify-content: center; font-size: 10px; font-variant-numeric: tabular-nums; color: var(--ink); cursor: ns-resize; touch-action: none; user-select: none; }

.card { border: 1px solid var(--line); border-radius: 6px; padding: 8px; margin-bottom: 8px; }
.card-top { display: grid; grid-template-columns: 124px 1fr; gap: 9px; }
.card canvas { width: 124px; height: 124px; cursor: pointer; }
.card .slider { margin: 2px 0; }
.card-name { display: flex; justify-content: space-between; align-items: center; margin-bottom: 5px; color: var(--ink-2); }
.card-name button { padding: 1px 6px; }
.typepick { display: flex; flex-wrap: wrap; gap: 3px; margin: 5px 0; align-items: center; }
.typepick button { width: 24px; height: 24px; padding: 0; color: #fff; font-weight: 700; border-width: 2px; border-color: transparent; }
.typepick button.on { border-color: #fff; }
.typepick span { color: var(--ink-2); margin-right: 4px; }

.chart-title { color: var(--ink-2); margin: 10px 0 2px; font-weight: 600; }
.legend { display: flex; flex-wrap: wrap; gap: 3px 12px; color: var(--ink-2); margin-bottom: 3px; }
.legend i { display: inline-block; width: 12px; height: 2px; vertical-align: middle; margin-right: 4px; border-radius: 1px; }
canvas.chart { height: 92px; }
canvas.curve { height: 110px; }
table.ledger { width: 100%; border-collapse: collapse; margin-top: 8px; font-variant-numeric: tabular-nums; }
table.ledger th { text-align: left; font-weight: 400; color: var(--ink-2); padding: 2px 0; }
table.ledger td { text-align: right; padding: 2px 0; }
table.ledger tr { border-top: 1px solid var(--line); }
table.ledger caption { text-align: left; color: var(--ink-3); padding-bottom: 3px; }

#tooltip { position: fixed; z-index: 10; pointer-events: none; display: none; background: var(--raised); border: 1px solid var(--line); border-radius: 5px; padding: 4px 8px; white-space: pre; font-variant-numeric: tabular-nums; }
#toast { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); background: var(--raised); border: 1px solid var(--accent); border-radius: 6px; padding: 6px 12px; opacity: 0; transition: opacity .2s; pointer-events: none; }
#toast.show { opacity: 1; }
#noscript { position: fixed; inset: 40% 0 auto; text-align: center; }

@media (max-width: 760px) {
  #panel { left: 0; width: auto; top: auto; height: 62%; border-left: 0; border-top: 1px solid var(--line); }
  .transport { padding-right: 12px; }
  #hud-help { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  #toast { transition: none; }
}
