/* 史前至夏商周 —— 中一學習預覽樣式（2026-11-23 閱讀優化） */

:root {
  --bg: #f3f0ea;
  --bg-muted: #e8e3d8;
  --surface: #fffcf7;
  --surface-soft: #f7f3ec;
  --text: #1c1917;
  --text-muted: #57534e;
  --border: #e4ddd0;
  --border-strong: #cfc6b6;
  --accent: #0f766e;
  --accent-hover: #0d5e58;
  --accent-soft: #e7f5f3;
  --accent-text: #115e59;
  --focus: #0f766e;
  --shadow: 0 1px 2px rgba(28, 25, 23, 0.05), 0 18px 40px -24px rgba(28, 25, 23, 0.28);
  --radius: 1.15rem;
  --radius-sm: 0.75rem;
  --header-h: 4.75rem;
  --read-width: 44rem;
  --font: "Noto Sans TC", "Source Han Sans TC", "PingFang TC", "Microsoft JhengHei", "Noto Sans CJK TC", sans-serif;
  --ok: #146c36;
  --ok-soft: #e8f7ec;
  --err: #b42318;
  --err-soft: #fdecea;
  --warn: #7a5200;
  --warn-soft: #fff6d8;
  --tag-required-bg: #e7f5f3;
  --tag-required-fg: #115e59;
  --tag-required-bd: #99d4cd;
  --tag-adapted-bg: #fff6d8;
  --tag-adapted-fg: #7d4e00;
  --tag-adapted-bd: #e8c36a;
  --tag-resource-bg: #f3eaff;
  --tag-resource-fg: #6d28d9;
  --tag-resource-bd: #d4b4ff;
  --tag-example-bg: #e8f7ec;
  --tag-example-fg: #166534;
  --tag-example-bd: #86d39a;
  --tag-missing-bg: #fdecea;
  --tag-missing-fg: #9f1239;
  --tag-missing-bd: #f5b5b0;
  --space-page-x: 1.15rem;
  --space-card: 1.25rem;
}

html[data-theme="dark"] {
  --bg: #10141a;
  --bg-muted: #0b0e13;
  --surface: #171d25;
  --surface-soft: #1d242d;
  --text: #eef2f6;
  --text-muted: #9aa3ad;
  --border: #2b3340;
  --border-strong: #3c4654;
  --accent: #5eead4;
  --accent-hover: #99f6e4;
  --accent-soft: #13332f;
  --accent-text: #99f6e4;
  --focus: #5eead4;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 18px 40px -20px rgba(0, 0, 0, 0.55);
  --ok: #4ade80;
  --ok-soft: #13281c;
  --err: #fb7185;
  --err-soft: #2a1418;
  --warn: #fbbf24;
  --warn-soft: #2a210c;
  --tag-required-bg: #13332f;
  --tag-required-fg: #99f6e4;
  --tag-required-bd: #0f766e;
  --tag-adapted-bg: #2a210c;
  --tag-adapted-fg: #fbbf24;
  --tag-adapted-bd: #9a6700;
  --tag-resource-bg: #26143a;
  --tag-resource-fg: #d8b4fe;
  --tag-resource-bd: #7e22ce;
  --tag-example-bg: #13281c;
  --tag-example-fg: #86efac;
  --tag-example-bd: #166534;
  --tag-missing-bg: #2a1418;
  --tag-missing-fg: #fb7185;
  --tag-missing-bd: #9f1239;
}

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

html {
  scroll-behavior: smooth;
  color-scheme: light;
  overflow-x: clip;
  scroll-padding-top: 0;
}

html[data-theme="dark"] { color-scheme: dark; }

body {
  margin: 0;
  font-family: var(--font);
  /* Mobile first：中一同學在手機上用 19px 正文，不在窄螢幕縮小 */
  font-size: 1.1875rem;
  line-height: 1.85;
  color: var(--text);
  background:
    radial-gradient(1200px 420px at 10% -10%, color-mix(in srgb, var(--accent-soft) 80%, transparent), transparent 60%),
    var(--bg);
  min-height: 100vh;
  overflow-x: clip;
}

