:root {
  --bg: #f4f6f2;
  --panel: #ffffff;
  --text: #1f2a22;
  --muted: #637066;
  --line: #dde3dc;
  --accent: #3f7a4f;
  --accent-soft: #e3eee5;
  --error: #a33a2c;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151a16;
    --panel: #1d241f;
    --text: #e4eae5;
    --muted: #9aa69d;
    --line: #2f3a32;
    --accent: #7cbf8b;
    --accent-soft: #263a2b;
    --error: #ef8a7a;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
}

.app {
  position: relative;
  display: grid;
  grid-template-columns: minmax(300px, 380px) 1fr;
  /* The visible height: 100vh reaches under the browser's toolbars on iPad. */
  height: 100vh;
  height: 100dvh;
}

.controls {
  overflow-y: auto;
  padding: 20px 20px 40px;
  background: var(--panel);
  border-right: 1px solid var(--line);
}

h1 { margin: 0 0 4px; font-size: 1.5rem; }
.lead { margin: 0 0 16px; color: var(--muted); }

/* The heading folds the settings away (ADR 31): a button that looks like the
   heading, with a small triangle that turns. */
.fold {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
  color: inherit;
  cursor: pointer;
}
.fold .triangle { display: inline-block; font-size: 0.8em; color: var(--accent); transition: transform 0.15s; }
.folded .fold .triangle { transform: rotate(-90deg); }
/* Folded, the panel is a small box over the 3D view, which takes the room. */
.app.folded { grid-template-columns: 1fr; }
.app.folded .settings { display: none; }
.app.folded .controls {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 2;
  padding: 6px 14px 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 2px 10px rgb(0 0 0 / 0.12);
}
.app.folded h1 { margin: 0; font-size: 1.15rem; }

.models {
  display: flex;
  gap: 4px;
  margin-bottom: 14px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 10px;
}
.models a {
  flex: 1;
  padding: 6px 10px;
  border-radius: 7px;
  color: var(--text);
  text-align: center;
  text-decoration: none;
}
.models a:hover { background: var(--accent-soft); }
.models a[aria-current="page"] { background: var(--accent); color: var(--panel); font-weight: 600; }

.base { margin: 0 0 14px; padding: 8px 10px; border-radius: 8px; background: var(--accent-soft); font-size: 0.85rem; }
.base a { color: var(--accent); font-weight: 600; }

.presets { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 16px; }

/* The bayonet lock (ADR 61): the locked settings stay, greyed out. */
.field.lock { margin: -4px 0 16px; }
.field .locked-tag { margin-left: 6px; font-weight: 400; font-size: 0.85rem; color: var(--muted); }
.field.locked input:disabled, .field.locked select:disabled { opacity: 0.45; cursor: not-allowed; }

button {
  font: inherit;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
}
button:hover { border-color: var(--accent); }
button[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); }
button.quiet { color: var(--muted); }

fieldset { border: 0; border-top: 1px solid var(--line); margin: 0; padding: 12px 0 4px; }

details.group { border-top: 1px solid var(--line); padding: 12px 0 4px; }
details.group summary { font-weight: 600; color: var(--accent); cursor: pointer; }
details.group summary .quiet { margin-left: 6px; font-weight: 400; font-size: 0.85rem; color: var(--muted); }
details.group fieldset { border: 0; padding: 4px 0 0; }

.field {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: baseline;
  gap: 2px 8px;
  margin: 8px 0 12px;
}
.field .name { font-weight: 500; }
.field .value { font-variant-numeric: tabular-nums; color: var(--muted); white-space: nowrap; }
.field .value input {
  width: 7ch;
  margin-right: 4px;
  padding: 2px 4px;
  font: inherit;
  text-align: right;
  color: var(--text);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 4px;
}
.field .value input:invalid { box-shadow: none; }
.field .value .sign { margin-right: 3px; font-size: 1.75em; line-height: 0; vertical-align: -0.12em; }
.field .value input:focus { outline: 2px solid var(--accent); outline-offset: 0; }
.field input[type="range"] { grid-column: 1 / -1; width: 100%; accent-color: var(--accent); }
.field .hint { grid-column: 1 / -1; font-size: 0.85rem; color: var(--muted); }
.field.check { grid-template-columns: auto 1fr; }
.field.vector .cells { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 6px; }
.field.vector .cell { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 0.8rem; color: var(--muted); }
.field.vector input[type="checkbox"] { width: 20px; height: 20px; margin: 4px 0; accent-color: var(--accent); }
.field.vector select, .field.choice select {
  font: inherit;
  font-size: 0.95rem;
  padding: 3px 4px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--text);
}
.field.check input { accent-color: var(--accent); }

