:root {
  --bg: #0b0e13;
  --panel: rgba(13, 17, 23, 0.66);
  --panel-solid: #141a22;
  --line: rgba(255, 255, 255, 0.14);
  --text: #f3f5f7;
  --muted: rgba(243, 245, 247, 0.66);
  --accent: #ff6a2b;
  --accent-ink: #1a0b03;
  --radius: 18px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-user-select: none;
  user-select: none;
  overscroll-behavior: none;
}

#cam, #gl {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}
#cam { object-fit: cover; background: #000; }
#gl { touch-action: none; }

button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; }
#hud > * { pointer-events: auto; }

.chip {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--line);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  font-size: 13px;
  color: var(--muted);
}
.chip strong { color: var(--text); letter-spacing: 0.04em; text-transform: uppercase; font-size: 12px; }

#topbar {
  position: absolute;
  top: calc(var(--safe-top) + 12px);
  left: calc(var(--safe-left) + 12px);
  pointer-events: none;
}

#lookup {
  position: absolute;
  top: calc(var(--safe-top) + 58px);
  left: 50%;
  transform: translateX(-50%);
  color: var(--text);
  white-space: nowrap;
  pointer-events: none;
}

#seek {
  position: absolute;
  left: 0; top: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 600;
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.8);
  pointer-events: none;
  will-change: transform;
}
#seek svg {
  width: 44px; height: 44px;
  padding: 9px;
  border-radius: 50%;
  background: var(--accent);
  fill: var(--accent-ink);
  transform: rotate(var(--angle, 0deg));
}

#toast {
  position: absolute;
  left: 50%;
  bottom: calc(var(--safe-bottom) + 190px);
  transform: translateX(-50%);
  max-width: min(88vw, 420px);
  padding: 10px 16px;
  border-radius: 14px;
  background: var(--panel-solid);
  border: 1px solid var(--line);
  text-align: center;
  font-size: 14px;
  pointer-events: none;
  animation: rise 0.25s ease-out;
}
@keyframes rise { from { opacity: 0; transform: translate(-50%, 8px); } }

#dock {
  position: absolute;
  left: calc(var(--safe-left) + 10px);
  right: calc(var(--safe-right) + 10px);
  bottom: calc(var(--safe-bottom) + 10px);
  max-width: 560px;
  margin: 0 auto;
  padding: 12px 14px 12px;
  border-radius: var(--radius);
  background: var(--panel);
  border: 1px solid var(--line);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}

