/* ==========================================================================
   Tokens
   ========================================================================== */
:root {
  --bg: #f6f3ff;
  --bg-accent:
    radial-gradient(1200px 600px at 10% -10%, #ece5ff 0%, transparent 60%),
    radial-gradient(900px 500px at 110% 0%, #fff1d6 0%, transparent 55%);
  --surface: #ffffff;
  --surface-2: #f3f0fb;
  --surface-3: #e9e4f7;
  --text: #1e1a33;
  --muted: #6c6787;
  --border: #e5e0f2;
  --primary: #6b4ef6;
  --primary-strong: #5537e8;
  --primary-soft: #ece7ff;
  --primary-ink: #ffffff;
  --gold: #f6b300;
  --gold-strong: #e09b00;
  --gold-soft: #fff4d1;
  --gold-ink: #3d2a00;
  --success: #17a34a;
  --success-soft: #dcf7e5;
  --warn: #e8890c;
  --warn-soft: #fff0da;
  --danger: #e0434b;
  --danger-soft: #fde6e7;
  --ring-track: #ebe6f8;

  --radius-sm: 10px;
  --radius: 16px;
  --radius-lg: 24px;
  --shadow-sm: 0 1px 2px rgba(30, 20, 70, 0.06);
  --shadow: 0 1px 2px rgba(30, 20, 70, 0.05), 0 8px 24px rgba(30, 20, 70, 0.07);
  --shadow-lg: 0 20px 60px rgba(30, 20, 70, 0.22);
  --font:
    ui-rounded, 'SF Pro Rounded', 'Nunito', 'Segoe UI Variable Display', system-ui, -apple-system, 'Segoe UI', Roboto,
    sans-serif;
  --mono: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  --tabbar-h: 64px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15131f;
    --bg-accent:
      radial-gradient(1000px 500px at 0% -10%, rgba(107, 78, 246, 0.18) 0%, transparent 60%),
      radial-gradient(800px 400px at 110% 0%, rgba(246, 179, 0, 0.08) 0%, transparent 55%);
    --surface: #1e1b2c;
    --surface-2: #262338;
    --surface-3: #312d47;
    --text: #f3f1fb;
    --muted: #a8a3c2;
    --border: #322e48;
    --primary: #8d76ff;
    --primary-strong: #a08dff;
    --primary-soft: rgba(141, 118, 255, 0.16);
    --gold-soft: rgba(246, 179, 0, 0.14);
    --success: #3ccf75;
    --success-soft: rgba(60, 207, 117, 0.14);
    --warn: #ffab3d;
    --warn-soft: rgba(255, 171, 61, 0.14);
    --danger: #ff6b72;
    --danger-soft: rgba(255, 107, 114, 0.14);
    --ring-track: #2d2943;
    --shadow-sm: none;
    --shadow: 0 1px 0 rgba(255, 255, 255, 0.03) inset, 0 8px 24px rgba(0, 0, 0, 0.25);
    --shadow-lg: 0 20px 60px rgba(0, 0, 0, 0.5);
  }
}

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

html {
  /* Keep the width steady when content height changes and a scrollbar comes and goes. */
  scrollbar-gutter: stable;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg-accent), var(--bg);
  background-attachment: fixed;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: clamp(1.6rem, 4vw, 2rem);
  line-height: 1.15;
  letter-spacing: -0.01em;
}

h2 {
  font-size: 1.15rem;
  line-height: 1.25;
}

h3 {
  font-size: 1rem;
}

a {
  color: var(--primary);
}

img {
  max-width: 100%;
  display: block;
}

[hidden] {
  display: none !important;
}

code {
  font-family: var(--mono);
  font-size: 0.88em;
  background: var(--surface-2);
  padding: 0.1em 0.35em;
  border-radius: 6px;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--primary) 55%, transparent);
  outline-offset: 2px;
}

.muted {
  color: var(--muted);
}

.hint {
  color: var(--muted);
  font-size: 0.85rem;
}

