/* Camera-first tool: full-bleed viewfinder, controls on frosted basalt glass. */
:root {
  --basalt: #0d1416;
  --glass: rgba(13, 20, 22, 0.58);
  --glass-strong: rgba(13, 20, 22, 0.86);
  --line: rgba(232, 244, 246, 0.16);
  --text: #eef5f4;
  --muted: #a3b4b3;
  --water: #9fdcec;
  --water-ink: #06222b;
  --ok: #7be0b4;
  --warn: #ffc457;
  --danger: #ff8a7a;
  --ui: "IBM Plex Sans KR", "Apple SD Gothic Neo", "Malgun Gothic", system-ui, sans-serif;
  --display: "Black Han Sans", "IBM Plex Sans KR", "Apple SD Gothic Neo", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, Menlo, monospace;
  --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 { height: 100%; margin: 0; }
body {
  background: var(--basalt);
  color: var(--text);
  font: 15px/1.5 var(--ui);
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  word-break: keep-all;
  -webkit-user-select: none;
  user-select: none;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--water); outline-offset: 2px; }

#app { position: fixed; inset: 0; }
#view, #overlay { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#view { touch-action: none; background: #000; }
#overlay { pointer-events: none; }
#cam { position: fixed; width: 1px; height: 1px; opacity: 0; pointer-events: none; left: 0; top: 0; }

/* ---------- top bar ---------- */
.topbar {
  position: absolute; left: 0; right: 0; top: 0;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(var(--safe-t) + 12px) max(16px, var(--safe-r)) 12px max(16px, var(--safe-l));
  pointer-events: none;
}
.topbar > * { pointer-events: auto; }
.pill {
  display: inline-flex; align-items: center; gap: 8px; min-width: 0;
  padding: 7px 14px 7px 11px; border-radius: 999px;
  background: var(--glass); border: 1px solid var(--line);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  font-size: 13px; font-weight: 500; letter-spacing: 0.01em;
}
.pill span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.pill[data-state="ok"] .dot { background: var(--ok); box-shadow: 0 0 0 4px rgba(123, 224, 180, 0.18); }
.pill[data-state="warn"] .dot { background: var(--warn); }
.pill[data-state="idle"] .dot { animation: breathe 1.6s ease-in-out infinite; }
@keyframes breathe { 50% { opacity: 0.3; } }

.icon-btn {
  width: 40px; height: 40px; flex: none; border-radius: 50%;
  display: grid; place-items: center; cursor: pointer;
  background: var(--glass); border: 1px solid var(--line);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
}
.icon-btn svg, .thumb.add svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }

/* ---------- dock ---------- */
.dock {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 14px 0 calc(var(--safe-b) + 14px);
  background: linear-gradient(to top, rgba(8, 12, 13, 0.78), rgba(8, 12, 13, 0));
  display: grid; gap: 12px;
}
body:not(.running) .dock, body:not(.running) .topbar { visibility: hidden; }
.strip {
  display: flex; gap: 10px; overflow-x: auto; scroll-snap-type: x proximity;
  padding: 4px max(16px, var(--safe-r)) 4px max(16px, var(--safe-l));
  scrollbar-width: none;
}
.strip::-webkit-scrollbar { display: none; }
.thumb {
  flex: none; width: 64px; padding: 0; border: 0; background: none; cursor: pointer;
  display: grid; gap: 5px; justify-items: center; scroll-snap-align: center;
}
.thumb canvas, .thumb.add svg {
  width: 64px; height: 64px; border-radius: 14px; display: block;
  border: 2px solid transparent; box-shadow: 0 0 0 1px var(--line);
  transition: transform 160ms ease, border-color 160ms ease;
}
.thumb span { font-size: 11px; color: var(--muted); white-space: nowrap; max-width: 64px; overflow: hidden; text-overflow: ellipsis; }
.thumb[aria-pressed="true"] canvas { border-color: var(--water); transform: translateY(-2px); }
.thumb[aria-pressed="true"] span { color: var(--text); }
.thumb.add svg { padding: 20px; background: var(--glass); }

