:root {
  --bg: #f6f7fb;
  --panel: #ffffff;
  --text: #1c2233;
  --muted: #677089;
  --line: #e3e6ef;
  --accent: #4f7cff;
  --accent-soft: #e8eeff;
  --good: #12a37f;
  --good-soft: #e1f6ef;
  --warn: #d9822b;
  --warn-soft: #fdf0e1;
  --bad: #d64555;
  --bad-soft: #fde8ea;
  --shadow: 0 1px 2px rgb(20 30 60 / 6%), 0 4px 14px rgb(20 30 60 / 6%);
  --radius: 14px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11141c;
    --panel: #1a1f2b;
    --text: #e8ebf3;
    --muted: #9aa3b8;
    --line: #2b3242;
    --accent: #7b9cff;
    --accent-soft: #232d4a;
    --good: #3cc59c;
    --good-soft: #17352d;
    --warn: #f0a15a;
    --warn-soft: #3a2a1a;
    --bad: #f07482;
    --bad-soft: #3d1f25;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
/* Keep things scrolled into view clear of the sticky top bar and the help button. */
html { scroll-padding-top: 76px; scroll-padding-bottom: 90px; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

main {
  max-width: 760px;
  margin: 0 auto;
  padding: 16px 16px calc(48px + env(safe-area-inset-bottom, 0px));
}

h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: 1rem; }
p { margin: 0; }
a { color: var(--accent); }

.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.center { text-align: center; }
.spacer { flex: 1; }
.stack > * + * { margin-top: 12px; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* top bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 16px 10px;
  background: color-mix(in srgb, var(--panel) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; color: var(--text); font-weight: 700; text-decoration: none; }
.topbar nav { margin-left: auto; display: flex; gap: 4px; align-items: center; }
.topbar nav a, .linkish {
  padding: 6px 10px;
  border-radius: 8px;
  color: var(--muted);
  text-decoration: none;
  font: inherit;
  font-size: 0.95rem;
  background: none;
  border: 0;
  cursor: pointer;
}
.topbar nav a.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

/* panels & cards */
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}
section + section, .panel + .panel, .section-gap { margin-top: 16px; }

.daynav { display: flex; align-items: center; gap: 8px; margin-bottom: 16px; }
.daynav h1 { flex: 1; text-align: center; font-size: 1.25rem; }
.daynav .sub { display: block; font-size: 0.85rem; font-weight: 400; color: var(--muted); margin-top: 2px; }

.cards { display: grid; gap: 12px; }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: 5px solid var(--subject, var(--accent));
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 16px;
}
.card.active { border-color: var(--accent); border-left-color: var(--subject, var(--accent)); box-shadow: 0 0 0 3px var(--accent-soft), var(--shadow); }
.card.done { opacity: 0.85; }
.card.carried { opacity: 0.6; }
.card-head { display: flex; align-items: flex-start; gap: 10px; }
.card-title { flex: 1; min-width: 0; }
.card-title .subject { font-weight: 700; font-size: 1.05rem; }
.card-title .details { color: var(--muted); overflow-wrap: anywhere; }
.card-meta { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 10px; font-size: 0.9rem; color: var(--muted); }
.card-meta b { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.card-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap;
  background: var(--line);
  color: var(--muted);
}
.badge.active { background: var(--accent-soft); color: var(--accent); }
.badge.paused { background: var(--warn-soft); color: var(--warn); }
.badge.done { background: var(--good-soft); color: var(--good); }
.badge.late { background: var(--warn-soft); color: var(--warn); }

.bar { height: 6px; border-radius: 99px; background: var(--line); margin-top: 10px; overflow: hidden; }
.bar > i { display: block; height: 100%; width: 0; background: var(--good); border-radius: 99px; transition: width 0.4s; }
.bar.over > i { background: var(--warn); }

details.timeline { margin-top: 10px; font-size: 0.9rem; }
details.timeline summary { cursor: pointer; color: var(--muted); }
.timeline ol { list-style: none; margin: 8px 0 0; padding: 0; border-left: 2px solid var(--line); }
.timeline li { padding: 4px 0 8px 12px; position: relative; }
.timeline li::before { content: ""; position: absolute; left: -6px; top: 10px; width: 10px; height: 10px; border-radius: 50%; background: var(--line); }
.timeline li.open::before { background: var(--accent); }
.note { margin-top: 4px; padding: 6px 10px; border-radius: 8px; background: var(--bg); color: var(--text); white-space: pre-wrap; overflow-wrap: anywhere; }
.note .lbl { color: var(--muted); font-size: 0.8rem; font-weight: 600; display: block; }

