/* CoasterQuest design system.
 *
 * Two surfaces, one set of tokens (Bible v4 §3 + PLAN.md §7):
 *   phone  — dark throughout with a bottom tab bar, for queues and night rides
 *   ≥900px — dark sidebar beside a light content area with white cards
 *
 * Components never name a colour. They use these tokens, so the light surface
 * is a re-declaration at the breakpoint rather than a second stylesheet.
 * --dark-* holds the sidebar palette, which stays dark on both surfaces.
 */

:root {
  --bg: #0b0a0f;
  --bg-elev: #16141d;
  --surface: #1c1926;
  --surface-2: #241f31;
  --border: #2f2a3d;

  --text: #f5f3f8;
  --muted: #a49dba;
  --faint: #6f6885;

  --accent: #a855f7;
  --accent-strong: #8b2fe8;
  --accent-soft: rgba(168, 85, 247, 0.14);
  /* Accent used as text: #a855f7 is only 2.7:1 on white, so the light surface
     swaps in a darker violet. Both stay above 4.5:1 on their own background. */
  --accent-text: #c084fc;
  --xp: #22d3ee;
  --success: #4ade80;
  --warn: #fbbf24;
  --danger: #f87171;

  /* Neutral fills that used to be hardcoded rgba(255,255,255,…) and inverted
     badly the moment the background turned white. */
  --track: rgba(255, 255, 255, 0.08);
  --track-strong: rgba(255, 255, 255, 0.16);
  --scrim: rgba(5, 4, 8, 0.72);
  --bar-bg: rgba(11, 10, 15, 0.92);

  /* The sidebar keeps this palette on every surface. */
  --dark-bg: #0b0a0f;
  --dark-surface: #16141d;
  --dark-border: #2f2a3d;
  --dark-text: #f5f3f8;
  --dark-muted: #a49dba;
  --dark-faint: #6f6885;

  --radius: 14px;
  --radius-sm: 9px;
  --gap: 14px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  --nav-h: 58px;
  --tabbar-h: 62px;
  --sidebar-w: 236px;
  --desktop: 900px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
  /* Without this, the elastic overscroll past the top/bottom edge — Safari's
     rubber-band bounce — drags the fixed .tabbar/.navbar along with the
     page for a frame before they snap back, which reads as the chrome
     "bouncing" separately from the content underneath it. */
  overscroll-behavior-y: none;
}

body {
  min-height: 100vh;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + 12px);
}

body.no-tabbar { padding-bottom: 24px; }

a { color: var(--accent-text); text-decoration: none; }
h1, h2, h3 { margin: 0 0 8px; line-height: 1.2; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 10px; }

.container {
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
  padding: 16px;
}

.muted { color: var(--muted); }
.faint { color: var(--faint); font-size: 0.85rem; }
.center { text-align: center; }
.row { display: flex; align-items: center; gap: 10px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1 1 auto; min-width: 0; }
.stack > * + * { margin-top: var(--gap); }
.hidden { display: none !important; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ------------------------------------------------------------------ navbar */

.navbar {
  position: sticky;
  top: 0;
  z-index: 40;
  /* Not gated behind `display-mode: standalone` like the old rule was: the
     iOS wrapper app loads this page in a plain WKWebView, which never
     reports as standalone, so that condition left the status bar (time /
     signal / battery icons) overlapping the navbar in the shipped app even
     though it worked fine for the installed home-screen PWA. env() resolves
     to 0px on browsers/contexts without an inset, so this is a no-op there. */
  height: calc(var(--nav-h) + env(safe-area-inset-top, 0px));
  padding: 0 14px;
  padding-top: env(safe-area-inset-top, 0px);
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bar-bg);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.navbar img { height: 34px; width: 34px; object-fit: contain; }

.navbar .brand {
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--text);
  font-size: 1.05rem;
}

.navbar .level-chip {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 11px;
  border-radius: 999px;
  background: var(--accent-soft);
  border: 1px solid rgba(168, 85, 247, 0.35);
  font-size: 0.82rem;
  font-weight: 600;
  color: #e9d5ff;
}

/* --------------------------------------------------------------- sidebar */
/* Hidden on phones; the desktop block at the end of this file turns it on. */

.sidebar { display: none; }