img { max-width: 100%; height: auto; }

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

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

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.skip-link {
  position: absolute;
  left: 0.75rem;
  top: -4rem;
  z-index: 1000;
  background: var(--accent);
  color: #fff;
  padding: 0.5rem 0.9rem;
  border-radius: var(--radius-sm);
  text-decoration: none;
  font-weight: 600;
}

.skip-link:focus { top: 0.75rem; color: #fff; }

html[data-theme="dark"] .skip-link,
html[data-theme="dark"] .skip-link:focus {
  color: #042f2e;
}

/* Header：手機維持文件流（不 sticky），避免捲動時蓋住正文 */
.site-header {
  position: static;
  z-index: 200;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.65rem 1rem;
  max-width: 76rem;
  margin: 0 auto;
  padding: 0.7rem var(--space-page-x);
  min-width: 0;
}

.site-brand {
  display: flex;
  flex-direction: column;
  text-decoration: none;
  color: var(--text);
  min-width: 0;
  flex: 1 1 auto;
}

.site-brand:hover { color: var(--text); }

.site-title {
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: 0.01em;
  line-height: 1.3;
}

.site-tagline {
  font-size: 0.8125rem;
  color: var(--text-muted);
  line-height: 1.45;
  font-weight: 400;
}

.nav-toggle,
.btn.nav-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-left: auto;
  min-height: 2.75rem;
  min-width: 2.75rem;
}

.site-nav {
  display: none;
  flex-basis: 100%;
  flex-direction: column;
  align-items: stretch;
  gap: 0.25rem;
  padding: 0.35rem 0 0.55rem;
}

.site-header.is-open .site-nav { display: flex; }

.site-nav a {
  display: inline-flex;
  align-items: center;
  min-height: 2.75rem;
  padding: 0.35rem 0.9rem;
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: var(--text);
  font-size: 1rem;
  font-weight: 600;
}

.site-nav a:hover {
  background: var(--bg-muted);
  color: var(--text);
}

.site-nav a[aria-current="page"] {
  background: var(--accent);
  color: #fff;
  font-weight: 700;
}

html[data-theme="dark"] .site-nav a[aria-current="page"] {
  color: #042f2e;
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  width: 100%;
  margin-left: 0;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.75rem;
  padding: 0.4rem 1rem;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}

.btn:hover {
  background: var(--bg-muted);
  color: var(--text);
}

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

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

html[data-theme="dark"] .btn-primary,
html[data-theme="dark"] .btn-primary:hover {
  color: #042f2e;
}

/* Main */
.site-main {
  max-width: var(--read-width);
  margin: 0 auto;
  padding: 1.5rem var(--space-page-x) 3.5rem;
  min-width: 0;
}

.site-main--wide { max-width: 50rem; }

.hero,
.card,
.notice,
.panel,
.maps-cta {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: var(--space-card);
  margin: 0 0 1.35rem;
}

.hero {
  padding: 1.5rem var(--space-card) 1.45rem;
  background:
    linear-gradient(165deg, color-mix(in srgb, var(--accent-soft) 88%, var(--surface)) 0%, var(--surface) 68%);
}

.kicker {
  display: inline-block;
  font-size: 0.8125rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--accent-text);
  margin: 0 0 0.55rem;
}

h1, h2, h3, h4 {
  line-height: 1.35;
  font-weight: 700;
  margin: 0 0 0.85rem;
  color: var(--text);
  letter-spacing: 0;
  text-wrap: pretty;
}

/* 窄螢幕標題仍明顯大於正文，只作輕微收斂 */
h1 { font-size: 1.875rem; line-height: 1.28; }
h2 { font-size: 1.4375rem; margin-top: 2.15rem; }
h3 { font-size: 1.25rem; margin-top: 1.75rem; }
h4 { font-size: 1.125rem; margin-top: 1.4rem; font-weight: 650; }

