/* FPV школа. Тема — кабіна пілота: графіт, один сигнальний помаранчевий,
   рамка видошукача й телеметрія там, де вони несуть дані, а не прикрашають. */

:root {
  color-scheme: dark light;

  --bg: #0f1012;
  --bg-2: #131417;
  --surface: #17191c;
  --surface-2: #1f2125;
  --line: #2a2d32;
  --line-strong: #3b3f45;
  --ink: #eeece8;
  --ink-2: #aeaaa2;
  --ink-3: #85827b;
  --accent: #ff7a1f;
  --accent-hover: #ff9446;
  --accent-soft: #33200f;
  --on-accent: #160b02;
  --ok: #5fd08c;
  --ok-soft: #14291d;
  --warn: #f0c04f;
  --warn-soft: #2e2611;
  --bad: #ff6f5e;
  --bad-soft: #341815;
  --focus: #ff7a1f;
  --figure-bg: #0b0c0e;

  --font-sans: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --font-mono: ui-monospace, 'Cascadia Mono', 'SF Mono', 'JetBrains Mono', Menlo, Consolas, monospace;

  --r-sm: 6px;
  --r: 10px;
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f3f0;
    --bg-2: #eeece8;
    --surface: #ffffff;
    --surface-2: #f0eeea;
    --line: #dedbd4;
    --line-strong: #c6c2b9;
    --ink: #17181a;
    --ink-2: #4c4a46;
    --ink-3: #6a6761;
    --accent: #c8510a;
    --accent-hover: #a84207;
    --accent-soft: #fbeadf;
    --on-accent: #ffffff;
    --ok: #217047;
    --ok-soft: #e2f1e8;
    --warn: #8a5a00;
    --warn-soft: #f8eed8;
    --bad: #b02a1c;
    --bad-soft: #fbe7e4;
    --focus: #c8510a;
    --figure-bg: #0f1012;
  }
}

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

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 {
  margin: 0;
  line-height: 1.2;
  font-weight: 650;
  letter-spacing: -0.01em;
  text-wrap: balance;
}

h1 { font-size: clamp(26px, 4.4vw, 36px); letter-spacing: -0.02em; }
h2 { font-size: 22px; }
h3 { font-size: 17px; }

p { margin: 0; text-wrap: pretty; }

a {
  color: inherit;
  text-underline-offset: 3px;
}

code, .mono {
  font-family: var(--font-mono);
  font-size: 0.92em;
}

.num {
  font-variant-numeric: tabular-nums;
}

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

.hidden {
  display: none !important;
}

.muted { color: var(--ink-2); }
.dim { color: var(--ink-3); font-size: 14px; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ===== Header ===== */
.topbar {
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}

.topbar-inner {
  max-width: 1040px;
  margin: 0 auto;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  display: inline-flex;
  gap: 10px;
  text-decoration: none;
  color: var(--ink);
  font-weight: 700;
  font-size: 16px;
  letter-spacing: 0.01em;
  min-height: 32px;
  align-items: center;
}

.brand-mark {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  background: var(--accent);
  flex-shrink: 0;
}

.brand-sub {
  color: var(--ink-3);
  font-weight: 500;
  font-size: 14px;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 14px;
  color: var(--ink-2);
}

.topbar-link {
  white-space: nowrap;
  color: var(--ink-2);
  text-decoration: none;
  min-height: 32px;
  display: inline-flex;
  align-items: center;
}

.topbar-link:hover { color: var(--ink); text-decoration: underline; }

/* ===== Layout ===== */
.page {
  max-width: 1040px;
  margin: 0 auto;
  padding: 40px 16px 80px;
}

.page-narrow {
  max-width: 720px;
  margin: 0 auto;
  padding: 32px 16px 80px;
}

.page-head {
  display: grid;
  gap: 10px;
  margin-bottom: 28px;
}

.page-head p {
  color: var(--ink-2);
  max-width: 60ch;
}

.eyebrow {
  font-size: 14px;
  color: var(--ink-3);
}

.stack { display: grid; gap: 16px; }

.row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.row-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.section-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

.section-head p { color: var(--ink-2); font-size: 15px; margin-top: 4px; }

/* ===== Surfaces ===== */
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 24px;
}