.eyebrow {
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.icon {
  width: 1.25em;
  height: 1.25em;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon--lg {
  width: 2rem;
  height: 2rem;
}

.icon--xl {
  width: 3rem;
  height: 3rem;
  stroke-width: 1.6;
}

/* Request progress bar */
html::before {
  content: '';
  position: fixed;
  inset: 0 0 auto 0;
  height: 3px;
  z-index: 1000;
  background: linear-gradient(90deg, var(--primary), var(--gold));
  transform: scaleX(0);
  transform-origin: left;
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
}

html.is-loading::before {
  opacity: 1;
  animation: loading-bar 1.4s ease-in-out infinite;
}

@keyframes loading-bar {
  0% {
    transform: scaleX(0);
    transform-origin: left;
  }
  50% {
    transform: scaleX(1);
    transform-origin: left;
  }
  51% {
    transform-origin: right;
  }
  100% {
    transform: scaleX(0);
    transform-origin: right;
  }
}

/* ==========================================================================
   Components
   ========================================================================== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 1.25rem;
}

.card__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

/* Buttons */
.btn {
  --btn-bg: var(--surface-2);
  --btn-fg: var(--text);
  --btn-border: transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  min-height: 44px;
  padding: 0.6rem 1.1rem;
  border-radius: 999px;
  border: 1.5px solid var(--btn-border);
  background: var(--btn-bg);
  color: var(--btn-fg);
  font-weight: 700;
  line-height: 1.1;
  text-decoration: none;
  white-space: nowrap;
  transition:
    transform 0.08s ease,
    background-color 0.15s ease,
    box-shadow 0.15s ease,
    opacity 0.15s ease;
  position: relative;
  user-select: none;
}

.btn:active:not(:disabled) {
  transform: scale(0.97);
}

.btn:disabled {
  opacity: 0.55;
  cursor: default;
}

.btn--primary {
  --btn-bg: var(--primary);
  --btn-fg: var(--primary-ink);
  box-shadow: 0 6px 16px color-mix(in srgb, var(--primary) 30%, transparent);
}

.btn--primary:hover:not(:disabled) {
  --btn-bg: var(--primary-strong);
}

.btn--gold {
  --btn-bg: linear-gradient(180deg, #ffd23f, var(--gold));
  background: var(--btn-bg);
  --btn-fg: var(--gold-ink);
  box-shadow:
    0 6px 0 var(--gold-strong),
    0 12px 24px rgba(224, 155, 0, 0.35);
}

.btn--gold:active:not(:disabled) {
  transform: translateY(3px);
  box-shadow:
    0 3px 0 var(--gold-strong),
    0 6px 14px rgba(224, 155, 0, 0.3);
}

.btn--ghost {
  --btn-bg: transparent;
  --btn-border: var(--border);
}

.btn--ghost:hover:not(:disabled) {
  --btn-bg: var(--surface-2);
}

.btn--danger {
  --btn-bg: var(--danger);
  --btn-fg: #fff;
}

.btn--sm {
  min-height: 36px;
  padding: 0.4rem 0.8rem;
  font-size: 0.88rem;
}

.btn--lg {
  min-height: 54px;
  padding: 0.85rem 1.5rem;
  font-size: 1.08rem;
}

.btn--block {
  width: 100%;
}

/* Spinner on the button that triggered a request */
.btn.htmx-request,
.htmx-request .btn[type='submit'],
.icon-btn.htmx-request {
  color: transparent !important;
}

.btn.htmx-request::after,
.htmx-request .btn[type='submit']::after,
.icon-btn.htmx-request::after {
  content: '';
  position: absolute;
  width: 1.1em;
  height: 1.1em;
  border-radius: 50%;
  border: 2.5px solid var(--btn-fg, var(--text));
  border-right-color: transparent;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 0;
  background: transparent;
  color: var(--muted);
  position: relative;
  text-decoration: none;
  flex: none;
}

.icon-btn:hover:not(:disabled) {
  background: var(--surface-2);
  color: var(--text);
}

.icon-btn:disabled,
.icon-btn[aria-disabled='true'] {
  opacity: 0.35;
  cursor: default;
}

.icon-btn--danger:hover:not(:disabled) {
  background: var(--danger-soft);
  color: var(--danger);
}

/* Pills & chips */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.2rem 0.65rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
  background: var(--surface-2);
  color: var(--muted);
  white-space: nowrap;
}

.pill--success {
  background: var(--success-soft);
  color: var(--success);
}

.pill--primary {
  background: var(--primary-soft);
  color: var(--primary);
}

.pill--gold {
  background: var(--gold-soft);
  color: var(--gold-strong);
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  font-size: 0.88rem;
  font-weight: 600;
}

.chip--streak {
  background: linear-gradient(135deg, #fff1d1, #ffe0c2);
  color: #9a4a00;
}

.chip--streak .icon {
  fill: #ff8a00;
  stroke: #ff6a00;
  stroke-width: 1.2;
}

@media (prefers-color-scheme: dark) {
  .chip--streak {
    background: rgba(255, 138, 0, 0.16);
    color: #ffc285;
  }
}

/* Meter: progress with a target marker */
.meter {
  position: relative;
  height: 8px;
  border-radius: 999px;
  background: var(--surface-3);
  margin-top: 0.55rem;
  overflow: visible;
}

.meter__fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: var(--value);
  border-radius: inherit;
  background: var(--warn);
  transition: width 0.5s ease;
}

.task--success .meter__fill,
.meter--plain .meter__fill {
  background: var(--success);
}

.meter--plain .meter__fill {
  background: var(--primary);
}

.meter__target {
  position: absolute;
  top: -3px;
  bottom: -3px;
  left: var(--target);
  width: 3px;
  margin-left: -1.5px;
  border-radius: 2px;
  background: var(--text);
  opacity: 0.55;
}

/* Empty states */
.empty {
  display: grid;
  justify-items: center;
  gap: 0.6rem;
  text-align: center;
  padding: 2rem 1rem;
  color: var(--muted);
}

.empty h2 {
  color: var(--text);
}

.empty .icon {
  color: var(--primary);
  opacity: 0.7;
}

/* Coupon art placeholder */
.art-placeholder {
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  width: 100%;
  background: linear-gradient(135deg, var(--primary-soft), var(--gold-soft));
  color: var(--primary);
}

.art-placeholder .icon {
  width: 40%;
  height: 40%;
  stroke-width: 1.5;
}

/* Section headings */
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin: 1.75rem 0 0.75rem;
}

.section-head--page {
  margin-top: 0.25rem;
  margin-bottom: 1.25rem;
}

.section-head--page p {
  margin-top: 0.25rem;
}

.card .section-head:first-child {
  margin-top: 0;
}

.subhead {
  margin: 1.5rem 0 0.75rem;
  font-size: 0.95rem;
  color: var(--muted);
}

/* Mini coupon rows */
.mini-list {
  display: grid;
  gap: 0.6rem;
}

.mini {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 0.6rem 0.85rem 0.6rem 0.6rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.card .mini {
  background: var(--surface-2);
  border-color: transparent;
}

.mini__art {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  object-fit: cover;
  flex: none;
}

.mini__text {
  display: grid;
  min-width: 0;
  flex: 1;
}

.mini__text strong {
  overflow-wrap: anywhere;
}

.mini__text span {
  font-size: 0.85rem;
  color: var(--muted);
}

/* Toasts */
.toasts {
  position: fixed;
  left: 50%;
  bottom: calc(var(--toast-offset, 1.25rem) + var(--safe-bottom));
  transform: translateX(-50%);
  display: grid;
  gap: 0.5rem;
  width: min(92vw, 420px);
  z-index: 900;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.8rem 1rem;
  border-radius: var(--radius);
  background: #1e1a33;
  color: #fff;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transform: translateY(12px) scale(0.98);
  transition:
    opacity 0.2s ease,
    transform 0.2s ease;
}

.toast.is-visible {
  opacity: 1;
  transform: none;
}

.toast--success .icon {
  color: #6ee7a1;
}

.toast--error {
  background: var(--danger);
}

@media (prefers-color-scheme: dark) {
  .toast {
    background: #f3f1fb;
    color: #1e1a33;
  }
  .toast--success .icon {
    color: var(--success);
  }
  .toast--error {
    background: var(--danger);
    color: #fff;
  }
}

/* Confirm sheet */
dialog {
  color: var(--text);
}

dialog::backdrop {
  background: rgba(20, 14, 45, 0.45);
  backdrop-filter: blur(3px);
}

.sheet {
  width: min(92vw, 400px);
  padding: 0;
  border: 0;
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
}

.sheet[open] {
  animation: pop-in 0.18s ease-out;
}

.sheet__inner {
  display: grid;
  gap: 0.75rem;
  padding: 1.5rem;
  text-align: center;
}

.sheet__image {
  width: 140px;
  height: 140px;
  margin: 0 auto 0.25rem;
  border-radius: var(--radius);
  object-fit: cover;
  box-shadow: var(--shadow);
}

.sheet__title {
  font-size: 1.3rem;
}

.sheet__text {
  color: var(--muted);
}

.sheet__actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
  margin-top: 0.5rem;
}

@keyframes pop-in {
  from {
    opacity: 0;
    transform: scale(0.94) translateY(8px);
  }
}

/* ==========================================================================
   Kid view
   ========================================================================== */
.kid {
  --toast-offset: calc(var(--tabbar-h) + 1rem);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(1.4) blur(14px);
  -webkit-backdrop-filter: saturate(1.4) blur(14px);
  padding-top: env(safe-area-inset-top, 0px);
}

.topbar__inner {
  max-width: 1180px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.7rem 1rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-weight: 800;
  font-size: 1.1rem;
  color: var(--text);
  text-decoration: none;
}

.brand img {
  border-radius: 9px;
}

.page {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0.5rem 1rem calc(var(--tabbar-h) + 2rem + var(--safe-bottom));
}

/* Tab bar: bottom on phones, floating pill on wide screens */
.tabbar {
  position: fixed;
  inset: auto 0 0 0;
  z-index: 60;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  height: calc(var(--tabbar-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(1.4) blur(14px);
  -webkit-backdrop-filter: saturate(1.4) blur(14px);
  border-top: 1px solid var(--border);
}

.tabbar__tab {
  position: relative;
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 0.15rem;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 700;
}

.tabbar__tab .icon {
  width: 26px;
  height: 26px;
}

.tabbar__tab[aria-selected='true'] {
  color: var(--primary);
}

.tabbar__tab[aria-selected='true'] .icon {
  stroke-width: 2.4;
}

.tabbar__badge {
  position: absolute;
  top: 6px;
  left: calc(50% + 6px);
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--gold);
  color: var(--gold-ink);
  font-size: 0.72rem;
  font-weight: 800;
  line-height: 20px;
  text-align: center;
}

.tabbar__badge:empty {
  display: none;
}

@media (min-width: 720px) {
  .kid {
    --toast-offset: 1.5rem;
  }
  .tabbar {
    position: sticky;
    top: calc(56px + env(safe-area-inset-top, 0px));
    inset: auto;
    width: max-content;
    margin: 0.25rem auto 1.25rem;
    height: auto;
    padding: 0.3rem;
    gap: 0.25rem;
    grid-template-columns: repeat(3, auto);
    border: 1px solid var(--border);
    border-radius: 999px;
    box-shadow: var(--shadow);
  }
  .tabbar__tab {
    grid-auto-flow: column;
    gap: 0.45rem;
    padding: 0.55rem 1.1rem;
    border-radius: 999px;
    font-size: 0.95rem;
  }
  .tabbar__tab .icon {
    width: 20px;
    height: 20px;
  }
  .tabbar__tab[aria-selected='true'] {
    background: var(--primary-soft);
  }
  .tabbar__badge {
    position: static;
  }
  .page {
    padding-bottom: 3rem;
  }
}

.tab-panel[hidden] {
  display: none;
}

/* Hero with progress ring */
.hero {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  padding: 1.25rem 1.4rem;
}

.ring {
  --size: 104px;
  flex: none;
  width: var(--size);
  height: var(--size);
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: conic-gradient(var(--primary) calc(var(--progress) * 1turn), var(--ring-track) 0);
  transition: background 0.4s;
}

.ring--done {
  background: conic-gradient(var(--success) 1turn, var(--success) 0);
}

.ring__inner {
  width: calc(var(--size) - 22px);
  height: calc(var(--size) - 22px);
  border-radius: 50%;
  background: var(--surface);
  display: grid;
  place-content: center;
  text-align: center;
  line-height: 1;
}

.ring__inner strong {
  font-size: 1.8rem;
  font-weight: 800;
}

.ring__inner small {
  font-size: 1rem;
  color: var(--muted);
}

.ring__inner span {
  font-size: 0.78rem;
  color: var(--muted);
  font-weight: 600;
  margin-top: 0.2rem;
}

.ring--done .ring__inner {
  color: var(--success);
}

.ring--done .icon {
  stroke-width: 3;
}

.hero__text {
  display: grid;
  gap: 0.3rem;
  min-width: 0;
}

.hero__message {
  color: var(--muted);
  font-size: 1.02rem;
}

/* Reward banner */
.reward {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-top: 1rem;
  padding: 1.1rem 1.25rem;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.reward__icon {
  display: grid;
  place-items: center;
  flex: none;
  width: 56px;
  height: 56px;
  border-radius: 18px;
  background: var(--surface-2);
  color: var(--muted);
}

.reward__icon .icon {
  width: 30px;
  height: 30px;
}

.reward__text {
  flex: 1;
  min-width: 0;
  display: grid;
  gap: 0.2rem;
}

.reward__text p {
  color: var(--muted);
}

.reward__art img,
.reward__art .art-placeholder {
  width: 72px;
  height: 72px;
  border-radius: 16px;
  object-fit: cover;
  box-shadow: var(--shadow);
}

.reward--ready {
  flex-wrap: wrap;
  border: 0;
  background:
    radial-gradient(circle at 15% 20%, rgba(255, 255, 255, 0.35) 0, transparent 40%),
    linear-gradient(135deg, #7b5cff, #b14dff 55%, #ff7aa8);
  color: #fff;
  box-shadow: 0 16px 40px rgba(123, 92, 255, 0.35);
}

.reward--ready .reward__text p {
  color: rgba(255, 255, 255, 0.88);
}

.reward--ready .reward__icon {
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
  animation: wiggle 2.4s ease-in-out infinite;
}

.reward--ready .btn {
  flex: 1 1 100%;
}

@keyframes wiggle {
  0%,
  80%,
  100% {
    transform: rotate(0);
  }
  85% {
    transform: rotate(-12deg) scale(1.08);
  }
  90% {
    transform: rotate(10deg) scale(1.08);
  }
  95% {
    transform: rotate(-6deg);
  }
}

.reward--claimed {
  background: linear-gradient(135deg, var(--gold-soft), var(--surface) 70%);
  border-color: color-mix(in srgb, var(--gold) 35%, var(--border));
}

.reward--locked .reward__text p {
  font-size: 0.92rem;
}

@media (max-width: 480px) {
  .reward--claimed {
    flex-wrap: wrap;
  }
  .reward--claimed .btn {
    flex: 1 1 100%;
  }
}

/* Task list */
.tasks {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.6rem;
}

.task {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  padding: 0.9rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.card .task {
  box-shadow: none;
}

.task__status {
  display: grid;
  place-items: center;
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--muted);
}

.task--success .task__status {
  background: var(--success);
  color: #fff;
}

.task--success .task__status .icon {
  stroke-width: 3;
}

.task--pending .task__status {
  background: var(--warn-soft);
  color: var(--warn);
}

.task--missing .task__status .icon {
  stroke-dasharray: 3 3.6;
}

.task--untracked {
  opacity: 0.7;
}

.task__body {
  flex: 1;
  min-width: 0;
}

.task__title {
  font-weight: 700;
  overflow-wrap: anywhere;
}

.task__detail {
  font-size: 0.86rem;
  color: var(--muted);
}

.task__aside {
  display: grid;
  justify-items: end;
  flex: none;
  text-align: right;
}

.score {
  font-size: 1.25rem;
  font-weight: 800;
  line-height: 1.1;
}

.task--success .score {
  color: var(--success);
}

.task--pending .score {
  color: var(--warn);
}

.score__sub {
  font-size: 0.78rem;
  color: var(--muted);
}

/* Wallet */
.wallet-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 0.9rem;
}

.ticket {
  position: relative;
  display: grid;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.ticket__art {
  position: relative;
  aspect-ratio: 1;
  background: var(--surface-2);
}

.ticket__art img,
.ticket__art .art-placeholder {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.ticket__count {
  position: absolute;
  top: 0.6rem;
  right: 0.6rem;
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  background: var(--gold);
  color: var(--gold-ink);
  font-weight: 800;
  font-size: 0.9rem;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
}

.ticket__body {
  position: relative;
  display: grid;
  gap: 0.7rem;
  grid-template-rows: 1fr auto;
  padding: 0.85rem;
  border-top: 2px dashed var(--border);
}

/* Perforated edge between the picture and the button */
.ticket__body::before,
.ticket__body::after {
  content: '';
  position: absolute;
  top: -10px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--bg);
  border: 1px solid var(--border);
}

.ticket__body::before {
  left: -10px;
}

.ticket__body::after {
  right: -10px;
}

.ticket__body h3 {
  font-size: 0.98rem;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

@media (min-width: 560px) {
  .wallet-grid {
    grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  }
}

/* Calendar */
.calendar__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.85rem;
}

.calendar__title {
  text-align: center;
}

.calendar__title p {
  font-size: 0.85rem;
}

.calendar__grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 0.35rem;
}

.calendar__dow {
  text-align: center;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--muted);
  padding-bottom: 0.2rem;
}

.day {
  position: relative;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 14px;
  background: var(--surface-2);
  color: var(--text);
  font-weight: 700;
  font-size: 0.95rem;
  padding: 0;
}

.day--blank {
  background: none;
}

.day:disabled {
  background: none;
  color: var(--muted);
  opacity: 0.5;
  cursor: default;
}

.day--partial {
  background: var(--primary-soft);
}

.day--earned {
  background: linear-gradient(160deg, #ffd23f, var(--gold));
  color: var(--gold-ink);
}

.day__num {
  position: relative;
  z-index: 1;
}

.day__star {
  position: absolute;
  top: 3px;
  right: 3px;
  width: 13px;
  height: 13px;
  fill: #fff;
  stroke: none;
}

.day--today {
  box-shadow: inset 0 0 0 2px var(--primary);
}

.day--selected {
  box-shadow:
    0 0 0 2px var(--surface),
    0 0 0 4px var(--primary);
}

.day__dots {
  position: absolute;
  bottom: 4px;
  display: flex;
  gap: 3px;
}

.dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
}

.dot--bonus {
  background: var(--primary);
}

.dot--used {
  background: var(--success);
}

.day--earned .dot--bonus {
  background: #5a2fd6;
}

.day--earned .dot--used {
  background: #0d7a35;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 1rem;
  margin-top: 1rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.legend__swatch {
  width: 14px;
  height: 14px;
  border-radius: 5px;
}

.legend__swatch--earned {
  background: var(--gold);
}

.legend__swatch--partial {
  background: var(--primary-soft);
  border: 1px solid color-mix(in srgb, var(--primary) 25%, transparent);
}

.history-day {
  margin-top: 1rem;
}

.history-day.htmx-request {
  opacity: 0.6;
  transition: opacity 0.2s;
}

/* Reward reveal */
.reveal {
  width: min(92vw, 380px);
  border: 0;
  border-radius: 28px;
  padding: 1.75rem 1.5rem 1.5rem;
  text-align: center;
  background: radial-gradient(circle at 50% 0%, var(--gold-soft) 0, transparent 60%), var(--surface);
  box-shadow: var(--shadow-lg);
  overflow: visible;
}

.reveal[open] {
  display: grid;
  gap: 0.6rem;
  animation: reveal-in 0.55s cubic-bezier(0.2, 1.4, 0.4, 1);
}

.reveal__card {
  width: 220px;
  max-width: 70vw;
  margin: 0.5rem auto;
  border-radius: 22px;
  overflow: hidden;
  box-shadow:
    0 0 0 4px #fff,
    0 0 0 8px var(--gold),
    0 18px 40px rgba(224, 155, 0, 0.35);
  animation: flip-in 0.8s 0.1s cubic-bezier(0.2, 1.2, 0.4, 1) both;
}

.reveal__card img,
.reveal__card .art-placeholder {
  width: 100%;
  height: auto;
}

.reveal h2 {
  font-size: 1.5rem;
  overflow-wrap: anywhere;
}

.reveal form {
  margin-top: 0.5rem;
}

@keyframes reveal-in {
  from {
    opacity: 0;
    transform: scale(0.6);
  }
}

@keyframes flip-in {
  from {
    transform: perspective(600px) rotateY(180deg) scale(0.7);
    opacity: 0;
  }
}

.confetti {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: visible;
}

.confetti i {
  --hue: calc(var(--i) * 47deg);
  position: absolute;
  top: 30%;
  left: 50%;
  width: 9px;
  height: 14px;
  border-radius: 2px;
  background: hsl(var(--hue) 90% 60%);
  opacity: 0;
  animation: confetti 1.6s calc(var(--i) * 0.02s) ease-out forwards;
}

.confetti i:nth-child(3n) {
  border-radius: 50%;
  width: 10px;
  height: 10px;
}

@keyframes confetti {
  0% {
    opacity: 1;
    transform: translate(-50%, 0) rotate(0);
  }
  100% {
    opacity: 0;
    transform: translate(calc(-50% + (var(--i) - 12) * 16px), calc(-160px + (var(--i) * 13 % 7) * 60px))
      rotate(calc(var(--i) * 97deg));
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ==========================================================================
   Admin
   ========================================================================== */
.admin-shell {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100dvh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  padding: 1.25rem 0.9rem;
  border-right: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 70%, transparent);
}

.sidebar .brand {
  padding: 0 0.5rem;
}

.sidenav {
  display: grid;
  gap: 0.2rem;
}

.sidenav__link {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  width: 100%;
  padding: 0.65rem 0.8rem;
  border: 0;
  border-radius: 12px;
  background: none;
  color: var(--muted);
  font-weight: 600;
  text-decoration: none;
  text-align: left;
}

.sidenav__link:hover {
  background: var(--surface-2);
  color: var(--text);
}

.sidenav__link.is-active {
  background: var(--primary-soft);
  color: var(--primary);
}

.sidebar__foot {
  margin-top: auto;
  display: grid;
  gap: 0.2rem;
}

.sidebar__foot form {
  margin: 0;
}

.admin-main {
  min-width: 0;
  max-width: 1120px;
  padding: 2rem 2rem 4rem;
}

.page-head {
  margin-bottom: 1.5rem;
}

.page-head p {
  margin-top: 0.3rem;
}

.admin-body {
  display: grid;
  gap: 1.25rem;
}

.admin-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 380px), 1fr));
  gap: 1.25rem;
  align-items: start;
}

