/* The camera's shared look, used by the Filter Lab and by the camera page inside the app.
   No colour is written here: the token variables (--sugar-light-bg and the rest) are set at
   load by camera/engine/tokens.js from src/theme/tokens.json. Type is Pri's set B (A13, A14). */
:root {
  --display: "Italiana", "Didot", serif;
  --title: "Jost", "Futura", system-ui, sans-serif;
  --ui: "Manrope", system-ui, -apple-system, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SF Mono", monospace;
  --touch: 48px;
  /* Inside the app's iframe or WebView the page cannot see the phone's notch and home bar, so
     the app passes them in (host.js sets these); env() covers the page opened on its own. */
  --top-inset: max(env(safe-area-inset-top), var(--safe-top, 0px));
  --bottom-inset: max(env(safe-area-inset-bottom), var(--safe-bottom, 0px));
}

/* The room in use: light Sugar by default, dark Sugar by system or toggle, Spice for After Dark. */
:root {
  --bg: var(--sugar-light-bg); --surface: var(--sugar-light-surface); --surface-2: var(--sugar-light-surface-2);
  --ink: var(--sugar-light-ink); --muted: var(--sugar-light-muted); --primary: var(--sugar-light-primary);
  --on-primary: var(--sugar-light-on-primary); --primary-soft: var(--sugar-light-primary-soft);
  --lilac: var(--sugar-light-accent-lilac); --accent: var(--sugar-light-accent-champagne);
  --jelly: var(--sugar-light-jelly); --warn: var(--sugar-light-warn); --line: var(--sugar-light-line);
  --rim: color-mix(in srgb, var(--sugar-light-on-primary) 70%, transparent);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: var(--sugar-dark-bg); --surface: var(--sugar-dark-surface); --surface-2: var(--sugar-dark-surface-2);
    --ink: var(--sugar-dark-ink); --muted: var(--sugar-dark-muted); --primary: var(--sugar-dark-primary);
    --on-primary: var(--sugar-dark-on-primary); --primary-soft: var(--sugar-dark-primary-soft);
    --lilac: var(--sugar-dark-accent-lilac); --accent: var(--sugar-dark-accent-champagne);
    --jelly: var(--sugar-dark-jelly); --warn: var(--sugar-dark-warn); --line: var(--sugar-dark-line);
    --rim: color-mix(in srgb, var(--sugar-dark-ink) 14%, transparent);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: var(--sugar-dark-bg); --surface: var(--sugar-dark-surface); --surface-2: var(--sugar-dark-surface-2);
  --ink: var(--sugar-dark-ink); --muted: var(--sugar-dark-muted); --primary: var(--sugar-dark-primary);
  --on-primary: var(--sugar-dark-on-primary); --primary-soft: var(--sugar-dark-primary-soft);
  --lilac: var(--sugar-dark-accent-lilac); --accent: var(--sugar-dark-accent-champagne);
  --jelly: var(--sugar-dark-jelly); --warn: var(--sugar-dark-warn); --line: var(--sugar-dark-line);
  --rim: color-mix(in srgb, var(--sugar-dark-ink) 14%, transparent);
  color-scheme: dark;
}
:root[data-room="spice"] {
  --bg: var(--spice-bg); --surface: var(--spice-surface); --surface-2: var(--spice-surface-2);
  --ink: var(--spice-ink); --muted: var(--spice-muted); --primary: var(--spice-primary);
  --on-primary: var(--spice-on-primary); --primary-soft: var(--spice-primary-soft);
  --lilac: var(--spice-accent-lilac); --accent: var(--spice-accent-champagne);
  --jelly: var(--spice-jelly); --warn: var(--spice-warn); --line: var(--spice-line);
  --rim: color-mix(in srgb, var(--spice-accent-champagne) 22%, transparent);
  color-scheme: dark;
}
/* Hidden until tokens.js has set the colours, so the page never flashes unstyled. */
:root:not([data-tokens]) body { visibility: hidden; }

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); }
body { font: 400 16px/1.45 var(--ui); -webkit-font-smoothing: antialiased; overflow: hidden; }
button { font: inherit; color: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; }
button:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }
svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
svg .fill { fill: currentColor; stroke: none; }

.view { position: absolute; inset: 0; width: 100%; height: 100%; display: block; background: var(--bg); }

/* Liquid glass: mostly solid so text keeps its contrast over any camera picture. */
.glass {
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  -webkit-backdrop-filter: blur(18px) saturate(1.3);
  backdrop-filter: blur(18px) saturate(1.3);
  border: 1px solid color-mix(in srgb, var(--line) 85%, transparent);
  box-shadow: inset 0 1px 0 var(--rim);
}

.eyebrow, .readout { font: 500 11px/1.2 var(--mono); letter-spacing: 0.1em; text-transform: uppercase; font-variant-numeric: tabular-nums; color: var(--muted); margin: 0; }
.display { font-family: var(--display); font-weight: 400; margin: 0; }
/* Italiana has no italic, so the turned word is set apart by colour, never a faked slant. */
.display em, .title em { font-style: normal; color: var(--primary); }
.fine { font-size: 13px; color: var(--muted); margin: 0; }

.topbar {
  position: absolute; top: 0; left: 0; right: 0; z-index: 2;
  display: flex; align-items: center; gap: 8px;
  padding: calc(var(--top-inset) + 10px) 16px 0;
}
.icon-btn { width: var(--touch); height: var(--touch); border-radius: 50%; display: grid; place-items: center; padding: 0; }

