/*
 * Good Job — layout and components, shared by her page and the admin page.
 *
 * Every colour, font and corner radius comes from a custom property set by
 * the active theme (assets/js/themes.js). The values below are the default
 * "Calm" theme, used until the scripts load. Cards: cards.css. Admin-only
 * pieces: admin.css.
 */

:root {
  --bg: #f4f1ea;
  --surface: #fffdf8;
  --surface-2: #ece7dc;
  --text: #2e3a33;
  --muted: #6b786f;
  --line: #e0dacd;
  --accent: #4f8160;
  --accent-ink: #ffffff;
  --soft: #dfeadf;
  --star: #d99a1e;
  --danger: #c4513f;
  --radius: 20px;
  --font-head: system-ui, sans-serif;
  --font-body: system-ui, -apple-system, 'Segoe UI', sans-serif;
  --head-scale: 1;
  --head-weight: 600;

  --radius-sm: calc(var(--radius) * 0.6);
  --shadow: 0 1px 2px color-mix(in srgb, var(--text) 8%, transparent), 0 6px 20px -8px color-mix(in srgb, var(--text) 18%, transparent);
  --shadow-lift: 0 2px 4px color-mix(in srgb, var(--text) 8%, transparent), 0 14px 32px -10px color-mix(in srgb, var(--text) 28%, transparent);
  --gutter: clamp(16px, 4vw, 32px);
  --max: 1100px;
  --tap: 44px;
  --ease: cubic-bezier(.2, .7, .2, 1);

  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 17px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  overflow-wrap: anywhere;
}

html.modal-open { overflow: hidden; }

h1, h2, h3 {
  font-family: var(--font-head);
  font-weight: var(--head-weight);
  line-height: 1.15;
  margin: 0;
  overflow-wrap: break-word;
}
h1 { font-size: calc(clamp(1.7rem, 4.5vw, 2.4rem) * var(--head-scale)); }
h2 { font-size: calc(1.3rem * var(--head-scale)); }
h3 { font-size: calc(1.05rem * var(--head-scale)); }

p { margin: 0; }
a { color: var(--accent); }
img { max-width: 100%; display: block; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button, .btn, .chip, .tab { overflow-wrap: normal; }
button:disabled { cursor: default; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 60%, transparent); outline-offset: 2px; }

.icon { flex: none; display: block; }
.hint { color: var(--muted); font-size: 0.88rem; }
.muted { color: var(--muted); }
.spacer { flex: 1; }
.nowrap { white-space: nowrap; }
[hidden] { display: none !important; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------------------------------------------------------------- buttons */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5em;
  min-height: var(--tap);
  padding: 0.55em 1.1em;
  border-radius: 999px;
  border: 1.5px solid transparent;
  background: var(--surface-2);
  color: var(--text);
  font-weight: 700;
  font-size: 0.97rem;
  text-decoration: none;
  line-height: 1.2;
  transition: transform 0.12s var(--ease), background 0.15s, box-shadow 0.15s;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}
.btn:active:not(:disabled) { transform: scale(0.97); }
.btn:disabled { opacity: 0.55; }
.btn.primary { background: var(--accent); color: var(--accent-ink); box-shadow: 0 4px 14px -6px var(--accent); }
.btn.primary:hover:not(:disabled) { background: color-mix(in srgb, var(--accent) 88%, black); }
.btn.soft { background: var(--soft); color: color-mix(in srgb, var(--accent) 70%, var(--text)); }
.btn.ghost { background: transparent; border-color: var(--line); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.big { min-height: 54px; padding: 0.7em 1.5em; font-size: 1.05rem; }
.btn.small { min-height: 36px; padding: 0.35em 0.9em; font-size: 0.9rem; }
.btn.block { width: 100%; }
.danger-text { color: var(--danger) !important; }

.btn.busy { position: relative; color: transparent !important; }
.btn.busy::after {
  content: '';
  position: absolute;
  width: 20px; height: 20px;
  border-radius: 50%;
  border: 2.5px solid var(--accent-ink);
  border-color: var(--accent-ink) transparent var(--accent-ink) transparent;
  animation: spin 0.8s linear infinite;
}
.btn.soft.busy::after, .btn.ghost.busy::after, .btn:not(.primary):not(.danger).busy::after { border-color: var(--accent) transparent var(--accent) transparent; }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: var(--tap);
  height: var(--tap);
  border-radius: 999px;
  border: 0;
  background: transparent;
  color: var(--text);
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}
.icon-btn:hover:not(:disabled) { background: var(--surface-2); }
.icon-btn:disabled { opacity: 0.35; }
.icon-btn.on { color: var(--danger); }

