/* ============================================================
   Morgenhelt — "Magisk skog" (Enchanted Forest) tema
   Fullstendig ny visuell drakt. Klassenavn og strukturell
   oppførsel (grid, staggered task-grid, done/active/hidden-tilstander,
   inline width/--progress-verdier fra app.js) er uendret slik at
   ingen JavaScript-logikk er berørt.
   ============================================================ */

:root {
  --bg-a: #0a1420;
  --bg-b: #123024;
  --bg-c: #163a2e;
  --panel: rgba(255, 255, 255, 0.055);
  --panel-strong: rgba(13, 36, 29, 0.78);
  --panel-soft: rgba(255, 255, 255, 0.035);
  --line: rgba(255, 213, 128, 0.26);
  --line-strong: rgba(255, 213, 128, 0.55);
  --gold: #ffd580;
  --gold-rgb: 255, 213, 128;
  --gold-deep: #f0b74a;
  --text: #f5efe0;
  --text-rgb: 245, 239, 224;
  --muted: #c9b98a;
  --muted-dim: #7c9184;
  --danger: #e08a8a;
  --shadow-soft: 0 14px 32px rgba(0, 0, 0, 0.38);
  --shadow-glow: 0 0 24px rgba(var(--gold-rgb), 0.35);
  --ink: var(--text);
  --ink-rgb: var(--text-rgb);
  --accent: var(--bg-a);
  --accent-rgb: 10, 20, 32;
  --bg: var(--bg-a);
}

@keyframes twinkleA {
  0%, 100% { opacity: .5; }
  50% { opacity: .95; }
}
@keyframes twinkleB {
  0%, 100% { opacity: .85; }
  50% { opacity: .4; }
}
@keyframes floaty {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}
@keyframes goldPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(var(--gold-rgb), 0.55); }
  50% { box-shadow: 0 0 0 6px rgba(var(--gold-rgb), 0); }
}

@keyframes taskPop {
  0% { transform: scale(1) rotate(0deg); }
  30% { transform: scale(1.22) rotate(-4deg); }
  55% { transform: scale(.93) rotate(3deg); }
  75% { transform: scale(1.06) rotate(-1deg); }
  100% { transform: scale(1) rotate(0deg); }
}
@keyframes taskRingBurst {
  0% { transform: scale(.55); opacity: .95; border-width: 4px; }
  100% { transform: scale(1.85); opacity: 0; border-width: 1px; }
}
@keyframes taskCheckPop {
  0% { transform: translate(-50%, -50%) scale(0); opacity: 0; }
  45% { transform: translate(-50%, -50%) scale(1.3); opacity: 1; }
  70% { transform: translate(-50%, -50%) scale(.9); opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(1); opacity: 0; }
}

* { box-sizing: border-box; }
html { font-size: 16px; }

body {
  margin: 0;
  font-family: "Quicksand", "Segoe UI", sans-serif;
  background: radial-gradient(circle at 18% -10%, #1c4433 0%, transparent 45%),
    linear-gradient(180deg, var(--bg-a) 0%, var(--bg-b) 55%, var(--bg-c) 100%);
  color: var(--text);
  min-height: 100vh;
  position: relative;
  overflow-x: hidden;
}

body::before,
body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
}

body::before {
  background-image:
    radial-gradient(2.5px 2.5px at 8% 12%, rgba(255, 233, 173, .9), transparent 60%),
    radial-gradient(2px 2px at 22% 6%, rgba(255, 233, 173, .8), transparent 60%),
    radial-gradient(2.5px 2.5px at 62% 4%, rgba(255, 233, 173, .85), transparent 60%),
    radial-gradient(2px 2px at 78% 14%, rgba(255, 233, 173, .75), transparent 60%),
    radial-gradient(3px 3px at 90% 22%, rgba(255, 233, 173, .9), transparent 60%),
    radial-gradient(2px 2px at 40% 20%, rgba(255, 233, 173, .7), transparent 60%),
    radial-gradient(2px 2px at 6% 34%, rgba(255, 233, 173, .6), transparent 60%),
    radial-gradient(2.5px 2.5px at 95% 40%, rgba(255, 233, 173, .7), transparent 60%);
  animation: twinkleA 4.5s ease-in-out infinite;
}

body::after {
  background-image:
    radial-gradient(2px 2px at 30% 8%, rgba(255, 233, 173, .7), transparent 60%),
    radial-gradient(2px 2px at 50% 16%, rgba(255, 233, 173, .6), transparent 60%),
    radial-gradient(2px 2px at 85% 6%, rgba(255, 233, 173, .65), transparent 60%),
    radial-gradient(120px 90px at 10% 100%, rgba(15, 40, 32, .9), transparent 70%),
    radial-gradient(160px 110px at 30% 100%, rgba(10, 30, 24, .9), transparent 70%),
    radial-gradient(140px 100px at 55% 100%, rgba(15, 40, 32, .85), transparent 70%),
    radial-gradient(180px 120px at 80% 100%, rgba(10, 30, 24, .9), transparent 70%),
    radial-gradient(140px 100px at 100% 100%, rgba(15, 40, 32, .85), transparent 70%);
  animation: twinkleB 5.5s ease-in-out infinite .8s;
}

/* ---------- Drifting fireflies: real movement, not just twinkling in place ---------- */

