:root {
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --bg: #0b0e14;
  --glass: rgba(14, 17, 25, 0.78);
  --glass-strong: rgba(16, 19, 28, 0.94);
  --line: rgba(255, 255, 255, 0.12);
  --text: #f1f4fa;
  --muted: rgba(225, 232, 245, 0.62);
  --accent: #ffb547;
  --pin: #ff5fa2;
  --radius: 18px;
  --font: "Barlow", system-ui, -apple-system, sans-serif;
  --font-cond: "Barlow Semi Condensed", "Barlow", system-ui, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text);
  font-family: var(--font); -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent; overscroll-behavior: none; touch-action: none;
  user-select: none; -webkit-user-select: none;
}
button { font: inherit; color: inherit; cursor: pointer; }

#video, #view { position: fixed; inset: 0; width: 100vw; height: 100vh; height: 100dvh; }
#video { object-fit: cover; display: none; }
body.has-camera #video { display: block; }
#view { touch-action: none; }

/* ---------- top HUD ---------- */
#hud-top {
  position: fixed; left: 10px; right: 10px; bottom: calc(var(--sab) + 94px);
  display: flex; gap: 8px; align-items: flex-end; pointer-events: none;
}
#loc {
  pointer-events: auto; display: flex; flex-direction: column; align-items: flex-start;
  background: var(--glass); border: 1px solid var(--line); border-radius: 12px; padding: 5px 10px 6px;
  max-width: 62vw; text-align: left; backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
#loc b { font: 600 14px/1.15 var(--font-cond); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
#loc span { font-size: 11.5px; color: var(--muted); }
#busy { background: var(--glass); border: 1px solid var(--line); border-radius: 12px;
  padding: 7px 10px; font: 500 12.5px var(--font-cond); color: var(--muted);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
#busy::before {
  content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 7px;
  background: var(--accent); animation: pulse 1.2s ease-in-out infinite; vertical-align: 1px;
}
@keyframes pulse { 50% { opacity: 0.25; } }
#share {
  pointer-events: auto; margin-left: auto; flex: none; width: 46px; height: 46px; border-radius: 50%;
  display: grid; place-items: center; background: var(--glass); border: 1px solid var(--line);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
#share svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linejoin: round; }
body.flash::after { content: ""; position: fixed; inset: 0; background: #fff; opacity: .55; z-index: 20; pointer-events: none; }
#clear-sel {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--sab) + 146px);
  background: var(--glass-strong); border: 1px solid var(--pin); color: var(--text);
  border-radius: 999px; padding: 7px 14px; font: 600 14px var(--font-cond);
  max-width: 80vw; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* ---------- look to identify ---------- */
#peek {
  position: fixed; left: 50%; bottom: calc(var(--sab) + 140px); transform: translate(-50%, 8px); z-index: 5;
  width: min(440px, calc(100vw - 32px)); display: flex; gap: 12px; align-items: flex-start; text-align: left;
  padding: 10px 14px 11px 10px; border-radius: 16px; color: var(--text);
  background: var(--glass-strong); border: 1px solid var(--line); border-left: 4px solid var(--c, var(--accent));
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); box-shadow: 0 8px 28px rgba(0,0,0,.35);
  opacity: 0; transition: opacity .2s, transform .2s; font: 14px/1.35 var(--font, system-ui, sans-serif);
}
#peek.show { opacity: 1; transform: translate(-50%, 0); }
#peek img { flex: none; width: 64px; height: 64px; object-fit: cover; border-radius: 10px; background: rgba(255,255,255,.06); }
#peek .txt { display: flex; flex-direction: column; min-width: 0; }
#peek b { font: 600 19px/1.15 var(--font-cond); }
#peek .kind { color: var(--c, var(--accent)); font: 600 13.5px var(--font-cond); margin-top: 1px; }
#peek .facts { color: var(--muted); font-size: 12.5px; margin-top: 1px; }
#peek .blurb { font-size: 13px; margin-top: 4px; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
#peek .blurb:empty { display: none; }
body.peeking #clear-sel { visibility: hidden; }
#sheet .blurb { font-size: 14px; line-height: 1.45; margin: 10px 0 4px; }
#sheet p.muted.small { font-size: 13px; margin: -6px 0 12px; }