.link-btn {
  border: 0;
  background: none;
  padding: 0.25em 0.4em;
  color: var(--accent);
  font-weight: 700;
  font-size: 0.92rem;
  text-decoration: underline;
  text-underline-offset: 3px;
  min-height: 36px;
}
.link-btn.muted { color: var(--muted); }

.button-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }

.spinner {
  display: inline-block;
  width: 22px; height: 22px;
  border-radius: 50%;
  border: 3px solid var(--line);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
.spinner.large { width: 40px; height: 40px; border-width: 4px; }
@keyframes spin { to { transform: rotate(360deg); } }
.boot { min-height: 70vh; display: grid; place-items: center; }

/* ------------------------------------------------------------ chips, tabs */

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4em;
  min-height: 40px;
  padding: 0.35em 0.95em;
  border-radius: 999px;
  border: 1.5px solid var(--line);
  background: var(--surface);
  color: var(--text);
  font-size: 0.95rem;
  font-weight: 700;
  line-height: 1.2;
  -webkit-tap-highlight-color: transparent;
}
.chip:hover { border-color: color-mix(in srgb, var(--accent) 50%, var(--line)); }
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.chip.guess:not([aria-pressed="true"]) { border-style: dashed; border-color: color-mix(in srgb, var(--accent) 60%, var(--line)); }
.chip.small { min-height: 32px; font-size: 0.85rem; padding: 0.2em 0.75em; }

.tabs {
  display: flex;
  gap: 4px;
  padding: 4px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  border: 0;
  background: transparent;
  border-radius: 999px;
  padding: 0.45em 1em;
  font-weight: 800;
  font-size: 0.92rem;
  color: var(--muted);
  min-height: 38px;
  white-space: nowrap;
}
.tab[aria-selected="true"], .tab[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35em;
  padding: 0.1em 0.65em;
  border-radius: 999px;
  background: var(--soft);
  font-size: 0.82rem;
  font-weight: 800;
  white-space: nowrap;
}
.pill.star { background: color-mix(in srgb, var(--star) 18%, var(--surface)); color: color-mix(in srgb, var(--star) 55%, var(--text)); }
.pill.bad { background: color-mix(in srgb, var(--danger) 14%, var(--surface)); color: var(--danger); }

/* ----------------------------------------------------------------- header */

.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(8px + env(safe-area-inset-top)) max(var(--gutter), env(safe-area-inset-right)) 8px max(var(--gutter), env(safe-area-inset-left));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(14px) saturate(1.4);
  -webkit-backdrop-filter: blur(14px) saturate(1.4);
  border-bottom: 1px solid color-mix(in srgb, var(--line) 70%, transparent);
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  text-decoration: none;
  min-width: 0;
  margin-right: auto;
}
.brand-mark {
  display: grid;
  place-items: center;
  width: 40px; height: 40px;
  border-radius: 13px;
  background: var(--accent);
  color: var(--accent-ink);
  flex: none;
}
.brand-title { font-family: var(--font-head); font-weight: var(--head-weight); font-size: calc(1.3rem * var(--head-scale)); line-height: 1.1; white-space: nowrap; }
.header-actions { display: flex; align-items: center; gap: 2px; flex: none; }

.points-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 40px;
  padding: 0.3em 0.9em 0.3em 0.7em;
  border-radius: 999px;
  background: color-mix(in srgb, var(--star) 16%, var(--surface));
  color: var(--text);
  font-weight: 800;
  text-decoration: none;
  margin-right: 4px;
}
.points-chip .star { color: var(--star); font-size: 1.1em; line-height: 1; }

/* ------------------------------------------------------------------ pages */

.page {
  max-width: var(--max);
  margin: 0 auto;
  padding: 18px max(var(--gutter), env(safe-area-inset-right)) calc(80px + env(safe-area-inset-bottom)) max(var(--gutter), env(safe-area-inset-left));
}
.page-head { display: grid; gap: 6px; margin: 6px 0 18px; }
.page-head .back { margin-bottom: 2px; }
.back {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--muted);
  text-decoration: none;
  font-weight: 700;
  font-size: 0.95rem;
  min-height: 36px;
  width: max-content;
}
.back:hover { color: var(--text); }
.lede { color: var(--muted); font-size: 1.02rem; max-width: 62ch; }

.section { display: grid; gap: 12px; margin-top: 28px; }
.section-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.section-head h2 { margin-right: auto; }

.panel {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 10px;
  padding: 40px 16px;
  color: var(--muted);
}
.empty h2 { color: var(--text); }
.empty-art {
  display: grid;
  place-items: center;
  width: 84px; height: 84px;
  border-radius: 50%;
  background: var(--soft);
  color: var(--accent);
  font-size: 2.2rem;
  margin-bottom: 4px;
}