@keyframes fireflyDrift {
  0% { transform: translate(0, 0) scale(.7); opacity: 0; }
  12% { opacity: var(--peak, .85); }
  50% { transform: translate(var(--dx1, 40px), var(--dy1, -50px)) scale(1.15); opacity: var(--peak, .85); }
  88% { opacity: var(--peak, .85); }
  100% { transform: translate(var(--dx2, -30px), var(--dy2, 40px)) scale(.7); opacity: 0; }
}

.firefly-field {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 0;
}
.firefly {
  position: absolute;
  left: var(--x, 50%);
  top: var(--y, 50%);
  width: var(--size, 4px);
  height: var(--size, 4px);
  border-radius: 50%;
  background: var(--tint, var(--gold));
  box-shadow: 0 0 6px 2px var(--tint, rgba(var(--gold-rgb), .8)), 0 0 14px 4px rgba(var(--gold-rgb), .35);
  opacity: 0;
  animation: fireflyDrift var(--duration, 20s) ease-in-out var(--delay, 0s) infinite;
}

/* ---------- Shared glowing particle used by task pops and level-up bursts ---------- */

@keyframes sparkParticleFly {
  0% { transform: translate(-50%, -50%) rotate(var(--angle)) translateX(0) scale(.4); opacity: 0; }
  18% { opacity: 1; }
  100% { transform: translate(-50%, -50%) rotate(var(--angle)) translateX(var(--distance)) scale(1); opacity: 0; }
}
.spark-particle {
  position: absolute;
  top: 50%;
  left: 50%;
  width: var(--size, 4px);
  height: var(--size, 4px);
  margin: calc(var(--size, 4px) / -2);
  border-radius: 50%;
  background: var(--tint, var(--gold));
  box-shadow: 0 0 6px 1px var(--tint, rgba(var(--gold-rgb), .85));
  opacity: 0;
  animation: sparkParticleFly var(--duration, .9s) var(--delay, 0s) ease-out both;
  pointer-events: none;
}
.task-spark-field {
  position: absolute;
  inset: 0;
  overflow: visible;
  pointer-events: none;
}
.float-spark-field {
  position: fixed;
  width: 0;
  height: 0;
  z-index: 400;
  pointer-events: none;
}

.app { max-width: 1280px; margin: 0 auto; padding: 1.6rem 1.2rem 3rem; position: relative; z-index: 1; }
main { display: grid; gap: 2.6rem; justify-items: center; }

main > .panel { width: 100%; max-width: 1180px; margin-inline: auto; }

body.setup-only .points-panel,
body.setup-only .stats-panel,
body.setup-only #childBoards {
  display: none !important;
}
body.setup-only main { min-height: 80vh; align-content: center; }
body.setup-only .boards-panel { max-width: 560px; }

.panel { background: transparent; border: none; border-radius: 0; padding: 0; box-shadow: none; }

/* ---------- Topbar ---------- */

.topbar {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  margin-top: .6rem;
  margin-bottom: 2.6rem;
  overflow: visible;
}
.topbar-brand { width: 100%; display: flex; justify-content: center; text-align: center; }

.site-logo { display: none; }

.brand-title {
  font-family: "Fredoka", "Segoe UI", sans-serif;
  font-weight: 600;
  font-size: clamp(2.2rem, 4vw, 3.1rem);
  letter-spacing: .01em;
  margin: .3rem 0;
  background: linear-gradient(90deg, #ffe9ad, var(--gold) 40%, var(--gold-deep) 70%, #ffe9ad);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 0 18px rgba(var(--gold-rgb), .35));
}

h1, h2, h3, h4, h5 { margin: 0; font-weight: 600; color: var(--text); font-family: "Fredoka", "Segoe UI", sans-serif; }
h1 { font-size: 1.4rem; margin: 0 0 .7rem; }
h2 { font-size: 1.2rem; margin: 0 0 .8rem; color: var(--gold); }
h3 { font-size: 1rem; }
h4, h5 { font-size: .92rem; }
p { margin: .45rem 0 0; font-size: .92rem; color: var(--muted); font-family: "Quicksand", "Segoe UI", sans-serif; }

::placeholder { color: var(--muted); opacity: .8; }

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

/* ---------- Buttons ---------- */

button {
  border: 2px solid var(--line-strong);
  border-radius: 14px;
  width: 100%;
  padding: .8rem 1.1rem;
  font-family: "Quicksand", "Segoe UI", sans-serif;
  font-weight: 700;
  cursor: pointer;
  font-size: .85rem;
  background: var(--panel);
  color: var(--text);
  transition: transform 120ms ease, box-shadow 120ms ease, background 120ms ease;
}
button:disabled { opacity: .4; cursor: not-allowed; }
button:not(:disabled):hover { transform: translateY(-1px); }
button:active, button:focus-visible {
  background: rgba(var(--gold-rgb), .18);
  color: var(--text);
  outline: none;
}
.primary {
  background: linear-gradient(90deg, var(--gold), var(--gold-deep));
  color: #1c2b1f;
  border: none;
  box-shadow: 0 5px 0 #a97a2c, var(--shadow-glow);
}
.primary:not(:disabled):hover { transform: translateY(-1px); }
.success { background: rgba(var(--gold-rgb), .16); color: var(--gold); border-color: var(--line-strong); }
.secondary { background: transparent; color: var(--text); border: 2px solid var(--line-strong); }

/* ---------- Child boards (one glowing "spellbook page" per child) ---------- */

.child-boards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
  gap: 1.6rem;
  width: 100%;
}