.controls {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px;
  padding: 0 max(16px, var(--safe-r)) 0 max(16px, var(--safe-l));
}
.seg {
  justify-self: end; flex: none; display: inline-flex; padding: 3px; border-radius: 12px;
  background: var(--glass); border: 1px solid var(--line);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
}
.seg button {
  border: 0; background: none; cursor: pointer; border-radius: 9px;
  padding: 6px 9px; font-size: 12px; font-weight: 600; color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.seg button[aria-pressed="true"] { background: var(--text); color: var(--basalt); }
.shutter {
  width: 68px; height: 68px; border-radius: 50%; cursor: pointer;
  border: 4px solid var(--text); background: rgba(238, 245, 244, 0.22);
  box-shadow: inset 0 0 0 4px rgba(0, 0, 0, 0.35);
  transition: transform 120ms ease;
}
.shutter:active { transform: scale(0.92); }
.hint { justify-self: end; margin: 0; font-size: 11px; line-height: 1.35; color: var(--muted); text-align: right; max-width: 8.5em; text-wrap: balance; }
.hint.hint-left { justify-self: start; text-align: left; }

/* ---------- settings sheet ---------- */
.sheet {
  position: absolute; right: max(12px, var(--safe-r)); top: calc(var(--safe-t) + 62px);
  width: min(340px, calc(100% - 24px)); max-height: calc(100% - var(--safe-t) - 80px); overflow-y: auto;
  padding: 6px 16px 16px; border-radius: 18px;
  background: var(--glass-strong); border: 1px solid var(--line);
  backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; }
.sheet h2 { margin: 0; font-size: 15px; font-weight: 700; }
.sheet-head .icon-btn { background: none; border: 0; }
.row {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 11px 0; border-top: 1px solid var(--line); cursor: pointer;
}
.row span { display: grid; min-width: 0; }
.row b { font-weight: 600; font-size: 14px; }
.row small { color: var(--muted); font-size: 12px; }
.row input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--water); flex: none; }
.row input[type="range"] { width: 110px; accent-color: var(--water); flex: none; }
.ghost {
  width: 100%; margin-top: 8px; padding: 10px; border-radius: 12px; cursor: pointer;
  background: none; border: 1px solid var(--line); font-weight: 600;
}

/* ---------- start ---------- */
.start {
  position: absolute; inset: 0; overflow-y: auto;
  display: grid; align-items: end;
  padding: calc(var(--safe-t) + 24px) max(20px, var(--safe-r)) calc(var(--safe-b) + 28px) max(20px, var(--safe-l));
  background:
    radial-gradient(120% 70% at 50% 0%, rgba(159, 220, 236, 0.16), transparent 60%),
    linear-gradient(180deg, #11201f 0%, var(--basalt) 55%);
}
.start-inner { width: 100%; max-width: 440px; margin: 0 auto; display: grid; gap: 14px; }
.eyebrow { margin: 0; font-size: 12px; letter-spacing: 0.14em; color: var(--water); font-weight: 600; }
.start h1 { margin: 0; font: 64px/1 var(--display); letter-spacing: 0.02em; text-wrap: balance; }
.lede { margin: 0; color: var(--muted); font-size: 16px; max-width: 30em; text-wrap: pretty; }
.actions { display: grid; gap: 10px; margin-top: 10px; }
.primary, .secondary {
  padding: 15px 18px; border-radius: 14px; font-size: 16px; font-weight: 700; cursor: pointer;
}
.primary { background: var(--water); color: var(--water-ink); border: 0; }
.secondary { background: rgba(238, 245, 244, 0.06); border: 1px solid var(--line); }
.link { background: none; border: 0; color: var(--water); padding: 6px; font-weight: 600; cursor: pointer; }
.actions button:disabled { opacity: 0.55; cursor: progress; }
.progress { margin: 0; min-height: 1.4em; font: 12px/1.4 var(--mono); color: var(--muted); }
.error {
  margin: 0; padding: 12px 14px; border-radius: 12px; font-size: 14px;
  background: rgba(255, 138, 122, 0.12); border: 1px solid rgba(255, 138, 122, 0.4); color: #ffd6cf;
}
.tips { margin: 6px 0 0; padding: 14px 0 0 1.1em; border-top: 1px solid var(--line); color: var(--muted); font-size: 13px; display: grid; gap: 4px; }

.toast {
  position: absolute; left: 50%; bottom: calc(var(--safe-b) + 190px); transform: translateX(-50%);
  max-width: calc(100% - 32px); padding: 10px 16px; border-radius: 12px;
  background: var(--glass-strong); border: 1px solid var(--line); font-size: 13px; text-align: center;
}

/* Phone held sideways: controls move to a column on the right so the bottle stays clear. */
@media (orientation: landscape) and (max-height: 540px) {
  .dock {
    left: auto; top: 0; right: 0; bottom: 0; width: calc(170px + var(--safe-r));
    padding: calc(var(--safe-t) + 64px) max(12px, var(--safe-r)) calc(var(--safe-b) + 12px) 12px;
    background: linear-gradient(to left, rgba(8, 12, 13, 0.78), rgba(8, 12, 13, 0));
    grid-template-rows: 1fr auto; align-content: stretch;
  }
  .strip {
    display: grid; grid-template-columns: repeat(2, 64px); justify-content: center; align-content: start;
    overflow-x: hidden; overflow-y: auto; padding: 4px 0;
  }
  .thumb span, .hint { display: none; }
  .controls { grid-template-columns: 1fr; justify-items: center; gap: 10px; padding: 0; }
  .shutter { width: 58px; height: 58px; }
  .sheet { right: calc(max(12px, var(--safe-r)) + 170px); }
  .toast { bottom: calc(var(--safe-b) + 24px); }
}

@media (prefers-reduced-motion: reduce) {
  .pill[data-state="idle"] .dot { animation: none; }
  .thumb canvas, .shutter { transition: none; }
}
