/* 小新學樂理 全站樣式。
   改動本檔後記得 bump src/views.ts 的 ASSET_VER（本檔以 ?v= 版本化長快取）。 */

:root,
:root[data-theme="light"] {
  --bg: #fcfbfd;
  --surface: #ffffff;
  --text: #22202c;
  --muted: #63606f;
  --border: #e3e0ea;
  --accent: #6244b8;
  --accent-soft: #f0ebfb;
  --code-bg: #f4f2f8;
  --shadow: 0 1px 2px rgb(34 32 44 / 6%), 0 4px 12px rgb(34 32 44 / 4%);
}

:root[data-theme="dark"] {
  --bg: #141320;
  --surface: #1c1a2b;
  --text: #e6e4f0;
  --muted: #a19dae;
  --border: #2e2b40;
  --accent: #a992f0;
  --accent-soft: #251f3c;
  --code-bg: #232035;
  --shadow: none;
}

* {
  box-sizing: border-box;
}

/* 顯式 display（flex 等）會蓋掉 UA 對 [hidden] 的 display:none，全域補回。
   少了這條，朗讀列與吸底播放列的顯示／隱藏狀態機會整組失效。 */
[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Helvetica Neue", -apple-system, BlinkMacSystemFont, "Segoe UI",
    "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  line-height: 1.75;
  -webkit-text-size-adjust: 100%;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.container {
  width: min(100% - 2.5rem, 52rem);
  margin-inline: auto;
}

/* 頁首 */
.site-header {
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 10;
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.9rem 0;
  flex-wrap: wrap;
}

.site-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0.02em;
}

.site-title:hover {
  text-decoration: none;
  color: var(--accent);
}

.site-nav {
  display: flex;
  align-items: center;
  gap: 1.1rem;
  font-size: 0.94rem;
}

.site-nav a {
  color: var(--muted);
}

.site-nav a:hover,
.site-nav a.active {
  color: var(--accent);
  text-decoration: none;
}

.site-nav a.active {
  font-weight: 600;
}

.theme-toggle {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  border-radius: 999px;
  width: 2rem;
  height: 2rem;
  line-height: 1;
  cursor: pointer;
  font-size: 0.9rem;
}

.theme-toggle:hover {
  color: var(--accent);
  border-color: var(--accent);
}

/* 內容區 */
.content {
  padding: 2.5rem 0 4rem;
}

h1 {
  font-size: 1.9rem;
  line-height: 1.4;
  margin: 0 0 0.75rem;
  letter-spacing: -0.01em;
}

h2 {
  font-size: 1.3rem;
  margin: 2.25rem 0 0.75rem;
  letter-spacing: -0.005em;
}

h3 {
  font-size: 1.08rem;
  margin: 1.75rem 0 0.5rem;
}

.page-lead {
  color: var(--muted);
  margin: 0 0 0.5rem;
}

.page-note {
  color: var(--muted);
  font-size: 0.92rem;
  margin: 0 0 2rem;
  padding-left: 0.8rem;
  border-left: 2px solid var(--border);
}

/* 首頁 hero */
.hero {
  margin-bottom: 3rem;
}

.hero h1 {
  font-size: 2.15rem;
}

.hero p {
  color: var(--muted);
  max-width: 42rem;
}

.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-top: 1.5rem;
}

.btn {
  display: inline-block;
  padding: 0.5rem 1.1rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.94rem;
  color: var(--text);
  background: var(--surface);
}

.btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  text-decoration: none;
}

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

.btn-primary:hover {
  color: #fff;
  opacity: 0.9;
}

/* 文章列表 */
.article-group h2 {
  padding-bottom: 0.4rem;
  border-bottom: 1px solid var(--border);
}

.article-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.article-list li {
  padding: 1rem 0;
  border-bottom: 1px solid var(--border);
}

.article-list li:last-child {
  border-bottom: none;
}

.article-list a {
  font-size: 1.05rem;
  font-weight: 600;
}

