:root {
  --bg: #0c0f16;
  --panel: #151a25;
  --panel-2: #1c2330;
  --line: #2a3345;
  --text: #e9eef7;
  --muted: #8d99ad;
  --accent: #5ad8ff;
  --accent-ink: #04222d;
  --warn: #ffb35a;
  --danger: #ff6b6b;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
  overscroll-behavior: none;
}
input, select, button { font: inherit; color: inherit; }
input[type="text"], input[type="number"], select { -webkit-user-select: text; user-select: text; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h2 { font-size: 1.05rem; margin: 22px 0 10px; }
h3 { font-size: 1rem; margin: 18px 0 8px; }
p { margin: 8px 0; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.tight { margin: 2px 0 8px; }
.center { text-align: center; }
[hidden] { display: none !important; }

#app { position: fixed; inset: 0; }
.screen {
  position: absolute; inset: 0; display: none; flex-direction: column;
  background: var(--bg);
}
.screen.active { display: flex; }
.scroll {
  flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: calc(var(--safe-t) + 14px) calc(var(--safe-r) + 16px) calc(var(--safe-b) + 24px) calc(var(--safe-l) + 16px);
}

/* ---------- botones ---------- */
.btn {
  appearance: none; border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
  padding: 12px 18px; border-radius: 14px; font-weight: 600; cursor: pointer; min-height: 46px;
  transition: transform .06s ease, background .15s;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.ghost { background: transparent; }
.btn.big { width: 100%; padding: 16px; font-size: 1.05rem; border-radius: 16px; }
.btn.small { padding: 8px 14px; min-height: 38px; font-size: .9rem; border-radius: 12px; }
.btn:disabled { opacity: .45; }
.icon-btn {
  appearance: none; border: 0; width: 42px; height: 42px; border-radius: 21px;
  background: rgba(12,15,22,.62); color: #fff; font-size: 1.25rem; line-height: 1;
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px); cursor: pointer;
}
.kbd { background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; padding: 1px 6px; font-size: .88em; white-space: nowrap; }

/* ---------- inicio ---------- */
.hero { text-align: center; padding: 18px 0 18px; }
.logo { border-radius: 16px; margin-bottom: 8px; }
.hero h1 { font-size: 1.9rem; letter-spacing: -.02em; }
.sub { color: var(--muted); margin-top: 6px; }
#btn-demo { width: 100%; margin-top: 10px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 14px 16px; margin: 14px 0; }
.card.note { font-size: .92rem; }
details.card summary { cursor: pointer; font-weight: 600; }
.tips { padding-left: 1.2em; margin: 10px 0 0; }
.tips li { margin: 8px 0; color: #c8d2e2; font-size: .93rem; }
.grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.scan-card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; position: relative; cursor: pointer; }
.scan-card img { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; background: #10131a; }
.scan-card .meta { padding: 8px 10px 10px; }
.scan-card .meta b { display: block; font-size: .92rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.scan-card .meta span { color: var(--muted); font-size: .78rem; }
.scan-card .del {
  position: absolute; top: 6px; right: 6px; width: 30px; height: 30px; border-radius: 15px; border: 0;
  background: rgba(12,15,22,.7); color: #fff; font-size: .95rem;
}

/* ---------- escaneo ---------- */
#scan { background: #000; }
.cam { position: absolute; inset: 0; background: #000; overflow: hidden; }
.cam video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.cam canvas { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
#flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; }
#flash.go { animation: flash .22s ease-out; }
@keyframes flash { from { opacity: .55; } to { opacity: 0; } }

.topbar {
  position: absolute; left: 0; right: 0; top: 0; z-index: 3;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(var(--safe-t) + 8px) calc(var(--safe-r) + 12px) 8px calc(var(--safe-l) + 12px);
}
.pill {
  background: rgba(12,15,22,.62); -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  padding: 7px 14px; border-radius: 20px; font-weight: 600; font-variant-numeric: tabular-nums;
}
.dial {
  position: absolute; z-index: 2; width: 92px; height: 92px;
  right: calc(var(--safe-r) + 12px); top: calc(var(--safe-t) + 62px);
}
.hint {
  position: absolute; z-index: 2; left: calc(var(--safe-l) + 12px); right: 116px;
  top: calc(var(--safe-t) + 62px);
  background: rgba(12,15,22,.62); -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  border-radius: 12px; padding: 8px 12px; font-size: .86rem; min-height: 38px;
}
.hint.warn { color: var(--warn); }
.toast {
  position: fixed; z-index: 30; left: 50%; transform: translateX(-50%);
  top: calc(var(--safe-t) + 150px); max-width: 80%;
  background: rgba(20,24,34,.92); border: 1px solid var(--line); padding: 10px 16px; border-radius: 12px; font-size: .9rem; text-align: center;
}

.sheet {
  position: absolute; z-index: 4; left: 0; right: 0;
  bottom: calc(var(--safe-b) + 92px);
  max-height: 42dvh; overflow-y: auto; -webkit-overflow-scrolling: touch;
  background: rgba(16,20,30,.94); -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
  border-top: 1px solid var(--line); border-radius: 20px 20px 0 0;
  padding: 14px calc(var(--safe-r) + 16px) 12px calc(var(--safe-l) + 16px);
  transform: translateY(calc(100% + 120px)); visibility: hidden; pointer-events: none;
  transition: transform .25s ease, visibility 0s linear .25s;
}
.sheet.open { transform: none; visibility: visible; pointer-events: auto; transition: transform .25s ease, visibility 0s; }
.controls {
  position: absolute; z-index: 5; left: 0; right: 0; bottom: 0;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px calc(var(--safe-r) + 18px) calc(var(--safe-b) + 14px) calc(var(--safe-l) + 18px);
  background: linear-gradient(to top, rgba(0,0,0,.65), rgba(0,0,0,0));
}
.controls .btn.big { flex: 1; }
.controls .btn.small { min-width: 96px; }
.shutter {
  width: 70px; height: 70px; border-radius: 35px; border: 4px solid #fff; background: rgba(255,255,255,.25);
  position: relative; cursor: pointer; flex: none;
}
.shutter::after { content: ""; position: absolute; inset: 5px; border-radius: 50%; background: #fff; }
.shutter:active::after { inset: 8px; }

.seg { display: flex; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { flex: 1; border: 0; background: transparent; padding: 9px 8px; border-radius: 9px; font-weight: 600; font-size: .88rem; color: var(--muted); cursor: pointer; }
.seg button.on { background: var(--accent); color: var(--accent-ink); }

.row { display: block; margin: 12px 0 4px; }
.row > span { display: flex; justify-content: space-between; font-size: .9rem; margin-bottom: 2px; }
.row b { color: var(--accent); font-weight: 600; }
.row2 { display: flex; gap: 12px; margin: 10px 0; align-items: end; }
.row2 > label, .row2 > span { flex: 1; font-size: .85rem; color: var(--muted); display: flex; flex-direction: column; gap: 4px; }
.refrow { align-items: center; }
.refrow span { flex: 1; }
.checks { margin: 8px 0 4px; }
.check { display: flex; align-items: center; gap: 10px; margin: 9px 0; font-size: .92rem; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }
input[type="range"] { width: 100%; accent-color: var(--accent); height: 28px; }
select, input[type="number"], input[type="text"] {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; color: var(--text); width: 100%; min-height: 42px;
}
details.adv { margin-top: 6px; font-size: .9rem; }
details.adv summary { cursor: pointer; color: var(--muted); padding: 6px 0; }

.modal {
  position: absolute; inset: 0; z-index: 10; display: flex; align-items: center; justify-content: center;
  background: rgba(5,8,13,.72); padding: 24px;
}
.modal .card { width: 100%; max-width: 380px; margin: 0; }
.modal .card .btn { width: 100%; margin-top: 8px; }
.bar-outer { height: 10px; background: var(--panel-2); border-radius: 5px; overflow: hidden; margin-top: 14px; }
.bar-inner { height: 100%; width: 0; background: var(--accent); transition: width .15s ease; }

/* ---------- barra superior genérica ---------- */
.bar {
  display: grid; grid-template-columns: 42px 1fr 42px; align-items: center; gap: 8px;
  padding: calc(var(--safe-t) + 8px) calc(var(--safe-r) + 12px) 8px calc(var(--safe-l) + 12px);
  border-bottom: 1px solid var(--line); background: var(--bg);
}
.bar .icon-btn { background: var(--panel); font-size: 1.6rem; padding-bottom: 3px; }
.bar h2 { margin: 0; text-align: center; font-size: 1.05rem; }
.bar .name { background: transparent; border: 0; text-align: center; font-weight: 700; font-size: 1.05rem; min-height: 36px; padding: 4px; }

/* ---------- revisión ---------- */
.thumbs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin: 10px 0 4px; }
.thumb { position: relative; border-radius: 8px; overflow: hidden; border: 2px solid transparent; background: #000; cursor: pointer; }
.thumb canvas { display: block; width: 100%; height: auto; }
.thumb i { position: absolute; left: 4px; top: 3px; font-style: normal; font-size: .66rem; background: rgba(0,0,0,.6); padding: 0 5px; border-radius: 6px; }
.thumb.low { border-color: var(--warn); }
.thumb.off { border-color: var(--danger); opacity: .35; }
.thumb.off::after { content: "✕"; position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 1.6rem; color: var(--danger); }

/* ---------- visor ---------- */
.stage { position: relative; flex: 0 0 46%; min-height: 220px; background: #10131a; }
.stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; display: block; }
.panel { padding-top: 12px; }
.exports { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.exports.two { grid-template-columns: 1fr 1fr; margin-top: 14px; }
.exports .btn { padding: 12px 6px; }
.hrow > span { flex: 2; color: var(--text); font-size: .9rem; display: flex; flex-direction: column; }
.hrow input { flex: 1; }