.hero h1, .hero h2, .card > h2:first-child { margin-top: 0; }

.notes-body > h1 { margin-top: 0; }

/* 筆記以 h3 作小節標題（原稿結構），視覺上要分明 */
.notes-body > h3 {
  font-size: 1.3125rem;
  margin-top: 2.15rem;
  padding-top: 0.15rem;
}

.lead {
  font-size: 1.2rem;
  line-height: 1.75;
  color: var(--text);
  margin: 0 0 0.85rem;
}

.muted, .meta {
  color: var(--text-muted);
  font-size: 1.0625rem;
}

.student-lead {
  color: var(--text);
  font-size: 1.125rem;
  line-height: 1.8;
  margin: 0 0 1.35rem;
  padding: 1rem 1.1rem;
  background: var(--accent-soft);
  border-radius: var(--radius-sm);
  border-left: 4px solid var(--accent);
}

p, ul, ol, table { margin: 0 0 1.15rem; }
ul, ol { padding-left: 1.35rem; }
li + li { margin-top: 0.4rem; }

.site-main,
.notes-body,
.card,
.hero,
.notice,
li, p, td, th, a, h1, h2, h3, h4 {
  overflow-wrap: anywhere;
  word-break: break-word;
}

/* Tags */
.tag,
.tag-row .tag {
  display: inline-block;
  font-size: 0.875rem;
  font-weight: 700;
  line-height: 1.45;
  padding: 0.22rem 0.65rem;
  border-radius: 999px;
  border: 1px solid;
  margin: 0 0.25rem 0.3rem 0;
  vertical-align: middle;
  max-width: 100%;
  white-space: normal;
}

.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin: 0 0 0.95rem;
}

.tag-required { background: var(--tag-required-bg); color: var(--tag-required-fg); border-color: var(--tag-required-bd); }
.tag-adapted { background: var(--tag-adapted-bg); color: var(--tag-adapted-fg); border-color: var(--tag-adapted-bd); }
.tag-resource { background: var(--tag-resource-bg); color: var(--tag-resource-fg); border-color: var(--tag-resource-bd); }
.tag-example { background: var(--tag-example-bg); color: var(--tag-example-fg); border-color: var(--tag-example-bd); }
.tag-missing { background: var(--tag-missing-bg); color: var(--tag-missing-fg); border-color: var(--tag-missing-bd); }
.tag-extension { background: var(--warn-soft); color: var(--warn); border-color: var(--warn); }

.table-wrap {
  overflow-x: auto;
  max-width: 100%;
  margin: 0 0 1.25rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 1.0625rem;
  margin: 0;
}

