/* LifeOS design system.
   Hand-written rather than a utility framework so the child-facing and
   parent-facing surfaces can diverge in tone while sharing one token set:
   the child screens get warmth and motion, the parent screens get restraint. */

:root {
  --ink:            #0f1729;
  --ink-2:          #35405a;
  --ink-3:          #6b7690;
  --ink-4:          #9aa3b8;
  --line:           #e3e7ef;
  --line-2:         #eef1f6;
  --surface:        #ffffff;
  --surface-2:      #f7f8fc;
  --surface-3:      #eff2f8;

  --brand:          #4338ca;
  --brand-2:        #6366f1;
  --brand-soft:     #eef0ff;
  --good:           #059669;
  --good-soft:      #e7f7f0;
  --warn:           #b45309;
  --warn-soft:      #fdf4e3;
  --bad:            #be123c;
  --bad-soft:       #fdeef1;
  --gold:           #b8860b;
  --gold-soft:      #fdf6e3;

  --math:           #4338ca;
  --reading:        #0e7490;
  --english:        #9333ea;
  --science:        #059669;
  --social_studies: #c2410c;

  --r-sm: 8px;
  --r:    12px;
  --r-lg: 18px;
  --r-xl: 26px;

  --shadow-1: 0 1px 2px rgba(15, 23, 41, .05), 0 1px 3px rgba(15, 23, 41, .04);
  --shadow-2: 0 4px 6px -1px rgba(15, 23, 41, .07), 0 2px 4px -2px rgba(15, 23, 41, .05);
  --shadow-3: 0 12px 24px -6px rgba(15, 23, 41, .14), 0 4px 8px -4px rgba(15, 23, 41, .08);

  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
}

[data-theme="dark"] {
  --ink:       #eef1f8;
  --ink-2:     #c4cbdb;
  --ink-3:     #8e98ae;
  --ink-4:     #6a7387;
  --line:      #262d3f;
  --line-2:    #1e2433;
  --surface:   #151a26;
  --surface-2: #0f131c;
  --surface-3: #1c2231;

  --brand:      #8b8cf8;
  --brand-2:    #a5a6fb;
  --brand-soft: #1e2140;
  --good:       #34d399;
  --good-soft:  #10291f;
  --warn:       #fbbf24;
  --warn-soft:  #2a2110;
  --bad:        #fb7185;
  --bad-soft:   #2c1219;
  --gold:       #fcd34d;
  --gold-soft:  #2a2312;

  --math: #8b8cf8; --reading: #38bdf8; --english: #c084fc;
  --science: #34d399; --social_studies: #fb923c;

  --shadow-1: 0 1px 3px rgba(0, 0, 0, .4);
  --shadow-2: 0 4px 8px rgba(0, 0, 0, .45);
  --shadow-3: 0 14px 30px rgba(0, 0, 0, .55);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: var(--sans);
  background: var(--surface-2);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  line-height: 1.55;
}

a { color: inherit; }

h1, h2, h3, h4 { margin: 0; line-height: 1.25; letter-spacing: -.015em; font-weight: 650; }
h1 { font-size: 1.65rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1rem; }
p  { margin: 0; }

/* --- Layout ------------------------------------------------------------- */

.wrap { max-width: 1120px; margin: 0 auto; padding: 0 20px; }
.wrap-narrow { max-width: 760px; margin: 0 auto; padding: 0 20px; }
main { padding: 28px 0 64px; }

.row  { display: flex; align-items: center; gap: 12px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.col  { display: flex; flex-direction: column; gap: 12px; }
.wrapflex { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.spacer { flex: 1; }

.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.split { display: grid; grid-template-columns: minmax(0, 1.9fr) minmax(0, 1fr); gap: 22px; }
.split-even { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 22px; }

.mt-1 { margin-top: 8px; } .mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; } .mt-4 { margin-top: 34px; }

@media (max-width: 860px) {
  .split, .split-even, .g3, .g4 { grid-template-columns: 1fr; }
  .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  h1 { font-size: 1.4rem; }
}

/* --- Header ------------------------------------------------------------- */

header.site {
  position: sticky; top: 0; z-index: 40;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--line);
}
header.site .inner { display: flex; align-items: center; gap: 18px; height: 58px; }
.logo { font-weight: 750; letter-spacing: -.03em; text-decoration: none; font-size: 1.05rem; }
.logo span { color: var(--ink-4); font-weight: 550; }
nav.site { display: flex; align-items: center; gap: 4px; margin-left: auto; }
nav.site a, nav.site button {
  font: inherit; font-size: .875rem; font-weight: 550;
  color: var(--ink-3); text-decoration: none;
  padding: 7px 11px; border-radius: var(--r-sm);
  background: none; border: 0; cursor: pointer;
}
nav.site a:hover, nav.site button:hover { color: var(--ink); background: var(--surface-3); }
nav.site a.active { color: var(--brand); background: var(--brand-soft); }

