:root {
  --bg: #fbf3ea;
  --card: #ffffff;
  --ink: #1b1a1f;
  --muted: #5d5a66;
  --line: #ece4da;
  --accent: #ff4f2e;
  --accent-ink: #ffffff;
  --accent-soft: #ffe6df;
  --blue: #2457e6;
  --good: #11804a;
  --good-soft: #dcf5e7;
  --warn: #9a5b00;
  --warn-soft: #fff1d2;
  --bad: #c22626;
  --bad-soft: #fde2e2;
  --radius: 18px;
  --shadow: 0 1px 2px rgb(0 0 0 / 6%), 0 4px 16px rgb(0 0 0 / 6%);
  --tabbar: 76px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15141a;
    --card: #1f1e26;
    --ink: #f6f3ee;
    --muted: #b0acb8;
    --line: #34323d;
    --accent: #ff6a4d;
    --accent-soft: #3a211c;
    --blue: #7ea2ff;
    --good: #4cd38a;
    --good-soft: #173526;
    --warn: #ffc457;
    --warn-soft: #3a2d10;
    --bad: #ff7b7b;
    --bad-soft: #3c1b1b;
    --shadow: 0 1px 2px rgb(0 0 0 / 40%);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 18px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
img { max-width: 100%; display: block; }
a { color: var(--blue); }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .4em; }
h1 { font-size: 1.7rem; }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.1rem; }
p { margin: 0 0 .8em; }
.muted { color: var(--muted); }
.small { font-size: .9rem; }
.center { text-align: center; }
.hidden { display: none !important; }
.wrap { max-width: 640px; margin: 0 auto; padding: 16px; }
/* Vertical rhythm: flex gap, so spacing can't collapse or be overridden by margins. */
.stack { display: flex; flex-direction: column; gap: 20px; }
.card.stack, .sheet .stack { gap: 14px; }
.stack > div:empty { display: none; } /* empty status slots shouldn't add gaps */
.stack > * { margin-top: 0; margin-bottom: 0; }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap-row { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }

