:root {
  --bg: #0e0f12;
  --surface: #17191e;
  --surface-2: #20232a;
  --line: #2a2e36;
  --text: #f4f4f6;
  --muted: #9a9fab;
  --accent: #f3c76b;      /* warm gold: dinner, evening light */
  --accent-ink: #1a1405;
  --danger: #ff6b6b;
  --radius: 14px;
  --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; background: var(--bg); color: var(--text); }
body {
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 16px; line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
h1, h2, h3 { margin: 0; letter-spacing: -0.02em; }
.muted { color: var(--muted); }
[hidden] { display: none !important; }

/* ---------- screens ---------- */
.screen { display: none; min-height: 100dvh; }
.screen.active { display: block; animation: fade .25s ease; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 20px; border-radius: 999px;
  font-weight: 600; transition: transform .08s ease, opacity .15s;
}
.btn:active { transform: scale(.97); }
.btn-lg { min-height: 56px; font-size: 17px; }
.btn-block { width: 100%; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-secondary { background: var(--surface-2); color: var(--text); }
.btn-ghost { color: var(--text); opacity: .85; }
.btn:disabled { opacity: .5; }
.link { color: var(--accent); font-weight: 600; padding: 4px; }
.icon-btn { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 50%; }
.icon-btn:active { background: var(--surface-2); }
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn-spacer { width: 44px; }
.chip {
  min-height: 36px; padding: 0 16px; border-radius: 999px;
  background: rgba(255,255,255,.12); font-weight: 600; font-size: 14px;
}
.chip.on { background: var(--accent); color: var(--accent-ink); }

/* ---------- home ---------- */
#home { position: relative; overflow: hidden; }
.home-bg {
  position: absolute; inset: 0; display: grid;
  grid-template-columns: repeat(3, 1fr); gap: 3px; opacity: .35;
  filter: saturate(.9);
}
.home-bg img { width: 100%; height: 100%; object-fit: cover; aspect-ratio: 3/4; }
.home-bg::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(180deg, rgba(14,15,18,.55) 0%, rgba(14,15,18,.85) 45%, var(--bg) 75%);
}
.home-inner {
  position: relative; z-index: 1; min-height: 100dvh;
  display: flex; flex-direction: column; justify-content: space-between;
  padding: calc(24px + var(--safe-t)) 24px calc(28px + var(--safe-b));
  max-width: 520px; margin: 0 auto;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; letter-spacing: .04em; text-transform: lowercase; }
.brand-mark { color: var(--accent); }
.home-copy { margin-top: auto; padding-bottom: 32px; }
.home-copy h1 { font-size: clamp(34px, 9vw, 44px); line-height: 1.08; font-weight: 700; }
.lead { color: #c9ccd4; font-size: 17px; margin: 14px 0 0; }
.home-actions { display: flex; flex-direction: column; gap: 10px; }
.fineprint { text-align: center; color: var(--muted); font-size: 13px; margin: 6px 0 0; }

/* ---------- loading ---------- */
.center-stack {
  min-height: 100dvh; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; padding: 24px; text-align: center;
}
.scan-ring {
  width: 120px; height: 120px; border-radius: 50%; position: relative;
  border: 2px solid var(--line); margin-bottom: 12px;
}
.scan-ring::before {
  content: ""; position: absolute; inset: -2px; border-radius: 50%;
  border: 2px solid transparent; border-top-color: var(--accent);
  animation: spin 1s linear infinite;
}
.scan-face {
  position: absolute; inset: 28px; border-radius: 50%;
  background: radial-gradient(circle at 50% 40%, var(--surface-2) 0 30%, transparent 31%),
              radial-gradient(ellipse at 50% 110%, var(--surface-2) 0 45%, transparent 46%);
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(6px + var(--safe-t)) 6px 6px;
  background: rgba(14,15,18,.85); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
}
.topbar-title { font-weight: 600; }

/* ---------- results ---------- */
#results { padding-bottom: calc(96px + var(--safe-b)); }
.results-head { padding: 8px 20px 12px; }
.results-head h2 { font-size: 28px; font-weight: 700; }
.results-head p { margin: 4px 0 0; }
.banner {
  display: flex; align-items: center; gap: 10px; margin: 0 16px 12px;
  padding: 10px 14px; border-radius: var(--radius); background: var(--surface); font-size: 14px;
}
.banner span:nth-child(2) { flex: 1; }
.dot-live { width: 8px; height: 8px; border-radius: 50%; background: #5bd68b; box-shadow: 0 0 0 4px rgba(91,214,139,.18); }

.group-head {
  position: sticky; top: calc(56px + var(--safe-t)); z-index: 3;
  padding: 10px 20px 8px; font-size: 13px; font-weight: 600; letter-spacing: .02em;
  color: var(--muted); background: var(--bg);
}
.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 2px; }
@media (min-width: 700px) { .grid { grid-template-columns: repeat(5, 1fr); } }
.tile { position: relative; aspect-ratio: 1; background: var(--surface); overflow: hidden; }
.tile img { width: 100%; height: 100%; object-fit: cover; display: block; opacity: 0; transition: opacity .25s; }
.tile img.loaded { opacity: 1; }
.tile .badge-new {
  position: absolute; top: 6px; left: 6px; font-size: 11px; font-weight: 700;
  background: var(--accent); color: var(--accent-ink); padding: 2px 7px; border-radius: 999px;
}
.tile .check {
  position: absolute; top: 6px; right: 6px; width: 24px; height: 24px; border-radius: 50%;
  border: 2px solid #fff; background: rgba(0,0,0,.25); display: none;
}
.selecting .tile .check { display: block; }
.tile.selected .check { background: var(--accent); border-color: var(--accent); }
.tile.selected img { transform: scale(.9); border-radius: 6px; transition: transform .15s; }
.tile.selected .check::after {
  content: ""; position: absolute; left: 6px; top: 2px; width: 6px; height: 11px;
  border: solid var(--accent-ink); border-width: 0 2px 2px 0; transform: rotate(45deg);
}

.possible { padding: 20px 16px 0; }
.possible #possibleGrid { margin: 14px -16px 0; }

/* justified rows */
.jgrid { display: flex; flex-direction: column; gap: 3px; padding: 0 3px; }
.jrow { display: flex; gap: 3px; }
.jrow .tile { aspect-ratio: auto; height: 100%; flex: none; border-radius: 4px; }
.jrow .tile img { object-fit: cover; }
.tile { transition: opacity .2s; }
.tile:active { opacity: .8; }
.empty { padding: 40px 28px; text-align: center; }
.empty p { margin: 0 0 6px; }

.bottom-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  display: flex; gap: 10px; padding: 12px 16px calc(12px + var(--safe-b));
  background: linear-gradient(180deg, rgba(14,15,18,0) 0%, var(--bg) 35%);
}
.bottom-bar .btn { flex: 1; }
.bottom-bar .btn-primary { flex: 0 0 auto; }

/* ---------- browse ---------- */
#browse { padding-bottom: calc(24px + var(--safe-b)); }
.loader-row { display: flex; justify-content: center; padding: 24px; }
.spinner {
  width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--line);
  border-top-color: var(--accent); animation: spin .8s linear infinite;
}