.panel + .panel { margin-top: 16px; }

.note {
  border-left: 3px solid var(--line-strong);
  padding: 2px 0 2px 14px;
  color: var(--ink-2);
  font-size: 15px;
}

.note-spaced { margin-bottom: 22px; }

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  margin-bottom: 16px;
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--bg-2);
}

.seg-btn {
  height: 40px;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--ink-2);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.seg-btn[aria-selected='true'] { background: var(--surface-2); color: var(--ink); }

.pilot-badge { display: inline-flex; align-items: center; gap: 10px; color: var(--ink); }

.link-btn {
  padding: 0;
  min-height: 32px;
  border: 0;
  background: none;
  color: var(--ink-3);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.link-btn:hover { color: var(--ink); }

.whoami { margin: 0 0 18px; font-size: 16px; }
.whoami strong { color: var(--ink); }

.empty {
  padding: 32px 0;
  color: var(--ink-2);
}

/* ===== Hero: viewfinder frame + course telemetry ===== */
.hero {
  position: relative;
  padding: 44px 40px 36px;
  margin-bottom: 36px;
  border: 1px solid var(--line);
  border-radius: var(--r);
  background:
    linear-gradient(var(--bg-2), var(--bg-2)) padding-box;
  overflow: hidden;
}

.hero h1 {
  font-size: clamp(32px, 6vw, 56px);
  line-height: 1.02;
  letter-spacing: -0.035em;
  font-weight: 700;
  max-width: 14ch;
}

.hero h1 em {
  font-style: normal;
  color: var(--accent);
}

.hero p {
  margin-top: 14px;
  color: var(--ink-2);
  max-width: 46ch;
  font-size: 17px;
}

.hero .eyebrow { display: block; margin-bottom: 18px; }

/* Four corner brackets, like the frame lines in FPV goggles. */
.vf {
  position: absolute;
  inset: 14px;
  pointer-events: none;
}

.vf i {
  position: absolute;
  width: 18px;
  height: 18px;
  border-color: var(--ink-3);
  border-style: solid;
  border-width: 0;
}

.vf i:nth-child(1) { top: 0; left: 0; border-top-width: 2px; border-left-width: 2px; }
.vf i:nth-child(2) { top: 0; right: 0; border-top-width: 2px; border-right-width: 2px; }
.vf i:nth-child(3) { bottom: 0; left: 0; border-bottom-width: 2px; border-left-width: 2px; }
.vf i:nth-child(4) { bottom: 0; right: 0; border-bottom-width: 2px; border-right-width: 2px; }

/* Artificial horizon: a level line with a pitch ladder, drawn in CSS. */
.horizon {
  position: absolute;
  right: 40px;
  top: 50%;
  width: min(34%, 300px);
  height: 120px;
  transform: translateY(-50%);
  pointer-events: none;
  opacity: 0.8;
}

/* The pitch ladder banks slowly; the aircraft symbol (::after) stays level, like a real attitude indicator. */
.horizon::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    linear-gradient(var(--ink-3), var(--ink-3)) center / 100% 1px no-repeat,
    linear-gradient(var(--line-strong), var(--line-strong)) center 20% / 40% 1px no-repeat,
    linear-gradient(var(--line-strong), var(--line-strong)) center 80% / 40% 1px no-repeat,
    linear-gradient(var(--line-strong), var(--line-strong)) center 35% / 22% 1px no-repeat,
    linear-gradient(var(--line-strong), var(--line-strong)) center 65% / 22% 1px no-repeat;
  animation: horizon-bank 9s ease-in-out infinite;
}

@keyframes horizon-bank {
  0%, 100% { transform: rotate(-3deg) translateY(2px); }
  50% { transform: rotate(3deg) translateY(-2px); }
}