/* The "?" beside a setting, and what it opens: the setting's description
   and its picture (ADRs 62, 94). */
.field .explain {
  display: inline-grid;
  place-items: center;
  width: 20px;
  height: 20px;
  margin-left: 6px;
  padding: 0;
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1;
  color: var(--muted);
  vertical-align: 1px;
}
.field .explain:hover { color: var(--accent); }
.explain-pop {
  width: min(94vw, 760px);
  max-height: 92vh;
  overflow: auto;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  color: var(--text);
  box-shadow: 0 12px 40px rgb(0 0 0 / 0.3);
}
.explain-pop.words { width: min(94vw, 420px); }
.explain-pop::backdrop { background: rgb(0 0 0 / 0.3); }
.explain-pop .what { margin: 2px 2px 10px; line-height: 1.45; }
/* Browsers without pop-overs (before Safari 17, Chrome 114, Firefox 125)
   would show them all in place; app.js marks those with no-popover and opens
   one as a fixed panel instead (ADR 63). */
.no-popover .explain-pop { display: none; }
.no-popover .explain-pop.open { display: block; position: fixed; inset: 0; margin: auto; height: fit-content; z-index: 100; }
.explain-pop figure { margin: 0; }
/* As large as the pop-over allows, but short enough to leave the caption in view. */
.explain-pop img {
  display: block;
  width: auto;
  max-width: 100%;
  height: auto;
  max-height: 70vh;
  margin: 0 auto;
  border-radius: 8px;
  background: #fff;
}
.explain-pop figcaption { margin: 10px 2px 8px; font-size: 0.9rem; line-height: 1.4; color: var(--muted); }
.explain-pop .close { float: right; }

.preview { position: relative; min-height: 0; }
#viewer { position: absolute; inset: 0; z-index: 0; }  /* keeps the labels' z-indexes inside */
#viewer canvas { display: block; width: 100%; height: 100%; }
#viewer .labels { position: absolute; inset: 0; pointer-events: none; }
/* Labels that belong to a group of settings show while that group is open. */
body:has(details[data-labels]:not([open])) #viewer .labels { visibility: hidden; }
.label {
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--panel);
  font-size: 0.8rem;
  font-weight: 600;
}

.status {
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: 16px;
  z-index: 1;
  pointer-events: none;
}
.status p {
  display: inline-block;
  margin: 4px 0 0;
  padding: 6px 12px;
  border-radius: 8px;
  background: var(--panel);
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  border: 1px solid var(--line);
  pointer-events: auto;
}
/* The render's summary stays hidden until Details opens it; a tap on it
   closes it again. */