.grid-list { display: grid; gap: 12px; }

/* ------------------------------------------------------------------- home */

.home { display: grid; gap: 18px; max-width: 720px; margin: 0 auto; }
.hello { display: grid; gap: 2px; text-align: center; margin-top: 6px; }
.hello h1 { font-size: calc(clamp(1.6rem, 5vw, 2.2rem) * var(--head-scale)); }
.hello .since { color: var(--muted); font-weight: 700; }

.ate-wrap { display: grid; justify-items: center; gap: 10px; padding: 8px 0 4px; }
.ate-btn {
  position: relative;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 4px;
  width: min(300px, 74vw);
  aspect-ratio: 1;
  border-radius: 50%;
  border: 0;
  background: radial-gradient(circle at 50% 38%, color-mix(in srgb, var(--accent) 78%, white) 0%, var(--accent) 62%, color-mix(in srgb, var(--accent) 80%, black) 100%);
  color: var(--accent-ink);
  box-shadow: 0 18px 40px -16px color-mix(in srgb, var(--accent) 80%, black), inset 0 -8px 0 color-mix(in srgb, var(--accent) 70%, black), inset 0 4px 0 color-mix(in srgb, white 25%, transparent);
  transition: transform 0.15s var(--ease), box-shadow 0.15s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.ate-btn::before {
  /* the rim of the plate */
  content: '';
  position: absolute;
  inset: 11%;
  border-radius: 50%;
  border: 3px solid color-mix(in srgb, var(--accent-ink) 28%, transparent);
  pointer-events: none;
}
.ate-btn:active:not(:disabled) { transform: scale(0.96) translateY(3px); box-shadow: 0 10px 24px -14px color-mix(in srgb, var(--accent) 80%, black), inset 0 -3px 0 color-mix(in srgb, var(--accent) 70%, black); }
.ate-btn:disabled { filter: saturate(0.6); }
.ate-emoji { font-size: clamp(3rem, 14vw, 4.4rem); line-height: 1; }
.ate-label { font-family: var(--font-head); font-weight: var(--head-weight); font-size: calc(clamp(1.3rem, 5vw, 1.65rem) * var(--head-scale)); line-height: 1.1; padding: 0 12%; text-align: center; }
.ate-sub { font-size: 0.85rem; font-weight: 700; opacity: 0.85; }
@media (prefers-reduced-motion: no-preference) {
  html:not(.calm) .ate-btn:not(:disabled) { animation: breathe 4.5s ease-in-out infinite; }
}
@keyframes breathe { 50% { transform: scale(1.025); } }

.cheer-banner {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--danger) 9%, var(--surface));
  border: 1.5px solid color-mix(in srgb, var(--danger) 25%, var(--line));
  animation: pop 0.3s var(--ease);
}
.cheer-banner .big { font-size: 1.8rem; line-height: 1; }
.cheer-banner .text { flex: 1; display: grid; gap: 2px; }
.cheer-banner .who { font-size: 0.82rem; font-weight: 800; color: var(--muted); }
.cheer-banner .msg { font-weight: 800; font-size: 1.08rem; }