.horizon::after {
  /* the aircraft symbol in the middle */
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  width: 44px;
  height: 10px;
  transform: translate(-50%, -2px);
  border: 2px solid var(--accent);
  border-top: 0;
}

.telemetry {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 36px;
  margin: 30px 0 0;
  padding-top: 18px;
  border-top: 1px dashed var(--line-strong);
}

.telemetry div { display: grid; gap: 2px; }

.telemetry dt {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-3);
}

.telemetry dd {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 24px;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}

/* ===== Chips (filters) ===== */
.chips {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.chip {
  height: 34px;
  padding: 0 14px;
  border-radius: 17px;
  border: 1px solid var(--line-strong);
  background: transparent;
  color: var(--ink-2);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background-color 0.15s var(--ease), color 0.15s var(--ease), border-color 0.15s var(--ease);
}

.chip:hover { color: var(--ink); border-color: var(--ink-3); }

.chip[aria-pressed='true'] {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--bg);
}

.chip .count {
  font-variant-numeric: tabular-nums;
  opacity: 0.7;
}

/* ===== Test list (student catalog) ===== */
.test-list {
  list-style: none;
  margin: 0;
  padding: 0;
  border-top: 1px solid var(--line);
}

.test-row {
  position: relative;
  display: grid;
  grid-template-columns: 88px 1fr auto;
  gap: 4px 24px;
  align-items: start;
  padding: 26px 12px 26px 0;
  border-bottom: 1px solid var(--line);
  transition: background-color 0.2s var(--ease);
}

.test-row::before {
  /* thin signal bar on the left edge, lights up on hover */
  content: '';
  position: absolute;
  left: 0;
  top: 26px;
  bottom: 26px;
  width: 2px;
  background: var(--accent);
  transform: scaleY(0);
  transform-origin: top;
  transition: transform 0.25s var(--ease);
}

.test-row:hover { background: var(--bg-2); }
.test-row:hover::before { transform: scaleY(1); }

.test-index {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 40px;
  font-weight: 300;
  line-height: 1;
  letter-spacing: -0.04em;
  color: var(--ink-3);
  padding-left: 18px;
  transition: color 0.2s var(--ease);
}

.test-row:hover .test-index { color: var(--accent); }

.test-day {
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
}

.test-body { display: grid; gap: 6px; min-width: 0; }

.test-body p { color: var(--ink-2); font-size: 15px; max-width: 62ch; }

.meta {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  font-size: 14px;
  color: var(--ink-3);
}

.meta span + span::before {
  content: '·';
  margin-right: 14px;
  color: var(--line-strong);
}

.test-action { align-self: center; }

.test-row.is-locked h3,
.test-row.is-locked .test-body p { color: var(--ink-3); }
.test-row.is-locked .test-day { color: var(--ink-3); }
.test-row.is-locked:hover::before { transform: scaleY(0); }
.test-row.is-locked:hover .test-index { color: var(--ink-3); }

.passed-tag { justify-self: start; }

.lock-text {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--warn);
}

.lock-text::before {
  content: '';
  width: 8px;
  height: 8px;
  border: 2px solid currentColor;
  border-radius: 2px;
}

.lock-banner {
  margin: 0 0 16px;
  padding: 14px 16px;
  border: 1px solid var(--line-strong);
  border-left: 3px solid var(--warn);
  border-radius: var(--r-sm);
  background: var(--warn-soft);
  color: var(--ink);
  font-size: 15px;
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 42px;
  padding: 0 18px;
  border-radius: var(--r-sm);
  border: 1px solid transparent;
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: background-color 0.15s var(--ease), border-color 0.15s var(--ease), color 0.15s var(--ease),
    transform 0.1s var(--ease);
}

.btn:active:not(:disabled) { transform: scale(0.97); }

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  color: var(--on-accent);
}

.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }

.btn-secondary {
  background: var(--surface);
  color: var(--ink);
  border-color: var(--line-strong);
}

.btn-secondary:hover:not(:disabled) { border-color: var(--ink-3); }

.btn-ghost {
  background: transparent;
  color: var(--ink-2);
}