/* ---------- viewer ---------- */
.viewer {
  position: fixed; inset: 0; z-index: 20; background: #000;
  display: flex; flex-direction: column; animation: fade .2s ease;
}
.viewer-top {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(6px + var(--safe-t)) 6px 6px; color: #fff; font-size: 14px;
}
.icon-btn.light:active { background: rgba(255,255,255,.12); }
.viewer-stage { flex: 1; overflow: hidden; position: relative; touch-action: pan-y; }
.viewer-track { display: flex; height: 100%; will-change: transform; }
.viewer-slide { flex: 0 0 100%; height: 100%; display: grid; place-items: center; }
.viewer-slide img { max-width: 100%; max-height: 100%; object-fit: contain; user-select: none; -webkit-user-drag: none; }
.viewer-bottom { padding: 12px 16px calc(14px + var(--safe-b)); display: flex; flex-direction: column; gap: 12px; }
.feedback { display: flex; align-items: center; justify-content: center; gap: 10px; font-size: 14px; }

/* ---------- sheets ---------- */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 30; background: rgba(0,0,0,.55);
  display: flex; align-items: flex-end; animation: fade .2s ease;
}
.sheet {
  width: 100%; max-width: 520px; margin: 0 auto;
  background: var(--surface); border-radius: 22px 22px 0 0;
  padding: 10px 20px calc(18px + var(--safe-b));
  animation: up .28s cubic-bezier(.2,.8,.2,1);
}
@keyframes up { from { transform: translateY(100%); } to { transform: none; } }
.sheet-handle { width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: 0 auto 16px; }
.sheet h3 { font-size: 22px; margin-bottom: 12px; }
.consent-list { margin: 0 0 18px; padding-left: 20px; color: #d3d6dd; }
.consent-list li { margin-bottom: 8px; }
.tips { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 18px; }
.tip {
  background: var(--surface-2); border-radius: 12px; padding: 12px 8px;
  text-align: center; font-size: 13px; color: #d3d6dd;
}
.tip span { display: block; font-size: 20px; color: var(--accent); margin-bottom: 4px; }
.sheet .btn + .btn { margin-top: 6px; }
.sheet-item { display: block; width: 100%; text-align: left; padding: 16px 4px; border-bottom: 1px solid var(--line); font-size: 16px; }
.sheet-item.danger { color: var(--danger); }

/* ---------- select bar ---------- */
.select-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 12px 16px calc(12px + var(--safe-b)); background: var(--surface);
  border-top: 1px solid var(--line);
}

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(96px + var(--safe-b)); transform: translateX(-50%);
  z-index: 40; background: #fff; color: #111; font-weight: 600; font-size: 14px;
  padding: 10px 16px; border-radius: 999px; box-shadow: 0 6px 24px rgba(0,0,0,.35);
  max-width: calc(100% - 32px); text-align: center; animation: fade .2s ease;
}

