:root {
  --bg: #f6f5fb; --fg: #1d1b2e; --card: #ffffff; --muted: #6b6880; --border: #e2e0ee;
  --accent: #4f46e5; --accent-fg: #ffffff; --good: #15803d; --good-bg: #dcfce7; --bad: #b91c1c; --bad-bg: #fee2e2;
  --radius: 14px; --shadow: 0 6px 20px -12px rgb(40 30 100 / 35%);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12111c; --fg: #f1f0fa; --card: #1d1b2c; --muted: #a09db8; --border: #34314a;
    --accent: #8b85ff; --accent-fg: #12111c; --good: #4ade80; --good-bg: #123522; --bad: #f87171; --bad-bg: #3d1717;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--fg); font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
.wrap { width: min(100% - 2rem, 760px); margin-inline: auto; }
main { padding: 1.25rem 0 5rem; outline: none; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5rem; }
h1, h2, .brand, .quiz-q { font-family: var(--font-display, inherit); }
h1 { font-size: 1.7rem; } h2 { font-size: 1.25rem; } h3 { font-size: 1.05rem; }
p { margin: 0 0 .75rem; }
.muted { color: var(--muted); } .small { font-size: .85rem; }

.top { position: sticky; top: 0; z-index: 5; background: var(--card); border-bottom: 1px solid var(--border); }
.top-inner { display: flex; align-items: center; justify-content: space-between; gap: .5rem; padding: .35rem 0; flex-wrap: wrap; }
.brand { font-weight: 800; font-size: 1.15rem; text-decoration: none; color: var(--fg); }
#nav { display: flex; gap: .25rem; flex-wrap: wrap; }
.tab { display: inline-flex; align-items: center; gap: .35rem; background: none; border: 0; border-radius: 999px; padding: .5rem .8rem; font: inherit; font-weight: 600; color: var(--muted); cursor: pointer; }
.tab:hover { color: var(--fg); }
.tab.active { background: var(--accent); color: var(--accent-fg); }

.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.1rem; margin-bottom: 1rem; box-shadow: var(--shadow); }
.row { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; }
.row.space { justify-content: space-between; }
.grow { flex: 1 1 12rem; min-width: 0; }
.grid2 { display: grid; gap: .75rem; grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr)); }

.stat { text-align: center; padding: .6rem .4rem; border-radius: 12px; background: var(--bg); }
.stat b { display: block; font-size: 1.5rem; line-height: 1.1; }
.stat span { font-size: .8rem; color: var(--muted); }

