/* Lettertypen van het meetscherm, meegeleverd zodat er geen derde partij bij komt kijken. */

@font-face {
  font-family: "Barlow Condensed";
  src: url("../fonts/barlow-condensed-latin-600-normal.woff2") format("woff2");
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Barlow Condensed";
  src: url("../fonts/barlow-condensed-latin-700-normal.woff2") format("woff2");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Barlow";
  src: url("../fonts/barlow-latin-600-normal.woff2") format("woff2");
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}

:root {
  color-scheme: light dark;

  --bg: #f4f4f0;
  --surface: #ffffff;
  --ink: #15171a;
  --muted: #5b626d;
  --line: #d9d9d2;
  --primary: #15171a;
  --primary-ink: #ffffff;
  --danger: #c22f35;

  --good: #178a48;
  --accent: #d7f23c;

  /* Het meetscherm is altijd donker, los van het thema van het toestel. */
  --frame: #0e1013;
  --glass: rgb(13 15 18 / 0.82);
  --hairline: rgb(255 255 255 / 0.1);
  --soft-white: rgb(255 255 255 / 0.8);
  --score-good: #3ddc84;
  --score-bad: #ff6b6b;
  --score-good-fill: #15803d;
  --score-bad-fill: #b91c1c;

  /* Kleuren voor wat over het videobeeld heen getekend wordt. */
  --overlay-neutral: #ffffff;
  --overlay-deep: #3ddc84;
  --overlay-limit: #d7f23c;
  --overlay-outline: #0e1013;

  --font-condensed: "Barlow Condensed", "Avenir Next Condensed", "Roboto Condensed", "Arial Narrow", sans-serif;
  --font-measure: "Barlow", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

  --radius: 16px;
  --gap: 12px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);

  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1013;
    --surface: #191c21;
    --ink: #f1f2f4;
    --muted: #9ba2ae;
    --line: #2b2f37;
    --primary: #d7f23c;
    --primary-ink: #15171a;
    --danger: #ff7a7f;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  overscroll-behavior: none;
}

[hidden] {
  display: none !important;
}

button,
input {
  font: inherit;
  color: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

:focus-visible {
  outline: 3px solid var(--focus, var(--ink));
  outline-offset: 2px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* Knoppen */

.button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 56px;
  padding: 0 20px;
  border: 2px solid transparent;
  border-radius: var(--radius);
  font-size: 1.0625rem;
  font-weight: 700;
  cursor: pointer;
}

.button--primary {
  background: var(--primary);
  color: var(--primary-ink);
}

.button--secondary {
  background: transparent;
  border-color: var(--line);
}

.button:active {
  transform: scale(0.98);
}

.link {
  padding: 8px 0;
  border: 0;
  background: none;
  font-weight: 700;
  text-decoration: underline;
  cursor: pointer;
}

/* Startscherm */

.start {
  display: flex;
  flex-direction: column;
  gap: 28px;
  min-height: 100dvh;
  max-width: 520px;
  margin: 0 auto;
  padding: calc(40px + var(--safe-top)) calc(24px + var(--safe-right)) calc(24px + var(--safe-bottom)) calc(24px + var(--safe-left));
}

.start h1 {
  margin: 0 0 12px;
  font-size: clamp(2.25rem, 11vw, 3.25rem);
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.03em;
  text-wrap: balance;
}

.lead {
  margin: 0;
  color: var(--muted);
  font-size: 1.0625rem;
  text-wrap: pretty;
}

.start__actions {
  display: grid;
  gap: var(--gap);
}

.error {
  margin: 0;
  color: var(--danger);
  font-weight: 600;
}

.tips {
  display: grid;
  gap: 14px;
  margin: 0;
  padding: 0;
  list-style: none;
  counter-reset: tip;
  color: var(--muted);
}

.tips li {
  position: relative;
  padding-left: 44px;
  counter-increment: tip;
}

.tips li::before {
  content: counter(tip);
  position: absolute;
  left: 0;
  top: 0;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border: 2px solid var(--line);
  border-radius: 50%;
  color: var(--ink);
  font-size: 0.875rem;
  font-weight: 700;
}

.tips strong {
  display: block;
  color: var(--ink);
}

.start__foot {
  display: grid;
  gap: 10px;
  margin-top: auto;
  color: var(--muted);
  font-size: 0.875rem;
}

.loader {
  display: grid;
  gap: 8px;
  justify-items: start;
}

.loader__bar {
  width: 100%;
  height: 6px;
  border-radius: 3px;
  background: var(--line);
  overflow: hidden;
}

.loader__fill {
  width: 100%;
  height: 100%;
  border-radius: 3px;
  background: var(--ink);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 200ms linear;
}

.fine {
  margin: 0;
}

/* Meetscherm: scorebord, daaronder het beeld, daaronder de bediening.
   Niets ligt over het beeld heen behalve de dieptemeter aan de rand. */

.measure {
  --focus: var(--accent);
  position: fixed;
  inset: 0;
  display: grid;
  grid-template: "board" auto "view" minmax(0, 1fr) "controls" auto / minmax(0, 1fr);
  padding: var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left);
  background: var(--frame);
  color: #fff;
  font-family: var(--font-measure);
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}

