:root {
  --paper: #fbf7ef;
  --ink: #2b2620;
  --muted: #6b6257;
  --card: #ffffff;
  --line: #e7dfd2;
  --accent: #3f7d4e;
  --accent-soft: #e4f1e6;
  --accent-ink: #ffffff;
  --radius: 18px;
  --shadow: 0 2px 0 rgba(43, 38, 32, 0.06), 0 8px 24px rgba(43, 38, 32, 0.07);
  --font-body: "Nunito", "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-head: "Fraunces", Georgia, "Times New Roman", serif;
}
body[data-level="1"] { --accent: #3f7d4e; --accent-soft: #e4f1e6; }
body[data-level="2"] { --accent: #2f6fa8; --accent-soft: #e2eef8; }
body[data-level="3"] { --accent: #6b4aa3; --accent-soft: #eee8f8; }
body[data-level="4"] { --accent: #b23a3a; --accent-soft: #f8e6e4; }
body[data-level="5"] { --accent: #1f2f4f; --accent-soft: #e5e9f1; }

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 17px;
  line-height: 1.55;
}
body.young { font-size: 19px; }
a { color: var(--accent); }
img { max-width: 100%; display: block; }
button { font: inherit; cursor: pointer; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; border-radius: 6px; }

.wrap { max-width: 1040px; margin: 0 auto; padding: 0 16px; }

/* Header */
.site-head { background: #fff; border-bottom: 1px solid var(--line); }
.site-head .wrap { display: flex; align-items: center; gap: 14px; padding-top: 10px; padding-bottom: 10px; }
.site-head img { height: 44px; width: auto; }
.site-head .brand { font-family: var(--font-head); font-size: 1.15rem; font-weight: 700; color: var(--ink); text-decoration: none; }
.site-head .brand small { display: block; font-family: var(--font-body); font-weight: 600; font-size: 0.78rem; color: var(--muted); letter-spacing: 0.04em; text-transform: uppercase; }
.site-head .spacer { flex: 1; }
.toggle {
  border: 2px solid var(--accent); background: #fff; color: var(--accent);
  border-radius: 999px; padding: 6px 14px; font-weight: 700; font-size: 0.9rem;
}
.toggle[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }

/* Index */
.hero { padding: 40px 0 16px; }
.hero h1 { font-family: var(--font-head); font-size: clamp(2rem, 5vw, 3rem); line-height: 1.1; margin: 0 0 10px; }
.hero p { color: var(--muted); max-width: 640px; margin: 0; font-size: 1.1rem; }
.level-block { margin: 28px 0; }
.level-block h2 { font-family: var(--font-head); margin: 0 0 4px; display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.level-pill { display: inline-block; border-radius: 999px; padding: 2px 12px; font-family: var(--font-body); font-size: 0.85rem; font-weight: 800; color: #fff; }
.lv1 { background: #3f7d4e; } .lv2 { background: #2f6fa8; } .lv3 { background: #6b4aa3; } .lv4 { background: #b23a3a; } .lv5 { background: #1f2f4f; }
.level-block .cefr { color: var(--muted); font-weight: 600; font-size: 0.95rem; }
.book-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; margin-top: 12px; }
.book-card {
  display: block; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 20px; text-decoration: none; color: var(--ink); border: 2px solid transparent; transition: transform .15s, border-color .15s;
}
.book-card:hover { transform: translateY(-2px); border-color: currentColor; }
.book-card .spine { height: 8px; border-radius: 6px; margin-bottom: 14px; }
.book-card h3 { font-family: var(--font-head); font-size: 1.35rem; margin: 0 0 2px; }
.book-card .author { color: var(--muted); font-size: 0.95rem; }
.book-card .go { margin-top: 12px; font-weight: 800; font-size: 0.95rem; }

/* Book page */
.book-hero { padding: 28px 0 8px; }
.crumbs { font-size: 0.9rem; color: var(--muted); margin-bottom: 10px; }
.crumbs a { color: var(--muted); }
.book-hero .tag { display: inline-block; background: var(--accent); color: #fff; font-weight: 800; border-radius: 999px; padding: 3px 12px; font-size: 0.85rem; }
.book-hero h1 { font-family: var(--font-head); font-size: clamp(2rem, 6vw, 3.2rem); line-height: 1.08; margin: 10px 0 2px; }
.book-hero .author { color: var(--muted); font-size: 1.05rem; }
.hook { background: var(--accent-soft); border-radius: var(--radius); padding: 16px 18px; margin: 16px 0 6px; font-size: 1.12rem; }
.meta-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.chip { background: #fff; border: 1px solid var(--line); border-radius: 999px; padding: 3px 12px; font-size: 0.88rem; font-weight: 600; color: var(--muted); }

.section { margin: 26px 0; }
.section > h2 { font-family: var(--font-head); font-size: 1.55rem; margin: 0 0 12px; }

/* Lesson tabs */
.tabs { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: thin; }
.tab {
  flex: 0 0 auto; border: 2px solid var(--line); background: #fff; border-radius: 14px; padding: 8px 14px; text-align: left; min-width: 150px;
}
.tab .n { display: block; font-size: 0.78rem; font-weight: 800; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.tab .s { display: block; font-weight: 800; }
.tab[aria-selected="true"] { border-color: var(--accent); background: var(--accent-soft); }
.tab .done { color: var(--accent); }

.lesson { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 22px; margin-top: 12px; }
.lesson h3 { font-family: var(--font-head); font-size: 1.5rem; margin: 0 0 4px; }
.goal { color: var(--muted); margin: 0 0 14px; }
.warmup { display: flex; gap: 12px; align-items: flex-start; background: var(--accent-soft); border-radius: 14px; padding: 12px 14px; margin-bottom: 16px; }
.warmup .icon { font-size: 1.5rem; line-height: 1; }
.steps { list-style: none; padding: 0; margin: 0 0 6px; display: grid; gap: 10px; }
.steps li { border-left: 4px solid var(--accent); padding: 4px 0 4px 12px; }
.steps .label { font-weight: 800; }
.teacher-only { display: none; }
body.teacher .teacher-only { display: block; }
.say { background: #fff8e6; border: 1px dashed #e0c879; border-radius: 10px; padding: 8px 10px; margin-top: 6px; font-style: italic; }
.say::before { content: "Teacher says: "; font-style: normal; font-weight: 800; }

/* Activity */
.activity { margin-top: 18px; border: 2px solid var(--accent); border-radius: var(--radius); padding: 18px; }
.activity h4 { margin: 0 0 6px; font-size: 1.15rem; display: flex; gap: 8px; align-items: center; }
.activity .prompt { margin: 0 0 14px; }
.word-grid { display: flex; flex-wrap: wrap; gap: 10px; }
.word {
  border: 2px solid var(--line); background: #fff; border-radius: 14px; padding: 10px 16px; font-weight: 800; font-size: 1.05rem; min-height: 48px;
}
.word.found { background: var(--accent); color: #fff; border-color: var(--accent); }
.word.nope { animation: shake .35s; border-color: #d9a7a0; }
@keyframes shake { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }
.wall { margin-top: 14px; min-height: 52px; background: repeating-linear-gradient(0deg, #fff, #fff 30px, #f3ece0 31px); border-radius: 12px; padding: 10px; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.wall .fossil { background: #fff; border: 2px solid var(--accent); border-radius: 10px; padding: 4px 10px; font-weight: 800; }
.wall .empty { color: var(--muted); font-size: 0.95rem; }
.feedback { min-height: 1.5em; margin-top: 10px; font-weight: 700; color: var(--accent); }

.vote { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.vote button { border: 3px solid var(--line); background: #fff; border-radius: 16px; padding: 16px; font-weight: 800; font-size: 1.05rem; min-height: 72px; }
.vote button[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); }
.bq { font-family: var(--font-head); font-size: 1.35rem; margin: 0 0 12px; }

.frame { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; font-size: 1.1rem; font-weight: 700; }
.frame input { flex: 1 1 180px; min-width: 140px; border: 2px solid var(--line); border-radius: 12px; padding: 10px 12px; font: inherit; font-weight: 600; }
.frame input:focus { border-color: var(--accent); outline: none; }
.built { margin-top: 12px; background: var(--accent-soft); border-radius: 12px; padding: 10px 12px; font-size: 1.1rem; font-weight: 700; }
textarea { width: 100%; min-height: 100px; border: 2px solid var(--line); border-radius: 12px; padding: 10px 12px; font: inherit; }
textarea:focus { border-color: var(--accent); outline: none; }
.pad-wrap { margin-top: 12px; }
canvas.pad { width: 100%; height: 260px; background: #fff; border: 2px dashed var(--line); border-radius: 14px; touch-action: none; }
.pad-tools { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.swatch { width: 36px; height: 36px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 0 0 2px var(--line); }
.swatch[aria-pressed="true"] { box-shadow: 0 0 0 3px var(--accent); }
.btn { border: 0; background: var(--accent); color: #fff; border-radius: 12px; padding: 10px 16px; font-weight: 800; min-height: 44px; }
.btn.ghost { background: #fff; color: var(--accent); border: 2px solid var(--accent); }
.row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 12px; }

.closing { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 16px; }
.closing div { background: #faf6ee; border-radius: 14px; padding: 12px 14px; }
.closing strong { display: block; font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }

/* Vocab */
.vocab { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.vcard { perspective: 800px; height: 150px; border: 0; background: none; padding: 0; text-align: left; }
.vcard .inner { position: relative; width: 100%; height: 100%; transition: transform .45s; transform-style: preserve-3d; }
.vcard.flipped .inner { transform: rotateY(180deg); }
.vcard .face { position: absolute; inset: 0; backface-visibility: hidden; border-radius: 16px; padding: 14px; box-shadow: var(--shadow); display: flex; flex-direction: column; justify-content: center; }
.vcard .front { background: #fff; align-items: center; text-align: center; }
.vcard .front .w { font-family: var(--font-head); font-size: 1.6rem; font-weight: 700; color: var(--accent); }
.vcard .front .hint { font-size: 0.8rem; color: var(--muted); margin-top: 6px; }
.vcard .back { background: var(--accent); color: #fff; transform: rotateY(180deg); font-size: 0.98rem; }
.vcard .back em { display: block; margin-top: 6px; opacity: .9; }
.speak { margin-top: 8px; align-self: center; border: 2px solid var(--accent); background: #fff; color: var(--accent); border-radius: 999px; padding: 4px 12px; font-weight: 800; font-size: 0.85rem; }

.frames { display: flex; flex-wrap: wrap; gap: 10px; }
.frames span { background: #fff; border: 2px solid var(--accent); border-radius: 12px; padding: 8px 12px; font-weight: 700; }

table.rubric { width: 100%; border-collapse: collapse; background: #fff; border-radius: 14px; overflow: hidden; box-shadow: var(--shadow); }
table.rubric th, table.rubric td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.rubric th { background: var(--accent-soft); width: 140px; }

.foot { color: var(--muted); font-size: 0.85rem; padding: 30px 0 40px; border-top: 1px solid var(--line); margin-top: 30px; }
.notice { background: #fff3f0; border: 1px solid #f0c9c0; border-radius: 12px; padding: 12px; }

@media (max-width: 640px) {
  .vote, .closing { grid-template-columns: 1fr; }
  .lesson { padding: 16px; }
  .site-head img { height: 36px; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
@media print {
  .site-head .toggle, .tabs, .pad-tools, .row, .speak { display: none !important; }
  .teacher-only { display: block !important; }
  .lesson, .book-card { box-shadow: none; border: 1px solid #ccc; }
}

/* "For grown-ups" 1-to-1 card (grownups.js): shown after a learner's 3rd finished story, only in the book's
   existing "For grown-ups" mode (reader.js sets body.grownup-mode). */
.ab-grownups { display: none; }
body.grownup-mode .ab-grownups { display: block; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.grownups-card { margin: 24px 0; padding: 20px 22px; background: var(--card); border: 2px solid var(--accent); border-radius: var(--radius); box-shadow: var(--shadow); max-width: 720px; }
.grownups-card h2 { margin: 2px 0 8px; font-size: 1.3rem; line-height: 1.25; }
.grownups-card p { margin: 0 0 12px; color: var(--ink); overflow-wrap: anywhere; }
.grownups-kicker { font-size: .78rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: var(--accent) !important; }
.grownups-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 20px; }
.grownups-actions .btn { display: inline-flex; align-items: center; text-decoration: none; }
.grownups-contact { color: var(--accent); font-weight: 700; min-height: 44px; display: inline-flex; align-items: center; }
.grownups-card a:focus-visible { outline: 3px solid var(--ink); outline-offset: 3px; }
@media print { .grownups-card { display: none !important; } }

/* End-of-book next step (next-story.js). "Read your next story" shows in both modes. After a level's second
   story the Mr. Jay card is for grown-ups only (body.grownup-mode); "My storybook" shows just the friendly line. */
.next-step { margin: 18px 0 6px; }
.next-story-btn { display: inline-block; font-weight: 700; }
.next-step-kid { font-weight: 700; color: var(--accent); margin: 0; }
.next-step .ns-short { display: none; }
.next-step-jay { display: none; background: #1f4d3a; color: #fff; border-radius: 16px; padding: 18px 20px; max-width: 560px; }
body.grownup-mode .next-step-jay { display: block; }
body.grownup-mode .next-step-kid { display: none; }
.next-step-jay h3 { color: #fff; margin: 4px 0 6px; }
.next-step-jay p { color: #e8f1ec; margin: 0 0 10px; }
.next-step-kicker { font-size: .8rem; letter-spacing: .06em; text-transform: uppercase; }
.next-step-actions { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.next-jay-btn { background: #fff; color: #1f4d3a; font-weight: 700; min-height: 44px; }
.next-back { color: #fff; text-decoration: underline; min-height: 44px; display: inline-flex; align-items: center; }
.next-step a:focus-visible { outline: 3px solid currentColor; outline-offset: 3px; }
.ab-next-step { max-width: 980px; margin: 0 auto; padding: 0 16px; }
@media print { .next-step, .ab-next-step { display: none !important; } }