.btn-ghost:hover:not(:disabled) { color: var(--ink); background: var(--surface-2); }

.btn-danger {
  background: transparent;
  color: var(--bad);
  border-color: var(--line-strong);
}

.btn-danger:hover:not(:disabled) { background: var(--bad-soft); border-color: var(--bad); }

.btn-sm {
  height: 34px;
  padding: 0 12px;
  font-size: 14px;
}

.btn-block { width: 100%; }

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 32px;
  margin-bottom: 20px;
  color: var(--ink-2);
  font-size: 15px;
  text-decoration: none;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  font-family: inherit;
}

.back-link:hover { color: var(--ink); text-decoration: underline; }

/* ===== Forms ===== */
.field { display: grid; gap: 6px; margin-bottom: 18px; }

.field label,
.field .label {
  font-size: 14px;
  font-weight: 600;
  color: var(--ink-2);
}

.field .hint { font-size: 13px; color: var(--ink-3); }

.input,
.textarea,
.select {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-sm);
  color: var(--ink);
  font: inherit;
  font-size: 16px; /* 16px stops iOS from zooming into the field */
  padding: 10px 12px;
  transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}

.input,
.select { height: 44px; }

/* Native select with our own chevron, so it looks like the other fields in both themes. */
.select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 38px;
  cursor: pointer;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--ink-2) 50%),
    linear-gradient(135deg, var(--ink-2) 50%, transparent 50%);
  background-position:
    right 18px center,
    right 13px center;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

.select option {
  background: var(--surface);
  color: var(--ink);
}

.input:focus,
.textarea:focus,
.select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.textarea {
  min-height: 140px;
  resize: vertical;
  line-height: 1.55;
}

.select-sm { height: 34px; width: auto; padding: 0 34px 0 10px; font-size: 14px; }

.check {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  cursor: pointer;
  font-size: 15px;
  color: var(--ink);
}

.check input {
  width: 18px;
  height: 18px;
  margin: 2px 0 0;
  accent-color: var(--accent);
  flex-shrink: 0;
}

/* Toggle switch: a real checkbox underneath, so keyboard and screen readers work as usual. */
.switch {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  cursor: pointer;
  font-size: 15px;
  color: var(--ink);
}

.switch input {
  position: absolute;
  opacity: 0;
  width: 40px;
  height: 22px;
  margin: 0;
  cursor: pointer;
}

.switch-track {
  position: relative;
  flex-shrink: 0;
  width: 40px;
  height: 22px;
  border-radius: 11px;
  background: var(--line-strong);
  transition: background-color 0.15s var(--ease);
}

.switch-track::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.25);
  transition: transform 0.18s var(--ease);
}

.switch input:checked + .switch-track { background: var(--accent); }
.switch input:checked + .switch-track::after { transform: translateX(18px); }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--focus); outline-offset: 2px; }

/* Correct answer shown during the test */
/* .options prefix outranks .option:has(input:checked) */
.options .option.is-locked { cursor: default; }
.options .option.is-locked:hover { border-color: var(--line-strong); }
.options .option.is-correct,
.options .option.is-correct:hover { border-color: var(--ok); background: var(--ok-soft); }
.options .option.is-wrong,
.options .option.is-wrong:hover { border-color: var(--bad); background: var(--bad-soft); }

.reveal {
  margin-top: 14px;
  padding: 14px 16px;
  border-radius: var(--r-sm);
  background: var(--surface-2);
  font-size: 15px;
}

.reveal-title { font-weight: 650; margin-bottom: 4px; }
.reveal-title.ok { color: var(--ok); }
.reveal-title.bad { color: var(--bad); }
.reveal-text { white-space: pre-wrap; color: var(--ink-2); }

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

/* ===== Tags (status labels) ===== */
.tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 24px;
  padding: 0 9px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--ink-2);
  white-space: nowrap;
}

.tag::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 3px;
  background: currentColor;
}