button, .btn { font: inherit; font-weight: 600; border-radius: 12px; border: 1px solid var(--border); background: var(--card); color: var(--fg); padding: .65rem 1rem; cursor: pointer; min-height: 44px; }
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: .5; cursor: not-allowed; }
button.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
button.big { width: 100%; font-size: 1.1rem; padding: .9rem 1rem; }
button.danger { color: var(--bad); }
button.ghost { background: none; border-color: transparent; color: var(--muted); }
button.small { min-height: 36px; padding: .3rem .7rem; font-size: .85rem; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

label { display: block; font-size: .9rem; font-weight: 600; margin-bottom: .65rem; }
input, select, textarea { display: block; width: 100%; margin-top: .25rem; font: inherit; font-weight: 400; color: var(--fg); background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: .6rem .7rem; min-height: 44px; }
textarea { min-height: 5rem; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 3px solid var(--accent); outline-offset: 1px; }

.bar { height: 12px; border-radius: 999px; background: var(--bg); border: 1px solid var(--border); overflow: hidden; }
.bar-fill { height: 100%; background: var(--accent); border-radius: 999px; transition: width .4s ease; }

.quiz-q { font-size: 1.35rem; font-weight: 700; white-space: pre-wrap; overflow-wrap: anywhere; margin: .5rem 0 1rem; }
.choices { display: grid; gap: .6rem; }
.choices button { text-align: left; white-space: normal; }
.verdict { border-radius: 12px; padding: .8rem 1rem; margin-bottom: .75rem; font-weight: 600; }
.verdict.good { background: var(--good-bg); color: var(--good); }
.verdict.bad { background: var(--bad-bg); color: var(--bad); }
.verdict .ans { display: block; color: var(--fg); font-weight: 500; margin-top: .25rem; overflow-wrap: anywhere; }
.tag { display: inline-block; font-size: .75rem; font-weight: 700; padding: .1rem .55rem; border-radius: 999px; background: var(--bg); border: 1px solid var(--border); color: var(--muted); }

.week { display: grid; grid-template-columns: repeat(7, 1fr); gap: .4rem; align-items: end; height: 110px; }
.week .col { display: flex; flex-direction: column; justify-content: flex-end; align-items: center; height: 100%; gap: .2rem; font-size: .75rem; color: var(--muted); }
.week .fill { width: 100%; max-width: 38px; background: var(--accent); border-radius: 6px 6px 2px 2px; min-height: 3px; opacity: .85; }
.heat { display: grid; grid-template-rows: repeat(7, 1fr); grid-auto-flow: column; grid-auto-columns: 1fr; gap: 3px; }
.heat i { aspect-ratio: 1; border-radius: 3px; background: var(--bg); border: 1px solid var(--border); }
.heat i.l1 { background: color-mix(in srgb, var(--accent) 25%, var(--card)); }
.heat i.l2 { background: color-mix(in srgb, var(--accent) 50%, var(--card)); }
.heat i.l3 { background: color-mix(in srgb, var(--accent) 75%, var(--card)); }
.heat i.l4 { background: var(--accent); }
.heat i.future { visibility: hidden; }

.badges { display: grid; gap: .6rem; grid-template-columns: repeat(auto-fill, minmax(10.5rem, 1fr)); }
.badge { border: 1px solid var(--border); border-radius: 12px; padding: .7rem; background: var(--bg); }
.badge .ico { font-size: 1.8rem; display: block; }
.badge.locked { opacity: .55; filter: grayscale(1); }
.badge b { display: block; }

.item { display: flex; gap: .6rem; align-items: flex-start; justify-content: space-between; padding: .7rem 0; border-top: 1px solid var(--border); }
.item:first-child { border-top: 0; }
.item .txt { min-width: 0; overflow-wrap: anywhere; }
.item .a { color: var(--muted); font-size: .9rem; }

#toasts { position: fixed; left: 0; right: 0; bottom: 1rem; display: grid; justify-items: center; gap: .5rem; pointer-events: none; z-index: 20; padding: 0 1rem; }
.toast { background: var(--fg); color: var(--bg); padding: .65rem 1rem; border-radius: 12px; font-weight: 600; box-shadow: 0 10px 30px -10px rgb(0 0 0 / 50%); max-width: 30rem; }
.banner { background: var(--bad-bg); color: var(--bad); border-radius: 12px; padding: .7rem 1rem; margin-bottom: 1rem; font-weight: 600; }
@media (prefers-reduced-motion: reduce) { .bar-fill { transition: none; } }

/* ---------- account bar ---------- */
.user { display: flex; align-items: center; gap: .5rem; font-size: .85rem; flex-wrap: wrap; }
.who { color: var(--muted); font-weight: 600; }
.sync { color: var(--muted); font-size: .8rem; }
.sync.warn { color: var(--bad); font-weight: 600; }
.auth { max-width: 26rem; margin: 2rem auto; }
.auth .banner { margin: .5rem 0 1rem; }

/* ---------- study buddy ---------- */
.buddy { position: relative; width: 4.5rem; height: 4.5rem; flex: none; display: grid; place-items: center; background: var(--bg); border-radius: 50%; border: 1px solid var(--border); }
.buddy .pet { font-size: 2.4rem; line-height: 1; }
.buddy .hat { position: absolute; top: -.55rem; left: 50%; transform: translateX(-50%) rotate(-8deg); font-size: 1.6rem; line-height: 1; }
.prize { border-color: var(--accent); }

/* ---------- pick lists, shop ---------- */
.pick { display: flex; gap: .6rem; align-items: flex-start; padding: .6rem 0; border-top: 1px solid var(--border); font-weight: 400; margin: 0; }
.pick .a { display: block; color: var(--muted); font-size: .9rem; overflow-wrap: anywhere; }
.pick > span { min-width: 0; overflow-wrap: anywhere; }
input[type="checkbox"] { width: 1.25rem; height: 1.25rem; min-height: 0; margin: .2rem 0 0; flex: none; accent-color: var(--accent); }
.shop { display: grid; gap: .6rem; grid-template-columns: repeat(auto-fill, minmax(9.5rem, 1fr)); }
.shop-item { display: grid; gap: .4rem; }
.swatch { display: flex; align-items: flex-end; min-height: 3.6rem; padding: .5rem .6rem; border-radius: 10px; border: 1px solid var(--border); font-weight: 700; font-size: .95rem; overflow-wrap: anywhere; }
.swatch.fontsw { align-items: center; background: var(--bg); color: var(--fg); font-size: 1.05rem; font-weight: 400; }
.swatch.hatsw { flex-direction: column; align-items: center; justify-content: center; background: var(--bg); color: var(--fg); font-size: 1.8rem; gap: .1rem; }
button[aria-pressed="true"] { cursor: default; }

/* ---------- unlocked colour themes (set by the app from the Shop) ---------- */
:root[data-palette] {
  --bg: var(--pal-bg); --fg: var(--pal-ink);
  --card: color-mix(in oklab, var(--pal-bg) 88%, white);
  --muted: color-mix(in oklab, var(--pal-ink) 68%, var(--pal-bg));
  --border: color-mix(in oklab, var(--pal-bg) 72%, var(--pal-ink));
  --accent: var(--pal-ink); --accent-fg: var(--pal-bg);
  --good: var(--pal-ink); --good-bg: color-mix(in oklab, var(--pal-bg) 80%, var(--pal-ink));
  --bad: var(--pal-ink); --bad-bg: color-mix(in oklab, var(--pal-bg) 80%, var(--pal-ink));
  --shadow: none;
}
:root[data-palette] .toast { background: var(--pal-ink); color: var(--pal-bg); }

/* ---------- farm ---------- */
.brand { user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; touch-action: manipulation; }
.farm { position: relative; border-radius: var(--radius); margin-bottom: 1rem; padding: 1rem .75rem 1.1rem; border: 1px solid var(--border); overflow: hidden;
  background: linear-gradient(to bottom, color-mix(in srgb, var(--accent) 12%, var(--card)) 0 22%, color-mix(in srgb, var(--good) 22%, var(--card)) 22% 100%); }
.farm::before { content: "☁️      ☀️      ☁️"; position: absolute; top: .2rem; left: 0; right: 0; text-align: center; letter-spacing: .35rem; opacity: .7; font-size: 1.2rem; pointer-events: none; }
.farm-grid { position: relative; display: grid; gap: .6rem; grid-template-columns: repeat(auto-fill, minmax(7.5rem, 1fr)); padding-top: 1.2rem; }
.pet-card { display: grid; justify-items: center; gap: .15rem; text-align: center; padding: .6rem .3rem; background: color-mix(in srgb, var(--card) 80%, transparent); }
.pet-card.on { border-color: var(--accent); outline: 2px solid var(--accent); }
.pet-emoji { position: relative; font-size: 2.6rem; line-height: 1.1; display: inline-block; animation: bob 2.4s ease-in-out infinite; }
.pet-emoji .hat { position: absolute; top: -.7rem; left: 50%; transform: translateX(-50%) rotate(-8deg); font-size: 1.4rem; }
.pet-name { font-weight: 700; overflow-wrap: anywhere; }
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-.35rem); } }