.article-list p {
  margin: 0.3rem 0 0;
  color: var(--muted);
  font-size: 0.94rem;
}

.skill-badge {
  display: inline-block;
  margin-left: 0.5rem;
  padding: 0.05rem 0.45rem;
  border-radius: 4px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.75rem;
  font-weight: 600;
  vertical-align: 0.1em;
}

/* 文章頁 */
.article-head {
  padding-bottom: 1.25rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1.75rem;
}

.article-category {
  margin: 0 0 0.35rem;
  color: var(--accent);
  font-size: 0.85rem;
  font-weight: 600;
}

.article-meta {
  margin: 0.5rem 0 0;
  color: var(--muted);
  font-size: 0.87rem;
}

.article-meta .dot {
  margin: 0 0.15rem;
}

/* 前置需求提示 */
.prereq {
  background: var(--accent-soft);
  border-radius: 10px;
  padding: 1rem 1.25rem;
  margin-bottom: 2rem;
}

.prereq-title {
  margin: 0 0 0.4rem;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--accent);
}

.prereq ul {
  margin: 0;
  padding-left: 1.1rem;
  font-size: 0.92rem;
}

.prereq li {
  margin: 0.15rem 0;
}

.prereq-todo {
  color: var(--muted);
}

.prereq-todo em {
  font-style: normal;
  font-size: 0.85em;
}

/* 文章內文 */
.prose > :first-child {
  margin-top: 0;
}

.prose p,
.prose li {
  color: var(--text);
}

.prose ul,
.prose ol {
  padding-left: 1.4rem;
}

.prose li {
  margin: 0.35rem 0;
}

.prose strong {
  color: var(--accent);
  font-weight: 700;
}

.prose code {
  background: var(--code-bg);
  border-radius: 4px;
  padding: 0.1rem 0.35rem;
  font-size: 0.9em;
  font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
}

.prose pre {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem 1.15rem;
  overflow-x: auto;
  line-height: 1.6;
}

.prose pre code {
  background: none;
  padding: 0;
  font-size: 0.88rem;
}

.prose table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.25rem 0;
  font-size: 0.93rem;
  display: block;
  overflow-x: auto;
}

.prose th,
.prose td {
  border: 1px solid var(--border);
  padding: 0.45rem 0.7rem;
  text-align: left;
  white-space: nowrap;
}

.prose th {
  background: var(--accent-soft);
  font-weight: 600;
}

.prose hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 2.5rem 0;
}

.prose blockquote {
  margin: 1.25rem 0;
  padding-left: 1rem;
  border-left: 3px solid var(--accent);
  color: var(--muted);
}

/* 練習頁 */
.practice-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.practice-head h1 {
  margin: 0.1rem 0 0;
}