/* now banner */
.now { display: flex; gap: 14px; align-items: flex-start; }
.now.active { border-color: var(--accent); background: linear-gradient(135deg, var(--accent-soft), var(--panel) 70%); }
.now .label { color: var(--muted); font-size: 0.9rem; }
.now .big { font-size: 1.35rem; font-weight: 700; overflow-wrap: anywhere; }
.now .clock { font-size: 2.4rem; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; line-height: 1.1; margin: 6px 0; }
.now .grow { flex: 1; min-width: 0; }
.pulse { width: 14px; height: 14px; margin-top: 6px; border-radius: 50%; background: var(--accent); flex: none; animation: pulse 1.6s infinite; }
.pulse.idle { background: var(--line); animation: none; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 50%, transparent); } 100% { box-shadow: 0 0 0 12px transparent; } }
@media (prefers-reduced-motion: reduce) { .pulse { animation: none; } }

/* tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
.tile { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.tile .k { color: var(--muted); font-size: 0.82rem; }
.tile .v { font-size: 1.35rem; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 2px; }
.tile .s { color: var(--muted); font-size: 0.8rem; margin-top: 2px; }

/* buttons */
.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  padding: 9px 16px;
  border-radius: 10px;
  cursor: pointer;
  min-height: 42px;
}
a.btn { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }
.btn:hover { border-color: var(--muted); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.good { background: var(--good); border-color: var(--good); color: #fff; }
.btn.warn { background: var(--warn-soft); border-color: transparent; color: var(--warn); }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.danger-ghost { color: var(--bad); border-color: transparent; background: none; }
.btn.ghost { background: none; }
.btn.small { padding: 5px 10px; min-height: 32px; font-size: 0.85rem; }
.btn.big { padding: 12px 22px; font-size: 1.05rem; }
.icon-btn { background: none; border: 0; color: var(--muted); cursor: pointer; padding: 4px 6px; border-radius: 6px; font: inherit; font-size: 0.85rem; }
.icon-btn:hover { background: var(--bg); color: var(--text); }

/* forms */
input, textarea, select {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  width: 100%;
}
input:focus, textarea:focus, select:focus, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.field { display: block; margin-top: 12px; }
.field > span, .field > legend { display: block; font-size: 0.88rem; font-weight: 600; margin-bottom: 6px; }
fieldset.field { border: 0; padding: 0; margin-inline: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
  padding: 6px 12px;
  border-radius: 999px;
  cursor: pointer;
}
.chip .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; background: var(--c, var(--accent)); }
.chip.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }
.choice label { display: inline-flex; align-items: center; }
.choice input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.choice input + span { border: 1px solid var(--line); padding: 7px 14px; border-radius: 999px; cursor: pointer; margin: 0 6px 6px 0; }
.choice input:checked + span { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }
.choice input:focus-visible + span { outline: 2px solid var(--accent); }
.guess-row { display: flex; gap: 8px; align-items: center; margin-top: 8px; }
.guess-row input { max-width: 120px; }

details.add-wrap > summary { cursor: pointer; font-weight: 600; list-style: none; }
details.add-wrap > summary::-webkit-details-marker { display: none; }
details.add-wrap > summary::before { content: "+ "; color: var(--accent); }

/* dialog */
dialog {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
  color: var(--text);
  padding: 20px;
  width: min(460px, calc(100vw - 32px));
  box-shadow: 0 20px 60px rgb(0 0 0 / 25%);
}
dialog::backdrop { background: rgb(10 15 30 / 45%); }
dialog h2 { margin-bottom: 4px; }
.dlg-actions { display: flex; gap: 8px; margin-top: 18px; align-items: center; flex-wrap: wrap; }

/* login */
.login { max-width: 360px; margin: 10vh auto 0; text-align: center; }
.login img { width: 64px; height: 64px; }
.login h1 { margin: 12px 0 4px; }
.login input { text-align: center; font-size: 1.6rem; letter-spacing: 0.3em; margin-top: 20px; }
.login .btn { width: 100%; margin-top: 12px; }
.error { color: var(--bad); margin-top: 10px; min-height: 1.4em; }

