/* ===========================================================
   乐理基础 · 共享样式
   Music Theory Basics — shared stylesheet (Chinese edition)
   =========================================================== */

:root {
  --bg:        #f6f4ef;
  --surface:   #ffffff;
  --ink:       #1f2430;
  --ink-soft:  #515a6b;
  --line:      #e3ddd2;
  --accent:    #6d4daa;
  --accent-2:  #b08400;
  --accent-soft:#efe9f7;
  --good:      #2f7d5b;
  --good-soft: #e6f3ec;
  --warn:      #b06a00;
  --warn-soft: #fbf0dd;
  --staff:     #2b2f38;
  --radius:    14px;
  --shadow:    0 1px 2px rgba(31,36,48,.05), 0 8px 24px rgba(31,36,48,.06);
  --maxw:      860px;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei",
               "Source Han Sans SC", "Noto Sans CJK SC", system-ui, sans-serif;
  font-size: 17px;
  line-height: 1.85;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.wrap { max-width: var(--maxw); margin: 0 auto; padding: 0 22px; }

/* ---------- 顶部条 ---------- */
.topbar {
  background: var(--ink);
  color: #f3f0ea;
  font-size: 14px;
}
.topbar .wrap {
  display: flex; align-items: center; justify-content: space-between;
  height: 52px;
}
.topbar a { color: #f3f0ea; text-decoration: none; opacity: .85; }
.topbar a:hover { opacity: 1; }
.topbar .brand { font-weight: 700; letter-spacing: .5px; opacity: 1; }
.topbar .brand span { color: #c7aef0; }

/* ---------- 课程页眉 ---------- */
.lesson-head {
  position: relative;
  overflow: hidden;
  background:
    radial-gradient(900px 320px at 12% -40%, var(--accent-soft), transparent 60%),
    linear-gradient(180deg, #fdfbf5 0%, var(--surface) 100%);
  border-bottom: 1px solid var(--line);
  padding: 64px 0 52px;
}
.lesson-head::before {
  content: "𝄞";
  position: absolute;
  top: -56px;
  right: -28px;
  font-family: "Bravura Text", "Apple Symbols", "Noto Music", serif;
  font-size: 320px;
  color: var(--accent);
  opacity: 0.06;
  line-height: 1;
  pointer-events: none;
  user-select: none;
}
.lesson-head .wrap { position: relative; z-index: 1; }
.eyebrow {
  display: inline-block;
  font-size: 12px; font-weight: 700; letter-spacing: .22em;
  color: var(--accent);
  text-transform: uppercase;
  margin: 0 0 14px;
}
.lesson-head h1 {
  margin: 0;
  font-size: 44px;
  line-height: 1.18;
  letter-spacing: .5px;
  font-weight: 700;
}
.lesson-head .en {
  margin: 10px 0 0;
  color: var(--ink-soft);
  font-size: 15px;
  font-style: italic;
}
.lesson-head .src-note {
  margin: 18px 0 0;
  font-size: 13px;
  color: var(--ink-soft);
}
.lesson-head .src-note a {
  color: var(--ink-soft);
  text-decoration: none;
  border-bottom: 1px dashed rgba(0,0,0,.18);
}
.lesson-head .src-note a:hover {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* ---------- 正文 ---------- */
main { padding: 44px 0 10px; }

section { margin: 0 0 30px; }

h2 {
  font-size: 23px;
  margin: 36px 0 14px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--accent-soft);
  display: flex; align-items: baseline; gap: 10px;
}
h2 .num {
  font-size: 14px; font-weight: 700;
  color: #fff; background: var(--accent);
  border-radius: 7px; padding: 2px 9px;
  position: relative; top: -2px;
}
h3 { font-size: 18px; margin: 24px 0 8px; color: var(--ink); }

p { margin: 12px 0; }

/* ---------- 章节（新格式：纯中文 + 图示） ---------- */
.unit {
  margin: 56px 0 0;
}
.unit:first-of-type {
  margin-top: 24px;
}
.unit > h2 {
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 24px;
  font-weight: 700;
  margin: 0 0 22px;
  padding: 0;
  border: none;
  color: var(--ink);
  letter-spacing: 0.5px;
}
.unit > h2 .num-circle {
  flex: 0 0 auto;
  width: 42px; height: 42px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent) 0%, #8b66cf 100%);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
  font-weight: 700;
  box-shadow: 0 6px 16px rgba(109, 77, 170, 0.32);
  font-family: "STKaiti", "KaiTi", "PingFang SC", serif;
}
.unit > h2::after {
  content: '';
  flex: 1;
  height: 2px;
  background: linear-gradient(to right, var(--accent-soft) 0%, transparent 100%);
  border-radius: 1px;
}
.unit > p {
  font-size: 17px;
  line-height: 1.95;
  margin: 14px 0;
  color: var(--ink);
}
.unit > p:first-of-type::first-letter {
  font-size: 1.05em;
}

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

strong, b { color: var(--ink); }
.term {
  color: var(--ink);
  font-weight: 700;
  background: linear-gradient(180deg, transparent 62%, rgba(109, 77, 170, 0.18) 62%, rgba(109, 77, 170, 0.18) 94%, transparent 94%);
  padding: 0 3px;
  margin: 0 -1px;
  border-radius: 2px;
}
.en-inline { color: var(--ink-soft); font-style: italic; font-size: .92em; }

ul, ol { padding-left: 1.3em; }
li { margin: 6px 0; }

/* ---------- 卡片 / 提示框 ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px 24px;
  margin: 18px 0;
}

.callout {
  border-radius: var(--radius);
  padding: 16px 20px;
  margin: 18px 0;
  border: 1px solid transparent;
  font-size: 16px;
}
.callout .lab {
  display: inline-block; font-weight: 700; margin-right: 8px;
}
.callout.tip   { background: var(--accent-soft); border-color: #ddd0f0; }
.callout.tip   .lab { color: var(--accent); }
.callout.note  { background: var(--good-soft);  border-color: #cfe7da; }
.callout.note  .lab { color: var(--good); }
.callout.warn  { background: var(--warn-soft);  border-color: #f0dcb6; }
.callout.warn  .lab { color: var(--warn); }

/* ---------- 表格 ---------- */
table {
  width: 100%;
  border-collapse: collapse;
  margin: 18px 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  font-size: 16px;
}
th, td { padding: 11px 14px; text-align: left; border-bottom: 1px solid var(--line); }
th { background: var(--accent-soft); color: var(--ink); font-weight: 700; }
tr:last-child td { border-bottom: none; }
td.glyph, th.glyph { font-size: 26px; text-align: center; line-height: 1; }
.musym { font-family: "Bravura Text", "Noto Music", "Apple Symbols", "Segoe UI Symbol", serif; }

/* ---------- 图示 ---------- */
figure {
  position: relative;
  margin: 36px 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 30px 24px 22px;
  text-align: center;
}
figure[data-num]::before {
  content: "图 " attr(data-num);
  position: absolute;
  top: -12px;
  left: 24px;
  background: linear-gradient(135deg, var(--accent) 0%, #8b66cf 100%);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.5px;
  padding: 5px 14px;
  border-radius: 999px;
  box-shadow: 0 4px 12px rgba(109, 77, 170, 0.35);
}
figure svg { max-width: 100%; height: auto; }
figcaption {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px dashed var(--line);
  color: var(--ink-soft);
  font-size: 13.5px;
  line-height: 1.6;
}

/* staff svg helpers */
.staff-line { stroke: var(--staff); stroke-width: 1.4; }
.ledger     { stroke: var(--staff); stroke-width: 1.4; }
.notehead   { fill: var(--staff); }
.bar        { stroke: var(--staff); stroke-width: 1.6; }
.clef       { font-family: "Bravura Text","Noto Music","Apple Symbols","Segoe UI Symbol", serif; fill: var(--staff); }
.lbl        { font-family: inherit; fill: var(--accent); font-weight: 700; font-size: 15px; }
.lbl-soft   { font-family: inherit; fill: var(--ink-soft); font-size: 13px; }

/* ---------- 上一课 / 下一课 ---------- */
.pager {
  display: flex; gap: 16px; flex-wrap: wrap;
  margin: 56px 0 60px;
  padding-top: 32px;
  border-top: 1px solid var(--line);
}
.pager a {
  flex: 1 1 0; min-width: 200px;
  display: block; text-decoration: none;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 20px;
  box-shadow: var(--shadow);
  transition: transform .15s ease, border-color .15s ease, box-shadow .15s ease;
}
.pager a:hover {
  transform: translateY(-3px);
  border-color: var(--accent);
  box-shadow: 0 8px 28px rgba(109, 77, 170, 0.15);
}
.pager a.next { text-align: right; }
.pager .dir {
  font-size: 12px; color: var(--ink-soft);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  font-weight: 600;
}
.pager .ttl { font-weight: 700; color: var(--ink); margin-top: 4px; font-size: 16px; }
.pager a.disabled { opacity: .4; pointer-events: none; }

footer {
  border-top: 1px solid var(--line);
  color: var(--ink-soft);
  font-size: 13px;
  text-align: center;
  padding: 26px 0 40px;
}

/* ===========================================================
   目录页
   =========================================================== */
.hero {
  background:
    radial-gradient(800px 320px at 80% -30%, var(--accent-soft), transparent 60%),
    radial-gradient(600px 260px at 0% 120%, var(--warn-soft), transparent 60%),
    var(--surface);
  border-bottom: 1px solid var(--line);
  padding: 56px 0 46px;
  text-align: center;
}
.hero h1 { font-size: 40px; margin: 0 0 10px; letter-spacing: 1px; }
.hero p  { margin: 0 auto; max-width: 560px; color: var(--ink-soft); }
.hero .src { font-size: 13px; margin-top: 18px; }

.cat { margin: 38px 0 8px; }
.cat h2 {
  border: none; padding: 0; font-size: 15px; letter-spacing: .14em;
  text-transform: uppercase; color: var(--accent-2);
}
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
  margin: 16px 0 8px;
}
.tile {
  display: block; text-decoration: none; color: inherit;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
  transition: transform .12s ease, border-color .12s ease;
}
.tile:hover { transform: translateY(-3px); border-color: var(--accent); }
.tile .no {
  font-size: 12px; font-weight: 700; color: var(--accent);
  letter-spacing: .1em;
}
.tile .zh { font-size: 19px; font-weight: 700; margin: 4px 0 2px; }
.tile .en { font-size: 13px; color: var(--ink-soft); font-style: italic; }

/* ===========================================================
   双语对照（原文逐句翻译版）
   =========================================================== */
.bi { list-style: none; padding: 0; margin: 20px 0; }
.bi > li {
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: 10px;
  padding: 12px 18px;
  margin: 10px 0;
  box-shadow: 0 1px 1px rgba(31,36,48,.03);
}
.bi .en-line {
  display: block;
  color: var(--ink-soft);
  font-style: italic;
  font-size: 15px;
  line-height: 1.55;
  margin-bottom: 4px;
}
.bi .zh-line {
  display: block;
  color: var(--ink);
  font-size: 17px;
  line-height: 1.7;
}
.bi h3.group {
  margin: 26px 0 6px;
  color: var(--accent);
  font-size: 13px;
  letter-spacing: .14em;
  text-transform: uppercase;
  border: none;
  padding: 0;
}
.src-note {
  font-size: 13px; color: var(--ink-soft);
  margin: 6px 0 0;
}

/* ===========================================================
   作业 / 考试 / 答案
   =========================================================== */
.hw-meta { display: flex; flex-wrap: wrap; gap: 10px; margin: 18px 0 0; }
.hw-meta span, .hw-meta a {
  font-size: 13px; background: var(--accent-soft); color: var(--accent);
  border-radius: 999px; padding: 4px 12px; font-weight: 700; text-decoration: none;
}
.hw-meta a:hover { background: var(--accent); color: #fff; }

.name-line {
  display: flex; gap: 28px; flex-wrap: wrap;
  margin: 8px 0 26px; font-size: 16px; color: var(--ink-soft);
}
.name-line span { flex: 1 1 200px; border-bottom: 1px solid var(--ink-soft); padding-bottom: 4px; }

.sec-head { display: flex; align-items: center; gap: 16px; }
.sec-head .sec-pts { margin-left: auto; font-size: 14px; font-weight: 400; color: var(--ink-soft); }

ol.qs { list-style: none; padding: 0; margin: 0; }
ol.qs > li.q {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 22px 18px 66px;
  margin: 14px 0;
  box-shadow: 0 1px 1px rgba(31,36,48,.03);
}
.q .qn {
  position: absolute; left: 18px; top: 18px;
  width: 32px; height: 32px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent) 0%, #8b66cf 100%);
  color: #fff; font-weight: 700; font-size: 14px;
  display: flex; align-items: center; justify-content: center;
}
.q.has-pts { padding-right: 62px; }
.q .pts { float: right; margin: 0 0 4px 14px; font-size: 12px; color: var(--ink-soft); }
.q p { margin: 0 0 8px; }
.q p:last-child { margin-bottom: 0; }
.opts {
  list-style: none; padding: 0; margin: 8px 0 0;
  display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 6px 18px;
}
.opts li { margin: 0; }
.opts .ol {
  display: inline-block; width: 22px; height: 22px; line-height: 20px; text-align: center;
  border: 1.5px solid var(--line); border-radius: 50%;
  font-size: 12px; font-weight: 700; margin-right: 8px; color: var(--accent);
}
ol.sub {
  list-style: none; padding: 0; margin: 6px 0 0;
  display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 4px 18px;
}
ol.sub.one { grid-template-columns: 1fr; }
ol.sub li { margin: 0; }
ol.sub .sn { color: var(--accent); font-weight: 700; margin-right: 6px; }
.blank { display: inline-block; min-width: 64px; border-bottom: 1.5px solid var(--ink); margin: 0 3px; }
.blank.w { min-width: 140px; }
.tf-mark { display: inline-block; width: 2.2em; border-bottom: 1.5px solid var(--ink); margin-right: 8px; }
.fig-scroll { overflow-x: auto; max-width: 100%; }
.fig-scroll svg { width: 100%; min-width: var(--fw, auto); }
.q figure { margin: 14px 0 6px; padding: 18px 12px 12px; box-shadow: none; }
.q figure figcaption { font-size: 13px; }
.q table { margin: 10px 0 0; font-size: 15px; }
.q th, .q td { padding: 7px 12px; }
.q td.fill { min-width: 90px; }

/* 课程页底部的作业入口 */
.hw-link {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  background: linear-gradient(135deg, var(--accent-soft) 0%, #fdfbf5 100%);
  border: 1px solid #ddd0f0; border-radius: var(--radius);
  padding: 16px 20px; margin: 40px 0 0;
  text-decoration: none; color: inherit;
  transition: transform .15s ease, border-color .15s ease;
}
.hw-link:hover { transform: translateY(-2px); border-color: var(--accent); }
.hw-link .lab { font-size: 12px; letter-spacing: .14em; font-weight: 700; color: var(--accent); }
.hw-link .ttl { font-weight: 700; font-size: 17px; margin-top: 2px; }
.hw-link .go { color: var(--accent); font-weight: 700; white-space: nowrap; }

/* 答案页 */
.key table td:first-child { width: 64px; font-weight: 700; color: var(--accent); white-space: nowrap; }
.key .sub-ans { display: inline-block; margin-right: 14px; }
.key .sub-ans .sn { color: var(--accent); font-weight: 700; margin-right: 3px; }
.key .why { color: var(--ink-soft); font-size: 14px; }
.key figure { margin: 10px 0 4px; padding: 16px 12px 10px; box-shadow: none; }

/* 课程页底部：本课作业 / 单元考试 */
.lesson-hw { margin: 44px 0 0; }
.hw-link + .hw-link { margin-top: 12px; }
.hw-link.exam {
  background: linear-gradient(135deg, var(--warn-soft) 0%, #fdfbf5 100%);
  border-color: #f0dcb6;
}
.hw-link.exam .lab { color: var(--accent-2); }
.hw-link.exam:hover { border-color: var(--accent-2); }
.hw-link.exam .go { color: var(--accent-2); }
.hw-sub {
  margin: 8px 2px 0;
  font-size: 13.5px;
  color: var(--ink-soft);
}
.hw-sub a { color: var(--accent); text-decoration: none; font-weight: 700; }
.hw-sub a:hover { text-decoration: underline; }
.hw-sub .sep { opacity: .45; margin: 0 8px; }

@media print {
  @page { size: A4; margin: 14mm 12mm 12mm; }

  .topbar, .pager, footer, .hw-actions, .hw-link, .lesson-head::before,
  .print-hide { display: none !important; }

  body { background: #fff; font-size: 12.5px; line-height: 1.62; }
  a { color: var(--ink); text-decoration: none; }

  .lesson-head { padding: 0 0 10px; background: none; border-bottom: 1.5px solid var(--accent); }
  .lesson-head h1 { font-size: 22px; }
  .lesson-head .en { font-size: 12px; margin-top: 4px; }
  .eyebrow { margin-bottom: 6px; font-size: 11px; }
  .hw-meta { gap: 6px; margin-top: 10px; }
  .hw-meta span, .hw-meta a { background: none; padding: 0; color: var(--ink-soft); font-weight: 400; font-size: 11.5px; }
  .hw-meta span::after { content: " ·"; }
  .hw-meta span:last-child::after { content: ""; }

  main { padding-top: 12px; }
  .wrap { max-width: 100%; padding: 0; }

  .name-line { margin: 10px 0 16px; font-size: 12.5px; }
  .unit { margin-top: 20px; break-inside: auto; }
  .unit > h2 { break-after: avoid; font-size: 18px; margin-bottom: 10px; }
  .unit > h2 .num-circle {
    width: 26px; height: 26px; font-size: 13px;
    background: var(--accent) !important; box-shadow: none !important;
  }
  .sec-head .sec-pts, .unit > h2 .sec-pts { font-size: 11.5px; }

  ol.qs > li.q {
    break-inside: avoid; box-shadow: none; background: none;
    border: none; border-left: 2px solid var(--line);
    border-radius: 0; padding: 4px 0 4px 46px; margin: 12px 0;
  }
  .q .qn {
    width: 24px; height: 24px; font-size: 12px; top: 4px; left: 10px;
    background: var(--accent) !important; box-shadow: none;
  }
  .q .pts { font-size: 11px; margin-left: 10px; }
  .opts { grid-template-columns: repeat(2, 1fr); gap: 2px 16px; }
  ol.sub { gap: 2px 16px; }

  .q figure, .key figure { break-inside: avoid; border: 1px solid var(--line); box-shadow: none; padding: 14px 8px 8px; margin: 10px 0 4px; }
  figure[data-num]::before { display: none; }
  .fig-scroll { overflow: visible; }
  .fig-scroll svg { min-width: 0; }

  .callout { break-inside: avoid; background: none !important; border: 1px solid var(--line); padding: 10px 14px; font-size: 12px; }
  table { break-inside: auto; font-size: 12px; box-shadow: none; }
  tr { break-inside: avoid; }
  th { background: #f0ebf8 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }

  /* 分页控制 */
  .page-break { break-before: page; }
  .print-doc + .print-doc { break-before: page; }
}

@media (max-width: 540px) {
  body { font-size: 16px; }
  .lesson-head h1 { font-size: 26px; }
  .hero h1 { font-size: 30px; }
  ol.qs > li.q { padding-left: 58px; }
  .q .qn { left: 14px; }
}
