:root {
  --bg: #0a1428;
  --bg-2: #1a2a4a;
  --fg: #eaeaea;
  --fg-dim: #88a;
  --primary: #7df;
  --primary-2: #4af;
  --ok: #7d7;
  --warn: #fa0;
  --err: #f78;
  --border: #2a2a3a;
  --radius: 12px;
  --shadow: 0 8px 24px rgba(0,0,0,0.4);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0;
  height: 100%; width: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
}

.screen {
  position: fixed; inset: 0;
  display: none;
  background: linear-gradient(160deg, var(--bg) 0%, var(--bg-2) 100%);
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}
.screen.active { display: flex; flex-direction: column; }
.content {
  flex: 1;
  display: flex; flex-direction: column;
  justify-content: center; align-items: center;
  padding: 40px 24px;
  text-align: center;
  max-width: 480px;
  margin: 0 auto;
  width: 100%;
}
.logo { font-size: 64px; line-height: 1; margin-bottom: 20px; }
h1 { font-size: 28px; font-weight: 600; margin: 0 0 12px; color: var(--primary); }
h2 { font-size: 22px; font-weight: 600; margin: 8px 0 12px; color: var(--primary); text-align: center; }
p { font-size: 16px; line-height: 1.5; margin: 0 0 20px; }
.muted { color: var(--fg-dim); }
b { color: var(--fg); font-weight: 600; }

.checklist {
  list-style: none; padding: 0; margin: 16px 0 32px;
  font-size: 15px;
  text-align: left;
  width: 100%; max-width: 320px;
}
.checklist li {
  padding: 10px 14px;
  background: rgba(125,221,255,0.06);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 8px;
}

.btn-primary, .btn-secondary {
  display: inline-block;
  padding: 14px 20px;
  border-radius: var(--radius);
  font: 600 16px inherit;
  border: 1px solid transparent;
  cursor: pointer;
  transition: transform .1s, background .15s;
  margin-top: 8px;
}
.btn-primary { background: var(--primary); color: var(--bg); width: 100%; }
.btn-primary:hover { background: var(--primary-2); }
.btn-primary:disabled { background: #345; color: #678; cursor: not-allowed; }
.btn-secondary {
  background: transparent;
  color: var(--primary);
  border-color: var(--primary);
}

/* === Tutorial === */
.tutorial-container {
  flex: 1;
  display: flex; flex-direction: column;
  padding: 24px 16px;
  padding-top: max(24px, env(safe-area-inset-top));
  padding-bottom: max(24px, env(safe-area-inset-bottom));
  max-width: 480px;
  margin: 0 auto;
  width: 100%;
}
.tutorial-progress {
  display: flex; justify-content: center; gap: 8px;
  margin-bottom: 24px;
}
.tutorial-progress .dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--border);
  transition: background .2s;
}
.tutorial-progress .dot.active { background: var(--primary); }
.tutorial-slides { flex: 1; position: relative; overflow: hidden; }
.tutorial-slide {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 16px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .3s;
}
.tutorial-slide.active { opacity: 1; pointer-events: auto; }
.tut-illustration {
  width: 100%;
  max-width: 280px;
  margin-bottom: 24px;
}
.tut-illustration svg { width: 100%; height: auto; }
.tutorial-slide p { max-width: 360px; }
.tutorial-nav {
  display: flex; gap: 8px;
  margin-top: 16px;
}
.tutorial-nav button { flex: 1; }

/* === Permissions === */
.perm-list { width: 100%; margin: 16px 0 24px; }
.perm-item {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 8px;
}
.perm-icon { font-size: 22px; }
.perm-label { flex: 1; text-align: left; font-weight: 500; }
.perm-status { color: var(--warn); font-size: 12px; text-transform: uppercase; }
.perm-item.granted .perm-status { color: var(--ok); }
.perm-item.denied .perm-status { color: var(--err); }

.probe-list { width: 100%; margin: 16px 0 24px; }
.probe-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 14px;
  background: rgba(255,255,255,0.04);
  border-radius: 8px;
  margin-bottom: 4px;
  font-size: 14px;
}
.probe-item .ok { color: var(--ok); }
.probe-item .warn { color: var(--warn); }
.probe-item .err { color: var(--err); }

/* === Capture screen === */
.capture-screen { background: #000; padding: 0; }
#camera-preview {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
  background: #000;
}

