: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 the picture it opens (ADR 62). */
.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::backdrop { background: rgb(0 0 0 / 0.3); }
/* 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; }
.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; }
.status progress { width: 120px; height: 6px; accent-color: var(--accent); }
.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); }

/* 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; }
  .status .wide { display: none; }
}

/* 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), 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; }

/* 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; }