/* ---------- bottom bar ---------- */
#bar {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--sab) + 14px);
  display: flex; gap: 4px; padding: 6px; border-radius: 22px;
  background: var(--glass); border: 1px solid var(--line);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  transition: opacity .2s;
}
body:not(.running) #bar, body:not(.running) #hud-top { opacity: 0; pointer-events: none; }
#bar button {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  width: 66px; padding: 7px 0 5px; border: 0; border-radius: 16px; background: transparent;
  font: 600 12px var(--font-cond); letter-spacing: .02em; color: var(--muted);
}
#bar svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
#bar button.active, #bar button.on { color: var(--text); background: rgba(255,255,255,.1); }
#bar button.filtered { color: var(--accent); }
#bar button span { max-width: 64px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- sheet ---------- */
#sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  max-height: 72vh; overflow: auto; -webkit-overflow-scrolling: touch;
  background: var(--glass-strong); border-top: 1px solid var(--line);
  border-radius: 22px 22px 0 0; padding: 18px 18px calc(var(--sab) + 22px);
  transform: translateY(calc(100% + 40px)); transition: transform .28s cubic-bezier(.2,.8,.2,1);
  backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
  user-select: text; -webkit-user-select: text; touch-action: pan-y;
}
#sheet.open { transform: none; }
body.calibrating #sheet { max-height: 46vh; background: rgba(16,19,28,.86); }
@media (min-width: 700px) {
  #sheet { left: auto; right: 16px; bottom: 16px; width: 400px; border-radius: 22px; border: 1px solid var(--line); }
}
#sheet-close {
  position: sticky; top: 0; float: right; width: 32px; height: 32px; border-radius: 50%;
  border: 0; background: rgba(255,255,255,.1); font-size: 14px; margin: -4px -4px 0 8px;
}
#sheet h2 { font: 700 24px/1.1 var(--font-cond); margin: 0 0 8px; letter-spacing: .01em; }
#sheet h3 { font: 600 13px var(--font-cond); text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 18px 0 6px; }
#sheet p { margin: 8px 0; line-height: 1.45; font-size: 15px; }
.muted { color: var(--muted); }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; flex: none; }

