:root {
  --bg: #0a0a0c;
  --bg-elev: #141417;
  --bg-elev-2: #1c1c20;
  --line: #2a2a30;
  --text: #f4f4f6;
  --text-dim: #9a9aa4;
  --accent: #f2c9a0;
  --accent-ink: #241a12;
  --radius: 16px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  padding-top: var(--safe-t);
}

/* ---------------- top bar ---------------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px 6px;
  flex: 0 0 auto;
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-weight: 650;
  letter-spacing: -0.02em;
  font-size: 17px;
}
.brand .dot { color: var(--accent); }
.brand small {
  font-weight: 500;
  font-size: 11px;
  color: var(--text-dim);
  letter-spacing: 0.02em;
  text-transform: lowercase;
}

.topbar .spacer { flex: 1; }

.icon-btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--bg-elev);
  color: var(--text);
  border-radius: 12px;
  height: 36px;
  padding: 0 12px;
  font-size: 13px;
  font-weight: 560;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}
.icon-btn:active { transform: scale(0.97); }
.icon-btn svg { width: 16px; height: 16px; display: block; }

.icon-btn.primary {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: transparent;
}
.icon-btn.subtle { background: transparent; }

/* ---------------- stage ---------------- */
.stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  place-items: center;
  padding: 6px 10px;
  overflow: hidden;
}

#view {
  max-width: 100%;
  max-height: 100%;
  display: block;
  border-radius: 6px;
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.55);
  touch-action: none;
}
#view.hidden { display: none; }

.empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 6px;
  text-align: center;
  padding: 24px;
}
.empty.hidden { display: none; }
.empty h1 {
  font-size: 22px;
  margin: 0 0 4px;
  letter-spacing: -0.03em;
  font-weight: 620;
}
.empty p {
  margin: 0;
  color: var(--text-dim);
  font-size: 14px;
  max-width: 30ch;
  line-height: 1.5;
}
.empty .cta {
  display: flex;
  gap: 12px;
  margin-top: 22px;
}
.cta button {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--bg-elev);
  color: var(--text);
  border-radius: 999px;
  padding: 13px 20px;
  font-size: 14px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}
.cta button.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.cta button svg { width: 18px; height: 18px; }

.badge {
  position: absolute;
  left: 50%;
  top: 14px;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.62);
  backdrop-filter: blur(10px);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
  padding: 5px 12px;
  border-radius: 999px;
  opacity: 0;
  transition: opacity 0.18s;
  pointer-events: none;
}
.badge.show { opacity: 1; }

/* ---------------- bottom sheet ---------------- */
.sheet {
  flex: 0 0 auto;
  background: linear-gradient(to top, var(--bg) 70%, rgba(10, 10, 12, 0.92));
  padding-bottom: calc(8px + var(--safe-b));
  border-top: 1px solid rgba(255, 255, 255, 0.04);
}

.presets {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding: 12px 14px 10px;
  scrollbar-width: none;
  scroll-snap-type: x proximity;
}
.presets::-webkit-scrollbar { display: none; }
.presets.disabled { opacity: 0.35; pointer-events: none; }

.preset {
  flex: 0 0 auto;
  width: 66px;
  background: none;
  border: 0;
  padding: 0;
  color: var(--text-dim);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  scroll-snap-align: center;
}
.preset canvas {
  width: 66px;
  height: 66px;
  border-radius: 12px;
  object-fit: cover;
  background: var(--bg-elev);
  border: 2px solid transparent;
  transition: border-color 0.15s, transform 0.12s;
  display: block;
}
.preset span {
  font-size: 10.5px;
  font-weight: 560;
  letter-spacing: 0.01em;
  white-space: nowrap;
  max-width: 70px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.preset.active canvas { border-color: var(--accent); transform: scale(1.04); }
.preset.active span { color: var(--text); }

.slider-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 2px 18px 8px;
}
.slider-row label {
  font-size: 11.5px;
  color: var(--text-dim);
  font-weight: 560;
  min-width: 58px;
  letter-spacing: 0.01em;
}
.slider-row output {
  font-size: 11.5px;
  color: var(--text-dim);
  min-width: 38px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  flex: 1;
  height: 26px;
  background: transparent;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 3px;
  background: var(--line);
  border-radius: 3px;
}
input[type="range"]::-moz-range-track {
  height: 3px;
  background: var(--line);
  border-radius: 3px;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--text);
  margin-top: -6.5px;
  border: none;
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.6);
}
input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--text);
  border: none;
}

.fine {
  border-top: 1px solid rgba(255, 255, 255, 0.05);
}
.fine summary {
  list-style: none;
  padding: 11px 18px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-dim);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
}
.fine summary::-webkit-details-marker { display: none; }
.fine summary::before {
  content: "";
  width: 6px;
  height: 6px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(-45deg);
  transition: transform 0.18s;
  margin-top: -2px;
}
.fine[open] summary::before { transform: rotate(45deg); margin-top: 2px; }
.fine .body { padding-bottom: 6px; }