.status .summary { display: block; width: fit-content; max-width: 100%; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.status .summary:not(.open) { display: none; }
.status .summary span { display: block; }
#exports p { display: flex; width: fit-content; }
/* The hint for Edge (ADR 26) goes on a line of its own under the timer. */
.status .elapsed:has(.edge-hint) { flex: 1 1 100%; }
.status .edge-hint { flex: 0 0 100%; font-size: 0.85rem; color: var(--text); }
.status .busy { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; color: var(--muted); }
.status .busy .build { font-size: 0.85rem; }
.status .elapsed { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; font-variant-numeric: tabular-nums; }
/* The progress bar, in the colour of what renders: the draft's or the
   model's, as the viewer shows them; one with no estimate yet sweeps. */
.status .bar { position: relative; display: inline-block; width: 160px; height: 6px; overflow: hidden;
               border-radius: 3px; background: color-mix(in srgb, var(--muted) 25%, transparent); }
.status .bar > span { position: absolute; inset: 0 auto 0 0; width: 0; border-radius: 3px; background: var(--bar);
                      transition: width 0.1s linear; }
.status .bar.draft { --bar: #5b7590; }
.status .bar.model { --bar: #4f7d5a; }
.status .bar.download { --bar: var(--muted); }
.status .bar.indeterminate > span { width: 30%; transition: none; animation: sweep 1.4s ease-in-out infinite; }
@keyframes sweep { from { left: -30%; } to { left: 100%; } }
@media (prefers-reduced-motion: reduce) {
  .status .bar.indeterminate > span { width: 100%; opacity: 0.5; animation: none; }
}
.status .error { color: var(--error); border-color: var(--error); }
.status .actions { display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: baseline; width: fit-content; }
.status button.link {
  padding: 0;
  border: 0;
  border-radius: 0;
  color: var(--accent);
  font-weight: 600;
  text-decoration: underline;
  white-space: nowrap;
}
.status .quiet { color: var(--muted); font-size: 0.85rem; }

.footer { margin-top: 24px; padding-top: 12px; border-top: 1px solid var(--line); font-size: 0.85rem; }
.footer a, .document a { color: var(--accent); }

/* The licences page: a plain document. */
.document { max-width: 860px; margin: 0 auto; padding: 24px 20px 60px; }
.document.benchmark { max-width: 1200px; }
.document h2 { margin-top: 32px; }
.document h3 { margin: 20px 0 8px; font-size: 1.05rem; }
.document li { margin: 6px 0; }
.document code { font-size: 0.9em; }
.document .note { color: var(--muted); font-size: 0.9rem; }
.document .files { padding-left: 20px; }
.document .files li { margin: 4px 0; }
.packages { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.packages th, .packages td { text-align: left; vertical-align: top; padding: 6px 8px; border-bottom: 1px solid var(--line); }
.packages th { color: var(--muted); font-weight: 600; }
.packages .text-link + .text-link::before { content: " · "; color: var(--muted); }

/* The settings page (ADR 78): a numbered index, then a card for each
   setting with its facts and picture. */
.settings .toc { display: flex; flex-wrap: wrap; gap: 6px; margin: 16px 0 32px; }
.settings .toc a {
  display: inline-flex; gap: 6px; align-items: baseline; padding: 3px 10px 3px 4px;
  border: 1px solid var(--line); border-radius: 999px; background: var(--panel);
  color: var(--text); text-decoration: none; font-size: 0.85rem;
}
.settings .toc a:hover, .settings .toc a:focus-visible { border-color: var(--accent); outline: none; }
.settings .num {
  display: inline-grid; place-items: center; min-width: 1.9em; height: 1.9em; padding: 0 4px;
  border-radius: 999px; background: var(--accent-soft); color: var(--accent);
  font-size: 0.78rem; font-weight: 600; font-variant-numeric: tabular-nums;
}
.settings .group { display: grid; gap: 16px; margin-bottom: 36px; }
.settings .group h2 {
  margin: 0; padding-bottom: 6px; border-bottom: 1px solid var(--line);
  color: var(--accent); font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.08em;
}
.settings .setting {
  display: grid; gap: 10px; min-width: 0; padding: 16px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--panel); scroll-margin-top: 16px;
}
.settings .setting header { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 10px; }
.settings .setting h3 { margin: 0; font-size: 1.1rem; }
.settings .setting header code { color: var(--muted); }
.settings .setting p { margin: 0; max-width: 70ch; }
.settings dl { display: grid; gap: 6px; margin: 0; }
.settings dl div { display: grid; grid-template-columns: 8em 1fr; gap: 12px; }
.settings dt { padding-top: 2px; color: var(--muted); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em; }
.settings dd { margin: 0; min-width: 0; }
.settings figure { margin: 4px 0 0; }
.settings figure img {
  display: block; width: auto; max-width: 100%; max-height: 80vh; height: auto; margin: 0 auto;
  border: 1px solid var(--line); border-radius: 8px; background: #fff;
}
.settings figcaption { margin-top: 8px; color: var(--muted); font-size: 0.9rem; max-width: 70ch; }
@media (max-width: 600px) { .settings dl div { grid-template-columns: 1fr; gap: 0; } }

/* Each svh after a vh for browsers without it (Safari before 15.4, ADR 63). */
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; grid-template-rows: 55vh auto; grid-template-rows: 55svh auto; height: auto; }
  .preview { order: -1; height: 55vh; height: 55svh; }
  .controls { border-right: 0; border-top: 1px solid var(--line); }
  .app.folded { grid-template-rows: 100vh; grid-template-rows: 100svh; }
  .app.folded .preview { height: 100vh; height: 100svh; }

  .status { left: 8px; right: 8px; bottom: 8px; font-size: 0.9rem; }
}

/* The benchmark page (ADR 65): its steps, and the recorded runs, a wide
   table that scrolls on its own. */
.benchmark #benchmark button { margin: 4px 0 8px; }
.benchmark .steps { margin: 0; padding-left: 20px; font-variant-numeric: tabular-nums; }
.benchmark .done { color: var(--accent); }
.benchmark .error { color: #b4442c; }
.benchmark .table { overflow-x: auto; margin: 8px 0 24px; }
.benchmark table { border-collapse: collapse; font-size: 0.85rem; font-variant-numeric: tabular-nums; }
.benchmark th, .benchmark td { padding: 4px 8px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
.benchmark th { color: var(--muted); font-weight: 600; }
.benchmark td.gpu { max-width: 16em; overflow: hidden; text-overflow: ellipsis; }
.benchmark tr.last td { background: var(--accent-soft); }
.benchmark td.error-text { white-space: normal; min-width: 20em; max-width: 40em; }

/* The development stage's visitor in the lower right corner (ADR 68, 79), as
   partypeople has it: name and ID in small type; a click opens a panel. */
#dev-visitor {
  position: fixed;
  right: calc(0.5rem + env(safe-area-inset-right));
  bottom: calc(0.25rem + env(safe-area-inset-bottom));
  z-index: 100;
  font: 10px/1.25 ui-monospace, SFMono-Regular, Menlo, monospace;
}
#dev-visitor summary {
  list-style: none;
  cursor: pointer;
  padding: 1px 4px;
  border-radius: 4px;
  text-align: right;
  color: var(--muted);
  background: var(--panel);
  background: color-mix(in srgb, var(--panel) 80%, transparent);
}
#dev-visitor summary::-webkit-details-marker { display: none; }
#dev-visitor summary span { display: block; }
#dev-visitor-id { user-select: all; }
#dev-visitor .dev-panel {
  position: absolute;
  right: 0;
  bottom: 100%;
  margin-bottom: 4px;
  width: min(30rem, calc(100vw - 1rem));
  max-height: 70vh;
  overflow: auto;
  padding: 10px 12px;
  border: 1px solid #b4442c;
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  font-size: 11px;
  box-shadow: 0 8px 30px rgb(0 0 0 / 0.25);
}
#dev-visitor .dev-panel a { color: var(--accent); }
#dev-visitor dl { display: grid; grid-template-columns: auto 1fr; gap: 2px 8px; margin: 6px 0 0; }
#dev-visitor dt { color: var(--muted); }
#dev-visitor dd { margin: 0; word-break: break-all; }
#dev-visitor .dev-delete { margin: 10px 0 0; color: var(--muted); }
#dev-visitor .dev-delete button { margin-right: 6px; font-size: 11px; padding: 3px 10px; color: var(--error); border-color: var(--error); }