.child-board {
  position: relative;
  padding: 1.6rem 1.4rem 1.5rem;
  background: transparent;
  border: none;
  box-shadow: none;
  overflow: visible;
}
.child-board::before {
  content: "";
  position: absolute;
  top: -40%;
  left: 50%;
  width: 220px;
  height: 220px;
  transform: translateX(-50%);
  background: radial-gradient(circle, rgba(var(--gold-rgb), .22), transparent 70%);
  pointer-events: none;
  z-index: -1;
}

.child-head { position: absolute; top: .7rem; right: .8rem; margin: 0; z-index: 2; }

.child-board h3 {
  font-size: 2.3rem;
  text-align: center;
  line-height: 1.05;
  margin-top: .1rem;
  background: linear-gradient(90deg, #ffe9ad, var(--gold) 45%, var(--gold-deep));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.child-level-animal {
  width: 210px;
  height: 210px;
  max-width: min(70vw, 210px);
  object-fit: contain;
  display: block;
  margin: .2rem auto .3rem;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(15, 40, 32, .9), rgba(15, 40, 32, .5) 70%);
  border: 3px solid var(--gold);
  padding: .5rem;
  box-shadow: 0 0 32px rgba(var(--gold-rgb), .4), inset 0 0 24px rgba(0, 0, 0, .35);
  animation: floaty 5s ease-in-out infinite;
}

.child-level-name {
  text-align: center;
  text-transform: uppercase;
  letter-spacing: .16em;
  font-size: .8rem;
  font-weight: 700;
  color: var(--muted);
  margin-top: .15rem;
}

/* ---------- Level progress as a winding forest path ---------- */

.child-level-progress {
  width: min(260px, 92%);
  aspect-ratio: 260 / 40;
  margin: .5rem auto 0;
}
.level-path { width: 100%; height: 100%; overflow: visible; }
.level-path-track {
  fill: none;
  stroke: rgba(255, 255, 255, .14);
  stroke-width: 3.5;
  stroke-linecap: round;
}
.level-path-fill {
  fill: none;
  stroke: var(--gold);
  stroke-width: 3.5;
  stroke-linecap: round;
  filter: drop-shadow(0 0 5px rgba(var(--gold-rgb), .75));
  transition: stroke-dashoffset 420ms ease;
}
.level-path-leaf {
  fill: rgba(var(--gold-rgb), .35);
}
.level-path-marker {
  fill: var(--gold);
  filter: drop-shadow(0 0 7px rgba(var(--gold-rgb), .9));
  transition: cx 420ms ease, cy 420ms ease;
}
.child-level-progress-text {
  margin-top: .35rem;
  text-align: center;
  font-size: .72rem;
  color: var(--muted);
  letter-spacing: .02em;
}

/* Little animal fact, tucked under the progress line like a small forest secret */
.child-level-fact {
  margin: .55rem auto 0;
  max-width: 100%;
  text-align: center;
  font-size: .95rem;
  line-height: 1.4;
  color: var(--muted);
  font-style: italic;
}
.child-level-fact:empty { display: none; }

/* ---------- Hero: a big centered companion portrait ---------- */

.child-hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  margin-top: .3rem;
}
.child-hero-info { width: 100%; }
.child-hero-info h3 { text-align: center; }
.child-hero-info .child-level-name { text-align: center; }
.child-hero-info .child-level-progress-text { text-align: center; }

.board-top-stats {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: .5rem;
  margin-top: 1.1rem;
}

.badge {
  background: rgba(255, 255, 255, .05);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: .35rem .7rem;
  font-family: "Fredoka", "Segoe UI", sans-serif;
  font-weight: 600;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  gap: .35rem;
}
.badge-streak { justify-self: start; }
.badge-streak, .badge-score { font-size: 1rem; }
.flame-icon, .score-star {
  display: inline-flex; width: 1em; height: 1em; object-fit: contain;
  filter: brightness(0) saturate(100%) invert(83%) sepia(37%) saturate(620%) hue-rotate(325deg) brightness(101%) contrast(101%);
}
.badge-score { justify-self: end; }

.badge-level {
  justify-self: center;
  font-size: 1.1rem;
  text-align: center;
  color: #1c2b1f;
  width: 3.6rem;
  height: 3.6rem;
  display: grid;
  place-items: center;
  line-height: 1;
  border: none;
  padding: 0;
  background: var(--gold);
  -webkit-mask: center / contain no-repeat url("./icons/level-badge.svg");
  mask: center / contain no-repeat url("./icons/level-badge.svg");
  filter: drop-shadow(0 0 8px rgba(var(--gold-rgb), .55));
}
.badge-level-value {
  line-height: 1;
  color: #1c2b1f;
  font-family: "Fredoka", "Segoe UI", sans-serif;
  font-weight: 700;
  /* the mask paints the whole element gold; push the digits back to a dark ink
     so they read against the gold sunburst shape */
  -webkit-text-fill-color: initial;
}
.badge-level { position: relative; }
.badge-level .badge-level-value {
  position: relative;
  z-index: 1;
}

