:root {
  --bg: #f6f4ff; --card: #fff; --ink: #1f1d36; --muted: #6b6890; --line: #e4e0f5;
  --accent: #6c4cf5; --accent-ink: #fff; --accent-2: #ff8a3d; --chip: #efeafe;
  --good: #1a9a5c; --good-bg: #e3f6ec; --bad: #d93d42; --bad-bg: #fdeaea;
  --shadow: 0 4px 14px rgba(60, 40, 140, .08);
  /* Class book (Evolve page colors) */
  --teal: #1b9fc0; --teal-ink: #fff; --teal-bg: #e2f1f7; --navy: #26323f; --yellow: #fcecae; --red: #cf1f3a; --red-ink: #fff; --paper: #fff;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14132a; --card: #1f1d3a; --ink: #eeeaff; --muted: #a7a3c9; --line: #322f5c;
    --accent: #9b85ff; --accent-ink: #14132a; --accent-2: #ffa265; --chip: #2c2858;
    --good: #45d18f; --good-bg: #173a2b; --bad: #ff7276; --bad-bg: #3d1d22; --shadow: none;
    --teal: #4cc3e0; --teal-ink: #0d2430; --teal-bg: #183846; --navy: #0d1520; --yellow: #4d4214; --red: #ff6b7f; --red-ink: #2a0a10; --paper: #1f1d3a;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 17px/1.6 Nunito, system-ui, sans-serif; }
a { color: var(--accent); }
h1 { font-size: 1.7rem; margin: .3rem 0 .4rem; line-height: 1.25; }
h2 { font-size: 1.2rem; margin: 1.6rem 0 .6rem; }
h3 { margin: 0 0 .4rem; }
u { text-decoration-color: var(--accent-2); text-decoration-thickness: 2px; text-underline-offset: 3px; }

.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 12px; padding: 10px 16px;
  background: var(--card); border-bottom: 1px solid var(--line); }
.logo { font-weight: 800; text-decoration: none; color: var(--ink); font-size: 1.1rem; }
#stats { margin-left: auto; display: flex; gap: 12px; font-weight: 700; font-size: .95rem; }
#stats a { color: inherit; text-decoration: none; }
.icon-btn { background: none; border: 0; font-size: 1.2rem; cursor: pointer; }

main { max-width: 760px; margin: 0 auto; padding: 16px 16px 80px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 18px; box-shadow: var(--shadow); }
.lead { color: var(--muted); margin-top: 0; }
.hint { color: var(--muted); font-size: .9rem; }
.back { display: inline-block; margin-bottom: 6px; text-decoration: none; font-weight: 700; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin: 12px 0; }
.row.center { justify-content: center; }
.row.spread { justify-content: space-between; }

.btn { border: 0; border-radius: 14px; padding: 10px 18px; font: inherit; font-weight: 800; cursor: pointer;
  background: var(--accent); color: var(--accent-ink); text-decoration: none; display: inline-block; }