/* ---------- Buttons & inputs (big targets) ---------- */
.btn {
  appearance: none; border: 0; border-radius: 14px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 56px; padding: 0 22px; font: inherit; font-weight: 700;
  background: var(--accent); color: var(--accent-ink); text-decoration: none;
  transition: transform .06s ease, filter .15s;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.block { display: flex; width: 100%; }
.btn.big { min-height: 68px; font-size: 1.2rem; border-radius: 18px; }
.btn.secondary { background: var(--card); color: var(--ink); border: 2px solid var(--line); }
.btn.ghost { background: transparent; color: var(--blue); min-height: 48px; padding: 0 12px; }
.btn.danger { background: var(--bad-soft); color: var(--bad); }
.btn.good { background: var(--good); color: #fff; }
.btn.sm { min-height: 40px; padding: 0 14px; font-size: .95rem; border-radius: 10px; }
label { display: block; font-weight: 700; margin-bottom: 6px; }
label .opt { font-weight: 400; color: var(--muted); }
input[type=text], input[type=email], input[type=number], input[type=datetime-local], input[type=password], textarea, select {
  width: 100%; font: inherit; font-size: 1.1rem; color: var(--ink);
  background: var(--card); border: 2px solid var(--line); border-radius: 14px;
  padding: 14px 16px; min-height: 56px; outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); }
textarea { min-height: 90px; resize: vertical; }
.code-input { text-align: center; letter-spacing: .25em; font-size: 1.8rem !important; font-weight: 800; text-transform: uppercase; font-family: ui-monospace, Menlo, monospace !important; }
.check { display: flex; gap: 12px; align-items: center; font-weight: 600; min-height: 48px; }
.check input { width: 26px; height: 26px; flex: none; accent-color: var(--accent); }

/* ---------- Cards ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.pill { display: inline-flex; align-items: center; gap: 4px; padding: 4px 12px; border-radius: 999px; font-weight: 800; font-size: .95rem; background: var(--accent-soft); color: var(--accent); white-space: nowrap; }
.pill.good { background: var(--good-soft); color: var(--good); }
.pill.muted { background: var(--line); color: var(--muted); }
.banner { border-radius: 14px; padding: 12px 16px; font-weight: 600; display: flex; gap: 10px; align-items: center; }
.banner.info { background: var(--accent-soft); }
.banner.warn { background: var(--warn-soft); color: var(--warn); }
.banner.good { background: var(--good-soft); color: var(--good); }
.banner.bad { background: var(--bad-soft); color: var(--bad); }
.error-text { color: var(--bad); font-weight: 600; min-height: 1.4em; }

/* ---------- Crew app layout ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10; background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px; border-bottom: 1px solid var(--line);
}
.topbar .inner { max-width: 640px; margin: 0 auto; display: flex; align-items: center; gap: 12px; }
.topbar .title { font-weight: 800; font-size: 1.15rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn { appearance: none; border: 0; background: var(--card); color: var(--ink); width: 48px; height: 48px; border-radius: 14px; font-size: 1.4rem; box-shadow: var(--shadow); cursor: pointer; display: grid; place-items: center; }
main.app { padding-bottom: calc(var(--tabbar) + env(safe-area-inset-bottom) + 24px); }
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10; background: var(--card);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
  display: flex; justify-content: center;
}
.tabbar .tabs { display: flex; width: 100%; max-width: 640px; }
.tabbar button {
  flex: 1; appearance: none; border: 0; background: none; font: inherit; color: var(--muted);
  height: var(--tabbar); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-weight: 700; font-size: .95rem; cursor: pointer;
}
.tabbar button .ico { font-size: 1.7rem; line-height: 1; }
.tabbar button[aria-current=page] { color: var(--accent); }

.progress { height: 14px; border-radius: 999px; background: var(--line); overflow: hidden; }
.progress > div { height: 100%; background: linear-gradient(90deg, var(--accent), #ffb02e); border-radius: 999px; transition: width .4s ease; }

.item { display: flex; gap: 16px; align-items: center; width: 100%; text-align: left; font: inherit; color: inherit; cursor: pointer; min-height: 92px; }
button.item:not(.card) { border: 0; }
.item .thumb { width: 64px; height: 64px; flex: none; border-radius: 14px; background: var(--accent-soft); display: grid; place-items: center; font-size: 1.8rem; overflow: hidden; }
.item .thumb img { width: 100%; height: 100%; object-fit: cover; }
.item.done .thumb { background: var(--good-soft); }
.item .t { font-weight: 800; font-size: 1.08rem; }
.item .d { color: var(--muted); font-size: .95rem; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.item .chev { color: var(--muted); font-size: 1.4rem; }

.photo-drop {
  width: 100%; aspect-ratio: 4/3; border-radius: var(--radius); border: 3px dashed var(--line);
  background: var(--card); display: grid; place-items: center; overflow: hidden; cursor: pointer; position: relative;
}
.photo-drop img { width: 100%; height: 100%; object-fit: cover; }
.photo-drop .ph { text-align: center; color: var(--muted); font-weight: 700; }
.photo-drop .ph .ico { font-size: 3.4rem; }

/* Feed */
.post { padding: 0; overflow: hidden; }
.post .img { background: var(--line); aspect-ratio: 1/1; width: 100%; object-fit: cover; cursor: zoom-in; }
.post .meta { padding: 14px 16px 16px; }
.post .who { font-weight: 800; }
.post .what { color: var(--muted); font-size: .95rem; }
.like { appearance: none; border: 2px solid var(--line); background: var(--card); color: var(--ink); border-radius: 999px; min-height: 44px; padding: 0 14px; font: inherit; font-weight: 700; cursor: pointer; }
.like[aria-pressed=true] { border-color: var(--accent); background: var(--accent-soft); }
.post.pending { opacity: .85; }
.post.pending .img { filter: saturate(.6); }

/* Leaderboard */
.leader { display: flex; align-items: center; gap: 12px; padding: 16px 18px; min-height: 72px; }
.leader + .leader { border-top: 1px solid var(--line); }
.leader .rank { width: 40px; text-align: center; font-weight: 800; font-size: 1.2rem; }
.leader .name { flex: 1; font-weight: 700; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.leader.me { background: var(--accent-soft); }
.leader .pts { font-weight: 800; font-size: 1.15rem; }

/* Overlays */
.sheet-backdrop { position: fixed; inset: 0; background: rgb(0 0 0 / 45%); z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--bg); width: 100%; max-width: 640px; max-height: 94vh; overflow: auto; border-radius: 24px 24px 0 0; padding: 20px 16px calc(24px + env(safe-area-inset-bottom)); }
.lightbox { position: fixed; inset: 0; background: #000; z-index: 60; display: grid; place-items: center; }
.lightbox img { max-width: 100%; max-height: 100%; object-fit: contain; }
.lightbox .close { position: absolute; top: calc(env(safe-area-inset-top) + 12px); right: 12px; }
.toast { position: fixed; left: 50%; top: calc(env(safe-area-inset-top) + 76px); transform: translateX(-50%); z-index: 70; background: var(--ink); color: var(--bg); padding: 14px 20px; border-radius: 14px; font-weight: 700; max-width: calc(100% - 32px); box-shadow: var(--shadow); }

.celebrate { text-align: center; padding: 30px 10px; }
.celebrate .burst { font-size: 4.5rem; animation: pop .5s cubic-bezier(.2,1.6,.4,1); }
.celebrate .pts { font-size: 2.4rem; font-weight: 900; color: var(--accent); }
@keyframes pop { from { transform: scale(.2); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 80; overflow: hidden; }
.confetti i { position: absolute; top: -20px; width: 10px; height: 16px; border-radius: 3px; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); } }
@media (prefers-reduced-motion: reduce) { .confetti { display: none; } .celebrate .burst { animation: none; } }

.spinner { width: 22px; height: 22px; border: 3px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
.skeleton { background: linear-gradient(90deg, var(--line), var(--card), var(--line)); background-size: 200% 100%; animation: sk 1.2s infinite; border-radius: var(--radius); }
@keyframes sk { to { background-position: -200% 0; } }

.hero { text-align: center; padding: 28px 8px 8px; }
.hero .logo { font-size: 4rem; }
/* Crew top bar: room for the hunt name next to ⭐ ❓ 👤 on small phones */
.topbar .inner { gap: 8px; }
.topbar .icon-btn { width: 42px; height: 42px; font-size: 1.2rem; border-radius: 12px; flex: none; }
.topbar .pill { padding: 4px 10px; }
