/* Layout: a clean French school sheet — no ruling, only the red margin and dashed row dividers. One page per screen, swipe to turn. English appears in the teacher's red pen and pushes the lines below it down. Dark theme = slate and chalk. */
:root {
  --paper: #EEF0EA;
  --sheet: #FBFBF9;
  --ink: #1D2858;          /* encre bleue */
  --ink2: #414A78;
  --muted: #6F7391;
  --rule: #DDDCE8;         /* dashed row dividers */
  --edge: #D5D4E3;
  --margin: #D2524A;       /* red margin line */
  --gloss: #B8372C;        /* teacher's red pen */
  --hi: #FFE45C;           /* surligneur */
  --hi-ink: #1D2858;
  --tint: #F1F1F6;
  --ok: #2E7D4F; --ok-bg: #E2F3E8;
  --bad: #B3362C; --bad-bg: #FBE5E2;
  --sky: #CFE3EF; --sun: #F6C94C; --hill: #9FC29A; --stone: #EDE6D6; --stone-dk: #CFC5AE;
  --ground: #D8C9A9; --wall: #F1E3C8; --board: #2F4B3F; --chalk: #F4F4EC; --wood: #A86F43;
  --awn1: #C8433A; --awn2: #FBF6EC;
  --skin-a: #F1C9A5; --skin-b: #A86F48; --skin-c: #E6B48C;
  --hair-brown: #6B3F26; --hair-black: #221C18; --hair-grey: #BDBDBD; --hair-auburn: #9A4A22;
  --c-yellow: #F2B632; --c-blue: #2F5DA8; --c-red: #C8433A; --c-green: #4E8B5A; --c-trousers: #34405F;
  --face: #2A2320; --bubble: #FFFFFF;
  --who-lea: #8A5A12; --who-arjun: #2F5DA8; --who-dubois: #B3362C; --who-thomas: #3F7A4B;
  --who-sophie: #7A3E9D; --who-karim: #B0571B; --who-martin: #3F6E66;
  --c-purple: #8C5BB8; --c-orange: #E07B39; --c-teal: #3E8C83; --skin-d: #C68A5E; --apron: #F4F1E8;
  --leaf: #6FA36B; --leaf-dk: #4E7F4C; --sea: #5FA3C8; --snow: #F7F7F4; --brick: #C9876A; --glass: #BFD9E6; --cream: #F6E7C8; --sofa: #5C7FA8; --tile: #E4E9EC;
  --f-display: "Young Serif", Georgia, "Times New Roman", serif;
  --f-body: "Literata", Georgia, "Times New Roman", serif;
  --f-hand: "Caveat", "Segoe Print", "Bradley Hand", cursive;
  --bar-h: 56px;
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) {
  --paper: #161D1A; --sheet: #1F2925; --ink: #EEF0E6; --ink2: #C8D0C4; --muted: #8E9A92;
  --rule: #34433D; --edge: #2E3B36; --margin: #C9685D; --gloss: #F2A08C;
  --hi: #E8D25A; --hi-ink: #1A1E14; --tint: #26312C;
  --ok: #7FD39C; --ok-bg: #1F3A2A; --bad: #F29B8F; --bad-bg: #432421;
  --sky: #2B3F4C; --sun: #E9C35A; --hill: #3F5E44; --stone: #CFC7B4; --stone-dk: #A69D86;
  --ground: #5A4E3B; --wall: #4A4235; --board: #22382E; --chalk: #E9EAE0; --wood: #7C5233;
  --awn1: #A8372F; --awn2: #E6DFD0; --bubble: #F7F7F1;
  --who-lea: #F2C25A; --who-arjun: #8FB4F2; --who-dubois: #F29B8F; --who-thomas: #8FD39C;
  --who-sophie: #D7A8F2; --who-karim: #F2B07F; --who-martin: #9CD3C8;
  --leaf: #4F7C4D; --leaf-dk: #3A5E39; --sea: #3D6E8A; --snow: #D9DCD4; --brick: #8E5C47; --glass: #55717E; --cream: #6B5F48; --sofa: #3D5675; --tile: #39443F;
  color-scheme: dark;
} }
:root[data-theme="dark"] {
  --paper: #161D1A; --sheet: #1F2925; --ink: #EEF0E6; --ink2: #C8D0C4; --muted: #8E9A92;
  --rule: #34433D; --edge: #2E3B36; --margin: #C9685D; --gloss: #F2A08C;
  --hi: #E8D25A; --hi-ink: #1A1E14; --tint: #26312C;
  --ok: #7FD39C; --ok-bg: #1F3A2A; --bad: #F29B8F; --bad-bg: #432421;
  --sky: #2B3F4C; --sun: #E9C35A; --hill: #3F5E44; --stone: #CFC7B4; --stone-dk: #A69D86;
  --ground: #5A4E3B; --wall: #4A4235; --board: #22382E; --chalk: #E9EAE0; --wood: #7C5233;
  --awn1: #A8372F; --awn2: #E6DFD0; --bubble: #F7F7F1;
  --who-lea: #F2C25A; --who-arjun: #8FB4F2; --who-dubois: #F29B8F; --who-thomas: #8FD39C;
  --who-sophie: #D7A8F2; --who-karim: #F2B07F; --who-martin: #9CD3C8;
  --leaf: #4F7C4D; --leaf-dk: #3A5E39; --sea: #3D6E8A; --snow: #D9DCD4; --brick: #8E5C47; --glass: #55717E; --cream: #6B5F48; --sofa: #3D5675; --tile: #39443F;
  color-scheme: dark;
}