.btn:active { transform: scale(.97); }
.btn.ghost { background: var(--chip); color: var(--ink); }
.btn.good { background: var(--good); color: #fff; }
.btn.bad { background: var(--bad); color: #fff; }
.btn.big { font-size: 1.15rem; padding: 14px 26px; }

/* home */
.hero { border-left: 5px solid var(--accent); }
.hero p { margin: 0 0 10px; color: var(--muted); }
.unit-tag { font-size: .85rem; font-weight: 700; color: var(--muted); }
.hero small { color: var(--muted); }
.meter { height: 8px; background: var(--chip); border-radius: 99px; overflow: hidden; margin: 10px 0 4px; }
.meter div { height: 100%; background: var(--accent); border-radius: 99px; }
/* list box: one row per item (see tile() in app.js) */
h2.sec { display: flex; align-items: center; gap: 8px; font-size: .95rem; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); margin: 1.6rem 0 .5rem; }
h2.sec .num { margin: 0; }
.tiles { background: var(--card); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow); overflow: hidden; }
.tile { display: flex; align-items: center; gap: 14px; padding: 12px 16px; text-decoration: none; color: var(--ink); }
.tile + .tile { border-top: 1px solid var(--line); }
.tile:hover { background: var(--chip); }
.tile .ic { font-size: 1.4rem; width: 1.8rem; text-align: center; flex: none; }
.tile .tx { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.35; }
.tile small { color: var(--muted); }
.tile .go { color: var(--muted); font-size: 1.4rem; flex: none; }
.badge-n { background: var(--bad); color: #fff; border-radius: 99px; padding: 0 8px; font-size: .8rem; margin-left: 4px; }

/* start: cover and chapter list */
.cover { display: block; width: min(420px, 100%); margin: 8px auto 0; border-radius: 6px; overflow: hidden; box-shadow: var(--shadow); transition: transform .2s; }
.cover:hover { transform: translateY(-3px); }
.cover img { display: block; width: 100%; height: auto; }
.lead.center { text-align: center; }
.chead { display: flex; align-items: center; gap: 16px; margin: 8px 0 16px; }
.chead img { width: 72px; border-radius: 4px; box-shadow: var(--shadow); }
.chead h1 { margin: 0; }
.chead .lead { margin: 2px 0 0; }
.tile .ic .unum { font-size: .95rem; color: var(--accent); }
.tile .ic:has(.unum) { width: 2.6rem; }

/* story */
.story p { margin: 0 0 12px; }
.story .quote { border-left: 4px solid var(--accent-2); padding-left: 12px; font-style: italic; }
.who { font-style: normal; color: var(--accent); }
.vw { font: inherit; font-weight: 800; color: var(--accent); background: var(--chip); border: 0; border-radius: 6px;
  padding: 0 4px; cursor: pointer; font-style: inherit; }

/* words */
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0; }
.chip { background: var(--chip); border-radius: 99px; padding: 2px 10px; font-size: .8rem; font-weight: 700; color: var(--muted); }
button.chip { border: 2px solid transparent; cursor: pointer; font: inherit; font-size: .9rem; font-weight: 700; color: var(--ink); padding: 4px 14px; }
button.chip.on { border-color: var(--accent); color: var(--accent); }
.wgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.wcard h3 { display: flex; align-items: center; gap: 8px; font-size: 1.2rem; }
.wcard p { margin: 4px 0; }
.ex { color: var(--muted); font-style: italic; }
.dots { letter-spacing: 2px; color: var(--accent-2); font-size: .8rem; }
.say { background: none; border: 0; cursor: pointer; font-size: 1rem; padding: 0 2px; }
.notes p { margin: 6px 0; }

/* grammar */
.gsec { margin-bottom: 12px; }
.num { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; background: var(--accent);
  color: var(--accent-ink); font-size: .85rem; margin-right: 4px; }
ul.ex-list { margin: 6px 0; padding-left: 20px; }
ul.ex-list li { margin: 4px 0; }
.tip { background: var(--chip); border-radius: 12px; padding: 8px 12px; margin: 8px 0 0; }
.accuracy { border: 2px solid var(--bad); }
.rightx { color: var(--good); }
.wrongx { color: var(--bad); }

/* quiz */
.progress { height: 8px; background: var(--chip); border-radius: 99px; overflow: hidden; }
.progress div { height: 100%; background: var(--accent); transition: width .3s; }
.qcount { color: var(--muted); font-weight: 700; font-size: .9rem; margin: 8px 0; }
.q { font-size: 1.2rem; font-weight: 700; margin: 0 0 12px; }
.blank { display: inline-block; min-width: 60px; border-bottom: 3px solid var(--accent-2); }
.opts { display: grid; gap: 10px; }
.opt { text-align: left; font: inherit; font-weight: 700; padding: 12px 16px; border-radius: 14px; border: 2px solid var(--line);
  background: var(--card); color: var(--ink); cursor: pointer; }
.opt:hover:not(:disabled) { border-color: var(--accent); }
.opt.right { border-color: var(--good); background: var(--good-bg); }
.opt.wrong { border-color: var(--bad); background: var(--bad-bg); }
.why { margin-top: 12px; }
.why .ok { color: var(--good); font-weight: 800; }
.why .no { color: var(--bad); font-weight: 800; }
.next { margin-top: 12px; }
input.type { font: inherit; font-size: 1.2rem; padding: 10px 14px; border-radius: 12px; border: 2px solid var(--line);
  width: 100%; background: var(--card); color: var(--ink); }