.badge-clock {
  font-size: 1.9rem;
  font-variant-numeric: tabular-nums;
  justify-self: center;
  font-family: "Fredoka", "Segoe UI", sans-serif;
  color: var(--gold);
  background: none;
  border: none;
  padding: 0;
}
.streak-value, .score-value { font-size: 1em; line-height: 1; }

/* ---------- Primary action: one big focused button, no dead greyed-out twin ---------- */

.child-primary-action {
  margin-top: 1.3rem;
}
.child-primary-action .start-btn {
  font-size: 1.05rem;
  padding: 1rem 1.2rem;
  border-radius: 999px;
}
.child-primary-action .start-btn:disabled { display: none; }

.running-pill {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .7rem;
  background: rgba(255, 255, 255, .05);
  border: 2px solid var(--line-strong);
  border-radius: 999px;
  padding: .45rem .45rem .45rem 1.1rem;
}
.running-pill:has(.finish-btn:disabled) { display: none; }
.pill-label {
  font-size: .68rem;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--muted);
  font-weight: 700;
  white-space: nowrap;
}
.running-pill .badge-clock { font-size: 1.35rem; padding: 0; }
.running-pill .finish-btn {
  width: auto;
  padding: .55rem 1.1rem;
  border-radius: 999px;
  font-size: .8rem;
}

/* ---------- Tasks zone: the day's quest board, framed as its own panel ---------- */

.child-tasks-zone {
  position: relative;
  margin-top: 1.6rem;
  padding: 1.1rem .5rem .8rem;
  background: transparent;
  border: none;
  overflow: visible;
}

.tasks-zone-head { display: grid; gap: .55rem; }

/* Today's task progress, as its own little wandering trail — each child
   gets a differently-shaped path (see buildDayPathD in app.js), so no two
   boards ever draw quite the same curve. */
.day-progress {
  width: calc(100% - .6rem); margin: 0 auto;
  aspect-ratio: 260 / 38;
}
.day-path { width: 100%; height: 100%; overflow: visible; }
.day-path-track {
  fill: none;
  stroke: rgba(255, 255, 255, .12);
  stroke-width: 3;
  stroke-linecap: round;
}
.day-path-fill {
  fill: none;
  stroke: var(--gold);
  stroke-width: 3;
  stroke-linecap: round;
  filter: drop-shadow(0 0 4px rgba(var(--gold-rgb), .7));
  transition: stroke-dashoffset 220ms ease;
}
.day-path-marker {
  fill: var(--gold);
  filter: drop-shadow(0 0 6px rgba(var(--gold-rgb), .9));
  transition: cx 220ms ease, cy 220ms ease;
}
.progress-count {
  margin-top: 0; text-align: center;
  text-transform: uppercase; letter-spacing: .2em;
  font-size: .85rem; color: var(--muted);
}

/* ---------- Task grid: glowing rune circles ---------- */

.task-grid {
  display: grid;
  grid-template-columns: repeat(3, 118px);
  justify-content: center;
  column-gap: 10px; row-gap: .9rem;
  margin-top: 1.1rem;
  padding-bottom: .2rem;
}
.task-grid > * { width: 118px; justify-self: center; }
.task-grid > :nth-child(3n + 2) { transform: translateY(40%); }

/* ---------- Footer: day status, tucked away and de-emphasized ---------- */

.child-footer {
  margin-top: 1.3rem;
  padding-top: .9rem;
  border-top: 1px dashed var(--line);
  opacity: .82;
}

.day-mode-note {
  margin-top: 0;
  font-size: .82rem;
  text-align: center;
  background: rgba(var(--gold-rgb), .14);
  border: 1px solid var(--line);
  color: var(--gold);
  padding: .5rem .7rem;
  border-radius: 12px;
}
.day-mode-note:empty { display: none; }
.day-mode-note:empty + .day-status-row { margin-top: 0; }

.day-status-row { margin-top: .6rem; display: grid; justify-items: center; gap: .3rem; }
.day-status-control {
  position: relative;
  width: min(240px, 92%);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  align-items: center;
}
.day-status-control::before {
  content: "";
  position: absolute; left: 10%; right: 10%; top: 50%;
  height: 2px;
  background: var(--line-strong);
  transform: translateY(-50%);
}
.day-status-step {
  position: relative; z-index: 1;
  width: 1rem; height: 1rem;
  margin: 0 auto;
  border: 2px solid var(--gold);
  border-radius: 999px;
  background: var(--bg-b);
  padding: 0;
}
.day-status-step.active { background: var(--gold); box-shadow: 0 0 10px rgba(var(--gold-rgb), .7); }
.day-status-step:focus-visible, .day-status-step:active { background: var(--gold); }
.day-status-labels {
  width: min(240px, 92%);
  display: grid; grid-template-columns: repeat(3, 1fr);
  font-size: .62rem; color: var(--muted);
}
.day-status-labels span { text-align: center; }