.hint {
  /* Just above the tray: hints never cover the head, where ears and halos are. */
  position: absolute; z-index: 2; left: 50%; bottom: calc(var(--tray-h, 240px) + 12px); --x: -50%;
  transform: translateX(-50%); margin: 0; padding: 10px 18px; border-radius: 999px;
  font-size: 15px; font-weight: 600; white-space: nowrap; animation: rise 0.35s ease-out;
}

.btn { min-height: 52px; padding: 0 22px; border-radius: 999px; border: 1px solid transparent; font: 500 17px/1 var(--title); letter-spacing: 0.01em; }
.btn-primary {
  background: linear-gradient(180deg, color-mix(in srgb, var(--primary), var(--on-primary) 14%), var(--primary));
  color: var(--on-primary); box-shadow: inset 0 1px 0 color-mix(in srgb, var(--on-primary) 35%, transparent), 0 6px 18px -8px var(--primary);
}
.btn-quiet { background: var(--surface-2); border-color: var(--line); color: var(--ink); }
.btn:active, .chip:active, .shutter:active, .round-btn:active { transform: scale(0.96); }
.btn[disabled] { opacity: 0.6; cursor: default; }

/* Bottom tray: chips, then the shutter row. */
.tray {
  position: absolute; z-index: 2; left: 0; right: 0; bottom: 0;
  padding: 14px 0 calc(var(--bottom-inset) + 12px); border-radius: 28px 28px 0 0;
  border-left: 0; border-right: 0; border-bottom: 0; display: grid; gap: 12px;
}
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 16px; scroll-snap-type: x proximity; scrollbar-width: none; align-items: center; }
.chips::-webkit-scrollbar { display: none; }
.group-label { flex: none; writing-mode: vertical-rl; transform: rotate(180deg); font: 500 10px/1 var(--mono); letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); }
.group-label.spice { margin-left: 8px; }
.chip {
  flex: none; scroll-snap-align: center; min-height: var(--touch); padding: 0 18px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface-2); color: var(--ink); font: 500 16px/1 var(--title);
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
}
.chip[aria-pressed="true"] {
  background: linear-gradient(180deg, color-mix(in srgb, var(--primary), var(--on-primary) 16%), var(--primary));
  color: var(--on-primary); border-color: transparent; box-shadow: inset 0 1px 0 color-mix(in srgb, var(--on-primary) 30%, transparent);
}
/* After Dark chips always wear the Spice room, so they read as their own place even in Sugar. */
.chip.spice { background: var(--spice-surface-2); color: var(--spice-ink); border-color: color-mix(in srgb, var(--spice-primary) 45%, var(--spice-line)); }
.chip.spice[aria-pressed="true"] { background: linear-gradient(180deg, color-mix(in srgb, var(--spice-primary), var(--spice-on-primary) 12%), var(--spice-primary)); color: var(--spice-on-primary); }

.actions { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; padding: 0 24px; }
.round-btn {
  justify-self: center; width: 64px; min-height: 64px; padding: 6px 0 4px; border: 0; background: transparent;
  display: grid; justify-items: center; gap: 2px; font: 500 11px/1.2 var(--mono); letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink);
}
.round-btn svg { width: 40px; height: 40px; padding: 8px; border-radius: 50%; background: var(--surface-2); border: 1px solid var(--line); }
/* The source button offers whichever source is not in use: a photo while live, the camera on a photo. */
.icon-camera, [data-source="photo"] .icon-photo { display: none; }
[data-source="photo"] .icon-camera { display: block; }
/* The shutter: a silver-lilac chrome ring around a glossy jelly button. */
.shutter {
  width: 78px; height: 78px; border-radius: 50%; padding: 5px; border: 0;
  background: linear-gradient(160deg, var(--sugar-light-surface), var(--sugar-dark-accent-lilac) 45%, var(--sugar-light-on-primary) 55%, var(--sugar-light-accent-lilac));
  box-shadow: 0 8px 22px -10px var(--sugar-light-accent-lilac);
}
.shutter span {
  display: block; width: 100%; height: 100%; border-radius: 50%;
  background: radial-gradient(circle at 36% 28%, var(--sugar-light-on-primary) 0 7%, color-mix(in srgb, var(--jelly), var(--sugar-light-on-primary) 35%) 18%, var(--jelly) 52%, var(--sugar-light-primary) 100%);
  box-shadow: inset 0 -6px 12px -4px color-mix(in srgb, var(--sugar-light-on-primary) 55%, transparent);
}
:root[data-room="spice"] .shutter span { background: radial-gradient(circle at 36% 28%, var(--spice-ink) 0 6%, var(--spice-primary) 40%, var(--spice-surface-2) 100%); }

.flash { position: absolute; inset: 0; z-index: 3; background: var(--sugar-light-surface); opacity: 0; pointer-events: none; }
.flash.on { animation: flash 0.35s ease-out; }

/* Sheets: the capture preview, and the lab's picks. */
.sheet {
  width: 100%; max-width: 520px; max-height: 92dvh; margin: auto auto 0; padding: 20px 20px calc(var(--bottom-inset) + 18px);
  border: 1px solid var(--line); border-bottom: 0; border-radius: 28px 28px 0 0; background: var(--surface); color: var(--ink);
  display: none; gap: 14px; animation: rise 0.3s ease-out;
}
.sheet[open] { display: grid; }
.sheet::backdrop { background: color-mix(in srgb, var(--bg) 72%, transparent); -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px); }
.sheet .display { font-size: 34px; }
.preview-img { width: 100%; max-height: 62dvh; object-fit: contain; border-radius: 18px; background: var(--surface-2); }
.sheet-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

@keyframes rise { from { opacity: 0; transform: translate(var(--x, 0), 12px); } }
@keyframes flash { from { opacity: 0.85; } to { opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