input.type:focus { outline: none; border-color: var(--accent); }

.result { text-align: center; }
.result .big { font-size: 3.5rem; }
.xp { font-weight: 800; color: var(--accent-2); font-size: 1.3rem; }
.missed { text-align: left; margin-top: 12px; }
.missed li { margin: 6px 0; }

/* workshop */
.convo p { margin: 0 0 14px; line-height: 2.1; }
.gapw u { opacity: .65; }
.convo select { font: inherit; font-weight: 700; border-radius: 10px; padding: 2px 6px; margin-left: 6px; border: 2px solid var(--accent);
  background: var(--card); color: var(--ink); }
.convo .gapin { font: inherit; font-weight: 700; border: 0; border-bottom: 3px solid var(--accent); background: var(--chip);
  color: var(--ink); border-radius: 6px 6px 0 0; padding: 0 6px; margin-left: 2px; max-width: 100%; }
.convo .gapin:focus { outline: none; border-color: var(--accent-2); }
.convo .right { border-color: var(--good); background: var(--good-bg); }
.convo .wrong { border-color: var(--bad); background: var(--bad-bg); }

/* games */
.timer { font-weight: 800; font-size: 1.3rem; color: var(--accent-2); }
.match { display: grid; grid-template-columns: 1fr 1.5fr; gap: 10px; }
.match > div { display: grid; gap: 10px; align-content: start; }
.tile-m { font: inherit; font-weight: 700; padding: 10px; border-radius: 14px; border: 2px solid var(--line); background: var(--card);
  color: var(--ink); cursor: pointer; min-height: 52px; line-height: 1.25; }
.tile-m.sel { border-color: var(--accent); background: var(--chip); }
.tile-m.done { border-color: var(--good); background: var(--good-bg); opacity: .55; cursor: default; }
.shake { animation: shake .35s; }
@keyframes shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }

.flip { perspective: 900px; height: 260px; cursor: pointer; position: relative; margin: 10px 0; }
.face { position: absolute; inset: 0; backface-visibility: hidden; transition: transform .5s; border-radius: 22px; padding: 20px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 8px;
  background: var(--card); border: 2px solid var(--line); box-shadow: var(--shadow); }
