:root {
  --brand: #a0522d; --brand-dark: #7a3d20; --cream: #fbf3e9; --paper: #ffffff; --ink: #2b2118; --muted: #7d6b5d;
  --line: #ecdfd0; --ok: #2e9d5b; --ok-bg: #e5f6ec; --bad: #d64545; --bad-bg: #fde9e7; --gold: #f2b01e;
  --maths: #2f6fb5; --francais: #d9534f; --radius: 18px; --shadow: 0 6px 18px rgba(122, 61, 32, .10);
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--cream); color: var(--ink);
  font-family: "Cairo", "Nunito", system-ui, sans-serif; font-size: 17px; line-height: 1.6;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}
[dir="ltr"], .ltr { font-family: "Nunito", "Cairo", system-ui, sans-serif; }
span.ltr { unicode-bidi: isolate; direction: ltr; white-space: nowrap; }
a { color: inherit; text-decoration: none; }
button { font: inherit; cursor: pointer; }
.n { font-family: "Nunito", system-ui, sans-serif; font-weight: 700; unicode-bidi: isolate; direction: ltr; }
bdi.n { white-space: nowrap; }

/* top bar + tabs */
.topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; background: var(--brand); color: #fff; box-shadow: 0 2px 10px rgba(0,0,0,.12); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; }
.brand img { width: 40px; height: 40px; border-radius: 10px; background: #fff; object-fit: contain; }
.brand b { font-family: "Nunito", sans-serif; }
.xp { background: rgba(255,255,255,.18); border-radius: 30px; padding: 4px 14px; font-weight: 700; }
.top-right { display: flex; align-items: center; gap: 8px; }
.acct { display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px; border-radius: 50%;
  background: rgba(255,255,255,.18); font-size: 18px; }
.acct.on { background: #fff; box-shadow: 0 0 0 2px var(--ok); }
.account { display: flex; align-items: center; gap: 12px; }
.account img, .account .avatar { width: 52px; height: 52px; border-radius: 50%; object-fit: cover; display: inline-flex;
  align-items: center; justify-content: center; background: var(--cream); font-size: 26px; }
.btn.google { background: #fff; color: var(--ink); border: 2px solid var(--line); }
.btn.google .g { font-family: "Nunito", sans-serif; font-weight: 800; color: #4285f4; font-size: 20px; }
.mailform input { width: 100%; font: inherit; padding: 12px 14px; border: 2px solid var(--line); border-radius: 14px;
  margin-top: 10px; background: var(--paper); }
.mailform input:focus { outline: none; border-color: var(--brand); }
.linklike { background: none; border: 0; color: var(--brand); font: inherit; font-size: 14px; margin-top: 10px; padding: 4px 0; text-decoration: underline; }
.tabs { position: fixed; bottom: 0; left: 0; right: 0; z-index: 5; display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--paper); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.tabs a { display: flex; flex-direction: column; align-items: center; padding: 8px 2px 10px; font-size: 13px; color: var(--muted); font-weight: 600; }
.tabs a span { font-size: 22px; line-height: 1.2; }
.tabs a.on { color: var(--brand); }

/* layout */
main { max-width: 720px; margin: 0 auto; padding: 16px; outline: none; }
h1 { font-size: 24px; margin: 6px 0 14px; line-height: 1.35; }
h2 { font-size: 19px; margin: 22px 0 10px; }
.card { background: var(--paper); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px; }
.muted { color: var(--muted); font-size: 14px; }
.row { display: flex; align-items: center; gap: 12px; }
.grow { flex: 1; min-width: 0; }
.back { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-weight: 600; margin-bottom: 6px; }

/* book (cover image drawn as a book: spine on the left, page edge, shadow) */
.book { position: relative; display: inline-block; flex: none; background: #1d7a49; padding: 0 0 0 9px;
  border-radius: 4px 10px 10px 4px; box-shadow: 0 14px 28px rgba(20, 40, 25, .32), 0 2px 4px rgba(20, 40, 25, .18); }
.book::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 9px; border-radius: 4px 0 0 4px;
  background: linear-gradient(90deg, #12502f, #1f8550 55%, #12502f); }
.book::after { content: ""; position: absolute; top: 4px; bottom: 4px; right: -4px; width: 4px; border-radius: 0 3px 3px 0;
  background: repeating-linear-gradient(180deg, #f1e7da 0 2px, #fff 2px 4px); }
.book img { display: block; width: 100%; height: auto; border-radius: 0 9px 9px 0; }
.book.sm { width: 92px; transform: rotate(-4deg); }
.book.lg { width: min(170px, 46vw); transform: rotate(-3deg); }

/* home */
.hero { background: linear-gradient(135deg, var(--brand-dark), var(--brand) 55%, #c4733f); color: #fff;
  border-radius: 24px; padding: 18px 18px 16px; margin-bottom: 14px; box-shadow: var(--shadow); position: relative; overflow: hidden; }
.hero::after { content: ""; position: absolute; width: 220px; height: 220px; border-radius: 50%; left: -70px; bottom: -110px;
  background: rgba(255, 255, 255, .07); pointer-events: none; }
.hero-top { display: flex; align-items: center; gap: 14px; }
.hero h1 { margin: 0 0 4px; font-size: 25px; }
.hero p { margin: 0; opacity: .92; font-size: 15px; }
.hero input { width: 100%; margin-top: 10px; border: 0; border-radius: 12px; padding: 10px 14px; font: inherit; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 16px; position: relative; z-index: 1; }
.stat { background: rgba(255,255,255,.16); border: 1px solid rgba(255,255,255,.18); border-radius: 16px; padding: 8px 4px;
  text-align: center; font-size: 13px; line-height: 1.3; }
.stat span { display: block; font-size: 16px; }
.stat b { display: block; font-size: 22px; font-family: "Nunito", sans-serif; }
.continue { display: flex; align-items: center; gap: 12px; background: var(--paper); border-radius: var(--radius); padding: 12px 14px;
  box-shadow: var(--shadow); margin-bottom: 12px; border-inline-start: 6px solid var(--c); }
.continue .ic { width: 46px; height: 46px; border-radius: 14px; background: var(--c); display: inline-flex; align-items: center;
  justify-content: center; font-size: 24px; flex: none; }
.continue small { display: block; color: var(--muted); font-weight: 700; font-size: 12px; }
.continue b { display: block; line-height: 1.35; }
.continue .go, .nudge b { width: 34px; height: 34px; border-radius: 50%; background: var(--cream); color: var(--brand);
  display: inline-flex; align-items: center; justify-content: center; font-weight: 800; flex: none; }
.nudge { display: flex; align-items: center; gap: 10px; background: #fff6ee; border: 1.5px dashed #e3c2a4; color: var(--brand-dark);
  border-radius: 16px; padding: 10px 14px; font-weight: 700; font-size: 15px; margin-bottom: 4px; }
.subjects { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.subject { position: relative; overflow: hidden; border-radius: 22px; padding: 14px; color: #fff; background: var(--c);
  box-shadow: 0 8px 18px rgba(0, 0, 0, .12); min-height: 150px; display: flex; flex-direction: column; gap: 4px;
  transition: transform .15s ease; }
.subject:active { transform: scale(.97); }
.subject::after { content: ""; position: absolute; width: 120px; height: 120px; border-radius: 50%; left: -40px; top: -50px;
  background: rgba(255, 255, 255, .12); pointer-events: none; }
.subject-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: auto; }
.subject .ic { width: 48px; height: 48px; border-radius: 16px; background: rgba(255,255,255,.95); display: inline-flex;
  align-items: center; justify-content: center; font-size: 26px; }
.subject .pct { background: rgba(0,0,0,.16); border-radius: 20px; padding: 1px 10px; font-size: 14px; }
.chip-soon { background: rgba(255,255,255,.9); color: var(--ink); border-radius: 20px; padding: 1px 10px; font-size: 12px; font-weight: 700; }
.subject b { font-size: 19px; line-height: 1.3; margin-top: 10px; }
.sub-meta { font-size: 13px; opacity: .92; }
.subject.soon { filter: saturate(.55); opacity: .85; }

/* welcome (first screen) */
body.welcome-mode { padding-bottom: 0; background: linear-gradient(180deg, var(--brand) 0 190px, var(--cream) 190px); }
body.welcome-mode .topbar, body.welcome-mode .tabs { display: none; }
.welcome { display: grid; gap: 8px; padding-top: 8px; }
.welcome-art { display: flex; flex-direction: column; align-items: center; gap: 14px; }
.welcome-logo { width: 52px; height: 52px; border-radius: 16px; background: #fff; object-fit: contain; padding: 4px;
  box-shadow: 0 4px 12px rgba(0,0,0,.15); }
.welcome-main { text-align: center; }
.welcome-main h1 { margin: 16px 0 2px; font-size: 24px; }
.welcome-main > p { font-size: 15px; }
.welcome-main > p { margin: 0 auto; color: var(--muted); max-width: 420px; }
.perks { list-style: none; padding: 0; margin: 12px 0; display: flex; justify-content: center; gap: 6px; flex-wrap: wrap; }
.perks li { background: var(--paper); border-radius: 30px; padding: 3px 10px; font-size: 13px; font-weight: 700; box-shadow: var(--shadow);
  display: inline-flex; align-items: center; gap: 6px; }
.welcome-card { text-align: start; max-width: 440px; margin: 0 auto 24px; }
.welcome-card > b { font-size: 18px; }
.welcome-card > .muted { margin: 0 0 12px; }
.small { font-size: 13px; text-align: center; margin: 10px 0 0; }
.or { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 14px; margin: 14px 0; }
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.mailbox { margin-top: 10px; }
.passage { background: var(--cream); border-radius: 14px; padding: 8px 14px; margin-bottom: 12px; font-size: 15px; line-height: 1.8; }
.passage summary { cursor: pointer; font-weight: 700; color: var(--brand); }
.passage p { margin: 8px 0; }
.mailbox summary { cursor: pointer; color: var(--brand); font-weight: 700; text-align: center; padding: 8px; list-style: none; }
.mailbox summary::-webkit-details-marker { display: none; }
.mailbox summary::after { content: " ▾"; }
.mailbox[open] summary::after { content: " ▴"; }
.btns.two { grid-template-columns: 1fr 1fr; }
@media (min-width: 820px) {
  body.welcome-mode { background: linear-gradient(90deg, var(--brand) 0 46%, var(--cream) 46%); }
  body.welcome-mode main { max-width: 1000px; }
  .welcome { grid-template-columns: 1fr 1fr; align-items: center; min-height: calc(100vh - 32px); gap: 40px; }
  .welcome-art { order: 2; }
  .book.lg { width: 290px; }
  .welcome-logo { width: 64px; height: 64px; }
  .welcome-main h1 { font-size: 32px; }
}
.bar { height: 8px; background: rgba(0,0,0,.08); border-radius: 8px; overflow: hidden; }
.subject .bar { background: rgba(255,255,255,.3); }
.bar i { display: block; height: 100%; background: var(--ok); border-radius: 8px; }
.subject .bar i { background: #fff; }

/* lesson list */
.unit-title { font-weight: 800; color: var(--muted); margin: 18px 4px 8px; }
.lesson { display: flex; align-items: center; gap: 12px; background: var(--paper); border-radius: 14px; padding: 12px 14px; margin-bottom: 8px; box-shadow: var(--shadow); }
.lesson .num { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 800; flex: none; font-family: "Nunito", sans-serif; }
.lesson.soon { opacity: .55; box-shadow: none; }
.stars { color: var(--gold); letter-spacing: 1px; white-space: nowrap; }
.stars .off { color: #ddd; }
.tag { font-size: 12px; background: var(--line); color: var(--muted); border-radius: 20px; padding: 2px 10px; white-space: nowrap; }

/* lesson summary */
.summary h3 { color: var(--brand); margin: 16px 0 6px; font-size: 18px; }
.summary h3:first-child { margin-top: 0; }
.summary ul { padding-inline-start: 20px; margin: 6px 0; }
.summary li { margin: 4px 0; }
.numtable { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; text-align: center; margin: 10px 0; }
.numtable div { background: var(--cream); border-radius: 10px; padding: 6px 2px; }
.numtable span { display: block; font-size: 12px; color: var(--muted); }
.numtable b { font-size: 20px; }
.units { display: flex; flex-wrap: wrap; gap: 4px; margin: 8px 0; }
.units span, .units b { flex: 1 0 auto; text-align: center; background: var(--cream); border-radius: 8px; padding: 4px 6px; font-size: 14px; }
.units b { background: var(--brand); color: #fff; }
table.abbr { border-collapse: collapse; width: 100%; font-size: 15px; }
table.abbr td { border-bottom: 1px solid var(--line); padding: 5px 6px; }
table.abbr td:nth-child(odd) { font-weight: 800; color: var(--brand); width: 18%; }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 0; border-radius: 14px; padding: 12px 20px; font-weight: 700; background: var(--brand); color: #fff; min-height: 48px; }
.btn.block { display: flex; width: 100%; }
.btn.ghost { background: var(--paper); color: var(--brand); border: 2px solid var(--brand); }
.btn:disabled { opacity: .45; cursor: default; }
.btns { display: grid; gap: 10px; margin-top: 14px; }

/* quiz */
.progress-top { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.progress-top .bar { flex: 1; }
.progress-top .bar i { background: var(--brand); }
.qtext { font-size: 20px; font-weight: 700; margin: 4px 0 16px; line-height: 1.55; }
.choices { display: grid; gap: 10px; }
.choice { text-align: start; background: var(--paper); border: 2px solid var(--line); border-radius: 14px; padding: 12px 16px; min-height: 52px; font-weight: 600; }
.choice.sel { border-color: var(--brand); background: #fff6ee; }
.choice.good { border-color: var(--ok); background: var(--ok-bg); }
.choice.wrong { border-color: var(--bad); background: var(--bad-bg); }
.answer-input { width: 100%; font: inherit; font-size: 22px; padding: 12px 16px; border: 2px solid var(--line); border-radius: 14px; background: var(--paper); text-align: center; }
.answer-input:focus { outline: none; border-color: var(--brand); }
.slots { min-height: 64px; border: 2px dashed var(--line); border-radius: 14px; padding: 8px; display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; background: var(--paper); }
.pool { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { border: 2px solid var(--line); background: var(--paper); border-radius: 12px; padding: 8px 14px; font-weight: 700; min-height: 44px; }
.slots .chip { border-color: var(--brand); background: #fff6ee; }
.feedback { border-radius: 14px; padding: 12px 16px; margin-top: 14px; font-weight: 600; }
.feedback.ok { background: var(--ok-bg); color: #1d6b3d; }
.feedback.bad { background: var(--bad-bg); color: #9b2c2c; }
.feedback small { display: block; font-weight: 400; color: var(--ink); margin-top: 4px; }
.timer { font-family: "Nunito", sans-serif; font-weight: 800; background: var(--paper); border-radius: 20px; padding: 2px 12px; }
.timer.low { color: var(--bad); }

/* results */
.result { text-align: center; }
.result .big { font-size: 54px; font-weight: 800; font-family: "Nunito", sans-serif; color: var(--brand); line-height: 1.1; }
.result .stars { font-size: 40px; }
.review { text-align: start; }
.review li { margin-bottom: 10px; }

/* progress / parents */
.badges { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.badge { background: var(--paper); border-radius: 14px; padding: 12px 6px; text-align: center; box-shadow: var(--shadow); font-size: 13px; font-weight: 700; }
.badge span { display: block; font-size: 32px; }
.badge.off { opacity: .35; filter: grayscale(1); box-shadow: none; }
.kv { display: flex; justify-content: space-between; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.kv:last-child { border-bottom: 0; }
.danger { color: var(--bad); background: none; border: 0; font-weight: 700; padding: 10px 0; }

@media (min-width: 600px) {
  .subjects { grid-template-columns: 1fr 1fr; }
  .badges { grid-template-columns: repeat(6, 1fr); }
}

/* ---- student code sign-in */
.codeform { display: grid; gap: 10px; margin-top: 10px; }
.code-input { font: 800 30px/1.2 Nunito, system-ui, sans-serif; letter-spacing: .35em; text-align: center; padding: 12px 8px 12px calc(8px + .35em);
  border: 2px solid var(--line, #ddd); border-radius: 14px; width: 100%; box-sizing: border-box; background: #fff; color: inherit; }
.code-input:focus { outline: none; border-color: var(--brand, #A0522D); box-shadow: 0 0 0 3px rgba(160, 82, 45, .15); }
.code-show { font: 800 26px/1.3 Nunito, system-ui, sans-serif; letter-spacing: .2em; direction: ltr; text-align: right; }
