:root {
  --bg: #0b0d12; --card: #151922; --edge: #272d3b; --ink: #edf0f6; --muted: #8e97ad;
  --accent: #ff5a64; --accent-ink: #1b0507; --good: #5fd39a; --bad: #ff7b6b; --well: #0d1017;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
[hidden] { display: none !important; }

.app { display: flex; gap: 20px; padding: 20px; align-items: flex-start; justify-content: center; }
.view { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 12px; position: sticky; top: 20px; }
.view.sliced .stage { width: min(100%, calc((100vh - 330px) * var(--ar, 1.3333))); }      /* leave room for the slices underneath */
.slices { width: 100%; max-width: 980px; background: var(--card); border: 1px solid var(--edge); border-radius: 14px; padding: 10px 14px 12px; display: flex; flex-direction: column; gap: 8px; }
.slicehead { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 6px 16px; font-size: 13.5px; }
.slicekey { display: flex; gap: 14px; font-size: 12px; color: var(--muted); }
.slicekey span { display: inline-flex; align-items: center; gap: 6px; }
.slicekey i { width: 12px; height: 8px; border-radius: 2px; display: inline-block; }
.slicegrid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.slicegrid figure { margin: 0; display: flex; flex-direction: column; gap: 4px; }
.slicegrid canvas { width: 100%; height: 190px; border-radius: 8px; background: #05070b; cursor: crosshair; touch-action: none; }
.slicegrid figcaption { font-size: 11.5px; color: var(--muted); text-align: center; }
.stage { position: relative; aspect-ratio: var(--ar, 1.3333); width: min(100%, calc((100vh - 40px) * var(--ar, 1.3333)));
  border: 1px solid var(--edge); border-radius: 18px; overflow: hidden;
  background: radial-gradient(ellipse at 50% 38%, #171d2b, #06080c 78%); }
.stage > video, .stage > img, .stage > canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
/* the picture and everything drawn on it are flipped, so it behaves like a mirror; the text layer is not */
#video, #photo { object-fit: cover; transform: scaleX(-1); }
#under, #gl { transform: scaleX(-1); pointer-events: none; }
#hud { pointer-events: none; }

.intro { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; padding: 24px; text-align: center; }
.intro h2 { margin: 0; font-size: 32px; font-weight: 750; letter-spacing: .01em; }
.intro p { margin: 0; max-width: 48ch; color: var(--muted); }
button.primary { font: inherit; font-size: 17px; font-weight: 700; color: var(--accent-ink); background: var(--accent);
  border: 0; border-radius: 999px; padding: 13px 26px; cursor: pointer; }
button.primary:disabled { opacity: .55; cursor: default; }

.side { flex: 0 0 340px; display: flex; flex-direction: column; gap: 12px; }
.side header h1 { margin: 0 0 4px; font-size: 22px; }
.titlebar { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.titlebar button.link { align-self: baseline; font-size: 13px; }
.toplinks { display: flex; gap: 14px; white-space: nowrap; }
.intro button.link { font-size: 14px; align-self: center; }
.status { margin: 0; font-size: 14px; font-weight: 600; color: var(--muted); }
.status.ok { color: var(--good); } .status.bad { color: var(--bad); }
.card { background: var(--card); border: 1px solid var(--edge); border-radius: 14px; padding: 13px 15px;
  display: flex; flex-direction: column; gap: 11px; }
.card h3 { margin: 0; font-size: 12px; font-weight: 650; color: var(--muted); text-transform: uppercase; letter-spacing: .09em; }

.chips, .seg { display: flex; flex-wrap: wrap; gap: 7px; }
.chips button, .seg button { font: inherit; font-size: 13px; color: var(--ink); background: var(--well);
  border: 1px solid var(--edge); border-radius: 999px; padding: 6px 12px; cursor: pointer; }
.chips button:hover, .seg button:hover { border-color: var(--accent); }
.seg button { flex: 1; border-radius: 10px; }
.seg button.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 700; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 12px; }
.split { display: flex; flex-direction: column; gap: 8px; border-top: 1px solid var(--edge); padding-top: 11px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; cursor: pointer; }
.check.strong { font-weight: 600; }
.check i { width: 10px; height: 10px; border-radius: 50%; background: var(--c); flex: none; }
input[type=checkbox] { width: 17px; height: 17px; margin: 0; accent-color: var(--accent); }
.slider { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 50%); align-items: center; gap: 12px; font-size: 14px; }
.slider input[type=range] { width: 100%; margin: 0; accent-color: var(--accent); }
.slider output { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; margin-left: 4px; white-space: nowrap; }
select { font: inherit; font-size: 14px; color: var(--ink); background: var(--well); border: 1px solid var(--edge);
  border-radius: 8px; padding: 6px 8px; width: 100%; }
.legend { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 5px 12px; font-size: 12.5px; color: var(--muted); }
.legend li { display: flex; align-items: center; gap: 7px; }
.legend i { width: 14px; height: 6px; border-radius: 3px; background: var(--c); flex: none; box-shadow: 0 0 0 1px rgba(255,255,255,.28); }
#data { margin: 0; padding: 9px 11px; background: var(--well); border: 1px solid var(--edge); border-radius: 8px;
  font: 12px/1.5 ui-monospace, Menlo, Consolas, monospace; white-space: pre-wrap; font-variant-numeric: tabular-nums; }
.losses { position: absolute; left: 12px; bottom: 12px; width: min(300px, 46%); padding: 10px 12px 9px; border-radius: 12px;
  background: rgba(9, 12, 18, .78); border: 1px solid rgba(255, 255, 255, .12); backdrop-filter: blur(6px);
  font-size: 12.5px; line-height: 1.3; pointer-events: none; }
.losses h4 { margin: 0 0 7px; font-size: 11px; font-weight: 650; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
.losses p { margin: 0; color: var(--muted); }
.loss { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; margin-bottom: 6px; }
.loss b { font-variant-numeric: tabular-nums; font-weight: 650; }
.loss i { grid-column: 1 / -1; display: flex; height: 6px; border-radius: 3px; overflow: hidden; background: rgba(255, 255, 255, .13); }
.losses em { display: block; height: 100%; }
.losses em.gone { background: #8d86a8; } .losses em.down { background: #ffae1f; }
.losses .key { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; margin-top: 8px; font-size: 11px; }
.losses .key em { width: 12px; height: 6px; border-radius: 3px; flex: none; }
.losses .key em.gone { margin-left: 6px; }
/* the steps of one repetition of a therapy, the current one lit */
.steps { list-style: none; margin: 0; padding: 0; }
.steps li { display: flex; gap: 7px; padding: 3px 6px; border-radius: 6px; color: var(--muted); }
.steps li b { flex: none; width: 1.1em; text-align: center; font-weight: 650; font-variant-numeric: tabular-nums; }
.steps li.on { background: rgba(63, 230, 196, .18); color: var(--ink); }
@media (max-width: 600px) { .steps li:not(.on) { display: none; } }      /* a small picture: only the current step, so the list does not cover it */
details > summary { cursor: pointer; font-size: 13.5px; font-weight: 600; }
/* a settings card that stays shut until its title is clicked */
.fold > summary { list-style: none; display: flex; align-items: center; justify-content: space-between; font-size: 12px; font-weight: 650;
  color: var(--muted); text-transform: uppercase; letter-spacing: .09em; }
.fold > summary::-webkit-details-marker { display: none; }
.fold > summary::after { content: "+"; font-size: 16px; font-weight: 500; line-height: 1; letter-spacing: 0; }
.fold[open] > summary::after { content: "\2212"; }
.fold > summary:hover { color: var(--ink); }
.fold[open] > summary { margin-bottom: 4px; }
.grouphead { margin: 6px 2px -4px; font-size: 12px; color: var(--muted); }
details[open] > summary { margin-bottom: 10px; }
details { display: flex; flex-direction: column; }
details > * + * { margin-top: 9px; }
.filters { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 8px; }
.filters select { font-size: 12.5px; padding: 5px 6px; }
#scanCount { margin-top: 5px; }
label.file { display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
label.file input { font: inherit; font-size: 12px; color: var(--muted); }
.readout .warn, .fine.bad { color: var(--bad); } .fine.ok { color: var(--good); }
code { font: 12px ui-monospace, Menlo, Consolas, monospace; background: var(--well); padding: 1px 5px; border-radius: 5px; }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
button.action { font: inherit; font-size: 13.5px; font-weight: 700; color: var(--accent-ink); background: var(--accent);
  border: 1px solid var(--accent); border-radius: 10px; padding: 8px 12px; cursor: pointer; }
button.action.quiet { color: var(--ink); background: var(--well); border-color: var(--edge); font-weight: 600; }
button.action.quiet:hover:not(:disabled) { border-color: var(--good); }
button.action:disabled { opacity: .45; cursor: default; }
.readout { font-size: 13.5px; line-height: 1.45; }
.readout p { margin: 0 0 7px; } .readout p:last-child { margin-bottom: 0; }
.readout ul { margin: 0; padding-left: 18px; } .readout li { margin-bottom: 3px; }
.readout b { font-variant-numeric: tabular-nums; }
.fine { font-size: 12px; color: var(--muted); margin: 0; }
button.link { font: inherit; font-size: 12px; color: var(--accent); background: none; border: 0; padding: 0; cursor: pointer; align-self: flex-start; }
.actions button.link { align-self: center; margin-left: auto; }

/* the key to the brain's regions: a colour, a name and what the region does */
.regionkey { grid-template-columns: 1fr; gap: 7px; max-height: 320px; overflow-y: auto; padding-right: 4px; }
.regionkey li { align-items: flex-start; line-height: 1.3; }
.regionkey li i { width: 12px; height: 12px; border-radius: 3px; margin-top: 2px; }
.regionkey li b { display: block; color: var(--ink); font-weight: 600; }
.regionkey li.head { margin-top: 6px; font-size: 11px; font-weight: 650; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.regionkey li.head:first-child { margin-top: 0; }

dialog { width: min(480px, calc(100vw - 32px)); background: var(--card); color: var(--ink); border: 1px solid var(--edge); border-radius: 16px; padding: 18px 20px; }
dialog[open] { display: flex; flex-direction: column; gap: 12px; }
dialog::backdrop { background: rgba(4, 7, 13, .7); }
dialog h2 { margin: 0; font-size: 18px; }
.field { display: flex; flex-direction: column; gap: 5px; font-size: 13.5px; }
.field textarea, .field input { font: inherit; font-size: 14px; color: var(--ink); background: var(--well); border: 1px solid var(--edge); border-radius: 8px; padding: 8px 9px; width: 100%; resize: vertical; }
.fine.warn { color: #ffcf6b; }
dialog .actions a { margin-left: auto; color: var(--accent); }
.link.dim { color: var(--muted); font-size: 12px; padding-left: 0; }      /* the way in to the preview features: there, but not calling for attention */

/* the guided tour: everything dims except the part being explained, and a note sits beside it */
.tour-block { position: fixed; inset: 0; z-index: 1000; }                       /* nothing underneath can be clicked while the tour is open */
.tour-ring { position: fixed; z-index: 1001; border-radius: 14px; border: 2px solid var(--accent); box-shadow: 0 0 0 200vmax rgba(4, 7, 13, .74); pointer-events: none;
  transition: left .18s ease, top .18s ease, width .18s ease, height .18s ease; }
.tour-plain .tour-ring { display: none; } .tour-plain .tour-block { background: rgba(4, 7, 13, .74); }
.tour-note { position: fixed; z-index: 1002; width: min(360px, calc(100vw - 16px)); background: var(--card); border: 1px solid var(--edge); border-radius: 14px;
  padding: 15px 17px; display: flex; flex-direction: column; gap: 9px; box-shadow: 0 12px 40px rgba(0, 0, 0, .55); font-size: 14px; line-height: 1.45; }
.tour-note h2 { margin: 0; font-size: 17px; }
.tour-note p { margin: 0 0 7px; } .tour-note p:last-child { margin-bottom: 0; }
.tour-note ul { margin: 2px 0 0; padding-left: 18px; } .tour-note li { margin-bottom: 3px; }
.tour-count { font-size: 11px; font-weight: 650; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.tour-count:empty { display: none; }
@media (prefers-reduced-motion: reduce) { .tour-ring { transition: none; } }

@media (max-width: 900px) {
  .app { flex-direction: column; align-items: stretch; }
  .view { position: static; } .side { flex: none; } .stage { width: 100%; }
}
