/* Folio — 「舊書房」：羊皮紙、墨、酒紅、墨綠 */
:root {
  --paper: #F3EDE1;
  --paper-2: #E8DFCC;
  --card: #FBF8F2;
  --ink: #26221D;
  --ink-2: #5A534A;
  --ink-3: #8A8174;
  --line: #DCD0B9;
  --wine: #7A2E2E;        /* 酒紅 */
  --wine-soft: #F1DEDA;
  --navy: #2F4A6B;        /* 海軍藍 */
  --navy-soft: #DDE5EF;
  --green: #3F6B4F;       /* 墨綠 */
  --green-soft: #DFEADF;
  --gold: #9C7A3C;
  --shadow: 0 1px 2px rgba(38, 34, 29, .06), 0 6px 18px rgba(38, 34, 29, .06);
  --radius: 14px;
  --serif: "EB Garamond", "Garamond", "Georgia", "Times New Roman", serif;
  --sans: "Noto Sans TC", "Microsoft JhengHei", "PingFang TC", system-ui, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #16151A; --paper-2: #1E1D23; --card: #222128; --ink: #EDE6D8; --ink-2: #B9B0A1; --ink-3: #888073;
    --line: #38363F; --wine: #D9817A; --wine-soft: #3A2423; --navy: #8FAED3; --navy-soft: #1F2A3A;
    --green: #8DBB98; --green-soft: #1F2E24; --gold: #CFAE6E;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #16151A; --paper-2: #1E1D23; --card: #222128; --ink: #EDE6D8; --ink-2: #B9B0A1; --ink-3: #888073;
  --line: #38363F; --wine: #D9817A; --wine-soft: #3A2423; --navy: #8FAED3; --navy-soft: #1F2A3A;
  --green: #8DBB98; --green-soft: #1F2E24; --gold: #CFAE6E;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.25);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; min-height: 100vh; background: var(--paper); color: var(--ink); font-family: var(--sans); font-size: 16px; line-height: 1.7; }
:lang(en) { font-family: var(--serif); }
.en { font-family: var(--serif); font-size: 1.12em; }
.serif { font-family: var(--serif); }
a { color: var(--navy); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--navy); outline-offset: 2px; border-radius: 6px; }