.tag-plain::before { display: none; }
.tag-ok { background: var(--ok-soft); color: var(--ok); }
.tag-warn { background: var(--warn-soft); color: var(--warn); }
.tag-bad { background: var(--bad-soft); color: var(--bad); }
.tag-accent { background: var(--accent-soft); color: var(--accent); }

/* ===== Test runner ===== */
.runner-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  font-family: var(--font-mono);
  font-size: 13px;
  letter-spacing: 0.04em;
  font-variant-numeric: tabular-nums;
  color: var(--ink-2);
  margin-bottom: 12px;
}

/* One segment per question, like a battery-cell meter in the OSD. */
.segments {
  display: flex;
  gap: 4px;
  margin-bottom: 22px;
}

.segments span {
  flex: 1;
  height: 6px;
  border-radius: 3px;
  background: var(--line);
  transition: background-color 0.2s var(--ease);
}

.segments .is-done { background: var(--ink-3); }
.segments .is-current { background: var(--accent); }
.segments .is-right { background: var(--ok); }
.segments .is-wrong { background: var(--bad); }

.runner-status .group { display: flex; gap: 18px; align-items: center; }

.focus-state { display: inline-flex; align-items: center; gap: 7px; }

.focus-state::before {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 4px;
  background: var(--ok);
}

.focus-state.warn::before { background: var(--warn); }
.focus-state.bad::before { background: var(--bad); }

.question-labels { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }

.question-text {
  font-size: 20px;
  font-weight: 600;
  line-height: 1.45;
  margin: 0 0 18px;
  text-wrap: pretty;
}

.figure {
  margin: 0 0 20px;
}

.figure-btn {
  display: block;
  width: 100%;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--figure-bg);
  cursor: zoom-in;
  overflow: hidden;
}

.figure-btn img {
  display: block;
  width: 100%;
  max-height: 440px;
  object-fit: contain;
}

.figure figcaption {
  margin-top: 6px;
  font-size: 13px;
  color: var(--ink-3);
}

.options {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  border: 0;
}

.option {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 16px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-sm);
  background: var(--surface);
  cursor: pointer;
  transition: border-color 0.15s var(--ease), background-color 0.15s var(--ease), transform 0.1s var(--ease);
}

.option:hover { border-color: var(--ink-3); }
.option:active:not(.is-locked) { transform: scale(0.99); }

.option input {
  width: 18px;
  height: 18px;
  margin: 2px 0 0;
  accent-color: var(--accent);
  flex-shrink: 0;
}