.face.front { background: linear-gradient(135deg, var(--accent), #a35cf5); color: #fff; border: 0; }
.face.front small { opacity: .8; }
.face.back { transform: rotateY(180deg); }
.flip.on .front { transform: rotateY(180deg); }
.flip.on .back { transform: rotateY(360deg); }
.word { font-size: 2.2rem; font-weight: 800; }
.meaning { font-size: 1.3rem; font-weight: 700; }

.slots { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin: 16px 0; }
.slot { width: 40px; height: 48px; border-bottom: 4px solid var(--accent); display: grid; place-items: center; font-size: 1.6rem;
  font-weight: 800; text-transform: uppercase; }
.gap { width: 18px; display: grid; place-items: center; font-size: 1.6rem; font-weight: 800; }
.letters { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.letter { width: 48px; height: 48px; border-radius: 12px; border: 0; background: var(--accent-2); color: #fff; font: inherit;
  font-size: 1.4rem; font-weight: 800; text-transform: uppercase; cursor: pointer; box-shadow: 0 3px 0 rgba(0,0,0,.15); }
.letter:disabled { opacity: .25; cursor: default; }
.solved .slot { color: var(--good); border-color: var(--good); }

.line, .bank { display: flex; flex-wrap: wrap; gap: 8px; min-height: 56px; padding: 10px; border-radius: 14px; }
.line { border: 2px dashed var(--accent); margin-bottom: 12px; }
.wtile { font: inherit; font-weight: 700; padding: 6px 12px; border-radius: 10px; border: 2px solid var(--line); background: var(--card);
  color: var(--ink); cursor: pointer; }
.line .wtile { border-color: var(--accent); }

.bgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.bgrid .card { text-align: center; }
.bgrid .locked { opacity: .4; filter: grayscale(1); }
.bgrid .ic { font-size: 2.4rem; }

/* word sheet, toast, confetti */
.sheet-bg { position: fixed; inset: 0; background: rgba(10, 8, 30, .45); z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
.sheet { width: 100%; max-width: 560px; border-radius: 22px 22px 0 0; animation: up .2s; }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
.toast { position: fixed; left: 50%; top: 70px; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 18px;
  border-radius: 14px; font-weight: 800; z-index: 30; animation: up .2s; max-width: calc(100vw - 32px); }
.confetti { position: fixed; top: -40px; font-size: 1.6rem; z-index: 40; pointer-events: none; animation: fall 1.8s ease-in forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(540deg); } }

@media (max-width: 520px) {
  body { font-size: 16px; }
  .match { grid-template-columns: 1fr 1.3fr; }
  .slot, .letter { width: 36px; height: 42px; font-size: 1.2rem; }
  #stats { gap: 8px; font-size: .85rem; }
}

/* class book: the real book page picture with tap areas (.sp) on top */
.classbtn { display: flex; gap: 14px; align-items: center; text-decoration: none; color: var(--ink); margin-top: 14px;
  border: 2px solid var(--teal); background: var(--teal-bg); }
.classbtn .ic { font-size: 2rem; }
.classbtn small { display: block; color: var(--muted); }
a.chip { text-decoration: none; font-size: .9rem; color: var(--ink); padding: 4px 14px; border: 2px solid transparent; }
a.chip.on { border-color: var(--teal); color: var(--teal); }
.btn.small { padding: 6px 14px; font-size: .9rem; }
body.wide main { max-width: 1100px; }
.ctool { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 4px 12px; }
.ctool .row { margin: 6px 0; }
.bkwrap { overflow-x: auto; border-radius: 8px; box-shadow: var(--shadow); border: 1px solid var(--line); }
.bk { position: relative; container-type: inline-size; background: #fff; }
.bk.zoom { width: 170%; }
.bk img { display: block; width: 100%; height: auto; }
.sp { position: absolute; margin: 0; padding: 0; border: 0; background: none; cursor: pointer; font: inherit; color: #1f1d36; border-radius: 6px; }
.sp:focus-visible { outline: 3px solid var(--accent-2); }
.sp-word { background: rgba(255, 214, 0, .30); border-radius: 4px; }
.sp-word:hover { background: rgba(255, 190, 0, .5); }
.sp-audio, .sp-go { border: 2px solid transparent; }
.sp-audio:hover, .sp-go:hover { border-color: #1b9fc0; background: rgba(27, 159, 192, .12); }
.sp-round { background: #1b9fc0; color: #fff; border-radius: 50%; font-size: 1.6cqw; box-shadow: 0 2px 6px rgba(0, 0, 0, .25); }
.sp-pick { border: 2px dotted rgba(108, 76, 245, .55); }
.sp-pick:hover { background: rgba(108, 76, 245, .10); }
.sp-pick.on { border: 3px solid #6c4cf5; background: rgba(108, 76, 245, .14); }
.sp-tick { border: 2px solid #6c4cf5; background: rgba(255, 255, 255, .7); color: #1a8f4a; font-weight: 800; font-size: 1rem; display: flex; align-items: center; justify-content: center; padding: 0; cursor: pointer; }
.sp-tick.on { background: #e3f7ea; }
.sp-type { border-bottom: 3px solid #1b9fc0; background: rgba(27, 159, 192, .10); border-radius: 4px 4px 0 0; cursor: text;
  font-size: 1.65cqw; font-weight: 700; color: #3a22c8; padding: 0 .6cqw; }
.sp-type:focus { outline: none; background: rgba(27, 159, 192, .2); }
.sp-sel { border: 2px dashed rgba(255, 138, 61, .9); background: rgba(255, 138, 61, .08); }
.sp-sel:hover { background: rgba(255, 138, 61, .18); }
.sp-sel.set { background: #fff; border-style: solid; text-align: left; }
.sp-sel span { font-size: 1.6cqw; font-weight: 800; color: #3a22c8; padding-left: .6cqw; white-space: nowrap; }
.sp-check { background: #6c4cf5; color: #fff; font-weight: 800; font-size: 1.35cqw; border-radius: 99px; box-shadow: 0 2px 6px rgba(0, 0, 0, .25); }
.sp-write { background: rgba(255, 255, 255, .55); border: 2px dashed rgba(27, 159, 192, .6); resize: none; cursor: text;
  font-size: 1.65cqw; line-height: 2.62cqw; padding: .3cqw .8cqw; color: #3a22c8; font-weight: 700; }
.sp.right { border: 3px solid #1a9a5c !important; background-color: rgba(26, 154, 92, .16); }
.sp.wrong { border: 3px solid #d93d42 !important; background-color: rgba(217, 61, 66, .14); }
.sp-sel.set.right, .sp-sel.set.wrong { background-color: #fff; }
.res { padding-left: 4px; list-style: none; }
.res li { margin: 8px 0; }
.lg { display: inline-block; width: 26px; height: 14px; vertical-align: middle; border-radius: 4px; }
.lg-word { background: rgba(255, 214, 0, .5); }
.lg-pick { border: 2px dotted #6c4cf5; }
.lg-sel { border: 2px dashed #ff8a3d; }
.lg-type { border-bottom: 3px solid #1b9fc0; background: rgba(27, 159, 192, .12); }
.notes-box { width: 100%; font: inherit; border: 2px solid var(--line); border-radius: 12px; padding: 10px; background: var(--bg); color: var(--ink); }
.sheet { max-height: 85vh; overflow-y: auto; }

/* lesson */
.lhead { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; margin: 6px 0; }
.lhead small { color: var(--muted); }
.lstep { margin-top: 12px; min-height: 260px; }
.lstep h2 { margin-top: 0; }
.big-text { font-size: 1.1rem; }

/* easy way (one-page chapter) */
.easy-sec { margin-top: 14px; }
.easy-sec h2 { margin-top: 0; }
.easy-wrap { overflow-x: auto; margin: 8px 0; }
.easy-table { width: 100%; border-collapse: collapse; }
.easy-table th, .easy-table td { text-align: left; vertical-align: top; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.easy-table th { color: var(--muted); font-size: .85rem; font-weight: 600; }
.peek { background: var(--chip); border-radius: 12px; padding: 8px 12px; margin: 8px 0; }
.peek summary { cursor: pointer; }
.peek p { margin: 6px 0 0; }
.scale { display: flex; align-items: stretch; gap: 6px; flex-wrap: wrap; margin: 10px 0 14px; }
.scale .arrow { align-self: center; color: var(--muted); }
.sc.vw { display: flex; flex-direction: column; align-items: center; padding: 10px 14px; border-radius: 14px; flex: 1 1 90px; }
.sc small { color: var(--muted); font-weight: 400; font-size: .8rem; }
.vs p { padding: 10px 14px; border-radius: 12px; margin: 8px 0; }
.vs .bad { background: var(--bad-bg); }
.vs .bad s { text-decoration-color: var(--bad); }
.vs .good { background: var(--good-bg); font-weight: 700; }
.chat { display: flex; flex-direction: column; gap: 8px; margin: 8px 0 12px; }
.bub { max-width: 85%; padding: 8px 14px; border-radius: 18px 18px 18px 4px; background: var(--chip); margin: 0; }
.bub.me { align-self: flex-end; border-radius: 18px 18px 4px 18px; background: var(--accent); color: var(--accent-ink); }
.bub.me .say { filter: grayscale(1) brightness(2); }
.audio-bar { position: fixed; left: 50%; bottom: 12px; transform: translateX(-50%); z-index: 50; display: flex; align-items: center; gap: 10px;
  width: min(640px, calc(100% - 32px)); box-sizing: border-box; padding: 8px 12px; background: var(--card); border: 1px solid var(--line);
  border-radius: 14px; box-shadow: 0 6px 20px rgba(0, 0, 0, .18); }
.audio-bar b { white-space: nowrap; font-size: .9rem; }
.audio-bar audio { flex: 1; min-width: 0; height: 40px; }
body.has-audio { padding-bottom: 76px; }