html, body { height: 100%; }
body { margin: 0; background: var(--paper); color: var(--ink); font-family: var(--f-body); font-size: 16px; line-height: 1.5; overflow: hidden; }
* { box-sizing: border-box; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 2px solid var(--margin); outline-offset: 2px; border-radius: 4px; }

.app { height: 100%; display: flex; flex-direction: column; }

/* top bar */
.top { flex: 0 0 auto; display: flex; align-items: center; gap: 10px; min-height: var(--bar-h);
  padding-top: env(safe-area-inset-top, 0px);
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
  border-bottom: 1px solid var(--edge); background: var(--paper); }
.brand { font-family: var(--f-display); font-size: 15px; color: var(--margin); letter-spacing: .02em; }
.top .crumb { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.15; }
.top .crumb b { font-family: var(--f-display); font-weight: 400; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top .crumb span { font-size: 12px; color: var(--muted); letter-spacing: .06em; text-transform: uppercase; }
.pill { display: inline-flex; align-items: center; gap: 6px; border: 1.5px solid var(--ink); background: transparent; border-radius: 999px;
  padding: 6px 12px; font-size: 13px; font-weight: 600; cursor: pointer; letter-spacing: .04em; white-space: nowrap; touch-action: manipulation; }
.pill[aria-pressed="true"] { background: var(--ink); color: var(--sheet); }
.pill svg { width: 16px; height: 16px; }
.pill small { font-family: var(--f-hand); font-size: 15px; font-weight: 500; letter-spacing: 0; color: var(--gloss); }
.pill[aria-pressed="true"] small { color: var(--hi); }

/* book */
.book { flex: 1 1 auto; min-height: 0; display: flex; overflow-x: auto; overflow-y: hidden; scroll-snap-type: x mandatory;
  scrollbar-width: none; overscroll-behavior-x: contain; }
.book::-webkit-scrollbar { display: none; }
.page { flex: 0 0 100%; width: 100%; height: 100%; overflow-y: auto; scroll-snap-align: start; scroll-snap-stop: always;
  padding-left: max(12px, env(safe-area-inset-left, 0px)); padding-right: max(12px, env(safe-area-inset-right, 0px)); padding-block: 14px 28px; }
.sheet { position: relative; max-width: 640px; margin: 0 auto; background-color: var(--sheet);
  background-image: linear-gradient(to right, transparent 33px, var(--margin) 33px, var(--margin) 34.5px, transparent 34.5px);
  border: 1px solid var(--edge); border-radius: 6px;
  padding: 22px 18px 26px 46px; min-height: 100%; display: flex; flex-direction: column; gap: 18px; }
.sheet > * { min-width: 0; }
.folio { position: absolute; top: 10px; right: 14px; font-family: var(--f-hand); font-size: 20px; color: var(--muted); }

.eyebrow { font-size: 12px; letter-spacing: .12em; text-transform: uppercase; color: var(--margin); font-weight: 600; }
h1, h2 { font-family: var(--f-display); font-weight: 400; margin: 0; text-wrap: balance; line-height: 1.1; }
h1 { font-size: clamp(44px, 13vw, 72px); }
h2 { font-size: 28px; }
.head { display: flex; flex-direction: column; gap: 4px; }

/* Any French text with its English hidden underneath. Revealing pushes the content below down. */
.fr { position: relative; display: block; touch-action: manipulation; -webkit-user-select: none; user-select: none; cursor: pointer;
  -webkit-tap-highlight-color: transparent; border-radius: 4px; }
.fr .t { font-size: 18px; }
h1.fr .t, h2.fr .t, .eyebrow.fr .t, .note .fr .t, .twocol .fr .t { font-size: inherit; }
.fr .en { display: block; font-family: var(--f-hand); font-size: 21px; font-weight: 500; color: var(--gloss); line-height: 1.15;
  text-transform: none; letter-spacing: 0;
  max-height: 0; opacity: 0; overflow: hidden; transform: translateY(-4px); transition: max-height .25s ease, opacity .2s ease, transform .2s ease; }
h2.fr .en { font-size: 25px; }
.eyebrow.fr .en { font-size: 18px; }
.fr.open .en, body.all-en .fr .en { max-height: 5em; opacity: 1; transform: none; }
.fr:active { background: var(--tint); }
.fr .hint { display: inline-block; width: 6px; height: 6px; margin-left: 6px; border-radius: 50%; background: var(--gloss); opacity: .35; vertical-align: 3px; }
.fr.open .hint, body.all-en .fr .hint { opacity: 0; }

.say { flex: 0 0 auto; width: 36px; height: 36px; border-radius: 50%; border: 1.5px solid var(--edge); background: var(--sheet);
  display: grid; place-items: center; cursor: pointer; color: var(--ink2); touch-action: manipulation; }
.say svg { width: 16px; height: 16px; }
.say.playing { background: var(--hi); color: var(--hi-ink); border-color: var(--hi); }
body.no-tts .say { display: none; }

/* vocab list */
.vocab { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.vocab li { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px dashed var(--rule); }
.vocab li .fr { flex: 1; min-width: 0; }
.vocab .tag { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); border: 1px solid var(--rule);
  border-radius: 4px; padding: 0 5px; margin-left: 6px; vertical-align: 2px; font-family: var(--f-body); }
.vocab li, .dialog li { cursor: pointer; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }

/* scene */
.art { border-radius: 8px; overflow: hidden; border: 1.5px solid var(--ink); background: var(--sky); }
.art svg { display: block; width: 100%; height: auto; }
.dialog { display: flex; flex-direction: column; margin: 0; padding: 0; list-style: none; }
.dialog li { display: grid; grid-template-columns: 74px 1fr auto; gap: 8px; align-items: start; padding: 8px 0; border-bottom: 1px dashed var(--rule); }
.who { font-size: 13px; font-weight: 600; letter-spacing: .04em; padding-top: 3px; }

.note { border-left: 4px solid var(--hi); background: var(--tint); padding: 10px 12px; border-radius: 0; font-size: 16px; display: flex; flex-direction: column; gap: 6px; }
.note > .fr:first-child .t { font-family: var(--f-display); font-size: 17px; }

/* cover */
.cover-sticker { align-self: flex-start; background: var(--hi); color: var(--hi-ink); font-weight: 600; font-size: 13px; letter-spacing: .1em;
  text-transform: uppercase; padding: 4px 10px; transform: rotate(-2deg); border-radius: 2px; }
.cover-sticker .en { color: var(--hi-ink) !important; }
.toc { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.toc button { width: 100%; display: flex; align-items: baseline; gap: 8px; background: none; border: 0; padding: 8px 0; cursor: pointer; text-align: left;
  border-bottom: 1px dashed var(--rule); touch-action: manipulation; }
.toc .n { font-family: var(--f-hand); font-size: 20px; color: var(--margin); width: 22px; flex: 0 0 auto; }
.toc .l { flex: 1; font-size: 17px; }
.toc .e { font-family: var(--f-hand); font-size: 18px; color: var(--muted); }
.how { display: grid; gap: 10px; }
.how div { display: flex; gap: 10px; align-items: flex-start; font-size: 15px; }
.how svg { flex: 0 0 auto; width: 28px; height: 28px; color: var(--margin); }
.try { border: 1.5px dashed var(--gloss); padding: 8px 10px; border-radius: 8px; }

/* grammar */
.conj { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 14px; }
.conj .fr { padding: 6px 8px; background: var(--tint); }
.conj .fr .t b { color: var(--margin); font-weight: 600; }
.twocol { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.twocol > div { background: var(--tint); border-radius: 6px; padding: 10px; display: flex; flex-direction: column; gap: 8px; font-size: 16px; }
.twocol h3 { margin: 0; font-family: var(--f-display); font-weight: 400; font-size: 26px; }

/* numbers */
.nums { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 8px; }
.num { border: 1.5px solid var(--edge); background: var(--sheet); border-radius: 8px; padding: 8px 6px; cursor: pointer; text-align: center;
  display: flex; flex-direction: column; touch-action: manipulation; }
.num b { font-family: var(--f-display); font-weight: 400; font-size: 26px; line-height: 1.1; font-variant-numeric: tabular-nums; }
.num span { font-size: 15px; }
.num.playing { background: var(--hi); color: var(--hi-ink); border-color: var(--hi); }

/* exercises */
.ex { display: flex; flex-direction: column; gap: 10px; }
.ex h3 { margin: 0; font-family: var(--f-display); font-weight: 400; font-size: 20px; display: flex; gap: 6px; }
.ex h3 .fr .t { font-size: inherit; }
.q { display: flex; flex-direction: column; gap: 8px; padding: 10px 0; border-bottom: 1px dashed var(--rule); }
.opts { display: flex; flex-wrap: wrap; gap: 8px; }
.opt { border: 1.5px solid var(--ink2); background: var(--sheet); border-radius: 999px; padding: 7px 14px; cursor: pointer; font-size: 16px; touch-action: manipulation; }
.opt:disabled { cursor: default; }
.opt.right { background: var(--ok-bg); border-color: var(--ok); color: var(--ok); font-weight: 600; }
.opt.wrong { background: var(--bad-bg); border-color: var(--bad); color: var(--bad); text-decoration: line-through; }
.score { display: flex; align-items: center; justify-content: space-between; gap: 12px; background: var(--tint); border-radius: 8px; padding: 10px 12px; }
.score b { font-family: var(--f-display); font-weight: 400; font-size: 26px; font-variant-numeric: tabular-nums; }
.model { display: none; }
.model.show { display: flex; }

.credits p { margin: 0; font-size: 15px; }
.credits a { color: var(--ink); text-decoration-color: var(--margin); text-underline-offset: 3px; }
.links { display: flex; flex-direction: column; gap: 6px; margin: 0; padding-left: 18px; font-size: 15px; }

/* bottom nav */
.nav { flex: 0 0 auto; display: flex; align-items: center; gap: 10px; min-height: var(--bar-h);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
  border-top: 1px solid var(--edge); background: var(--paper); }
.nav .arrow { width: 42px; height: 42px; border-radius: 50%; border: 1.5px solid var(--ink); background: transparent; cursor: pointer; display: grid; place-items: center; touch-action: manipulation; }
.nav .arrow:disabled { opacity: .3; cursor: default; }
.nav .arrow svg { width: 18px; height: 18px; }
.dots { flex: 1; display: flex; justify-content: center; gap: 6px; flex-wrap: wrap; }
.dot { width: 9px; height: 9px; border-radius: 50%; border: 1.5px solid var(--ink2); background: transparent; padding: 0; cursor: pointer; }
.dot.on { background: var(--hi); border-color: var(--ink); transform: scale(1.25); }

.toast { position: fixed; left: 50%; bottom: calc(var(--bar-h) + 14px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%);
  background: var(--ink); color: var(--sheet); font-size: 14px; padding: 8px 14px; border-radius: 999px; opacity: 0; pointer-events: none; transition: opacity .2s; max-width: calc(100% - 32px); text-align: center; }
.toast.show { opacity: 1; }

@media (max-width: 380px) {
  .sheet { padding-left: 42px; padding-right: 14px; }
  .dialog li { grid-template-columns: 62px 1fr auto; }
  .twocol, .conj { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) { .fr .en { transition: none; } }

/* back button + library */
.back { width: 38px; height: 38px; border-radius: 50%; border: 1.5px solid var(--ink); background: transparent; display: grid; place-items: center; cursor: pointer; flex: 0 0 auto; touch-action: manipulation; }
.back svg { width: 18px; height: 18px; }
.library { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding-left: max(12px, env(safe-area-inset-left, 0px)); padding-right: max(12px, env(safe-area-inset-right, 0px)); padding-block: 14px 28px; }
.library .sheet { min-height: 0; }
.lib-title { font-family: var(--f-display); font-size: clamp(48px, 15vw, 76px); line-height: 1; margin: 0; }
.lib-sub { font-family: var(--f-hand); font-size: 22px; color: var(--gloss); }
.level { display: flex; align-items: baseline; gap: 10px; margin-top: 6px; }
.level b { background: var(--hi); color: var(--hi-ink); font-size: 13px; letter-spacing: .1em; padding: 2px 8px; border-radius: 2px; }
.level span { font-size: 13px; color: var(--muted); }
.lessons { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.lesson-btn { width: 100%; display: grid; grid-template-columns: 34px 1fr auto; gap: 10px; align-items: center; text-align: left; background: none; border: 0; border-bottom: 1px dashed var(--rule); padding: 10px 0; cursor: pointer; touch-action: manipulation; }
.lesson-btn .n { font-family: var(--f-hand); font-size: 26px; color: var(--margin); line-height: 1; }
.lesson-btn .t { font-family: var(--f-display); font-size: 19px; line-height: 1.15; display: block; }
.lesson-btn .e { font-family: var(--f-hand); font-size: 18px; color: var(--muted); display: block; line-height: 1.1; }
.lesson-btn .prog { font-size: 12px; color: var(--muted); text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.lesson-btn .prog i { display: block; font-style: normal; color: var(--ok); }
.lib-note { font-size: 14px; color: var(--muted); }
.lib-note a { color: var(--ink); text-decoration-color: var(--margin); text-underline-offset: 3px; }

/* profile button */
.me { width: 38px; height: 38px; border-radius: 50%; border: 0; background: var(--who-arjun); color: var(--sheet); font: 600 16px var(--f-body); display: grid; place-items: center; cursor: pointer; position: relative; flex: 0 0 auto; touch-action: manipulation; }
.me i { position: absolute; top: 0; right: 0; width: 10px; height: 10px; border-radius: 50%; background: var(--margin); border: 2px solid var(--paper); }

/* invitation card */
.invite { border: 1.5px dashed var(--margin); border-radius: 8px; padding: 10px 12px; display: flex; flex-direction: column; gap: 6px; }
.invite > .fr:first-child .t { font-family: var(--f-display); font-size: 18px; }
.invite-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 2px; }
.pill.ghost { border-color: var(--edge); }
.pill.solid { background: var(--ink); color: var(--sheet); }
.pill.solid small { color: var(--hi); }

/* profile sheet */
.me-wrap { position: fixed; inset: 0; z-index: 50; }
.me-dim { position: absolute; inset: 0; background: rgba(15, 20, 45, .45); }
.me-sheet { position: absolute; left: 0; right: 0; bottom: 0; max-width: 560px; margin: 0 auto; max-height: 88%; overflow-y: auto;
  background: var(--sheet); color: var(--ink); border-radius: 16px 16px 0 0; display: flex; flex-direction: column; gap: 6px;
  padding: 14px max(18px, env(safe-area-inset-right, 0px)) calc(18px + env(safe-area-inset-bottom, 0px)) max(18px, env(safe-area-inset-left, 0px)); }
.me-head { display: flex; align-items: center; justify-content: space-between; }
.me-x { width: 36px; height: 36px; border: 0; background: none; font-size: 26px; line-height: 1; cursor: pointer; color: var(--muted); }
.me-q { display: block; margin-top: 8px; font-size: 18px; }
.me-q .t { font-size: 18px; }
.me-in { width: 100%; font: 17px var(--f-body); color: var(--ink); background: var(--paper); border: 1.5px solid var(--ink2); border-radius: 8px; padding: 10px 12px; }
.me-in:focus { outline: 2px solid var(--margin); outline-offset: 1px; }
.me-picked { font-family: var(--f-hand); font-size: 19px; color: var(--gloss); min-height: 0; }
.me-picked:empty { display: none; }
.me-list { list-style: none; margin: 0; padding: 0; border: 1px solid var(--edge); border-radius: 8px; overflow: hidden; }
.me-list li { display: flex; align-items: baseline; gap: 6px; padding: 10px 12px; border-bottom: 1px dashed var(--rule); cursor: pointer; }
.me-list li:last-child { border-bottom: 0; }
.me-list li:active { background: var(--tint); }
.me-list li em { font-style: normal; color: var(--muted); font-size: 14px; }
.me-list li span { margin-left: auto; color: var(--muted); font-size: 14px; text-align: right; }
.me-err { color: var(--bad); font-size: 14px; }
.me-err span { color: var(--muted); }
.me-seg { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.me-seg button { border: 1.5px solid var(--edge); background: var(--paper); border-radius: 10px; padding: 10px 8px; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 2px; touch-action: manipulation; }
.me-seg button b { font: 400 18px var(--f-display); }
.me-seg button span { font-size: 13px; color: var(--muted); }
.me-seg button[aria-checked="true"] { border-color: var(--ink); background: var(--hi); color: var(--hi-ink); }
.me-seg button[aria-checked="true"] span { color: var(--hi-ink); }
.me-row { display: flex; justify-content: space-between; gap: 10px; margin-top: 12px; }
.me-fine { margin: 6px 0 0; font-size: 12px; color: var(--muted); }
.me-fine a { color: var(--muted); }