/* Without the cookie (ADR 79): "No Cookie" and a crossed-out cookie, which
   asks again on a click; with it, the name and ID. */
#dev-visitor .no-cookie, #dev-visitor[data-agreed] .with-cookie { display: block; }
#dev-visitor .with-cookie, #dev-visitor[data-agreed] .no-cookie { display: none; }
#dev-visitor:not([data-agreed]) .dev-panel { display: none; }
#dev-visitor .no-cookie { font-size: 11px; padding: 2px 0; }
#dev-visitor .crossed-cookie { position: relative; display: inline-block; vertical-align: -1px; margin-right: 4px; font-size: 13px; filter: grayscale(0.4); }
#dev-visitor .crossed-cookie::after {
  content: "";
  position: absolute;
  left: -2px;
  right: -2px;
  top: 50%;
  border-top: 2px solid var(--error);
  transform: rotate(-40deg);
}
#dev-visitor summary.landed { animation: dev-landed 0.45s cubic-bezier(0.3, 1.6, 0.6, 1); }
@keyframes dev-landed { from { transform: scale(1.35); } }

/* The question, once a tab, until it is answered (ADR 79); a yes flies it
   into the corner (app.js). */
#dev-consent {
  position: fixed;
  z-index: 101;
  right: calc(16px + env(safe-area-inset-right));
  bottom: calc(2.75rem + env(safe-area-inset-bottom));
  width: min(26rem, calc(100vw - 32px));
  max-height: calc(100vh - 5rem);
  overflow: auto;
  padding: 16px 18px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  color: var(--text);
  font-size: 0.85rem;
  line-height: 1.45;
  box-shadow: 0 12px 40px rgb(0 0 0 / 0.25);
  transform-origin: 0 0;
}
#dev-consent[hidden] { display: none; }
#dev-consent.opening { animation: dev-consent-in 0.3s ease-out; }
@keyframes dev-consent-in { from { opacity: 0; transform: translateY(12px); } }
#dev-consent h2 { margin: 0 0 8px; font-size: 1.05rem; }
#dev-consent p { margin: 0 0 10px; }
#dev-consent .dev-consent-buttons { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
#dev-consent button.primary { background: var(--accent); border-color: var(--accent); color: var(--panel); font-weight: 600; }

