/* Theme tokens: every colour on the page comes from here. Light by default, dark by data-theme or the OS. */
:root {
  --tok-bg: hsl(40 20% 97%);
  --tok-surface: hsl(0 0% 100%);
  --tok-surface-2: hsl(40 15% 93%);
  --tok-text: hsl(220 15% 15%);
  --tok-muted: hsl(220 10% 45%);
  --tok-line: hsl(220 10% 85%);
  --tok-accent: hsl(355 80% 48%);
  --tok-accent-text: hsl(0 0% 100%);
  --tok-built: hsl(145 55% 38%);
  --tok-tray: hsl(40 90% 45%);
  --tok-partial: hsl(210 70% 48%);
  --tok-focus: hsl(210 90% 55%);
  --tok-shadow: hsl(220 20% 10% / 0.15);
  --radius: 10px;
  --tap: 44px;
  color-scheme: light;
}
[data-theme="dark"] {
  --tok-bg: hsl(220 15% 10%);
  --tok-surface: hsl(220 14% 14%);
  --tok-surface-2: hsl(220 12% 19%);
  --tok-text: hsl(40 20% 92%);
  --tok-muted: hsl(220 10% 62%);
  --tok-line: hsl(220 10% 28%);
  --tok-accent: hsl(355 80% 58%);
  --tok-accent-text: hsl(0 0% 100%);
  --tok-built: hsl(145 55% 48%);
  --tok-tray: hsl(40 90% 58%);
  --tok-partial: hsl(210 75% 62%);
  --tok-shadow: hsl(220 20% 0% / 0.5);
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --tok-bg: hsl(220 15% 10%);
    --tok-surface: hsl(220 14% 14%);
    --tok-surface-2: hsl(220 12% 19%);
    --tok-text: hsl(40 20% 92%);
    --tok-muted: hsl(220 10% 62%);
    --tok-line: hsl(220 10% 28%);
    --tok-accent: hsl(355 80% 58%);
    --tok-built: hsl(145 55% 48%);
    --tok-tray: hsl(40 90% 58%);
    --tok-partial: hsl(210 75% 62%);
    --tok-shadow: hsl(220 20% 0% / 0.5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--tok-bg); color: var(--tok-text);
  font: 16px/1.4 -apple-system, "SF Pro Text", "Helvetica Neue", Helvetica, Arial, sans-serif; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; min-height: var(--tap); min-width: var(--tap); border: 1px solid var(--tok-line);
  background: var(--tok-surface); border-radius: var(--radius); padding: 0 14px; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid var(--tok-focus); outline-offset: 1px; }
button[disabled] { opacity: .45; cursor: default; }
input, select { min-height: var(--tap); border: 1px solid var(--tok-line); background: var(--tok-surface);
  border-radius: var(--radius); padding: 0 12px; }

header { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 20px; padding: 14px 20px;
  border-bottom: 1px solid var(--tok-line); background: var(--tok-surface); position: sticky; top: 0; z-index: 2; }
header h1 { font-size: 20px; margin: 0; }
header h1 span { color: var(--tok-accent); }
#stats { color: var(--tok-muted); font-size: 14px; flex: 1; min-width: 200px; }
nav.tabs { display: flex; gap: 6px; padding: 10px 20px 0; flex-wrap: wrap; }
nav.tabs button { border-radius: var(--radius) var(--radius) 0 0; border-bottom: none; background: var(--tok-surface-2); }
nav.tabs button[aria-selected="true"] { background: var(--tok-surface); font-weight: 600; box-shadow: inset 0 -3px 0 var(--tok-accent); }

main { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; padding: 16px 20px 40px; }
main.with-card { grid-template-columns: minmax(0, 1fr) minmax(360px, 520px); }
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.filters input[type="search"] { flex: 1; min-width: 220px; }
.pager { display: flex; align-items: center; gap: 10px; color: var(--tok-muted); }

table.sets { width: 100%; border-collapse: collapse; background: var(--tok-surface); border-radius: var(--radius);
  overflow: hidden; box-shadow: 0 1px 3px var(--tok-shadow); }