.today {
  display: grid;
  gap: 10px;
  padding: 16px 18px;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.today-head { display: flex; align-items: baseline; gap: 8px; }
.today-head h2 { font-size: calc(1.05rem * var(--head-scale)); margin-right: auto; }
.timeline { position: relative; height: 58px; margin: 4px 6px 0; }
.timeline-track { position: absolute; left: 0; right: 0; top: 22px; height: 6px; border-radius: 3px; background: var(--surface-2); }
.timeline-now { position: absolute; top: 14px; width: 2px; height: 22px; background: var(--muted); border-radius: 1px; opacity: 0.6; }
.timeline-dot {
  position: absolute;
  top: 8px;
  transform: translateX(-50%);
  display: grid;
  place-items: center;
  width: 34px; height: 34px;
  border-radius: 50%;
  background: var(--surface);
  border: 2px solid var(--accent);
  font-size: 1rem;
  box-shadow: 0 0 0 2px var(--surface);
}
.timeline-ticks { position: absolute; left: 0; right: 0; top: 40px; display: flex; justify-content: space-between; font-size: 0.72rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.today-list { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 0.92rem; color: var(--muted); }
.today-list b { color: var(--text); }

.run-line { text-align: center; color: var(--muted); font-weight: 700; }
.run-line b { color: var(--text); }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.tile {
  display: grid;
  gap: 4px;
  align-content: start;
  min-height: 112px;
  padding: 14px 16px;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  color: var(--text);
  text-decoration: none;
  transition: transform 0.15s var(--ease), box-shadow 0.15s;
}
.tile:hover { transform: translateY(-2px); box-shadow: var(--shadow-lift); }
.tile-emoji { font-size: 1.7rem; line-height: 1.1; }
.tile-name { font-family: var(--font-head); font-weight: var(--head-weight); font-size: calc(1.05rem * var(--head-scale)); }
.tile-sub { font-size: 0.85rem; color: var(--muted); font-weight: 700; }
.meter { height: 8px; border-radius: 4px; background: color-mix(in srgb, var(--accent) 16%, var(--surface)); overflow: hidden; margin-top: 4px; }
.meter > i { display: block; height: 100%; border-radius: 4px; background: var(--accent); }

.earlier-link { justify-self: center; }

/* ----------------------------------------------------------------- reveal */

.dialog.reveal {
  width: min(560px, 100vw);
  max-width: 100vw;
  height: min(100dvh, 920px);
  max-height: 100dvh;
  background: var(--bg);
}
@media (max-width: 600px) {
  .dialog.reveal { width: 100vw; height: 100dvh; max-height: 100dvh; border-radius: 0; margin: 0; animation: fadeIn 0.25s ease; }
}
.reveal .dialog-inner { height: 100%; }
.reveal .dialog-head { padding-bottom: 0; }
.reveal .dialog-body { flex: 1; display: flex; flex-direction: column; padding: 4px 20px calc(18px + env(safe-area-inset-bottom)); gap: 14px; }
.reveal-steps { display: flex; justify-content: center; gap: 6px; }
.reveal-steps i { width: 8px; height: 8px; border-radius: 50%; background: var(--line); transition: background 0.2s, width 0.2s; }
.reveal-steps i.on { background: var(--accent); width: 22px; border-radius: 4px; }
.reveal-stage { flex: 1; display: grid; place-items: center; align-content: center; gap: 16px; text-align: center; min-height: 0; }
.reveal-stage > * { animation: rise 0.35s var(--ease) both; }
.reveal-stage.clip { overflow: hidden; margin: 0 -20px; padding: 0 20px; }
html.calm .reveal-stage > * { animation: fadeIn 0.25s ease both; }
.reveal-title { font-family: var(--font-head); font-weight: var(--head-weight); font-size: calc(clamp(1.5rem, 6vw, 2rem) * var(--head-scale)); }
.reveal-sub { color: var(--muted); font-weight: 700; max-width: 34ch; }
.reveal-actions { display: grid; gap: 8px; }
.reveal-actions .btn { width: 100%; }
.check-big {
  display: grid;
  place-items: center;
  width: 110px; height: 110px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
  box-shadow: 0 14px 30px -14px var(--accent);
}
.gain { font-family: var(--font-head); font-weight: var(--head-weight); font-size: calc(2.4rem * var(--head-scale)); color: var(--text); }
.gain .star { color: var(--star); }
.reveal-badges { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.tap-hint { color: var(--muted); font-weight: 700; font-size: 0.95rem; }

@keyframes rise { from { opacity: 0; transform: translateY(14px); } }
@keyframes fadeIn { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(12px) scale(0.98); } }
@keyframes popOut { to { opacity: 0; transform: translateY(8px) scale(0.98); } }

/* --------------------------------------------------------- reward bodies */

.fact-card {
  display: grid;
  gap: 10px;
  width: 100%;
  max-width: 460px;
  padding: 20px;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  text-align: left;
}
.fact-topic { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 0.88rem; color: var(--muted); }
.fact-text { font-size: 1.12rem; font-weight: 700; line-height: 1.45; }
.fact-why { color: var(--muted); font-size: 0.93rem; }
.fact-source { font-size: 0.85rem; }
.fact-actions { display: flex; gap: 6px; align-items: center; margin-top: 2px; flex-wrap: wrap; }

.pic-card { display: grid; gap: 8px; width: 100%; max-width: 460px; }
.pic-card img { width: 100%; max-height: 52dvh; object-fit: cover; border-radius: var(--radius); box-shadow: var(--shadow); background: var(--surface-2); cursor: zoom-in; }
.pic-credit { font-size: 0.8rem; color: var(--muted); }
.pic-credit a { color: inherit; }

.note-card {
  position: relative;
  width: 100%;
  max-width: 440px;
  padding: 26px 22px;
  border-radius: 6px;
  background: color-mix(in srgb, #fff5c9 88%, var(--surface));
  color: #3b3020;
  box-shadow: 0 16px 30px -18px rgba(0, 0, 0, 0.5);
  font-size: 1.15rem;
  font-weight: 700;
  line-height: 1.5;
  white-space: pre-line;
  transform: rotate(-1.2deg);
}
html[data-dark="1"] .note-card { background: #f5e9b8; }
.note-card::before { content: ''; position: absolute; top: -10px; left: 50%; width: 80px; height: 22px; transform: translateX(-50%) rotate(2deg); background: color-mix(in srgb, var(--accent) 35%, transparent); border-radius: 2px; }
.note-from { font-size: 0.85rem; font-weight: 800; color: #7a6a4a; margin-top: 10px; }
.stash-photo { width: 100%; max-width: 440px; display: grid; gap: 8px; }
.stash-photo img { width: 100%; max-height: 54dvh; object-fit: contain; border-radius: 10px; background: #fff; padding: 10px 10px 32px; box-shadow: 0 16px 30px -18px rgba(0, 0, 0, 0.5); transform: rotate(1deg); cursor: zoom-in; }

.badge-card {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  max-width: 440px;
  padding: 14px 16px;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  text-align: left;
}
.badge-emoji {
  display: grid;
  place-items: center;
  flex: none;
  width: 58px; height: 58px;
  border-radius: 50%;
  font-size: 1.9rem;
  background: color-mix(in srgb, var(--star) 22%, var(--surface));
  box-shadow: inset 0 0 0 3px color-mix(in srgb, var(--star) 55%, transparent);
}
.badge-name { font-weight: 800; font-size: 1.05rem; }
.badge-text { color: var(--muted); font-size: 0.92rem; }

/* ----------------------------------------------------------------- extras */

.extras { display: grid; gap: 16px; width: 100%; text-align: left; }
.extras .q { display: grid; gap: 8px; }
.extras .q-label { font-weight: 800; }
.extras .q-label small { color: var(--muted); font-weight: 700; }
.what-input {
  width: 100%;
  min-height: var(--tap);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--line);
  background: var(--surface);
  font-size: 1rem;
}
.what-input:focus { outline: none; border-color: var(--accent); }

/* ------------------------------------------------------------- collection */

.set-block { display: grid; gap: 12px; margin-bottom: 30px; }
.set-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.set-head h2 { margin-right: auto; }
.set-progress { width: 100%; }
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(var(--cw, 128px), 1fr)); gap: 14px 12px; justify-items: center; }
.card-cell { display: grid; justify-items: center; gap: 4px; border: 0; padding: 0; background: none; color: inherit; -webkit-tap-highlight-color: transparent; }
.card-cell:hover .gj-card { transform: translateY(-3px); }
.card-count { font-size: 0.8rem; font-weight: 800; color: var(--muted); }

.card-view { display: grid; justify-items: center; gap: 14px; text-align: center; }
.card-meta { color: var(--muted); font-weight: 700; font-size: 0.92rem; }

/* -------------------------------------------------------------- treasures */

.treasure-list { display: grid; gap: 12px; }
.treasure-list .fact-card { max-width: none; }
.pic-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.pic-tile { position: relative; border: 0; padding: 0; border-radius: var(--radius-sm); overflow: hidden; aspect-ratio: 1; background: var(--surface-2); }
.pic-tile img { width: 100%; height: 100%; object-fit: cover; }
.pic-tile .love { position: absolute; right: 6px; bottom: 6px; font-size: 1.1rem; filter: drop-shadow(0 1px 2px rgba(0,0,0,.5)); }
.love-btn.on { color: var(--danger); }

/* ------------------------------------------------------------------- shop */

.balance-hero { display: grid; justify-items: center; gap: 2px; padding: 8px 0 4px; }
.balance-hero .num { font-family: var(--font-body); font-weight: 800; font-size: 3rem; line-height: 1; }
.balance-hero .num .star { color: var(--star); }
.shop-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.shop-item { display: grid; gap: 8px; align-content: start; padding: 16px; border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.shop-emoji { font-size: 2rem; line-height: 1; }
.shop-title { font-weight: 800; font-size: 1.05rem; }
.shop-desc { color: var(--muted); font-size: 0.92rem; }
.shop-item .btn { margin-top: 4px; }
.iou-list { display: grid; gap: 8px; }
.iou {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1.5px dashed var(--line);
}
.iou.done { opacity: 0.7; border-style: solid; }
.iou .e { font-size: 1.5rem; }
.iou .t { flex: 1; display: grid; }
.iou .t small { color: var(--muted); font-weight: 700; }

/* ----------------------------------------------------------------- badges */

.badge-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 10px; }
.badge-grid .badge-card { max-width: none; }
.badge-card.locked .badge-emoji { filter: grayscale(1); opacity: 0.45; background: var(--surface-2); box-shadow: none; }
.badge-card.locked .badge-name { color: var(--muted); }
.badge-progress { display: grid; gap: 3px; margin-top: 4px; font-size: 0.78rem; color: var(--muted); font-weight: 700; }

/* ---------------------------------------------------------------- history */

.day-group { display: grid; gap: 8px; margin-bottom: 18px; }
.day-label { font-weight: 800; color: var(--muted); font-size: 0.9rem; text-transform: uppercase; letter-spacing: 0.04em; }
.meal-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  box-shadow: var(--shadow);
  border: 0;
  width: 100%;
  text-align: left;
}
.meal-row .e { font-size: 1.4rem; width: 32px; text-align: center; }
.meal-row .t { flex: 1; display: grid; min-width: 0; }
.meal-row .t small { color: var(--muted); font-weight: 600; }
.meal-row .time { font-weight: 800; font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------------ forms */

.field { display: grid; gap: 6px; min-width: 0; }
.field-label { font-weight: 800; font-size: 0.92rem; }
.field-help { color: var(--muted); font-size: 0.85rem; }
.field input[type="text"], .field input[type="number"], .field input[type="password"], .field input[type="url"],
.field input[type="datetime-local"], .field input[type="time"], .field select, .field textarea, .login-form input {
  width: 100%;
  min-height: var(--tap);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--line);
  background: var(--surface);
  font-size: 1rem;
}
.field textarea { resize: vertical; line-height: 1.5; min-height: 90px; }
.field :is(input, select, textarea):focus, .login-form input:focus { outline: none; border-color: var(--accent); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 460px) { .field-row { grid-template-columns: 1fr; } }
.check-row { display: inline-flex; align-items: center; gap: 10px; font-weight: 700; min-height: var(--tap); cursor: pointer; }
.check-row input { width: 22px; height: 22px; accent-color: var(--accent); flex: none; }
.form-error { color: var(--danger); font-weight: 700; min-height: 1.4em; }

/* ------------------------------------------------------------------ login */

.login-page { display: grid; place-items: center; min-height: 72vh; }
.login-card {
  display: grid;
  justify-items: center;
  gap: 14px;
  width: min(420px, 100%);
  padding: 32px 24px;
  border-radius: calc(var(--radius) * 1.2);
  background: var(--surface);
  box-shadow: var(--shadow-lift);
  text-align: center;
}
.login-card .login-form { width: 100%; display: grid; gap: 12px; }
.login-card .btn { width: 100%; }

/* ---------------------------------------------------------------- dialogs */

.dialog {
  width: min(560px, calc(100vw - 24px));
  max-height: min(90vh, 900px);
  padding: 0;
  border: 0;
  border-radius: calc(var(--radius) * 1.1);
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 30px 80px -20px rgba(0, 0, 0, 0.45);
  animation: pop 0.2s var(--ease);
}
.dialog.small { width: min(420px, calc(100vw - 24px)); }
.dialog.wide { width: min(860px, calc(100vw - 24px)); }
.dialog.closing { animation: popOut 0.16s ease-in forwards; }
.dialog::backdrop { background: rgba(20, 16, 12, 0.5); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); }
@media (max-width: 600px) {
  .dialog:not(.full):not(.reveal):not(.wrapped) {
    width: 100vw;
    max-width: 100vw;
    max-height: 92vh;
    margin: auto 0 0;
    border-radius: calc(var(--radius) * 1.1) calc(var(--radius) * 1.1) 0 0;
    animation: sheet 0.25s var(--ease);
  }
  @keyframes sheet { from { transform: translateY(40px); opacity: 0; } }
}
.dialog-inner { display: flex; flex-direction: column; max-height: inherit; }
.dialog-head { display: flex; align-items: center; gap: 10px; padding: 14px 12px 8px 22px; }
.dialog-head h2 { flex: 1; }
.dialog-body { padding: 8px 22px 22px; overflow: auto; display: grid; gap: 16px; }
.dialog-foot {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  padding: 12px 22px calc(16px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
}
.confirm-text { font-size: 1.05rem; }

.dialog.full {
  width: 100vw;
  max-width: 100vw;
  height: 100dvh;
  max-height: none;
  border-radius: 0;
  background: #0d0b0a;
  color: #fff;
}
.lightbox .dialog-head { position: absolute; top: env(safe-area-inset-top); right: 0; z-index: 2; background: none; }
.lightbox .dialog-head h2 { display: none; }
.lightbox .dialog-x { color: #fff; background: rgba(255, 255, 255, 0.14); }
.lightbox .dialog-body { padding: 0; height: 100%; }
.lightbox-stage { position: relative; height: 100%; display: grid; place-items: center; }
.lightbox-img { max-width: 100%; max-height: calc(100dvh - 70px); object-fit: contain; }
.lightbox-caption { position: absolute; bottom: calc(14px + env(safe-area-inset-bottom)); left: 0; right: 0; text-align: center; font-size: 0.85rem; opacity: 0.8; padding: 0 16px; }
.lightbox-caption a { color: #fff; }

.theme-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
.theme-card {
  display: grid;
  gap: 4px;
  padding: 8px 8px 12px;
  text-align: left;
  border-radius: calc(var(--radius) * 0.8);
  border: 2px solid var(--line);
  background: var(--surface);
  color: var(--text);
  font-family: var(--font-body);
}
.theme-card[aria-pressed="true"] { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 30%, transparent); }
.theme-preview { display: grid; gap: 6px; padding: 10px; border-radius: calc(var(--radius) * 0.5); background: var(--bg); margin-bottom: 4px; }
.tp-plate { width: 34px; height: 34px; border-radius: 50%; background: var(--accent); }
.tp-title { font-family: var(--font-head); font-weight: var(--head-weight); font-size: calc(1.05rem * var(--head-scale)); line-height: 1.1; color: var(--text); }
.tp-row { display: flex; gap: 4px; align-items: center; }
.tp-chip { font-size: 0.68rem; padding: 1px 6px; border-radius: 999px; background: var(--soft); font-weight: 700; color: var(--text); }
.tp-star { margin-left: auto; font-size: 0.68rem; padding: 1px 6px; border-radius: 999px; background: color-mix(in srgb, var(--star) 20%, var(--surface)); font-weight: 800; color: var(--text); }
.theme-name { display: flex; align-items: center; justify-content: space-between; font-weight: 800; padding: 0 4px; }
.theme-name .icon { color: var(--accent); }
.theme-note { font-size: 0.8rem; color: var(--muted); padding: 0 4px; }

.settings-section { display: grid; gap: 10px; padding-bottom: 16px; border-bottom: 1px solid var(--line); }
.settings-section:last-child { border-bottom: 0; padding-bottom: 0; }
.toggle-row { display: flex; align-items: center; gap: 12px; min-height: var(--tap); }
.toggle-row .t { flex: 1; display: grid; }
.toggle-row .t small { color: var(--muted); font-weight: 600; }
.switch { position: relative; width: 52px; height: 30px; flex: none; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: var(--line); transition: background 0.2s; pointer-events: none; }
.switch span::after { content: ''; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.3); transition: transform 0.2s var(--ease); }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(22px); }
.switch input:focus-visible + span { outline: 3px solid color-mix(in srgb, var(--accent) 60%, transparent); outline-offset: 2px; }

/* ------------------------------------------------------------------ stats */

.filter-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 16px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.kpi { display: grid; gap: 2px; padding: 14px 16px; border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.kpi-label { font-size: 0.85rem; color: var(--muted); font-weight: 700; }
.kpi-value { font-size: 2rem; font-weight: 800; line-height: 1.15; font-family: var(--font-body); }
.kpi-note { font-size: 0.8rem; color: var(--muted); }

.chart-card { display: grid; gap: 10px; padding: 16px 18px; border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); min-width: 0; }
.chart-card h3 { font-family: var(--font-body); font-weight: 800; font-size: 1rem; }
.chart-card .sub { color: var(--muted); font-size: 0.86rem; margin-top: -6px; }
.chart-wrap { position: relative; width: 100%; }
.chart-wrap svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); gap: 14px; margin-top: 14px; }
.chart svg text { fill: var(--muted); font-size: 11px; font-family: var(--font-body); font-variant-numeric: tabular-nums; }
.chart svg text.strong { fill: var(--text); font-weight: 700; }
.chart .grid line { stroke: color-mix(in srgb, var(--line) 80%, var(--surface)); stroke-width: 1; }
.chart .axis line { stroke: var(--line); stroke-width: 1; }
.chart .mark { transition: opacity 0.15s; }
.chart .mark:hover, .chart .mark:focus { opacity: 0.75; outline: none; }
.chart .hit { fill: transparent; cursor: default; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 0.84rem; color: var(--muted); font-weight: 700; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.legend i.line { height: 3px; border-radius: 2px; width: 16px; }
.chart-tip {
  position: fixed;
  z-index: 200;
  pointer-events: none;
  padding: 8px 11px;
  border-radius: 10px;
  background: var(--text);
  color: var(--bg);
  font-size: 0.82rem;
  line-height: 1.35;
  box-shadow: var(--shadow-lift);
  max-width: 240px;
  transform: translate(-50%, calc(-100% - 12px));
}
.chart-tip b { display: block; font-size: 1rem; }
.table-toggle summary { cursor: pointer; color: var(--accent); font-weight: 700; font-size: 0.85rem; min-height: 32px; display: flex; align-items: center; }
.data-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; font-variant-numeric: tabular-nums; }
.data-table th, .data-table td { text-align: left; padding: 5px 8px; border-bottom: 1px solid var(--line); }
.data-table td.n, .data-table th.n { text-align: right; }
.table-scroll { max-height: 260px; overflow: auto; }

