:root {
  --paper: #fbf6ec;
  --paper-deep: #f1e6d2;
  --card: #fffdf8;
  --ink: #2a241c;
  --ink-soft: #5a5248;
  --line: #e4d8c4;
  --line-strong: #d2c3a8;
  --seal: #b44732;
  --seal-dark: #8c3324;
  --seal-soft: #f8e4de;
  --gold: #e8c56b;
  --gold-soft: #f8e7b4;
  --leaf: #2f6a4f;
  --leaf-soft: #e4f0e8;
  --warn: #8a5a12;
  --warn-soft: #f8efd6;
  --info: #3d5a73;
  --info-soft: #e7eef4;
  --oral: #5b4a7a;
  --oral-soft: #efeaf7;
  --shadow: 0 10px 30px rgba(42, 36, 28, 0.07);
  --font-ui: "Noto Sans TC", "PingFang HK", "Microsoft JhengHei", sans-serif;
  --font-serif: "Noto Serif TC", "Songti TC", "PMingLiU", serif;
  --max: 52rem;
  --header-h: 3.5rem;
  --radius: 16px;
  --focus: 0 0 0 3px #fff, 0 0 0 6px var(--seal);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  max-width: 100%;
  overflow-x: hidden;
}

body {
  margin: 0;
  background:
    radial-gradient(1200px 400px at 10% -10%, rgba(180, 71, 50, 0.07), transparent 50%),
    var(--paper);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 1.05rem;
  line-height: 1.75;
  max-width: 100%;
  overflow-x: hidden;
  min-height: 100vh;
}

img,
svg,
video,
table {
  max-width: 100%;
}

a {
  color: var(--seal-dark);
  text-underline-offset: 0.18em;
}

a:hover {
  color: var(--seal);
}

:focus-visible {
  outline: none;
  box-shadow: var(--focus);
}

.skip-link {
  position: absolute;
  left: 12px;
  top: -40px;
  background: var(--ink);
  color: #fff;
  padding: 8px 12px;
  border-radius: 8px;
  z-index: 100;
}

.skip-link:focus {
  top: 12px;
}

.preview-banner {
  background: var(--ink);
  color: #f6eedf;
  font-size: 0.85rem;
  letter-spacing: 0.04em;
  text-align: center;
  padding: 0.4rem 16px;
  overflow-wrap: anywhere;
}

.wrap {
  width: 100%;
  max-width: var(--max);
  margin-inline: auto;
  padding-inline: 16px;
  min-width: 0;
}

.topbar {
  background: rgba(251, 246, 236, 0.92);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 40;
  backdrop-filter: blur(10px);
}

.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: var(--header-h);
  min-width: 0;
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 0.55rem;
  text-decoration: none;
  color: var(--ink);
  min-width: 0;
}

.brand-mark {
  font-family: var(--font-serif);
  font-weight: 700;
  color: var(--seal);
  font-size: 1.25rem;
  line-height: 1;
}

.brand-text {
  font-family: var(--font-serif);
  font-weight: 600;
  font-size: 1.05rem;
  white-space: nowrap;
}

.brand-text small {
  display: block;
  font-family: var(--font-ui);
  font-weight: 400;
  font-size: 0.72rem;
  color: var(--ink-soft);
  letter-spacing: 0.06em;
}

.nav-desktop {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 0.15rem;
  min-width: 0;
}

.nav-desktop a {
  text-decoration: none;
  color: var(--ink-soft);
  padding: 0.4rem 0.75rem;
  border-radius: 999px;
  font-weight: 500;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
}

.nav-desktop a[aria-current="page"],
.nav-desktop a:hover {
  color: var(--seal-dark);
  background: var(--seal-soft);
}

main {
  padding: 1.5rem 0 6rem;
  min-width: 0;
}

.notice {
  background: var(--warn-soft);
  border: 1px solid #ead7a2;
  color: var(--warn);
  border-radius: var(--radius);
  padding: 0.9rem 1rem;
  margin: 0 0 1.25rem;
}

.notice strong {
  color: var(--ink);
}

.hero {
  display: grid;
  gap: 1.25rem;
  margin-bottom: 1.75rem;
}

.kicker {
  font-size: 0.82rem;
  letter-spacing: 0.12em;
  text-transform: none;
  color: var(--seal);
  font-weight: 600;
  margin: 0 0 0.4rem;
}

h1,
h2,
h3,
.lesson-body h1,
.lesson-body h2,
.lesson-body h3 {
  font-family: var(--font-serif);
  line-height: 1.35;
  font-weight: 700;
  margin: 0 0 0.7rem;
}

