:root {
  --bg: #f7f5f0;
  --surface: #ffffff;
  --text: #1c1917;
  --muted: #78716c;
  --line: #e7e5e4;
  --brand: #0f766e;
  --brand-ink: #ffffff;
  --brand-soft: #ccfbf1;
  --danger: #b91c1c;
  --warn-bg: #fef3c7;
  --warn-ink: #92400e;
  --radius: 14px;
  --shadow: 0 1px 2px rgb(0 0 0 / .06), 0 4px 16px rgb(0 0 0 / .06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c0a09;
    --surface: #1c1917;
    --text: #f5f5f4;
    --muted: #a8a29e;
    --line: #292524;
    --brand: #2dd4bf;
    --brand-ink: #042f2e;
    --brand-soft: #134e4a;
    --danger: #f87171;
    --warn-bg: #422006;
    --warn-ink: #fcd34d;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  padding-bottom: env(safe-area-inset-bottom);
}
button, input, select { font: inherit; color: inherit; }
a { color: var(--brand); }
.hidden { display: none !important; }

/* ---------- layout ---------- */
.wrap { max-width: 1100px; margin: 0 auto; padding: 0 16px; }
.narrow { max-width: 440px; margin: 0 auto; padding: 48px 16px; }
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
}
h1 { font-size: 28px; line-height: 1.2; margin: 0 0 8px; letter-spacing: -.02em; }
h2 { font-size: 20px; margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.stack > * + * { margin-top: 14px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

.logo { font-weight: 800; font-size: 20px; letter-spacing: -.02em; display: flex; align-items: center; gap: 6px; }
.hero-emoji { font-size: 44px; line-height: 1; margin-bottom: 12px; }

/* ---------- forms & buttons ---------- */
label.field { display: block; font-size: 14px; font-weight: 600; }
label.field input {
  display: block; width: 100%; margin-top: 6px;
  padding: 12px 14px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--bg);
}
input:focus-visible, button:focus-visible, select:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px 18px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface); cursor: pointer; font-weight: 600; font-size: 15px;
  text-decoration: none; color: var(--text); white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn.block { width: 100%; }
.btn.sm { padding: 7px 12px; font-size: 14px; }
.btn:disabled { opacity: .55; cursor: default; }
.check { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; }
.check input { margin-top: 3px; width: 18px; height: 18px; accent-color: var(--brand); flex: none; }
.error { color: var(--danger); font-size: 14px; min-height: 1em; }

/* ---------- selfie ---------- */
.selfie-preview {
  width: 160px; height: 160px; border-radius: 50%; margin: 8px auto 0;
  background: var(--bg) center/cover; border: 3px dashed var(--line);
  display: grid; place-items: center; font-size: 54px;
}
.selfie-preview.has { border-style: solid; border-color: var(--brand); font-size: 0; }
.tips { font-size: 14px; color: var(--muted); padding-left: 18px; margin: 0; }