/* ── 版面 ── */
.app { display: grid; grid-template-columns: 224px 1fr; min-height: 100vh; }
.side { position: sticky; top: 0; height: 100vh; padding: 28px 18px; border-right: 1px solid var(--line); display: flex; flex-direction: column; gap: 4px; }
.brand { display: flex; align-items: center; gap: 12px; margin: 0 6px 26px; text-decoration: none; color: var(--ink); }
.brand .mark { width: 44px; height: 44px; border-radius: 10px; background: var(--wine); color: #FBF8F2; display: grid; place-items: center; font-family: var(--serif); font-style: italic; font-size: 28px; box-shadow: inset 0 0 0 2px rgba(255,255,255,.22); }
.brand b { font-family: var(--serif); font-size: 26px; font-weight: 600; letter-spacing: .04em; display: block; line-height: 1.1; }
.brand small { color: var(--ink-3); font-size: 12px; letter-spacing: .15em; }
.nav a { display: flex; align-items: center; gap: 12px; padding: 9px 10px; border-radius: 10px; color: var(--ink-2); text-decoration: none; font-size: 15px; }
.nav a .k { width: 30px; height: 30px; border-radius: 50%; border: 1px solid var(--line); display: grid; place-items: center; font-family: var(--serif); font-size: 15px; color: var(--ink); background: var(--card); }
.nav a:hover { background: var(--paper-2); }
.nav a.on { color: var(--ink); background: var(--card); box-shadow: var(--shadow); }
.nav a.on .k { background: var(--wine); color: #FBF8F2; border-color: var(--wine); }
.nav .badge { margin-left: auto; background: var(--wine); color: #fff; font-size: 11px; border-radius: 10px; padding: 0 7px; }
.side .foot { margin-top: auto; font-size: 13px; line-height: 1.5; color: var(--ink-3); padding: 0 8px; }
main { padding: 32px clamp(16px, 4vw, 48px) 120px; max-width: 1100px; width: 100%; min-width: 0; }
@media (max-width: 880px) {
  .app { grid-template-columns: 1fr; }
  .side { position: fixed; bottom: 0; top: auto; left: 0; right: 0; height: auto; z-index: 20; flex-direction: row; padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); border-right: 0; border-top: 1px solid var(--line); background: var(--card); overflow-x: auto; gap: 0; }
  .brand, .side .foot { display: none; }
  .nav { display: flex; gap: 2px; }
  .nav a { flex-direction: column; gap: 2px; font-size: 11px; padding: 4px 8px; min-width: 56px; white-space: nowrap; position: relative; }
  .nav a .k { width: 28px; height: 28px; font-size: 14px; }
  .nav a.on { box-shadow: none; background: transparent; }
  .nav .badge { position: absolute; margin: 0 0 0 22px; }
  main { padding: 20px 16px 110px; }
}

/* ── 標題橫幅（純排版，不用圖片） ── */
.hero { position: relative; border-radius: var(--radius); overflow: hidden; margin-bottom: 24px; padding: 30px 30px 26px; background: var(--wine); color: #F7F1E5; box-shadow: var(--shadow); }
.hero::before { content: attr(data-orn); position: absolute; right: 18px; top: -34px; font-family: var(--serif); font-style: italic; font-size: 190px; line-height: 1; color: rgba(255,255,255,.09); pointer-events: none; }
.hero::after { content: ""; position: absolute; inset: 10px; border: 1px solid rgba(255,255,255,.2); border-radius: 9px; pointer-events: none; }
.hero h1 { position: relative; font-family: var(--serif); font-weight: 500; font-size: clamp(28px, 4vw, 40px); margin: 0; line-height: 1.2; }
.hero p { position: relative; margin: 8px 0 0; color: rgba(247,241,229,.85); font-size: 14px; max-width: 640px; }
.hero.navy { background: var(--navy); } .hero.green { background: var(--green); } .hero.ink { background: #2E2A25; }
:root[data-theme="dark"] .hero { color: #F7F1E5; }

h2.sec { font-family: var(--serif); font-weight: 600; font-size: 22px; margin: 30px 0 12px; display: flex; align-items: center; gap: 10px; }
h2.sec::before { content: "❧"; color: var(--wine); font-size: 18px; }

/* ── 元件 ── */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); }
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.muted { color: var(--ink-3); }
.small { font-size: 13px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; padding: 0 16px; border-radius: 999px; border: 1px solid var(--line); background: var(--card); cursor: pointer; text-decoration: none; color: var(--ink); font-size: 14px; white-space: nowrap; }
.btn:hover { border-color: var(--ink-3); }
.btn.wine { background: var(--wine); border-color: var(--wine); color: #FBF8F2; }
.btn.navy { background: var(--navy); border-color: var(--navy); color: #FBF8F2; }
.btn.ghost { background: transparent; }
.btn.sm { min-height: 32px; padding: 0 12px; font-size: 13px; }
.btn svg { width: 16px; height: 16px; }
.btn[disabled] { opacity: .45; cursor: default; }
.icon-btn { width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--line); background: var(--card); cursor: pointer; display: inline-grid; place-items: center; flex: none; color: var(--ink-2); }
.icon-btn:hover { border-color: var(--navy); color: var(--navy); }
.icon-btn svg { width: 17px; height: 17px; }
.icon-btn.on { background: var(--navy); color: #fff; border-color: var(--navy); }
.icon-btn.on.paused { background: var(--card); color: var(--navy); }
.icon-btn[aria-pressed="true"] { color: var(--gold); border-color: var(--gold); }
.icon-btn[aria-pressed="true"] svg { fill: currentColor; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 1px 10px; border-radius: 999px; font-size: 12px; border: 1px solid var(--line); color: var(--ink-2); background: var(--paper); white-space: nowrap; text-decoration: none; }
.chip.wine { color: var(--wine); border-color: var(--wine); background: var(--wine-soft); }
.chip.navy { color: var(--navy); border-color: var(--navy); background: var(--navy-soft); }
.chip.green { color: var(--green); border-color: var(--green); background: var(--green-soft); }
button.chip { cursor: pointer; }
button.chip[aria-pressed="true"] { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.seg { display: inline-flex; background: var(--paper-2); border-radius: 999px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg button { border: 0; background: transparent; padding: 6px 14px; border-radius: 999px; cursor: pointer; color: var(--ink-2); font-size: 14px; }
.seg button[aria-pressed="true"] { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }
.level { font-family: var(--serif); font-weight: 600; font-size: 12px; padding: 0 7px; border-radius: 4px; border: 1.5px solid currentColor; }
.level.B1 { color: var(--green); } .level.B2 { color: var(--navy); } .level.C1 { color: var(--wine); }
input[type=text], input[type=search], textarea, select { width: 100%; padding: 10px 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); }
textarea { min-height: 80px; resize: vertical; }
input[type=range] { accent-color: var(--wine); width: 100%; }

/* ── 單字 ── */
.wcard { display: flex; flex-direction: column; gap: 4px; text-decoration: none; color: inherit; position: relative; transition: transform .15s; }
.wcard:hover { transform: translateY(-2px); border-color: var(--ink-3); }
.wcard .w { font-family: var(--serif); font-size: 26px; line-height: 1.2; }
.wcard .r { color: var(--ink-3); font-size: 13px; }
.wcard .zh { font-size: 14px; color: var(--ink-2); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.wcard .in { position: absolute; top: 14px; right: 14px; width: 9px; height: 9px; border-radius: 50%; background: var(--green); }
.ipa { font-family: "Charis SIL", "Doulos SIL", "Lucida Sans Unicode", "Segoe UI", sans-serif; color: var(--ink-3); }
.detail .head { display: flex; gap: 16px; align-items: flex-start; flex-wrap: wrap; }
.detail .big { font-family: var(--serif); font-weight: 500; font-size: clamp(38px, 6vw, 56px); line-height: 1.1; margin: 0; }
.detail .zh-main { font-size: 20px; margin: 12px 0 0; }
.block { margin-top: 22px; }
.block h3 { font-size: 13px; letter-spacing: .15em; color: var(--ink-3); margin: 0 0 8px; font-weight: 500; }
.simple { font-family: var(--serif); font-size: 19px; padding: 12px 16px; border-left: 3px solid var(--green); background: var(--green-soft); border-radius: 0 10px 10px 0; }
.ex { display: flex; gap: 10px; align-items: flex-start; padding: 10px 0; border-bottom: 1px dashed var(--line); }
.ex:last-child { border-bottom: 0; }
.ex .en { font-size: 19px; line-height: 1.5; }
.ex .zh { color: var(--ink-2); font-size: 14px; }
.hide-zh .ex .zh { filter: blur(5px); cursor: pointer; transition: filter .2s; }
.hide-zh .ex .zh:hover, .hide-zh .ex .zh.show { filter: none; }
.wrong { color: var(--wine); font-family: var(--serif); font-size: 18px; }
.box { padding: 12px 16px; border-radius: 10px; background: var(--paper-2); }
.connect { font-size: 15px; padding: 10px 14px; border: 1px dashed var(--navy); border-radius: 10px; color: var(--navy); background: var(--navy-soft); }
mark.kw { background: color-mix(in srgb, var(--gold) 30%, transparent); color: inherit; border-radius: 3px; padding: 0 2px; }

/* ── 測驗 ── */
.quiz .q { font-family: var(--serif); font-size: 20px; margin-bottom: 12px; line-height: 1.5; }
.opts { display: grid; gap: 8px; }
.opt { text-align: left; padding: 10px 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); cursor: pointer; display: flex; gap: 10px; align-items: center; }
.opt:hover { border-color: var(--navy); }
.opt .n { width: 22px; height: 22px; border-radius: 50%; border: 1px solid var(--line); display: grid; place-items: center; font-size: 12px; flex: none; }
.opt.right { border-color: var(--green); background: var(--green-soft); }
.opt.right .n { color: var(--green); border-color: var(--green); font-size: 0; }
.opt.right .n::after { content: "✓"; font-size: 13px; }
.opt.bad { border-color: var(--wine); background: var(--wine-soft); }
.opt.bad .n { color: var(--wine); border-color: var(--wine); font-size: 0; }
.opt.bad .n::after { content: "✗"; font-size: 13px; }
.explain { margin: 10px 0 0; }

/* ── 首頁 ── */
.today { display: grid; grid-template-columns: 1.25fr 1fr; gap: 16px; }
@media (max-width: 880px) { .today { grid-template-columns: 1fr; } }
.task { display: flex; align-items: center; gap: 14px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.task:last-child { border-bottom: 0; }
.task .k { width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; font-family: var(--serif); font-size: 20px; background: var(--paper-2); flex: none; }
.task.done .k { background: var(--green); color: #fff; }
.task .t { font-weight: 500; }
.task .s { font-size: 13px; color: var(--ink-3); }
.quote .q { font-family: var(--serif); font-style: italic; font-size: 23px; line-height: 1.55; margin: 4px 0 10px; }
.quote .q::before { content: "“"; color: var(--wine); font-size: 1.6em; line-height: 0; vertical-align: -.35em; margin-right: 2px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat { text-align: center; padding: 12px 6px; }
.stat b { display: block; font-family: var(--serif); font-size: 34px; font-weight: 500; line-height: 1.1; }
.stat span { font-size: 12px; color: var(--ink-3); }
.heat { display: grid; grid-auto-flow: column; grid-template-rows: repeat(7, 12px); grid-auto-columns: 12px; justify-content: start; gap: 3px; overflow-x: auto; padding-bottom: 4px; }
.heat i { width: 12px; height: 12px; border-radius: 3px; background: var(--paper-2); }
.heat i[data-l="1"] { background: color-mix(in srgb, var(--wine) 30%, var(--paper-2)); }
.heat i[data-l="2"] { background: color-mix(in srgb, var(--wine) 55%, var(--paper-2)); }
.heat i[data-l="3"] { background: color-mix(in srgb, var(--wine) 80%, var(--paper-2)); }
.heat i[data-l="4"] { background: var(--wine); }
.bar { height: 6px; border-radius: 6px; background: var(--paper-2); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--wine); border-radius: 6px; transition: width .4s; }

/* ── 複習 ── */
.flash { min-height: 340px; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 12px; padding: 30px 20px; }
.flash .front { font-family: var(--serif); font-size: clamp(40px, 7vw, 60px); line-height: 1.2; }
.flash .front.zhq { font-family: var(--sans); font-size: 24px; }
.flash .type { font-size: 12px; letter-spacing: .2em; color: var(--ink-3); }
.flash .back { width: 100%; max-width: 640px; text-align: left; border-top: 1px solid var(--line); padding-top: 16px; margin-top: 6px; animation: rise .25s ease; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.rate { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; width: 100%; max-width: 640px; }
.rate button { padding: 10px 4px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); cursor: pointer; }
.rate button b { display: block; font-size: 15px; }
.rate button small { color: var(--ink-3); font-size: 12px; }
.rate .r1 b { color: var(--wine); } .rate .r2 b { color: var(--gold); } .rate .r3 b { color: var(--green); } .rate .r4 b { color: var(--navy); }
.new-badge { color: var(--wine); border: 1px solid var(--wine); font-size: 11px; border-radius: 4px; padding: 0 6px; letter-spacing: .1em; }

/* ── 閱讀（長篇用純色底） ── */
.reader-bar { position: sticky; top: 0; z-index: 5; background: color-mix(in srgb, var(--paper) 94%, transparent); backdrop-filter: blur(6px); padding: 10px 0; margin-bottom: 10px; border-bottom: 1px solid var(--line); }
.reader { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 32px clamp(20px, 5vw, 56px); font-family: var(--serif); line-height: 1.75; max-width: 46em; }
.reader h3 { font-size: 1em; font-weight: 600; letter-spacing: .08em; margin: 0 0 1em; color: var(--wine); font-variant: small-caps; }
.reader p { margin: 0 0 1em; position: relative; hyphens: auto; }
.reader.prose p + p { text-indent: 1.5em; margin-top: -.6em; }
.reader.verse p { margin-bottom: 1.4em; }
.reader .gl { border-bottom: 1.5px dotted var(--wine); cursor: pointer; }
.reader .gl:hover, .reader .gl.on { background: var(--wine-soft); }
.reader .say { position: absolute; left: -30px; top: .25em; width: 22px; height: 22px; border: 0; background: none; cursor: pointer; color: var(--ink-3); padding: 0; opacity: .45; }
.reader .say svg { width: 18px; height: 18px; }
.reader .say:hover { opacity: 1; color: var(--navy); }
@media (max-width: 560px) { .reader .say { left: -22px; } }
.reader p.speaking { background: var(--navy-soft); border-radius: 6px; box-shadow: 0 0 0 6px var(--navy-soft); }
.sheet { position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%); width: min(560px, calc(100% - 32px)); z-index: 40; animation: rise .2s; }
@media (max-width: 880px) { .sheet { bottom: 88px; } }
.sheet .close { position: absolute; top: 10px; right: 10px; }
.tcard .w { font-size: 24px; }
.tcard .by { font-family: var(--serif); font-style: italic; color: var(--ink-2); }

/* ── 聽力 ── */
.listen-stage { text-align: center; padding: 26px 18px; }
.play-big { width: 92px; height: 92px; border-radius: 50%; border: 0; background: var(--navy); color: #fff; cursor: pointer; display: inline-grid; place-items: center; box-shadow: 0 8px 22px color-mix(in srgb, var(--navy) 40%, transparent); }
.play-big svg { width: 38px; height: 38px; }
.diff { font-family: var(--serif); font-size: 20px; line-height: 1.9; }
.diff .miss { background: var(--wine-soft); color: var(--wine); text-decoration: underline wavy; }
.diff .extra { color: var(--ink-3); text-decoration: line-through; }
.mask-0 .reveal-en, .mask-0 .reveal-zh, .mask-1 .reveal-zh { visibility: hidden; }

/* ── 搜尋 ── */
.searchbox { position: relative; }
.searchbox input { padding: 14px 18px 14px 46px; font-size: 18px; border-radius: 999px; }
.searchbox svg { position: absolute; left: 16px; top: 50%; transform: translateY(-50%); width: 20px; color: var(--ink-3); }
.res { display: flex; gap: 12px; align-items: baseline; padding: 10px 4px; border-bottom: 1px solid var(--line); text-decoration: none; color: inherit; flex-wrap: wrap; }
.res:last-child { border-bottom: 0; }
.res:hover { background: var(--paper-2); }
.res .p { font-family: var(--serif); font-size: 20px; min-width: 9em; }
mark { background: color-mix(in srgb, var(--gold) 35%, transparent); color: inherit; border-radius: 3px; }

#toast { position: fixed; left: 50%; bottom: 30px; transform: translate(-50%, 20px); background: var(--ink); color: var(--paper); padding: 10px 18px; border-radius: 999px; opacity: 0; pointer-events: none; transition: .25s; z-index: 99; font-size: 14px; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
@media (max-width: 880px) { #toast { bottom: 96px; } }
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 50; display: grid; place-items: center; padding: 16px; }
.modal { width: min(520px, 100%); }

/* 詳細頁：上一個／下一個 */
.pager { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: center; gap: 10px; margin: 0 0 14px; }
.pager.bottom { margin: 16px 0 0; }
.pager .back { justify-self: center; text-align: center; font-size: 14px; white-space: nowrap; }
.pager .pg { display: inline-flex; align-items: center; gap: 4px; min-height: 40px; padding: 6px 12px; border: 1px solid var(--line); border-radius: 999px; background: var(--card); color: var(--ink); text-decoration: none; max-width: 100%; min-width: 0; }
.pager .pg span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: var(--serif); font-size: 17px; }
.pager .pg svg { width: 18px; height: 18px; flex: none; color: var(--navy); }
.pager .prev { justify-self: start; } .pager .next { justify-self: end; } .pager .off { visibility: hidden; }
@media (max-width: 560px) { .pager .back .small { display: none; } }

.copy { cursor: copy; border-radius: 6px; transition: background .2s; }
.copy:hover { background: var(--navy-soft); }
.copy.copied { background: var(--green-soft); }
.backup-banner { margin-bottom: 16px; border-left: 4px solid var(--gold); }

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
