/* Latticework: a family thinking dojo.
   Readability first: light by default, 18px body, high-contrast muted text, generous spacing.
   Dark mode is opt-in (☾ button) and remembered per device. */
:root {
  --paper: #F5F6F8;
  --surface: #FFFFFF;
  --ink: #1A1D2B;
  --ink-2: #4A4F63;
  --line: #D6D9E3;
  --violet: #4F35E0;
  --violet-ink: #FFFFFF;
  --violet-soft: #EEEBFF;
  --lime: #C8F542;
  --lime-soft: #F0FBCF;
  --lime-ink: #1E2A00;
  --coral: #D63A40;
  --coral-soft: #FFE9EA;
  --amber-soft: #FFF3D6;
  --radius: 16px;
  --radius-sm: 12px;
  --shadow: 0 1px 2px rgba(26, 29, 43, .05), 0 6px 20px -12px rgba(26, 29, 43, .15);
  --display: "Bricolage Grotesque", "Segoe UI", system-ui, sans-serif;
  --body: "Atkinson Hyperlegible", "Segoe UI", system-ui, sans-serif;
  --gutter: 16px;
  --maxw: 680px;
}
:root[data-theme="dark"] {
  --paper: #12141F; --surface: #1C1F2E; --ink: #F1F2F8; --ink-2: #C0C5D8; --line: #363C55;
  --violet: #8B75FF; --violet-ink: #12141F; --violet-soft: #2A2650; --lime: #C8F542; --lime-soft: #2E3A12; --lime-ink: #1E2A00;
  --coral: #FF7A7F; --coral-soft: #3F2427; --amber-soft: #3E3520;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 6px 20px -12px rgba(0,0,0,.6);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; } /* the hidden attribute must beat display:grid/flex classes */
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font-family: var(--body); font-size: 18px; line-height: 1.6;
  min-height: 100dvh; overflow-x: hidden;
}
a { color: var(--violet); }
button { font: inherit; color: inherit; }
h1, h2, h3 { font-family: var(--display); line-height: 1.15; margin: 0 0 .4em; letter-spacing: -.01em; }
h1 { font-size: clamp(28px, 5.5vw, 38px); font-weight: 700; }
h2 { font-size: clamp(22px, 4.5vw, 27px); font-weight: 700; }
h3 { font-size: 20px; font-weight: 700; }
p { margin: 0 0 .9em; }
.muted { color: var(--ink-2); }
.small { font-size: 15.5px; line-height: 1.5; }
.eyebrow { font-family: var(--display); font-weight: 700; font-size: 13.5px; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-2); margin-bottom: 8px; }

/* top bar */
.top { position: sticky; top: 0; z-index: 5; background: var(--surface);
  display: flex; align-items: center; gap: 10px; padding: 10px var(--gutter); border-bottom: 1px solid var(--line); }
