:root {
  --ink: #1c1a17;
  --mid: #8c8579;
  --paper: #efe8da;
  --glass: rgba(20, 19, 15, 0.62);
  --line: rgba(239, 232, 218, 0.22);
  --text: #f3eee4;
  --dim: rgba(243, 238, 228, 0.66);
  --accent: #e9a23b;
  --ok: #8fc79a;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: #14130f; color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, system-ui, sans-serif;
  user-select: none; -webkit-user-select: none; touch-action: manipulation;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }

#stage { position: fixed; inset: 0; overflow: hidden; background: #0d0c0a; }
#video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
#still, #overlay { position: absolute; inset: 0; width: 100%; height: 100%; }
#gl { position: absolute; }
#overlay { pointer-events: none; }

/* ── top ── */
#top {
  position: fixed; top: calc(var(--safe-t) + 74px); left: 0; right: 0;
  display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none;
}
.chip {
  pointer-events: auto; padding: 7px 14px; border-radius: 999px;
  background: var(--accent); color: #1a1408; font-weight: 600; font-size: 14px;
  box-shadow: 0 2px 12px rgba(0,0,0,.35);
}
#toast {
  pointer-events: auto; max-width: min(92vw, 420px); padding: 10px 14px; border-radius: 12px;
  background: var(--glass); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  font-size: 14px; color: var(--text); text-align: center;
}

#toprow {
  position: fixed; z-index: 3; top: calc(var(--safe-t) + 10px); left: 12px; right: 12px;
  display: flex; gap: 8px; align-items: flex-start;
}
#cam {
  flex: none; padding: 7px 12px; border-radius: 999px; font-size: 13px; font-weight: 600;
  background: var(--glass); border: 1px solid var(--line);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
#cam::first-letter { color: #e5534b; }
#valuebar {
  flex: 1; min-width: 0; padding: 5px; border-radius: 12px;
  background: var(--glass); border: 1px solid var(--line);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
#vsegs { display: flex; height: 22px; border-radius: 7px; overflow: hidden; }
#vsegs div {
  flex-basis: 0; min-width: 3px; display: grid; place-items: center;
  font-size: 11px; font-weight: 600; transition: flex-grow .25s;
}
#vsegs div.ground { box-shadow: inset 0 -3px 0 var(--accent); }
.vmeta { display: flex; justify-content: space-between; align-items: center; padding: 4px 3px 0; font-size: 11.5px; color: var(--dim); }
#vpal { font-size: 11.5px; font-weight: 600; color: var(--text); padding: 0 2px; }
#vpal::after { content: ' ▾'; color: var(--dim); }

/* ── beam ── */
#beamwrap {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--safe-b) + 170px); width: min(72vw, 340px); height: 54px; pointer-events: none;
}
#beam { position: absolute; left: 0; right: 0; top: 14px; height: 6px; transition: transform .12s linear; }
#beam .bar { position: absolute; inset: 0; border-radius: 3px; background: var(--text); box-shadow: 0 1px 6px rgba(0,0,0,.5); }
#beam .end { position: absolute; top: -5px; width: 16px; height: 16px; border-radius: 50%; background: var(--text); }
#beam .end.l { left: -4px; } #beam .end.r { right: -4px; }
.fulcrum {
  position: absolute; left: 50%; top: 20px; transform: translateX(-50%);
  width: 0; height: 0; border-left: 9px solid transparent; border-right: 9px solid transparent;
  border-bottom: 14px solid var(--text); filter: drop-shadow(0 1px 3px rgba(0,0,0,.5));
}
#beamlabel {
  position: absolute; top: 36px; left: 0; right: 0; text-align: center;
  font-size: 13px; font-weight: 600; letter-spacing: .02em; text-shadow: 0 1px 4px rgba(0,0,0,.8);
}
#beamwrap.hit #beam .bar, #beamwrap.hit #beam .end { background: var(--accent); }
#beamwrap.hit .fulcrum { border-bottom-color: var(--accent); }
#beamwrap.hit #beamlabel { color: var(--accent); }

/* ── controls ── */
#bar {
  position: fixed; left: 0; right: 0; bottom: 0;
  padding: 10px 12px calc(var(--safe-b) + 14px);
  background: linear-gradient(to top, rgba(14,13,10,.92), rgba(14,13,10,.55) 70%, transparent);
}
#bar .row { display: flex; justify-content: center; gap: 8px; }
#bar .row.main { justify-content: space-between; align-items: center; margin-top: 14px; padding: 0 10px; }
.seg { display: flex; border: 1px solid var(--line); border-radius: 999px; padding: 2px; background: var(--glass); }
.seg button { padding: 6px 10px; border-radius: 999px; font-size: 13px; color: var(--dim); }
.seg button.on { background: var(--text); color: var(--ink); font-weight: 600; }
.side { display: flex; flex-direction: column; align-items: center; gap: 2px; width: 64px; font-size: 11px; color: var(--dim); cursor: pointer; }
.side .icon { font-size: 22px; line-height: 1; color: var(--text); }
#shutter {
  width: 72px; height: 72px; border-radius: 50%; border: 4px solid var(--text);
  display: grid; place-items: center;
}
#shutter span { width: 56px; height: 56px; border-radius: 50%; background: var(--text); transition: transform .1s; }
#shutter:active span { transform: scale(.9); }
body.frozen #shutter span { background: var(--accent); }