.sidebar .brand-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 16px 14px;
}

.sidebar .brand-row img { width: 36px; height: 36px; object-fit: contain; }

.sidebar .brand-row .brand {
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--dark-text);
}

.sidebar nav { display: flex; flex-direction: column; gap: 2px; padding: 6px 10px; }

.sidebar nav a {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--dark-muted);
  font-weight: 600;
  font-size: 0.94rem;
}

.sidebar nav a .icon { font-size: 1.15rem; line-height: 1; }
.sidebar nav a:hover { background: rgba(255, 255, 255, 0.06); color: var(--dark-text); }
.sidebar nav a.active { background: var(--accent-soft); color: #e9d5ff; }

.sidebar .sidebar-foot {
  margin-top: auto;
  padding: 14px 16px calc(14px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--dark-border);
}

.sidebar .level-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--accent-soft);
  border: 1px solid rgba(168, 85, 247, 0.35);
  font-size: 0.82rem;
  font-weight: 600;
  color: #e9d5ff;
}

/* --------------------------------------------------------------- tab bar */

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 45;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  background: rgba(22, 20, 29, 0.96);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--border);
}

.tabbar a, .tabbar button {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  background: none;
  border: none;
  color: var(--faint);
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  font-family: inherit;
  cursor: pointer;
}

.tabbar a span.icon, .tabbar button span.icon { font-size: 1.25rem; line-height: 1; }
.tabbar a.active, .tabbar button.active { color: var(--accent); }

/* ------------------------------------------------------- offline banner */

.offline-banner {
  position: sticky;
  top: calc(var(--nav-h) + env(safe-area-inset-top, 0px));
  z-index: 39;
  margin: 0 0 4px;
  padding: 8px 14px;
  text-align: center;
  font-size: 0.83rem;
  font-weight: 600;
  color: var(--warn);
  background: rgba(251, 191, 36, 0.14);
  border-bottom: 1px solid rgba(251, 191, 36, 0.35);
}

/* --------------------------------------------------------- install hint */

.install-hint {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-radius: var(--radius);
  background: var(--accent-soft);
  border: 1px solid rgba(168, 85, 247, 0.35);
  font-size: 0.88rem;
}

.install-hint .grow { min-width: 0; }
.install-hint button { flex: 0 0 auto; }

/* ----------------------------------------------------------------- cards */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}

.card.tight { padding: 11px 12px; }
.card.clickable { cursor: pointer; transition: border-color 0.15s, transform 0.1s; }
.card.clickable:active { transform: scale(0.995); }
.card.clickable:hover { border-color: var(--accent); }

.section-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin: 22px 0 10px;
}

.section-title h2 { margin: 0; }

/* ------------------------------------------------------------ stat tiles */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

@media (min-width: 620px) {
  .stat-grid { grid-template-columns: repeat(4, 1fr); }
}

.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  text-align: center;
}

.stat .value {
  font-size: 1.7rem;
  font-weight: 700;
  line-height: 1.1;
  color: var(--text);
}

.stat .label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-top: 3px;
}

/* ------------------------------------------------------------ level ring */

.level-ring-wrap {
  display: flex;
  align-items: center;
  gap: 18px;
}

.level-ring {
  --pct: 0;
  position: relative;
  flex: 0 0 auto;
  width: 116px;
  height: 116px;
  border-radius: 50%;
  background:
    conic-gradient(var(--accent) calc(var(--pct) * 1%), var(--track) 0);
  display: grid;
  place-items: center;
  transition: background 0.6s ease;
}

.level-ring::after {
  content: "";
  position: absolute;
  inset: 9px;
  border-radius: 50%;
  background: var(--surface);
}

.level-ring .inner {
  position: relative;
  z-index: 1;
  text-align: center;
}

.level-ring .lvl-label {
  font-size: 0.66rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.level-ring .lvl-value {
  font-size: 2.1rem;
  font-weight: 800;
  line-height: 1;
  color: var(--text);
}

/* ------------------------------------------------------------- progress */

.bar {
  height: 8px;
  border-radius: 999px;
  background: var(--track);
  overflow: hidden;
}

.bar > i {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent-strong), var(--accent));
  transition: width 0.5s ease;
}

