*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --green:  #00ff88;
  --orange: #ff8c00;
  --red:    #ff4455;
  --blue:   #44aaff;
  --purple: #cc88ff;
  --bg:     #080c10;
  --card:   rgba(8,12,16,.85);
  --border: rgba(255,255,255,.1);
  --muted:  #4a5568;
  --text:   #c9d6e3;
}

html, body {
  height: 100%; background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, sans-serif;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}
.hidden { display: none !important; }

/* ── LOADING OVERLAY — sits on top of main screen ────────── */
#loading-screen {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
  z-index: 200;          /* above everything */
  transition: opacity .3s ease;
}
#loading-screen.hidden {
  display: none !important;
}
.loader-box {
  display: flex; flex-direction: column;
  align-items: center; gap: .9rem;
  padding: 2rem; text-align: center;
}
.loader-box h1 {
  font-size: 1.55rem; font-weight: 700;
  color: #fff; letter-spacing: 1px;
}

/* SVG ring progress */
.ring-wrap {
  position: relative; width: 80px; height: 80px;
  display: flex; align-items: center; justify-content: center;
}
.ring-svg { position: absolute; inset: 0; width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-bg  { fill: none; stroke: rgba(255,255,255,.07); stroke-width: 3; }
.ring-arc {
  fill: none; stroke: var(--green); stroke-width: 3;
  stroke-linecap: round;
  stroke-dasharray: 213.6;   /* 2π×34 */
  stroke-dashoffset: 213.6;
  transition: stroke-dashoffset .5s ease;
}
.ring-icon {
  position: relative; z-index: 1;
  animation: pulse 2s ease-in-out infinite;
}
@keyframes pulse { 0%,100%{opacity:.7} 50%{opacity:1} }

#load-status { color: var(--text); font-size: .88rem; font-weight: 500; }
.load-sub    { color: var(--muted); font-size: .75rem; min-height: 1em; }

.prog-track {
  width: 180px; height: 2px;
  background: rgba(255,255,255,.08); border-radius: 1px; overflow: hidden;
}
#prog-bar {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--green), #00ccff);
  border-radius: 1px;
  transition: width .5s ease;
}

/* ── MAIN ─────────────────────────────────────────────────── */
#main-screen { position: fixed; inset: 0; }

#video {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
}
#canvas {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
  pointer-events: none;
}
#canvas.calib-mode { pointer-events: all; cursor: crosshair; }

/* scan-line shimmer */
.scanline {
  position: absolute; inset: 0;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0,0,0,.03) 2px,
    rgba(0,0,0,.03) 4px
  );
  pointer-events: none; z-index: 5;
}

/* corner frame decorations */
.frame-corner {
  position: absolute;
  width: 24px; height: 24px;
  border-color: rgba(0,255,136,.35);
  border-style: solid;
  pointer-events: none; z-index: 6;
}
.fc-tl { top: 10px; left: 10px;  border-width: 2px 0 0 2px; border-radius: 2px 0 0 0; }
.fc-tr { top: 10px; right: 10px; border-width: 2px 2px 0 0; border-radius: 0 2px 0 0; }
.fc-bl { bottom: 10px; left: 10px;  border-width: 0 0 2px 2px; border-radius: 0 0 0 2px; }
.fc-br { bottom: 10px; right: 10px; border-width: 0 2px 2px 0; border-radius: 0 0 2px 0; }

/* ── HUD TOP ──────────────────────────────────────────────── */
.hud-top {
  position: absolute;
  top: max(env(safe-area-inset-top, 0px), 14px);
  left: 50%; transform: translateX(-50%);
  display: flex; gap: .4rem;
  z-index: 10; white-space: nowrap;
}
.pill {
  display: flex; flex-direction: column; align-items: center;
  background: var(--card);
  backdrop-filter: blur(16px) saturate(180%);
  -webkit-backdrop-filter: blur(16px) saturate(180%);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: .32rem .75rem;
  min-width: 66px;
}
.pill-lbl { font-size: .55rem; letter-spacing: .1em; color: var(--muted); font-weight: 700; }
.pill-val { font-size: 1.05rem; font-weight: 700; color: #fff; font-variant-numeric: tabular-nums; }
.pill-hi .pill-val { color: var(--green); }

/* ── STATUS DOT ──────────────────────────────────────────── */
.status-bar {
  position: absolute;
  top: max(env(safe-area-inset-top, 0px), 14px);
  right: 14px;
  display: flex; align-items: center; gap: .4rem;
  background: var(--card);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: .28rem .65rem;
  font-size: .72rem; color: var(--muted);
  z-index: 10;
}
.dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--green);
  animation: blink 1.4s ease-in-out infinite;
}
.dot.busy { background: var(--orange); animation: none; }
@keyframes blink { 0%,100%{opacity:1} 50%{opacity:.3} }