@media (max-width: 860px) {
  .admin-shell {
    grid-template-columns: minmax(0, 1fr);
  }
  .sidebar {
    position: sticky;
    z-index: 50;
    min-width: 0;
    height: auto;
    flex-direction: row;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    padding-top: calc(0.5rem + env(safe-area-inset-top, 0px));
    border-right: 0;
    border-bottom: 1px solid var(--border);
    background: color-mix(in srgb, var(--surface) 90%, transparent);
    backdrop-filter: blur(14px);
    overflow-x: auto;
    scrollbar-width: none;
  }
  .sidebar .brand span,
  .sidebar__foot .sidenav__link span {
    display: none;
  }
  .sidebar .brand {
    padding: 0;
    flex: none;
  }
  .sidenav {
    display: flex;
    gap: 0.15rem;
  }
  .sidenav__link {
    padding: 0.5rem 0.7rem;
    white-space: nowrap;
  }
  .sidebar__foot {
    margin: 0 0 0 auto;
    display: flex;
  }
  .admin-main {
    padding: 1.25rem 1rem 3rem;
  }
}

@media (max-width: 520px) {
  .sidenav .sidenav__link span {
    display: none;
  }
  .sidenav .sidenav__link.is-active span {
    display: inline;
  }
}

/* Stats */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0.9rem;
}