.hud-top {
  position: absolute; top: 0; left: 0; right: 0;
  padding: 12px 16px;
  padding-top: max(12px, env(safe-area-inset-top));
  display: flex; align-items: center; gap: 12px;
  background: linear-gradient(to bottom, rgba(0,0,0,0.75), transparent);
  z-index: 5;
}
.hud-stats {
  flex: 1; display: flex; flex-direction: column; gap: 2px;
  color: #fff; font: 600 13px inherit;
  text-shadow: 0 1px 3px rgba(0,0,0,0.9);
}
#stat-time { font-weight: 400; font-size: 11px; opacity: .8; }
.hud-btn {
  width: 44px; height: 44px;
  border-radius: 50%;
  border: 0; padding: 0;
  background: rgba(0,0,0,0.6);
  color: #fff;
  font-size: 20px;
  cursor: pointer;
  backdrop-filter: blur(8px);
}
.hud-btn.primary { background: var(--ok); color: #000; }

.hud-quality {
  position: absolute; top: 70px; left: 12px;
  display: flex; flex-direction: column; gap: 4px;
  z-index: 4;
}
.qchip {
  display: flex; align-items: center; gap: 6px;
  padding: 4px 8px;
  background: rgba(0,0,0,0.65);
  backdrop-filter: blur(8px);
  border-radius: 12px;
  color: #fff; font: 500 11px inherit;
  text-shadow: 0 1px 2px rgba(0,0,0,0.8);
}
.qchip .dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--err);
  transition: background .2s, box-shadow .2s;
}
.qchip.ok .dot   { background: var(--ok); box-shadow: 0 0 6px var(--ok); }
.qchip.warn .dot { background: var(--warn); }

/* Guidance grande arriba derecha */
.guidance {
  position: absolute; top: 80px; right: 16px;
  z-index: 4;
  background: rgba(0,0,0,0.75);
  backdrop-filter: blur(10px);
  padding: 12px 16px;
  border-radius: 14px;
  max-width: 220px;
  text-align: center;
  border: 1px solid rgba(125,221,255,0.3);
}
.guide-arrow {
  font-size: 32px;
  line-height: 1;
  margin-bottom: 4px;
  animation: pulse 1.5s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: .9; }
  50% { transform: scale(1.15); opacity: 1; }
}
.guide-text {
  color: #fff;
  font: 600 13px inherit;
  line-height: 1.3;
  text-shadow: 0 1px 2px rgba(0,0,0,0.8);
}

/* Brújula central */
.compass-wrap {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 180px; height: 180px;
  pointer-events: none;
  z-index: 3;
}
.compass {
  width: 100%; height: 100%;
  filter: drop-shadow(0 4px 16px rgba(0,0,0,0.6));
}
.compass-seg {
  fill: rgba(255,255,255,0.12);
  stroke: rgba(0,0,0,0.3);
  stroke-width: 1;
  transition: fill .3s;
}
.compass-seg.covered { fill: rgba(125,221,125,0.85); }
.compass-seg.missing-highlight { fill: rgba(255,120,140,0.7); animation: blink 0.8s ease-in-out infinite; }
@keyframes blink {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 1; }
}
.compass-center {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  color: #fff;
  text-shadow: 0 1px 4px rgba(0,0,0,0.9);
  pointer-events: none;
}
.compass-pct {
  font: 700 28px sans-serif;
  color: var(--ok);
  line-height: 1;
}
.compass-height {
  font: 500 11px sans-serif;
  margin-top: 4px;
  color: #fff;
}
.compass-height small { display: block; font-weight: 400; opacity: .8; font-size: 10px; }