.bar-list { display: grid; gap: 8px; }
.bar-item { display: grid; grid-template-columns: minmax(80px, 30%) 1fr auto; align-items: center; gap: 10px; font-size: 0.92rem; }
.bar-item .lab { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-item .track { height: 14px; }
.bar-item .track i { display: block; height: 100%; min-width: 4px; border-radius: 0 4px 4px 0; background: var(--accent); }
.bar-item .val { font-weight: 800; font-variant-numeric: tabular-nums; }

.month-list { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---------------------------------------------------------------- wrapped */

.dialog.wrapped { width: min(480px, 100vw); height: min(100dvh, 860px); max-height: 100dvh; background: var(--accent); color: var(--accent-ink); }
@media (max-width: 600px) { .dialog.wrapped { width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh; border-radius: 0; margin: 0; } }
.wrapped .dialog-inner { height: 100%; }
.wrapped .dialog-head { position: absolute; top: env(safe-area-inset-top); right: 0; z-index: 3; }
.wrapped .dialog-head h2 { display: none; }
.wrapped .dialog-x { color: inherit; background: color-mix(in srgb, var(--accent-ink) 16%, transparent); }
.wrapped .dialog-body { height: 100%; padding: 0; }
.wr-stage { position: relative; height: 100%; display: grid; grid-template-rows: auto 1fr auto; padding: calc(16px + env(safe-area-inset-top)) 22px calc(20px + env(safe-area-inset-bottom)); }
.wr-bars { display: flex; gap: 4px; padding-right: 50px; }
.wr-bars i { flex: 1; height: 4px; border-radius: 2px; background: color-mix(in srgb, var(--accent-ink) 30%, transparent); }
.wr-bars i.on { background: var(--accent-ink); }
.wr-slide { display: grid; align-content: center; justify-items: center; gap: 14px; text-align: center; animation: rise 0.35s var(--ease); }
.wr-kicker { font-weight: 800; letter-spacing: 0.06em; text-transform: uppercase; font-size: 0.85rem; opacity: 0.85; }
.wr-big { font-family: var(--font-head); font-weight: var(--head-weight); font-size: calc(clamp(3.2rem, 18vw, 5.5rem) * var(--head-scale)); line-height: 1; }
.wr-text { font-size: 1.2rem; font-weight: 700; max-width: 26ch; }
.wr-emoji { font-size: 3.6rem; line-height: 1; }
.wr-nav { display: flex; justify-content: space-between; gap: 10px; }
.wr-nav .btn { background: color-mix(in srgb, var(--accent-ink) 18%, transparent); color: inherit; }
.wr-tap { position: absolute; top: 60px; bottom: 80px; width: 40%; border: 0; background: transparent; }
.wr-tap.prev { left: 0; }
.wr-tap.next { right: 0; }
.wr-mini { display: flex; gap: 3px; align-items: flex-end; height: 70px; }
.wr-mini i { width: 7px; border-radius: 3px 3px 0 0; background: var(--accent-ink); opacity: 0.85; }

/* ----------------------------------------------------------------- toasts */

.toasts {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 300;
  display: grid;
  gap: 8px;
  width: min(460px, calc(100vw - 28px));
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px 12px 18px;
  border-radius: 14px;
  background: var(--text);
  color: var(--bg);
  font-weight: 600;
  box-shadow: var(--shadow-lift);
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.2s, transform 0.2s var(--ease);
  pointer-events: auto;
}
.toast.in { opacity: 1; transform: none; }
.toast.bad { background: var(--danger); color: #fff; }
.toast > span { flex: 1; }
.toast-action { border: 0; background: color-mix(in srgb, var(--bg) 18%, transparent); color: inherit; font-weight: 800; padding: 6px 12px; border-radius: 999px; }

.confetti { position: fixed; inset: 0; width: 100vw; height: 100vh; pointer-events: none; z-index: 400; }

/* Calm mode and reduced motion: no movement beyond simple fades. */
html.calm *, html.calm *::before, html.calm *::after { transition-duration: 0.01ms !important; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}
