:root {
  --bg: #0b1220;
  --panel: rgba(15, 23, 42, 0.72);
  --line: rgba(148, 163, 184, 0.25);
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #38bdf8;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
  color: var(--text);
  background: rgba(30, 41, 59, 0.85);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 14px;
  min-height: 44px;
  cursor: pointer;
}
button.active {
  border-color: var(--accent);
  color: var(--accent);
}
button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #082032;
  font-weight: 600;
}
button.big {
  display: block;
  width: 100%;
  padding: 14px;
  font-size: 17px;
  border-radius: 14px;
}
button.ghost {
  background: transparent;
  color: var(--accent);
  border-color: var(--accent);
  margin-top: 10px;
}

/* stage */
#stage {
  position: fixed;
  inset: 0;
  background: #000;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

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

#ref {
  position: absolute;
  inset: 0;
  margin: auto;
  max-width: 88%;
  max-height: 78%;
  opacity: 0.5;
  pointer-events: none;
  -webkit-user-drag: none;
  will-change: transform, opacity;
  transform-origin: center center;
  display: none;
}
#ref.on { display: block; }

#grid {
  position: absolute;
  inset: 0;
  pointer-events: none;
  display: none;
}
#grid.on { display: block; }
#grid i { position: absolute; background: rgba(255, 255, 255, 0.35); }
#grid i.v { top: 0; bottom: 0; width: 1px; }
#grid i.h { left: 0; right: 0; height: 1px; }

/* bars */
.bar {
  position: fixed;
  left: 0;
  right: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 8px;
  padding-left: max(12px, env(safe-area-inset-left));
  padding-right: max(12px, env(safe-area-inset-right));
}

#topbar {
  top: 0;
  padding-top: calc(10px + env(safe-area-inset-top));
  flex-wrap: wrap;
  justify-content: center;
}
#topbar button {
  min-height: 38px;
  padding: 7px 11px;
  font-size: 13px;
  backdrop-filter: blur(10px);
  background: var(--panel);
}
#startBtn {
  border-color: var(--accent);
  color: var(--accent);
}
body.live #startBtn { display: none; }
body:not(.live) #flip { display: none; }

#controls {
  bottom: 0;
  padding-bottom: calc(14px + env(safe-area-inset-bottom));
  flex-direction: column;
  align-items: stretch;
  background: linear-gradient(to top, rgba(11, 18, 32, 0.9), transparent);
  pointer-events: none;
}
#controls > * { pointer-events: auto; }

#oprow {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px 14px;
  margin-bottom: 10px;
  backdrop-filter: blur(10px);
}
#oprow .lbl { font-size: 13px; color: var(--muted); }
#opval { min-width: 44px; text-align: right; font-variant-numeric: tabular-nums; }

input[type="range"] {
  flex: 1;
  appearance: none;
  -webkit-appearance: none;
  height: 36px;
  background: transparent;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 3px;
  background: rgba(148, 163, 184, 0.4);
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 28px;
  height: 28px;
  margin-top: -11px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
}

/* gate */
#gate {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(4, 8, 16, 0.82);
  backdrop-filter: blur(14px);
  padding: max(16px, env(safe-area-inset-top)) 20px max(16px, env(safe-area-inset-bottom));
}
#gate[hidden] { display: none; }

.card {
  width: min(420px, 100%);
  background: rgba(15, 23, 42, 0.92);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 26px 22px;
}
.card h1 {
  margin: 0 0 6px;
  font-size: 26px;
  letter-spacing: 0.5px;
}
.tag { margin: 0 0 14px; color: var(--muted); line-height: 1.45; }
.steps {
  margin: 0 0 18px;
  padding-left: 20px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.7;
}
.hint { margin: 14px 0 0; font-size: 12px; color: var(--muted); }
#err {
  margin: 12px 0 0;
  color: #fca5a5;
  font-size: 13px;
  line-height: 1.5;
}

/* toast */
#toast {
  position: fixed;
  left: 50%;
  bottom: calc(120px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 30;
  background: rgba(15, 23, 42, 0.95);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 13px;
  border-radius: 12px;
  padding: 10px 14px;
  max-width: 86vw;
  text-align: center;
}
