:root {
  --bg: #f6f7f9;
  --card: #ffffff;
  --text: #1c2733;
  --muted: #66707c;
  --accent: #2563eb;
  --accent-text: #ffffff;
  --earn: #157f3d;
  --spend: #b42318;
  --border: #e2e6ea;
  --gold: #eab308;
  --radius: 12px;
  --font-display: ui-rounded, "SF Pro Rounded", -apple-system,
    BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161b;
    --card: #1b2129;
    --text: #e8ecf1;
    --muted: #97a1ac;
    --accent: #5b8cf2;
    /* Dark mode flips accent surfaces to bright hue + ink text —
       brighter accents can't carry white text at AA contrast. */
    --accent-text: #0d1117;
    --earn: #4ade80;
    --spend: #f87171;
    --border: #2a323d;
  }
}

/* Per-child accents (Profile.accent): scoping one of these classes on a
   card or page recolors everything inside that uses --accent. */
.accent-sky { --accent: #2563eb; }
.accent-coral { --accent: #c2410c; }
.accent-grape { --accent: #6d28d9; }
.accent-teal { --accent: #0f766e; }
.accent-berry { --accent: #be185d; }

@media (prefers-color-scheme: dark) {
  .accent-sky { --accent: #5b8cf2; }
  .accent-coral { --accent: #f97316; }
  .accent-grape { --accent: #a78bfa; }
  .accent-teal { --accent: #2dd4bf; }
  .accent-berry { --accent: #f472b6; }
}

* { box-sizing: border-box; }

a, button, summary { touch-action: manipulation; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  line-height: 1.5;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.25rem 1rem;
  padding-top: calc(0.25rem + env(safe-area-inset-top));
  padding-left: calc(1rem + env(safe-area-inset-left));
  padding-right: calc(1rem + env(safe-area-inset-right));
  background: var(--card);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--text);
  text-decoration: none;
}

.link-button {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 1rem;
  cursor: pointer;
  min-height: 44px;
  padding: 0.5rem;
}

.container {
  max-width: 34rem;
  margin: 0 auto;
  padding: 1rem;
  padding-bottom: calc(1rem + env(safe-area-inset-bottom));
  padding-left: calc(1rem + env(safe-area-inset-left));
  padding-right: calc(1rem + env(safe-area-inset-right));
}

h1 { font-size: 1.4rem; margin: 0.5rem 0 1rem; }
h2 { font-size: 1.1rem; margin: 1.5rem 0 0.5rem; }

.brand,
h1,
h2,
.big-balance .number,
.balance-pill,
.milestone-banner {
  font-family: var(--font-display);
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 0.75rem;
}

.child-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  text-decoration: none;
  color: var(--text);
  min-height: 64px;
}

.child-link .name { font-weight: 600; font-size: 1.05rem; }

.pills {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.requests-pill {
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  color: var(--accent);
  border-radius: 999px;
  padding: 0.25rem 0.7rem;
  font-weight: 700;
  font-size: 0.9rem;
  white-space: nowrap;
}

.balance-pill {
  background: var(--accent);
  color: var(--accent-text);
  border-radius: 999px;
  padding: 0.25rem 0.9rem;
  font-weight: 700;
  font-size: 1.05rem;
  white-space: nowrap;
}

.big-balance {
  text-align: center;
  padding: 1.5rem 1rem;
}

.big-balance .number {
  font-size: 3.5rem;
  font-weight: 800;
  line-height: 1.1;
  color: var(--accent);
}

.big-balance .label {
  color: var(--muted);
  font-size: 0.95rem;
}

.child-context {
  position: sticky;
  top: calc(0.5rem + env(safe-area-inset-top));
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  box-shadow: 0 5px 18px rgba(0, 0, 0, 0.08);
}

.child-context h1 {
  min-width: 0;
  margin: 0;
}

.child-context .balance-pill { flex: 0 0 auto; }

.row-list { list-style: none; margin: 0; padding: 0; }

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

.row-list li:last-child { border-bottom: none; }

.row-list .delta {
  font-weight: 700;
  min-width: 2.8rem;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.row-list .delta.earn { color: var(--earn); }
.row-list .delta.spend { color: var(--spend); }

.row-list .what { flex: 1; }

.row-list .when {
  color: var(--muted);
  font-size: 0.8rem;
  white-space: nowrap;
}

form p { margin: 0 0 0.75rem; }

form label {
  display: block;
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
}

input[type="text"],
input[type="number"],
input[type="password"] {
  width: 100%;
  min-height: 44px;
  padding: 0.65rem 0.75rem;
  font-size: 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
}

button[type="submit"]:not(.link-button):not(.chip):not(.row-delete):not(.inline):not(.avatar-choice),
button.btn-primary {
  width: 100%;
  min-height: 44px;
  padding: 0.7rem;
  font-size: 1rem;
  font-weight: 600;
  color: var(--accent-text);
  background: var(--accent);
  border: none;
  border-radius: 8px;
  cursor: pointer;
}

button.danger { background: var(--spend); }

.flash {
  padding: 0.7rem 1rem;
  border-radius: 8px;
  margin-bottom: 1rem;
  background: var(--card);
  border: 1px solid var(--border);
}

.flash-success { border-color: var(--earn); }
.flash-error { border-color: var(--spend); }

.errorlist {
  list-style: none;
  margin: 0 0 0.5rem;
  padding: 0;
  color: var(--spend);
  font-size: 0.9rem;
}

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

.avatar-link-wrap {
  text-align: center;
  margin: -0.25rem 0 1rem;
}

.avatar-picker-link {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0.45rem 0.9rem;
  color: var(--accent);
  font-size: 0.9rem;
  font-weight: 600;
  text-decoration: none;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 999px;
}

.avatar-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(44px, 1fr));
  gap: 0.4rem;
  justify-items: center;
}

button.avatar-choice {
  position: relative;
  width: 44px;
  min-height: 44px;
  padding: 0;
  font-size: 1.35rem;
  line-height: 1.2;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 50%;
  cursor: pointer;
}

button.avatar-choice.selected {
  background: color-mix(in srgb, var(--accent) 14%, var(--card));
  border: 2px solid var(--accent);
}

.selected-mark {
  position: absolute;
  right: -0.2rem;
  bottom: -0.15rem;
  display: grid;
  width: 1.1rem;
  height: 1.1rem;
  place-items: center;
  color: var(--accent-text);
  background: var(--accent);
  border-radius: 50%;
  font-size: 0.7rem;
  font-weight: 800;
}

.avatar-help {
  margin: -0.5rem 0 0.75rem;
}

.avatar-editor {
  padding: 0.75rem;
}

.page-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
  margin-top: 1.25rem;
}

.page-actions a {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 52px;
  padding: 0.6rem 0.75rem;
  text-align: center;
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.back-link {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  margin: -0.5rem 0 -0.15rem;
  color: var(--accent);
  font-weight: 600;
  text-decoration: none;
}

.disclosure-card {
  padding: 0;
  overflow: hidden;
}

.disclosure-card > summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 52px;
  padding: 0.7rem 1rem;
  font-weight: 700;
  cursor: pointer;
  list-style: none;
}

.disclosure-card > summary::-webkit-details-marker { display: none; }

.disclosure-card > summary::after {
  content: "+";
  color: var(--accent);
  font-size: 1.25rem;
}

.disclosure-card[open] > summary {
  border-bottom: 1px solid var(--border);
}

.disclosure-card[open] > summary::after { content: "−"; }

.disclosure-body { padding: 1rem; }

.quote {
  color: var(--muted);
  font-style: italic;
  font-size: 0.9rem;
  text-align: center;
  margin: -0.25rem 0 1rem;
}
.empty { text-align: center; color: var(--muted); padding: 1.5rem 0; }

.list-help {
  font-size: 0.85rem;
  margin: -0.5rem 0 0.5rem;
}

.row-list li[data-armable] {
  display: grid;
  grid-template-columns: 2.8rem minmax(0, 1fr) 44px;
  column-gap: 0.75rem;
  row-gap: 0.2rem;
  align-items: center;
}

.row-list li[data-armable] .delta {
  grid-column: 1;
  grid-row: 1;
}

.row-list li[data-armable] .what {
  grid-column: 2;
  grid-row: 1;
  min-width: 0;
}

.row-list li[data-armable] .when {
  grid-column: 2;
  grid-row: 2;
}

.row-list li.armed {
  background: color-mix(in srgb, var(--spend) 8%, transparent);
  border-radius: 8px;
}

.row-menu,
.row-cancel,
.row-list .row-delete {
  border: none;
  font-size: 0.85rem;
  font-weight: 600;
  min-height: 44px;
  padding: 0.4rem 0.8rem;
  border-radius: 999px;
  cursor: pointer;
}

.row-menu {
  grid-column: 3;
  grid-row: 1 / span 2;
  width: 44px;
  padding: 0;
  background: transparent;
  color: var(--muted);
  font-size: 1.3rem;
}

.row-menu:hover,
.row-menu:focus-visible {
  background: var(--bg);
  color: var(--text);
}

.row-actions-confirm {
  display: flex;
  grid-column: 1 / -1;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 0.25rem;
}

.row-actions-confirm[hidden] { display: none; }

.row-cancel {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}

.row-list .row-delete {
  background: var(--spend);
  color: var(--accent-text);
}

.goal-card .goal-head {
  font-weight: 700;
  margin-bottom: 0.6rem;
}

.progress {
  height: 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--gold));
  border-radius: 999px;
  transition: width 0.6s ease;
}

.goal-status {
  margin: 0.5rem 0 0;
  font-size: 0.9rem;
  color: var(--muted);
}

.goal-status.done {
  color: var(--earn);
  font-weight: 600;
}

button.goal-chip {
  font-size: 0.8rem;
  padding: 0.3rem 0.7rem;
  white-space: nowrap;
}

.reward-row { align-items: center; }

.reward-info { min-width: 0; }

.reward-name,
.reward-status { display: block; }

.reward-status {
  margin-top: 0.1rem;
  color: var(--muted);
  font-size: 0.78rem;
}

.reward-status.available {
  color: var(--earn);
  font-weight: 700;
}

.pending-list { margin-top: 0.5rem; }

.chip:disabled {
  opacity: 0.45;
  cursor: default;
}

.request-text {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  margin: 0 0 0.6rem;
  font-weight: 600;
}

.request-text .when {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 400;
  white-space: nowrap;
}

.request-actions {
  display: block;
}

.request-points-field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.5rem;
}

.request-points-field label { margin: 0; }

.request-points-field input[type="number"] {
  width: 5rem;
  flex: 0 0 auto;
}

.request-action-buttons {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.5rem;
}

button.inline {
  border: none;
  border-radius: 8px;
  min-height: 44px;
  padding: 0.55rem 1rem;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
}

button.inline.give {
  flex: 1;
  background: var(--accent);
  color: var(--accent-text);
}

button.inline.dismiss {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

button.chip {
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  border-radius: 999px;
  min-height: 44px;
  padding: 0.5rem 0.9rem;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
}

button.chip:active {
  background: var(--accent);
  color: var(--accent-text);
  border-color: var(--accent);
}

@media (max-width: 360px) {
  .page-actions { grid-template-columns: 1fr; }
  .avatar-grid { grid-template-columns: repeat(5, minmax(44px, 1fr)); }
}

.confetti {
  position: fixed;
  top: -2rem;
  z-index: 99;
  pointer-events: none;
  animation: confetti-fall 2.6s linear forwards;
}

@keyframes confetti-fall {
  to { transform: translateY(110vh) rotate(540deg); opacity: 0.7; }
}

.milestone-banner {
  position: fixed;
  top: 32%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--card);
  border: 2px solid var(--gold);
  border-radius: var(--radius);
  padding: 1.25rem 1.75rem;
  text-align: center;
  font-weight: 700;
  font-size: 1.1rem;
  z-index: 101;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
  animation: banner-pop 0.55s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.milestone-banner .trophy {
  font-size: 3rem;
  line-height: 1.2;
  animation: trophy-bounce 0.9s ease-in-out infinite alternate;
}

@keyframes banner-pop {
  from { transform: translate(-50%, -50%) scale(0.3); opacity: 0; }
}

@keyframes trophy-bounce {
  to { transform: translateY(-8px); }
}

.toast {
  position: fixed;
  top: calc(0.75rem + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
  padding: 0.6rem 1.2rem;
  border-radius: 999px;
  white-space: nowrap;
  z-index: 100;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
  animation: toast-in 0.3s ease-out;
}

@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, -1rem); }
}

form.submit-locked button {
  pointer-events: none;
}

button.submitting {
  animation: submit-pulse 0.9s ease-in-out infinite;
}

@keyframes submit-pulse {
  50% { opacity: 0.45; }
}
