/*
 * "Vở ô ly" theme — the squared exercise notebook every Vietnamese pupil learns to write in.
 * Layout: home = a shelf of blue notebooks with nhãn vở labels; lesson = notebook pages with a
 * red margin, index tabs down the side, sticky notes for tips and ô-ly squares for syllables.
 * Light = blue ink on graph paper. Dark = chalk on a blue-black board.
 */
:root {
  --paper: #fbfdff;
  --paper-2: #eef5fd;
  --sheet: #ffffff;
  --ink: #173b6c;
  --pen: #2463c9;
  --pen-2: #4aa3f0;
  --hl: #bfe0ff;
  --grid-fine: #e4eefa;
  --grid-bold: #c6dbf2;
  --margin: #e0636b;
  --sticky: #fff1a6;
  --sticky-ink: #5c4600;
  --tape: #cfe3f7;
  --label: #ffffff;
  --label-ink: #173b6c;
  --cover-ink: #ffffff;
  --shadow-ink: #173b6c;
  --t0: #2b7fd8; --t1: #7d5cf0; --t2: #e8701f; --t3: #129a8c; --t4: #d6406f; --t5: #5f7896;

  /* existing component tokens mapped onto the notebook palette */
  --bg: var(--paper);
  --surface: var(--sheet);
  --surface-2: var(--paper-2);
  --text: #13263f;
  --muted: #5b7290;
  --line: #d2e3f5;
  --accent: var(--pen);
  --accent-2: var(--pen-2);
  --accent-soft: #e3effd;

  /* Chinese is set in Kai (楷体) everywhere, the same face as the handwritten "已完成" */
  --f-kai: "Kaiti SC", "STKaiti", "KaiTi", "BiauKai", "LXGW WenKai TC", "Noto Serif SC", serif;
  --f-display: "Lexend", var(--f-kai);
  --f-body: "Lexend", var(--f-kai);
  --f-zh: var(--f-kai);
  --f-hand: "Patrick Hand", var(--f-kai);
  --font: var(--f-body);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #12283b; --paper-2: #183450; --sheet: #16304a;
    --ink: #eaf4ff; --pen: #8ec9ff; --pen-2: #b9e1ff; --hl: #2a5a8a;
    --grid-fine: #183048; --grid-bold: #22405e; --margin: #ff8e94;
    --tape: #6f8fae; --label: #f6f9fd; --label-ink: #173b6c; --shadow-ink: #050d16;
    --text: #e7f1fb; --muted: #9db4ca; --line: #2b4a66; --accent-soft: #1d3a58;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #12283b; --paper-2: #183450; --sheet: #16304a;
  --ink: #eaf4ff; --pen: #8ec9ff; --pen-2: #b9e1ff; --hl: #2a5a8a;
  --grid-fine: #183048; --grid-bold: #22405e; --margin: #ff8e94;
  --tape: #6f8fae; --label: #f6f9fd; --label-ink: #173b6c; --shadow-ink: #050d16;
  --text: #e7f1fb; --muted: #9db4ca; --line: #2b4a66; --accent-soft: #1d3a58;
  color-scheme: dark;
}

/* ---------- graph paper ---------- */
body {
  font-family: var(--f-body);
  background-color: var(--paper);
  background-image:
    linear-gradient(var(--grid-bold) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-bold) 1px, transparent 1px),
    linear-gradient(var(--grid-fine) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-fine) 1px, transparent 1px);
  background-size: 64px 64px, 64px 64px, 16px 16px, 16px 16px;
}
.container { max-width: 1140px; }

