:root {
  --gold: #d4af37;
  --gold-bright: #f3d56a;
  --gold-dim: #8a7020;
  --bg: #0a0a0a;
  --panel: rgba(8, 8, 8, 0.86);
  --panel-border: rgba(212, 175, 55, 0.35);
  --text: #f6f1e3;
  --muted: #c4b89a;
  --danger: #e25b4a;
  --ok: #9dcf6e;
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.55);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --hud-pad: 12px;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI",
    system-ui, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  height: 100dvh;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  position: fixed;
  inset: 0;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

button, input, select { font: inherit; color: inherit; }

#app {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #000;
}

#view {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background: #000;
  touch-action: none;
}

#cam {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform-origin: center center;
  background: #000;
}

#vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 45%, rgba(0,0,0,0.45) 100%);
}

#brackets {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

#brackets svg { width: 100%; height: 100%; display: block; }

.bracket-hit {
  position: absolute;
  left: 0;
  right: 0;
  height: 56px;
  pointer-events: auto;
  touch-action: none;
  cursor: ns-resize;
}

#hit-mid {
  position: absolute;
  left: 18%;
  right: 18%;
  pointer-events: auto;
  touch-action: none;
  cursor: grab;
}

#hud-top {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  padding: calc(var(--safe-top) + 8px) 12px 8px;
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 5;
  pointer-events: none;
  background: linear-gradient(to bottom, rgba(0,0,0,0.65), transparent);
}

#hud-top > * { pointer-events: auto; }

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1;
}

.brand img {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: 1px solid var(--panel-border);
  flex-shrink: 0;
}

.brand h1 {
  margin: 0;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--gold-bright);
  line-height: 1.15;
  text-shadow: 0 1px 4px #000;
}

.brand h1 span {
  display: block;
  font-size: 10px;
  letter-spacing: 0.18em;
  color: var(--muted);
  font-weight: 600;
}

.icon-btn {
  appearance: none;
  border: 1px solid var(--panel-border);
  background: var(--panel);
  color: var(--gold-bright);
  min-width: 44px;
  min-height: 44px;
  padding: 0 12px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 650;
  letter-spacing: 0.04em;
  box-shadow: var(--shadow);
}

.icon-btn:active { transform: scale(0.97); background: #1a1508; }

#range-box {
  position: absolute;
  top: calc(var(--safe-top) + 58px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 4;
  pointer-events: none;
  text-align: center;
  min-width: 220px;
  padding: 8px 18px 10px;
  background: rgba(0, 0, 0, 0.72);
  border: 1px solid var(--gold);
  border-radius: 14px;
  box-shadow: var(--shadow);
}

#range-yd {
  font-size: clamp(40px, 12vw, 64px);
  font-weight: 760;
  letter-spacing: -0.03em;
  line-height: 1;
  color: var(--gold-bright);
  text-shadow: 0 2px 10px #000;
  font-variant-numeric: tabular-nums;
}

#range-m {
  margin-top: 2px;
  font-size: clamp(18px, 5.4vw, 26px);
  font-weight: 650;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

#range-note, #hold-note, #calib-chip {
  margin-top: 6px;
  font-size: 11px;
  line-height: 1.35;
  color: var(--muted);
  letter-spacing: 0.02em;
}

#calib-chip {
  color: var(--gold);
  font-weight: 650;
}

#range-box.warn #range-yd { color: #f0c27a; }
#range-box.bad #range-yd { color: var(--danger); }

#hud-bottom {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 5;
  padding: 8px 10px calc(var(--safe-bottom) + 10px);
  background: linear-gradient(to top, rgba(0,0,0,0.92) 50%, rgba(0,0,0,0.55) 80%, transparent);
}

#presets {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scroll-snap-type: x proximity;
  padding: 4px 2px 10px;
  touch-action: pan-x;
}

#presets::-webkit-scrollbar { display: none; }

.preset {
  flex: 0 0 auto;
  scroll-snap-align: start;
  appearance: none;
  border: 1px solid rgba(212, 175, 55, 0.28);
  background: rgba(18, 16, 10, 0.9);
  color: var(--text);
  min-height: 48px;
  padding: 6px 12px;
  border-radius: 12px;
  text-align: left;
  min-width: 108px;
}

.preset .p-name { display: block; font-size: 13px; font-weight: 700; }
.preset .p-size { display: block; font-size: 11px; color: var(--muted); margin-top: 1px; }

.preset[aria-pressed="true"] {
  border-color: var(--gold);
  background: linear-gradient(180deg, #2a220c, #151208);
  box-shadow: 0 0 0 1px var(--gold);
  color: var(--gold-bright);
}

.row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
}

.row label {
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 650;
  flex-shrink: 0;
}