.option:has(input:checked) {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.answer-hint { margin-top: 8px; font-size: 13px; color: var(--ink-3); }

.runner-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 24px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

/* ===== Result summary ===== */
.score {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin: 28px 0 4px;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

.score-value { font-size: 64px; line-height: 1; letter-spacing: -0.04em; color: var(--accent); }
.score-label { color: var(--ink-3); font-size: 14px; }

.facts {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 8px 24px;
  margin: 24px 0 28px;
  font-size: 15px;
}

.facts dt { color: var(--ink-3); }
.facts dd { margin: 0; font-variant-numeric: tabular-nums; font-weight: 600; }

/* ===== Dialogs ===== */
dialog {
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--surface);
  color: var(--ink);
  padding: 0;
  width: min(820px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
}

dialog::backdrop { background: rgb(20 19 17 / 0.55); }

dialog[open] { animation: dialog-in 0.18s var(--ease); }

@keyframes dialog-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.dialog-head {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.dialog-body { padding: 20px; }

.dialog-foot {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 16px 20px;
  border-top: 1px solid var(--line);
}

.lightbox {
  width: auto;
  max-width: calc(100vw - 32px);
  background: var(--figure-bg);
  border: 0;
  cursor: zoom-out;
}

.lightbox img {
  display: block;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 48px);
}

/* ===== Toasts ===== */
.toasts {
  position: fixed;
  right: 16px;
  bottom: 16px;
  left: 16px;
  z-index: 90;
  display: grid;
  justify-items: end;
  gap: 8px;
  pointer-events: none;
}

.toast {
  max-width: 400px;
  padding: 12px 16px;
  border-radius: var(--r-sm);
  background: var(--ink);
  color: var(--bg);
  font-size: 15px;
  box-shadow: 0 8px 24px rgb(0 0 0 / 0.18);
  animation: toast-in 0.2s var(--ease);
  transition: opacity 0.2s var(--ease);
}

.toast-warn { border-left: 4px solid var(--warn); }
.toast-err { border-left: 4px solid var(--bad); }
.toast-ok { border-left: 4px solid var(--ok); }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

/* ===== Admin ===== */
.tabs {
  display: flex;
  gap: 4px 24px;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--line);
  margin-bottom: 32px;
}

.tab {
  height: 44px;
  padding: 0;
  margin-bottom: -1px;
  background: none;
  border: 0;
  border-bottom: 2px solid transparent;
  color: var(--ink-2);
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

.tab:hover { color: var(--ink); }

.tab[aria-selected='true'] {
  color: var(--ink);
  border-bottom-color: var(--accent);
}

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1px;
  background: var(--line);
  border: 1px solid var(--line);
  border-radius: var(--r);
  overflow: hidden;
  margin-bottom: 32px;
}

.stat {
  background: var(--surface);
  padding: 18px 20px;
  display: grid;
  gap: 2px;
}

.stat-value {
  font-size: 30px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

.stat-label { font-size: 14px; color: var(--ink-2); }
.stat-sub { font-size: 13px; color: var(--ink-3); }

.inline-form {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: flex-end;
}

.inline-form .field { margin-bottom: 0; flex: 1 1 200px; }

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 20px;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 12px;
  align-content: start;
  min-width: 0;
}

.card p { color: var(--ink-2); font-size: 15px; }

.ref-link {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 6px 6px 12px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--bg);
}

.ref-link code {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
  color: var(--ink-2);
}

.actions { display: flex; gap: 8px; flex-wrap: wrap; }

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--surface);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 15px;
}

th,
td {
  padding: 12px 14px;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--line);
}

th {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-3);
  background: var(--surface-2);
  white-space: nowrap;
}

tr:last-child td { border-bottom: 0; }

tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover td { background: var(--surface-2); }

.cell-sub { font-size: 13px; color: var(--ink-3); margin-top: 2px; }

.q-editor {
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  padding: 16px;
  margin-bottom: 12px;
  background: var(--bg);
  display: grid;
  gap: 12px;
}

.q-editor-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.opt-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.opt-row input[type='radio'] { width: 18px; height: 18px; accent-color: var(--accent); flex-shrink: 0; }
.opt-row .input { height: 38px; }

.img-preview {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.img-preview img {
  max-height: 100px;
  max-width: 200px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: #fff;
  object-fit: contain;
}

.file-btn { position: relative; }
.file-btn:focus-within { outline: 2px solid var(--focus); outline-offset: 2px; }
.file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

.answer-block {
  border-top: 1px solid var(--line);
  padding: 14px 0;
}

.answer-block .q { font-size: 14px; color: var(--ink-2); margin-bottom: 6px; }
.answer-block .a { white-space: pre-wrap; font-size: 15px; }

.text-bad { color: var(--bad); }

.role-tag { margin-left: 6px; height: 20px; border-radius: 10px; font-size: 12px; vertical-align: 1px; }

.start-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 14px;
  color: var(--ink-2);
}

.input-sm { height: 36px; width: auto; padding: 0 10px; font-size: 14px; }

.progress-table th,
.progress-table td { white-space: nowrap; }
.progress-table td:first-child { white-space: normal; min-width: 140px; }

.day-cell {
  display: inline-grid;
  gap: 1px;
  min-width: 84px;
  padding: 6px 10px;
  border-radius: var(--r-sm);
  border: 1px solid transparent;
  font: inherit;
  font-size: 13px;
  text-align: left;
  color: var(--ink-2);
  background: var(--surface-2);
}

