/* Depth Scan - dark camera-app look, sized for iPhone (safe areas, 44 px targets). */
:root {
  --bg: #0d0f12;
  --stage: #0d0f12;
  --panel: #171a1f;
  --panel-2: #20242b;
  --line: #2c313a;
  --text: #eef1f5;
  --muted: #9aa3ae;
  --accent: #ffd23f;      /* scanning ring, selected states */
  --shutter: #ff4f45;
  --danger: #ff6b61;
  --ok: #58d68d;
  --radius: 14px;
  --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);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
  -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
button, select, input { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.view { position: fixed; inset: 0; display: flex; flex-direction: column; }
.stage { position: relative; flex: 1; min-height: 0; overflow: hidden; background: var(--stage); }
.spacer { flex: 1; }
.muted { color: var(--muted); font-size: 14px; }

/* ---------- camera ---------- */
#scan .stage { position: absolute; inset: 0; }
#video, #live { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
#live { opacity: 0.7; pointer-events: none; }
#flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; transition: opacity 0.35s; }
#flash.on { opacity: 0.55; transition: none; }
.intro {
  position: absolute; inset: 0; display: flex; flex-direction: column; justify-content: center;
  padding: 24px calc(28px + var(--safe-r)) 180px calc(28px + var(--safe-l)); max-width: 560px; margin: 0 auto;
}
.intro h1 { font-size: 30px; margin: 0 0 10px; letter-spacing: -0.02em; }
.intro p { color: var(--muted); margin: 0; font-size: 17px; }

.bar { display: flex; align-items: center; gap: 10px; }
.bar.top {
  position: absolute; left: 0; right: 0; top: 0; z-index: 2;
  padding: calc(10px + var(--safe-t)) calc(14px + var(--safe-r)) 10px calc(14px + var(--safe-l));
  background: linear-gradient(rgba(0,0,0,0.45), transparent);
}
.bar.bottom {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 2;
  justify-content: space-between;
  padding: 18px calc(26px + var(--safe-r)) calc(20px + var(--safe-b)) calc(26px + var(--safe-l));
  background: linear-gradient(transparent, rgba(0,0,0,0.55));
}
.status {
  position: absolute; left: 0; right: 0; z-index: 2; bottom: calc(126px + var(--safe-b));
  text-align: center; font-size: 17px; font-weight: 600; text-shadow: 0 1px 6px rgba(0,0,0,0.8);
  padding: 0 20px; min-height: 24px; pointer-events: none;
}
.status small { display: block; font-weight: 400; font-size: 14px; color: #d5dbe2; }

.chip {
  height: 36px; padding: 0 14px; border-radius: 18px; border: 0;
  background: rgba(20,22,26,0.6); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  font-size: 15px; font-weight: 600;
}
.chip[aria-pressed="true"] { background: var(--accent); color: #111; }
.icon {
  width: 44px; height: 44px; border-radius: 22px; border: 0; display: grid; place-items: center;
  background: rgba(20,22,26,0.6); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  font-size: 26px; line-height: 1;
}
.icon svg, .round svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linejoin: round; }

.shutter { position: relative; width: 80px; height: 80px; border: 0; padding: 0; background: none; }
.shutter svg { position: absolute; inset: 0; width: 80px; height: 80px; transform: rotate(-90deg); }
.shutter .track { fill: none; stroke: rgba(255,255,255,0.9); stroke-width: 5; }
.shutter .ring { fill: none; stroke: var(--accent); stroke-width: 5; stroke-linecap: round;
  stroke-dasharray: 226.2; stroke-dashoffset: 226.2; opacity: 0; transition: stroke-dashoffset 0.12s linear; }
.shutter .core {
  position: absolute; left: 50%; top: 50%; width: 62px; height: 62px; margin: -31px 0 0 -31px;
  border-radius: 31px; background: var(--shutter); transition: all 0.2s;
}
.shutter.scanning .track { stroke: rgba(255,255,255,0.3); }
.shutter.scanning .ring { opacity: 1; }
.shutter.scanning .core { width: 30px; height: 30px; margin: -15px 0 0 -15px; border-radius: 7px; }
.shutter.hold .ring { animation: pulse 0.6s ease-in-out infinite alternate; }
@keyframes pulse { from { stroke-opacity: 1; } to { stroke-opacity: 0.45; } }

.thumb, .round {
  width: 52px; height: 52px; border-radius: 12px; border: 2px solid rgba(255,255,255,0.85);
  background: rgba(20,22,26,0.6); padding: 0; position: relative; overflow: visible;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; border-radius: 10px; display: block; }
.thumb #count {
  position: absolute; right: -8px; top: -8px; min-width: 22px; height: 22px; padding: 0 6px; border-radius: 11px;
  background: var(--accent); color: #111; font-size: 13px; font-weight: 700; line-height: 22px;
}
.thumb #count:empty { display: none; }
.round { border-radius: 26px; display: grid; place-items: center; }
.round:disabled { opacity: 0.35; }

/* ---------- pages ---------- */
.page { background: var(--bg); }
.bar.head {
  padding: calc(8px + var(--safe-t)) calc(12px + var(--safe-r)) 8px calc(12px + var(--safe-l));
  border-bottom: 1px solid var(--line); min-height: 56px; background: var(--bg);
}
.bar.head h1 { flex: 1; font-size: 17px; margin: 0; text-align: center; }
.back { border: 0; background: none; color: var(--accent); font-size: 17px; padding: 8px 4px; min-height: 44px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; min-height: 40px; padding: 0 14px;
  border-radius: 10px; border: 1px solid var(--line); background: var(--panel-2); font-size: 15px; font-weight: 600;
}
.btn.primary { background: var(--accent); color: #111; border-color: transparent; }
.btn.danger { color: var(--danger); }
.btn.quiet { background: none; border-color: transparent; color: var(--muted); }
.btn:disabled { opacity: 0.4; }

.scroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 8px calc(12px + var(--safe-r)) calc(24px + var(--safe-b)) calc(12px + var(--safe-l)); }
.empty { color: var(--muted); text-align: center; margin-top: 30vh; }
.scan-group { margin: 14px 0 22px; }
.scan-head { display: flex; align-items: center; gap: 8px; margin: 0 2px 8px; }
.scan-head h2 { flex: 1; font-size: 15px; margin: 0; font-weight: 600; }
.scan-head .muted { font-weight: 400; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 6px; }
.card {
  position: relative; aspect-ratio: 3 / 4; border: 0; padding: 0; border-radius: 8px; overflow: hidden;
  background: var(--panel);
}
.card img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.card img.depth { clip-path: inset(0 0 0 50%); }
.card .n { position: absolute; left: 6px; bottom: 5px; font-size: 12px; font-weight: 700; text-shadow: 0 1px 3px #000; }
.card .state {
  position: absolute; right: 6px; top: 6px; width: 10px; height: 10px; border-radius: 5px;
  background: var(--accent); animation: pulse-dot 1s ease-in-out infinite alternate;
}
.card .state.error { background: var(--danger); animation: none; }
@keyframes pulse-dot { from { opacity: 1; } to { opacity: 0.3; } }
.card .restore { position: absolute; left: 6px; right: 6px; bottom: 6px; min-height: 32px; font-size: 13px; }
details#removed { margin-top: 20px; }
details#removed summary { color: var(--muted); padding: 10px 2px; font-size: 15px; }
details#removed .btn { margin-top: 12px; }

/* ---------- one shot ---------- */
#shot .stage { background: var(--stage); }
.frame { position: absolute; }
.frame img, .frame canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.three { position: absolute; inset: 0; touch-action: none; }
.three canvas { display: block; }
.busy {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  background: rgba(20,22,26,0.8); padding: 10px 16px; border-radius: 10px; font-size: 15px;
}
.panel {
  padding: 12px calc(16px + var(--safe-r)) 6px calc(16px + var(--safe-l));
  border-top: 1px solid var(--line); background: var(--bg);
  display: flex; flex-direction: column; gap: 10px;
}
.slider { display: flex; align-items: center; gap: 12px; font-size: 14px; color: var(--muted); }
.slider span:first-child { min-width: 92px; }
.slider input { flex: 1; accent-color: var(--accent); min-height: 32px; }
.slider output { min-width: 42px; text-align: right; color: var(--text); font-variant-numeric: tabular-nums; }
#depthPanel .slider span:first-child { min-width: 0; }
.legend { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--muted); }
.legend i { flex: 1; height: 8px; border-radius: 4px;
  background: linear-gradient(90deg, #30123b, #4662d7, #36aaf9, #1ae4b6, #72fe5e, #c8ef34, #faba39, #f66b19, #ca2a04, #7a0403); }
.row { display: flex; align-items: center; gap: 10px; justify-content: space-between; }
.bar.pager {
  padding: 6px calc(12px + var(--safe-r)) calc(8px + var(--safe-b)) calc(12px + var(--safe-l)); background: var(--bg);
}
.bar.pager .icon { background: var(--panel-2); }
.bar.pager .icon:disabled { opacity: 0.3; }
#shotTitle { font-size: 15px; font-weight: 600; min-width: 90px; text-align: center; }

.seg { display: inline-flex; background: var(--panel-2); border-radius: 10px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: none; min-height: 34px; padding: 0 14px; border-radius: 8px; font-size: 15px; font-weight: 600; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--text); color: #111; }
.seg.small button { min-height: 32px; padding: 0 12px; font-size: 14px; }

/* ---------- dialogs ---------- */
dialog {
  border: 1px solid var(--line); border-radius: 18px; background: var(--panel); color: var(--text);
  width: min(420px, calc(100vw - 24px)); padding: 20px; max-height: calc(100vh - 40px);
}
dialog::backdrop { background: rgba(0,0,0,0.55); }
dialog h2 { margin: 0; font-size: 19px; }
dialog form { display: flex; flex-direction: column; gap: 14px; }
fieldset { border: 0; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
legend { font-size: 14px; color: var(--muted); padding: 0; margin-bottom: 6px; }
fieldset .seg { display: flex; }
fieldset .seg button { flex: 1; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--muted); }
.field select { min-height: 42px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel-2); padding: 0 10px; color: var(--text); font-size: 16px; }
.actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 4px; }
.exports { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.exports li { display: flex; align-items: center; gap: 8px; padding: 10px 12px; background: var(--panel-2); border-radius: 12px; }
.exports li div { flex: 1; min-width: 0; }
.exports li b { display: block; font-size: 15px; }
.exports li small { color: var(--muted); font-size: 13px; }
.exports .btn { min-height: 36px; padding: 0 12px; background: var(--panel); }