#zoom-btns { display: flex; gap: 6px; flex: 1; }

#zoom-btns button {
  appearance: none;
  flex: 1;
  min-height: 40px;
  border-radius: 10px;
  border: 1px solid rgba(212, 175, 55, 0.28);
  background: rgba(18, 16, 10, 0.9);
  color: var(--text);
  font-weight: 700;
  font-size: 14px;
}

#zoom-btns button[aria-pressed="true"] {
  border-color: var(--gold);
  background: #2a220c;
  color: var(--gold-bright);
}

#zero-wrap, #custom-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(18, 16, 10, 0.9);
  border: 1px solid rgba(212, 175, 55, 0.28);
  border-radius: 10px;
  padding: 4px 8px;
  min-height: 40px;
}

#zero-wrap input, #custom-wrap input, .field input, .field select {
  appearance: none;
  border: 0;
  background: transparent;
  width: 64px;
  min-height: 32px;
  font-size: 16px; /* iOS won't zoom if >= 16px */
  font-weight: 700;
  color: var(--gold-bright);
  text-align: center;
  outline: none;
}

#custom-wrap { display: none; flex: 1; }
#custom-wrap.visible { display: flex; }
#custom-wrap input { width: 80px; }

.unit { font-size: 12px; color: var(--muted); font-weight: 650; }

#disclaimer {
  margin: 8px 2px 0;
  font-size: 11px;
  line-height: 1.4;
  color: var(--muted);
  text-align: center;
}

#cam-msg, #install-banner {
  position: absolute;
  left: 16px;
  right: 16px;
  z-index: 6;
  padding: 14px 16px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  text-align: center;
}

#cam-msg {
  top: 40%;
  display: none;
}

#cam-msg.visible { display: block; }

#cam-msg h2 {
  margin: 0 0 8px;
  font-size: 16px;
  color: var(--gold-bright);
}

#cam-msg p, #install-banner p { margin: 0; font-size: 14px; line-height: 1.45; color: var(--text); }

#install-banner {
  top: calc(var(--safe-top) + 58px);
  display: none;
  text-align: left;
}

#install-banner.visible { display: block; }
#install-banner .row { justify-content: flex-end; margin-top: 10px; }

/* Overlay screens */
.sheet {
  position: absolute;
  inset: 0;
  z-index: 20;
  background: rgba(0, 0, 0, 0.72);
  display: none;
  overflow: auto;
  touch-action: pan-y;
}

.sheet.open { display: block; }

.sheet-card {
  margin: calc(var(--safe-top) + 16px) 14px calc(var(--safe-bottom) + 16px);
  background: #12100b;
  border: 1px solid var(--panel-border);
  border-radius: 18px;
  padding: 18px 16px 16px;
  box-shadow: var(--shadow);
  max-width: 520px;
  margin-left: auto;
  margin-right: auto;
}

.sheet-card h2 {
  margin: 0 0 8px;
  font-size: 20px;
  color: var(--gold-bright);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.sheet-card p { margin: 0 0 12px; font-size: 14px; line-height: 1.5; color: var(--text); }

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 12px;
}

.field span {
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 650;
}

.field select, .field input[type="number"] {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  background: #0a0a0a;
  padding: 0 10px;
  text-align: left;
  color: var(--text);
}

.actions { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }

.actions button, .primary, .ghost {
  appearance: none;
  min-height: 46px;
  padding: 0 16px;
  border-radius: 12px;
  font-weight: 700;
  font-size: 15px;
  flex: 1;
}

.primary {
  border: 1px solid var(--gold);
  background: linear-gradient(180deg, #d4af37, #9a7b1c);
  color: #1a1404;
}

.ghost {
  border: 1px solid var(--panel-border);
  background: transparent;
  color: var(--text);
}

.hint {
  font-size: 12px;
  color: var(--muted);
  margin-top: 8px;
}

#selftest-report {
  position: absolute;
  left: 0;
  bottom: 0;
  z-index: 50;
  background: #fff;
  color: #000;
  font-size: 11px;
  max-height: 30%;
  overflow: auto;
  width: 100%;
  pointer-events: none;
}

#bracket-adj {
  position: absolute;
  right: 8px;
  top: 46%;
  transform: translateY(-50%);
  z-index: 5;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}
#bracket-adj button {
  pointer-events: auto;
  appearance: none;
  width: 48px;
  height: 48px;
  border-radius: 12px;
  border: 1px solid var(--gold);
  background: var(--panel);
  color: var(--gold-bright);
  font-size: 26px;
  font-weight: 700;
  line-height: 1;
  box-shadow: var(--shadow);
}
#bracket-adj button:active { background: #2a220c; transform: scale(0.97); }