/* The development stage's log of a browser (ADR 68): a table, newest first,
   each entry's data unfolding below its line. */
.document.dev-log { max-width: 1200px; }
.dev-log .table { overflow-x: auto; }
.dev-log table { border-collapse: collapse; width: 100%; font-size: 0.85rem; }
.dev-log th, .dev-log td { padding: 4px 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.dev-log th { color: var(--muted); font-weight: 600; }
.dev-log td.time, .dev-log td.kind { white-space: nowrap; font-variant-numeric: tabular-nums; color: var(--muted); }
.dev-log summary { cursor: pointer; overflow-wrap: anywhere; }
.dev-log pre { max-height: 50vh; overflow: auto; margin: 6px 0; padding: 8px; border-radius: 6px; background: var(--accent-soft);
  font-size: 0.75rem; white-space: pre-wrap; overflow-wrap: anywhere; }
.dev-log tr.kind-failure summary { color: #b4442c; font-weight: 600; }

/* The examples (ADR 87): a card for each moss pole of a render matrix run,
   its picture linking to it in the configurator, and a small table of what
   each browser and build made. */
.examples .filters { display: flex; flex-wrap: wrap; gap: 4px 12px; margin: 8px 0; }
.examples .filters a.on { color: var(--text); font-weight: 700; text-decoration: none; }
.examples .example-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(360px, 100%), 1fr)); gap: 16px; }
.examples .example { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 12px; min-width: 0; }
.examples .example.failed { border-color: #b4442c; }
.examples .example .picture { display: flex; align-items: center; justify-content: center; height: 240px; }
.examples .example img { max-width: 100%; max-height: 100%; width: auto; height: auto; }
.examples .example h2 { margin: 8px 0 2px; font-size: 1.05rem; }
.examples .example h2 span { color: var(--muted); font-weight: 400; }
.examples .example p { margin: 4px 0; }
.examples .example summary { cursor: pointer; color: var(--accent); margin: 4px 0; }
.examples .example table { width: 100%; margin: 8px 0; font-size: 0.78rem; }
.examples .example th, .examples .example td { padding: 2px 4px; }
.examples .example tr.desktop td { color: var(--muted); }
.examples td.error { color: #b4442c; cursor: help; }
.examples td.differs { color: #b07a1c; font-weight: 600; cursor: help; }