th, td {
  text-align: left;
  padding: 0.8rem 0.95rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

th { background: var(--bg-muted); font-weight: 650; }
tr:last-child th, tr:last-child td { border-bottom: 0; }

/* 窄螢幕：所有表格改為卡片式直排，避免欄位被擠扁或出現橫向捲動 */
.table-wrap table,
.table-wrap thead,
.table-wrap tbody,
.table-wrap tr,
.table-wrap th,
.table-wrap td {
  display: block;
  width: 100%;
}

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

.table-wrap tr {
  border-bottom: 1px solid var(--border);
  padding: 0.95rem 1rem 1.05rem;
}

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

.table-wrap td,
.table-wrap th {
  border-bottom: 0;
  padding: 0.2rem 0;
}

.table-wrap td:first-child,
.table-wrap th:first-child {
  padding-top: 0;
  font-weight: 650;
}

.table-wrap td[data-label]::before {
  content: attr(data-label);
  display: block;
  font-size: 0.8125rem;
  font-weight: 700;
  color: var(--text-muted);
  margin: 0.55rem 0 0.15rem;
  line-height: 1.4;
}

.table-wrap td[data-label=""]::before { content: none; margin: 0; }

.notice-missing { border-color: var(--tag-missing-bd); background: var(--tag-missing-bg); }
.notice-extension { border-color: color-mix(in srgb, var(--warn) 45%, var(--border)); background: var(--warn-soft); }

.emm-note {
  display: block;
  font-size: 0.9375rem;
  color: var(--text-muted);
  margin: 0.2rem 0 0.45rem;
}

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

.nav-card {
  display: block;
  text-decoration: none;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.2rem 1.25rem 1.25rem;
  transition: transform 0.15s ease, border-color 0.15s ease;
}

.nav-card:hover {
  border-color: var(--accent);
  color: var(--text);
  transform: translateY(-2px);
}

.nav-card h2, .nav-card h3 {
  margin: 0.2rem 0 0.5rem;
  font-size: 1.2rem;
  line-height: 1.4;
}

.nav-card p:last-child { margin-bottom: 0; }

.pager {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin: 1.6rem 0 0;
}

.pager .btn { flex: 1 1 12rem; }

.practice-cta { margin: 1.5rem 0 0.4rem; }

/* Practice */
.practice-group { margin: 0 0 0.5rem; }

.q-block {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem 1.2rem 1.35rem;
  margin: 0 0 1.2rem;
}

.q-head {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 0.7rem;
  align-items: baseline;
  margin-bottom: 0.8rem;
}

.q-num {
  margin: 0;
  font-size: 1.1875rem;
}

.q-stem {
  margin: 0 0 0.95rem;
  font-weight: 550;
}

.option-list {
  list-style: none;
  padding: 0;
  margin: 0 0 0.4rem;
}

.option-list li + li { margin-top: 0.5rem; }

.option-list label,
.tf-options label {
  display: flex;
  gap: 0.7rem;
  align-items: flex-start;
  padding: 0.85rem 0.95rem;
  min-height: 2.85rem;
  cursor: pointer;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 0.9rem;
}

.option-list label:hover,
.tf-options label:hover { border-color: var(--accent); }

.option-list input,
.tf-options input {
  margin-top: 0.35rem;
  width: 1.2rem;
  height: 1.2rem;
  flex: 0 0 auto;
}

.tf-options {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.55rem;
  margin: 0 0 0.7rem;
  padding: 0;
}

.fill-line {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.4rem;
  margin: 0 0 0.9rem;
  line-height: 2;
}

.fill-line input,
input[type="text"],
input[type="file"],
textarea {
  font-family: inherit;
  font-size: 1.0625rem;
  line-height: 1.5;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 0.8rem;
  padding: 0.55rem 0.75rem;
  max-width: 100%;
}

.fill-line input,
input[type="text"] {
  min-height: 2.75rem;
  min-width: 7.5rem;
  width: 100%;
}

textarea {
  width: 100%;
  min-height: 8.5rem;
  resize: vertical;
}

.correction-field label,
.sa-field label {
  display: block;
  font-weight: 600;
  margin: 0.25rem 0 0.4rem;
}

.practice-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.7rem;
  padding: 1.2rem 0 0.6rem;
  margin-top: 0.6rem;
  /* 不要 sticky，以免擋住選項或誤觸提交 */
}

.practice-actions .btn { min-width: 10rem; }

#results { margin: 0 0 1.5rem; }

.review-summary {
  background: var(--accent-soft);
  border: 1px solid color-mix(in srgb, var(--accent) 35%, var(--border));
}

.feedback {
  margin-top: 0.95rem;
  padding: 1rem 1.05rem;
  border-radius: var(--radius-sm);
  background: var(--bg-muted);
  font-size: 1.0625rem;
}

.feedback.ok { background: var(--ok-soft); }
.feedback.bad { background: var(--err-soft); }
.feedback.mixed { background: var(--warn-soft); }

.feedback[hidden],
#results[hidden],
.hidden { display: none !important; }

.ref-note {
  font-size: 1rem;
  color: var(--text-muted);
  border-left: 3px solid var(--accent);
  padding-left: 0.8rem;
}

