:root {
  --bg: #f5f2ec;
  --card: #ffffff;
  --card-2: #f0ece4;
  --ink: #1c2622;
  --muted: #69736e;
  --line: #e3ddd2;
  --primary: #0f766e;
  --primary-ink: #ffffff;
  --primary-soft: #d5efe9;
  --accent: #ea580c;
  --accent-soft: #fde6d6;
  --good: #15803d;
  --good-soft: #dcf3e2;
  --bad: #b91c1c;
  --bad-soft: #fde2e2;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(20, 30, 25, .06), 0 4px 14px rgba(20, 30, 25, .06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111715;
    --card: #1a2320;
    --card-2: #232e2a;
    --ink: #eef3f0;
    --muted: #97a39d;
    --line: #2c3833;
    --primary: #2dd4bf;
    --primary-ink: #062b27;
    --primary-soft: #133a35;
    --accent: #fb923c;
    --accent-soft: #3d2516;
    --good: #4ade80;
    --good-soft: #143222;
    --bad: #f87171;
    --bad-soft: #3a1818;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body {
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
img, video { max-width: 100%; display: block; }
a { color: var(--primary); }
h1, h2, h3 { line-height: 1.15; margin: 0 0 .4em; letter-spacing: -.01em; }
h1 { font-size: 1.75rem; }
h2 { font-size: 1.3rem; }
p { margin: 0 0 .8em; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.pre { white-space: pre-wrap; }
.pre, .hintbox, .done-banner, .prompt { overflow-wrap: anywhere; }
[hidden] { display: none !important; }

.app { max-width: 640px; margin: 0 auto; min-height: 100dvh; }
.center-screen { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.page { padding: 16px 16px calc(96px + env(safe-area-inset-bottom)); }
.stack > * + * { margin-top: 12px; }

/* ---------- controls */
.btn {
  appearance: none; border: 0; border-radius: 12px; padding: 14px 18px;
  font: inherit; font-weight: 650; cursor: pointer; text-align: center;
  background: var(--primary); color: var(--primary-ink); width: 100%;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  transition: transform .08s ease, opacity .15s;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.secondary { background: var(--card-2); color: var(--ink); }
.btn.ghost { background: transparent; color: var(--primary); }
.btn.accent { background: var(--accent); color: #fff; }
.btn.danger { background: var(--bad-soft); color: var(--bad); }
.btn.small { padding: 8px 12px; font-size: .9rem; width: auto; border-radius: 10px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-row > .btn { flex: 1 1 140px; }

label.field { display: block; }
label.field > span { display: block; font-size: .85rem; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
input[type=text], input[type=number], input[type=password], input[type=datetime-local], input:not([type]), textarea, select {
  width: 100%; font: inherit; color: var(--ink); background: var(--card);
  border: 1.5px solid var(--line); border-radius: 12px; padding: 12px 14px; outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--primary); }
textarea { min-height: 90px; resize: vertical; }
.big-input { font-size: 1.6rem; font-weight: 700; text-align: center; letter-spacing: .15em; text-transform: uppercase; }

.segmented { display: flex; background: var(--card-2); border-radius: 12px; padding: 4px; gap: 4px; }
.segmented button {
  flex: 1; border: 0; background: transparent; font: inherit; font-weight: 600; color: var(--muted);
  padding: 10px 6px; border-radius: 9px; cursor: pointer;
}
.segmented button.on { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }

.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.pill {
  display: inline-flex; align-items: center; gap: 4px; font-size: .75rem; font-weight: 700;
  padding: 3px 9px; border-radius: 99px; background: var(--card-2); color: var(--muted);
  text-transform: uppercase; letter-spacing: .03em;
}
.pill.points { background: var(--accent-soft); color: var(--accent); }
.pill.good { background: var(--good-soft); color: var(--good); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.primary { background: var(--primary-soft); color: var(--primary); }

.spinner {
  width: 34px; height: 34px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--primary); animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(90px + env(safe-area-inset-bottom)); z-index: 50;
  background: var(--ink); color: var(--bg); padding: 12px 18px; border-radius: 12px;
  font-weight: 600; max-width: calc(100% - 32px); box-shadow: 0 6px 24px rgba(0,0,0,.25);
}
.toast.bad { background: var(--bad); color: #fff; }
.confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 60; }

/* ---------- hero / join */
.hero {
  position: relative; border-radius: 0 0 28px 28px; overflow: hidden; color: #fff;
  background: linear-gradient(140deg, #0f766e, #134e4a 60%, #1c2622);
  min-height: 220px; display: flex; align-items: flex-end;
}
.hero img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.hero::after { content: ""; position: absolute; inset: 0; background: linear-gradient(transparent 20%, rgba(0,0,0,.65)); }
.hero .hero-text { position: relative; z-index: 1; padding: 20px; }
.hero h1 { font-size: 2rem; margin: 0; }
.brand { font-weight: 800; letter-spacing: -.02em; font-size: 1.1rem; display: flex; align-items: center; gap: 8px; }

/* ---------- header + nav */
.topbar {
  position: sticky; top: 0; z-index: 10; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px; display: flex; align-items: center; gap: 12px;
  border-bottom: 1px solid var(--line);
}
.topbar .title { flex: 1; min-width: 0; }
.topbar .title b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .title small { color: var(--muted); }
.scorebox { text-align: right; }
.scorebox b { font-size: 1.3rem; color: var(--accent); display: block; line-height: 1; }
.scorebox small { color: var(--muted); font-size: .75rem; }
.timer { font-variant-numeric: tabular-nums; font-weight: 700; }
.timer.low { color: var(--bad); }

.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  background: var(--card); border-top: 1px solid var(--line);
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  display: flex; justify-content: center;
}
.tabbar .inner { display: flex; width: 100%; max-width: 640px; }
.tabbar a {
  flex: 1; text-align: center; text-decoration: none; color: var(--muted);
  font-size: .72rem; font-weight: 650; padding: 6px 0; border-radius: 10px;
}
.tabbar a .ico { display: block; font-size: 1.35rem; line-height: 1.2; filter: grayscale(1); opacity: .7; }
.tabbar a.on { color: var(--primary); }
.tabbar a.on .ico { filter: none; opacity: 1; }

/* ---------- challenge list */
.progress { height: 8px; background: var(--card-2); border-radius: 99px; overflow: hidden; }
.progress > div { height: 100%; background: var(--primary); border-radius: 99px; transition: width .4s; }
.clist { display: grid; gap: 10px; }
.citem {
  display: flex; gap: 12px; align-items: center; background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 12px; text-decoration: none; color: inherit; position: relative;
}
.citem .thumb {
  width: 58px; height: 58px; border-radius: 12px; flex: none; background: var(--card-2);
  display: grid; place-items: center; font-size: 1.7rem; overflow: hidden;
}
.citem .thumb img { width: 100%; height: 100%; object-fit: cover; }
.citem .body { flex: 1; min-width: 0; }
.citem .body b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.citem .meta { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }
.citem.done .thumb { background: var(--good-soft); }
.citem.locked { opacity: .55; box-shadow: none; background: var(--card-2); }
.citem .check { font-size: 1.4rem; }
.section-title { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; margin: 22px 0 8px; }

/* ---------- challenge detail */
.back { display: inline-flex; align-items: center; gap: 4px; text-decoration: none; font-weight: 600; margin-bottom: 10px; }
.detail-img { border-radius: var(--radius); overflow: hidden; margin-bottom: 14px; }
.detail-img img { width: 100%; max-height: 360px; object-fit: cover; }
.prompt { font-size: 1.1rem; }
.done-banner { background: var(--good-soft); color: var(--good); border-radius: var(--radius); padding: 14px 16px; font-weight: 650; }
.reject-banner { background: var(--bad-soft); color: var(--bad); border-radius: var(--radius); padding: 14px 16px; font-weight: 650; }
.hintbox { background: var(--accent-soft); border-radius: 12px; padding: 12px 14px; }
.choices { display: grid; gap: 8px; }
.choices .btn { justify-content: flex-start; text-align: left; }

.compass-card { text-align: center; }
.compass {
  position: relative; width: min(240px, 70vw); aspect-ratio: 1; margin: 6px auto 10px;
}
.compass .dial {
  position: absolute; inset: 0; border-radius: 50%;
  background: radial-gradient(circle, var(--card) 58%, var(--card-2) 59%);
  border: 2px solid var(--line); transition: transform .25s ease-out;
}
.compass .dial span { position: absolute; left: 50%; top: 6px; transform: translateX(-50%); font-weight: 800; color: var(--bad); font-size: .9rem; }
.compass .dial span.e { top: 50%; left: auto; right: 8px; transform: translateY(-50%); color: var(--muted); }
.compass .dial span.s { top: auto; bottom: 6px; color: var(--muted); }
.compass .dial span.w { top: 50%; left: 8px; transform: translateY(-50%); color: var(--muted); }
.compass .arrow {
  position: absolute; inset: 18%; transition: transform .25s ease-out;
  display: grid; place-items: center;
}
.compass .arrow svg { width: 100%; height: 100%; filter: drop-shadow(0 3px 6px rgba(0,0,0,.2)); }
.compass.here .dial { border-color: var(--good); box-shadow: 0 0 0 6px var(--good-soft); }
.distance { font-size: 2.2rem; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1; }
.heat { font-weight: 700; margin-top: 4px; }

.upload-preview { border-radius: 12px; overflow: hidden; background: var(--card-2); }
.upload-preview img, .upload-preview video { width: 100%; max-height: 420px; object-fit: contain; }
.bar { height: 6px; background: var(--card-2); border-radius: 99px; overflow: hidden; }
.bar > div { height: 100%; width: 0; background: var(--accent); transition: width .2s; }

/* ---------- feed / board */
.feed { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
.feed button { all: unset; cursor: pointer; aspect-ratio: 1; position: relative; overflow: hidden; border-radius: 6px; background: var(--card-2); }
.feed img, .feed video { width: 100%; height: 100%; object-fit: cover; }
.feed .vid { position: absolute; right: 6px; top: 6px; color: #fff; text-shadow: 0 1px 4px #000; }
.lightbox {
  position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,.92); color: #fff;
  display: flex; flex-direction: column; justify-content: center; padding: 16px;
  padding-top: calc(16px + env(safe-area-inset-top)); padding-bottom: calc(16px + env(safe-area-inset-bottom));
}
.lightbox img, .lightbox video { max-height: 75dvh; width: auto; margin: 0 auto; border-radius: 8px; }
.lightbox .cap { text-align: center; margin-top: 12px; }
.lightbox .close { position: absolute; top: calc(12px + env(safe-area-inset-top)); right: 12px; background: rgba(255,255,255,.15); color: #fff; border: 0; font-size: 1.4rem; width: 44px; height: 44px; border-radius: 50%; cursor: pointer; }

.board { display: grid; gap: 8px; }
.brow { display: flex; align-items: center; gap: 12px; background: var(--card); border-radius: 14px; padding: 12px 14px; box-shadow: var(--shadow); }
.brow .rank { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; font-weight: 800; background: var(--card-2); flex: none; }
.brow:nth-child(1) .rank { background: #fde68a; color: #78350f; }
.brow:nth-child(2) .rank { background: #e5e7eb; color: #374151; }
.brow:nth-child(3) .rank { background: #fed7aa; color: #7c2d12; }
.brow .name { flex: 1; min-width: 0; }
.brow .name b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brow .pts { font-weight: 800; font-size: 1.15rem; color: var(--accent); }
.brow.me { outline: 2px solid var(--primary); }

.codebig { font-size: 2.4rem; font-weight: 800; letter-spacing: .25em; text-align: center; color: var(--primary); }
.empty { text-align: center; padding: 40px 16px; color: var(--muted); }
.empty .ico { font-size: 2.6rem; display: block; margin-bottom: 8px; }