/* ── reading card ── */
#card {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  padding: 10px 20px calc(var(--safe-b) + 18px);
  background: #1d1b17; border-top-left-radius: 18px; border-top-right-radius: 18px;
  box-shadow: 0 -8px 30px rgba(0,0,0,.5); max-height: 48vh; overflow: auto; font-size: 13.5px; line-height: 1.35;
}
#card .grip { width: 38px; height: 4px; border-radius: 2px; background: var(--line); margin: 0 auto 10px; }
#card h2 { margin: 2px 0 6px; font-size: 16px; flex: 1; min-width: 0; }
.cardhead { display: flex; align-items: center; gap: 10px; }
.seg.small button { padding: 4px 10px; font-size: 12px; }
#card dt { display: flex; justify-content: space-between; align-items: center; }
.vd { display: flex; gap: 4px; }
.vd button {
  width: 30px; height: 24px; border-radius: 8px; border: 1px solid var(--line);
  font-size: 13px; color: var(--dim); text-transform: none; letter-spacing: 0;
}
.vd button[data-v="yes"].on { background: var(--ok); color: #10200f; border-color: transparent; }
.vd button[data-v="no"].on { background: #e5534b; color: #fff; border-color: transparent; }
.hint { color: var(--dim); font-size: 12px; margin: 10px 0 0; }
.chips { display: flex; gap: 6px; margin: 10px 0 6px; flex-wrap: wrap; }
.chips button { padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line); font-size: 13px; }
.chips button.on { background: var(--text); color: var(--ink); font-weight: 600; }
#cropreceipt { margin: 6px 0 0; padding-left: 18px; }
#cropreceipt li { margin: 3px 0; }
.cardfoot { display: flex; gap: 8px; margin-top: 4px; }
.cardfoot .wide { flex: 1; padding: 11px 10px; }
#card dl { margin: 0 0 14px; }
#card dt { font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; color: var(--accent); margin-top: 8px; }
#card dd { margin: 3px 0 0; color: var(--text); }

.wide {
  display: block; width: 100%; padding: 13px 16px; margin-top: 10px; border-radius: 12px;
  border: 1px solid var(--line); background: rgba(255,255,255,.04); font-weight: 600; text-align: center;
}
.wide.primary { background: var(--text); color: var(--ink); border-color: transparent; }

/* ── start ── */
#start {
  position: fixed; inset: 0; z-index: 10; overflow: auto;
  display: grid; place-items: center; padding: 24px 20px;
  background:
    radial-gradient(circle at 72% 30%, rgba(233,162,59,.14), transparent 45%),
    #14130f;
}
#start .inner { width: min(100%, 380px); }
#start h1 { font-size: 34px; margin: 0 0 6px; letter-spacing: -.01em; }
.lede { color: var(--dim); margin: 0 0 18px; font-size: 16px; }
.how { padding: 0; margin: 0 0 18px; list-style: none; }
.how li { padding: 9px 0; border-top: 1px solid var(--line); color: var(--dim); }
.how b { color: var(--text); }
.note { color: var(--dim); font-size: 12px; margin-top: 14px; text-align: center; }
#camNote { color: var(--accent); }

[hidden] { display: none !important; }

@media (min-width: 760px) {
  #beamwrap { bottom: 168px; }
}

/* ── squint row, slider ── */
#bar .row.squintrow { margin-bottom: 8px; align-items: center; }
body:not(.lens-squint) #bar .row.squintrow { display: none; }
.slider {
  display: flex; align-items: center; gap: 6px; padding: 4px 12px; border-radius: 999px;
  background: var(--glass); border: 1px solid var(--line); font-size: 11px; color: var(--dim);
}
.slider input { width: 120px; accent-color: var(--text); }
body.lens-squint #beamwrap { bottom: calc(var(--safe-b) + 210px); }

/* ── compare divider ── */
#divider { position: absolute; width: 0; z-index: 2; touch-action: none; }
#divider::before { content: ''; position: absolute; top: 0; bottom: 0; left: -1px; width: 2px; background: rgba(243,238,228,.9); box-shadow: 0 0 6px rgba(0,0,0,.6); }
#divider .knob {
  position: absolute; top: calc(100% - 22px); left: 0; transform: translate(-50%, -50%);
  width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center;
  background: var(--text); color: var(--ink); font-size: 16px; font-weight: 700;
  box-shadow: 0 2px 10px rgba(0,0,0,.5); cursor: ew-resize;
}

/* ── ghost beam for the thumb test ── */
#beamghost {
  position: absolute; left: 0; right: 0; top: 14px; height: 6px; border-radius: 3px;
  border: 1.5px dashed rgba(243,238,228,.55); opacity: 0; transition: opacity .2s;
}
#beamwrap.thumb #beamghost { opacity: 1; }

/* hosted / no save endpoint: no verdict controls */
body.nosave .vd, body.nosave #cropuse, body.nosave .savehint { display: none !important; }
body:not(.nosave) .hostnote { display: none; }