.icon-btn {
  display: inline-grid; place-items: center; width: 34px; height: 34px;
  border: 1px solid var(--line); border-radius: 50%;
  background: var(--surface); cursor: pointer; font-size: .95rem;
  color: var(--ink-2);
}
.icon-btn:hover { border-color: var(--ink-4); }

/* --- Cards -------------------------------------------------------------- */

.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-lg); padding: 20px; box-shadow: var(--shadow-1);
}
.card.flush { padding: 0; overflow: hidden; }
.card.tint-good { background: var(--good-soft); border-color: color-mix(in srgb, var(--good) 28%, transparent); }
.card.tint-warn { background: var(--warn-soft); border-color: color-mix(in srgb, var(--warn) 28%, transparent); }
.card.tint-bad  { background: var(--bad-soft);  border-color: color-mix(in srgb, var(--bad) 28%, transparent); }
.card.tint-brand{ background: var(--brand-soft);border-color: color-mix(in srgb, var(--brand) 28%, transparent); }
.card.tint-gold { background: var(--gold-soft); border-color: color-mix(in srgb, var(--gold) 32%, transparent); }
.card.interactive { transition: transform .16s ease, box-shadow .16s ease, border-color .16s ease; }
.card.interactive:hover { transform: translateY(-2px); box-shadow: var(--shadow-2); border-color: var(--ink-4); }
.card.locked { background: var(--surface-3); border-style: dashed; box-shadow: none; }

.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.section-label {
  font-size: .69rem; font-weight: 700; letter-spacing: .1em;
  text-transform: uppercase; color: var(--ink-4);
}

/* --- Text --------------------------------------------------------------- */

.muted  { color: var(--ink-3); }
.faint  { color: var(--ink-4); }
.small  { font-size: .8125rem; }
.tiny   { font-size: .72rem; }
.big    { font-size: 1.65rem; font-weight: 700; letter-spacing: -.03em; }
.huge   { font-size: 2.6rem; font-weight: 750; letter-spacing: -.04em; line-height: 1; }
.mono   { font-family: var(--mono); font-size: .82rem; letter-spacing: .04em; }
.strong { font-weight: 650; }
.good { color: var(--good); } .warn { color: var(--warn); } .bad { color: var(--bad); }
.brand { color: var(--brand); }
.prose { max-width: 62ch; }
.pre { white-space: pre-wrap; font-family: inherit; margin: 0; }

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

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  font: inherit; font-size: .875rem; font-weight: 600;
  padding: 9px 16px; border-radius: 10px; cursor: pointer;
  border: 1px solid transparent; text-decoration: none;
  transition: transform .12s ease, filter .12s ease, background .12s ease;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--brand); color: #fff; box-shadow: var(--shadow-1); }
.btn-primary:hover { filter: brightness(1.1); }
.btn-ghost { background: var(--surface); border-color: var(--line); color: var(--ink); }
.btn-ghost:hover { border-color: var(--ink-4); background: var(--surface-3); }
.btn-good { background: var(--good); color: #fff; }
.btn-lg { font-size: .95rem; padding: 12px 22px; border-radius: 12px; }
.btn-sm { font-size: .8rem; padding: 6px 12px; border-radius: 8px; }
.btn-block { width: 100%; }
.btn[disabled], .btn.disabled { opacity: .45; pointer-events: none; }
.btn-link {
  background: none; border: 0; padding: 0; font: inherit; font-size: .8125rem;
  color: var(--ink-3); text-decoration: underline; cursor: pointer;
}
.btn-link:hover { color: var(--ink); }

/* --- Forms -------------------------------------------------------------- */

.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: .78rem; font-weight: 600; color: var(--ink-2); }
input[type=text], input[type=email], input[type=password], input[type=number], select, textarea {
  font: inherit; font-size: .9rem; width: 100%;
  padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  transition: border-color .12s ease, box-shadow .12s ease;
}
input:focus, select:focus, textarea:focus {
  outline: 0; border-color: var(--brand);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 18%, transparent);
}
input.answer { font-size: 1.15rem; padding: 14px 16px; font-weight: 600; }

/* --- Chips, pills, badges ---------------------------------------------- */