.bar.xp > i { background: linear-gradient(90deg, #0891b2, var(--xp)); }
.bar.done > i { background: linear-gradient(90deg, #16a34a, var(--success)); }

/* -------------------------------------------------------------- buttons */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: filter 0.15s, transform 0.08s;
}

.btn:hover { filter: brightness(1.15); }
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn.primary {
  background: linear-gradient(135deg, var(--accent-strong), var(--accent));
  border-color: transparent;
  color: #fff;
}

.btn.ghost { background: transparent; }
.btn.small { padding: 7px 11px; font-size: 0.85rem; }
.btn.block { width: 100%; }
.btn.danger { color: var(--danger); }

.fab-log {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 17px;
  font-size: 1.1rem;
  font-weight: 700;
  border: none;
  border-radius: var(--radius);
  color: #fff;
  background: linear-gradient(135deg, var(--accent-strong), var(--accent));
  box-shadow: 0 8px 24px rgba(168, 85, 247, 0.35);
  cursor: pointer;
}

.fab-log:active { transform: scale(0.99); }

/* --------------------------------------------------------------- inputs */

label { display: block; font-size: 0.82rem; color: var(--muted); margin-bottom: 5px; }

input, select, textarea {
  width: 100%;
  padding: 11px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text);
  font: inherit;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.field + .field { margin-top: 12px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }

.chip {
  padding: 7px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

.chip.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: #e9d5ff;
}

.tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 600;
}

.tag.ridden { background: rgba(74, 222, 128, 0.14); border-color: rgba(74, 222, 128, 0.4); color: #bbf7d0; }
.tag.accent { background: var(--accent-soft); border-color: rgba(168, 85, 247, 0.4); color: #e9d5ff; }

/* ---------------------------------------------------------------- lists */

.list { display: flex; flex-direction: column; gap: 8px; }

.list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.list-item:hover { border-color: var(--accent); }
.list-item .title { font-weight: 600; }
.list-item .sub { font-size: 0.82rem; color: var(--muted); }
.list-item .right { margin-left: auto; text-align: right; flex: 0 0 auto; }

/* --------------------------------------------------------------- modal */

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: var(--scrim);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

@media (min-width: 620px) { .modal-backdrop { align-items: center; } }

.modal {
  width: 100%;
  max-width: 560px;
  max-height: 88vh;
  overflow-y: auto;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 16px;
  box-shadow: var(--shadow);
  animation: slide-up 0.18s ease-out;
}

@media (min-width: 620px) { .modal { border-radius: var(--radius); } }

@keyframes slide-up {
  from { transform: translateY(16px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.modal .modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.icon-btn {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  padding: 4px 8px;
}

/* -------------------------------------------------------------- toasts */

.toast-stack {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(var(--tabbar-h) + 16px);
  z-index: 80;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: min(92vw, 460px);
  pointer-events: none;
}

.toast {
  width: 100%;
  padding: 12px 14px;
  border-radius: var(--radius);
  background: var(--surface-2);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  animation: toast-in 0.22s ease-out;
}

.toast.xp {
  border-color: rgba(34, 211, 238, 0.45);
  background: linear-gradient(135deg, rgba(8, 145, 178, 0.28), var(--surface-2));
}

.toast.quest {
  border-color: rgba(168, 85, 247, 0.5);
  background: linear-gradient(135deg, rgba(139, 47, 232, 0.3), var(--surface-2));
}

.toast.error { border-color: rgba(248, 113, 113, 0.5); }

.toast .toast-title { font-weight: 700; display: flex; align-items: center; gap: 8px; }
.toast .toast-sub { font-size: 0.83rem; color: var(--muted); }
.toast .xp-amount { font-size: 1.35rem; font-weight: 800; color: var(--xp); }
.toast .badge-emoji { font-size: 1.6rem; }

.toast.leaveup { animation: toast-out 0.25s ease-in forwards; }

@keyframes toast-in {
  from { transform: translateY(14px) scale(0.97); opacity: 0; }
  to { transform: translateY(0) scale(1); opacity: 1; }
}

@keyframes toast-out {
  to { transform: translateY(-8px); opacity: 0; }
}

/* confetti-lite: pure CSS, no library */
.confetti {
  position: fixed;
  inset: 0;
  z-index: 79;
  pointer-events: none;
  overflow: hidden;
}

.confetti i {
  position: absolute;
  top: -12px;
  width: 8px;
  height: 14px;
  border-radius: 2px;
  opacity: 0.95;
  animation: confetti-fall linear forwards;
}

@keyframes confetti-fall {
  to { transform: translateY(105vh) rotate(720deg); opacity: 0; }
}

/* ------------------------------------------------------------ level-up */

.levelup-flash {
  position: fixed;
  inset: 0;
  z-index: 78;
  pointer-events: none;
  background: radial-gradient(circle at 50% 60%, var(--accent-soft), transparent 65%);
  animation: flash 1.1s ease-out forwards;
}

@keyframes flash {
  0% { opacity: 0; }
  25% { opacity: 1; }
  100% { opacity: 0; }
}

/* --------------------------------------------------------------- login */

.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
}

.auth-card img { display: block; width: 84px; margin: 0 auto 10px; }
.auth-tabs { display: flex; gap: 8px; margin-bottom: 16px; }
.auth-tabs .chip { flex: 1; text-align: center; }

.auth-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 16px 0;
  color: var(--muted);
  font-size: 13px;
}
.auth-divider::before, .auth-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.form-error {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: rgba(248, 113, 113, 0.12);
  border: 1px solid rgba(248, 113, 113, 0.4);
  color: #fecaca;
  font-size: 0.88rem;
}

/* ----------------------------------------------------------- danger zone */

.danger-zone {
  border-color: rgba(248, 113, 113, 0.35);
  background: rgba(248, 113, 113, 0.05);
}

.btn.danger {
  color: var(--danger);
  border-color: rgba(248, 113, 113, 0.45);
}

.btn.danger:hover { background: rgba(248, 113, 113, 0.12); }

/* --------------------------------------------------------------- quests */

.quest {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.quest.completed { border-color: rgba(74, 222, 128, 0.42); background: rgba(74, 222, 128, 0.06); }
.quest.secret { border-style: dashed; }
.quest .badge-emoji { font-size: 1.8rem; line-height: 1; flex: 0 0 auto; }
.quest .quest-body { flex: 1 1 auto; min-width: 0; }
.quest .quest-title { font-weight: 600; }
.quest .quest-desc { font-size: 0.83rem; color: var(--muted); margin: 2px 0 8px; }
.quest .quest-meta { display: flex; justify-content: space-between; font-size: 0.76rem; color: var(--faint); margin-top: 5px; }

.badge-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 10px;
}

.badge-tile {
  text-align: center;
  padding: 12px 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.badge-tile .emoji { font-size: 2rem; line-height: 1.1; }
.badge-tile .name { font-size: 0.78rem; font-weight: 600; margin-top: 4px; }
.badge-tile .date { font-size: 0.68rem; color: var(--faint); }

/* ----------------------------------------------------------------- map */

#map {
  height: min(70vh, 560px);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow: hidden;
  background: var(--bg-elev);
}

.map-legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 0.82rem; color: var(--muted); }
.map-legend .dot { display: inline-block; width: 11px; height: 11px; border-radius: 50%; margin-right: 5px; }
.dot.visited { background: #a855f7; }
.dot.unvisited { background: #6b7280; }

.leaflet-popup-content-wrapper,
.leaflet-popup-tip { background: var(--surface); color: var(--text); }
.leaflet-popup-content { margin: 10px 12px; }

/* -------------------------------------------------------------- states */

.empty {
  padding: 28px 16px;
  text-align: center;
  color: var(--muted);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

.skeleton {
  height: 62px;
  border-radius: var(--radius-sm);
  background: linear-gradient(90deg, var(--surface), var(--surface-2), var(--surface));
  background-size: 200% 100%;
  animation: shimmer 1.2s infinite linear;
}

@keyframes shimmer {
  from { background-position: 200% 0; }
  to { background-position: -200% 0; }
}

.placeholder { display: grid; place-items: center; min-height: 100vh; text-align: center; }

/* ------------------------------------------------------------- ratings */

.stars { display: inline-flex; gap: 3px; font-size: 1.35rem; cursor: pointer; }
.stars .star { color: var(--faint); }
.stars .star.on { color: var(--warn); }

/* Half-star rating (Bible §7: 0,5 tot 5 sterren). Two stacked copies of the
   same glyphs; the coloured one is clipped to the score, which is what makes
   half stars possible without half-star characters. */
.star-rating {
  position: relative;
  display: inline-block;
  font-size: 1.7rem;
  line-height: 1;
  letter-spacing: 2px;
  white-space: nowrap;
  user-select: none;
}

.star-rating .track { color: var(--track-strong); }

.star-rating .fill {
  position: absolute;
  inset: 0;
  overflow: hidden;
  color: var(--warn);
  white-space: nowrap;
  width: 0;
  transition: width 0.12s ease-out;
}

.star-rating.input { cursor: pointer; touch-action: none; }
.star-rating.input:hover .fill { filter: brightness(1.15); }
.star-rating.small { font-size: 1.15rem; }

.rating-value {
  margin-left: 10px;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text);
  vertical-align: super;
}

/* ------------------------------------------------------ period bar chart */

.period-chart {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  height: 132px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.period-bar {
  flex: 1 0 26px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  height: 100%;
  min-width: 26px;
}

.period-track {
  flex: 1 1 auto;
  width: 100%;
  display: flex;
  align-items: flex-end;
  background: var(--track);
  border-radius: 4px;
  overflow: hidden;
}

.period-track > i {
  display: block;
  width: 100%;
  min-height: 2px;
  border-radius: 4px;
  background: linear-gradient(180deg, var(--accent), var(--accent-strong));
  transition: height 0.4s ease;
}

.period-label {
  font-size: 0.64rem;
  color: var(--faint);
  white-space: nowrap;
  transform: rotate(-45deg);
  transform-origin: center;
  height: 14px;
}

.collection .bar { max-width: 100%; }

/* ---------------------------------------------------------------- photos */

.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(88px, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.photo-thumb {
  position: relative;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  aspect-ratio: 1;
  background: var(--bg-elev);
  cursor: pointer;
}

.photo-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-thumb:hover { border-color: var(--accent); }

.photo-picker {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 12px;
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  color: var(--muted);
  cursor: pointer;
  background: var(--bg-elev);
}

.photo-picker:hover { border-color: var(--accent); color: var(--text); }
.photo-picker input[type="file"] { display: none; }

.photo-pending {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.photo-pending img {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: rgba(4, 3, 7, 0.94);
  display: grid;
  grid-template-columns: auto 1fr auto;
  grid-template-rows: 1fr auto;
  align-items: center;
  justify-items: center;
  gap: 8px;
  padding: 16px;
}

.lightbox img {
  grid-column: 2;
  grid-row: 1;
  max-width: 100%;
  max-height: 82vh;
  object-fit: contain;
  border-radius: var(--radius-sm);
}

.lightbox-close {
  position: absolute;
  top: 12px;
  right: 16px;
  background: none;
  border: none;
  color: var(--text);
  font-size: 2rem;
  line-height: 1;
  cursor: pointer;
}

.lightbox-nav {
  background: none;
  border: none;
  color: var(--text);
  font-size: 2.6rem;
  line-height: 1;
  padding: 8px 12px;
  cursor: pointer;
  opacity: 0.75;
}

.lightbox-nav:hover { opacity: 1; }
.lightbox-nav.prev { grid-column: 1; grid-row: 1; }
.lightbox-nav.next { grid-column: 3; grid-row: 1; }

.lightbox-caption {
  grid-column: 1 / -1;
  grid-row: 2;
  color: var(--muted);
  font-size: 0.88rem;
  text-align: center;
}

/* --------------------------------------------------------------- reviews */

.review {
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.review + .review { margin-top: 8px; }
.review .review-head { display: flex; align-items: center; gap: 10px; }
.review .review-author { font-weight: 600; }
.review .review-body { margin-top: 8px; white-space: pre-wrap; line-height: 1.5; }

.community-score {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.community-score .big {
  font-size: 1.9rem;
  font-weight: 800;
  line-height: 1;
}

textarea {
  min-height: 92px;
  resize: vertical;
  font-family: inherit;
}

/* ======================================================== desktop surface ==
 *
 * Bible §3: dark sidebar, light content, white cards. Only the token values
 * change here — components are untouched, because none of them names a colour.
 */

@media (min-width: 900px) {
  body {
    --bg: #f4f2f7;
    --bg-elev: #ffffff;
    --surface: #ffffff;
    --surface-2: #f1eef7;
    --border: #e2dced;

    --text: #191527;
    --muted: #5d5673;
    --faint: #8b849e;

    /* 5.4:1 on white; the bright violet is reserved for fills and the sidebar. */
    --accent-text: #7c3aed;
    --accent-soft: rgba(124, 58, 237, 0.10);

    --track: rgba(25, 21, 39, 0.10);
    --track-strong: rgba(25, 21, 39, 0.20);
    --bar-bg: rgba(255, 255, 255, 0.9);
    --shadow: 0 10px 30px rgba(31, 22, 51, 0.12);

    /* Darker so they still read as colour on white rather than pastel. */
    --success: #16a34a;
    --warn: #b45309;
    --danger: #dc2626;
    --xp: #0e7490;

    padding-bottom: 0;
  }

  /* Only pages with a shell get the sidebar column; login has none. */
  body.with-sidebar {
    display: grid;
    grid-template-columns: var(--sidebar-w) 1fr;
    min-height: 100vh;
  }

  .navbar, .tabbar { display: none; }

  body.with-sidebar > .sidebar {
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    background: var(--dark-bg);
    border-right: 1px solid var(--dark-border);
  }

  body > main { padding: 8px 0 40px; min-width: 0; }

  .container { max-width: 940px; padding: 16px 28px; }

  /* White cards need a shadow to sit off the page; on dark, borders did it. */
  .card, .stat, .list-item, .quest, .review, .badge-tile, .photo-thumb {
    box-shadow: 0 1px 2px rgba(31, 22, 51, 0.06);
  }

  .card, .stat { border-color: var(--border); }

  input, select, textarea { background: #fff; }

  .fab-log { box-shadow: 0 8px 20px rgba(124, 58, 237, 0.28); }

  .toast-stack { bottom: 24px; }

  /* The modal keeps a dark scrim over a light page. */
  .modal-backdrop { --scrim: rgba(31, 22, 51, 0.45); }

  .skeleton {
    background: linear-gradient(90deg, var(--surface-2), #fbfaff, var(--surface-2));
    background-size: 200% 100%;
  }

  /* Leaflet ships light tiles; let its popups follow the page. */
  .leaflet-popup-content-wrapper, .leaflet-popup-tip {
    background: #fff;
    color: var(--text);
  }

  /* Tints picked to read on near-black are invisible on white. These are the
     handful of places that carry their own colour rather than a token. */
  .tag.ridden {
    background: rgba(22, 163, 74, 0.12);
    border-color: rgba(22, 163, 74, 0.35);
    color: #15803d;
  }

  .tag.accent {
    background: rgba(124, 58, 237, 0.10);
    border-color: rgba(124, 58, 237, 0.30);
    color: #6d28d9;
  }

  .quest.completed {
    border-color: rgba(22, 163, 74, 0.35);
    background: rgba(22, 163, 74, 0.06);
  }

  .form-error {
    background: rgba(220, 38, 38, 0.08);
    border-color: rgba(220, 38, 38, 0.30);
    color: #991b1b;
  }

  .toast { color: var(--text); }
  .toast.xp { background: linear-gradient(135deg, rgba(14, 116, 144, 0.12), #fff); }
  .toast.quest { background: linear-gradient(135deg, rgba(124, 58, 237, 0.12), #fff); }
  .toast.error { border-color: rgba(220, 38, 38, 0.45); }

  .offline-banner {
    color: #92400e;
    background: rgba(180, 83, 9, 0.10);
    border-bottom-color: rgba(180, 83, 9, 0.30);
  }

  .install-hint {
    background: rgba(124, 58, 237, 0.08);
    border-color: rgba(124, 58, 237, 0.28);
  }

  .community-score { background: var(--surface-2); }

  .danger-zone {
    border-color: rgba(220, 38, 38, 0.30);
    background: rgba(220, 38, 38, 0.04);
  }

  .btn.danger { border-color: rgba(220, 38, 38, 0.40); }
  .btn.danger:hover { background: rgba(220, 38, 38, 0.08); }
}

/* Wide enough to give the content real breathing room. */
@media (min-width: 1280px) {
  .container { max-width: 1100px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