body.hide-extension .extension-only { display: none !important; }

.extension-hidden-banner {
  display: none;
  background: var(--warn-soft);
  border: 1px solid var(--warn);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  margin: 0 0 1.25rem;
}

body.hide-extension .extension-hidden-banner { display: block; }

.map-grid {
  display: grid;
  gap: 1rem;
}

.map-card {
  margin: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  padding: 0 0 1rem;
}

.map-card img {
  display: block;
  width: 100%;
  max-height: 28rem;
  object-fit: contain;
  background: var(--bg-muted);
}

.map-card figcaption {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  padding: 0.9rem 1rem 0.45rem;
}

.map-card .btn { margin: 0 1rem; }

#map-status.is-error { color: var(--err); }

.site-footer {
  border-top: 1px solid var(--border);
  padding: 1.6rem var(--space-page-x) 2.4rem;
  color: var(--text-muted);
  font-size: 0.9375rem;
  line-height: 1.7;
  text-align: center;
  max-width: 48rem;
  margin: 0 auto;
}

/* 較寬螢幕：導航橫列、表格恢復欄位、標題略放大；正文維持同樣字級 */
@media (min-width: 641px) {
  .table-wrap table {
    display: table;
    width: 100%;
  }

  .table-wrap thead {
    position: static;
    display: table-header-group;
    width: auto;
    height: auto;
    margin: 0;
    overflow: visible;
    clip: auto;
    border: 0;
  }

  .table-wrap tbody { display: table-row-group; }

  .table-wrap tr {
    display: table-row;
    padding: 0;
    border-bottom: 0;
  }

  .table-wrap th,
  .table-wrap td {
    display: table-cell;
    width: auto;
    padding: 0.8rem 0.95rem;
    border-bottom: 1px solid var(--border);
    font-weight: inherit;
  }

  .table-wrap th { font-weight: 650; }

  .table-wrap td:first-child,
  .table-wrap th:first-child { padding-top: 0.8rem; font-weight: inherit; }

  .table-wrap th:first-child { font-weight: 650; }

  .table-wrap tr:last-child th,
  .table-wrap tr:last-child td { border-bottom: 0; }

  .table-wrap td[data-label]::before { display: none; }

  .tf-options { grid-template-columns: 1fr 1fr; }

  .fill-line input,
  input[type="text"] { width: 10rem; }
}

@media (min-width: 801px) {
  html { scroll-padding-top: var(--header-h); }

  .site-header {
    position: sticky;
    top: 0;
  }

  body { font-size: 1.1875rem; }

  h1 { font-size: 2.125rem; }
  h2 { font-size: 1.5rem; }
  h3 { font-size: 1.275rem; }
  .notes-body > h3 { font-size: 1.375rem; }


  .nav-toggle,
  .btn.nav-toggle { display: none; }

  .site-nav,
  .site-header.is-open .site-nav {
    display: flex;
    flex-basis: auto;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.2rem;
    padding: 0;
  }

  .site-nav a {
    min-height: 2.5rem;
    padding: 0.2rem 0.8rem;
    border-radius: 999px;
    font-size: 0.98rem;
  }

  .header-inner {
    padding: 0.85rem 1.35rem;
    gap: 0.75rem 1.1rem;
  }

  .header-actions {
    width: auto;
    margin-left: auto;
  }

  .site-title { font-size: 1.12rem; }

  .site-main {
    padding: 2.25rem 1.35rem 4rem;
  }

  .hero,
  .card,
  .notice,
  .panel,
  .maps-cta {
    padding: 1.55rem 1.55rem 1.6rem;
  }

  .hero { padding: 1.9rem 1.65rem 1.75rem; }

  .btn { min-height: 2.5rem; }

  .card-grid.topics,
  .map-grid { grid-template-columns: 1fr 1fr; }

  .q-block { padding: 1.35rem 1.4rem 1.4rem; }
}

@media (max-width: 640px) {
  .site-tagline { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .nav-card { transition: none; }
}