.toast {
  position: absolute; bottom: 150px; left: 50%;
  transform: translateX(-50%);
  padding: 10px 16px;
  background: rgba(0,0,0,0.85);
  color: #fff;
  border-radius: 20px;
  font: 500 14px inherit;
  max-width: 80%;
  text-align: center;
  z-index: 6;
  animation: toast-in .2s ease-out;
}
.toast.warn { background: rgba(255,170,0,0.95); color: #000; }
.toast.err  { background: rgba(255,90,120,0.95); color: #fff; }
.toast.ok   { background: rgba(120,220,120,0.95); color: #000; }
@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 10px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}

.hud-bottom {
  position: absolute; bottom: 0; left: 0; right: 0;
  padding: 16px;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  background: linear-gradient(to top, rgba(0,0,0,0.75), transparent);
  z-index: 5;
}
.shutter {
  width: 64px; height: 64px;
  border-radius: 50%;
  background: rgba(255,255,255,0.3);
  border: 3px solid #fff;
  padding: 0; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: transform .1s, background .15s;
}
.shutter:not(:disabled):active { transform: scale(0.92); }
.shutter:disabled { border-color: rgba(255,255,255,0.4); cursor: not-allowed; }
.shutter-inner {
  width: 50px; height: 50px;
  border-radius: 50%;
  background: #fff;
  display: block;
}
.shutter:disabled .shutter-inner { background: rgba(255,255,255,0.3); }
.hud-help {
  color: rgba(255,255,255,0.85);
  font-size: 11px;
  text-align: center;
  text-shadow: 0 1px 2px rgba(0,0,0,0.8);
}

/* Flash visual al captura */
.flash-overlay {
  position: absolute; inset: 0;
  background: white;
  pointer-events: none;
  opacity: 0;
  z-index: 100;
}

/* === AR overlay (dom-overlay durante immersive-ar) === */
.ar-overlay {
  position: fixed; inset: 0;
  z-index: 9999;
  pointer-events: none;
  display: flex; flex-direction: column;
  font-family: -apple-system, system-ui, sans-serif;
}
.ar-overlay[hidden] { display: none; }
.ar-top {
  display: flex; justify-content: space-between; align-items: center;
  padding: max(16px, env(safe-area-inset-top)) 16px 12px;
  background: linear-gradient(to bottom, rgba(0,0,0,0.6), transparent);
}
.ar-photos {
  color: #fff; font: 700 18px sans-serif;
  text-shadow: 0 2px 6px rgba(0,0,0,0.9);
  background: rgba(0,0,0,0.5);
  padding: 6px 14px; border-radius: 18px;
  backdrop-filter: blur(8px);
}
.ar-finish {
  pointer-events: auto;
  background: #7d7; color: #000;
  border: 0; border-radius: 20px;
  padding: 10px 18px;
  font: 700 15px sans-serif;
  box-shadow: 0 2px 8px rgba(0,0,0,0.4);
}
.ar-planes {
  display: flex; gap: 8px; justify-content: center;
  padding: 8px;
}
.ar-plane {
  background: rgba(0,0,0,0.5);
  color: rgba(255,255,255,0.5);
  padding: 6px 12px; border-radius: 14px;
  font: 600 12px sans-serif;
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255,255,255,0.15);
  transition: all .3s;
}
.ar-plane.detected {
  color: #7d7;
  border-color: #7d7;
  background: rgba(125,221,125,0.2);
}
.ar-guidance {
  margin: auto;
  text-align: center;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(12px);
  border-radius: 20px;
  padding: 20px 28px;
  border: 2px solid rgba(125,221,255,0.4);
  max-width: 80%;
}
.ar-arrow {
  font-size: 56px; line-height: 1;
  margin-bottom: 8px;
  animation: pulse 1.5s ease-in-out infinite;
}
.ar-text {
  color: #fff; font: 600 17px sans-serif;
  line-height: 1.4;
  text-shadow: 0 2px 4px rgba(0,0,0,0.9);
}
.ar-status {
  text-align: center;
  color: rgba(255,255,255,0.7);
  font: 400 11px sans-serif;
  padding: 8px 16px max(16px, env(safe-area-inset-bottom));
  text-shadow: 0 1px 2px rgba(0,0,0,0.9);
}

/* Debug log on-screen (para celular sin PC) */
.ar-debug-toggle {
  position: fixed; bottom: 12px; right: 12px;
  pointer-events: auto;
  background: rgba(0,0,0,0.7); color: #7df;
  border: 1px solid #7df; border-radius: 16px;
  padding: 6px 12px; font: 600 12px monospace;
  z-index: 10000;
}
.ar-debug {
  position: fixed; bottom: 50px; left: 8px; right: 8px;
  max-height: 40vh; overflow-y: auto;
  pointer-events: auto;
  background: rgba(0,0,0,0.92);
  border: 1px solid #2a2a3a; border-radius: 8px;
  padding: 8px;
  font: 400 10px/1.4 monospace;
  color: #ccc;
  z-index: 10000;
  white-space: pre-wrap; word-break: break-word;
}
.ar-debug[hidden] { display: none; }
.ar-debug .err { color: #f78; }
.ar-debug .warn { color: #fa0; }
.ar-debug .ok { color: #7d7; }

/* === Gallery (review) === */
.gallery {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(70px, 1fr));
  gap: 4px;
  width: 100%; max-height: 50vh;
  overflow-y: auto;
  margin: 12px 0;
}
.gallery img {
  width: 100%; aspect-ratio: 1; object-fit: cover;
  border-radius: 4px;
  background: #222;
}
.actions { display: flex; gap: 8px; width: 100%; margin-top: 16px; }
.actions button { flex: 1; }
.upload-status {
  margin-top: 16px;
  padding: 12px;
  background: rgba(125,221,255,0.1);
  border: 1px solid var(--primary);
  border-radius: 8px;
  font-size: 13px;
  text-align: left;
}