table.sets th, table.sets td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--tok-line); vertical-align: middle; }
table.sets th { font-size: 13px; color: var(--tok-muted); font-weight: 600; }
table.sets tr:last-child td { border-bottom: none; }
.thumb { width: 56px; height: 56px; object-fit: contain; background: var(--tok-surface-2); border-radius: 6px; display: block; }
.num { font-variant-numeric: tabular-nums; color: var(--tok-muted); white-space: nowrap; }
.name { background: none; border: none; padding: 0; min-height: var(--tap); text-align: left; font-weight: 600; color: var(--tok-text); }
.name:hover { color: var(--tok-accent); }
.own { display: inline-flex; gap: 4px; }
.own button { padding: 0 10px; font-size: 14px; white-space: nowrap; }
.own button[aria-pressed="true"] { color: var(--tok-accent-text); border-color: transparent; }
.own button[data-state="none"][aria-pressed="true"] { background: var(--tok-muted); }
.own button[data-state="built"][aria-pressed="true"] { background: var(--tok-built); }
.own button[data-state="tray"][aria-pressed="true"] { background: var(--tok-tray); }
.own button[data-state="partial"][aria-pressed="true"] { background: var(--tok-partial); }
.saved { font-size: 12px; color: var(--tok-built); margin-left: 6px; opacity: 0; transition: opacity .2s; }
.saved.on { opacity: 1; }
.saved.failed { color: var(--tok-accent); }
.note-wrap { display: flex; flex-direction: column; }
input.note { width: 100%; min-width: 120px; }

aside.card { background: var(--tok-surface); border-radius: var(--radius); box-shadow: 0 1px 3px var(--tok-shadow);
  padding: 16px; position: sticky; top: 76px; max-height: calc(100vh - 90px); overflow: auto; }
aside.card .close { float: right; }
aside.card img { width: 100%; max-height: 260px; object-fit: contain; background: var(--tok-surface-2); border-radius: var(--radius); }
aside.card h2 { margin: 10px 0 2px; font-size: 20px; }
aside.card .meta { color: var(--tok-muted); font-size: 14px; }
aside.card dl { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 12px 0; }
aside.card dt { color: var(--tok-muted); }
table.parts { width: 100%; border-collapse: collapse; font-size: 14px; }
table.parts td { padding: 6px 4px; border-bottom: 1px solid var(--tok-line); }
.swatch { display: inline-block; width: 18px; height: 18px; border-radius: 4px; border: 1px solid var(--tok-line); vertical-align: middle; margin-right: 6px; }
.noshape { color: var(--tok-tray); font-size: 12px; }
details summary { cursor: pointer; min-height: var(--tap); display: flex; align-items: center; color: var(--tok-muted); }
.empty { color: var(--tok-muted); padding: 30px; text-align: center; }

/* jobs */
.jobs-actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 14px; }
.panel { background: var(--tok-surface); border-radius: var(--radius); box-shadow: 0 1px 3px var(--tok-shadow); padding: 14px 16px; margin-bottom: 14px; }
.panel h3 { margin: 0 0 6px; font-size: 16px; }
.panel .phase { display: flex; flex-wrap: wrap; gap: 6px 16px; align-items: center; }
.bar { height: 10px; background: var(--tok-surface-2); border-radius: 5px; overflow: hidden; margin: 8px 0; }
.bar > div { height: 100%; background: var(--tok-partial); transition: width .3s; }
.bar.indeterminate > div { width: 30%; animation: slide 1.2s infinite linear; }
@keyframes slide { from { margin-left: -30%; } to { margin-left: 100%; } }
.muted { color: var(--tok-muted); font-size: 14px; }
table.jobs { width: 100%; border-collapse: collapse; background: var(--tok-surface); border-radius: var(--radius); overflow: hidden; font-size: 14px; }
table.jobs td, table.jobs th { padding: 8px 10px; border-bottom: 1px solid var(--tok-line); text-align: left; vertical-align: top; }
table.jobs th { font-size: 13px; color: var(--tok-muted); }
.status { display: inline-block; padding: 2px 8px; border-radius: 6px; font-size: 13px; background: var(--tok-surface-2); }
.status.done { background: var(--tok-built); color: var(--tok-accent-text); }
.status.running, .status.fetching { background: var(--tok-partial); color: var(--tok-accent-text); }
.status.failed, .status.error { background: var(--tok-accent); color: var(--tok-accent-text); }
.status.queued { background: var(--tok-tray); color: var(--tok-accent-text); }
.err { color: var(--tok-accent); font-size: 13px; }
.bookmark { color: var(--tok-muted); font-size: 13px; margin-left: 6px; }
.books a { display: inline-block; min-height: var(--tap); line-height: var(--tap); margin-right: 12px; color: var(--tok-partial); font-weight: 600; }
#jobs h3 { margin: 18px 0 8px; font-size: 16px; }

