/* Unit / dictation screens — Classroom Hub (after-folder-revise-2) tokens
   Per-unit themes via body.theme-unit1 … theme-dictation3
   Fredoka (display) + Nunito (body) · solid accents · no pastel mint chrome */

:root {
  --bg: #fcf0d8;
  --surface: #fcf0e4;
  --ink: #243c6c;
  --muted: #5a6570;
  --accent: #fcc03c;       /* default sunny; overridden per theme */
  --accent-ink: #243c6c;   /* text on accent header; Unit 2 overrides to white */
  --navy: #243c6c;
  --cream: #fcf0d8;
  --sunny: #fcc03c;
  --green: #009c48;
  --sky: #84c0e4;
  --pink: #f0909c;
  --coral: #fc903c;        /* CTA */
  --white: #ffffff;

  --font-display: "Fredoka", "Nunito", "PingFang TC", "Noto Sans TC", system-ui, sans-serif;
  --font-text: "Nunito", "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
  --margin: clamp(1rem, 2.2vw, 1.75rem);
  --illust: 220px;
  --radius: 24px;
  --radius-sm: 18px;
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --t-press: 140ms;
  --t-hover: 180ms;

  --shell: 0.85rem; /* coloured shell thickness around cream panel */
  --highlight: rgba(252, 192, 60, 0.95); /* sunny word highlight */
}

/* —— Per-unit theme tokens —— */
body.theme-unit1 {
  --accent: #fcc03c;
  --accent-ink: #243c6c;
  --shell-color: #fcc03c;
}
body.theme-unit2 {
  --accent: #009c48;
  --accent-ink: #ffffff; /* white text on green header */
  --shell-color: #009c48;
}
body.theme-unit3 {
  --accent: #84c0e4;
  --accent-ink: #243c6c;
  --shell-color: #84c0e4;
}
body.theme-unit4 {
  --accent: #fcc03c;
  --accent-ink: #243c6c;
  --shell-color: #fcc03c;
}
body.theme-unit5 {
  --accent: #fc903c;
  --accent-ink: #243c6c;
  --shell-color: #fc903c;
}
body.theme-unit6 {
  --accent: #f0909c;
  --accent-ink: #243c6c;
  --shell-color: #f0909c;
}
body.theme-dictation3 {
  --accent: #f0909c;
  --accent-ink: #243c6c;
  --shell-color: #f0909c;
}

*, *::before, *::after { box-sizing: border-box; }
html { scrollbar-gutter: stable; }
html, body {
  margin: 0; padding: 0;
  background: var(--bg); color: var(--ink);
  font-family: var(--font-text);
  font-size: 1.0625rem;
  font-weight: 500;
  line-height: 1.55;
  letter-spacing: -0.01em;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow-x: clip;
}
img, svg { display: block; max-width: 100%; }
a { color: inherit; }
button { font: inherit; cursor: pointer; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
::selection { background: var(--sunny); color: var(--navy); }

.unit-header {
  background: var(--accent);
  color: var(--accent-ink);
  padding: 1rem var(--margin) 1.15rem;
  overflow: hidden;
}
.unit-header > * { position: relative; z-index: 1; }
.back {
  display: inline-block;
  font-weight: 700;
  font-family: var(--font-display);
  font-size: 1rem;
  text-decoration: underline;
  text-underline-offset: 0.15em;
  margin-bottom: 0.4rem;
  color: var(--accent-ink);
  opacity: 0.9;
}
.back:hover { opacity: 1; text-decoration: underline; }
.unit-header h1 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 650;
  font-size: clamp(1.55rem, 1.15rem + 1.8vw, 2.2rem);
  line-height: 1.1;
  letter-spacing: -0.02em;
  max-width: 22ch;
  color: var(--accent-ink);
}
.sub {
  margin: 0.4rem 0 0;
  color: var(--accent-ink);
  font-size: 1rem;
  font-weight: 600;
  opacity: 0.9;
}
.hint {
  max-width: 720px;
  margin: 1.1rem auto 0;
  padding: 0 var(--margin);
  color: var(--ink);
  font-size: 1rem;
  font-weight: 600;
}

.list, .grid {
  max-width: 760px;
  margin: 0 auto;
  padding: 1rem var(--margin) calc(2.5rem + env(safe-area-inset-bottom, 0px));
  display: flex;
  flex-direction: column;
  gap: 1.15rem;
}
.grid { display: grid; grid-template-columns: 1fr; }

.card {
  position: relative;
  padding: var(--shell);
  color: var(--ink);
  border: 0;
  border-radius: var(--radius);
  background: var(--shell-color, var(--accent));
  /* Keep overflow visible so speaker isn't clipped; shell is padding not border */
  overflow: visible;
  scroll-margin-top: 1rem;
}
.card > * { position: relative; z-index: 1; }
.card::after {
  content: "";
  position: absolute;
  inset: var(--shell);
  background: var(--cream);
  border-radius: calc(var(--radius) - 8px);
  z-index: 0;
  pointer-events: none;
}

/* Fill variants all use unit shell colour (no leftover pastel mint/rose) */
.card.fill-a,
.card.fill-b,
.card.fill-c,
.card.fill-d,
.card.fill-e,
.card.fill-f {
  background: var(--shell-color, var(--accent));
  color: var(--ink);
}
.card.fill-f::after { background: var(--cream); }

.card.playing { outline: 4px solid var(--navy); outline-offset: 2px; }