/* ---------- top bar ---------- */
.topbar {
  background: color-mix(in srgb, var(--paper) 92%, transparent);
  border-bottom: 3px double var(--grid-bold);
  box-shadow: none;
}
.brand-mark {
  position: relative; width: 38px; height: 46px; border-radius: 4px 8px 8px 4px;
  background: var(--pen); color: var(--cover-ink); font-family: var(--f-zh); font-size: 17px;
  box-shadow: inset 6px 0 0 color-mix(in srgb, #000 22%, var(--pen)), 3px 3px 0 var(--shadow-ink);
  animation: none;
}
.brand:hover .brand-mark { animation: wiggle .5s ease; }
.brand-text { font-family: var(--f-display); font-weight: 700; color: var(--ink); letter-spacing: .01em; }
.brand-text small { font-family: var(--f-hand); font-size: 15px; color: var(--pen); font-weight: 400; }
.topnav a { font-weight: 500; color: var(--muted); border: 2px solid transparent; }
.topnav a:hover { background: transparent; border-color: var(--grid-bold); color: var(--ink); }
.topnav a.active { background: var(--ink); color: var(--paper); border-color: var(--ink); }

/* ---------- highlighter ---------- */
.hl {
  background: linear-gradient(var(--hl), var(--hl)) no-repeat 0 88% / 100% 42%;
  padding: 0 .12em; border-radius: 3px;
  box-decoration-break: clone; -webkit-box-decoration-break: clone;
}
.section.reveal .hl { background-size: 0% 42%; transition: background-size .9s cubic-bezier(.3, .8, .2, 1) .25s; }
.section.reveal.in .hl { background-size: 100% 42%; }
.hero .hl, .chapter-head .hl { animation: hlsweep 1s cubic-bezier(.3, .8, .2, 1) .35s both; }

/* ---------- home: hero ---------- */
.hero {
  display: grid; grid-template-columns: 1fr auto; gap: 28px; align-items: center;
  background: none; border: none; box-shadow: none; padding: 30px 4px 36px; margin-bottom: 18px;
  color: var(--text); overflow: visible;
}
.hero::before, .hero::after { content: none; }
.hero-kicker { font-family: var(--f-hand); font-size: 22px; color: var(--pen); margin: 0 0 4px; transform: rotate(-1.5deg); transform-origin: left; }
.hero h1 { font-family: var(--f-display); font-weight: 800; font-size: clamp(30px, 4.6vw, 48px); line-height: 1.18; color: var(--ink); margin: 0 0 14px; text-wrap: balance; }
.hero h1 .hand { font-family: var(--f-hand); font-weight: 400; color: var(--pen); font-size: 1.18em; display: inline-block; transform: rotate(-3deg); }
.hero p { color: var(--muted); max-width: 60ch; font-size: 16px; }
.hero .progress-bar { max-width: 420px; height: 10px; background: var(--sheet); border: 2px solid var(--ink); margin-top: 18px; }
.hero .progress-bar > i { background: repeating-linear-gradient(-45deg, var(--pen) 0 8px, var(--pen-2) 8px 16px); }
.hero-progress { font-family: var(--f-hand); font-size: 17px !important; margin-top: 6px; }
.hero-stamp {
  width: 168px; height: 168px; border-radius: 50%; display: grid; place-content: center; text-align: center;
  color: var(--margin); border: 4px double var(--margin); transform: rotate(-12deg);
  font-family: var(--f-display); animation: stampin .7s cubic-bezier(.2, 1.5, .4, 1) .5s both;
}
.hero-stamp b { font-size: 46px; line-height: 1; }
.hero-stamp span { font-weight: 700; letter-spacing: .1em; }
.hero-stamp small { font-family: var(--f-hand); font-size: 16px; }
@media (max-width: 640px) {
  .hero { grid-template-columns: 1fr; }
  .hero-stamp { width: 132px; height: 132px; justify-self: end; margin-top: -10px; }
  .hero-stamp b { font-size: 36px; }
}

/* ---------- home: chapters + notebook shelf ---------- */
.chapter { margin-bottom: 44px; }
.chapter-head { gap: 12px; margin-bottom: 18px; }
.chapter-head h2 { font-family: var(--f-zh); font-size: 26px; color: var(--ink); padding: 0; }
.chapter-head h2::before { content: none; }
.chapter-head > span { font-family: var(--f-hand); font-size: 18px; color: var(--pen); }

.shelf {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(196px, 1fr)); gap: 26px 22px;
  padding-bottom: 18px; border-bottom: 10px solid color-mix(in srgb, var(--ink) 18%, var(--paper));
  border-radius: 0 0 6px 6px;
}
.notebook {
  --cov: #1f56a0;
  position: relative; display: block; min-height: 250px; text-decoration: none; perspective: 900px;
}
.notebook.c1 { --cov: #2467bd; } .notebook.c2 { --cov: #2f80cf; } .notebook.c3 { --cov: #17447e; } .notebook.c4 { --cov: #3a72b4; }
/* the pages inside, seen when the cover swings open */
.notebook::before {
  content: ""; position: absolute; inset: 6px 4px 4px 10px; border-radius: 4px 10px 10px 4px;
  background:
    linear-gradient(90deg, transparent 22px, var(--margin) 22px 24px, transparent 24px),
    repeating-linear-gradient(var(--sheet) 0 13px, var(--grid-bold) 13px 14px);
  box-shadow: 0 10px 22px -12px var(--shadow-ink);
}
.nb-cover {
  position: absolute; inset: 0; display: flex; flex-direction: column; gap: 10px; padding: 16px 14px 14px 26px;
  border-radius: 4px 12px 12px 4px; color: var(--cover-ink);
  background:
    linear-gradient(90deg, color-mix(in srgb, #000 28%, var(--cov)) 0 12px, transparent 12px),
    repeating-linear-gradient(135deg, transparent 0 6px, color-mix(in srgb, #fff 6%, transparent) 6px 7px),
    var(--cov);
  box-shadow: 4px 4px 0 var(--shadow-ink);
  transform-origin: left center; transition: transform .55s cubic-bezier(.3, .9, .3, 1), box-shadow .3s;
}
.nb-cover::before { /* stitches on the spine */
  content: ""; position: absolute; left: 5px; top: 10px; bottom: 10px; width: 2px;
  background: repeating-linear-gradient(color-mix(in srgb, #fff 55%, transparent) 0 6px, transparent 6px 12px);
}
.notebook:hover .nb-cover, .notebook:focus-visible .nb-cover { transform: rotateY(-24deg); box-shadow: 10px 8px 18px -6px color-mix(in srgb, var(--shadow-ink) 60%, transparent); }
.nb-brand { font-size: 11px; font-weight: 700; letter-spacing: .32em; opacity: .85; }
.nb-label {
  background: var(--label); color: var(--label-ink); border-radius: 12px; padding: 12px 12px 10px;
  border: 2px solid var(--label-ink); outline: 2px dashed color-mix(in srgb, var(--label-ink) 35%, transparent); outline-offset: -7px;
  display: flex; flex-direction: column; gap: 4px;
}
.nb-row { display: flex; align-items: baseline; gap: 8px; border-bottom: 1.5px dotted color-mix(in srgb, var(--label-ink) 45%, transparent); padding-bottom: 2px; }
.nb-row em { font-family: var(--f-hand); font-style: normal; font-size: 16px; color: #2463c9; }
.nb-row b { font-family: var(--f-hand); font-size: 28px; line-height: 1; color: #2463c9; }
.nb-title { font-family: var(--f-display); font-weight: 700; font-size: 15.5px; line-height: 1.3; }
.nb-zh { font-family: var(--f-zh); font-size: 13px; color: #4b6584; line-height: 1.4; }
.nb-foot { margin-top: auto; font-size: 12.5px; display: flex; justify-content: space-between; align-items: center; opacity: .92; }
.nb-done {
  font-style: normal; font-weight: 700; font-size: 12px; color: #fff; background: var(--margin);
  padding: 2px 8px; border-radius: 4px; transform: rotate(-6deg); box-shadow: 0 0 0 2px color-mix(in srgb, #fff 60%, transparent);
}
.notebook.missing { filter: saturate(.25); opacity: .6; }
.notebook.missing.in { opacity: .6; }
.notebook.missing .nb-cover { box-shadow: 4px 4px 0 color-mix(in srgb, var(--shadow-ink) 40%, transparent); }
@media (max-width: 520px) {
  .shelf { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px 14px; }
  .notebook { min-height: 228px; }
  .nb-cover { padding: 12px 10px 10px 20px; }
  .nb-title { font-size: 14px; }
}

/* ---------- lesson: nhãn vở header ---------- */
.lesson-head {
  background: none; border: none; box-shadow: none; padding: 26px 0 8px; color: var(--text);
  display: flex; flex-direction: column; align-items: flex-start; gap: 16px; overflow: visible;
}
.nhan-vo {
  position: relative; max-width: 700px; width: 100%; background: var(--label); color: var(--label-ink);
  border: 3px solid var(--label-ink); border-radius: 22px; padding: 18px 26px 16px;
  outline: 2px dashed color-mix(in srgb, var(--label-ink) 35%, transparent); outline-offset: -11px;
  box-shadow: 6px 6px 0 var(--shadow-ink); transform: rotate(-.8deg);
  animation: labelin .7s cubic-bezier(.2, 1.2, .4, 1) both;
}
.nhan-vo::before, .nhan-vo::after { /* tape */
  content: ""; position: absolute; top: -14px; width: 86px; height: 26px; background: var(--tape); opacity: .8;
  border-radius: 3px;
}
.nhan-vo::before { left: 26px; transform: rotate(-6deg); }
.nhan-vo::after { right: 26px; transform: rotate(5deg); }
.nv-top { display: flex; justify-content: space-between; gap: 12px; font-size: 12px; font-weight: 700; letter-spacing: .28em; color: #2463c9; margin-bottom: 6px; }
.nv-top span:last-child { letter-spacing: .05em; font-family: var(--f-zh); }
.lesson-head h1 { font-family: var(--f-display); font-weight: 800; font-size: clamp(26px, 4vw, 38px); color: var(--label-ink); margin: 0; line-height: 1.2; text-wrap: balance; }
.lesson-head h1 .say { text-decoration-color: color-mix(in srgb, #2463c9 45%, transparent); }
.lesson-head .zh-title { font-family: var(--f-zh); font-size: 20px; color: #3e5878; margin-top: 2px; }
.nv-lines { display: flex; flex-wrap: wrap; gap: 6px 26px; margin-top: 12px; font-size: 14px; }
.nv-lines span { border-bottom: 1.5px dotted color-mix(in srgb, var(--label-ink) 45%, transparent); padding-right: 14px; }
.nv-lines em { font-family: var(--f-hand); font-style: normal; color: #2463c9; font-size: 16px; margin-right: 8px; }
.lesson-watermark { display: none; }

/* ---------- lesson: side index tabs + pages ---------- */
.lesson-body { display: grid; grid-template-columns: 196px minmax(0, 1fr); gap: 26px; align-items: start; margin-top: 18px; }
.lesson-main { min-width: 0; }
.toc {
  position: sticky; top: calc(84px + env(safe-area-inset-top, 0px)); display: flex; flex-direction: column; gap: 6px;
  padding: 0; margin: 0; background: none; overflow: visible;
}
.toc a {
  display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-radius: 0 12px 12px 0;
  border: 2px solid var(--grid-bold); border-left: 6px solid var(--grid-bold); background: var(--sheet);
  color: var(--muted); font-size: 14px; font-weight: 500; transition: transform .25s, background .25s, color .25s, border-color .25s;
}
.toc a b { font-family: var(--f-hand); font-size: 19px; color: var(--pen); width: 16px; text-align: center; }
.toc a:hover { transform: translateX(4px); color: var(--ink); border-color: var(--pen); background: var(--sheet); }
.toc a.on { transform: translateX(10px); background: var(--ink); color: var(--paper); border-color: var(--ink); border-left-color: var(--margin); }
.toc a.on b { color: var(--paper); }
@media (max-width: 900px) {
  .lesson-body { grid-template-columns: minmax(0, 1fr); gap: 12px; }
  .toc {
    flex-direction: row; overflow-x: auto; top: calc(62px + env(safe-area-inset-top, 0px)); z-index: 10;
    background: color-mix(in srgb, var(--paper) 94%, transparent); padding: 6px 2px 10px; margin: 0 -2px;
  }
  .toc a { flex: none; border-radius: 10px 10px 0 0; border-left-width: 2px; border-top: 5px solid var(--grid-bold); padding: 6px 10px; }
  .toc a:hover { transform: translateY(-2px); }
  .toc a.on { transform: translateY(-3px); border-top-color: var(--margin); }
}

/* a notebook page: red double margin, punched holes, number written in the margin */
.section {
  position: relative; background: var(--sheet); border: none; border-radius: 4px 14px 14px 4px;
  padding: 26px 26px 28px 92px; margin-bottom: 26px; box-shadow: 0 1px 0 var(--grid-bold), 0 14px 30px -22px var(--shadow-ink);
  scroll-margin-top: 110px;
}
.section::before {
  content: ""; position: absolute; top: 0; bottom: 0; left: 70px; width: 5px;
  border-left: 1.5px solid var(--margin); border-right: 1.5px solid var(--margin); opacity: .75;
}
.section::after {
  content: ""; position: absolute; top: 18px; bottom: 18px; left: 18px; width: 18px;
  background: radial-gradient(circle at 9px 9px, var(--paper) 0 7px, var(--grid-bold) 7px 8px, transparent 8.5px) 0 0 / 18px 96px repeat-y;
}
.section > h2 { display: flex; align-items: flex-start; gap: 0; margin: 0 0 20px; padding: 0; }
.section > h2::after { content: none; }
.sec-no {
  position: absolute; left: 34px; top: 22px; width: auto; height: auto; background: none; box-shadow: none; border-radius: 0;
  font-family: var(--f-hand); font-weight: 400; font-size: 34px; color: var(--pen); transform: rotate(-6deg);
}
.sec-title { display: flex; flex-direction: column; gap: 2px; font-family: var(--f-zh); font-weight: 700; font-size: 25px; color: var(--ink); line-height: 1.3; }
.sec-title small { font-family: var(--f-hand); font-size: 19px; font-weight: 400; color: var(--pen); text-transform: none; letter-spacing: .02em; margin: 0; }
@media (max-width: 560px) {
  .section { padding: 20px 16px 22px 58px; }
  .section::before { left: 44px; }
  .section::after { left: 8px; width: 16px; background-size: 16px 96px; }
  .sec-no { left: 14px; top: 18px; font-size: 28px; }
  .sec-title { font-size: 21px; }
}

/* sub-headings: pen note with a highlighter stroke */
.block > h3 {
  display: inline-flex; align-items: center; gap: 8px; margin: 0 0 12px; padding: 0 4px;
  font-family: var(--f-display); font-weight: 700; font-size: 16px; color: var(--ink);
  background: linear-gradient(var(--hl), var(--hl)) no-repeat 0 90% / 100% 40%; border-radius: 0;
}
.block > h3::before { content: "✎"; width: auto; height: auto; background: none; box-shadow: none; color: var(--pen); font-size: 18px; }
.block { margin-top: 24px; }

/* goals list */
ul.clean li::before { background: none; content: "✓"; width: auto; height: auto; top: 0; left: 0; color: var(--pen); font-weight: 700; }
ul.clean li { padding-left: 22px; }

/* sticky notes for tips */
.tips {
  position: relative; background: var(--sticky); color: var(--sticky-ink); border-radius: 2px 2px 14px 2px;
  padding: 22px 22px 18px; transform: rotate(-.6deg);
  box-shadow: 0 12px 20px -14px #3b2d00, inset 0 -18px 24px -22px #6b5200;
  transition: transform .35s ease;
}
.tips:hover { transform: rotate(.3deg) translateY(-2px); }
.tips::before {
  content: ""; position: absolute; top: -11px; left: 50%; width: 96px; height: 24px; margin-left: -48px;
  background: var(--tape); opacity: .75; transform: rotate(-3deg); border-radius: 2px;
}
.tips h3 { font-family: var(--f-hand); font-size: 22px; font-weight: 400; color: var(--sticky-ink) !important; background: none !important; padding: 0 !important; }
.tips h3::before { content: none !important; }
.tips .bi .zh { color: color-mix(in srgb, var(--sticky-ink) 75%, transparent); }
.tips ul.clean li::before { content: "•"; color: var(--sticky-ink); }

/* ô-ly squares for syllables */
.grid { gap: 10px; }
.grid .cell {
  position: relative; overflow: hidden; border-radius: 3px; border: 1.5px solid var(--grid-bold); box-shadow: none;
  background:
    linear-gradient(90deg, transparent calc(50% - .5px), var(--grid-fine) calc(50% - .5px) calc(50% + .5px), transparent calc(50% + .5px)),
    repeating-linear-gradient(transparent 0 calc(25% - 1px), var(--grid-fine) calc(25% - 1px) 25%),
    var(--sheet);
  font-family: var(--f-display); font-size: 21px; font-weight: 600; color: var(--ink); min-height: 58px;
  display: grid; place-items: center; transition: transform .18s, border-color .18s, color .18s, box-shadow .18s;
}
.grid .cell:hover { transform: translateY(-3px) rotate(-1.5deg); border-color: var(--pen); color: var(--pen); box-shadow: 3px 3px 0 var(--shadow-ink); }
.grid .cell.head { background: none; border: none; font-family: var(--f-hand); font-size: 20px; color: var(--pen); font-weight: 400; min-height: 0; }
.grid .cell.empty { background: none; border: 1.5px dashed var(--grid-bold); color: var(--muted); }
.grid .cell.playing { background: var(--pen); color: var(--sheet); border-color: var(--pen); }

/* six tone colours */
.tone-0 { --tc: var(--t0); } .tone-1 { --tc: var(--t1); } .tone-2 { --tc: var(--t2); }
.tone-3 { --tc: var(--t3); } .tone-4 { --tc: var(--t4); } .tone-5 { --tc: var(--t5); }
.tone-grid .cell:not(.head) { color: color-mix(in srgb, var(--tc) 70%, var(--text)); border-bottom: 4px solid var(--tc); }
.tone-grid .cell:not(.head):hover { background: var(--tc); color: #fff; border-color: var(--tc); }
.tone-head { display: flex !important; flex-direction: column; align-items: center; padding: 8px 2px !important; border-radius: 10px 10px 2px 2px !important; background: var(--tc) !important; color: #fff !important; font-family: var(--f-display) !important; font-weight: 700 !important; font-size: 13px !important; }
.tone-head b { font-size: 22px; line-height: 1; }
.tone-head small { font-family: var(--f-zh); font-weight: 600; opacity: .9; }

/* ruled tables */
.table-wrap { border: 2px solid var(--ink); border-radius: 6px; box-shadow: 4px 4px 0 var(--shadow-ink); background: var(--sheet); }
th { background: var(--ink); color: var(--paper); font-family: var(--f-display); font-weight: 600; letter-spacing: .02em; }
td { border-bottom: 1px dashed var(--grid-bold); }
td.vi-cell { font-family: var(--f-display); color: var(--ink); }

/* phrases on ruled lines */
.pairs { gap: 0; }
.pair { background: none; border-radius: 0; border-bottom: 1.5px solid var(--grid-fine); padding: 12px 6px; transition: background .2s, transform .2s; }
.pair:hover { background: linear-gradient(90deg, var(--hl), transparent); transform: translateX(4px); }
.pair .num { font-family: var(--f-hand); font-size: 20px; color: var(--pen); }
.pair .vi { font-family: var(--f-display); font-size: 16.5px; color: var(--ink); }
.grammar-item .pair, .ex.pairs .pair { border-bottom-style: dashed; }

/* reading text on lined paper */
.reading { background: var(--sheet); border: 2px solid var(--grid-bold); border-radius: 6px; padding: 10px 18px; }
.reading .line { padding: 10px 0; border-bottom: 1.5px solid var(--grid-fine); }
.reading .line:last-child { border-bottom: none; }
.reading .who { font-family: var(--f-hand); font-size: 20px; color: var(--margin); font-weight: 400; min-width: 64px; }
.reading .vi { color: var(--ink); }

/* grammar notes */
.grammar-item { border-left: 3px solid var(--pen); border-radius: 0; padding: 2px 0 2px 18px; margin-bottom: 22px; }
.grammar-item::before { content: none; }
.grammar-item h4 { font-family: var(--f-display); font-size: 17px; color: var(--pen); }

/* vocabulary as ruled index cards */
.vocab-list { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.vocab {
  border: none; border-radius: 4px; padding: 14px 16px 12px; box-shadow: 0 1px 0 var(--grid-bold), 3px 3px 0 var(--shadow-ink);
  background: var(--sheet); column-gap: 0; row-gap: 0;
  outline: 1.5px solid var(--grid-bold);
  transition: transform .25s ease, box-shadow .25s ease;
}
.vocab:nth-child(odd) { transform: rotate(-.5deg); }
.vocab:nth-child(even) { transform: rotate(.5deg); }
.vocab:hover { transform: rotate(0) translateY(-4px); box-shadow: 0 1px 0 var(--grid-bold), 6px 8px 0 var(--shadow-ink); }
.vocab .word b { font-family: var(--f-display); font-size: 21px; color: var(--ink); }
.vocab .pos { font-family: var(--f-hand); font-size: 15px; background: none; color: var(--pen); border: 1.5px solid var(--pen); border-radius: 10px; padding: 0 7px; }
.vocab .mean { font-family: var(--f-zh); font-size: 15.5px; color: var(--text); }
/* the red rule sits under the headword row, however tall it gets; example lines sit on blue rules */
.vocab .word, .vocab .mean { align-self: stretch; display: flex; align-items: center; padding-bottom: 10px; border-bottom: 1.5px solid var(--margin); }
.vocab .mean { padding-left: 12px; }
.vocab .ex {
  line-height: 28px; padding-top: 6px; margin-top: 0;
  background: repeating-linear-gradient(transparent 0 27px, var(--grid-fine) 27px 28px) 0 6px / 100% calc(100% - 6px) no-repeat;
}

/* worksheets */
.exercise { border: 2px dashed var(--grid-bold); border-radius: 10px; background: var(--sheet); padding: 18px; }
.exercise > h3 { font-family: var(--f-display); font-size: 17px; color: var(--ink); }
.exercise .hint { font-family: var(--f-hand); font-size: 17px; color: var(--pen); }
.q .prompt { font-family: var(--f-display); color: var(--ink); }
.opt { border: 2px solid var(--grid-bold); border-radius: 999px; background: var(--sheet); font-family: var(--f-display); transition: transform .15s, border-color .15s, box-shadow .15s; }
.opt:hover { border-color: var(--ink); box-shadow: 2px 2px 0 var(--shadow-ink); transform: translate(-1px, -1px); }
.opt.right { box-shadow: 2px 2px 0 var(--good); }
input.text, textarea.text {
  border: none; border-bottom: 2px dashed var(--pen); border-radius: 0; background: transparent; padding: 8px 4px;
  font-family: var(--f-display); font-size: 16px; color: var(--ink);
}
input.text:focus, textarea.text:focus { outline: none; border-bottom-style: solid; background: var(--accent-soft); }
select.text { border: 2px solid var(--grid-bold); border-radius: 8px; font-family: var(--f-display); }

/* buttons: sticker style with an ink offset shadow */
.btn {
  position: relative; overflow: hidden; font-family: var(--f-display); font-weight: 600;
  border: 2px solid var(--ink); background: var(--sheet); color: var(--ink); box-shadow: 3px 3px 0 var(--shadow-ink);
  transition: transform .12s, box-shadow .12s, background .2s;
}
.btn:hover { transform: translate(-1px, -1px); box-shadow: 4px 4px 0 var(--shadow-ink); border-color: var(--ink); }
.btn:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--shadow-ink); }
.btn.primary { background: var(--pen); color: #fff; border-color: var(--ink); }
.btn.primary:hover { filter: none; background: color-mix(in srgb, var(--pen) 88%, #000); }
:root[data-theme="dark"] .btn.primary { color: #0d2236; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .btn.primary { color: #0d2236; } }
.spk { position: relative; overflow: hidden; background: var(--sheet); color: var(--pen); border: 2px solid var(--pen); width: 30px; height: 30px; transition: transform .15s, background .15s; }
.spk:hover { background: var(--pen); color: var(--sheet); transform: scale(1.1) rotate(-6deg); }
.say { text-decoration-color: color-mix(in srgb, var(--pen) 50%, transparent); }
.say:hover { background: var(--hl); }

.voice-warning { font-family: var(--f-hand); font-size: 17px; background: var(--sticky); color: var(--sticky-ink); border-radius: 2px; transform: rotate(-.4deg); }
.pager { margin-top: 10px; }
.crumbs { font-family: var(--f-hand); font-size: 17px; color: var(--pen); }
.crumbs a { color: var(--pen); }
.footer { font-family: var(--f-hand); font-size: 17px; color: var(--muted); }

/* flashcards + quiz */
.face { border: 2px solid var(--ink); box-shadow: 6px 6px 0 var(--shadow-ink); border-radius: 6px;
  background:
    linear-gradient(var(--margin), var(--margin)) 0 54px / 100% 1.5px no-repeat,
    repeating-linear-gradient(transparent 0 31px, var(--grid-fine) 31px 32px) 0 56px / 100% calc(100% - 56px) no-repeat,
    var(--sheet); }
.face .big { font-family: var(--f-display); color: var(--ink); }
.face.back { background: var(--pen); color: #fff; }
.face.back .small { color: color-mix(in srgb, #fff 85%, transparent); }
.face .mid { font-family: var(--f-zh); font-size: 26px; }
.quiz-card { background: var(--sheet); }
.quiz-word { font-family: var(--f-display); color: var(--ink); }
.result b {
  display: inline-grid !important; place-items: center; width: 170px; height: 170px; margin: 0 auto 12px; border-radius: 50%;
  border: 5px double var(--margin); color: var(--margin); font-family: var(--f-display); font-size: 40px;
  transform: rotate(-10deg); animation: stampin .7s cubic-bezier(.2, 1.5, .4, 1) both;
}
.result p { font-family: var(--f-hand); font-size: 22px; }

/* recording page rows sit on the notebook too */
.rec-row { border: 2px solid var(--grid-bold); border-radius: 8px; box-shadow: 2px 2px 0 var(--grid-bold); }
.rec-text { font-family: var(--f-display); color: var(--ink); }

/* ---------- motion ---------- */
.ripple {
  position: absolute; width: 10px; height: 10px; margin: -5px 0 0 -5px; border-radius: 50%; pointer-events: none;
  background: color-mix(in srgb, var(--pen) 35%, transparent); animation: ripple .6s ease-out forwards;
}
.btn.primary .ripple { background: color-mix(in srgb, #fff 45%, transparent); }
.reveal { animation: none !important; opacity: 0; transform: translateY(22px); }
.reveal.in { opacity: 1; transform: none; transition: opacity .6s ease var(--d, 0ms), transform .7s cubic-bezier(.2, .8, .2, 1) var(--d, 0ms); }
.vocab.reveal.in:nth-child(odd) { transform: rotate(-.5deg); }
.vocab.reveal.in:nth-child(even) { transform: rotate(.5deg); }
.vocab.reveal.in:hover { transform: rotate(0) translateY(-4px); }
.tips.reveal.in { transform: rotate(-.6deg); }
.tips.reveal.in:hover { transform: rotate(.3deg) translateY(-2px); }
.notebook.reveal { transform: translateY(26px) rotate(-3deg); }
.notebook.reveal.in { transform: none; }
.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 100; overflow: hidden; }
.confetti i { position: absolute; top: -12px; width: 9px; height: 14px; border-radius: 2px; animation: fall 2.2s cubic-bezier(.25, .6, .4, 1) forwards; }
#app > .hero, #app > .lesson-head { animation: rise .5s ease both; }

@keyframes hlsweep { from { background-size: 0% 42%; } to { background-size: 100% 42%; } }
@keyframes stampin { 0% { opacity: 0; transform: scale(1.8) rotate(8deg); } 70% { opacity: 1; transform: scale(.94) rotate(-14deg); } 100% { opacity: 1; transform: scale(1) rotate(-12deg); } }
@keyframes labelin { from { opacity: 0; transform: translateY(-14px) rotate(-4deg); } to { opacity: 1; transform: rotate(-.8deg); } }
@keyframes ripple { to { transform: scale(28); opacity: 0; } }
@keyframes fall { to { transform: translate(var(--x), 105vh) rotate(var(--r)); opacity: .9; } }

@media (max-width: 560px) {
  .topnav a { white-space: nowrap; }
  .brand-text { font-size: 14px; }
  .brand-text small { font-size: 13px; }
  .brand-mark { width: 30px; height: 38px; font-size: 15px; }
  .nhan-vo { padding: 16px 18px 14px; }
}
@media (prefers-reduced-motion: reduce) {
  .reveal { opacity: 1; transform: none; }
  .hl, .section.reveal .hl { background-size: 100% 42% !important; }
}

/* ---------- name page + personal greeting ---------- */
.welcome { min-height: calc(100vh - 220px); display: grid; place-items: center; padding: 30px 0 50px; }
.name-card { max-width: 560px; display: flex; flex-direction: column; gap: 10px; padding: 26px 30px 26px; }
.welcome-hand { font-family: var(--f-hand); font-size: 30px; color: #2463c9; margin: 4px 0 0; transform: rotate(-2deg); transform-origin: left; }
.name-card h1 { font-family: var(--f-kai); font-weight: 700; font-size: clamp(24px, 4vw, 32px); color: var(--label-ink); margin: 0; }
.welcome-sub { font-family: var(--f-kai); color: #3e5878; margin: 0 0 8px; font-size: 17px; }
.name-label { font-family: var(--f-kai); font-size: 16px; color: #3e5878; margin-top: 6px; }
.name-label em { font-family: var(--f-hand); font-style: normal; font-size: 19px; color: #2463c9; margin-right: 8px; }
.name-input {
  font-family: var(--f-hand), var(--f-kai); font-size: 30px; color: #2463c9; background: transparent;
  border: none; border-bottom: 2.5px dotted #173b6c; padding: 4px 2px 6px; outline: none; width: 100%;
}
.name-input::placeholder { color: color-mix(in srgb, #173b6c 30%, transparent); }
.name-input:focus { border-bottom-style: solid; border-bottom-color: #2463c9; }
.welcome-actions { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 14px; }
.name-card .btn { box-shadow: 3px 3px 0 #173b6c; border-color: #173b6c; }
.name-card .btn:not(.primary) { background: #fff; color: #173b6c; }
.name-card .btn.primary { background: #2463c9; color: #fff; }
.name-card .feedback { margin: 0; }

.hero h1 { font-family: var(--f-display); }
.hero-welcome { font-family: var(--f-kai); font-size: clamp(20px, 2.6vw, 26px) !important; color: var(--ink) !important; font-weight: 700; margin: 0 0 12px; }
.hero-motto {
  display: inline-block; font-family: var(--f-kai); font-size: 20px !important; font-weight: 700; color: var(--margin) !important;
  margin: 10px 0 0; padding: 2px 10px; border: 2px solid var(--margin); border-radius: 6px; transform: rotate(-1.5deg);
  animation: stampin2 .7s cubic-bezier(.2, 1.5, .4, 1) .9s both;
}
.rename { font-family: var(--f-kai); font-size: 15px; color: var(--muted); text-decoration: none; border-bottom: 1.5px dashed currentColor; }
.rename:hover { color: var(--pen); }
@keyframes stampin2 { 0% { opacity: 0; transform: scale(1.6) rotate(6deg); } 100% { opacity: 1; transform: scale(1) rotate(-1.5deg); } }
@media (prefers-reduced-motion: reduce) { .hero-motto { animation: none; } }
