:root {
  --bg: #f6f5f1;
  --panel: #ffffff;
  --ink: #1d1d1b;
  --muted: #62625d;
  --line: #d9d7cf;
  --accent: #1f5f8b;
  --accent-ink: #ffffff;
  --hl: #ffe27a;
  --hl-ink: #1d1d1b;
  --play: #b8e3c4;
  --warn: #8a4b00;
  --warn-bg: #fff4e0;
  --focus: #c45f00;
  --control: #86847b; /* 輸入框、按鈕外框：與背景對比至少 3:1（WCAG 1.4.11） */
  --mono: "Consolas", "Menlo", "DejaVu Sans Mono", monospace;
  --braille: "Segoe UI Symbol", "Apple Braille", "DejaVu Sans", "Noto Sans Symbols 2", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1b1c1e;
    --panel: #232427;
    --ink: #ecebe6;
    --muted: #a7a69f;
    --line: #3a3b3f;
    --accent: #6fb3e0;
    --accent-ink: #10181f;
    --hl: #7a6420;
    --hl-ink: #ffffff;
    --play: #2f6b41;
    --warn: #ffc27a;
    --warn-bg: #3a2c16;
    --focus: #e0761a;
    --control: #85847d;
  }
}
/* 放在視障輔助工具集裡時，跟著網站的深色／淺色切換 */
:root[data-theme="dark"] {
  --bg: #1b1c1e;
  --panel: #232427;
  --ink: #ecebe6;
  --muted: #a7a69f;
  --line: #3a3b3f;
  --accent: #6fb3e0;
  --accent-ink: #10181f;
  --hl: #7a6420;
  --hl-ink: #ffffff;
  --play: #2f6b41;
  --warn: #ffc27a;
  --warn-bg: #3a2c16;
  --focus: #e0761a;
  --control: #85847d;
}