/* builds */
#build-view { display: grid; grid-template-columns: minmax(0, 1fr) minmax(300px, 420px); gap: 16px; align-items: start; }
#build-view .head { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; }
#build-view .head h2 { margin: 0; font-size: 20px; }
.render { background: var(--tok-surface); border-radius: var(--radius); box-shadow: 0 1px 3px var(--tok-shadow); padding: 12px; position: sticky; top: 76px; }
.render img { width: 100%; height: auto; border-radius: 6px; background: var(--tok-surface-2); }
.render .nav { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 10px; }
.steps { display: flex; flex-direction: column; gap: 8px; }
.steps h3 { margin: 10px 0 2px; font-size: 15px; color: var(--tok-muted); }
.step { background: var(--tok-surface); border-radius: var(--radius); box-shadow: 0 1px 3px var(--tok-shadow); padding: 10px 12px; cursor: pointer; border: 2px solid transparent; }
.step[aria-selected="true"] { border-color: var(--tok-partial); }
.step .n { font-weight: 700; margin-right: 10px; }
.step .callout { display: inline-flex; flex-wrap: wrap; gap: 6px 14px; font-size: 14px; }
.step .callout span { white-space: nowrap; }
.finding { font-size: 13px; margin-top: 4px; padding-left: 8px; border-left: 3px solid var(--tok-line); }
.finding.fail { border-left-color: var(--tok-accent); color: var(--tok-accent); }
.finding.warn { border-left-color: var(--tok-tray); color: var(--tok-tray); }
.step.has-fail { border-color: var(--tok-accent); }
.step.unresolved { border-left: 6px solid var(--tok-tray); }
.step .page { margin-left: 10px; font-size: 13px; white-space: nowrap; display: inline-block; min-height: 44px; line-height: 44px; }
.step .note { font-size: 13px; color: var(--tok-muted); margin-top: 4px; }
.reading { background: var(--tok-surface); border-radius: var(--radius); box-shadow: 0 1px 3px var(--tok-shadow); padding: 10px 12px; margin-bottom: 12px; grid-column: 1 / -1; }
.reading .line { display: flex; flex-wrap: wrap; gap: 6px 16px; align-items: baseline; }
.reading details { margin-top: 6px; }
.reading h4 { margin: 10px 0 4px; font-size: 14px; }
.replays .name { display: block; }
.verdict { display: inline-block; padding: 2px 10px; border-radius: 6px; font-weight: 600; background: var(--tok-surface-2); }
.verdict.engine_pass { background: var(--tok-built); color: var(--tok-accent-text); }
.verdict.engine_fail { background: var(--tok-accent); color: var(--tok-accent-text); }

@media (max-width: 1000px) {
  #build-view { grid-template-columns: minmax(0, 1fr); }
  .render { position: static; order: -1; }
  #build-view .head { order: -2; }
  main.with-card { grid-template-columns: minmax(0, 1fr); }
  aside.card { position: fixed; inset: 0; top: 0; max-height: none; border-radius: 0; z-index: 3; }
  table.sets th.year, table.sets td.year { display: none; }
}