.chip {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: .72rem; font-weight: 650; padding: 3px 9px;
  border-radius: 999px; background: var(--surface-3); color: var(--ink-2);
  white-space: nowrap;
}
.chip-good  { background: var(--good-soft); color: var(--good); }
.chip-warn  { background: var(--warn-soft); color: var(--warn); }
.chip-bad   { background: var(--bad-soft); color: var(--bad); }
.chip-brand { background: var(--brand-soft); color: var(--brand); }
.chip-gold  { background: var(--gold-soft); color: var(--gold); }
.chip-outline { background: none; border: 1px solid var(--line); color: var(--ink-3); }

.badge-tile {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 14px 10px; border-radius: var(--r);
  background: var(--surface-3); text-align: center; text-decoration: none;
}
.badge-tile .glyph { font-size: 1.7rem; line-height: 1; }
.badge-tile.bronze { background: color-mix(in srgb, #cd7f32 12%, var(--surface)); }
.badge-tile.silver { background: color-mix(in srgb, #94a3b8 16%, var(--surface)); }
.badge-tile.gold   { background: var(--gold-soft); }
.badge-tile.locked { opacity: .34; filter: grayscale(1); }

/* --- Progress ----------------------------------------------------------- */

.bar { height: 7px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.bar > i {
  display: block; height: 100%; border-radius: 999px;
  background: var(--brand); transition: width .7s cubic-bezier(.22, .9, .25, 1);
}
.bar.thin { height: 5px; }
.bar.thick { height: 11px; }
.bar > i.good { background: var(--good); }
.bar > i.warn { background: var(--warn); }
.bar > i.bad  { background: var(--bad); }
.bar > i.striped {
  background-image: linear-gradient(115deg,
    rgba(255,255,255,.28) 25%, transparent 25%, transparent 50%,
    rgba(255,255,255,.28) 50%, rgba(255,255,255,.28) 75%, transparent 75%);
  background-size: 14px 14px;
  animation: slide 1.1s linear infinite;
}
@keyframes slide { to { background-position: 14px 0; } }

.ring { display: grid; place-items: center; position: relative; }
.ring svg { transform: rotate(-90deg); display: block; }
.ring circle { fill: none; stroke-linecap: round; }
.ring .track { stroke: var(--surface-3); }
.ring .value { stroke: var(--brand); transition: stroke-dashoffset 1s cubic-bezier(.22,.9,.25,1); }
.ring .label {
  position: absolute; display: grid; place-items: center; text-align: center;
  font-weight: 700; letter-spacing: -.02em;
}

.stat { text-align: center; padding: 14px 10px; border-radius: var(--r); background: var(--surface-3); }
.stat .n { font-size: 1.4rem; font-weight: 700; letter-spacing: -.03em; line-height: 1.1; }
.stat .k { font-size: .7rem; color: var(--ink-3); margin-top: 2px; }

/* --- Streak heatmap ---------------------------------------------------- */

.heat { display: grid; grid-auto-flow: column; grid-template-rows: repeat(7, 1fr); gap: 3px; }
.heat i {
  width: 11px; height: 11px; border-radius: 3px; display: block;
  background: var(--surface-3);
}
.heat i[data-l="1"] { background: color-mix(in srgb, var(--good) 28%, var(--surface-3)); }
.heat i[data-l="2"] { background: color-mix(in srgb, var(--good) 50%, var(--surface-3)); }
.heat i[data-l="3"] { background: color-mix(in srgb, var(--good) 72%, var(--surface-3)); }
.heat i[data-l="4"] { background: var(--good); }
.heat-scroll { overflow-x: auto; padding-bottom: 4px; }

/* --- Tables ------------------------------------------------------------- */

table.data { width: 100%; border-collapse: collapse; font-size: .85rem; }
table.data th {
  text-align: left; font-size: .69rem; font-weight: 700; letter-spacing: .08em;
  text-transform: uppercase; color: var(--ink-4);
  padding: 9px 12px; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; background: var(--surface);
}
table.data td { padding: 10px 12px; border-bottom: 1px solid var(--line-2); }
table.data tr:last-child td { border-bottom: 0; }
table.data tr.flagged td { background: var(--bad-soft); }
table.data td.num { text-align: right; font-variant-numeric: tabular-nums; }
.scroll-y { max-height: 460px; overflow-y: auto; }

/* --- Subject accents --------------------------------------------------- */

.subj-math    { --accent: var(--math); }
.subj-reading { --accent: var(--reading); }
.subj-english { --accent: var(--english); }
.subj-science { --accent: var(--science); }
.subj-social_studies { --accent: var(--social_studies); }
.accent-bar { height: 3px; background: var(--accent, var(--brand)); }
.accent-text { color: var(--accent, var(--brand)); }
.bar > i.accent { background: var(--accent, var(--brand)); }
.ring .value.accent { stroke: var(--accent, var(--brand)); }

/* --- Feedback, toasts, modals ----------------------------------------- */

.note {
  border-radius: var(--r); padding: 14px 16px; font-size: .875rem;
  border: 1px solid var(--line); background: var(--surface);
}
.note-good { background: var(--good-soft); border-color: color-mix(in srgb, var(--good) 30%, transparent); color: color-mix(in srgb, var(--good) 82%, var(--ink)); }
.note-warn { background: var(--warn-soft); border-color: color-mix(in srgb, var(--warn) 30%, transparent); color: color-mix(in srgb, var(--warn) 82%, var(--ink)); }
.note-bad  { background: var(--bad-soft);  border-color: color-mix(in srgb, var(--bad) 30%, transparent);  color: color-mix(in srgb, var(--bad) 82%, var(--ink)); }
.note-info { background: var(--brand-soft); border-color: color-mix(in srgb, var(--brand) 30%, transparent); color: color-mix(in srgb, var(--brand) 82%, var(--ink)); }

#toasts {
  position: fixed; right: 18px; bottom: 18px; z-index: 90;
  display: flex; flex-direction: column; gap: 9px; pointer-events: none;
}
.toast {
  background: var(--ink); color: var(--surface);
  padding: 11px 16px; border-radius: 10px; font-size: .85rem; font-weight: 550;
  box-shadow: var(--shadow-3); animation: toast-in .3s cubic-bezier(.2,.9,.25,1) both;
  max-width: 320px;
}
@keyframes toast-in { from { opacity: 0; transform: translateY(14px) scale(.96); } }
.toast.out { animation: toast-out .28s ease forwards; }
@keyframes toast-out { to { opacity: 0; transform: translateY(8px) scale(.97); } }

.scrim {
  position: fixed; inset: 0; z-index: 80; display: grid; place-items: center;
  background: color-mix(in srgb, var(--ink) 55%, transparent);
  backdrop-filter: blur(3px); padding: 20px;
  animation: fade .22s ease both;
}
.modal {
  background: var(--surface); border-radius: var(--r-xl); padding: 30px;
  max-width: 460px; width: 100%; text-align: center; box-shadow: var(--shadow-3);
  animation: pop .42s cubic-bezier(.18, 1.3, .4, 1) both;
}
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: scale(.86) translateY(14px); } }

/* --- Motion ------------------------------------------------------------- */

.fade-up { animation: fade-up .38s cubic-bezier(.2, .9, .25, 1) both; }
@keyframes fade-up { from { opacity: 0; transform: translateY(10px); } }
.pop-in { animation: pop .4s cubic-bezier(.18, 1.3, .4, 1) both; }
.shake { animation: shake .42s ease; }
@keyframes shake {
  10%, 90% { transform: translateX(-2px); } 20%, 80% { transform: translateX(4px); }
  30%, 50%, 70% { transform: translateX(-6px); } 40%, 60% { transform: translateX(6px); }
}
.stagger > * { animation: fade-up .4s cubic-bezier(.2,.9,.25,1) both; }
.stagger > *:nth-child(1) { animation-delay: .02s; }
.stagger > *:nth-child(2) { animation-delay: .06s; }
.stagger > *:nth-child(3) { animation-delay: .1s; }
.stagger > *:nth-child(4) { animation-delay: .14s; }
.stagger > *:nth-child(5) { animation-delay: .18s; }
.stagger > *:nth-child(6) { animation-delay: .22s; }

.skeleton {
  background: linear-gradient(90deg, var(--surface-3) 25%, var(--line-2) 37%, var(--surface-3) 63%);
  background-size: 400% 100%; animation: shimmer 1.3s ease-in-out infinite;
  border-radius: var(--r-sm); color: transparent;
}
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }

.htmx-request .hide-while-loading { visibility: hidden; }
.htmx-indicator { opacity: 0; transition: opacity .2s; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { opacity: 1; }

.spinner {
  width: 15px; height: 15px; border-radius: 50%; display: inline-block;
  border: 2px solid color-mix(in srgb, currentColor 25%, transparent);
  border-top-color: currentColor; animation: spin .65s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 85; }

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

/* --- Print (weekly report) -------------------------------------------- */

@media print {
  header.site, nav.site, .no-print { display: none !important; }
  body { background: #fff; }
  .card { box-shadow: none; border-color: #ddd; break-inside: avoid; }
}