.stat {
  display: grid;
  gap: 0.2rem;
  padding: 1rem 1.1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.stat__label {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--muted);
}

.stat__value {
  font-size: 1.7rem;
  font-weight: 800;
  line-height: 1.1;
}

.stat__value small {
  font-size: 0.9rem;
  color: var(--muted);
  font-weight: 600;
}

.stat__value--text {
  font-size: 1.1rem;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.stat__hint {
  font-size: 0.8rem;
  color: var(--muted);
}

/* Rows (generic list items in admin cards) */
.rows {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
}

.row {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  padding: 0.7rem 0;
  border-bottom: 1px solid var(--border);
}

.row:last-child {
  border-bottom: 0;
}

.row--wrap {
  flex-wrap: wrap;
}

.row__art {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  object-fit: cover;
  flex: none;
}

.row__main {
  flex: 1;
  min-width: 140px;
  display: grid;
}

.row__main .muted {
  font-size: 0.85rem;
}

.row__actions {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  flex: none;
}

.status-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--surface-3);
  flex: none;
}

.status-dot--success {
  background: var(--success);
}

.status-dot--pending {
  background: var(--warn);
}

/* Tables */
.table-wrap {
  overflow-x: auto;
  margin: 0 -1.25rem;
  padding: 0 1.25rem;
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}