/* 只給報讀軟體的文字 */
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* ASCII 點字用的 SimBraille 字型：放在視障輔助工具集的 music/ 時，取用工具集根目錄的 SIMBRL.TTF */
@font-face { font-family: 'SimBraille'; src: url('../../SIMBRL.TTF') format('truetype'); }

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, "Microsoft JhengHei", "PingFang TC", "Noto Sans TC", sans-serif;
  font-size: 16px;
  line-height: 1.5;
}
a { color: var(--accent); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

.site-header, .toolbar, main, .site-footer { max-width: 1400px; margin: 0 auto; padding: 0 16px; }
.site-header { padding-top: 20px; }
.site-header h1 { margin: 0; font-size: 1.6rem; }
.subtitle { margin: 4px 0 0; color: var(--muted); }

.toolbar {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
  margin-top: 14px; margin-bottom: 14px;
}
.sep { width: 1px; height: 24px; background: var(--line); margin: 0 4px; }
button, select, input[type="number"] {
  font: inherit; color: var(--ink); background: var(--panel);
  border: 1px solid var(--control); border-radius: 6px; padding: 5px 10px;
}
button { cursor: pointer; }
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
label { display: inline-flex; gap: 6px; align-items: center; }

.editors { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 900px) { .editors { grid-template-columns: 1fr; } }

.pane {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 12px 14px; min-width: 0;
}
.pane + .pane, .editors + .pane { margin-top: 14px; }
.pane-head { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.pane h2 { margin: 0; font-size: 1.1rem; }
.pane-tools { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; }
.hint { color: var(--muted); font-size: 0.9rem; margin: 0; }

/* 編輯區：透明 textarea 疊在標示用的背景層上 */
.editor { position: relative; border: 1px solid var(--control); border-radius: 6px; background: var(--bg); }
.editor textarea, .editor .backdrop {
  margin: 0; border: 0; padding: 10px 12px;
  font-family: var(--mono); font-size: 15px; line-height: 1.6;
  white-space: pre; overflow-wrap: normal; letter-spacing: 0;
  width: 100%; height: 340px; tab-size: 4;
}
.editor.braille textarea, .editor.braille .backdrop { font-family: var(--braille); font-size: 24px; line-height: 1.45; }
.editor.braille.brf textarea, .editor.braille.brf .backdrop { font-family: var(--mono); font-size: 18px; }
.editor.braille.simbraille textarea, .editor.braille.simbraille .backdrop { font-family: 'SimBraille', var(--mono); }
.editor textarea {
  position: relative; z-index: 1; display: block;
  background: transparent; color: var(--ink); resize: vertical; overflow: auto;
}
.editor textarea:focus { outline: none; }
.editor:focus-within { outline: 3px solid var(--focus); outline-offset: 1px; }
.editor .backdrop {
  position: absolute; inset: 0; z-index: 0; overflow: hidden;
  color: transparent; pointer-events: none;
}
.backdrop mark { background: var(--hl); color: transparent; border-radius: 3px; }
.backdrop mark.play { background: var(--play); }

.cell-info { min-height: 1.5em; margin: 6px 0 0; color: var(--muted); font-size: 0.9rem; }

.player input[type="range"] { width: 120px; }
.paper { overflow-x: auto; background: #fff; border-radius: 6px; min-height: 120px; color: #000; }
.paper svg { max-width: none; }
.paper.scroll { overflow: auto !important; max-height: 70vh; } /* abcjs 會在容器寫入 overflow: hidden */
.paper-tools { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; margin-bottom: 6px; }
.paper .abcjs-note, .paper .abcjs-rest { cursor: pointer; }
.paper .hl, .paper .hl path { fill: #d9480f !important; stroke: #d9480f; }
.paper .playing, .paper .playing path { fill: #2b8a3e !important; }

.score-export { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 10px; }

/* 列印五線譜：只留下樂譜 */
@media print {
  body.print-score { background: #fff; }
  body.print-score > :not(main) { display: none !important; }
  body.print-score main > :not(.preview) { display: none !important; }
  body.print-score .preview { border: 0; padding: 0; }
  body.print-score .preview > :not(.paper) { display: none !important; }
  body.print-score .paper { overflow: visible; max-height: none; }
  body.print-score .paper .hl, body.print-score .paper .playing { fill: #000 !important; }
  body.print-dual { background: #fff; }
  body.print-dual > :not(main) { display: none !important; }
  body.print-dual main > :not(.dual) { display: none !important; }
  body.print-dual .dual { border: 0; padding: 0; }
  body.print-dual .dual > :not(.dv-sheet) { display: none !important; }
  body.print-dual .dv-sheet { overflow: visible; max-height: none; padding: 0; }
  body.print-dual .dv-line { break-inside: avoid; }
  body.print-dual .dv-hl, body.print-dual .dv-play { background: none !important; }
}

/* 雙視對照：每一方點字固定寬度（--cw），墨字以方為單位定位；像點字紙一樣固定白底 */
.dv-sheet { --dvsize: 28px; --cw: calc(var(--dvsize) * 1.15); position: relative; overflow: auto; max-height: 75vh; background: #fff; color: #000; border-radius: 6px; padding: 12px 16px; font-size: var(--dvsize); }
.dv-line { position: relative; width: max-content; }
.dv-top { position: relative; height: calc(var(--stack, 1) * 0.6em + 0.35em); }
.dv-top.dv-empty { height: 0.25em; }
.dv-top > span { position: absolute; bottom: 0.2em; display: flex; flex-direction: column; align-items: center; font-size: 0.5em; line-height: 1.2; white-space: nowrap; cursor: default; }
.dv-top > .dv-note, .dv-top > .dv-lyric { cursor: pointer; }
.dv-top > .dv-lyric, .dv-top > .dv-text { font-size: 0.6em; line-height: 1; }
.dv-top > .u1::after, .dv-top > .u2::after { content: ''; position: absolute; left: 0; right: 0; bottom: -0.25em; border-bottom: 1.5px solid currentColor; }
.dv-top > .u2::after { border-bottom: 4px double currentColor; bottom: -0.35em; }
.dv-top > .gap::after { right: 0.4em; }
.dv-brl { white-space: nowrap; line-height: 1.3; }
.dv-cell { display: inline-block; width: var(--cw); text-align: center; font-family: var(--braille); cursor: pointer; }
.dv-bar { position: absolute; top: 0.15em; bottom: 0.15em; width: 0; border-left: 1.5px solid #555; pointer-events: none; }
.dv-sheet.brf .dv-cell { font-family: var(--mono); font-size: 0.7em; line-height: calc(1.3em / 0.7); }
.dv-sheet.simbraille .dv-cell { font-family: 'SimBraille', var(--mono); }
.dual summary { cursor: pointer; }
.dual summary h2 { display: inline; }
.dual[open] summary { margin-bottom: 8px; }
.dv-sheet .dv-hl { background: #ffe27a; }
.dv-sheet .dv-play { background: #b8e3c4; }

.messages ul { margin: 0; padding-left: 0; list-style: none; }
.messages li { padding: 6px 10px; border-radius: 6px; margin-top: 6px; }
.messages li.warn { background: var(--warn-bg); color: var(--warn); }
.messages li.ok { color: var(--muted); }
.messages li button { margin-left: 8px; padding: 1px 8px; font-size: 0.85rem; }

.settings summary, .help summary { cursor: pointer; font-weight: 600; }
.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 10px 20px; margin-top: 10px; }
.help-body h3 { font-size: 1rem; margin: 14px 0 4px; }
.help-body ul { margin: 0; padding-left: 20px; }
.help-body p { margin: 0; }

.site-footer { color: var(--muted); font-size: 0.85rem; padding-top: 10px; padding-bottom: 30px; }

/* 視障輔助工具集的「🔊 報讀」區塊（speech-block.js）沿用本頁配色 */
.speech-block {
  --bd: var(--control); --surf: var(--panel); --surf2: var(--bg); --dim: var(--muted);
  --blue: #1f5f8b; /* 目前朗讀行：白字對比 6.8:1，深淺色都用同一色 */
  --focus-ring: 0 0 0 3px var(--focus);
  margin-top: 12px;
}

/* ---------- 規則對照頁（rules.html） ---------- */
.back { margin: 0 0 6px; }
.subtitle a { color: var(--accent); }
.rules .pane h2 { font-size: 1.25rem; }
.rules h3 { font-size: 1.05rem; margin: 18px 0 6px; }
.rule-body ul { margin: 6px 0; padding-left: 22px; }
.rule-body li { margin: 3px 0; }
.rule-body p { margin: 6px 0; }
.par { font-size: 0.85rem; font-weight: normal; color: var(--muted); margin-left: 6px; white-space: nowrap; }
.toc ol { margin: 6px 0 0; padding-left: 22px; }
.toc li { margin: 4px 0; }
.table-wrap { overflow-x: auto; }
.rules table { border-collapse: collapse; margin: 6px 0; }
.rules caption { text-align: left; color: var(--muted); font-size: 0.9rem; padding-bottom: 4px; }
.rules th, .rules td { border: 1px solid var(--line); padding: 6px 10px; text-align: left; vertical-align: middle; }
.rules thead th { background: var(--bg); }
.sign { display: inline-flex; flex-direction: column; align-items: flex-start; vertical-align: middle; line-height: 1.2; }
.sign-brl { font-family: var(--braille); font-size: 1.6rem; }
.sign-dots { font-size: 0.8rem; color: var(--muted); white-space: nowrap; }
.hint .sign, .rules caption .sign { flex-direction: row; align-items: center; gap: 4px; }
.hint .sign-brl, .rules caption .sign-brl { font-size: 1.2rem; }
.example { border-top: 1px solid var(--line); padding-top: 10px; margin-top: 14px; }
.example h4 { margin: 0 0 8px; font-size: 1rem; }
.ex-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 800px) { .ex-grid { grid-template-columns: 1fr; } }
.ex-label { display: block; font-weight: 600; font-size: 0.9rem; margin-bottom: 4px; }
.example textarea {
  width: 100%; font: 0.95rem/1.5 var(--mono); color: var(--ink); background: var(--bg);
  border: 1px solid var(--control); border-radius: 6px; padding: 6px 8px; resize: vertical;
}
.ex-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 6px; }
.ex-brl {
  margin: 0; padding: 8px 10px; min-height: 3em; overflow-x: auto;
  font-family: var(--braille); font-size: 1.6rem; line-height: 1.4;
  background: var(--bg); border: 1px solid var(--line); border-radius: 6px;
}
.ex-speech { margin-top: 6px; font-size: 0.9rem; }
.ex-speech summary { cursor: pointer; }
.ex-speech-text p { margin: 4px 0 0; }
.ex-warn { margin: 6px 0 0; padding-left: 20px; color: var(--warn); }
.ex-warn:empty { display: none; }
.ex-staff { margin-top: 8px; max-width: 760px; }
.ex-note { margin: 6px 0 0; }
.to-top { margin: 14px 0 0; font-size: 0.9rem; }
.display-bar { display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; }
.sign-brl.ascii, .ex-brl.ascii { font-family: var(--mono); font-size: 1.1rem; }
.sign-brl.simbraille, .ex-brl.simbraille { font-family: 'SimBraille', var(--mono); font-size: 1.6rem; }
