/* SphereCam — dark, camera-app styling. Mobile first; safe areas for notched phones. */
:root {
  --bg: #0b0c0e;
  --panel: #15171b;
  --panel-2: #1d2026;
  --line: #2a2e36;
  --text: #f2f3f5;
  --muted: #9aa0aa;
  --accent: #ffd34e;
  --accent-ink: #1b1600;
  --ok: #4ade80;
  --warn: #ff8a6b;
  --radius: 16px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
button, select, input { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13.5px; }
.warn { color: var(--warn); font-size: 14px; }

.screen { display: none; min-height: 100dvh; }
.screen.active { display: block; }

/* ---------- home ---------- */
#home { max-width: 560px; margin: 0 auto; padding: calc(var(--safe-t) + 8px) 16px calc(var(--safe-b) + 24px); }
.bar { display: flex; align-items: center; justify-content: space-between; height: 52px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; font-size: 18px; letter-spacing: 0.2px; }
.brand svg { width: 28px; height: 28px; color: var(--accent); stroke-width: 1.6; }
.icon-btn { width: 42px; height: 42px; border-radius: 50%; border: 1px solid var(--line); background: var(--panel); display: grid; place-items: center; }
.icon-btn svg { width: 22px; height: 22px; }

.hero { padding: 18px 0 8px; }
.hero h1 { font-size: clamp(26px, 7.4vw, 34px); line-height: 1.12; margin: 6px 0 10px; letter-spacing: -0.4px; }
.lead { color: #c9ccd2; margin: 0 0 20px; }
.modes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 14px; }
.modes button {
  border: 1px solid var(--line); background: var(--panel); border-radius: 12px; padding: 10px 6px; font-weight: 600;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.modes button small { font-weight: 400; font-size: 12px; color: var(--muted); }
.modes button[aria-checked="true"] { border-color: var(--accent); background: #262111; }
.modes button[aria-checked="true"] small { color: #d9c486; }
.primary {
  width: 100%; border: 0; border-radius: 14px; background: var(--accent); color: var(--accent-ink); font-weight: 700; font-size: 17px;
  padding: 16px; display: flex; align-items: center; justify-content: center; gap: 10px;
}
.primary svg { width: 24px; height: 24px; stroke-width: 2; }
.primary:active { transform: scale(0.99); }
.primary:disabled { opacity: 0.6; }
.secondary { border: 1px solid var(--line); background: var(--panel-2); border-radius: 12px; padding: 10px 16px; font-weight: 600; }
#shotEstimate { text-align: center; margin: 10px 0 0; min-height: 1.4em; }
.demo-link { display: block; text-align: center; color: var(--accent); margin-top: 10px; font-size: 14px; }

.gallery-wrap h2 { font-size: 17px; margin: 28px 0 12px; }
.gallery { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.card { position: relative; border-radius: 12px; overflow: hidden; background: var(--panel); border: 1px solid var(--line); text-align: left; padding: 0; }
.card img, .card .ph { display: block; width: 100%; aspect-ratio: 2 / 1; object-fit: cover; background: #111318; }
.card .ph { display: grid; place-items: center; color: var(--muted); font-size: 13px; }
.card .meta { padding: 8px 10px 10px; font-size: 13px; }
.card .meta b { display: block; font-weight: 600; font-size: 13.5px; }
.card .tag { position: absolute; top: 8px; left: 8px; background: rgba(0,0,0,0.6); border-radius: 999px; padding: 2px 8px; font-size: 12px; }
.card .tag.todo { color: var(--accent); }

.tips { margin-top: 26px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px; }
.tips summary { font-weight: 600; cursor: pointer; }
.tips ul { margin: 10px 0 2px; padding-left: 20px; color: #c9ccd2; font-size: 14.5px; }
.tips li { margin: 6px 0; }
.foot { text-align: center; margin-top: 22px; }

/* ---------- capture ---------- */
.capture { position: fixed; inset: 0; background: #000; overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none; }
.capture.active { display: block; }
.cap-video, .cap-ar, .cap-hud { position: absolute; inset: 0; width: 100%; height: 100%; }
.cap-video { object-fit: cover; }
.capture.sim .cap-video { object-fit: contain; }
.cap-ar, .cap-hud { pointer-events: none; }
.cap-top {
  position: absolute; left: 0; right: 0; top: 0; padding: calc(var(--safe-t) + 10px) 14px 10px;
  display: flex; align-items: center; justify-content: space-between;
  background: linear-gradient(rgba(0,0,0,0.55), rgba(0,0,0,0));
}
.round { width: 44px; height: 44px; border-radius: 50%; border: 0; background: rgba(20,22,26,0.65); display: grid; place-items: center; backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
.round svg { width: 22px; height: 22px; stroke-width: 2; }
.round:disabled { opacity: 0.35; }
.cap-count { font-weight: 700; font-size: 17px; background: rgba(20,22,26,0.65); padding: 8px 16px; border-radius: 999px; font-variant-numeric: tabular-nums; }
.cap-hint {
  position: absolute; left: 50%; top: calc(var(--safe-t) + 70px); transform: translateX(-50%); max-width: calc(100% - 32px);
  background: rgba(20,22,26,0.72); padding: 8px 14px; border-radius: 12px; font-size: 15px; text-align: center; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
.cap-bottom {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 18px 20px calc(var(--safe-b) + 22px);
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  background: linear-gradient(rgba(0,0,0,0), rgba(0,0,0,0.55));
}
.cap-side { display: flex; justify-content: flex-end; }
.cap-shoot { width: 70px; height: 70px; border-radius: 50%; border: 4px solid #fff; background: rgba(255,255,255,0.18); padding: 0; }
.cap-shoot:active { background: rgba(255,255,255,0.5); }
.pill { border: 0; border-radius: 999px; background: rgba(20,22,26,0.75); padding: 10px 14px; font-weight: 600; font-size: 14px; }
.cap-flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; }
.cap-flash.on { animation: flash 0.28s ease-out; }
@keyframes flash { from { opacity: 0.7; } to { opacity: 0; } }
.cap-coach { position: absolute; inset: 0; background: rgba(0,0,0,0.72); display: grid; place-items: center; padding: 16px; z-index: 5; }
.coach-card { width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 18px; text-align: center; }
.coach-card svg { width: 200px; height: 120px; margin: 0 auto 6px; display: block; }
.coach-card h3 { margin: 4px 0 8px; font-size: 18px; }
.coach-card p { margin: 0 0 6px; color: #c9ccd2; font-size: 14.5px; }
.coach-card .check { justify-content: center; font-size: 14px; }
.coach-path { stroke: var(--muted); stroke-width: 1.5; stroke-dasharray: 4 5; }
.coach-arrow { stroke: var(--accent); stroke-width: 2.5; }
.coach-phone { stroke: var(--accent); stroke-width: 2.5; fill: #262111; }
.coach-foot { fill: #3a3e46; stroke: none; }
.cap-rotate { position: absolute; inset: 0; background: rgba(0,0,0,0.85); display: grid; place-content: center; text-align: center; gap: 10px; }
.cap-rotate svg { width: 56px; height: 56px; margin: 0 auto; color: var(--accent); }

/* ---------- stitching ---------- */
.stitch.active { display: grid; place-items: center; padding: 24px 16px; }
.stitch-box { width: 100%; max-width: 420px; text-align: center; }
.stitch-box h2 { margin: 22px 0 6px; font-size: 21px; }
.progress { height: 8px; border-radius: 99px; background: var(--panel-2); overflow: hidden; margin: 18px 0 14px; }
.progress i { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 99px; transition: width 0.25s; }
.globe { position: relative; width: 96px; height: 96px; margin: 0 auto; border-radius: 50%; border: 2px solid var(--accent); overflow: hidden; }
.globe i { position: absolute; inset: 0; border: 2px solid rgba(255, 211, 78, 0.55); border-radius: 50%; animation: spin 2.4s linear infinite; }
.globe i:nth-child(2) { animation-delay: -0.8s; }
.globe i:nth-child(3) { animation-delay: -1.6s; }
@keyframes spin { from { transform: scaleX(1); } 50% { transform: scaleX(0.05); } to { transform: scaleX(1); } }
.row { display: flex; gap: 10px; justify-content: center; margin-top: 14px; }
.row.end { justify-content: space-between; align-items: center; }

/* ---------- viewer ---------- */
.view { position: fixed; inset: 0; background: #000; }
.view.active { display: block; }
#viewCanvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; display: block; }
.view-top { position: absolute; left: 0; right: 0; top: 0; padding: calc(var(--safe-t) + 10px) 14px 10px; display: flex; align-items: center; justify-content: space-between; gap: 10px; pointer-events: none; }
.view-top > * { pointer-events: auto; }
.view-info { background: rgba(20,22,26,0.65); padding: 6px 12px; border-radius: 999px; font-size: 13px; text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.view-bottom { position: absolute; left: 0; right: 0; bottom: 0; padding: 14px 12px calc(var(--safe-b) + 16px); display: flex; justify-content: center; gap: 8px; pointer-events: none; }
.tool { pointer-events: auto; border: 0; border-radius: 14px; background: rgba(20,22,26,0.72); min-width: 72px; padding: 9px 12px 7px; display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: 12.5px; backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
.tool svg { width: 22px; height: 22px; }
.tool[aria-pressed="true"] { background: #3a3215; color: var(--accent); }
.primary-tool { background: var(--accent); color: var(--accent-ink); font-weight: 650; }
.menu { position: absolute; right: 14px; top: calc(var(--safe-t) + 62px); background: var(--panel); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; min-width: 230px; box-shadow: 0 12px 40px rgba(0,0,0,0.5); }
.menu button { display: block; width: 100%; text-align: left; background: none; border: 0; padding: 13px 16px; border-bottom: 1px solid var(--line); }
.menu button:last-child { border-bottom: 0; }
.menu .danger { color: var(--warn); }
.details { position: absolute; left: 12px; right: 12px; top: calc(var(--safe-t) + 62px); max-height: 60dvh; overflow: auto; background: rgba(15,16,19,0.92); border: 1px solid var(--line); border-radius: 12px; padding: 12px; font-size: 11.5px; line-height: 1.4; white-space: pre-wrap; margin: 0; }

/* ---------- settings ---------- */
.sheet { border: 1px solid var(--line); background: var(--panel); color: var(--text); border-radius: 18px; padding: 0; width: min(520px, calc(100% - 24px)); }
.sheet::backdrop { background: rgba(0,0,0,0.6); }
.sheet form { padding: 18px 18px 16px; }
.sheet h2 { margin: 0 0 14px; font-size: 19px; }
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-weight: 600; font-size: 14px; margin-bottom: 6px; }
.field small { display: block; margin-top: 4px; font-size: 12.5px; }
select, input[type="number"] { width: 100%; background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.inline { display: flex; align-items: center; gap: 10px; }
.inline input { max-width: 140px; }
.check { display: flex; align-items: center; gap: 10px; margin: 10px 0; font-size: 15px; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }
.small-btn { width: auto; padding: 10px 22px; font-size: 15px; }

.toast { position: fixed; left: 50%; bottom: calc(var(--safe-b) + 96px); transform: translateX(-50%); background: #22252c; border: 1px solid var(--line); padding: 10px 16px; border-radius: 12px; font-size: 14px; z-index: 20; max-width: calc(100% - 32px); text-align: center; }

@media (min-width: 720px) {
  .gallery { grid-template-columns: repeat(3, 1fr); }
  #home { max-width: 760px; }
}