.table th {
  text-align: left;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0 0.75rem 0.6rem 0;
  border-bottom: 1px solid var(--border);
}

.table td {
  padding: 0.7rem 0.75rem 0.7rem 0;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.table tr:last-child td {
  border-bottom: 0;
}

.table__actions {
  text-align: right;
  white-space: nowrap;
}

.table__edit td {
  background: var(--surface-2);
  padding: 1rem;
  border-radius: var(--radius);
}

/* Forms */
.form {
  display: grid;
  gap: 1rem;
}

.form--inline {
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  align-items: end;
}

.field {
  display: grid;
  gap: 0.35rem;
  margin: 0;
  padding: 0;
  border: 0;
  min-width: 0;
}

.field--inline {
  grid-auto-flow: column;
  align-items: center;
  justify-content: start;
  gap: 0.6rem;
}

.field__label {
  font-size: 0.85rem;
  font-weight: 700;
  padding: 0;
}

input[type='text'],
input[type='password'],
input[type='number'],
input[type='date'],
select {
  width: 100%;
  min-height: 44px;
  padding: 0.55rem 0.8rem;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  transition:
    border-color 0.15s,
    box-shadow 0.15s;
}

input:focus,
select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 4px var(--primary-soft);
}

input[type='file'] {
  font-size: 0.9rem;
  max-width: 100%;
}

