/* Cartoon look of the A1 stories library: thick outlines, round corners, solid offset shadows. No dark theme. */
@font-face { font-family: "Baloo 2"; font-style: normal; font-weight: 500 800; font-display: swap; src: url("assets/fonts/baloo2-latin.woff2") format("woff2"); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: "Baloo 2"; font-style: normal; font-weight: 500 800; font-display: swap; src: url("assets/fonts/baloo2-latin-ext.woff2") format("woff2"); unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF; }
@font-face { font-family: "Nunito"; font-style: normal; font-weight: 600 800; font-display: swap; src: url("assets/fonts/nunito-latin.woff2") format("woff2"); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: "Nunito"; font-style: normal; font-weight: 600 800; font-display: swap; src: url("assets/fonts/nunito-latin-ext.woff2") format("woff2"); unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF; }

:root {
  --sky: #9fd8ff; --sky-2: #e9f7ff; --ink: #1d2b4f; --blue: #13598b; --gold: #f5b51b;
  --green: #17743f; --paper: #fffdf6; --line: #1d2b4f;
  --display: "Baloo 2", ui-rounded, "Arial Rounded MT Bold", "Trebuchet MS", system-ui, sans-serif;
  --body: "Nunito", ui-rounded, "Segoe UI", system-ui, sans-serif;
}
* { box-sizing: border-box; }
body {
  margin: 0; min-height: 100vh; color: var(--ink); font-family: var(--body); font-weight: 600;
  background: radial-gradient(circle at 15% 10%, #fff 0 60px, transparent 61px), radial-gradient(circle at 80% 6%, #fff 0 40px, transparent 41px), linear-gradient(var(--sky), var(--sky-2) 60%) fixed;
}
button { font: inherit; color: inherit; }
h1, h2, .badge, .chip, .read-ribbon { font-family: var(--display); }
.wrap { max-width: 1180px; margin: 0 auto; padding: 20px 16px 60px; }

.top { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.hero { display: flex; align-items: center; gap: 16px; }
.mascot { flex: none; }
.hero h1 { font-size: clamp(2rem, 4vw, 3.2rem); margin: 0; line-height: 1; text-shadow: 3px 3px 0 #fff; }
.subtitle { margin: 6px 0 0; font-size: 1.1rem; font-weight: 800; }

.language-selector { display: flex; gap: 6px; flex-wrap: wrap; }
.language-button { border: 3px solid var(--line); border-radius: 999px; background: #fff; padding: 4px 12px; font-weight: 800; cursor: pointer; box-shadow: 0 3px 0 var(--line); }
.language-button[aria-pressed="true"] { background: var(--gold); }

.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 18px; }
.chip { border: 3px solid var(--line); border-radius: 999px; background: #fff; padding: 2px 16px; font-size: 1.05rem; font-weight: 800; cursor: pointer; box-shadow: 0 3px 0 var(--line); }
.chip[aria-pressed="true"] { background: var(--blue); color: #fff; }
.chip:focus-visible, .language-button:focus-visible, .mark input:focus-visible + .box, .card-link:focus-visible { outline: 4px solid #3aa0ff; outline-offset: 3px; }

.empty { margin: 30px auto; max-width: 560px; padding: 18px 22px; text-align: center; font-family: var(--display); font-size: 1.4rem; font-weight: 800; background: var(--paper); border: 4px solid var(--line); border-radius: 26px; box-shadow: 0 8px 0 var(--line); }
.empty[hidden], .read-ribbon[hidden] { display: none; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 24px; }
.card { position: relative; overflow: hidden; background: var(--paper); border: 4px solid var(--line); border-radius: 26px; box-shadow: 0 8px 0 var(--line); transition: transform 0.15s; cursor: pointer; }
.card:hover { transform: translateY(-4px) rotate(-0.6deg); }
.pic { aspect-ratio: 16 / 10; background: #cfe9ff; border-bottom: 4px solid var(--line); overflow: hidden; }
.pic img { display: block; width: 100%; height: 100%; object-fit: cover; }
.card.read .pic { filter: saturate(0.75); }
.body { padding: 12px 16px 16px; }
.body h2 { margin: 0 0 6px; font-size: 1.45rem; line-height: 1.1; }
.card-link { color: inherit; text-decoration: none; }
.card-link:hover { text-decoration: underline; }
.meta { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-weight: 800; font-size: 0.95rem; }
.badge { border: 3px solid var(--line); border-radius: 12px; padding: 0 10px; background: var(--gold); font-weight: 800; }
.badge.b2 { background: #8fd3ff; }
.badge.b3 { background: #ffb3c1; }
.read-ribbon { position: absolute; top: 18px; right: -42px; transform: rotate(35deg); background: var(--green); color: #fff; border: 3px solid var(--line); padding: 2px 46px; font-weight: 800; white-space: nowrap; }
.progress { height: 14px; margin-top: 10px; border: 3px solid var(--line); border-radius: 999px; background: #fff; overflow: hidden; }
.progress i { display: block; height: 100%; background: var(--gold); }
.mark { position: relative; display: flex; align-items: center; gap: 8px; margin-top: 12px; font-weight: 800; cursor: pointer; user-select: none; }
.mark input { position: absolute; opacity: 0; width: 30px; height: 30px; margin: 0; cursor: pointer; }
.box { flex: none; width: 30px; height: 30px; display: grid; place-items: center; border: 3px solid var(--line); border-radius: 9px; background: #fff; color: transparent; font-size: 1.2rem; font-weight: 800; }
.mark input:checked + .box { background: var(--green); color: #fff; }

/* ---- Chapter reader ---- */
[hidden] { display: none !important; }
/* The reader fills the viewport: the question, the answers and the buttons stay visible at the bottom of the card,
   only the paragraph area scrolls when the text is too long. */
.rwrap { max-width: 1280px; margin: 0 auto; padding: 8px 16px 18px; height: 100vh; height: 100dvh; display: flex; flex-direction: column; }
.rtop { flex: none; display: flex; align-items: center; flex-wrap: wrap; gap: 8px 12px; margin-bottom: 12px; }
.rtop h1 { margin: 0; font-size: clamp(1.3rem, 2.2vw, 2rem); line-height: 1; }
.rtools { margin-left: auto; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.rtools .language-selector { gap: 4px; }
.rtools .language-button { padding: 2px 8px; box-shadow: 0 2px 0 var(--line); }
.rtools .language-name { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.steps { flex: 1 0 100%; display: flex; gap: 3px; }
.steps span { flex: 1; height: 14px; border: 3px solid var(--line); border-radius: 999px; background: #fff; }
.steps span.passed { background: var(--green); }
.steps span.now { background: var(--gold); }

.btn { display: inline-block; border: 4px solid var(--line); border-radius: 20px; background: #fff; padding: 8px 18px; font-family: var(--display); font-weight: 800; font-size: clamp(1.1rem, 1.7vw, 1.5rem); line-height: 1.2; text-align: left; color: var(--ink); text-decoration: none; cursor: pointer; box-shadow: 0 5px 0 var(--line); }
.btn.small { padding: 3px 12px; border-width: 3px; border-radius: 16px; font-size: 1rem; box-shadow: 0 3px 0 var(--line); }
.btn.go { background: var(--gold); text-align: center; }
.btn:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 2px 0 var(--line); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn:focus-visible, .w:focus-visible, .pchoice:focus-visible { outline: 4px solid #3aa0ff; outline-offset: 3px; }

.stage { flex: 0 1 auto; min-height: 0; background: var(--paper); border: 5px solid var(--line); border-radius: 30px; box-shadow: 0 8px 0 var(--line); padding: 16px 22px 18px; display: grid; grid-template-rows: minmax(0, 1fr); gap: 12px; }
.paras {
  display: grid; align-content: start; gap: 8px; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding-right: 6px;
  scrollbar-width: auto; scrollbar-color: #7d8aab transparent;
  /* Scroll shadows: covers that move with the content hide the shadows when there is nothing more to scroll. */
  background:
    linear-gradient(var(--paper) 40%, rgb(255 253 246 / 0)) top / 100% 28px no-repeat local,
    linear-gradient(rgb(255 253 246 / 0), var(--paper) 60%) bottom / 100% 28px no-repeat local,
    radial-gradient(farthest-side at 50% 0, rgb(29 43 79 / 0.35), transparent) top / 100% 14px no-repeat scroll,
    radial-gradient(farthest-side at 50% 100%, rgb(29 43 79 / 0.35), transparent) bottom / 100% 14px no-repeat scroll;
}
/* Steps showing one paragraph (pictures, quiz) keep the whole paragraph readable: if it does not fit with the
   answers, the page scrolls as a normal page instead of clipping the text. */
body[data-layout="flow"] .rwrap { height: auto; min-height: 100vh; min-height: 100dvh; }
body[data-layout="flow"] .stage { flex: none; grid-template-rows: none; }
body[data-layout="flow"] .paras { overflow: visible; padding-right: 0; background: none; }
/* The update banner is fixed at the bottom: keep the pinned buttons clear of it. */
body:has(> .update-banner) .rwrap { padding-bottom: 104px; }
.paras::-webkit-scrollbar { width: 12px; }
.paras::-webkit-scrollbar-thumb { background: #7d8aab; border-radius: 999px; border: 3px solid var(--paper); }
.paras:focus { outline: none; }
.para { margin: 0; font-size: clamp(2rem, 2.4vw, 2.4rem); line-height: 1.45; font-weight: 800; }
.para.dim { opacity: 0.6; }
.tok { white-space: nowrap; }
.w { display: inline-block; margin: 0; padding: 0 3px; border: 0; border-bottom: 3px solid transparent; border-radius: 10px; background: none; font: inherit; line-height: inherit; color: inherit; cursor: default; }
.para.active .w { cursor: pointer; border-bottom: 3px dotted #7d8aab; }
.para.active .w:hover { background: #fff1c2; }
.w[data-state] { border-bottom-color: transparent; }
.w[data-state]::after { font-size: 0.6em; margin-left: 3px; font-weight: 800; }
.w[data-state="good"] { background: var(--green); color: #fff; animation: pop 0.3s; }
.w[data-state="good"]::after { content: "✓"; }
.w[data-state="why"] { background: #8fd0ff; color: var(--ink); box-shadow: inset 0 0 0 3px #0b4a7a; animation: pop 0.3s; }
.w[data-state="why"]::after { content: "✓"; color: #0b4a7a; }
.w[data-state="bad"] { background: #ffd3da; color: var(--ink); animation: shake 0.4s; }
.w[data-state="bad"]::after { content: "✗"; color: #a3112c; }
@keyframes pop { 50% { transform: scale(1.15); } }
@keyframes shake { 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }

.ask { display: flex; align-items: center; gap: 12px; background: var(--blue); color: #fff; border: 4px solid var(--line); border-radius: 22px; padding: 6px 16px 6px 10px; }
.ask-mascot { flex: none; width: 52px; height: 52px; }
.ask-text { font-family: var(--display); font-weight: 800; font-size: clamp(1.3rem, 2vw, 1.8rem); line-height: 1.15; }

.choices { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.pchoice { position: relative; display: block; padding: 0; border: 5px solid var(--line); border-radius: 22px; overflow: hidden; background: #fff; cursor: default; box-shadow: 0 6px 0 var(--line); transition: transform 0.15s; }
.pchoice img { display: block; width: 100%; aspect-ratio: 16 / 9; max-height: 30vh; max-height: 30dvh; object-fit: cover; background: #cfe9ff; }
.pchoice[aria-disabled="false"] { cursor: pointer; }
.pchoice[aria-disabled="false"]:hover { transform: translateY(-3px); }
.lbl { position: absolute; top: 8px; left: 8px; width: 42px; height: 42px; display: grid; place-items: center; border: 3px solid var(--line); border-radius: 50%; background: var(--gold); font-family: var(--display); font-weight: 800; font-size: 1.5rem; }
.stamp { position: absolute; display: none; place-items: center; font-weight: 800; }
.pchoice .stamp { top: 8px; right: 8px; width: 42px; height: 42px; border: 3px solid var(--line); border-radius: 50%; font-size: 1.6rem; }
.pchoice[data-state="right"] { outline: 8px solid var(--green); outline-offset: -5px; }
.pchoice[data-state="right"] .stamp { display: grid; background: var(--green); color: #fff; }
.pchoice[data-state="right"] .stamp::before { content: "✓"; }
.pchoice[data-state="wrong"] { outline: 8px solid #c8324b; outline-offset: -5px; animation: shake 0.4s; }
.pchoice[data-state="asking"] { outline: 8px dashed #1f78d1; outline-offset: -5px; }
.pchoice[data-state="wrong"] .stamp, .pchoice[data-state="asking"] .stamp { display: grid; background: #ffd3da; color: #a3112c; }
.pchoice[data-state="wrong"] .stamp::before, .pchoice[data-state="asking"] .stamp::before { content: "✗"; }

.mcq { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.opt { display: flex; align-items: center; gap: 12px; position: relative; padding-right: 54px; }
.opt .key { flex: none; width: 36px; height: 36px; display: grid; place-items: center; border: 3px solid var(--line); border-radius: 50%; background: var(--gold); font-size: 1.2rem; }
.opt .stamp { right: 14px; top: 50%; transform: translateY(-50%); font-size: 1.8rem; }
.opt[aria-disabled="true"] { cursor: default; box-shadow: 0 5px 0 var(--line); }
.opt[data-state="right"] { background: var(--green); color: #fff; }
.opt[data-state="right"] .stamp { display: block; }
.opt[data-state="right"] .stamp::before { content: "✓"; }
.opt[data-state="wrong"] { background: #ffd3da; animation: shake 0.4s; }
.opt[data-state="wrong"] .stamp { display: block; color: #a3112c; }
.opt[data-state="wrong"] .stamp::before { content: "✗"; }

.controls { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.status { flex: 1; min-width: 0; display: flex; align-items: center; gap: 14px; flex-wrap: wrap; font-weight: 800; font-size: 1.15rem; }
.counter { padding: 0 12px; border: 3px solid var(--line); border-radius: 12px; background: #fff; font-family: var(--display); }
.actions { display: flex; gap: 10px; align-items: center; margin-left: auto; }

.done { display: grid; justify-items: center; gap: 12px; padding: 18px 0; text-align: center; }
.done-title { margin: 0; font-family: var(--display); font-size: clamp(2rem, 4vw, 3rem); text-shadow: 3px 3px 0 var(--gold); }
.done-text { margin: 0; font-size: 1.4rem; font-weight: 800; }
.games, .done-links { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }
.game-link { background: #e9f7ff; }
.done-mascot { animation: pop 1.2s ease-in-out 2; }
.done-back { justify-self: start; }

@media (max-width: 900px) { .choices { gap: 8px; } .pchoice { border-width: 4px; border-radius: 16px; } .lbl, .pchoice .stamp { width: 32px; height: 32px; font-size: 1.1rem; } }
@media (max-width: 760px) { .choices, .mcq { grid-template-columns: 1fr; } .stage { padding: 14px; } .rtools { margin-left: 0; } }
/* Phones and very short screens: the stacked answers cannot share the screen with the text, so the page scrolls. */
@media (max-width: 760px), (max-height: 520px) { .rwrap { height: auto; display: block; } .stage { grid-template-rows: none; } .paras { overflow: visible; padding-right: 0; background: none; } }

@media (max-width: 760px) { .grid { grid-template-columns: 1fr; } .hero { align-items: flex-start; } .mascot { width: 56px; height: 56px; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; animation: none !important; } .card:hover { transform: none; } }

/* Offline: class preparation, update banner, offline page */
.offline-box { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; font-weight: 800; }
.offline-box .btn[disabled] { cursor: progress; }
.update-banner { position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%); z-index: 50; display: flex; align-items: center; gap: 14px; padding: 8px 14px 10px 20px; max-width: calc(100vw - 32px); background: var(--paper); border: 4px solid var(--line); border-radius: 22px; box-shadow: 0 6px 0 var(--line); font-family: var(--display); font-weight: 800; }
.offline-page { max-width: 560px; padding-top: 12vh; text-align: center; }
.offline-page h1 { font-size: clamp(2rem, 5vw, 3rem); margin: 12px 0; text-shadow: 3px 3px 0 #fff; }
.offline-page p { font-size: 1.2rem; margin: 0 0 24px; }