.brand { display: inline-flex; align-items: center; gap: 9px; text-decoration: none; color: var(--ink); font-family: var(--display); font-weight: 700; font-size: 19px; margin-right: auto; }
.brand-mark { width: 28px; height: 28px; }
.brand-mark rect { fill: var(--violet); }
.brand-mark path { stroke: var(--lime); stroke-width: 2.5; stroke-linecap: round; fill: none; }
.top-nav { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.chip { display: inline-flex; align-items: center; gap: 6px; min-height: 38px; padding: 6px 13px; border-radius: 999px; background: var(--paper); border: 1px solid var(--line); text-decoration: none; color: var(--ink); font-size: 15.5px; font-weight: 700; }
.chip.active { background: var(--violet); color: var(--violet-ink); border-color: var(--violet); }
.theme { width: 40px; height: 40px; border-radius: 999px; border: 1px solid var(--line); background: var(--paper); cursor: pointer; font-size: 18px; line-height: 1; flex: none; }
@media (max-width: 520px) {
  /* phones: brand + theme on the first line, the nav chips on their own line below */
  .top { flex-wrap: wrap; row-gap: 6px; padding: 8px var(--gutter) 8px; padding-top: calc(8px + env(safe-area-inset-top)); }
  .brand { font-size: 17px; }
  .brand-mark { width: 24px; height: 24px; }
  .theme { width: 36px; height: 36px; }
  .top-nav { order: 3; width: 100%; justify-content: flex-start; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .top-nav::-webkit-scrollbar { display: none; }
  .chip { white-space: nowrap; min-height: 34px; padding: 4px 12px; }
}
/* notched phones: keep content and the toast clear of the home bar */
.app { padding-bottom: calc(90px + env(safe-area-inset-bottom)); }
.toast { bottom: calc(24px + env(safe-area-inset-bottom)); }
@media (max-width: 360px) {
  :root { --gutter: 12px; }
  body { font-size: 17px; }
  .stat .n { font-size: 26px; }
  .stat .l { font-size: 13.5px; }
  .btn.big { font-size: 18px; }
}
/* tap feedback on touch screens, no sticky hover states */
@media (hover: none) {
  .btn:hover, .opt:hover, .kid:hover, .lattice.full a.tile:hover { background: inherit; border-color: var(--line); }
  .btn.primary:hover { background: var(--violet); border-color: var(--violet); }
  .btn.lime:hover { background: var(--lime); border-color: var(--lime); }
  .btn.danger:hover { background: var(--coral-soft); }
  .btn.primary, .btn.lime, .btn, .opt, .kid { -webkit-tap-highlight-color: transparent; }
  .btn:active, .opt:active, .kid:active { transform: scale(.98); }
}

/* layout */
.app { max-width: var(--maxw); margin: 0 auto; padding: 22px var(--gutter) 90px; }
.stack > * + * { margin-top: 18px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.card.flat { box-shadow: none; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.two-up { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 360px) { .two-up { grid-template-columns: 1fr; } }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 52px; padding: 12px 18px; border-radius: 14px;
  border: 1.5px solid var(--line); background: var(--surface); font-weight: 700; font-size: 17px; cursor: pointer; text-decoration: none; color: var(--ink); transition: transform .08s ease, background .15s; text-align: center; }
.btn:hover { background: var(--violet-soft); }
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--violet); color: var(--violet-ink); border-color: var(--violet); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.lime { background: var(--lime); color: var(--lime-ink); border-color: var(--lime); }
.btn.danger { background: var(--coral-soft); color: var(--coral); border-color: transparent; }
.btn.big { min-height: 62px; font-size: 19px; width: 100%; font-family: var(--display); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.small { min-height: 42px; font-size: 15.5px; padding: 8px 14px; }
.btn[disabled] { opacity: .5; cursor: default; }
:focus-visible { outline: 3px solid var(--violet); outline-offset: 2px; }

/* forms */
label { display: block; font-weight: 700; font-size: 16px; margin: 14px 0 6px; }
input[type=text], input[type=password], input[type=number], select, textarea {
  width: 100%; font: inherit; font-size: 17px; color: var(--ink); background: var(--paper); border: 1.5px solid var(--line); border-radius: var(--radius-sm); padding: 12px 14px; min-height: 50px; }
textarea { min-height: 96px; resize: vertical; line-height: 1.5; }
.radios { display: grid; gap: 8px; }
.radios label { display: flex; gap: 12px; align-items: center; margin: 0; padding: 12px 14px; border: 1.5px solid var(--line); border-radius: var(--radius-sm); background: var(--paper); font-weight: 400; font-size: 16.5px; cursor: pointer; }
.radios input { accent-color: var(--violet); width: 20px; height: 20px; flex: none; }

/* why-play strip on the picker */
.hooks { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.hook { display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto; column-gap: 10px; align-items: center; padding: 12px 14px; border-radius: 14px; background: var(--surface); border: 1.5px solid var(--line); }
.hook .ico { grid-row: 1 / 3; font-size: 28px; line-height: 1; }
.hook b { font-family: var(--display); font-size: 17px; line-height: 1.2; }
.hook span:not(.ico) { font-size: 14.5px; color: var(--ink-2); line-height: 1.35; }
@media (max-width: 640px) { .hooks { grid-template-columns: 1fr; gap: 8px; } .hook { padding: 10px 12px; } }

/* kid picker */
.kids { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 14px; }
.kid { display: grid; gap: 10px; text-align: left; padding: 18px; border-radius: var(--radius); border: 1.5px solid var(--line); background: var(--surface); box-shadow: var(--shadow); cursor: pointer; }
.kid:hover { border-color: var(--violet); }
.kid .emoji { font-size: 40px; line-height: 1; }
.kid .name { font-family: var(--display); font-weight: 700; font-size: 22px; }
.kid .meta { font-size: 15px; color: var(--ink-2); line-height: 1.4; }
.kid.test { border-style: dashed; }
.kid .badge { vertical-align: middle; font-size: 12px; }

/* the lattice */
.lattice { display: grid; gap: 6px; }
.lattice.mini { grid-template-columns: repeat(9, 1fr); max-width: 170px; gap: 4px; }
.lattice.mini .tile { aspect-ratio: 1; border-radius: 5px; border: 1.5px solid var(--line); background: var(--surface); position: relative; overflow: hidden; }
.lattice.mini .tile .fill { position: absolute; left: 0; right: 0; bottom: 0; height: var(--m, 0%); background: var(--violet); }
.lattice.mini .tile.mastered { border-color: var(--violet); background: var(--violet); }
.lattice.full { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.lattice.full .tile { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 6px 10px; padding: 12px 12px 10px; border-radius: 14px; border: 1.5px solid var(--line); background: var(--surface); text-decoration: none; color: var(--ink); min-height: 64px; }
.lattice.full a.tile:hover { border-color: var(--violet); }
.lattice.full .tile .num { width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; font-family: var(--display); font-weight: 700; font-size: 15px; background: var(--violet-soft); color: var(--violet); }
.lattice.full .tile .name { font-weight: 700; font-size: 15.5px; line-height: 1.2; }
.lattice.full .tile .check { color: var(--violet); font-weight: 700; font-size: 18px; }
.lattice.full .tile .bar { grid-column: 1 / -1; height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; }
.lattice.full .tile .bar i { display: block; height: 100%; background: var(--violet); transition: width .5s ease; }
.lattice.full .tile.mastered { border-color: var(--violet); background: var(--violet-soft); }
.tile.pulse { animation: pulse .7s ease; }
@keyframes pulse { 0% { transform: scale(1); } 40% { transform: scale(1.06); box-shadow: 0 0 0 6px color-mix(in srgb, var(--lime) 55%, transparent); } 100% { transform: scale(1); } }
.set-label { grid-column: 1 / -1; font-family: var(--display); font-weight: 700; font-size: 16px; color: var(--ink); margin-top: 10px; }
.set-label:first-child { margin-top: 0; }

/* reflex questions */
.reflex-row { display: flex; gap: 14px; align-items: flex-start; padding: 12px 0; border-top: 1px solid var(--line); }
.reflex-row:first-child { border-top: 0; padding-top: 4px; }
.reflex-row .n { flex: none; width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; font-family: var(--display); font-weight: 700; font-size: 17px; background: var(--violet-soft); color: var(--violet); }
.reflex-row.zero .n { background: var(--lime-soft); color: var(--lime-ink); }
.reflex-row b { font-size: 18px; line-height: 1.35; display: block; }

/* stats */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat { background: var(--paper); border-radius: var(--radius-sm); padding: 14px 10px; text-align: center; }
.stat .n { font-family: var(--display); font-weight: 700; font-size: 30px; line-height: 1; }
.stat .l { font-size: 14.5px; color: var(--ink-2); margin-top: 6px; line-height: 1.3; }

/* quiz */
.progress { display: flex; gap: 5px; margin-bottom: 16px; }
.progress i { flex: 1; height: 7px; border-radius: 4px; background: var(--line); }
.progress i.ok { background: var(--lime); }
.progress i.bad { background: var(--coral); }
.progress i.cur { background: var(--violet); }
.q { font-family: var(--display); font-weight: 700; font-size: clamp(21px, 4.5vw, 25px); line-height: 1.3; margin: 6px 0 20px; }
.options { display: grid; gap: 10px; }
.opt { min-height: 60px; text-align: left; padding: 14px 16px; border-radius: 14px; border: 2px solid var(--line); background: var(--surface); font-weight: 700; font-size: 18px; line-height: 1.3; cursor: pointer; color: var(--ink); }
.opt:hover { border-color: var(--violet); }
.opt.right { border-color: var(--lime); background: var(--lime-soft); }
.opt.wrong { border-color: var(--coral); background: var(--coral-soft); }
.opt[disabled] { cursor: default; }
.verdict { margin-top: 16px; padding: 16px 18px; border-radius: 14px; background: var(--violet-soft); line-height: 1.55; }
.verdict.bad { background: var(--amber-soft); }
.verdict .h { font-family: var(--display); font-weight: 700; font-size: 20px; margin-bottom: 6px; }
.verdict .ask { font-style: italic; margin-top: 10px; }

/* hints */
.hints { display: grid; gap: 8px; margin-top: 12px; }
.hint-box { padding: 10px 14px; border-radius: 12px; background: var(--amber-soft); font-size: 16px; line-height: 1.45; }
.opt.dim { opacity: .35; text-decoration: line-through; }

/* welcome walkthrough */
.welcome-card { text-align: center; padding: 34px 22px; }
.welcome-ico { font-size: 56px; line-height: 1; margin-bottom: 12px; }
.welcome-card p { font-size: 19px; line-height: 1.55; max-width: 34em; margin: 0 auto; }

/* the race */
.board { list-style: none; margin: 0; padding: 0; }
.board li { display: grid; grid-template-columns: 34px 1fr auto; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); font-size: 17px; }
.board li:first-child { border-top: 0; }
.board li.me { background: var(--violet-soft); margin: 0 -8px; padding: 10px 8px; border-radius: 10px; border-top: 0; }
.board .rank { width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; font-family: var(--display); font-weight: 700; background: var(--paper); }
.board li:first-child .rank { background: var(--lime); color: var(--lime-ink); }
.board .pts { font-family: var(--display); font-weight: 700; font-size: 20px; }

/* model page */
.tabs { display: flex; gap: 8px; margin: 14px 0 18px; }
.tabs button { flex: 1; min-height: 46px; padding: 6px 8px; border-radius: 12px; border: 1.5px solid var(--line); background: var(--surface); font-weight: 700; font-size: 15.5px; cursor: pointer; }
.tabs button.on { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.say { font-size: 15.5px; color: var(--ink-2); font-style: italic; }
.ask-line { font-family: var(--display); font-weight: 700; font-size: 21px; line-height: 1.3; padding: 14px 18px; border-left: 5px solid var(--lime); background: var(--paper); border-radius: 0 12px 12px 0; margin: 16px 0; }
.list { padding-left: 22px; margin: 0 0 1em; }
.list li { padding-left: 4px; }
.list li + li { margin-top: 10px; }
.model-row { display: flex; gap: 14px; align-items: center; padding: 14px 0; border-top: 1px solid var(--line); text-decoration: none; color: var(--ink); }
.model-row:first-of-type { border-top: 0; }
.model-row .n { width: 32px; height: 32px; flex: none; border-radius: 9px; display: grid; place-items: center; font-family: var(--display); font-weight: 700; font-size: 15px; background: var(--violet-soft); color: var(--violet); }
.model-row .t { flex: 1; }
.model-row .t b { display: block; font-size: 17px; }
.model-row .t span { font-size: 15.5px; color: var(--ink-2); line-height: 1.4; }
.model-row .m { width: 48px; height: 7px; border-radius: 4px; background: var(--line); overflow: hidden; flex: none; }
.model-row .m i { display: block; height: 100%; background: var(--violet); }

/* parent activity strip */
.act-strip { display: grid; grid-template-columns: repeat(14, 1fr); gap: 4px; margin: 8px 0 6px; }
.act-day { display: grid; gap: 3px; justify-items: center; }
.act-day i { display: block; width: 100%; aspect-ratio: 1; border-radius: 5px; background: var(--line); }
.act-day.l1 i { background: color-mix(in srgb, var(--violet) 35%, var(--surface)); }
.act-day.l2 i { background: color-mix(in srgb, var(--violet) 65%, var(--surface)); }
.act-day.l3 i { background: var(--violet); }
.act-day.today i { outline: 2px solid var(--ink); outline-offset: 1px; }
.act-day span { font-size: 11px; color: var(--ink-2); line-height: 1; }

/* sightings */
.sight { border-top: 1px solid var(--line); padding: 14px 0; }
.sight:first-of-type { border-top: 0; }
.badge { display: inline-block; font-size: 13.5px; font-weight: 700; padding: 3px 10px; border-radius: 999px; background: var(--paper); border: 1px solid var(--line); white-space: nowrap; }
.badge.approved { background: var(--lime); color: var(--lime-ink); border-color: var(--lime); }
.badge.declined { background: var(--coral-soft); color: var(--coral); border-color: transparent; }
.badge.pending { background: var(--amber-soft); }
.quote { border-left: 3px solid var(--line); padding-left: 12px; color: var(--ink-2); margin: 8px 0; line-height: 1.5; }

/* videos */
.video-wrap { display: grid; grid-template-columns: 148px 1fr; gap: 12px; align-items: start; padding: 12px 0; border-top: 1px solid var(--line); }
.video-wrap:first-of-type { border-top: 0; }
.video-wrap.dim { opacity: .8; }
.video { position: relative; aspect-ratio: 16 / 9; border-radius: 10px; overflow: hidden; background: var(--ink); cursor: pointer; }
.video img { width: 100%; height: 100%; object-fit: cover; display: block; }
.video .play { position: absolute; inset: 0; display: grid; place-items: center; color: #fff; font-size: 28px; text-shadow: 0 2px 8px rgba(0,0,0,.6); }
.video iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.video-wrap:has(.playing) { grid-template-columns: 1fr; }
.video-meta b { display: block; line-height: 1.3; font-size: 16.5px; }
details summary { cursor: pointer; padding: 8px 0; font-weight: 700; }
@media (max-width: 420px) { .video-wrap { grid-template-columns: 120px 1fr; } }

/* flashcards */
.flip { display: block; width: 100%; min-height: 260px; padding: 0; border: 0; background: transparent; cursor: pointer; perspective: 1200px; text-align: left; font: inherit; color: inherit; }
.flip-inner { position: relative; width: 100%; min-height: 260px; transition: transform .55s cubic-bezier(.2,.7,.2,1); transform-style: preserve-3d; }
.flip.flipped .flip-inner { transform: rotateY(180deg); }
.flip .face { position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden; display: flex; flex-direction: column; justify-content: center; padding: 22px; border-radius: var(--radius); border: 2px solid var(--ink); background: var(--surface); box-shadow: 8px 8px 0 var(--violet-soft); overflow: auto; }
.flip .face.back { transform: rotateY(180deg); background: var(--lime-soft); border-color: var(--lime-ink); }
.flip .face-big { font-family: var(--display); font-weight: 700; font-size: clamp(28px, 6vw, 40px); line-height: 1.1; }
.flip .face-mid { font-family: var(--display); font-weight: 700; font-size: clamp(20px, 4.4vw, 26px); line-height: 1.3; }
.flip:not(.flipped) .face.front::after { content: "tap to flip"; position: absolute; right: 14px; bottom: 10px; font-size: 13px; color: var(--ink-2); }
@media (prefers-reduced-motion: reduce) { .flip-inner { transition: none; } }

/* tutor chat */
.chat { display: grid; gap: 10px; margin-bottom: 12px; }
.bubble { padding: 12px 16px; border-radius: 16px; max-width: 92%; line-height: 1.5; white-space: pre-wrap; }
.bubble.user { background: var(--violet); color: var(--violet-ink); justify-self: end; border-bottom-right-radius: 4px; }
.bubble.tutor { background: var(--paper); border: 1px solid var(--line); justify-self: start; border-bottom-left-radius: 4px; }
.bubble.sys { background: var(--lime-soft); color: var(--lime-ink); font-size: 15.5px; justify-self: stretch; max-width: none; }
.bubble.err { background: var(--coral-soft); color: var(--coral); }
.starters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.starters .chip { cursor: pointer; font-weight: 400; min-height: 36px; }
.askform { display: flex; gap: 8px; align-items: flex-end; }
.askform textarea { flex: 1; min-height: 52px; }
.askform .btn { min-height: 52px; }

/* BS or Not */
.bs-btn { background: var(--ink); color: var(--paper); border-color: var(--ink); flex-direction: column; gap: 2px; line-height: 1.25; }
.bs-btn:hover { filter: brightness(1.15); background: var(--ink); }
.bs-btn.done { background: var(--surface); color: var(--ink); border-color: var(--line); }
.bs-btn .small { color: inherit; opacity: .8; }
.scenario { background: var(--surface); border: 2px solid var(--ink); border-radius: var(--radius); padding: 20px; box-shadow: 6px 6px 0 var(--violet-soft); }
.scenario-setup { margin: 6px 0 10px; color: var(--ink-2); font-size: 16.5px; line-height: 1.45; }
.scenario-text { font-family: var(--display); font-weight: 700; font-size: clamp(21px, 4.5vw, 26px); line-height: 1.3; }
.verdicts { display: grid; gap: 10px; }
.verdicts .opt { display: grid; gap: 3px; }
.verdicts .opt span { font-weight: 400; }
.opt.v-bs.on { border-color: var(--coral); background: var(--coral-soft); }
.opt.v-check.on { border-color: #E0A800; background: var(--amber-soft); }
.opt.v-legit.on { border-color: var(--lime); background: var(--lime-soft); }
.opt.qpick { display: flex; gap: 12px; align-items: center; font-weight: 400; font-size: 17px; }
.opt.qpick.on { border-color: var(--violet); background: var(--violet-soft); }
.opt.qpick .qn { flex: none; width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; font-family: var(--display); font-weight: 700; background: var(--violet-soft); color: var(--violet); }
.opt.qpick.on .qn { background: var(--violet); color: var(--violet-ink); }

.empty { text-align: center; padding: 28px 12px; color: var(--ink-2); }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: var(--paper); padding: 13px 20px; border-radius: 999px; font-weight: 700; font-size: 16px; box-shadow: var(--shadow); z-index: 20; max-width: calc(100% - 32px); }
.jar { font-family: var(--display); font-weight: 700; font-size: 22px; color: var(--violet); }
hr { border: 0; border-top: 1px solid var(--line); margin: 18px 0; }

@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
