:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --ink: #1d1d1f;
  --muted: #6e6e73;
  --line: #e2e2e7;
  --accent: #0a84ff;
  --accent-ink: #ffffff;
  --warning: #c26a00;
  --hud: rgba(255, 255, 255, 0.78);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111113;
    --panel: #1c1c1f;
    --ink: #f2f2f5;
    --muted: #9a9aa1;
    --line: #2c2c31;
    --accent: #3d9bff;
    --warning: #ffb340;
    --hud: rgba(28, 28, 31, 0.78);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

main {
  max-width: 720px;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
}

h1 { font-size: 2rem; margin: 0.2em 0; }
h2 { font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); margin: 1.6em 0 0.5em; }
h3 { margin: 0; font-size: 1.05rem; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.strong { font-weight: 600; }
.title { margin-bottom: 8px; }

.notice { padding: 10px 12px; border-radius: 10px; background: var(--panel); }
.notice.warning { color: var(--warning); }

.panel { background: var(--panel); border-radius: 14px; overflow: hidden; }
.row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  min-height: 48px; padding: 8px 14px; border-bottom: 1px solid var(--line);
}
.row:last-child { border-bottom: none; }
select { font: inherit; color: inherit; background: transparent; border: none; text-align: right; max-width: 60%; }
input[type="checkbox"] { width: 22px; height: 22px; accent-color: var(--accent); }

