:root {
  --bg: #ffffff;
  --soft: #f6f7f9;
  --ink: #0b0b0b;
  --ink2: #52514e;
  --muted: #898781;
  --line: #e3e5ea;
  --accent: #2a78d6;
  --accent-dark: #1c5cab;
  --good: #0ca30c;
  --warn: #eb6834;
  --radius: 14px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); }
body { font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-text-size-adjust: 100%; }

/* App shell: header, one page, footer. Nothing scrolls on a normal screen. */
.app { height: 100vh; height: 100dvh; display: grid; grid-template-rows: auto minmax(0, 1fr) auto; }
main { min-height: 0; padding: 14px max(18px, env(safe-area-inset-left)) 10px; }
.page { height: 100%; max-width: 1180px; margin: 0 auto; display: flex; flex-direction: column; min-height: 0; overflow: auto; }

h1 { font-size: clamp(24px, 3.6vh, 34px); margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 16px; margin: 0 0 8px; }
h2 small { font-weight: 400; color: var(--muted); }
h3 { font-size: 13px; margin: 14px 0 2px; }
.note { color: var(--ink2); margin: 4px 0; font-size: 13px; }
.fine { color: var(--muted); font-size: 12px; margin: 0; }

button, select, input[type="number"] { font: inherit; color: var(--ink); }
button { background: #fff; border: 1px solid #cfd3da; border-radius: 10px; padding: 8px 14px; cursor: pointer; }
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.primary:hover:not(:disabled) { background: var(--accent-dark); }
button.big { padding: 13px 34px; font-size: 17px; border-radius: 12px; }
select, input[type="number"] { border: 1px solid #cfd3da; border-radius: 8px; padding: 6px 8px; background: #fff; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Header */
.top { display: flex; align-items: center; gap: 12px 20px; padding: 10px max(18px, env(safe-area-inset-left)); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; border: 0; padding: 0; background: none; text-align: left; }
.brand b { display: block; font-size: 18px; letter-spacing: .06em; }
.brand small { display: block; font-size: 11px; color: var(--muted); }
.steps { display: flex; gap: 4px; margin: 0 auto; }
.steps button { border: 0; border-radius: 999px; padding: 6px 14px 6px 6px; display: flex; align-items: center; gap: 8px; color: var(--ink2); }
.steps i { font-style: normal; width: 24px; height: 24px; border-radius: 50%; background: var(--soft); border: 1px solid var(--line); display: grid; place-items: center; font-size: 12px; font-weight: 700; }
.steps button[aria-current="step"] { background: var(--soft); color: var(--ink); font-weight: 600; }
.steps button[aria-current="step"] i { background: var(--accent); border-color: var(--accent); color: #fff; }
.topright { display: flex; align-items: center; gap: 12px; }

.seg { display: inline-flex; border: 1px solid #cfd3da; border-radius: 10px; overflow: hidden; background: #fff; }
.seg button { border: 0; border-radius: 0; padding: 9px 20px; font-weight: 600; }
.seg.small button { padding: 5px 11px; font-size: 13px; }
.seg button[aria-checked="true"] { background: var(--ink); color: #fff; }

/* Eye signal indicators */
.eyemini { display: flex; gap: 5px; }
.eyemini span { width: 18px; height: 11px; border-radius: 50%; border: 2px solid #c3c7cf; background: #fff; }
.eyemini span.on { border-color: var(--good); background: var(--good); }
.eyemini span.face { border-color: var(--warn); }
.eyebig { display: flex; justify-content: center; gap: 4%; margin: 4px 0; flex: 1 1 auto; min-height: 60px; max-height: 150px; }
.eyebig svg { height: 100%; width: auto; max-width: 46%; }
.eyebig .lid { fill: #fff; stroke: #c3c7cf; stroke-width: 4; transition: stroke .2s, fill .2s; }
.eyebig .iris { fill: #dfe2e8; transition: fill .2s; }
.eyebig .pup { fill: #b4b9c2; transition: fill .2s; }
.eyebig .tick { fill: none; stroke: #fff; stroke-width: 5; stroke-linecap: round; stroke-linejoin: round; opacity: 0; }
.eyebig svg.face .lid { stroke: var(--warn); }
.eyebig svg.on .lid { stroke: var(--good); fill: #eaf7ea; }
.eyebig svg.on .iris { fill: var(--good); }
.eyebig svg.on .pup { fill: var(--good); }
.eyebig svg.on .tick { opacity: 1; }
.guide { font-size: 19px; font-weight: 600; text-align: center; margin: 4px 0 0; }
#guidesub { text-align: center; }

/* Welcome */
.hero { margin: auto; text-align: center; display: flex; flex-direction: column; align-items: center; gap: clamp(8px, 2vh, 18px); max-width: 860px; }
.herologo { width: clamp(64px, 14vh, 120px); height: auto; }
.lead { font-size: clamp(15px, 2.1vh, 18px); color: var(--ink2); margin: 0; }
.feat { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; width: 100%; }
.feat div { background: var(--soft); border-radius: var(--radius); padding: 14px; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.feat svg, .taskgrid svg { width: 28px; height: 28px; fill: none; stroke: var(--accent); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.feat span { font-size: 13px; color: var(--ink2); }
.who { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; justify-content: center; }

/* Cards and columns */
.cols { display: grid; grid-template-columns: minmax(300px, 5fr) 7fr; gap: 14px; height: 100%; min-height: 0; }
.cols.results { grid-template-columns: minmax(250px, 3fr) 9fr; }
.card { border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; min-height: 0; display: flex; flex-direction: column; background: #fff; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin: 8px 0; }
.chip { border: 1px solid var(--line); border-radius: 999px; padding: 2px 10px; font-size: 12px; color: var(--ink2); font-variant-numeric: tabular-nums; }
.chip.warn { border-color: var(--warn); color: #a23d12; }
.camctl { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; justify-content: center; font-size: 13px; margin-top: auto; }
.camctl select { max-width: 170px; }
#status { text-align: center; min-height: 1.4em; }

.viewhead { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.viewbody { flex: 1; min-height: 0; margin-top: 8px; display: flex; }
.view { flex: 1; min-height: 0; min-width: 0; display: flex; flex-direction: column; gap: 6px; align-items: center; justify-content: center; }
.view canvas { max-width: 100%; }
#camview { flex: 1; min-height: 0; width: 100%; object-fit: contain; border-radius: 10px; background: var(--soft); }
#eyes { flex: 1; min-height: 0; width: 100%; object-fit: contain; border-radius: 10px; transform: scaleX(-1); }
#video { position: fixed; left: 0; bottom: 0; width: 2px; height: 2px; opacity: .01; pointer-events: none; }
.plot { display: block; width: 100%; flex: 1; min-height: 60px; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--ink2); align-self: flex-start; }
.legend i { display: inline-block; width: 14px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 5px; }

/* Tests */
.testhead { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.testopts { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; font-size: 13px; }
.taskgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; flex: 1; min-height: 0; max-height: 300px; }
.taskgrid button { text-align: left; display: flex; flex-direction: column; gap: 6px; padding: 16px; border-radius: var(--radius); }
.taskgrid button:hover:not(:disabled) { box-shadow: 0 4px 14px rgba(42, 120, 214, .14); }
.taskgrid b { font-size: 16px; }
.taskgrid span { color: var(--ink2); font-size: 13px; }
#teststatus { min-height: 1.4em; margin-top: 10px; }

/* Results */
#runlist { flex: 1; min-height: 0; overflow: auto; display: flex; flex-direction: column; gap: 6px; }
#runlist button { text-align: left; display: flex; flex-direction: column; padding: 8px 10px; }
#runlist button small { color: var(--muted); }
#runlist button[aria-current="true"] { border-color: var(--accent); background: #f0f6fd; }
.dl { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.dl button { font-size: 13px; padding: 6px 10px; }
.rundetail h3 { margin: 0 0 4px; font-size: 15px; }
.rundetail ul { margin: 6px 0 0; padding-left: 18px; color: var(--ink2); font-size: 13px; overflow: auto; max-height: 34%; }

/* Footer */
.bottom { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px max(18px, env(safe-area-inset-left)) max(10px, env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }
.bottom .note { text-align: center; flex: 1; margin: 0; }

/* Dialogs */
dialog { border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; width: min(620px, 94vw); max-height: 92vh; box-shadow: 0 20px 60px rgba(0, 0, 0, .18); }
dialog::backdrop { background: rgba(20, 24, 32, .35); }
.dlgfoot { display: flex; justify-content: space-between; margin-top: 14px; }
.stimctl { display: flex; flex-wrap: wrap; gap: 10px 18px; align-items: center; margin: 8px 0; font-size: 13px; }
.thumbs { display: flex; gap: 8px; align-items: center; margin: 6px 0; }
.thumbs .lab { font-weight: 700; width: 16px; }
.thumbs div { display: flex; gap: 6px; flex-wrap: wrap; }
.thumbs canvas { width: 48px; height: 48px; border-radius: 6px; }
.cardcal { padding: 12px; display: grid; place-items: center; background: var(--soft); border-radius: 10px; overflow: hidden; }
#cardbox { border: 2px solid var(--accent); border-radius: 3.7%/5.9%; background: #fff; }
#cardslider { width: 100%; }
.distcal { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; font-size: 13px; }
.distcal input { width: 84px; }
.timing { display: flex; gap: 14px; flex-wrap: wrap; font-size: 13px; margin: 10px 0; }
.timing input { width: 70px; }

/* Test screen */
/* The pointer is hidden during tests, because a visible cursor attracts gaze. */
#stage { position: fixed; inset: 0; z-index: 10; background: rgb(128, 128, 128); touch-action: none; cursor: none; }
#stage canvas { width: 100%; height: 100%; display: block; }
#abort { position: absolute; top: max(8px, env(safe-area-inset-top)); right: max(8px, env(safe-area-inset-right)); width: 36px; height: 36px; padding: 0; border-radius: 50%; opacity: .35; }
#tip { position: fixed; z-index: 5; pointer-events: none; background: #fff; border: 1px solid #c3c2b7; border-radius: 6px; padding: 4px 8px; font-size: 12px; white-space: pre; box-shadow: 0 2px 8px rgba(0, 0, 0, .08); }

/* Tablets and phones */
@media (max-width: 820px) {
  .brand small { display: none; }
  .steps { order: 3; width: 100%; justify-content: center; }
  .cols, .cols.results { grid-template-columns: 1fr; grid-template-rows: auto minmax(180px, 1fr); height: auto; min-height: 100%; }
  .feat { grid-template-columns: 1fr; }
  .feat div { flex-direction: row; text-align: left; gap: 10px; padding: 10px 12px; }
  .feat div b { white-space: nowrap; }
  .taskgrid { max-height: none; flex: none; }
  .bottom .note { display: none; }
  .taskgrid button { padding: 12px; }
}
@media (max-height: 520px) {
  .top { padding-top: 4px; padding-bottom: 4px; }
  .brand img { width: 26px; height: 26px; }
  .feat { display: none; }
  .herologo { width: 48px; }
}