.detail-head { display: flex; gap: 12px; align-items: flex-start; padding-right: 36px; }
.detail-head .dot { width: 14px; height: 14px; margin-top: 7px; }
.detail-head p { margin: 0 !important; font-size: 14px !important; text-transform: capitalize; }
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 8px; margin: 14px 0 6px; }
.fact { background: rgba(255,255,255,.06); border-radius: 12px; padding: 8px 10px; }
.fact span { display: block; font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.fact b, .fact output { font: 600 18px var(--font-cond); }
.status { font-size: 15px; }
.turn { font: 600 15px var(--font-cond) !important; color: var(--accent) !important; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.actions button, form.search button, .ghost, .seg button {
  flex: 1 1 auto; border: 1px solid var(--line); background: rgba(255,255,255,.07);
  border-radius: 12px; padding: 11px 14px; font: 600 15px var(--font-cond);
}
button.primary { background: var(--text); color: #0b0e14; border-color: transparent; }
.links { display: flex; gap: 16px; flex-wrap: wrap; margin-top: 14px; font-size: 14px; align-items: center; }
.links a, .linkish { color: #9fd7ff; text-decoration: none; background: none; border: 0; padding: 0; font-size: 14px; }

form.search { display: flex; gap: 8px; margin: 10px 0; }
form.search input {
  flex: 1; min-width: 0; font: 500 16px var(--font); color: var(--text);
  background: rgba(255,255,255,.08); border: 1px solid var(--line); border-radius: 12px; padding: 11px 12px;
}
form.search button { flex: none; }
ul.results { list-style: none; margin: 0; padding: 0; }
ul.results li button {
  display: flex; gap: 12px; align-items: center; width: 100%; text-align: left;
  background: none; border: 0; border-bottom: 1px solid var(--line); padding: 10px 2px;
}
ul.results b { display: block; font: 600 16px var(--font-cond); }
ul.results small { color: var(--muted); font-size: 13px; }
ul.results .note { padding: 10px 2px; font-size: 14px; }

.toggles { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 10px; margin: 6px 0 14px; }
.toggle { display: flex; gap: 9px; align-items: center; font: 600 15px var(--font-cond); padding: 6px 0; }
.toggle input { width: 18px; height: 18px; accent-color: var(--accent); }
.range { display: block; margin: 12px 0; }
.range > span { display: flex; justify-content: space-between; font: 600 14px var(--font-cond); margin-bottom: 4px; }
.range output { color: var(--muted); font-weight: 500; }
.range input { width: 100%; accent-color: var(--accent); }
.seg { display: flex; gap: 8px; align-items: center; font: 600 14px var(--font-cond); margin: 12px 0; }
.seg button { flex: 0 0 auto; padding: 7px 14px; }
.seg button.on { background: var(--text); color: #0b0e14; }

/* ---------- toast ---------- */
#toast {
  position: fixed; left: 50%; top: calc(var(--sat) + 120px); transform: translate(-50%, -10px);
  max-width: min(92vw, 440px); padding: 10px 14px; border-radius: 14px;
  background: var(--glass-strong); border: 1px solid var(--line); font-size: 14px; line-height: 1.35;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 6;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.actionable.show { pointer-events: auto; }
#toast button {
  display: block; margin: 8px 0 0 auto; border: 0; border-radius: 10px; padding: 7px 12px;
  background: var(--text); color: #0b0e14; font: 600 14px var(--font-cond);
}
.status.gone { color: #e6c79c; }

/* ---------- intro ---------- */
#intro {
  position: fixed; inset: 0; z-index: 10; display: grid; place-items: center; padding: 24px 16px;
  background: radial-gradient(120% 80% at 50% 0%, #1a2a48 0%, #0b0e14 60%);
  transition: opacity .35s, visibility .35s; overflow: auto;
}
#intro.gone { opacity: 0; visibility: hidden; }
.intro-inner { width: min(420px, 100%); display: flex; flex-direction: column; gap: 12px; }
.intro-art { width: 100%; height: auto; border-radius: 18px; box-shadow: 0 20px 60px rgba(0,0,0,.5); }
#intro h1 { font: 700 46px/1 var(--font-cond); margin: 14px 0 0; letter-spacing: .01em; }
.lede { font-size: 17px; line-height: 1.45; color: rgba(235,240,250,.86); margin: 0 0 8px; }
.big { padding: 15px 18px !important; font: 700 18px var(--font-cond) !important; border-radius: 14px !important; border: 0; }
.ghost { color: var(--text); }
.fine { font-size: 12.5px; color: var(--muted); text-align: center; margin: 4px 0 0; }

/* ---------- debug panel ---------- */
#debug-panel {
  position: fixed; left: 6px; right: 6px; top: calc(var(--sat) + 62px); z-index: 4;
  max-height: 46vh; overflow: auto; margin: 0; padding: 8px 10px; border-radius: 10px;
  background: rgba(0,0,0,.72); color: #b9f6c5; font: 10.5px/1.35 ui-monospace, Menlo, monospace;
  white-space: pre-wrap; word-break: break-all; pointer-events: none;
}

/* ---------- filter sheet ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 6px 0 4px; }
.chip {
  display: inline-flex; align-items: center; gap: 8px; padding: 9px 13px; border-radius: 999px;
  border: 1px solid var(--line); background: rgba(255,255,255,.05); font: 600 15px var(--font-cond); color: var(--muted);
}
.chip .dot { opacity: .35; }
.chip.on { background: rgba(255,255,255,.14); border-color: rgba(255,255,255,.35); color: var(--text); }
.chip.on .dot { opacity: 1; }
.chips.dist .chip { min-width: 56px; justify-content: center; }
.quick { display: flex; flex-wrap: wrap; gap: 8px 14px; margin: 8px 0 0; }

/* ---------- phone on its side ---------- */
@media (orientation: landscape) and (max-height: 560px) {
  #bar {
    left: auto; right: calc(env(safe-area-inset-right, 0px) + 10px); top: 50%; bottom: auto;
    transform: translateY(-50%); flex-direction: column; padding: 4px; gap: 2px;
  }
  #bar button { width: 64px; padding: 5px 0 4px; }
  #bar svg { width: 21px; height: 21px; }
  #hud-top { bottom: 10px; left: calc(env(safe-area-inset-left, 0px) + 10px); right: 96px; }
  #clear-sel { bottom: 14px; }
  #toast { top: 84px; }
  #peek { bottom: 62px; left: calc(50% - 46px); width: min(460px, calc(100vw - 140px)); padding: 8px 12px 8px 8px; }
  #peek img { width: 50px; height: 50px; }
  #peek .blurb { -webkit-line-clamp: 2; }
  #sheet { left: auto; right: 92px; bottom: 8px; width: min(400px, 60vw); max-height: 82vh; border-radius: 22px; border: 1px solid var(--line); }
  body.calibrating #sheet { max-height: 60vh; }
}

/* ---------- sync & share ---------- */
.qr { background: #fff; border-radius: 14px; padding: 10px; width: min(250px, 66vw); margin: 14px auto 6px; }
.qr svg { display: block; width: 100%; height: auto; }
#sheet p.small { font-size: 13px; }
.linktext { word-break: break-all; user-select: all; -webkit-user-select: all; }
.phrase { text-align: center; margin: 2px 0 !important; font: italic 600 21px/1.3 Georgia, "Iowan Old Style", "Palatino Linotype", serif !important; }
#sheet p.center { text-align: center; margin: 4px 0; }