.practice-skill {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.practice-stats {
  display: flex;
  gap: 1.75rem;
  margin: 1.25rem 0 1rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

.practice-stats dt {
  font-size: 0.78rem;
  color: var(--muted);
}

.practice-stats dd {
  margin: 0.1rem 0 0;
  font-size: 1.05rem;
  font-weight: 600;
}

.practice-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem;
  box-shadow: var(--shadow);
}

/* 樂譜一律白底：VexFlow 以黑色繪製，深色主題下會看不見。
   樂譜本來就是白紙黑字，固定底色也比反轉顏色自然。 */
.practice-stage {
  background: #fff;
  border-radius: 8px;
  padding: 0.5rem;
  min-height: 150px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.practice-prompt {
  margin: 1rem 0 0.25rem;
  font-size: 1.05rem;
  font-weight: 600;
  text-align: center;
}

.practice-play {
  display: block;
  margin: 0.5rem auto 0;
  font-size: 0.85rem;
  padding: 0.3rem 0.9rem;
}

.practice-choices {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.6rem;
  margin-top: 1.1rem;
}

.choice {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  font: inherit;
  font-size: 0.98rem;
  text-align: left;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 0.7rem 0.9rem;
  cursor: pointer;
  transition: border-color 0.15s ease;
}

.choice:hover:not(:disabled) {
  border-color: var(--accent);
}

.choice:disabled {
  cursor: default;
}

.choice-key {
  flex: none;
  width: 1.4rem;
  height: 1.4rem;
  display: grid;
  place-items: center;
  border-radius: 5px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.75rem;
  font-weight: 700;
}

.choice.is-correct {
  border-color: #2e9e63;
  background: color-mix(in srgb, #2e9e63 12%, transparent);
}

.choice.is-wrong {
  border-color: #d0604f;
  background: color-mix(in srgb, #d0604f 12%, transparent);
}

.practice-feedback {
  margin-top: 1.1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  font-size: 0.94rem;
}

.practice-feedback p {
  margin: 0 0 0.6rem;
}

.verdict {
  font-weight: 700;
}

.verdict.is-correct {
  color: #2e9e63;
}

.verdict.is-wrong {
  color: #d0604f;
}

/* 答錯時的正解算法：與歸因說明區隔，但不喧賓奪主 */
.practice-feedback .how {
  color: var(--muted);
  padding-left: 0.8rem;
  border-left: 2px solid var(--border);
}

.next {
  font: inherit;
  font-size: 0.9rem;
  color: #fff;
  background: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 0.45rem 1.1rem;
  cursor: pointer;
}

.practice-hint,
.practice-note {
  margin: 1rem 0 0;
  font-size: 0.82rem;
  color: var(--muted);
  text-align: center;
}

.practice-note {
  margin-top: 0.35rem;
  opacity: 0.75;
}

kbd {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 0.85em;
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 0.05rem 0.35rem;
  background: var(--surface);
}

/* 互動鋼琴鍵盤 */
.practice-keyboard {
  background: #fff;
  border-radius: 8px;
  padding: 0.5rem;
  margin-top: 1.1rem;
}

.keyboard {
  width: 100%;
  height: auto;
  display: block;
  touch-action: manipulation;
}

.key {
  cursor: pointer;
}

.key-white {
  fill: #fff;
  stroke: #4a4560;
  stroke-width: 1;
}

.key-black {
  fill: #2b2740;
  stroke: #15121f;
  stroke-width: 1;
}

.key-white:hover {
  fill: #efeaff;
}

.key-black:hover {
  fill: #4a4270;
}

/* 題目給定的起音、正解、答錯的鍵 */
.key.is-given {
  fill: #6244b8;
}

.key.is-correct {
  fill: #2e9e63;
}

.key.is-wrong {
  fill: #d0604f;
}

.key-label {
  font-size: 11px;
  fill: #8a83ad;
  pointer-events: none;
  user-select: none;
}

/* 練習列表 */
.practice-list {
  list-style: none;
  padding: 0;
  margin: 1.5rem 0 0;
}

.practice-list li {
  padding: 1rem 0;
  border-bottom: 1px solid var(--border);
}

.practice-list li:last-child {
  border-bottom: none;
}

.practice-list a {
  font-size: 1.05rem;
  font-weight: 600;
}

.practice-list-skill {
  margin-left: 0.4rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.practice-list p {
  margin: 0.3rem 0 0;
  color: var(--muted);
  font-size: 0.94rem;
}

/* 練習之間的切換 */
.practice-switch {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 1rem;
  justify-content: center;
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  font-size: 0.88rem;
}

/* 文章頁的練習入口 */
.article-practice {
  margin: 0 0 1.75rem;
}

@media (max-width: 30rem) {
  .practice-choices {
    grid-template-columns: 1fr;
  }
}

/* 文章朗讀 */
.reader {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin: 0 0 1.5rem;
  font-size: 0.85rem;
}

.reader button,
.reader-player button {
  font: inherit;
  font-size: 0.85rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.2rem 0.8rem;
  cursor: pointer;
}

.reader button:hover,
.reader-player button:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.reader .reader-toggle {
  color: var(--accent);
}

.reader-error {
  color: var(--muted);
}

/* 吸底播放列 */
.reader-player {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.65rem;
  flex-wrap: wrap;
  padding: 0.65rem 1rem calc(0.65rem + env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--border);
  box-shadow: 0 -4px 16px rgb(0 0 0 / 12%);
  font-size: 0.85rem;
}

.reader-rate-label {
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}

.reader-rate {
  font: inherit;
  font-size: 0.85rem;
  padding: 0.1rem 0.4rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
}

.reader-progress {
  color: var(--muted);
}

/* 朗讀中的段落 */
.prose .reading,
h1.reading {
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  border-radius: 6px;
  box-shadow: 0 0 0 6px color-mix(in srgb, var(--accent) 12%, transparent);
  transition: background 0.3s ease;
}

/* 課程地圖 */
.module {
  margin-bottom: 2.75rem;
}

.module h2 {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  padding-bottom: 0.4rem;
  border-bottom: 1px solid var(--border);
}

.module-id {
  font-size: 0.8rem;
  font-weight: 700;
  color: #fff;
  background: var(--accent);
  border-radius: 4px;
  padding: 0.1rem 0.4rem;
}

.module-summary {
  color: var(--muted);
  font-size: 0.93rem;
  margin: 0.5rem 0 1.25rem;
}

.skill-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 0.75rem;
}

.skill {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.9rem 1.1rem;
  box-shadow: var(--shadow);
  scroll-margin-top: 5rem;
}

.skill:target {
  border-color: var(--accent);
}

.skill-head {
  display: flex;
  align-items: baseline;
  gap: 0.55rem;
  flex-wrap: wrap;
}

.skill-code {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 4px;
  padding: 0.1rem 0.4rem;
  font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
}

.skill-title {
  font-weight: 600;
  font-size: 1.02rem;
}

.skill-title.is-todo {
  color: var(--text);
}

.skill-todo {
  font-size: 0.75rem;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0 0.35rem;
}

.skill-summary {
  margin: 0.35rem 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.skill-prereq {
  margin: 0.5rem 0 0;
  font-size: 0.83rem;
  color: var(--muted);
}

.skill-prereq.is-entry {
  font-style: italic;
  opacity: 0.75;
}

/* 詞彙表 */
.glossary-group h2 {
  padding-bottom: 0.4rem;
  border-bottom: 1px solid var(--border);
}

.glossary {
  margin: 0;
}

.glossary dt {
  font-weight: 700;
  margin-top: 1.25rem;
  scroll-margin-top: 5rem;
}

.glossary-en {
  margin-left: 0.5rem;
  font-weight: 400;
  font-size: 0.85rem;
  color: var(--muted);
}

.glossary dd {
  margin: 0.25rem 0 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.glossary-link {
  margin-left: 0.4rem;
  font-size: 0.85rem;
  white-space: nowrap;
}

/* 404 */
.notfound {
  padding: 3rem 0;
  text-align: center;
}

.notfound .hero-actions {
  justify-content: center;
}

/* 頁尾 */
.site-footer {
  border-top: 1px solid var(--border);
  background: var(--surface);
  padding: 2rem 0;
  font-size: 0.88rem;
  color: var(--muted);
}

.footer-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 1rem;
  align-items: center;
}

.footer-label {
  color: var(--muted);
  opacity: 0.7;
}

.footer-current {
  color: var(--text);
  font-weight: 600;
}

.footer-disclaimer {
  margin: 1rem 0 0;
  opacity: 0.8;
  line-height: 1.7;
}

/* 窄螢幕 */
@media (max-width: 40rem) {
  .header-inner {
    gap: 0.5rem;
  }

  .site-nav {
    gap: 0.85rem;
    font-size: 0.88rem;
  }

  .hero h1 {
    font-size: 1.7rem;
  }

  h1 {
    font-size: 1.55rem;
  }

  .content {
    padding: 1.75rem 0 3rem;
  }
}