/* ---------- home buttons ---------- */
.btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.btn-row .btn { min-height: 52px; padding: 0 12px; white-space: nowrap; }
.btn-row .btn svg { width: 18px; height: 18px; }

/* ---------- segmented filter ---------- */
.sticky-head { position: sticky; top: 0; z-index: 5; background: rgba(14,15,18,.9);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); padding-bottom: 8px; }
.sticky-head .topbar { position: static; background: transparent; backdrop-filter: none; -webkit-backdrop-filter: none; }
.segmented { display: flex; gap: 2px; margin: 0 16px; padding: 3px; border-radius: 12px; background: var(--surface); }
#resultsSeg { margin: 0 16px 12px; }
.segmented { display: grid; grid-template-columns: 1fr 1.45fr 1.1fr .7fr; }
#resultsSeg { grid-template-columns: 1fr 1.45fr 1.1fr; }
.segmented button { min-width: 0; min-height: 36px; padding: 0 4px; border-radius: 9px; font-size: 14px; font-weight: 600;
  color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  display: inline-flex; align-items: center; justify-content: center; gap: 4px; transition: background .2s, color .2s; }
@media (max-width: 380px) { .segmented button { font-size: 13px; } .seg-count { display: none; } }
.segmented button.on { background: var(--surface-2); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.35); }
.seg-count { font-weight: 500; opacity: .6; font-size: 12px; }
#browse .group-head { top: calc(104px + var(--safe-t)); }

/* ---------- time sections ---------- */
.moment-head { display: flex; align-items: baseline; justify-content: space-between;
  padding: 14px 20px 8px; font-size: 15px; font-weight: 600; }
.moment-head .count { font-size: 12px; color: var(--muted); font-weight: 500; }
.group-head + .moment-head { padding-top: 4px; }

/* ---------- favourites / credits ---------- */
.badge-fav { position: absolute; right: 6px; bottom: 5px; font-size: 14px; color: #ff5d7a;
  text-shadow: 0 1px 3px rgba(0,0,0,.6); }
#viewerFav.on svg { fill: #ff5d7a; stroke: #ff5d7a; }
.viewer-credit { text-align: center; color: #c9ccd4; font-size: 13px; min-height: 18px; }

/* ---------- floating add button ---------- */
.fab { position: fixed; right: 16px; bottom: calc(18px + var(--safe-b)); z-index: 7;
  display: inline-flex; align-items: center; gap: 6px; min-height: 48px; padding: 0 18px;
  border-radius: 999px; background: var(--accent); color: var(--accent-ink); font-weight: 700;
  box-shadow: 0 8px 24px rgba(0,0,0,.45); }
.selecting .fab { display: none; }

/* ---------- upload sheet ---------- */
.sheet-text { color: #d3d6dd; margin: 0 0 16px; }
.field { display: block; margin-bottom: 14px; }
.field span { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.field em { font-style: normal; color: var(--muted); font-weight: 500; }
.field input { width: 100%; min-height: 48px; padding: 0 14px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface-2); color: var(--text); font: inherit; font-size: 16px; }
.field input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.upload-progress { margin: 4px 0 16px; }
.upload-progress .bar { height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
.upload-progress .bar span { display: block; height: 100%; width: 0; background: var(--accent); transition: width .3s; }
.upload-progress p { margin: 8px 0 0; font-size: 14px; color: #d3d6dd; }