.cards { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
@media (min-width: 640px) { .cards { grid-template-columns: 1fr 1fr; } }
.card {
  display: flex; gap: 12px; align-items: center; padding: 12px;
  background: var(--panel); border-radius: 14px; cursor: pointer;
}
.card:active { transform: scale(0.99); }
.card.unavailable { opacity: 0.5; }
.card .preview { width: 64px; height: 64px; flex: none; }
.card > div { min-width: 0; }
.card p { margin: 2px 0 0; }
.summary { color: var(--muted); font-size: 0.85rem; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.badge { font-size: 0.75rem; color: var(--muted); }
.badge.warning { color: var(--warning); }

.preview-box { background: var(--panel); border-radius: 16px; padding: 16px; }
#detail-preview { width: 100%; height: 280px; display: block; }
.info { list-style: none; padding: 0; color: var(--muted); }
.info li { padding: 4px 0; }

button {
  font: inherit; border: none; border-radius: 12px; padding: 14px 18px; cursor: pointer;
  background: var(--panel); color: var(--ink);
}
button:disabled { opacity: 0.4; cursor: default; }
.primary { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.secondary { background: var(--panel); color: var(--accent); border: 1px solid var(--line); }
.small-button { padding: 6px 12px; border-radius: 8px; font-size: 0.9rem; }
.actions { display: grid; gap: 10px; }
.back { background: none; color: var(--accent); padding: 8px 0; }

/* Training and teaching */
.live {
  position: fixed; inset: 0; background: #000; color: var(--ink);
}
.stage { position: absolute; inset: 0; }
.stage.mirrored { transform: scaleX(-1); }
.stage video, .stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.stage video { object-fit: cover; }

.hud {
  position: absolute; left: 0; right: 0; padding: 12px;
  display: flex; gap: 12px;
}
.hud.top {
  top: 0; align-items: center;
  margin: max(10px, env(safe-area-inset-top)) 10px 0;
  background: var(--hud); backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
  border-radius: 16px;
}
/* In landscape it reaches up past the buttons at the top right, so only its contents take clicks */
.hud.bottom > * { pointer-events: auto; }
.hud.bottom {
  pointer-events: none;
  bottom: 0; flex-direction: column;
  padding: 0 10px max(10px, env(safe-area-inset-bottom));
}
.hud-text { flex: 1; min-width: 0; }
.hud-text progress { width: 100%; height: 6px; accent-color: var(--accent); }
.hud-buttons { display: flex; flex-direction: column; gap: 6px; align-items: flex-end; }
.close { background: none; color: var(--muted); font-size: 1.3rem; padding: 4px 8px; }
.target { width: 56px; height: 56px; flex: none; }

.ring {
  --value: 0;
  width: 46px; height: 46px; flex: none; border-radius: 50%;
  background: conic-gradient(#34c759 calc(var(--value) * 1turn), var(--line) 0);
  display: grid; place-items: center;
}
.ring span {
  width: 36px; height: 36px; border-radius: 50%; background: var(--panel);
  display: grid; place-items: center; font-size: 0.85rem; font-weight: 600;
}

.message, .result {
  margin: 0; padding: 14px 16px; border-radius: 16px;
  background: var(--hud); backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
}
.message { font-size: 1.15rem; font-weight: 600; text-align: center; }
.result { max-height: 60vh; overflow: auto; }
.result h3 { margin-bottom: 6px; }
.result ul { list-style: none; padding: 0; margin: 8px 0; }
.result li { display: flex; justify-content: space-between; gap: 8px; padding: 3px 0; font-size: 0.9rem; }
.result .buttons { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.result .buttons button { padding: 10px 14px; }
.measured { color: #34c759; }
.replaced { color: #ff9f0a; }
.unavailable-check { color: #ff3b30; }

/* The study (/workflow) */
.study h1 { font-size: 1.7rem; }
.study .text h2 { font-size: 1.05rem; text-transform: none; letter-spacing: 0; color: var(--ink); margin: 1.4em 0 0.4em; }
.study .text ul { padding-left: 1.2em; }
.study .text li { margin: 0.25em 0; }
.study .actions { margin-top: 24px; }
.study .actions .back { justify-self: center; padding: 8px 16px; }
.link { background: none; color: var(--muted); padding: 6px 8px; font-size: inherit; text-decoration: underline; }
/* The study team's code and reset: at the very bottom of every page, as quiet as possible */
.team {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: center;
  margin-top: 56px; font-size: 0.8rem; color: var(--muted);
}
.team form { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: center; }
/* 16px, or iOS zooms in when the field gets focus */
.team input {
  width: 9em; padding: 6px 10px; font: inherit; font-size: 16px; color: inherit;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
}
.confirm {
  display: flex; gap: 12px; align-items: flex-start; margin-top: 20px; padding: 14px;
  background: var(--panel); border-radius: 14px; cursor: pointer;
}
.confirm input { flex: none; margin: 0; }
.modality { border-left: 4px solid var(--accent); }
.exercise-preview { width: 100%; height: 240px; display: block; }
.preview-box.photo { padding: 0; overflow: hidden; }
.exercise-image { display: block; width: 100%; max-height: 360px; object-fit: contain; }
.code {
  font: 600 1.8rem/1.2 ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: 0.08em;
  text-align: center; background: var(--panel); border-radius: 14px; padding: 18px;
}

/* Results after the study */
.level-good { --color: #34c759; }
.level-fair { --color: #ffcc00; }
.level-low { --color: #ff9f0a; }
.overview { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin: 18px 0 6px; }
.tile { background: var(--panel); border-radius: 14px; padding: 12px 14px; color: var(--muted); font-size: 0.8rem; }
.tile b { display: block; margin-bottom: 2px; font-size: 1.35rem; color: var(--ink); font-variant-numeric: tabular-nums; }
.result-card { background: var(--panel); border-radius: 16px; padding: 16px; margin-top: 14px; }
.result-card header { display: flex; align-items: center; gap: 12px; }
.result-card .preview { width: 52px; height: 52px; flex: none; }
.result-card .heading { flex: 1; min-width: 0; }
.result-card .heading p { margin: 0; }
.result-card h2 { margin: 2px 0 0; font-size: 1.2rem; text-transform: none; letter-spacing: 0; color: var(--ink); }
.result-card h3 { margin: 20px 0 8px; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.outcome {
  display: inline-flex; align-items: center; gap: 6px; flex: none;
  padding: 4px 10px; border-radius: 999px; background: var(--bg); font-size: 0.8rem; font-weight: 600;
}
.outcome::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.outcome.completed::before { background: #34c759; }
.outcome.timeout::before { background: #ffcc00; }
.score { display: flex; align-items: center; gap: 14px; margin-top: 16px; }
.score p { margin: 0; }
.score-ring {
  --value: 0;
  width: 76px; height: 76px; flex: none; border-radius: 50%;
  background: conic-gradient(var(--color) calc(var(--value) * 1turn), var(--line) 0);
  display: grid; place-items: center;
}
.score-ring span {
  width: 60px; height: 60px; border-radius: 50%; background: var(--panel);
  display: grid; place-items: center; font-weight: 700; font-size: 1.1rem; font-variant-numeric: tabular-nums;
}
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; margin: 18px 0 0; }
.stats dt { font-size: 0.8rem; color: var(--muted); }
.stats dd { margin: 2px 0 0; font-weight: 600; }
.parts, .tips { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.parts li { display: grid; grid-template-columns: minmax(0, 8.5em) 1fr 3em; align-items: center; gap: 10px; font-size: 0.9rem; }
.bar { position: relative; height: 8px; border-radius: 4px; background: var(--line); overflow: hidden; }
.bar::after { content: ""; position: absolute; inset: 0 auto 0 0; width: calc(var(--value) * 100%); background: var(--color); border-radius: inherit; }
.parts .value { text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
.tips li { padding: 10px 12px; border-radius: 10px; background: var(--bg); font-size: 0.9rem; }

.questions { display: grid; gap: 14px; margin-top: 16px; }
.question { border: none; margin: 0; padding: 14px; background: var(--panel); border-radius: 14px; min-width: 0; }
/* Floated, so the legend stays inside the padding */
.question legend { float: left; width: 100%; padding: 0; margin-bottom: 10px; font-weight: 600; }
.question.missing { box-shadow: inset 0 0 0 2px var(--warning); }
.required { color: var(--warning); }
.options, .scale, .scale-labels, .question input:not([type="radio"]), .question textarea { clear: both; }
.options { display: grid; gap: 4px; }
.option { display: flex; gap: 10px; align-items: center; min-height: 40px; cursor: pointer; }
.option input { width: 20px; height: 20px; margin: 0; flex: none; accent-color: var(--accent); }
.scale { display: flex; gap: 6px; }
.scale label { flex: 1; position: relative; }
.scale input { position: absolute; opacity: 0; pointer-events: none; }
.scale span {
  display: grid; place-items: center; height: 44px; cursor: pointer; font-weight: 600;
  border: 1px solid var(--line); border-radius: 10px;
}
.scale input:checked + span { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.scale input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.scale small { display: block; margin-top: 4px; text-align: center; font-size: 0.72rem; line-height: 1.2; color: var(--muted); overflow-wrap: anywhere; }
.scale-item { clear: both; margin-top: 18px; border-radius: 10px; }
.scale-item + .scale-item { padding-top: 18px; border-top: 1px solid var(--line); border-radius: 0; }
.scale-item.missing { box-shadow: 0 0 0 4px var(--panel), 0 0 0 6px var(--warning); border-radius: 10px; }
.item-statement { margin-bottom: 8px; font-weight: 600; font-size: 1.08rem; line-height: 1.3; }
.item-ends { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 6px; font-weight: 600; font-size: 0.88rem; }
.question.group > legend { font-size: 1.35rem; line-height: 1.25; margin-bottom: 24px; }
.group .scale span { height: 50px; font-size: 1.1rem; }
.scale-labels { display: flex; justify-content: space-between; gap: 12px; margin-top: 6px; font-size: 0.8rem; color: var(--muted); }
.question input:not([type="radio"]), .question textarea {
  display: block; width: 100%; padding: 10px 12px; font: inherit; color: inherit;
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
}
.question textarea { min-height: 90px; resize: vertical; }

.audio-only [data-visual] { display: none !important; }

/* Training is watched from 2 to 3 meters away, so the instructions and the hold timer are large. On a landscape
   screen (laptop) the instructions get a column on the right, where the camera image is mostly background. */
.message {
  font-size: clamp(1.5rem, 8vw, 2.8rem); line-height: 1.2; font-weight: 700; padding: 16px 18px;
  /* See-through enough to keep the person visible; the light blur and bold text keep it readable */
  background: color-mix(in srgb, var(--panel) 60%, transparent);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.message.holding { background: rgba(31, 143, 58, 0.85); color: #fff; text-align: center; }
.ring { width: clamp(52px, 11vmin, 104px); height: clamp(52px, 11vmin, 104px); }
.ring span { width: 78%; height: 78%; font-size: clamp(1rem, 4vmin, 2rem); }
.target { width: clamp(56px, 11vmin, 104px); height: clamp(56px, 11vmin, 104px); }
@media (orientation: landscape) and (min-width: 700px) {
  .hud-text { font-size: clamp(1rem, 1.6vw, 1.5rem); }
  .hud-text .small { font-size: 0.8em; }
  .hud.bottom {
    top: 0; left: auto; width: min(36vw, 600px); justify-content: flex-end;
    padding: max(120px, 16vh) 12px max(16px, env(safe-area-inset-bottom)) 0;
  }
  .message { font-size: clamp(1.8rem, 3.6vw, 3.8rem); text-align: left; padding: 24px 28px; }
}

/* Zone editor (editor.html) */
main.editor { max-width: 1200px; }
.editor-bar { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: center; margin: 12px 0; }
.editor-bar label { display: flex; gap: 8px; align-items: center; }
.editor-bar select { text-align: left; max-width: none; padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); }
.editor-layout { display: grid; gap: 16px; }
@media (min-width: 900px) { .editor-layout { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: start; } .editor-view { position: sticky; top: 12px; } }
.figure-box { position: relative; width: 100%; margin: 0 auto; background: var(--panel); border-radius: 14px; overflow: hidden; }
.figure-box canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; cursor: grab; }
.editor-stage { position: relative; aspect-ratio: 3 / 4; background: #000; border-radius: 14px; overflow: hidden; }
.editor-stage.mirrored { transform: scaleX(-1); }
.editor-stage video, .editor-stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.editor-stage video { object-fit: cover; }
.zone-row { background: var(--panel); border-radius: 12px; padding: 12px 14px; margin-bottom: 10px; border-left: 6px solid #8e8e93; }
.zone-row.unavailable { opacity: 0.6; }
.zone-row { cursor: pointer; }
.zone-row.selected { box-shadow: 0 0 0 2px var(--accent); }
.zone-joint { margin-top: 2px; }
.zone-metric { margin: 2px 0 8px; font: 0.8rem ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--muted); }
.zone-fields { display: flex; flex-wrap: wrap; gap: 8px 14px; }
.zone-field { display: flex; align-items: center; gap: 6px; font-size: 0.85rem; color: var(--muted); }
.zone-field input[type="number"] { width: 6.5em; font: inherit; color: var(--ink); padding: 5px 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.zone-gauge { display: block; width: 100%; height: 26px; margin-top: 10px; }
.zone-value { margin-top: 4px; }
.editor pre { white-space: pre-wrap; font-size: 0.8rem; background: var(--panel); padding: 12px; border-radius: 10px; }