.task-btn {
  position: relative;
  font-family: "Quicksand", "Segoe UI", sans-serif;
  font-size: .82rem;
  font-weight: 700;
  text-align: center;
  padding: .5rem;
  background: rgba(255, 255, 255, .04);
  border: 2.5px solid var(--gold);
  color: var(--text);
  border-radius: 999px;
  width: 118px; height: 118px;
  min-height: 0;
  transform: rotate(var(--tilt, 0deg));
  transition: transform 120ms ease, box-shadow 120ms ease, background 120ms ease;
  display: flex; flex-direction: column; justify-content: center; align-items: center;
  white-space: normal; word-break: break-word;
  box-shadow: 0 0 14px rgba(var(--gold-rgb), .18);
}
.task-btn:hover:not(:disabled) { transform: translateY(-2px) rotate(var(--tilt, 0deg)); box-shadow: 0 0 20px rgba(var(--gold-rgb), .4); }
.task-btn:active, .task-btn.done {
  background: linear-gradient(160deg, var(--gold), var(--gold-deep));
  border-color: var(--gold-deep);
  color: #1c2b1f;
  box-shadow: 0 0 22px rgba(var(--gold-rgb), .6);
}
.task-btn.done small { color: #1c2b1f; }
.task-text { text-align: center; margin-top: .15rem; font-size: inherit; line-height: 1.2; }
.task-btn small { display: block; margin-top: .25rem; font-size: .64rem; font-weight: 600; }

/* ---------- Task completion celebration: circles bursting gold ---------- */

.task-btn.task-pop {
  animation: taskPop 520ms cubic-bezier(.34, 1.56, .64, 1);
  z-index: 2;
}
.task-btn.task-pop::before {
  content: "";
  position: absolute;
  pointer-events: none;
  border-radius: 999px;
  inset: -8px;
  border: 4px solid var(--gold);
  animation: taskRingBurst 620ms ease-out both;
}
.task-btn.task-pop .task-checkmark {
  position: absolute;
  left: 50%;
  top: 50%;
  font-size: 2.6rem;
  line-height: 1;
  color: #1c2b1f;
  text-shadow: 0 0 14px rgba(255, 255, 255, .8);
  animation: taskCheckPop 620ms ease-out both;
  pointer-events: none;
}

.add-task-btn {
  background: rgba(255, 255, 255, .03);
  border: 2px dashed var(--line-strong);
  color: var(--muted);
}

.task-item { position: relative; }

.remove-task-btn {
  position: absolute; top: 2px; right: 8px;
  border: none; background: transparent; color: var(--muted);
  font-size: 1.3rem; line-height: 1; padding: 0;
}
.icon-btn { border: none; background: transparent; color: var(--muted); padding: .1rem .25rem; font-size: .8rem; width: auto; }
.icon-btn:hover { color: var(--gold); }

/* ---------- Points & rewards ---------- */

/* Same column grid as the child profiles above, so each child's rewards
   line up directly under their own board. */
.points-overview { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 1.6rem; width: 100%; }
.points-card {
  padding: 1.2rem .3rem;
  display: grid; gap: .9rem;
  background: transparent;
  border: none;
}
.points-header h4 { font-size: 1.1rem; }
.points-header p strong { color: var(--gold); }

.reward-menu { display: grid; gap: .9rem; }
.reward-menu-rings { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); column-gap: 15px; row-gap: .9rem; }

.reward-choice { display: grid; justify-items: center; text-align: center; gap: .5rem; }
.reward-ring {
  --progress: 0%;
  width: 128px; aspect-ratio: 1; border-radius: 50%;
  background: conic-gradient(var(--gold) var(--progress), rgba(255, 255, 255, .1) 0);
  display: grid; place-items: center;
  filter: drop-shadow(0 0 10px rgba(var(--gold-rgb), .25));
}
.reward-ring::before {
  content: ""; width: 106px; aspect-ratio: 1; border-radius: 50%;
  background: var(--bg-b); grid-area: 1 / 1;
}
.reward-ring span { grid-area: 1 / 1; z-index: 1; font-size: .8rem; color: var(--gold); font-weight: 700; }
.reward-choice h5 { margin: 0; font-size: .88rem; font-weight: 600; color: var(--text); line-height: 1.1; }

.reward-history { display: grid; gap: .3rem; }
.reward-history ul { margin: 0; padding-left: 1rem; display: grid; gap: .2rem; }
.reward-history li { font-size: .78rem; color: var(--muted); }
.reward-history-cost { font-size: .72rem; color: var(--danger); }

.reward-claim-btn {
  width: auto; min-width: 0;
  padding: .4rem .8rem; font-size: .8rem;
  background: linear-gradient(90deg, var(--gold), var(--gold-deep));
  color: #1c2b1f; border: none; border-radius: 999px;
}
.reward-claim-btn--hidden { visibility: hidden; pointer-events: none; }
.reward-claim-btn:disabled { background: rgba(var(--gold-rgb), .25); color: rgba(245, 239, 224, .6); }

/* ---------- Weekly stats (lives inside the parent settings dialog) ---------- */

.settings-stats-panel {
  margin-top: .2rem;
  padding-top: .2rem;
  border-top: 1px solid var(--line);
}
.settings-stats-panel h3 { margin-bottom: .5rem; }

#weeklyStats { display: grid; grid-template-columns: 1fr; gap: 1rem; }
.stat-card {
  padding: 1.1rem 1.2rem; font-size: .82rem;
  background: var(--panel-strong);
  border: 1px solid var(--line);
  border-radius: 20px;
}
.stat-card-extended { padding-top: 1.1rem; }
.stat-card-extended h5 { margin: .8rem 0 .6rem; font-size: .74rem; color: var(--muted); text-transform: uppercase; letter-spacing: .1em; }
.graph-list { display: grid; gap: .4rem; }
.graph-row { display: grid; grid-template-columns: 1fr 1.4fr auto; align-items: center; gap: .5rem; font-size: .7rem; }
.graph-label { color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.graph-track { height: 8px; border-radius: 5px; width: 100%; background: rgba(255, 255, 255, .08); overflow: hidden; }
.graph-fill { height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--gold-deep), var(--gold)); }
.graph-value { color: var(--muted); font-variant-numeric: tabular-nums; }