input[type='file']::file-selector-button {
  margin-right: 0.75rem;
  padding: 0.5rem 0.9rem;
  border: 0;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 700;
  cursor: pointer;
}

.input-suffix {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  max-width: 160px;
}

.input-suffix span {
  color: var(--muted);
  font-weight: 700;
}

.form-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.form-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-top: 1rem;
}

.field--inline select {
  width: auto;
}

.segmented {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.segmented label {
  position: relative;
}

.segmented input {
  position: absolute;
  opacity: 0;
  inset: 0;
}

.segmented span {
  display: inline-block;
  padding: 0.55rem 0.95rem;
  border: 1.5px solid var(--border);
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.92rem;
  cursor: pointer;
}

.segmented input:checked + span {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary);
}

.segmented input:focus-visible + span {
  box-shadow: 0 0 0 4px var(--primary-soft);
}

.app-form:has(input[value='user_reported']:checked) .threshold-field {
  display: none;
}

.score-form {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.score-form input {
  width: 70px;
  min-height: 36px;
  padding: 0.35rem 0.5rem;
}

.disclosure {
  margin-top: 1rem;
  border-top: 1px solid var(--border);
  padding-top: 0.9rem;
}

.disclosure summary {
  cursor: pointer;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 0.9rem;
}

.code {
  margin: 0.6rem 0;
  padding: 0.8rem 1rem;
  border-radius: 12px;
  background: var(--surface-2);
  font-family: var(--mono);
  font-size: 0.85rem;
  overflow-x: auto;
}

.notice {
  padding: 0.7rem 0.9rem;
  border-radius: 12px;
  font-weight: 600;
}

.notice--error {
  background: var(--danger-soft);
  color: var(--danger);
}

/* Award picker */
.choice-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 0.6rem;
}

