:root {
  --obsidian: #0A0D0C;
  --panel: #131a17;
  --panel-2: #0f1512;
  --line: #2a382f;
  --quartz: #EEF4F0;
  --slate: #93aaa0;
  --gold: #E5B54A;
  --gold-deep: #B8862B;
  --accent: #B78BFF;
  --font-display: "Chakra Petch", ui-sans-serif, system-ui, sans-serif;
  --font-data: "IBM Plex Mono", ui-monospace, Consolas, monospace;
  color: var(--quartz);
  background: var(--obsidian);
  font-family: ui-sans-serif, system-ui, -apple-system, sans-serif;
}
body[data-mode="minerals"] { --accent: #B78BFF; }
body[data-mode="rocks"] { --accent: #E8935A; }
body[data-mode="plants"] { --accent: #3ED598; }
body[data-mode="flowers"] { --accent: #FF7EB6; }
body[data-mode="fruitsveg"] { --accent: #FFB03A; }

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-height: 100dvh; overflow: hidden;
  /* Static gradient, not an animated layer: the phone paints this once. */
  background:
    radial-gradient(70% 40% at 50% 0%, color-mix(in srgb, var(--accent) 9%, transparent), transparent 70%),
    var(--obsidian);
  transition: background .6s; }

.app { position: fixed; inset: 0; display: flex; flex-direction: column;
  padding: calc(8px + env(safe-area-inset-top)) 12px calc(10px + env(safe-area-inset-bottom)); gap: 10px; }
@media (min-width: 720px) {
  .app { inset: 50% auto auto 50%; transform: translate(-50%, -50%); width: min(440px, 94vw); height: min(880px, 96dvh);
    border: 1px solid var(--line); border-radius: 28px; box-shadow: 0 40px 120px #000c; }
}

header { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex: none; }
.brand { display: flex; align-items: center; gap: 8px; font-family: var(--font-display); font-weight: 700; letter-spacing: .08em; font-size: 1.02rem;
  background: linear-gradient(100deg, var(--quartz) 30%, var(--gold) 62%, var(--gold-deep) 92%);
  -webkit-background-clip: text; background-clip: text; color: transparent; }
.mark { width: 26px; height: 26px; }
.mark.big { width: 74px; height: 74px; }
.facet-a { fill: #2b2416; stroke: var(--gold); stroke-width: 1; }
.facet-b { fill: #e5b54a3d; } .facet-c { fill: #e5b54a1a; }
.status { display: inline-flex; align-items: center; gap: 7px; border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 6px 11px; color: var(--slate); font-family: var(--font-data); font-size: .68rem; letter-spacing: .06em; text-transform: uppercase; }
.led { width: 7px; height: 7px; border-radius: 50%; background: var(--slate); transition: background .3s; }
.status.on .led { background: #4ade80; box-shadow: 0 0 8px #4ade80; }
.status.busy .led { background: var(--gold); box-shadow: 0 0 8px var(--gold); animation: breathe .9s ease-in-out infinite; }
@keyframes breathe { 50% { opacity: .4; } }

/* ═══ The lens: camera + scan area, one and the same ═══════════════════════
   The video is exactly this box. Nothing else on screen composites video, so
   the GPU paints ~84k pixels of camera per frame instead of ~330k. */
.stage { position: relative; flex: none; display: flex; justify-content: center; }
.lens { position: relative; width: min(88vw, 46dvh, 400px); aspect-ratio: 1 / 1; overflow: hidden;
  border: 1px solid color-mix(in srgb, var(--accent) 40%, var(--line)); border-radius: 26px; background: #050807;
  box-shadow: 0 18px 44px #000a, 0 0 34px color-mix(in srgb, var(--accent) 12%, transparent); transition: border-color .5s, box-shadow .5s; }
.lens video { width: 100%; height: 100%; display: block; object-fit: cover; }
.lens-edge { position: absolute; inset: 0; pointer-events: none; border-radius: 26px; box-shadow: inset 0 0 40px #000a; }

.grid-overlay { position: absolute; inset: 0; opacity: .13; pointer-events: none;
  background-image: linear-gradient(color-mix(in srgb, var(--accent) 16%, transparent) 1px, transparent 1px), linear-gradient(90deg, color-mix(in srgb, var(--accent) 16%, transparent) 1px, transparent 1px);
  background-size: 40px 40px; mask-image: radial-gradient(70% 70% at 50% 50%, #000, transparent); }

.reticle { position: absolute; inset: 7%; pointer-events: none; }
.ring { position: absolute; inset: 0; width: 100%; height: 100%; }
.ring circle { fill: none; stroke: color-mix(in srgb, var(--accent) 30%, transparent); stroke-width: .5; stroke-dasharray: 2.2 3.4; transition: stroke .5s; }
.lens.scanning .ring circle { stroke: color-mix(in srgb, var(--accent) 70%, transparent); }
.reticle i { position: absolute; width: 26px; height: 26px; border: 0 solid var(--accent); transition: border-color .5s; }
.reticle i:nth-child(2) { top: 0; left: 0; border-width: 2.5px 0 0 2.5px; border-top-left-radius: 8px; }
.reticle i:nth-child(3) { top: 0; right: 0; border-width: 2.5px 2.5px 0 0; border-top-right-radius: 8px; }
.reticle i:nth-child(4) { bottom: 0; left: 0; border-width: 0 0 2.5px 2.5px; border-bottom-left-radius: 8px; }
.reticle i:nth-child(5) { bottom: 0; right: 0; border-width: 0 2.5px 2.5px 0; border-bottom-right-radius: 8px; }

/* One pass per read — the only animation that runs while scanning */
.beam { position: absolute; left: 5%; right: 5%; top: 4%; height: 3px; border-radius: 3px; opacity: 0; pointer-events: none;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  box-shadow: 0 0 16px color-mix(in srgb, var(--accent) 70%, transparent); }
.beam.pass { animation: beam-pass .65s ease-in-out; }
@keyframes beam-pass { 0% { opacity: 0; transform: translateY(0); } 15% { opacity: .95; } 85% { opacity: .95; } 100% { opacity: 0; transform: translateY(1000%); } }

.head-tools { display: flex; align-items: center; gap: 7px; }
.tool { width: 36px; height: 36px; flex: none; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 50%; background: var(--panel); color: var(--slate); cursor: pointer; transition: color .3s, border-color .3s; }
.tool svg { width: 17px; height: 17px; }
.tool:hover { color: var(--quartz); border-color: color-mix(in srgb, var(--accent) 50%, var(--line)); }

/* ═══ Calibration — covers the lens only ═══════════════════════════════════ */
.calib { position: absolute; inset: 0; z-index: 5; display: grid; place-content: center; gap: 10px; justify-items: center; background: #060a08f0; border-radius: 26px; }
.calib-core { position: relative; width: 108px; height: 108px; }
.calib-core svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.calib-track { fill: none; stroke: #ffffff12; stroke-width: 3; }
.calib-arc { fill: none; stroke: var(--accent); stroke-width: 3; stroke-linecap: round; stroke-dasharray: 232; stroke-dashoffset: 232; transition: stroke-dashoffset .2s linear, stroke .5s; }
.calib-arc.indeterminate { stroke-dashoffset: 174; animation: spin 1.1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.calib-core::before { content: ""; position: absolute; inset: 8px; border-radius: 50%; border: 1px dashed color-mix(in srgb, var(--accent) 32%, transparent); animation: spin 7s linear infinite; }
#calib-pct { position: absolute; inset: 0; display: grid; place-items: center; font-family: var(--font-data); font-weight: 600; font-size: 1.2rem; color: var(--accent); }
#calib-pct.small { font-size: .8rem; }
#calib-label { margin: 0; font-family: var(--font-data); font-size: .66rem; letter-spacing: .16em; text-transform: uppercase; color: var(--slate); text-align: center; padding: 0 14px; }

/* ═══ Readout ══════════════════════════════════════════════════════════════ */
/* Sized to its content — a panel stretched to fill the screen read as dead
   space. The chips take the leftover room instead. */
.readout { flex: 0 0 auto; max-height: 46dvh; overflow-y: auto; border: 1px solid var(--line); border-radius: 18px; padding: 13px 15px; background: var(--panel); transition: border-color .5s; }
.modes { margin-top: auto; }
.readout.fresh { animation: pop .4s cubic-bezier(.3,1.4,.4,1); border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }
@keyframes pop { 0% { transform: scale(.985); } }
.readout-main { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.readout-name { min-width: 0; flex: 1; }
.eyebrow { margin: 0 0 2px; color: var(--accent); font-family: var(--font-data); font-size: .6rem; letter-spacing: .2em; text-transform: uppercase; transition: color .5s; }
h2 { margin: 0; font-family: var(--font-display); font-size: clamp(1.05rem, 5.2vw, 1.42rem); font-weight: 700; line-height: 1.15; overflow-wrap: anywhere;
  background: linear-gradient(95deg, var(--quartz) 40%, color-mix(in srgb, var(--accent) 75%, var(--quartz))); -webkit-background-clip: text; background-clip: text; color: transparent; }
.hint { margin: 3px 0 0; color: var(--slate); font-size: .78rem; line-height: 1.35; }
.dial { position: relative; width: 60px; height: 60px; flex: none; }
.dial svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.dial-track { fill: none; stroke: #ffffff14; stroke-width: 5; }
.dial-fill { fill: none; stroke: var(--accent); stroke-width: 5; stroke-linecap: round; stroke-dasharray: 163.4; stroke-dashoffset: 163.4; transition: stroke-dashoffset .6s cubic-bezier(.3,.9,.3,1), stroke .4s; }
.dial span { position: absolute; inset: 0; display: grid; place-items: center; font-family: var(--font-data); font-weight: 600; font-size: .82rem; color: var(--accent); transition: color .5s; }
.candidates { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 6px; }
.candidates:empty { margin: 0; }
.candidates li { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 10px; font-family: var(--font-data); font-size: .72rem; color: var(--slate); }
.candidates .lbl { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.candidates .bar { grid-column: 1 / -1; height: 3px; border-radius: 3px; background: #ffffff12; overflow: hidden; }
.candidates .bar i { display: block; height: 100%; width: 0%; border-radius: 3px; background: linear-gradient(90deg, color-mix(in srgb, var(--accent) 55%, #333), var(--accent)); transition: width .5s cubic-bezier(.3,.9,.3,1); }
.candidates li:first-child .bar i { background: linear-gradient(90deg, var(--gold-deep), var(--gold)); }
.candidates .pct { color: var(--quartz); }

/* ═══ Library chips ════════════════════════════════════════════════════════ */
.modes { flex: none; display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; padding: 2px; scroll-padding-inline: 4px; }
.modes::-webkit-scrollbar { display: none; }
.chip { --c: var(--slate); flex: none; display: flex; flex-direction: column; align-items: flex-start; padding: 8px 13px; border-radius: 13px; border: 1px solid var(--line); background: var(--panel); color: var(--slate); cursor: pointer; scroll-snap-align: center;
  transition: color .3s, border-color .3s, background .3s; }
.chip b { font-family: var(--font-display); font-weight: 700; font-size: .8rem; letter-spacing: .07em; text-transform: uppercase; }
.chip small { font-family: var(--font-data); font-size: .58rem; opacity: .75; }
.chip[data-mode="minerals"] { --c: #B78BFF; } .chip[data-mode="rocks"] { --c: #E8935A; }
.chip[data-mode="plants"] { --c: #3ED598; } .chip[data-mode="flowers"] { --c: #FF7EB6; }
.chip[data-mode="fruitsveg"] { --c: #FFB03A; }
.chip:hover { color: var(--quartz); }
.chip.active { color: var(--c); border-color: color-mix(in srgb, var(--c) 60%, transparent); background: linear-gradient(160deg, color-mix(in srgb, var(--c) 18%, var(--panel)), var(--panel)); }

/* ═══ Tuner ════════════════════════════════════════════════════════════════ */
.tuner { position: absolute; left: 12px; right: 12px; bottom: calc(66px + env(safe-area-inset-bottom)); z-index: 8; max-height: 60dvh; overflow-y: auto;
  border: 1px solid color-mix(in srgb, var(--accent) 35%, var(--line)); border-radius: 20px; padding: 16px; background: #0a0f0dfa; box-shadow: 0 20px 60px #000c; animation: pop .3s cubic-bezier(.25,1.3,.4,1); }
.tuner-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.tuner-head h3 { margin: 2px 0 0; font-family: var(--font-display); font-size: 1.05rem; color: var(--quartz); }
.tuner-close { width: 32px; height: 32px; flex: none; border: 1px solid var(--line); border-radius: 50%; background: transparent; color: var(--slate); cursor: pointer; }
.tuner-close:hover { color: var(--quartz); border-color: var(--accent); }
.slider { display: block; margin-bottom: 15px; }
.slider-top { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; font-family: var(--font-display); font-size: .84rem; font-weight: 700; letter-spacing: .04em; color: var(--quartz); text-transform: uppercase; }
.slider-top b { font-family: var(--font-data); font-weight: 600; font-size: .8rem; color: var(--accent); text-transform: none; }
.slider small { display: block; margin-top: 6px; color: var(--slate); font-size: .71rem; line-height: 1.4; }
.slider input[type="range"] { -webkit-appearance: none; appearance: none; width: 100%; height: 26px; margin: 6px 0 0; background: transparent; cursor: pointer; }
.slider input[type="range"]::-webkit-slider-runnable-track { height: 5px; border-radius: 5px; background: linear-gradient(90deg, color-mix(in srgb, var(--accent) 55%, transparent), color-mix(in srgb, var(--accent) 18%, transparent)); }
.slider input[type="range"]::-moz-range-track { height: 5px; border-radius: 5px; background: linear-gradient(90deg, color-mix(in srgb, var(--accent) 55%, transparent), color-mix(in srgb, var(--accent) 18%, transparent)); }
.slider input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 22px; height: 22px; margin-top: -8.5px; border-radius: 50%; background: var(--accent); border: 3px solid #0a0f0d; }
.slider input[type="range"]::-moz-range-thumb { width: 22px; height: 22px; border-radius: 50%; background: var(--accent); border: 3px solid #0a0f0d; }
.tuner-reset { width: 100%; padding: 11px; border: 1px solid var(--line); border-radius: 13px; background: transparent; color: var(--slate); font-family: var(--font-display); font-weight: 700; font-size: .82rem; letter-spacing: .06em; text-transform: uppercase; cursor: pointer; }
.tuner-reset:hover { color: var(--quartz); border-color: var(--accent); }

/* ═══ Gate ═════════════════════════════════════════════════════════════════ */
.gate { position: absolute; inset: 0; z-index: 7; display: grid; place-content: center; justify-items: center; gap: 10px; padding: 24px 24px 110px; text-align: center;
  background: radial-gradient(80% 60% at 50% 30%, #101815, var(--obsidian)); }
.gate h1 { margin: 4px 0 0; font-family: var(--font-display); font-size: 2rem; letter-spacing: .06em;
  background: linear-gradient(100deg, var(--quartz) 30%, var(--gold) 62%, var(--gold-deep) 92%); -webkit-background-clip: text; background-clip: text; color: transparent; }
.gate p { margin: 0; max-width: 300px; color: var(--slate); line-height: 1.55; font-size: .95rem; }
.cta { margin-top: 14px; border: 1px solid var(--gold); border-radius: 16px; padding: 15px 34px; font-family: var(--font-display); font-weight: 700; font-size: 1.05rem; letter-spacing: .06em; cursor: pointer; color: #221703;
  background: linear-gradient(120deg, var(--gold), var(--gold-deep)); box-shadow: 0 8px 30px #e5b54a44; transition: transform .15s, box-shadow .3s; }
.cta:hover { box-shadow: 0 10px 38px #e5b54a77; }
.cta:active { transform: translateY(1px) scale(.985); }
/* The rail sits above the gate so the chosen library is the one downloaded. */
.modes { position: relative; z-index: 9; }

button:focus-visible, .chip:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

@media (prefers-reduced-motion: reduce) {
  .status.busy .led, .calib-core::before, .calib-arc.indeterminate, .beam.pass, .readout.fresh, .tuner { animation: none !important; }
}