/* ---------- trip header ---------- */
header.top {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
header.top .wrap { display: flex; align-items: center; gap: 10px; padding-top: 10px; padding-bottom: 10px; }
.trip-name { font-weight: 700; font-size: 17px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.tabs { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; padding-bottom: 8px; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  border: 0; background: none; padding: 8px 14px; border-radius: 999px; cursor: pointer;
  font-weight: 600; font-size: 15px; color: var(--muted); white-space: nowrap;
}
.tab[aria-selected="true"] { background: var(--text); color: var(--bg); }
.badge {
  display: inline-block; min-width: 20px; padding: 0 6px; margin-left: 4px; border-radius: 999px;
  background: var(--danger); color: #fff; font-size: 12px; line-height: 20px; text-align: center;
}

.banner {
  margin: 12px 0 0; padding: 10px 14px; border-radius: 12px; font-size: 14px;
  background: var(--brand-soft); display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
}
.banner.warn { background: var(--warn-bg); color: var(--warn-ink); }
.spinner {
  width: 16px; height: 16px; border-radius: 50%; flex: none;
  border: 2px solid currentColor; border-right-color: transparent; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.progress { height: 6px; background: var(--line); border-radius: 99px; overflow: hidden; flex-basis: 100%; }
.progress > div { height: 100%; background: var(--brand); transition: width .2s; }

.section-head { display: flex; align-items: center; gap: 10px; margin: 20px 0 12px; flex-wrap: wrap; }
.section-head h2 { margin: 0; }

/* ---------- photo grid ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 3px; }
@media (min-width: 700px) { .grid { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 6px; } }
.grid button {
  aspect-ratio: 1; border: 0; padding: 0; cursor: pointer; overflow: hidden; border-radius: 4px;
  background: var(--line);
}
.grid img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .2s; }
.grid button:hover img { transform: scale(1.03); }

.empty { text-align: center; padding: 56px 16px; color: var(--muted); }
.empty .big { font-size: 48px; }

/* ---------- people ---------- */
.people { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.person {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 12px; text-align: center; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 6px;
}
.person:hover { border-color: var(--muted); }
.avatar {
  width: 72px; height: 72px; border-radius: 50%; object-fit: cover; background: var(--line);
  display: grid; place-items: center; font-weight: 700; font-size: 26px; color: var(--muted);
}
.avatar.sm { width: 28px; height: 28px; font-size: 13px; }
.person .name { font-weight: 600; overflow-wrap: anywhere; }

/* ---------- who is this ---------- */
.clusters { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.cluster { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.crops { display: flex; gap: 6px; margin-bottom: 10px; }
.crops img { width: 64px; height: 64px; border-radius: 10px; object-fit: cover; background: var(--line); }
.cluster select {
  width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg);
}

/* ---------- FAB & upload ---------- */
.fab {
  position: fixed; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom)); z-index: 30;
  box-shadow: 0 6px 24px rgb(0 0 0 / .25); padding: 15px 22px; font-size: 16px;
}

/* ---------- viewer ---------- */
.viewer {
  position: fixed; inset: 0; z-index: 50; background: #000; color: #fff;
  display: flex; flex-direction: column;
}
.viewer .bar { display: flex; align-items: center; gap: 8px; padding: 10px 12px; padding-top: max(10px, env(safe-area-inset-top)); }
.viewer .stage { flex: 1; position: relative; min-height: 0; display: grid; place-items: center; touch-action: pan-y; }
.viewer .stage img { max-width: 100%; max-height: 100%; object-fit: contain; user-select: none; -webkit-user-drag: none; }
.viewer .nav {
  position: absolute; top: 50%; transform: translateY(-50%); background: rgb(255 255 255 / .12);
  border: 0; color: #fff; width: 44px; height: 44px; border-radius: 50%; font-size: 22px; cursor: pointer;
}
.viewer .nav.prev { left: 12px; } .viewer .nav.next { right: 12px; }
@media (hover: none) { .viewer .nav { display: none; } }
.viewer .info { padding: 10px 12px calc(14px + env(safe-area-inset-bottom)); display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.viewer .btn { background: rgb(255 255 255 / .1); color: #fff; border-color: rgb(255 255 255 / .2); }
.viewer .btn.primary { background: #fff; color: #000; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px 4px 4px; border-radius: 999px;
  background: rgb(255 255 255 / .12); font-size: 14px;
}
.chip button { background: none; border: 0; color: #fca5a5; cursor: pointer; font-size: 13px; padding: 0 0 0 4px; }

/* ---------- menu / dialog ---------- */
dialog {
  border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; max-width: min(420px, calc(100vw - 32px));
  background: var(--surface); color: var(--text); box-shadow: var(--shadow);
}
dialog::backdrop { background: rgb(0 0 0 / .45); }

#toast {
  position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%) translateY(20px); z-index: 60;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: .2s; max-width: calc(100vw - 32px); text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%); }

/* ---------- selfie steps & video ---------- */
.steps { display: flex; gap: 6px; margin-bottom: 16px; }
.steps span { flex: 1; height: 5px; border-radius: 99px; background: var(--line); }
.steps span.done { background: var(--brand); }
.steps span.now { background: var(--text); }
.grid button { position: relative; }
.vbadge {
  position: absolute; left: 6px; bottom: 6px; background: rgb(0 0 0 / .65); color: #fff;
  font-size: 12px; font-weight: 600; padding: 2px 7px; border-radius: 6px; pointer-events: none;
}
.viewer .stage video { max-width: 100%; max-height: 100%; background: #000; }
.viewer button.chip { border: 0; color: #fff; cursor: pointer; font: inherit; font-size: 14px; }

/* ---------- icons ---------- */
.icon { width: 1.15em; height: 1.15em; flex: none; vertical-align: -0.2em; }
.btn .icon { width: 18px; height: 18px; }
.logo .icon { width: 30px; height: 30px; padding: 6px; border-radius: 9px; background: var(--brand); color: var(--brand-ink); box-sizing: border-box; }
.big .icon, .hero-icon .icon { width: 44px; height: 44px; stroke-width: 1.6; color: var(--muted); }
.hero-icon { margin-bottom: 12px; }
.hero-icon .icon { color: var(--brand); width: 48px; height: 48px; }
.banner > .icon { width: 20px; height: 20px; }
.vbadge .icon { width: 11px; height: 11px; vertical-align: -1px; }
.viewer .nav { display: grid; place-items: center; }
.viewer .nav .icon { width: 24px; height: 24px; }

/* ---------- selfie head animation ---------- */
.selfie-preview svg { width: 82%; height: 82%; }
.selfie-preview.has svg { display: none; }
.head-shape { fill: var(--surface); stroke: var(--text); stroke-width: 3; }
.head-eye { fill: var(--text); }
.head-line { fill: none; stroke: var(--text); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.head-brow { stroke-width: 2.5; }
.head-arrow { fill: none; stroke: var(--brand); stroke-width: 3.5; stroke-linecap: round; stroke-linejoin: round; animation: head-arrow 2.6s ease-in-out infinite; }
.head-face { animation: head-front 2.6s ease-in-out infinite; transform-box: view-box; transform-origin: 60px 62px; }
.head-left .head-face { animation-name: head-left; }
.head-right .head-face { animation-name: head-right; }
.head-left .head-shape { animation: head-shape-left 2.6s ease-in-out infinite; transform-origin: 60px 62px; }
.head-right .head-shape { animation: head-shape-right 2.6s ease-in-out infinite; transform-origin: 60px 62px; }
@keyframes head-front { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-2px); } }
@keyframes head-left { 0%, 12% { transform: translateX(0) scaleX(1); } 45%, 78% { transform: translateX(-15px) scaleX(.8); } 100% { transform: translateX(0) scaleX(1); } }
@keyframes head-right { 0%, 12% { transform: translateX(0) scaleX(1); } 45%, 78% { transform: translateX(15px) scaleX(.8); } 100% { transform: translateX(0) scaleX(1); } }
@keyframes head-shape-left { 0%, 12%, 100% { transform: translateX(0); } 45%, 78% { transform: translateX(-3px); } }
@keyframes head-shape-right { 0%, 12%, 100% { transform: translateX(0); } 45%, 78% { transform: translateX(3px); } }
@keyframes head-arrow { 0%, 12%, 100% { opacity: .25; } 45%, 78% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) {
  .head-face, .head-shape, .head-arrow { animation: none !important; }
  .head-left .head-face { transform: translateX(-15px) scaleX(.8); }
  .head-right .head-face { transform: translateX(15px) scaleX(.8); }
}
.banner > .grow { flex: 1 1 0; min-width: 0; }