/* ---------- Settings button / topbar actions ---------- */

.topbar-actions { position: absolute; top: .1rem; right: 0; z-index: 3; }
.settings-btn {
  appearance: none; border: none; background: rgba(255, 255, 255, .06);
  border: 1px solid var(--line);
  color: var(--gold); font-size: 1.2rem; line-height: 1;
  width: 2.6rem; height: 2.6rem; padding: 0; position: relative;
  border-radius: 999px; display: grid; place-items: center;
}
.settings-fallback { position: absolute; inset: 0; display: grid; place-items: center; font-size: 1.2rem; line-height: 1; color: var(--gold); }
.settings-btn:active, .settings-btn:focus-visible { background: rgba(var(--gold-rgb), .18); color: var(--gold); }
.settings-icon {
  width: 1.25rem; height: 1.25rem; display: block; object-fit: contain; position: relative; z-index: 1;
  filter: brightness(0) saturate(100%) invert(83%) sepia(37%) saturate(620%) hue-rotate(325deg) brightness(101%) contrast(101%);
}

#profileDialog { width: min(560px, calc(100vw - 1.5rem)); }
.profile-panel { display: grid; gap: .75rem; }
.auth-grid { display: grid; grid-template-columns: 1fr; gap: .5rem; }

textarea, input[type="text"], input[type="password"], input[type="number"], input[type="email"] {
  border: 1px solid var(--line-strong);
  background: rgba(255, 255, 255, .05);
  color: var(--text);
  border-radius: 12px;
  width: 100%; padding: .6rem .8rem; font-size: .82rem;
  font-family: "Quicksand", "Segoe UI", sans-serif;
}
input:focus-visible, textarea:focus-visible { outline: 2px solid var(--gold); outline-offset: 1px; }

.row { display: flex; justify-content: flex-end; gap: .5rem; }
.switch-row { grid-template-columns: auto 1fr; align-items: center; }
.note { color: var(--muted); margin: 0; }

.empty-state-note {
  max-width: 420px;
  margin: 3rem auto;
  padding: 1.4rem 1.6rem;
  text-align: center;
  font-size: 1rem;
  line-height: 1.5;
  background: var(--panel-strong);
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: var(--shadow-soft);
}

/* ---------- Add-child row ---------- */