/* ── HUD BOTTOM ──────────────────────────────────────────── */
.hud-bottom {
  position: absolute;
  bottom: max(env(safe-area-inset-bottom, 0px), 28px);
  left: 50%; transform: translateX(-50%);
  display: flex; gap: .75rem;
  z-index: 10;
}
.ctrl-btn {
  width: 54px; height: 54px; border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--card);
  backdrop-filter: blur(16px) saturate(180%);
  -webkit-backdrop-filter: blur(16px) saturate(180%);
  color: #fff; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s, border-color .15s, transform .1s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.ctrl-btn:active       { transform: scale(.93); background: rgba(255,255,255,.14); }
.ctrl-btn.active       { border-color: var(--green); color: var(--green); background: rgba(0,255,136,.12); }
.ctrl-btn.calibrated   { border-color: var(--orange); color: var(--orange); }

/* ── CALIBRATION BADGE ───────────────────────────────────── */
.calib-badge {
  position: absolute;
  bottom: max(env(safe-area-inset-bottom, 0px), 28px);
  left: 14px;
  display: flex; align-items: center; gap: .4rem;
  background: var(--card);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: .28rem .65rem;
  font-size: .7rem; color: var(--muted);
  z-index: 10;
  transition: border-color .3s, color .3s;
}
.calib-badge.on { border-color: var(--orange); color: var(--orange); }

/* ── CALIBRATION PANEL ───────────────────────────────────── */
.calib-panel {
  position: absolute;
  bottom: 90px; left: 50%; transform: translateX(-50%);
  background: rgba(4,8,12,.92);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(0,255,136,.35);
  border-radius: 16px;
  padding: 1rem 1.2rem;
  z-index: 20; min-width: 280px; max-width: 340px;
  text-align: center;
  box-shadow: 0 0 40px rgba(0,255,136,.08);
}
.calib-panel p    { font-size: .87rem; color: var(--text); margin-bottom: .6rem; }
.calib-panel label{ font-size: .74rem; color: var(--muted); display: block; margin-bottom: .5rem; }

.calib-diagram { margin: .5rem auto; opacity: .9; }

.calib-inputs { display: flex; gap: .6rem; justify-content: center; margin-bottom: .7rem; }
.calib-field  { display: flex; align-items: center; gap: .35rem; }
.calib-field-lbl { font-size: .72rem; font-weight: 700; }
.calib-field input {
  width: 60px; padding: .38rem .4rem;
  background: rgba(255,255,255,.06);
  border: 1px solid rgba(255,255,255,.15);
  border-radius: 6px; color: #fff;
  font-size: .88rem; text-align: center; outline: none;
}
.calib-field input:focus { border-color: var(--green); }
.calib-field span { color: var(--muted); font-size: .8rem; }

.calib-btns { display: flex; gap: .4rem; justify-content: center; }

.btn-green {
  padding: .42rem .9rem;
  background: var(--green); color: #000;
  font-weight: 700; font-size: .82rem;
  border: none; border-radius: 6px; cursor: pointer;
  touch-action: manipulation;
}
.btn-ghost {
  padding: .42rem .7rem;
  background: rgba(255,255,255,.07);
  border: 1px solid var(--border);
  color: var(--text); font-size: .82rem;
  border-radius: 6px; cursor: pointer;
  touch-action: manipulation;
}
.btn-red { border-color: rgba(255,68,85,.4); color: var(--red) !important; }

/* ── RESPONSIVE ──────────────────────────────────────────── */
@media (max-width: 380px) {
  .pill { min-width: 56px; padding: .28rem .55rem; }
  .pill-val { font-size: .9rem; }
  .hud-top { gap: .3rem; }
}