button.day-cell { cursor: pointer; }
button.day-cell:hover { border-color: var(--ink-3); }
.day-cell.cell-ok { background: var(--ok-soft); color: var(--ok); }
.day-cell.cell-done { background: var(--surface-2); color: var(--ink); }
.day-cell.cell-missed { background: var(--bad-soft); color: var(--bad); }
.day-cell.cell-open { background: var(--accent-soft); color: var(--accent); }
.day-cell.cell-locked { background: transparent; color: var(--ink-3); }

.grade-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.grade-btn { background: transparent; border-color: var(--line-strong); color: var(--ink-2); }
.grade-btn.is-ok { background: var(--ok-soft); border-color: var(--ok); color: var(--ok); }
.grade-btn.is-bad { background: var(--bad-soft); border-color: var(--bad); color: var(--bad); }

.event-log {
  margin: 8px 0 0;
  padding-left: 18px;
  font-size: 14px;
  color: var(--ink-2);
}

.help-list {
  margin: 0;
  padding-left: 20px;
  display: grid;
  gap: 10px;
  color: var(--ink-2);
  font-size: 15px;
}

.settings-grid {
  display: grid;
  grid-template-columns: minmax(0, 3fr) minmax(0, 2fr);
  gap: 16px;
  align-items: start;
}

.settings-grid .panel + .panel { margin-top: 0; }

/* Corner brackets around a question's scheme, same motif as the hero. */
.figure-vf .figure-btn {
  position: relative;
  background:
    linear-gradient(var(--accent), var(--accent)) top left / 16px 2px no-repeat,
    linear-gradient(var(--accent), var(--accent)) top left / 2px 16px no-repeat,
    linear-gradient(var(--accent), var(--accent)) bottom right / 16px 2px no-repeat,
    linear-gradient(var(--accent), var(--accent)) bottom right / 2px 16px no-repeat,
    var(--figure-bg);
  padding: 10px;
}

/* ===== Tablets ===== */
@media (max-width: 900px) {
  .settings-grid { grid-template-columns: 1fr; }
  .hero { padding: 36px 28px 30px; }
  .horizon { width: 30%; right: 24px; }
  .cards { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
}

@media (max-width: 760px) {
  .horizon { display: none; }
}

/* ===== Phones ===== */
@media (max-width: 680px) {
  body { font-size: 16px; }
  .page,
  .page-narrow { padding: 20px 16px 64px; }
  .panel { padding: 18px; }
  .grid-2 { grid-template-columns: 1fr; }
  .brand-sub { display: none; }
  .topbar-inner { padding: 10px 16px; }

  .hero { padding: 30px 20px 24px; margin-bottom: 24px; }
  .hero h1 { font-size: 34px; }
  .hero p { font-size: 16px; }
  .vf { inset: 10px; }
  .telemetry { gap: 12px 24px; margin-top: 22px; }
  .telemetry dd { font-size: 20px; }

  .chips {
    flex-wrap: nowrap;
    overflow-x: auto;
    margin: 0 -16px 16px;
    padding: 0 16px 4px;
    scrollbar-width: none;
  }
  .chips::-webkit-scrollbar { display: none; }
  .chip { flex-shrink: 0; height: 38px; border-radius: 19px; }

  .test-row {
    grid-template-columns: 52px 1fr;
    gap: 10px 14px;
    padding: 20px 0;
  }
  .test-row::before { display: none; }
  .test-index { font-size: 26px; padding-left: 0; }
  .test-action { grid-column: 1 / -1; }
  .test-action .btn { width: 100%; height: 46px; }

  .question-text { font-size: 18px; }
  .option { padding: 15px 14px; font-size: 16px; }
  .input, .select { height: 48px; }
  .btn { height: 46px; }
  .btn-sm { height: 38px; }

  /* The test's Back/Next stay under the thumb. */
  .runner-footer {
    position: sticky;
    bottom: 0;
    z-index: 5;
    margin: 20px -18px -18px;
    padding: 12px 18px calc(12px + env(safe-area-inset-bottom));
    background: var(--surface);
    border-radius: 0 0 var(--r) var(--r);
  }
  .runner-footer .btn { flex: 1; height: 50px; }

  .score-value { font-size: 52px; }

  /* Admin */
  .tabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    gap: 22px;
    margin: 0 -16px 24px;
    padding: 0 16px;
    scrollbar-width: none;
  }
  .tabs::-webkit-scrollbar { display: none; }
  .tab { flex-shrink: 0; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat { padding: 14px 16px; }
  .stat-value { font-size: 24px; }
  .inline-form .btn { width: 100%; }
  .table-wrap table { min-width: 620px; }
  .cards { grid-template-columns: 1fr; }
  .actions .btn { flex: 1 1 auto; }

  dialog {
    width: 100vw;
    max-width: 100vw;
    height: 100dvh;
    max-height: 100dvh;
    margin: 0;
    border-radius: 0;
    border: 0;
  }
  .dialog-head,
  .dialog-body,
  .dialog-foot { padding-left: 16px; padding-right: 16px; }
  .dialog-foot {
    position: sticky;
    bottom: 0;
    background: var(--surface);
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
  }
  .dialog-foot .btn { flex: 1; }
  .lightbox { width: auto; height: auto; margin: auto; background: var(--figure-bg); }

  .toasts { left: 12px; right: 12px; bottom: calc(76px + env(safe-area-inset-bottom)); justify-items: stretch; }
  .toast { max-width: none; }
}

/* Touch screens: no hover-only effects that stick after a tap. */
@media (hover: none) {
  .test-row:hover { background: none; }
  .test-row:hover::before { transform: scaleY(0); }
  .test-row:hover .test-index { color: var(--ink-3); }
}

/* ===== Motion =====
   Short, ease-out, never in the way: screens and rows arrive, the question slides in from the
   side the pilot is moving to, a right answer flashes green, a wrong one gives a small shake. */

@keyframes view-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}

