/* Layout: full-bleed camera stage; a floating survey-instrument HUD on top, tool dock + bottom sheet below. */
:root {
  --ink: #0b1626;            /* panel base: survey-night navy */
  --ink-raised: #15263f;     /* controls on a panel */
  --line: rgba(190, 214, 255, 0.16);
  --paper: #eef3fa;          /* primary text */
  --mute: #a3b4cb;           /* secondary text */
  --flag: #ff4f9a;           /* surveyor's flagging-tape pink */
  --flag-ink: #2a0716;       /* text on the accent */
  --ok: #49d6a0;
  --warn: #ffc65c;
  --bad: #ff7a66;
  --sky: #0a1424;            /* preview backdrop */
  --haze: #33486a;
  --panel: rgba(11, 22, 38, 0.84);

  --font-ui: 'Vazirmatn', system-ui, -apple-system, 'Segoe UI', Tahoma, sans-serif;
  --font-display: 'Lalezar', 'Vazirmatn', Tahoma, sans-serif;
  --font-data: ui-monospace, 'SF Mono', Menlo, Consolas, 'Vazirmatn', monospace;

  --gutter-l: max(16px, env(safe-area-inset-left, 0px));
  --gutter-r: max(16px, env(safe-area-inset-right, 0px));
  --radius: 14px;
  color-scheme: dark;
}

[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--sky);
  color: var(--paper);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.6;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
}
#app { position: fixed; inset: 0; overflow: hidden; }
#app *, #app *::before, #app *::after { box-sizing: border-box; }

/* ---------- stage ---------- */
#stage {
  position: absolute; inset: 0;
  background: linear-gradient(to bottom, var(--sky) 0%, #1a2b47 28%, var(--haze) 46%, var(--haze) 100%);
}
#app[data-mode="ar"] #stage { background: #000; }
#cam { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
#gl { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; outline: none; }

/* ---------- HUD ---------- */
#hud {
  position: absolute; top: 0; left: 0; right: 0;
  padding-top: calc(env(safe-area-inset-top, 0px) + 12px);
  padding-left: var(--gutter-l); padding-right: var(--gutter-r);
  display: flex; flex-direction: column; gap: 8px; align-items: flex-start;
  pointer-events: none;
}
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 11px; border-radius: 999px;
  background: var(--panel); border: 1px solid var(--line);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  font-size: 13px; font-variant-numeric: tabular-nums; white-space: nowrap;
}
.chip::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--mute); }
.chip[data-state="ok"]::before { background: var(--ok); }
.chip[data-state="warn"]::before { background: var(--warn); }
.chip[data-state="bad"]::before { background: var(--bad); }
.chip-mode::before { background: var(--flag); }
.hint {
  margin: 0; max-width: 34em; padding: 7px 12px; border-radius: 10px;
  background: var(--panel); border: 1px solid var(--line); color: var(--warn);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  font-size: 13px;
}

/* ---------- off-screen arrows ---------- */
.arrow {
  position: absolute; top: 38%;
  display: flex; align-items: center; gap: 4px;
  padding: 8px 12px; border-radius: 999px;
  background: var(--flag); color: var(--flag-ink);
  font-size: 13px; font-weight: 700; pointer-events: none;
  animation: nudge 1.2s ease-in-out infinite;
}
.arrow svg { width: 20px; height: 20px; flex: none; }
.arrow-left { left: max(10px, env(safe-area-inset-left, 0px)); --dx: -5px; }
.arrow-right { right: max(10px, env(safe-area-inset-right, 0px)); --dx: 5px; }
@keyframes nudge { 50% { transform: translateX(var(--dx)); } }

/* ---------- bottom stack ---------- */
#bottom {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding-left: var(--gutter-l); padding-right: var(--gutter-r);
  padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 12px);
  display: flex; flex-direction: column; gap: 10px;
  pointer-events: none;
  max-width: 560px; margin-inline: auto;
}
#bottom > * { pointer-events: auto; }

.card, .sheet, .dock {
  background: var(--panel); border: 1px solid var(--line);
  -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
}
.card { border-radius: var(--radius); padding: 14px 16px 16px; display: flex; flex-direction: column; gap: 12px; }
.card-head { display: flex; flex-direction: column; gap: 2px; }
.brand { margin: 0; font-family: var(--font-display); font-weight: 400; font-size: 34px; line-height: 1.15; letter-spacing: 0; }
.brand::after { content: ""; display: inline-block; width: 9px; height: 9px; margin-inline-start: 6px; border-radius: 50%; background: var(--flag); }
.lead { margin: 0; font-size: 15px; text-wrap: balance; }
.note { margin: 0; color: var(--mute); font-size: 13px; }
.err { margin: 0; color: var(--bad); font-size: 13px; }
.row { display: flex; flex-wrap: wrap; gap: 8px; }
#app[data-sheet] #startCard, #app[data-sheet] #promptCard { display: none; }