h1 {
  font-size: clamp(1.7rem, 4vw, 2.35rem);
}

h2 {
  font-size: 1.35rem;
}

.lede {
  font-size: 1.08rem;
  color: var(--ink-soft);
  margin: 0 0 1rem;
  max-width: 40rem;
}

.hero-actions,
.inline-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.7rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-height: 44px;
  padding: 0.55rem 1.15rem;
  border-radius: 999px;
  border: 1px solid transparent;
  text-decoration: none;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  background: var(--card);
  color: var(--ink);
}

.btn-accent {
  background: var(--seal);
  color: #fff;
  border-color: var(--seal-dark);
}

.btn-accent:hover {
  background: var(--seal-dark);
  color: #fff;
}

.btn-ghost {
  background: transparent;
  border-color: var(--line-strong);
  color: var(--ink);
}

.btn-ghost:hover {
  background: var(--paper-deep);
}

.btn-small {
  min-height: 44px;
  padding: 0.4rem 0.9rem;
  font-size: 0.95rem;
}

.card-grid {
  display: grid;
  gap: 1rem;
  margin: 1rem 0 1.75rem;
}

@media (min-width: 720px) {
  .card-grid.two {
    grid-template-columns: 1fr 1fr;
  }
  .goals {
    grid-template-columns: repeat(3, 1fr);
  }
}

.card,
.goal-card,
.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.1rem 1.15rem;
  min-width: 0;
}

.card h2,
.goal-card h2,
.goal-card h3 {
  margin-bottom: 0.4rem;
}

.goal-card {
  border-top: 4px solid var(--seal);
}

.muted {
  color: var(--ink-soft);
}

.meta-list,
.footer-note,
.lesson-toc {
  padding: 0;
  margin: 0;
}

.meta-list li,
.lesson-toc li {
  list-style: none;
}

.meta-list li {
  padding: 0.2rem 0;
}

.pill-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin: 0.6rem 0 0;
}

.pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 0.2rem 0.7rem;
  background: var(--paper-deep);
  font-size: 0.88rem;
  color: var(--ink-soft);
}

.not-required {
  background: var(--info-soft);
  border-color: #c9d7e4;
}

/* Lesson */
.lesson-layout {
  display: grid;
  gap: 1.25rem;
}

@media (min-width: 900px) {
  .lesson-layout {
    grid-template-columns: 13.5rem minmax(0, 1fr);
    align-items: start;
  }
  .lesson-toc-wrap {
    position: sticky;
    top: calc(var(--header-h) + 1rem);
  }
}

.lesson-toc a {
  display: block;
  text-decoration: none;
  color: var(--ink-soft);
  padding: 0.35rem 0;
  border-left: 3px solid transparent;
  padding-left: 0.7rem;
  overflow-wrap: break-word;
}

.lesson-toc a:hover,
.lesson-toc a:focus {
  color: var(--seal-dark);
  border-left-color: var(--seal);
}

.lesson-body,
.q-stem,
.feedback,
.instructions {
  overflow-wrap: break-word;
  word-wrap: break-word;
  min-width: 0;
}

.lesson-body h1 {
  margin-top: 0;
}

.lesson-body h2 {
  margin-top: 2rem;
  padding-top: 0.4rem;
}

.lesson-body p,
.lesson-body li {
  max-width: 42rem;
}

.key-term {
  background: var(--gold-soft);
  box-shadow: inset 0 -0.18em 0 var(--gold);
  border-radius: 0.2em;
  padding: 0.02em 0.18em;
  font-weight: 600;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
}

.table-wrap {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  margin: 1rem 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
}

.table-wrap table {
  width: 100%;
  border-collapse: collapse;
  min-width: 16rem;
}

.table-wrap th,
.table-wrap td {
  text-align: left;
  padding: 0.7rem 0.85rem;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

.table-wrap th {
  background: var(--paper-deep);
  font-weight: 600;
  white-space: nowrap;
}

.table-wrap tr:last-child td {
  border-bottom: none;
}

.video-ref {
  margin-top: 2rem;
  padding: 1rem 1rem 1.1rem;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  background: #f7f4ee;
}

.video-badge {
  display: inline-block;
  margin: 0 0 0.7rem;
  background: var(--ink);
  color: #f6eedf;
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  border-radius: 10px;
  padding: 0.35rem 0.75rem;
  max-width: 100%;
  line-height: 1.5;
  overflow-wrap: break-word;
}

.video-ref h2 {
  margin-top: 0;
}

.video-ref a {
  font-weight: 600;
}

/* Practice */
.instructions {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem 1.15rem 0.3rem;
  margin-bottom: 1rem;
}

.instructions h2 {
  font-size: 1.15rem;
}

.jump-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  position: sticky;
  top: var(--header-h);
  z-index: 30;
  background: rgba(251, 246, 236, 0.94);
  padding: 0.55rem 0;
  margin: 0 0 0.8rem;
  border-bottom: 1px solid var(--line);
}