.view-enter { animation: view-in 0.32s var(--ease) both; }

.row-enter {
  animation: view-in 0.4s var(--ease) both;
  animation-delay: calc(min(var(--i, 0), 10) * 45ms);
}

@keyframes q-in-next {
  from { opacity: 0; transform: translateX(22px); }
  to { opacity: 1; transform: none; }
}

@keyframes q-in-prev {
  from { opacity: 0; transform: translateX(-22px); }
  to { opacity: 1; transform: none; }
}

.q-enter-next { animation: q-in-next 0.26s var(--ease) both; }
.q-enter-prev { animation: q-in-prev 0.26s var(--ease) both; }

@keyframes flash-ok {
  0% { box-shadow: 0 0 0 0 var(--ok); }
  100% { box-shadow: 0 0 0 12px transparent; }
}

@keyframes shake {
  0%, 100% { transform: none; }
  20% { transform: translateX(-5px); }
  40% { transform: translateX(5px); }
  60% { transform: translateX(-3px); }
  80% { transform: translateX(2px); }
}

.options .option.is-correct.just-revealed { animation: flash-ok 0.7s ease-out; }
.options .option.is-wrong.just-revealed { animation: shake 0.4s ease-in-out; }
.reveal.just-revealed { animation: view-in 0.3s var(--ease) both; }

@keyframes seg-fill {
  from { transform: scaleX(0); }
  to { transform: scaleX(1); }
}

.segments .is-current { transform-origin: left; animation: seg-fill 0.35s var(--ease); }

/* Viewfinder corners close in on the hero when the page opens. */
@keyframes vf-in {
  from { opacity: 0; transform: translate(var(--dx), var(--dy)); }
  to { opacity: 1; transform: none; }
}

.vf i { animation: vf-in 0.6s var(--ease) both; animation-delay: 0.1s; }
.vf i:nth-child(1) { --dx: -10px; --dy: -10px; }
.vf i:nth-child(2) { --dx: 10px; --dy: -10px; }
.vf i:nth-child(3) { --dx: -10px; --dy: 10px; }
.vf i:nth-child(4) { --dx: 10px; --dy: 10px; }

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    animation-delay: 0s !important;
    transition-duration: 0.01ms !important;
  }
}