/* designed builds */
.design { background: var(--tok-surface); border-radius: var(--radius); box-shadow: 0 1px 3px var(--tok-shadow); padding: 10px 12px; margin-bottom: 10px; }
.design .line { display: flex; flex-wrap: wrap; gap: 6px 16px; align-items: center; margin-bottom: 6px; }
.versions { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 4px; }
.versions button[aria-pressed="true"] { border-color: var(--tok-partial); font-weight: 700; }
.parts-check { margin-bottom: 10px; }
.parts-check table { border-collapse: collapse; font-size: 14px; }
.parts-check th, .parts-check td { text-align: left; padding: 4px 10px 4px 0; border-bottom: 1px solid var(--tok-line); }
.parts-check tr.short td { color: var(--tok-accent); font-weight: 600; }
.notes, .request { margin-top: 12px; }
.notes h4, .request h4 { margin: 6px 0 4px; font-size: 14px; color: var(--tok-muted); }
.notes .row, .request .row { display: flex; align-items: center; gap: 10px; margin-top: 6px; flex-wrap: wrap; }
.notes label { display: inline-flex; align-items: center; gap: 6px; min-height: var(--tap); }
textarea { font: inherit; color: inherit; width: 100%; min-height: var(--tap); border: 1px solid var(--tok-line); background: var(--tok-surface); border-radius: 6px; padding: 8px; }
textarea:focus-visible { outline: 3px solid var(--tok-focus); outline-offset: 1px; }
button.small { min-width: 0; padding: 2px 10px; font-size: 13px; margin-left: 8px; }

.viewer { width: 100%; aspect-ratio: 4 / 3; border-radius: 6px; background: var(--tok-surface-2); overflow: hidden; touch-action: none; }
.viewer canvas { width: 100% !important; height: 100% !important; display: block; }

/* the Trays tab */
.toggle { display: inline-flex; align-items: center; gap: 8px; min-height: var(--tap); }
.toggle input { width: 20px; height: 20px; }
.tray-set { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; min-height: var(--tap); }
.coverage { display: inline-flex; align-items: center; gap: 8px; min-width: 160px; }
.coverage .bar { flex: 1; height: 10px; min-width: 90px; background: var(--tok-surface-2); border-radius: 5px; overflow: hidden; }
.coverage .fill { display: block; height: 100%; background: var(--tok-tray); }
.coverage .pct { min-width: 44px; text-align: right; }
.could-row { cursor: pointer; }
.could-detail td { font-size: 14px; padding-bottom: 10px; }

/* the Parts tab */
.noshape { color: var(--tok-accent); }
.part-body { display: grid; grid-template-columns: minmax(240px, 420px) 1fr; gap: 16px; align-items: start; }
.part-body .part-pic { width: 100%; height: auto; border-radius: 6px; background: var(--tok-surface-2); }
.part-body .line { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; margin-bottom: 4px; word-break: break-word; }
.part-body h4 { margin: 10px 0 4px; font-size: 14px; color: var(--tok-muted); }
@media (max-width: 820px) { .part-body { grid-template-columns: 1fr; } }

/* people (phase 8): a secret shown once, in a box to copy from */
.secret { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 8px; }
.secret input { flex: 1; min-width: 240px; min-height: var(--tap); padding: 6px 10px; border: 1px solid var(--tok-line); border-radius: var(--radius); background: var(--tok-surface-2); color: inherit; font-family: ui-monospace, monospace; font-size: 13px; }
table.people { width: 100%; border-collapse: collapse; font-size: 14px; }
table.people td, table.people th { padding: 8px 10px; border-bottom: 1px solid var(--tok-line); text-align: left; vertical-align: middle; }
table.people td.actions { display: flex; gap: 6px; flex-wrap: wrap; }
#who { font-size: 14px; }

nav.tabs[hidden] { display: none; }
img.thumb { width: 64px; height: 48px; object-fit: contain; background: var(--tok-surface-2); border-radius: 4px; }

/* their books (phase 10): my uploads, one row each */
#my-books .book-row { display: flex; gap: 8px 14px; align-items: center; flex-wrap: wrap; min-height: var(--tap); padding: 4px 0; border-bottom: 1px solid var(--tok-line); }
#my-books .book-row:last-child { border-bottom: 0; }
#my-books .book-row .title { font-weight: 600; }