/* Speaker fully inside cream panel: shell + inner radius clearance + gap
   Stays sunny yellow on every unit */
.speaker {
  position: absolute;
  top: calc(var(--shell) + 14px);
  right: calc(var(--shell) + 14px);
  width: 44px; height: 44px;
  border-radius: 14px;
  background: var(--sunny);
  color: var(--navy);
  z-index: 2;
  display: grid; place-items: center;
  border: 0;
  box-shadow: 0 1px 0 rgba(36, 60, 108, 0.08);
  transition: transform var(--t-press) var(--ease-out), background var(--t-hover);
}
.speaker:hover { background: #f0b020; }
.speaker:active { transform: scale(0.94); }
.speaker svg { width: 22px; height: 22px; }

.top {
  display: grid;
  grid-template-columns: var(--illust) 1fr;
  gap: 1rem;
  align-items: start;
  /* leave room so syllables don't collide with inset speaker */
  padding: 0.85rem 3.7rem 0 0.85rem;
}
.illust {
  position: relative;
  border-radius: var(--radius-sm);
  overflow: hidden;
  aspect-ratio: 1;
  background: #fff;
  cursor: pointer;
}
.illust img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  max-width: none;
  object-fit: cover;
  object-position: center;
  background: transparent;
}
.illust.cutout { background: #fff; }
.illust.cutout img {
  object-fit: contain;
  background: #fff;
}
.main .num {
  display: inline-block;
  font-weight: 700;
  font-family: var(--font-display);
  font-size: 0.95rem;
  opacity: 0.85;
  margin-bottom: 0.25rem;
}
.syllables {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: clamp(1.25rem, 1.05rem + 0.8vw, 1.55rem);
  line-height: 1.2;
  letter-spacing: -0.02em;
  margin: 0 0 0.35rem;
  word-break: normal;
  overflow-wrap: normal;
  hyphens: manual;
}
.zh {
  margin: 0;
  font-size: 1rem;
  line-height: 1.45;
  opacity: 0.95;
  font-family: "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", var(--font-text);
}

.ex {
  margin-top: 0.85rem;
  padding: 0.85rem 0.95rem;
  border-radius: var(--radius-sm);
  background: rgba(36, 60, 108, 0.05);
}
.ex-label {
  display: block;
  font-weight: 700;
  font-family: var(--font-display);
  font-size: 0.9rem;
  margin-bottom: 0.3rem;
}
.ex-en { margin: 0 0 0.25rem; font-size: 1rem; line-height: 1.45; }
.ex-zh {
  margin: 0;
  font-size: 0.95rem;
  line-height: 1.45;
  opacity: 0.95;
  font-family: "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", var(--font-text);
}
.hl {
  background: var(--highlight);
  color: var(--navy);
  border-radius: 6px;
  padding: 0 0.15em;
}

.lightbox {
  position: fixed; inset: 0;
  background: rgba(36, 60, 108, 0.88);
  display: none;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 1rem;
  padding: 1.5rem;
  z-index: 80;
}
.lightbox.open { display: flex; }
.lightbox img {
  max-width: min(920px, 100%);
  max-height: 70vh;
  object-fit: contain;
  border-radius: var(--radius);
  background: var(--cream);
}
.lb-bar { display: flex; gap: 0.75rem; flex-wrap: wrap; justify-content: center; }
.lb-btn {
  min-height: 48px;
  padding: 0.6rem 1.2rem;
  border-radius: var(--radius-sm);
  border: 0;
  font-weight: 700;
  font-family: var(--font-display);
  background: var(--coral);
  color: var(--white);
}
.lb-close { background: var(--cream); color: var(--navy); }

@media (max-width: 560px) {
  :root { --illust: 140px; }
  .top {
    grid-template-columns: 1fr;
    padding: 0.85rem 0.85rem 0;
  }
  .illust {
    max-width: min(200px, 100%);
    width: 100%;
  }
  /* Speaker stays fully inside cream panel on phone */
  .speaker {
    top: calc(var(--shell) + 12px);
    right: calc(var(--shell) + 12px);
  }
  .unit-header h1 { max-width: none; }
  .card { overflow: visible; }
  .lb-btn { flex: 1 1 auto; min-width: 7rem; }
}

.headword {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: clamp(1.25rem, 1.05rem + 0.8vw, 1.55rem);
  line-height: 1.2;
  margin: 0;
}
.teach {
  margin: 0.85rem 0.85rem 0;
  padding: 0.85rem 0.95rem;
  border-radius: var(--radius-sm);
  background: rgba(36, 60, 108, 0.05);
}
.teach-tip { background: rgba(252, 192, 60, 0.22); }
.pattern, .tip-en { margin: 0; font-weight: 600; line-height: 1.45; }
.card .ex { margin-left: 0.85rem; margin-right: 0.85rem; }
.card .ex:last-child { margin-bottom: 0.85rem; }
.illust { position: relative; z-index: 1; }


/* Practice link in unit header */
.header-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.35rem;
}
.header-nav .back { margin-bottom: 0; }
.practice-link {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.95rem;
  text-decoration: none;
  color: var(--accent-ink);
  background: rgba(255,255,255,0.55);
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  white-space: nowrap;
}
.practice-link:hover { background: rgba(255,255,255,0.85); text-decoration: underline; }
body.theme-unit2 .practice-link {
  background: rgba(255,255,255,0.22);
  color: #fff;
}