.toolbar {
  display: flex;
  gap: 8px;
  padding: 0 14px 8px;
}
.toolbar button { flex: 1; justify-content: center; }

/* ---------------- camera overlay ---------------- */
.camera {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: #000;
  display: flex;
  flex-direction: column;
}
.camera.hidden { display: none; }
.camera video {
  flex: 1;
  width: 100%;
  height: 100%;
  object-fit: cover;
  min-height: 0;
}
.camera .cam-bar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(20px + var(--safe-b));
  display: flex;
  align-items: center;
  justify-content: space-around;
  padding: 0 24px;
}
.shutter {
  width: 68px;
  height: 68px;
  border-radius: 50%;
  border: 4px solid rgba(255, 255, 255, 0.85);
  background: rgba(255, 255, 255, 0.22);
  cursor: pointer;
}
.shutter:active { background: rgba(255, 255, 255, 0.6); }
.cam-close, .cam-flip {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.14);
  border: 0;
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
}
.cam-close svg, .cam-flip svg { width: 20px; height: 20px; }

/* ---------------- toast ---------------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + var(--safe-b));
  transform: translate(-50%, 20px);
  background: #fff;
  color: #111;
  font-size: 13px;
  font-weight: 600;
  padding: 10px 18px;
  border-radius: 999px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 100;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.busy {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(3px);
  display: grid;
  place-items: center;
  font-size: 13px;
  color: var(--text-dim);
  letter-spacing: 0.03em;
}
.busy.hidden { display: none; }

/* ---------------- install banner ---------------- */
.install {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(12px + var(--safe-b));
  z-index: 60;
  max-width: 480px;
  margin: 0 auto;
  background: rgba(28, 28, 32, 0.94);
  backdrop-filter: blur(14px);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 14px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.6);
  display: flex;
  flex-direction: column;
  gap: 12px;
  transform: translateY(0);
  transition: transform 0.25s ease, opacity 0.25s ease, visibility 0s;
}
.install.hidden {
  opacity: 0;
  transform: translateY(140%);
  pointer-events: none;
  visibility: hidden;
  transition: transform 0.25s ease, opacity 0.25s ease, visibility 0s 0.25s;
}
.install-main {
  display: flex;
  gap: 12px;
  align-items: center;
}
.install-main img {
  border-radius: 10px;
  flex: 0 0 auto;
}
.install-main strong {
  display: block;
  font-size: 14px;
  font-weight: 620;
  letter-spacing: -0.01em;
}
.install-main p {
  margin: 3px 0 0;
  font-size: 12.5px;
  line-height: 1.45;
  color: var(--text-dim);
}
.install-main p b { color: var(--text); font-weight: 600; }
.install-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}
.install-actions .icon-btn { height: 34px; font-size: 12.5px; }

/* ---------------- instruction sheet ---------------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
}
.modal.hidden { display: none; }
.modal-card {
  width: 100%;
  max-width: 520px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-bottom: none;
  border-radius: 22px 22px 0 0;
  padding: 10px 20px calc(20px + var(--safe-b));
  text-align: center;
  animation: sheet-up 0.24s cubic-bezier(0.2, 0.8, 0.2, 1);
}
@keyframes sheet-up {
  from { transform: translateY(24px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
.modal-grab {
  width: 38px;
  height: 4px;
  border-radius: 4px;
  background: #3a3a42;
  margin: 0 auto 16px;
}
.modal-icon {
  border-radius: 13px;
  margin-bottom: 10px;
}
.modal-card h2 {
  font-size: 18px;
  font-weight: 640;
  letter-spacing: -0.02em;
  margin: 0 0 6px;
}
.modal-card > p {
  margin: 0 auto 16px;
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--text-dim);
  max-width: 34ch;
}
.modal-card p b { color: var(--text); font-weight: 600; }

.steps {
  text-align: left;
  margin: 0 0 18px;
  padding: 14px 16px 14px 16px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 14px;
  list-style: none;
  counter-reset: step;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.steps li {
  position: relative;
  padding-left: 30px;
  font-size: 13.5px;
  line-height: 1.45;
  color: var(--text);
  counter-increment: step;
  text-align: left;
}
.steps li::before {
  content: counter(step);
  position: absolute;
  left: 0;
  top: -1px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--bg-elev-2);
  color: var(--text-dim);
  font-size: 11px;
  font-weight: 700;
  display: grid;
  place-items: center;
}
.steps li b { font-weight: 650; }

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
}
.modal-actions .icon-btn { height: 40px; padding: 0 18px; font-size: 13.5px; }

body.sheet-open { overflow: hidden; }

/* Toolbar install button disappears once installed. */
html.installed #btnInstall { display: none; }
@media (display-mode: standalone) {
  #btnInstall { display: none; }
}

@media (min-width: 860px) {
  #app { max-width: 720px; margin: 0 auto; }
}