/* ---------- the hidden parade ---------- */
.parade { position: fixed; inset: 0; pointer-events: none; z-index: 30; overflow: hidden; }
.runner { position: absolute; top: var(--y); left: -4rem; font-size: var(--s); animation: march 6.5s linear var(--d) forwards; }
@keyframes march { 0% { transform: translateX(0) translateY(0) rotate(-6deg); } 25% { transform: translateX(30vw) translateY(-1.2rem) rotate(6deg); } 50% { transform: translateX(60vw) translateY(0) rotate(-6deg); } 75% { transform: translateX(90vw) translateY(-1.2rem) rotate(6deg); } 100% { transform: translateX(calc(100vw + 5rem)) translateY(0) rotate(0); } }
@media (prefers-reduced-motion: reduce) { .pet-emoji { animation: none; } .runner { animation: none; display: none; } }

/* ===== Layout: phone vs computer ===== */
.tab span:first-child { font-size: 1.15rem; line-height: 1; }

/* Phones and small tablets: app-style bottom tab bar, thumb-sized buttons */
@media (max-width: 719px) {
  .wrap { width: min(100% - 1.5rem, 640px); }
  .top-inner { flex-wrap: nowrap; }
  .brand { font-size: 1.05rem; }
  .user { font-size: .8rem; justify-content: flex-end; }
  #nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 0; background: var(--card); border-top: 1px solid var(--border); padding: .25rem .25rem calc(.25rem + env(safe-area-inset-bottom)); }
  .tab { flex-direction: column; gap: .1rem; border-radius: 12px; padding: .4rem .1rem; font-size: .7rem; min-height: 52px; justify-content: center; }
  .tab span:first-child { font-size: 1.4rem; }
  main { padding: 1rem 0 calc(6.5rem + env(safe-area-inset-bottom)); }
  #toasts { bottom: calc(5rem + env(safe-area-inset-bottom)); }
  h1 { font-size: 1.5rem; }
  .card { padding: .9rem; border-radius: 14px; }
  .grid2 { grid-template-columns: repeat(2, 1fr); }
  .shop { grid-template-columns: repeat(2, 1fr); }
  .farm-grid { grid-template-columns: repeat(2, 1fr); }
  button.big, .row > button.primary { min-height: 52px; }
  .quiz-q { font-size: 1.25rem; }
}