.choice {
  position: relative;
  display: grid;
  gap: 0.4rem;
  padding: 0.5rem;
  border: 2px solid var(--border);
  border-radius: 14px;
  cursor: pointer;
  text-align: center;
  transition:
    border-color 0.15s,
    background 0.15s;
}

.choice input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.choice__art {
  width: 100%;
  height: auto;
  aspect-ratio: 1;
  border-radius: 10px;
  object-fit: cover;
}

.choice__label {
  font-size: 0.78rem;
  font-weight: 600;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.choice:has(input:checked) {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.choice:has(input:focus-visible) {
  box-shadow: 0 0 0 4px var(--primary-soft);
}

/* Reward library */
.reward-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 1rem;
}

.reward-card {
  display: grid;
  grid-template-rows: auto 1fr;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}

.reward-card > form {
  display: contents;
}

.reward-card__art {
  aspect-ratio: 16 / 10;
  background: var(--surface-2);
  overflow: hidden;
}

.reward-card__art img,
.reward-card__art .art-placeholder {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.reward-card__body {
  display: grid;
  gap: 0.5rem;
  align-content: start;
  padding: 0.9rem 1rem 1rem;
}

.reward-card__body h3 {
  overflow-wrap: anywhere;
}

.reward-card__chance {
  display: flex;
  justify-content: space-between;
  font-size: 0.88rem;
  color: var(--muted);
}

.reward-card__chance strong {
  color: var(--text);
}

.reward-card .meter {
  margin-top: 0;
}

.reward-card__actions {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-wrap: wrap;
  margin-top: 0.25rem;
}

.reward-card__actions .icon-btn {
  margin-left: auto;
}

.reward-card--archived {
  opacity: 0.75;
}

.reward-card--archived .reward-card__art {
  filter: grayscale(0.8);
}

.reward-card--editing {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px var(--primary-soft);
}

.image-picker {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.image-picker__preview {
  display: grid;
  place-items: center;
  width: 96px;
  height: 96px;
  border-radius: 16px;
  background: var(--surface-2);
  color: var(--muted);
  overflow: hidden;
  flex: none;
}

.image-picker__preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Activity date nav */
.date-nav {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  padding: 0.75rem 1rem;
}

.date-nav__form {
  margin: 0;
}

.date-nav__form input {
  width: auto;
}

.date-nav__label {
  margin-left: auto;
}

/* Login */
.admin--login {
  display: grid;
  place-items: center;
  padding: 1.5rem;
}

.login {
  width: min(100%, 400px);
}

.login__card {
  display: grid;
  gap: 1rem;
  padding: 2rem 1.75rem;
  text-align: center;
}

.login__card img {
  margin: 0 auto;
  border-radius: 14px;
}

.login__card .field {
  text-align: left;
}

.login__back {
  font-size: 0.9rem;
  text-decoration: none;
}

/* Let cards shrink on phones so tables scroll inside them instead of widening the page */
.admin-body > *,
.admin-grid > * {
  min-width: 0;
}

@media (max-width: 560px) {
  .row {
    flex-wrap: wrap;
  }
  .row__actions {
    margin-left: auto;
  }
}

/* Tablet landscape (the main way this is used): side-by-side columns */
@media (min-width: 960px) {
  .page,
  .topbar__inner {
    padding-left: 1.75rem;
    padding-right: 1.75rem;
  }
  .today-layout {
    display: grid;
    grid-template-columns: minmax(0, 5fr) minmax(0, 6fr);
    gap: 1.5rem;
    align-items: start;
  }
  .today-layout__main {
    position: sticky;
    top: 8.5rem;
  }
  .today-layout__side > .section-head:first-child {
    margin-top: 0;
  }
  .hero {
    padding: 1.6rem;
  }
  .ring {
    --size: 120px;
  }
  .history-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 1.5rem;
    align-items: start;
  }
  .history-layout .history-day {
    margin-top: 0;
  }
  .history-layout .calendar {
    position: sticky;
    top: 8.5rem;
  }
  .wallet-grid {
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1.1rem;
  }
}