.distance output { display: block; font-weight: 600; font-size: 15px; margin-bottom: 2px; }
.distance .scale { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin-top: -2px; }

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 32px;
  margin: 0;
  background: none;
}
input[type="range"]::-webkit-slider-runnable-track { height: 4px; border-radius: 2px; background: rgba(255, 255, 255, 0.28); }
input[type="range"]::-moz-range-track { height: 4px; border-radius: 2px; background: rgba(255, 255, 255, 0.28); }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 24px; height: 24px;
  margin-top: -10px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.5);
}
input[type="range"]::-moz-range-thumb { width: 24px; height: 24px; border: 0; border-radius: 50%; background: #fff; }

.actions { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.actions button:not(.shutter) {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 8px 4px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.09);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.actions button:not(.shutter):active, .actions button[aria-expanded="true"] { background: rgba(255, 255, 255, 0.22); }
.actions svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }

.shutter {
  flex: 0 0 auto;
  width: 54px; height: 54px;
  border-radius: 50%;
  border: 3px solid #fff;
  padding: 3px;
  margin-left: 4px;
}
.shutter span { display: block; width: 100%; height: 100%; border-radius: 50%; background: #fff; transition: transform 0.1s; }
.shutter:active span { transform: scale(0.86); }

/* ---------- Sheets ---------- */
.sheet {
  position: absolute;
  left: calc(var(--safe-left) + 10px);
  right: calc(var(--safe-right) + 10px);
  bottom: calc(var(--safe-bottom) + 176px);
  max-width: 560px;
  max-height: calc(100% - 260px - var(--safe-top) - var(--safe-bottom));
  overflow-y: auto;
  margin: 0 auto;
  padding: 14px;
  border-radius: var(--radius);
  background: var(--panel-solid);
  border: 1px solid var(--line);
  animation: sheet 0.2s ease-out;
}
@keyframes sheet { from { opacity: 0; transform: translateY(10px); } }
.sheet h2 { margin: 0 0 10px; font-size: 12px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }

.options { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.options button {
  text-align: left;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid transparent;
}
.options button b { display: block; font-size: 14px; }
.options button small { color: var(--muted); font-size: 12px; }
.options button[aria-pressed="true"] { border-color: var(--accent); background: rgba(255, 106, 43, 0.16); }

.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.row:first-of-type { border-top: 0; padding-top: 0; }
.row.column { flex-direction: column; align-items: stretch; gap: 2px; padding-bottom: 0; }
.row-title { font-weight: 600; }
.row-title output { color: var(--muted); font-weight: 400; margin-left: 6px; }
.row-note { color: var(--muted); font-size: 12.5px; }

.stepper { display: flex; align-items: center; gap: 4px; flex: 0 0 auto; }
.stepper button { width: 40px; height: 40px; border-radius: 50%; background: rgba(255, 255, 255, 0.1); font-size: 22px; line-height: 1; }
.stepper button:active { background: rgba(255, 255, 255, 0.24); }
.stepper output { min-width: 72px; text-align: center; font-weight: 600; }

input[type="checkbox"] {
  -webkit-appearance: none;
  appearance: none;
  flex: 0 0 auto;
  width: 50px; height: 30px;
  margin: 0;
  border-radius: 15px;
  background: rgba(255, 255, 255, 0.2);
  position: relative;
  transition: background 0.15s;
}
input[type="checkbox"]::after {
  content: "";
  position: absolute;
  top: 3px; left: 3px;
  width: 24px; height: 24px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.15s;
}
input[type="checkbox"]:checked { background: var(--accent); }
input[type="checkbox"]:checked::after { transform: translateX(20px); }

/* ---------- Intro ---------- */
#intro {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: calc(var(--safe-top) + 20px) 24px calc(var(--safe-bottom) + 20px);
  background: radial-gradient(120% 80% at 50% 0%, #1b2532 0%, var(--bg) 62%);
  overflow-y: auto;
}
.intro-inner { width: min(100%, 380px); text-align: center; }
.teaser { height: min(38vh, 300px); margin-bottom: 8px; }
.t-ground { stroke: rgba(255, 255, 255, 0.35); stroke-width: 1; }
.t-ticks line { stroke: rgba(255, 255, 255, 0.4); stroke-width: 0.8; }
.t-steel { fill: #d5d9de; }
.t-tiles { fill: #23272d; }
.t-split { stroke: #7d848d; stroke-width: 0.8; }
.t-you { fill: var(--accent); }
.t-label { fill: var(--muted); font-size: 9px; font-weight: 600; }
.t-you-label { fill: var(--accent); }

h1 { margin: 0 0 8px; font-size: clamp(28px, 8vw, 36px); line-height: 1.1; letter-spacing: -0.02em; text-wrap: balance; }
.lede { margin: 0 0 22px; color: var(--muted); font-size: 16px; text-wrap: pretty; }
.primary {
  display: block;
  width: 100%;
  padding: 16px;
  border-radius: 14px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 17px;
  font-weight: 700;
}
.primary:active { filter: brightness(0.9); }
.primary:disabled { opacity: 0.6; }
.link { margin-top: 6px; padding: 12px; color: var(--muted); text-decoration: underline; text-underline-offset: 3px; }
.fine { margin: 10px 0 0; color: rgba(243, 245, 247, 0.45); font-size: 12.5px; }

@media (orientation: landscape) and (max-height: 520px) {
  .teaser { display: none; }
  #dock { max-width: 460px; margin-right: 0; padding: 8px 12px; }
  .sheet { max-width: 460px; margin-right: 0; bottom: calc(var(--safe-bottom) + 150px); max-height: calc(100% - 170px); }
  #toast { bottom: auto; top: calc(var(--safe-top) + 12px); }
}