.settings-add-child { display: grid; gap: .6rem; margin-top: .2rem; }
.settings-add-child h3 { margin: 0; font-size: .88rem; color: var(--gold); }
.child-create-row {
  max-width: 480px; width: 100%;
  display: grid; grid-template-columns: 1fr auto;
  align-items: stretch; gap: .5rem;
}
.child-create-row input[type="text"] { min-height: 2.9rem; }
.add-child-inline {
  width: 2.9rem; min-height: 2.9rem; aspect-ratio: 1 / 1;
  border: none;
  background: linear-gradient(135deg, var(--gold), var(--gold-deep));
  color: #1c2b1f;
  padding: 0; font-size: 1.3rem; line-height: 1;
  display: grid; place-items: center;
  border-radius: 999px;
  box-shadow: var(--shadow-glow);
  animation: goldPulse 2.6s ease-in-out infinite;
}
.add-child-inline:active, .add-child-inline:focus-visible { background: var(--gold-deep); color: #1c2b1f; }

/* ---------- Settings dialog (parchment / spellbook) ---------- */

dialog {
  border: 1px solid var(--line-strong);
  border-radius: 20px;
  width: 100%; width: min(430px, calc(100vw - 2rem));
  background: var(--bg-b);
  color: var(--text);
  box-shadow: var(--shadow-soft);
}
dialog::backdrop { background: rgba(4, 10, 8, .6); backdrop-filter: blur(2px); }

.pin-form, #parentSettings { display: grid; gap: .8rem; }
label { display: grid; gap: .3rem; font-family: "Quicksand", "Segoe UI", sans-serif; font-weight: 600; font-size: .82rem; }

.settings-dialog {
  border: 1px solid var(--line-strong);
  outline: none;
  background: var(--bg-b);
  color: var(--text);
  border-radius: 22px;
}
.settings-dialog #parentSettings, .settings-dialog h3, .settings-dialog label, .settings-dialog .note { color: var(--text); }
.settings-dialog h3 { color: var(--gold); }
.settings-dialog input[type="number"], .settings-dialog input[type="password"] {
  border-color: var(--line-strong); background: rgba(255, 255, 255, .05); color: var(--text);
}
.settings-dialog .secondary, .settings-dialog .success {
  border-color: var(--line-strong); color: var(--gold); background: transparent;
}

.parent-settings-panel { position: relative; display: grid; gap: .8rem; }

.reward-settings { display: grid; gap: .5rem; margin-top: .2rem; }
.reward-settings h3 { margin: 0; font-size: .88rem; color: var(--gold); }
.reward-settings-list { display: grid; gap: .35rem; }
.reward-settings-item {
  display: grid; grid-template-columns: 1fr auto auto; gap: .4rem; align-items: center;
  background: rgba(255, 255, 255, .04);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: .4rem .6rem;
}
.reward-settings-item .reward-remove-btn { border: none; background: transparent; color: var(--muted); width: auto; padding: .15rem .35rem; font-size: .9rem; }
.reward-settings-item .reward-remove-btn:hover { color: var(--danger); }

.reward-create-row { display: grid; grid-template-columns: 1fr 110px; gap: .4rem; }
.reward-create-row button { grid-column: 1 / -1; }

.settings-close-x {
  position: absolute; top: 0; right: 0; border: none; background: transparent;
  color: var(--muted); width: auto; padding: .2rem; font-size: 1.1rem;
}
.settings-close-x:hover { color: var(--gold); }

.settings-dialog input[type="checkbox"] {
  appearance: none; width: 1.15rem; height: 1.15rem;
  border: 1.5px solid var(--line-strong); background: rgba(255, 255, 255, .05);
  border-radius: 5px; display: grid; place-content: center;
}
.settings-dialog input[type="checkbox"]:checked { background: var(--gold); border-color: var(--gold); }
.settings-dialog input[type="checkbox"]::before { content: ""; }
.settings-dialog input[type="checkbox"]:checked::before { content: "✓"; color: #1c2b1f; font-size: .7rem; line-height: 1; }

.score-stepper { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: .4rem; }
.step-btn { border: 1px solid var(--line-strong); background: transparent; color: var(--gold); width: auto; padding: .15rem .5rem; font-size: 1.1rem; line-height: 1; border-radius: 8px; }
.score-value-display { text-align: center; color: var(--text); font-size: .88rem; font-weight: 700; }

.settings-logout {
  margin-top: .8rem;
  background: transparent;
  color: var(--danger);
  border: 1.5px solid var(--danger);
}
.settings-logout:active, .settings-logout:focus-visible { background: var(--danger); color: var(--bg-b); }

/* ============================================================
   Level-up celebration overlay
   Rendered outside #childBoards (appended to <body>) so the
   1-second renderBoards() refresh cycle never interrupts it.
   ============================================================ */

@keyframes levelUpBackdropIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes levelUpCardIn {
  0% { transform: scale(.6) translateY(30px); opacity: 0; }
  60% { transform: scale(1.05) translateY(-4px); opacity: 1; }
  100% { transform: scale(1) translateY(0); opacity: 1; }
}
@keyframes levelUpRing {
  0% { transform: scale(.55); opacity: .9; }
  100% { transform: scale(1.9); opacity: 0; }
}
@keyframes levelUpSpin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
@keyframes levelUpSpinReverse { from { transform: rotate(0deg); } to { transform: rotate(-360deg); } }
@keyframes levelUpTwinkle {
  0%, 100% { opacity: .2; transform: scale(.7); }
  50% { opacity: 1; transform: scale(1.25); }
}
@keyframes levelUpSpark {
  0% { transform: rotate(var(--angle)) translateX(0) scale(0); opacity: 0; }
  25% { opacity: 1; }
  100% { transform: rotate(var(--angle)) translateX(var(--distance)) scale(1); opacity: 0; }
}
@keyframes levelUpFloat {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

.level-up-overlay {
  position: fixed;
  inset: 0;
  z-index: 500;
  display: grid;
  place-items: center;
  background: radial-gradient(circle at 50% 40%, rgba(18, 48, 36, .82), rgba(4, 10, 8, .88));
  backdrop-filter: blur(3px);
  opacity: 0;
  cursor: pointer;
  padding: 1.5rem;
}
.level-up-overlay.show { animation: levelUpBackdropIn 320ms ease-out forwards; }
.level-up-overlay.hide { animation: levelUpBackdropIn 380ms ease-in reverse forwards; }

.level-up-card {
  display: grid;
  justify-items: center;
  text-align: center;
  gap: .3rem;
  opacity: 0;
  animation: levelUpCardIn 620ms 120ms cubic-bezier(.25, 1.1, .4, 1) forwards;
  cursor: default;
}

.level-up-portal {
  position: relative;
  width: min(300px, 62vw);
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  margin-bottom: .6rem;
}
.level-up-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid var(--gold);
}
.level-up-ring-a { animation: levelUpRing 2.2s ease-out infinite; }
.level-up-ring-b { animation: levelUpRing 2.2s ease-out 1.1s infinite; }
.level-up-portal::before {
  content: "";
  position: absolute;
  inset: 8%;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(var(--gold-rgb), .5) 0%, rgba(179, 157, 219, .22) 55%, transparent 76%);
}
.level-up-portal::after {
  content: "";
  position: absolute;
  inset: -6%;
  border-radius: 50%;
  border: 1.5px dashed rgba(var(--gold-rgb), .55);
  animation: levelUpSpin 18s linear infinite;
}
.level-up-sparkles { position: absolute; inset: 0; }
.level-up-spark {
  position: absolute;
  top: 50%; left: 50%;
  width: var(--size, 4px);
  height: var(--size, 4px);
  margin: calc(var(--size, 4px) / -2);
  border-radius: 50%;
  background: var(--tint, var(--gold));
  box-shadow: 0 0 8px var(--tint, rgba(var(--gold-rgb), .9));
  animation: levelUpSpark var(--orbit-duration, 1.3s) var(--delay, 0s) ease-out infinite;
}
.level-up-portrait {
  position: absolute;
  inset: 12%;
  border-radius: 50%;
  background: radial-gradient(circle, #163a2e, #0d1b2a 75%);
  border: 4px solid var(--gold);
  box-shadow: 0 0 50px rgba(var(--gold-rgb), .55), inset 0 0 26px rgba(0, 0, 0, .4);
  display: grid;
  place-items: center;
  overflow: hidden;
  animation: levelUpFloat 3.2s ease-in-out infinite;
}
.level-up-portrait img { width: 78%; height: 78%; object-fit: contain; filter: drop-shadow(0 0 16px rgba(var(--gold-rgb), .5)); }
.level-up-badge {
  position: absolute;
  left: 50%;
  bottom: -6%;
  transform: translateX(-50%);
  background: var(--bg-b);
  border: 2px solid var(--gold);
  border-radius: 999px;
  padding: .4rem 1.3rem;
  font-family: "Fredoka", "Segoe UI", sans-serif;
  font-weight: 700;
  font-size: 1rem;
  color: var(--gold);
  white-space: nowrap;
  box-shadow: 0 0 24px rgba(var(--gold-rgb), .5);
}

.level-up-kicker {
  margin: 0;
  font-family: "Fredoka", "Segoe UI", sans-serif;
  font-weight: 600;
  font-size: .82rem;
  letter-spacing: .2em;
  text-transform: uppercase;
  color: var(--muted);
}
.level-up-title {
  margin: 0;
  max-width: min(480px, 84vw);
  font-size: clamp(1.5rem, 4.5vw, 2.3rem);
  background: linear-gradient(90deg, #ffe9ad, var(--gold) 40%, var(--gold-deep) 70%, #ffe9ad);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 0 18px rgba(var(--gold-rgb), .4));
}
.level-up-hint {
  margin-top: .8rem;
  font-size: .74rem;
  color: var(--muted);
  letter-spacing: .04em;
}

/* ---------- Legacy auth screen (kept dormant, styled defensively) ---------- */

.auth-screen { min-height: 100vh; display: grid; align-content: center; gap: 1.2rem; }
.auth-card { max-width: 520px; margin: 0 auto; display: grid; gap: .8rem; text-align: center; }
.email-login-row { display: grid; gap: .45rem; }
.email-auth-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .5rem; }
.email-auth-actions button { width: 100%; }
#authEmailCreate { background: linear-gradient(90deg, var(--gold), var(--gold-deep)); color: #1c2b1f; border: none; }
#authEmailCreate:active, #authEmailCreate:focus-visible { background: var(--gold-deep); color: #1c2b1f; border: none; }
#authScreen input[type="email"], #authScreen input[type="password"] {
  border: 1px solid var(--line-strong); border-radius: 12px; padding: .7rem .9rem;
  font-family: "Quicksand", "Segoe UI", sans-serif; font-size: .82rem;
  background: rgba(255, 255, 255, .05); color: var(--text);
}

/* ============================================================
   Responsive
   ============================================================ */

@media (max-width: 900px) {
  html { font-size: 14px; }
  .child-boards { grid-template-columns: 1fr; max-width: 420px; margin-inline: auto; }
  .points-overview { grid-template-columns: 1fr; max-width: 420px; margin-inline: auto; }
  .child-board h3 { font-size: 2.1rem; }
  .reward-menu-rings { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
  .reward-choice .reward-claim-btn { width: auto; }
}

@media (max-width: 700px) {
  html { font-size: 17px; }
  .app { padding: 1rem .7rem 1.6rem; }
  .topbar { margin-top: .5rem; margin-bottom: 2.1rem; }
  .brand-title { font-size: 2rem; }
  .topbar-actions { top: .1rem; right: .1rem; }
  .child-hero { margin-top: 1.4rem; }
  .child-level-animal { width: 180px; height: 180px; max-width: min(65vw, 180px); }
  .child-hero-info h3, .child-board h3 { font-size: 1.9rem; }
  .board-top-stats { gap: .4rem; margin-top: 1rem; }
  .badge-level { width: 3.1rem; height: 3.1rem; }
  .badge-level-value { font-size: .82rem; }
  .badge-streak, .badge-score { font-size: .92rem; }
  .day-status-control, .day-status-labels { width: min(280px, 98%); }
  .child-primary-action { margin-top: .9rem; }
  .running-pill .badge-clock { font-size: 1.15rem; }
  .child-tasks-zone { margin-top: 1.1rem; padding: .9rem .7rem 1.2rem; }
  .progress-count { font-size: .74rem; letter-spacing: .12em; }
  .task-grid { gap: .5rem; margin-top: .9rem; }
}

@media (max-width: 520px) {
  .email-auth-actions { grid-template-columns: 1fr; }
  .task-grid { grid-template-columns: repeat(2, 132px); column-gap: 10px; row-gap: .6rem; padding-bottom: 1.2rem; }
  .task-grid > :nth-child(3n + 2) { transform: none; }
  .task-grid > :nth-child(even) { transform: translateY(40%); }
  .task-grid > * { width: 132px; }
  .task-btn { width: 132px; height: 132px; }
  .child-create-row { grid-template-columns: 1fr auto; gap: .4rem; }
  .child-board h3, .child-hero-info h3 { font-size: 1.7rem; }
  .child-level-name { font-size: .68rem; }
}