/* Computers: side menu on the left, wider content, bigger grids */
@media (min-width: 960px) {
  body { font-size: 17px; }
  .top-inner.wrap { width: min(100% - 4rem, 1240px); }
  #nav { position: fixed; top: 4.2rem; left: max(1.5rem, calc(50% - 620px)); width: 11.5rem; flex-direction: column; gap: .25rem; flex-wrap: nowrap; }
  .tab { justify-content: flex-start; border-radius: 12px; padding: .7rem .9rem; font-size: 1rem; }
  .tab:hover:not(.active) { background: var(--bg); }
  main.wrap { width: min(100% - 4rem, 1240px); padding-left: 13.5rem; padding-top: 1.75rem; box-sizing: border-box; }
  h1 { font-size: 2rem; }
  .card { padding: 1.25rem 1.4rem; }
  .grid2 { grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr)); }
  .shop { grid-template-columns: repeat(auto-fill, minmax(11.5rem, 1fr)); }
  .farm-grid { grid-template-columns: repeat(auto-fill, minmax(10rem, 1fr)); }
  .quiz-q { font-size: 1.6rem; }
  button.big { width: auto; min-width: 14rem; }
}
@media (min-width: 1500px) { body { font-size: 18px; } }
@media (min-width: 960px) { body:has(#nav:empty) main.wrap { padding-left: 0; width: min(100% - 4rem, 620px); } }
@media (min-width: 960px) { .heat { max-width: 640px; } }