.jump-nav a,
.jump-nav button {
  border: 1px solid var(--line-strong);
  background: var(--card);
  color: var(--ink);
  text-decoration: none;
  border-radius: 999px;
  min-height: 40px;
  padding: 0.25rem 0.8rem;
  font: inherit;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
}

.jump-nav a:hover,
.jump-nav button:hover,
.jump-nav a[aria-current="true"] {
  border-color: var(--seal);
  color: var(--seal-dark);
  background: var(--seal-soft);
}

.level-block {
  margin: 1.4rem 0 2rem;
}

.level-block h2 {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.5rem;
}

.level-block h2 .count {
  font-family: var(--font-ui);
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--ink-soft);
}

.q-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem 1rem 1.1rem;
  margin: 0 0 1rem;
  min-width: 0;
}

.q-card.q-oral {
  border-color: #d4c8e6;
  background: linear-gradient(180deg, var(--oral-soft), var(--card) 3rem);
}

.q-head {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
  margin-bottom: 0.55rem;
}

.q-id {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.tag {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 0.1rem 0.55rem;
  font-size: 0.78rem;
  font-weight: 600;
  background: var(--paper-deep);
  color: var(--ink-soft);
}

.tag-foundation { background: #efe6d3; color: #5a4a2c; }
.tag-application { background: #e4eef6; color: var(--info); }
.tag-inquiry { background: #ece4f6; color: var(--oral); }
.tag-marks { background: var(--seal-soft); color: var(--seal-dark); }
.tag-oral { background: var(--ink); color: #f6eedf; }

.q-target {
  color: var(--ink-soft);
  font-size: 0.92rem;
}

.q-stem {
  margin: 0.2rem 0 0.8rem;
  font-size: 1.05rem;
}

.options {
  border: 0;
  margin: 0 0 0.8rem;
  padding: 0;
  display: grid;
  gap: 0.45rem;
  min-width: 0;
}

.option {
  display: flex;
  gap: 0.65rem;
  align-items: flex-start;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.7rem 0.8rem;
  min-height: 44px;
  cursor: pointer;
  background: #fff;
  min-width: 0;
}

.option:hover {
  border-color: var(--line-strong);
  background: var(--paper);
}

.option input {
  margin-top: 0.3rem;
  flex: none;
  width: 1.1rem;
  height: 1.1rem;
  accent-color: var(--seal);
}

.option .opt-letter {
  font-weight: 700;
  color: var(--seal-dark);
  flex: none;
}

.option .opt-text {
  min-width: 0;
  overflow-wrap: break-word;
}

.option.is-correct {
  border-color: var(--leaf);
  background: var(--leaf-soft);
}

.option.is-wrong {
  border-color: var(--seal);
  background: var(--seal-soft);
}

textarea,
input[type="text"] {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  font: inherit;
  font-size: 16px; /* avoid iOS zoom */
  line-height: 1.6;
  padding: 0.75rem 0.85rem;
  border-radius: 12px;
  border: 1px solid var(--line-strong);
  background: #fff;
  color: var(--ink);
  resize: vertical;
  margin-bottom: 0.5rem;
}

textarea {
  min-height: 7.5rem;
}

textarea.long-answer {
  min-height: 10rem;
}

.char-count {
  font-size: 0.85rem;
  color: var(--ink-soft);
  margin: -0.2rem 0 0.7rem;
}

.q-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.2rem;
}

.feedback {
  margin-top: 0.9rem;
  padding: 0.85rem 0.9rem;
  border-radius: 12px;
  background: var(--paper);
  border: 1px solid var(--line);
}

.feedback h3 {
  font-family: var(--font-ui);
  font-size: 0.95rem;
  margin: 0.8rem 0 0.3rem;
}

.feedback h3:first-child {
  margin-top: 0;
}

.feedback.ok {
  background: var(--leaf-soft);
  border-color: #b7d6c3;
}

.feedback.bad {
  background: var(--seal-soft);
  border-color: #e4b7ad;
}

.feedback.review {
  background: var(--info-soft);
  border-color: #c9d7e4;
}

.mp-list,
.steps {
  margin: 0.2rem 0 0.4rem;
  padding-left: 1.15rem;
}

.mp-item {
  display: flex;
  gap: 0.6rem;
  align-items: flex-start;
  margin: 0.35rem 0;
  min-width: 0;
}

.mp-item label {
  min-width: 0;
  overflow-wrap: break-word;
}

.mp-item input {
  margin-top: 0.35rem;
  width: 1.15rem;
  height: 1.15rem;
  flex: none;
  accent-color: var(--leaf);
}

.mp-note {
  color: var(--ink-soft);
  font-size: 0.95rem;
}

.synonym-note {
  margin: 0.4rem 0 0.7rem;
  font-size: 0.95rem;
}

.results {
  background: var(--card);
  border: 2px solid var(--seal);
  border-radius: var(--radius);
  padding: 1.1rem 1.15rem;
  margin: 1.2rem 0 2rem;
  box-shadow: var(--shadow);
}

.results[hidden] {
  display: none;
}

.score-row {
  display: grid;
  gap: 0.6rem;
  margin: 0.8rem 0;
}

@media (min-width: 640px) {
  .score-row {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

.score-box {
  background: var(--paper);
  border-radius: 12px;
  padding: 0.8rem;
  min-width: 0;
}

.score-box .num {
  font-family: var(--font-serif);
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--seal-dark);
}

.oral-callout {
  background: var(--oral-soft);
  border-radius: 12px;
  padding: 0.75rem 0.85rem;
  color: var(--oral);
}

.sticky-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(42, 36, 28, 0.94);
  color: #f6eedf;
  z-index: 50;
  padding: 0.55rem 16px;
}

/* Practice page: dock the action bar (and mobile nav) below the scroll area
   so feedback is never covered, and students can still open 學習重點. */
html:has(body.has-sticky-bar) {
  height: 100%;
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
}
body.has-sticky-bar {
  height: 100%;
  height: 100dvh;
  max-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
body.has-sticky-bar .preview-banner,
body.has-sticky-bar .topbar {
  flex-shrink: 0;
}
body.has-sticky-bar main {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding-top: 0;
  padding-bottom: 1.5rem;
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--jump-nav-h, 5.5rem) + 0.75rem);
  scroll-padding-bottom: 1rem;
}
body.has-sticky-bar main > .wrap {
  padding-top: 1.5rem;
}
body.has-sticky-bar .site-footer {
  padding-bottom: 1.2rem;
}
body.has-sticky-bar .sticky-bar {
  position: static;
  flex-shrink: 0;
  width: 100%;
}
body.has-sticky-bar .jump-nav {
  top: 0;
  background: var(--paper);
}
body.has-sticky-bar .level-block,
body.has-sticky-bar .q-card,
body.has-sticky-bar #results {
  /* Offset comes from main's scroll-padding-top, so it is not doubled. */
  scroll-margin-top: 0;
  scroll-margin-bottom: 1rem;
}

.sticky-bar .wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: center;
  justify-content: space-between;
}

.sticky-bar .btn-accent {
  background: var(--gold);
  color: var(--ink);
  border-color: #c9a74a;
}

.sticky-bar .btn-ghost {
  color: #f6eedf;
  border-color: #e6d5b8;
  background: rgba(246, 238, 223, 0.1);
}

.sticky-bar .btn-ghost:hover {
  color: #fff;
  background: rgba(246, 238, 223, 0.2);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.site-footer {
  border-top: 1px solid var(--line);
  padding: 1.2rem 0 5.5rem;
  color: var(--ink-soft);
  font-size: 0.92rem;
}

.bottom-nav {
  display: none;
}

@media (max-width: 719px) {
  .nav-desktop {
    display: none;
  }
  .bottom-nav {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(251, 246, 236, 0.96);
    border-top: 1px solid var(--line);
    z-index: 45;
    padding: 0.15rem 0 calc(0.15rem + env(safe-area-inset-bottom));
  }
  .bottom-nav a {
    text-decoration: none;
    color: var(--ink-soft);
    text-align: center;
    font-size: 0.78rem;
    font-weight: 600;
    padding: 0.35rem 0.2rem;
    min-height: 52px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.1rem;
    min-width: 0;
  }
  .bottom-nav a[aria-current="page"] {
    color: var(--seal-dark);
  }
  body.has-sticky-bar .bottom-nav {
    display: grid;
    position: static;
    flex-shrink: 0;
    width: 100%;
  }
  main {
    padding-bottom: 7.5rem;
  }
  body.has-sticky-bar main {
    padding-bottom: 1.5rem;
  }
}

@media (min-width: 720px) {
  body.has-sticky-bar main {
    padding-bottom: 1.5rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  body.has-sticky-bar main { scroll-behavior: auto; }
}

.lesson-body h2,
.level-block,
.q-card,
#results {
  scroll-margin-top: calc(var(--header-h) + 3.5rem);
}