/* Scorebord */

.board {
  grid-area: board;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 6px 12px 8px;
}

.board__cells {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.cell {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 4px 12px 6px;
  border-radius: 12px;
  transition: background-color 350ms ease-out;
}

.cell--good {
  --cell-color: var(--score-good);
  --cell-fill: var(--score-good-fill);
}

.cell--bad {
  --cell-color: var(--score-bad);
  --cell-fill: var(--score-bad-fill);
}

.cell__label {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--soft-white);
  font-family: var(--font-condensed);
  font-size: 0.9375rem;
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.cell__label svg {
  width: 14px;
  height: 14px;
  fill: none;
  stroke: var(--cell-color);
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.cell__value {
  font-family: var(--font-condensed);
  font-size: 3.75rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 0.86;
}

.cell::after {
  content: "";
  height: 3px;
  border-radius: 2px;
  background: var(--cell-color);
}

/* Kort ingekleurd op het moment dat er een herhaling bijkomt. */
.cell.is-hit {
  --cell-color: #fff;
  background: var(--cell-fill);
  transition-duration: 60ms;
}

.cell.is-hit .cell__label {
  color: #fff;
}

.board__summary {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 12px;
}

.tally {
  margin: 0;
  color: var(--soft-white);
  font-size: 0.8125rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.tally span:empty {
  display: none;
}

.tally span + span::before {
  content: " · ";
  white-space: pre;
}

/* De laatste twaalf herhalingen: gevuld is goed, een open randje is niet goed. */
.history {
  flex: 1;
  display: flex;
  gap: 4px;
}

.history span {
  flex: 1;
  height: 8px;
  box-sizing: border-box;
  border-radius: 2px;
  background: rgb(255 255 255 / 0.12);
}

.history .is-good {
  background: var(--score-good);
}

.history .is-bad {
  border: 2px solid var(--score-bad);
  background: none;
}

.history .is-new {
  outline: 2px solid #fff;
  outline-offset: 1px;
}

/* Beeld */

.viewport {
  grid-area: view;
  position: relative;
  display: grid;
  place-items: center;
  min-height: 0;
  margin: 3px 14px;
  border-radius: 14px;
  background: #000;
  overflow: hidden;
  container-type: size;
}

.stage {
  position: relative;
}

.stage video,
.stage canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

/* Alleen het beeld spiegelen, niet de meter of de tekst eroverheen. */
.stage.is-mirrored video,
.stage.is-mirrored canvas {
  transform: scaleX(-1);
}

/* Dieptemeter: de knop zakt mee met de heup; de gele streep is de grens. */

.gauge {
  position: absolute;
  top: 8px;
  bottom: 8px;
  right: 10px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  justify-content: center;
  gap: 8px;
  pointer-events: none;
}

/* Eigen donkere ondergrond, anders valt de tekst weg tegen licht videobeeld. */
.gauge__title {
  width: 44px;
  box-sizing: border-box;
  padding: 3px 0;
  border: 1px solid var(--hairline);
  border-radius: 6px;
  background: var(--glass);
  color: var(--soft-white);
  font-family: var(--font-condensed);
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: 0.1em;
  text-align: center;
  text-transform: uppercase;
}

.gauge__rail {
  position: relative;
  flex: 0 1 300px;
  min-height: 90px;
  width: 44px;
  box-sizing: border-box;
  border: 1px solid var(--hairline);
  border-radius: 22px;
  background: var(--glass);
}

.gauge__scale {
  position: absolute;
  inset: 18px 0;
}

/* Twaalf schaalstreepjes, gelijk verdeeld van boven tot onder. */
.gauge__scale::before {
  content: "";
  position: absolute;
  left: 8px;
  top: 0;
  bottom: 0;
  width: 8px;
  background: linear-gradient(rgb(255 255 255 / 0.4) 1px, transparent 1px) top / 100% calc((100% - 1px) / 11) repeat-y;
}

.gauge__scale::after {
  content: "";
  position: absolute;
  left: 23px;
  top: 0;
  bottom: 0;
  width: 6px;
  border-radius: 3px;
  background: rgb(255 255 255 / 0.16);
}

.gauge__fill {
  position: absolute;
  z-index: 1;
  left: 23px;
  top: 0;
  bottom: 0;
  width: 6px;
  border-radius: 3px;
  background: var(--overlay-neutral);
  transform: scaleY(var(--depth, 0));
  transform-origin: top;
}

.gauge__limit {
  position: absolute;
  z-index: 1;
  left: -8px;
  right: -8px;
  top: calc(var(--mark, 0.77) * 100%);
  height: 3px;
  margin-top: -1.5px;
  border-radius: 2px;
  background: var(--overlay-limit);
}

.gauge__limit span {
  position: absolute;
  right: calc(100% + 6px);
  top: 50%;
  padding: 2px 7px;
  border-radius: 5px;
  background: var(--overlay-limit);
  color: #15171a;
  font-family: var(--font-condensed);
  font-size: 0.8125rem;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  transform: translateY(-50%);
}

/* Verschuift over de volle schaalhoogte; de knop zelf hangt aan de bovenrand. */
.gauge__travel {
  position: absolute;
  z-index: 2;
  inset: 0;
  transform: translateY(calc(var(--depth, 0) * 100%));
}

.gauge__knob {
  position: absolute;
  left: 17px;
  top: -9px;
  width: 18px;
  height: 18px;
  box-sizing: border-box;
  border: 3px solid var(--overlay-outline);
  border-radius: 50%;
  background: var(--overlay-neutral);
}

.gauge.is-deep .gauge__fill,
.gauge.is-deep .gauge__knob {
  background: var(--overlay-deep);
}

.gauge__readout {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border: 1px solid var(--hairline);
  border-radius: 999px;
  background: var(--glass);
  font-size: 0.875rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.gauge__readout svg {
  display: none;
  width: 14px;
  height: 14px;
  fill: none;
  stroke: #fff;
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.gauge.is-deep .gauge__readout {
  border-color: transparent;
  background: var(--score-good-fill);
}

.gauge.is-deep .gauge__readout svg {
  display: block;
}

/* Oordeel per herhaling: het hele beeldvlak kleurt, zichtbaar vanuit je ooghoek. */

.flash {
  position: absolute;
  z-index: 3;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  box-sizing: border-box;
  padding: 20px;
  border: 8px solid transparent;
  border-radius: 14px;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 350ms ease-out;
}

.flash.is-active {
  opacity: 1;
  transition-duration: 60ms;
}

.flash[data-verdict="good"] {
  --verdict: var(--score-good-fill);
  border-color: var(--score-good);
  background: rgb(21 128 61 / 0.72);
}

.flash[data-verdict="bad"] {
  --verdict: var(--score-bad-fill);
  border-color: var(--score-bad);
  background: rgb(185 28 28 / 0.74);
}

.flash[data-verdict="good"] .flash__for-bad,
.flash[data-verdict="bad"] .flash__for-good {
  display: none;
}

/* De cq-eenheden laten het oordeel meekrimpen in een klein beeldvlak; de regel ervoor is de terugval. */
.flash__icon {
  flex: none;
  width: 72px;
  height: 72px;
  width: min(72px, 16cqh);
  height: min(72px, 16cqh);
}

.flash__icon circle {
  fill: #fff;
}

.flash__icon path {
  fill: none;
  stroke: var(--verdict);
  stroke-width: 7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.flash__title {
  font-family: var(--font-condensed);
  font-size: 6rem;
  font-size: min(8.5rem, 32cqw, 26cqh);
  font-weight: 700;
  line-height: 0.88;
  letter-spacing: 0.01em;
  text-transform: uppercase;
}

/* Twee vaste regels; de maat is zo gekozen dat "niet diep" ook in een breder terugvalfont past. */
.flash__title--long {
  font-size: 4rem;
  font-size: min(5rem, 20cqw, 16cqh);
  line-height: 0.9;
  white-space: nowrap;
}

.flash__detail {
  font-size: 1.25rem;
  font-size: min(1.25rem, 5.5cqw);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.hint {
  position: absolute;
  z-index: 4;
  left: 50%;
  bottom: 12px;
  width: max-content;
  max-width: calc(100% - 24px);
  margin: 0;
  padding: 10px 16px;
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  background: var(--glass);
  font-size: 0.9375rem;
  font-weight: 600;
  text-align: center;
  text-wrap: balance;
  transform: translateX(-50%);
}

.hint.is-error {
  border-color: transparent;
  background: var(--score-bad-fill);
}

/* Bediening */

.controls {
  grid-area: controls;
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
  padding: 4px 8px;
}

.controls button {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 60px;
  padding: 0;
  border: 0;
  border-radius: 12px;
  background: none;
  color: #fff;
  font-family: inherit;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
}

.controls button:active {
  background: rgb(255 255 255 / 0.12);
}

.controls button.is-armed {
  background: var(--score-bad-fill);
}

.controls svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Telefoon op zijn kant: scorebord links, bediening rechts, het beeld ertussen. */

@media (orientation: landscape) and (max-height: 540px) {
  .measure {
    grid-template: "board view controls" minmax(0, 1fr) / 164px minmax(0, 1fr) 72px;
  }

  .board {
    justify-content: center;
    gap: 8px;
    padding: 12px 10px;
  }

  .board__cells {
    grid-template-columns: minmax(0, 1fr);
  }

  .board__summary {
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
    padding: 4px 12px 0;
  }

  /* De smalle kolom is te krap voor één regel. */
  .tally {
    display: flex;
    flex-direction: column;
  }

  .tally span + span::before {
    content: none;
  }

  .history {
    flex: none;
    gap: 3px;
  }

  .viewport {
    margin: 12px 4px;
  }

  /* Links onderin, zodat de aanwijzing niet over de uitlezing van de dieptemeter valt. */
  .hint {
    left: 12px;
    max-width: calc(100% - 190px);
    text-align: left;
    transform: none;
  }

  .controls {
    grid-auto-flow: row;
    grid-auto-rows: minmax(0, 1fr);
    padding: 8px 4px;
  }

  .controls button {
    min-height: 44px;
  }
}

/* Uitschuifpanelen */

.sheet {
  width: 100%;
  max-width: 520px;
  max-height: 92dvh;
  margin: auto auto 0;
  padding: 0;
  border: 0;
  border-radius: 24px 24px 0 0;
  background: var(--surface);
  color: var(--ink);
  overflow-y: auto;
}

.sheet::backdrop {
  background: rgb(0 0 0 / 0.55);
}

.sheet[open] {
  animation: sheet-in 220ms ease-out;
}

@keyframes sheet-in {
  from { transform: translateY(24px); opacity: 0; }
}

.sheet__body {
  display: grid;
  gap: 20px;
  padding: 24px calc(20px + var(--safe-right)) calc(20px + var(--safe-bottom)) calc(20px + var(--safe-left));
}

.sheet h2 {
  margin: 0;
  font-size: 1.375rem;
  font-weight: 800;
  letter-spacing: -0.01em;
}

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.row--stack {
  display: grid;
  justify-content: stretch;
  gap: 10px;
}

.row__text {
  display: grid;
  gap: 2px;
  padding: 0;
}

/* Een legend doet niet mee in het raster van zijn fieldset. */
legend.row__text {
  margin-bottom: 10px;
}

.row__text small {
  color: var(--muted);
  font-size: 0.875rem;
}

.switch {
  appearance: none;
  flex: none;
  position: relative;
  width: 54px;
  height: 32px;
  margin: 0;
  border-radius: 16px;
  background: var(--line);
  cursor: pointer;
  transition: background 150ms;
}

.switch::before {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgb(0 0 0 / 0.3);
  transition: transform 150ms;
}

.switch:checked {
  background: var(--good);
}

.switch:checked::before {
  transform: translateX(22px);
}

input[type="range"] {
  width: 100%;
  height: 32px;
  margin: 0;
  accent-color: var(--primary);
}

.range-ends {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 0.8125rem;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  border-radius: var(--radius);
  background: var(--bg);
}

.segmented label {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 48px;
  border-radius: 12px;
  font-weight: 700;
  cursor: pointer;
}

.segmented input {
  position: absolute;
  opacity: 0;
}

.segmented label:has(input:checked) {
  background: var(--primary);
  color: var(--primary-ink);
}

.segmented label:has(input:focus-visible) {
  outline: 3px solid var(--ink);
  outline-offset: 2px;
}

.adjust {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.adjust .button {
  min-height: 48px;
  font-size: 1rem;
}

.summary {
  margin: 0;
  font-size: 1.125rem;
}

.actions {
  display: grid;
  grid-auto-flow: column;
  gap: 8px;
}

.actions:not(:has(> :not([hidden]))) {
  display: none;
}

a.button {
  text-decoration: none;
  text-align: center;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition: none !important;
  }

  .sheet[open] {
    animation: none;
  }

  .button:active {
    transform: none;
  }
}