.checks { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 13px; }
.checks li { display: inline-flex; align-items: center; gap: 6px; color: var(--mute); }
.checks .dot { width: 9px; height: 9px; border-radius: 50%; border: 2px solid var(--mute); }
.checks li[data-state="ok"] { color: var(--paper); }
.checks li[data-state="ok"] .dot { background: var(--ok); border-color: var(--ok); }
.checks li[data-state="bad"] { color: var(--bad); }
.checks li[data-state="bad"] .dot { background: var(--bad); border-color: var(--bad); }
.checks li[data-state="wait"] .dot { animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.3; } }

/* ---------- buttons ---------- */
.btn {
  appearance: none; border: 1px solid transparent; border-radius: 12px;
  min-height: 46px; padding: 0 18px;
  font: inherit; font-weight: 700; color: inherit; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  flex: 1 1 auto;
}
.btn-primary { background: var(--flag); color: var(--flag-ink); }
.btn-ghost { background: var(--ink-raised); border-color: var(--line); font-weight: 500; }
.btn-mini { min-height: 34px; padding: 0 12px; flex: none; background: var(--ink-raised); border-color: var(--line); font-weight: 500; font-size: 13px; }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn:active:not(:disabled) { transform: translateY(1px); }
#app :focus-visible { outline: 2px solid var(--paper); outline-offset: 2px; }

/* ---------- dock ---------- */
.dock { border-radius: var(--radius); padding: 5px; display: flex; gap: 4px; }
.tab {
  appearance: none; background: none; border: 0; border-radius: 10px;
  flex: 1 1 0; min-width: 0; min-height: 50px; padding: 5px 4px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  font: inherit; font-size: 12.5px; color: var(--mute); cursor: pointer;
}
.tab svg { width: 21px; height: 21px; }
.tab[aria-selected="true"] { background: var(--ink-raised); color: var(--paper); box-shadow: inset 0 -2px 0 var(--flag); }

/* ---------- sheet ---------- */
.sheet { border-radius: var(--radius); max-height: min(46vh, 400px); overflow-y: auto; overscroll-behavior: contain; padding: 14px 16px 16px; }
.opts { display: flex; flex-direction: column; gap: 16px; }
.opt { display: flex; flex-direction: column; gap: 8px; }
.opt-label, .field label, .k { font-size: 13px; color: var(--mute); }

.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg button {
  appearance: none; flex: 1 1 auto; min-height: 42px; padding: 0 14px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--ink-raised);
  font: inherit; color: var(--paper); cursor: pointer;
}
.seg button[aria-checked="true"] { background: var(--flag); border-color: var(--flag); color: var(--flag-ink); font-weight: 700; }

.swatches { display: flex; flex-wrap: wrap; gap: 10px; }
.swatch {
  appearance: none; width: 40px; height: 40px; border-radius: 50%; padding: 0; cursor: pointer;
  background: var(--c); border: 2px solid rgba(255, 255, 255, 0.28);
}
.swatch[aria-checked="true"] { box-shadow: 0 0 0 2px var(--ink), 0 0 0 4px var(--flag); border-color: transparent; }

.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; min-height: 42px; }
.switch-row small { display: block; color: var(--mute); font-size: 12px; }
.switch {
  appearance: none; flex: none; width: 52px; height: 30px; border-radius: 999px; padding: 0; cursor: pointer;
  background: var(--ink-raised); border: 1px solid var(--line); position: relative;
}
.switch::after {
  content: ""; position: absolute; top: 3px; inset-inline-start: 3px; width: 22px; height: 22px; border-radius: 50%;
  background: var(--mute); transition: inset-inline-start 0.15s ease, background 0.15s ease;
}
.switch[aria-checked="true"] { background: var(--flag); border-color: var(--flag); }
.switch[aria-checked="true"]::after { inset-inline-start: 25px; background: var(--flag-ink); }

.field { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; align-items: baseline; margin: 0; }
.field output { font-variant-numeric: tabular-nums; font-size: 14px; }
.field input[type="range"], .field .inline, .field .err { grid-column: 1 / -1; }
input[type="range"] { width: 100%; min-height: 34px; margin: 0; accent-color: var(--flag); direction: ltr; }
.inline { display: flex; gap: 8px; }
.inline .btn { flex: none; }
input[type="text"] {
  flex: 1 1 0; min-width: 0; min-height: 46px; padding: 0 12px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--ink-raised);
  color: var(--paper); font-family: var(--font-data); font-size: 16px;
}
input[type="text"]::placeholder { color: var(--mute); opacity: 0.7; }

.kv { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; align-items: center; }
.kv .k { grid-column: 1 / -1; }
.coord { font-family: var(--font-data); font-size: 14px; text-align: start; overflow-wrap: anywhere; min-width: 0; unicode-bidi: plaintext; }

/* ---------- toast ---------- */
.toast {
  position: absolute; left: 50%; top: calc(env(safe-area-inset-top, 0px) + 112px); transform: translateX(-50%);
  max-width: min(88vw, 30em); padding: 9px 16px; border-radius: 12px;
  background: var(--paper); color: var(--ink); font-size: 14px; text-align: center;
  pointer-events: none;
}

@media (max-height: 520px) {
  .brand { font-size: 26px; }
  .sheet { max-height: 52vh; }
  .arrow { top: 30%; }
}
@media (prefers-reduced-motion: reduce) {
  .arrow, .checks li[data-state="wait"] .dot { animation: none; }
  .switch::after { transition: none; }
}