/* reports */
.seg { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 16px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; font-size: 0.8rem; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.daybars { display: grid; gap: 6px; margin-top: 10px; }
.daybar { display: grid; grid-template-columns: 88px 1fr 64px; gap: 8px; align-items: center; font-size: 0.85rem; }
.daybar .track { height: 14px; background: var(--bg); border-radius: 4px; overflow: hidden; }
.daybar .track i { display: block; height: 100%; background: var(--accent); border-radius: 4px; }
.daybar .val { text-align: right; font-variant-numeric: tabular-nums; }
.pill { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 0.8rem; font-weight: 600; }
.pill.ok { background: var(--good-soft); color: var(--good); }
.pill.over { background: var(--warn-soft); color: var(--warn); }
.pill.under { background: var(--accent-soft); color: var(--accent); }
.empty { text-align: center; padding: 28px 16px; color: var(--muted); }
.empty h2 { color: var(--text); margin-bottom: 6px; }

/* messages from a parent */
.nudge-chips .chip { font-size: 0.88rem; }
.nudge-chips .chip:disabled { opacity: 0.5; }
#msgForm input { max-width: none; flex: 1; min-width: 0; }
.nudge-log { list-style: none; margin: 12px 0 0; padding: 0; font-size: 0.9rem; }
.nudge-log li { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; padding: 6px 0; border-top: 1px solid var(--line); }
.nudge-log b.help { color: var(--bad); }

dialog.nudge-dlg {
  width: min(440px, calc(100vw - 32px));
  text-align: center;
  padding: 28px 22px 22px;
  border: 3px solid var(--accent);
}
dialog.nudge-dlg::backdrop { background: rgb(40 60 140 / 55%); }
dialog.nudge-dlg.pop { animation: nudge-pop 0.5s cubic-bezier(0.2, 1.4, 0.4, 1); }
.nudge-emoji { font-size: 4.5rem; line-height: 1; margin-bottom: 10px; }
.nudge-dlg.pop .nudge-emoji { animation: nudge-wiggle 0.9s 0.3s ease-in-out 2; }
.nudge-text { font-size: 1.6rem; margin: 6px 0 4px; overflow-wrap: anywhere; }
.nudge-actions { display: grid; gap: 8px; margin-top: 20px; }
@keyframes nudge-pop { from { transform: scale(0.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes nudge-wiggle { 0%, 100% { transform: rotate(0); } 25% { transform: rotate(-12deg) scale(1.1); } 75% { transform: rotate(12deg) scale(1.1); } }
@media (prefers-reduced-motion: reduce) { dialog.nudge-dlg.pop, .nudge-dlg.pop .nudge-emoji { animation: none; } }

.eta-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.eta-grid .btn { padding-inline: 6px; }
.eta-custom { justify-content: center; margin: 4px 0; }
.eta-custom input { max-width: 110px; }
.eta { margin-top: 8px; padding: 8px 12px; border-radius: 10px; background: var(--good-soft); color: var(--text); font-size: 0.92rem; }
.eta.late { background: var(--warn-soft); }
.eta.late b:last-child { color: var(--warn); }

.sound-hint {
  display: block;
  width: 100%;
  margin-bottom: 12px;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px dashed var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.nudge-log .who { font-weight: 600; }
.nudge-log li.is-help { color: var(--bad); }
.nudge-log li.is-help .muted { color: inherit; opacity: 0.8; }

/* pop-up variants */
dialog.nudge-dlg { overflow: hidden; }
dialog.nudge-dlg.alert { border-color: var(--bad); }
dialog.nudge-dlg.alert::backdrop { background: rgb(150 20 40 / 50%); }
dialog.nudge-dlg.celebrate { border-color: #f5c518; }
dialog.nudge-dlg.celebrate::backdrop { background: rgb(60 40 120 / 55%); }
dialog.nudge-dlg form { position: relative; }
.ach-big { font-size: 5rem; }
.ach-list { list-style: none; padding: 0; margin: 14px 0 0; text-align: left; display: grid; gap: 10px; }
.ach-list li { display: flex; gap: 12px; align-items: center; }
.ach-list .ach-emoji { font-size: 1.8rem; }
.level-note { margin-top: 12px; }

.confetti { position: absolute; inset: -30px 0 auto; height: 0; pointer-events: none; z-index: 1; }
.confetti i {
  position: absolute;
  top: 0;
  width: 8px;
  height: 12px;
  border-radius: 2px;
  opacity: 0;
  animation: confetti-fall linear forwards;
}
@keyframes confetti-fall {
  0% { transform: translate(0, 0) rotate(0); opacity: 1; }
  100% { transform: translate(var(--drift), 520px) rotate(var(--spin)); opacity: 0; }
}
@media (prefers-reduced-motion: reduce) { .confetti { display: none; } }

/* help button */
.help-fab {
  position: fixed;
  right: 16px;
  bottom: calc(18px + env(safe-area-inset-bottom, 0px));
  z-index: 20;
  border: 0;
  border-radius: 999px;
  padding: 14px 20px;
  font: inherit;
  font-weight: 700;
  font-size: 1.05rem;
  color: #fff;
  background: var(--bad);
  box-shadow: 0 6px 20px rgb(214 69 85 / 40%);
  cursor: pointer;
}
.help-fab:active { transform: scale(0.96); }
main { padding-bottom: calc(96px + env(safe-area-inset-bottom, 0px)); }

/* level ring */
.ring .ring-track { fill: none; stroke: var(--line); stroke-width: 9; }
.ring .ring-fill { fill: none; stroke: var(--accent); stroke-width: 9; stroke-linecap: round; transition: stroke-dashoffset 0.8s; }
.ring .ring-num { text-anchor: middle; dominant-baseline: middle; font-weight: 800; font-size: 30px; fill: var(--text); }
.ring .ring-lbl { text-anchor: middle; font-size: 9px; letter-spacing: 0.12em; fill: var(--muted); font-weight: 700; }
svg.ring[width="64"] .ring-num { font-size: 20px; }
svg.ring[width="64"] .ring-lbl { font-size: 7px; }

.level-card { display: flex; gap: 18px; align-items: center; flex-wrap: wrap; }
.level-card .grow { flex: 1; min-width: 200px; }
.level-title { font-size: 1.35rem; margin: 2px 0 8px; }
.xp-bar { height: 10px; margin: 0 0 6px; }
.xp-bar > i { background: var(--accent); }
.xp-how { margin-top: 10px; font-size: 0.9rem; }
.xp-how summary { cursor: pointer; color: var(--muted); }

/* achievements */
.ach-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-top: 12px; }
.ach {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 12px;
  border-radius: 12px;
  border: 1px dashed var(--line);
  color: var(--muted);
  font-size: 0.92rem;
}
.ach .ach-emoji { font-size: 1.8rem; filter: grayscale(1); opacity: 0.6; }
.ach.on { border: 1px solid var(--line); background: var(--bg); color: var(--text); }
.ach.on .ach-emoji { filter: none; opacity: 1; }
.ach-date { font-size: 0.78rem; color: var(--good); font-weight: 600; margin-top: 2px; }

/* heatmap */
.heatmap-wrap { overflow-x: auto; margin-top: 12px; }
.heatmap { display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto; gap: 4px 6px; width: max-content; }
.hm-months { grid-column: 2; display: grid; grid-template-columns: repeat(26, 14px); gap: 3px; font-size: 0.7rem; color: var(--muted); }
.hm-months span { white-space: nowrap; overflow: visible; width: 14px; }
.hm-days { grid-row: 2; display: grid; grid-template-rows: repeat(7, 14px); gap: 3px; font-size: 0.68rem; color: var(--muted); }
.hm-days span { line-height: 14px; }
.hm-grid { grid-row: 2; grid-column: 2; display: grid; grid-template-rows: repeat(7, 14px); grid-auto-flow: column; grid-auto-columns: 14px; gap: 3px; }
.hm-grid i, .hm-legend i { display: block; width: 14px; height: 14px; border-radius: 3px; }
.hm-legend { display: flex; gap: 3px; align-items: center; margin-top: 8px; }
.hm-legend i { display: inline-block; width: 12px; height: 12px; }
.hm-0 { background: var(--line); }
.hm-1 { background: color-mix(in srgb, var(--good) 30%, var(--panel)); }
.hm-2 { background: color-mix(in srgb, var(--good) 55%, var(--panel)); }
.hm-3 { background: color-mix(in srgb, var(--good) 80%, var(--panel)); }
.hm-4 { background: var(--good); }
.hm-future { background: transparent; }

/* month in review */
.review-head { display: flex; align-items: center; gap: 8px; }
.review-head h2 { flex: 1; text-align: center; }
.stories { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; margin-top: 14px; }
.story {
  border-radius: 14px;
  padding: 16px;
  background: linear-gradient(145deg, color-mix(in srgb, var(--story, var(--accent)) 16%, var(--panel)), var(--panel));
  border: 1px solid var(--line);
}
.story-emoji { font-size: 1.6rem; }
.story-big { font-size: 1.6rem; font-weight: 800; margin-top: 4px; overflow-wrap: anywhere; }
.story-text { color: var(--muted); font-size: 0.9rem; margin-top: 2px; }

/* recap */
.recap { position: relative; overflow: hidden; }
.recap.kid-celebrate { border-color: #f5c518; background: linear-gradient(160deg, color-mix(in srgb, #f5c518 14%, var(--panel)), var(--panel) 60%); }
.recap-head { display: flex; gap: 12px; align-items: flex-start; }
.recap-head .grow { flex: 1; min-width: 0; }
.recap-level { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.recap-facts { list-style: none; padding: 0; margin: 12px 0 0; display: grid; gap: 6px; }
.recap-facts li { display: flex; gap: 8px; }
.recap-badges { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.badge-pill { padding: 4px 10px; border-radius: 999px; background: var(--good-soft); color: var(--good); font-weight: 600; font-size: 0.85rem; }

@media (max-width: 520px) {
  .brand span { display: none; }
  .topbar nav a, .linkish { padding: 6px 7px; font-size: 0.9rem; }
}

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 10px;
  max-width: calc(100vw - 32px);
  z-index: 50;
  font-size: 0.95rem;
  pointer-events: none;
}
#toast.err { background: var(--bad); color: #fff; }
