/* 言の葉 — 「和紙と墨」 */
:root {
  --paper: #F4EEE2;
  --paper-2: #EAE1CF;
  --card: #FBF8F1;
  --ink: #2B2926;
  --ink-2: #5E5A52;
  --ink-3: #8C867A;
  --line: #DCD1BC;
  --shu: #B8392B;        /* 朱 */
  --shu-soft: #F3DDD6;
  --ai: #34557A;         /* 藍 */
  --ai-soft: #DCE5EE;
  --matcha: #6E7F4C;
  --matcha-soft: #E3E8D4;
  --kin: #A8854D;        /* 金茶 */
  --shadow: 0 1px 2px rgba(43, 41, 38, .06), 0 6px 18px rgba(43, 41, 38, .06);
  --radius: 14px;
  --serif: "Shippori Mincho", "Yu Mincho", "YuMincho", "Hiragino Mincho ProN", "Noto Serif JP", serif;
  --sans-ja: "Noto Sans JP", "Yu Gothic UI", "Yu Gothic", "Hiragino Sans", "Meiryo", sans-serif;
  --sans-tc: "Noto Sans TC", "Microsoft JhengHei", "PingFang TC", sans-serif;
  --grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .45 0 0 0 0 .38 0 0 0 0 .25 0 0 0 .09 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #14161B; --paper-2: #1B1E24; --card: #1F232A; --ink: #ECE6D9; --ink-2: #B4AD9F; --ink-3: #847E72;
    --line: #353A44; --shu: #E0675A; --shu-soft: #3A2421; --ai: #86A9D3; --ai-soft: #1F2C3B;
    --matcha: #A4B67D; --matcha-soft: #263020; --kin: #CBA86F;
    --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: #14161B; --paper-2: #1B1E24; --card: #1F232A; --ink: #ECE6D9; --ink-2: #B4AD9F; --ink-3: #847E72;
  --line: #353A44; --shu: #E0675A; --shu-soft: #3A2421; --ai: #86A9D3; --ai-soft: #1F2C3B;
  --matcha: #A4B67D; --matcha-soft: #263020; --kin: #CBA86F;
  --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) var(--grain);
  color: var(--ink);
  font-family: var(--sans-tc);
  font-size: 16px; line-height: 1.7;
}
:lang(ja) { font-family: var(--sans-ja); }
.serif, .serif:lang(ja) { font-family: var(--serif); }
a { color: var(--ai); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--ai); outline-offset: 2px; border-radius: 6px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ── 版面 ── */
.app { display: grid; grid-template-columns: 220px 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(--shu); color: #FBF8F1;
  display: grid; place-items: center; font-family: var(--serif); font-size: 22px; font-weight: 700;
  box-shadow: inset 0 0 0 2px rgba(255,255,255,.25);
}
.brand b { font-family: var(--serif); font-size: 22px; letter-spacing: .12em; display: block; line-height: 1.2; }
.brand small { color: var(--ink-3); font-size: 11px; letter-spacing: .2em; }
.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(--shu); color: #FBF8F1; border-color: var(--shu); }
.nav .badge { margin-left: auto; background: var(--shu); color: #fff; font-size: 11px; border-radius: 10px; padding: 0 7px; }
.side .foot { margin-top: auto; font-size: 12px; 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; min-height: 190px;
  display: flex; align-items: flex-end; margin-bottom: 24px; box-shadow: var(--shadow);
  background: var(--paper-2);
}
.hero img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.hero::after { content: ""; position: absolute; inset: 0; background: linear-gradient(90deg, rgba(20,18,16,.78) 0%, rgba(20,18,16,.35) 55%, rgba(20,18,16,0) 85%); }
.hero .txt { position: relative; z-index: 1; padding: 22px 26px; color: #F7F1E5; max-width: 640px; }
.hero h1 { font-family: var(--serif); font-size: clamp(26px, 4vw, 36px); margin: 0; letter-spacing: .08em; line-height: 1.3; }
.hero p { margin: 6px 0 0; color: rgba(247,241,229,.86); font-size: 14px; }
.hero .credit { position: absolute; right: 10px; bottom: 6px; z-index: 1; font-size: 10px; color: rgba(247,241,229,.7); }

h2.sec { font-family: var(--serif); font-size: 20px; margin: 30px 0 12px; display: flex; align-items: center; gap: 10px; letter-spacing: .05em; }
h2.sec::before { content: ""; width: 6px; height: 20px; background: var(--shu); border-radius: 3px; }

/* ── 元件 ── */
.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.shu { background: var(--shu); border-color: var(--shu); color: #FBF8F1; }
.btn.ai { background: var(--ai); border-color: var(--ai); color: #FBF8F1; }
.btn.ghost { background: transparent; }
.btn.sm { min-height: 32px; padding: 0 12px; font-size: 13px; }
.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; }
.icon-btn:hover { border-color: var(--ai); color: var(--ai); }
.icon-btn svg { width: 17px; height: 17px; }
.icon-btn.on { background: var(--ai); color: #fff; border-color: var(--ai); }
.icon-btn.on.paused { background: var(--card); color: var(--ai); }

.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; }
.chip.shu { color: var(--shu); border-color: var(--shu); background: var(--shu-soft); }
.chip.ai { color: var(--ai); border-color: var(--ai); background: var(--ai-soft); }
.chip.matcha { color: var(--matcha); border-color: var(--matcha); background: var(--matcha-soft); }
.chip.kin { color: var(--kin); border-color: var(--kin); }
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: 700; font-size: 12px; padding: 0 7px; border-radius: 4px; border: 1.5px solid currentColor; }
.level.N1 { color: var(--shu); }
.level.N2 { color: var(--ai); }

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(--shu); width: 100%; }

/* ── 單字卡 ── */
.wcard { cursor: pointer; display: flex; flex-direction: column; gap: 6px; 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: 24px; 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(--matcha); }

.detail .head { display: flex; gap: 16px; align-items: flex-start; flex-wrap: wrap; }
.detail .big { font-family: var(--serif); font-size: clamp(36px, 6vw, 52px); line-height: 1.15; margin: 0; }
.detail .big ruby rt { font-size: 15px; font-family: var(--sans-ja); color: var(--ink-3); letter-spacing: .1em; }
.detail .zh-main { font-size: 20px; margin: 10px 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; }
.yasashii { font-size: 17px; padding: 12px 16px; border-left: 3px solid var(--matcha); background: var(--matcha-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 .ja { font-size: 17px; }
.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(--shu); }
.box { padding: 12px 16px; border-radius: 10px; background: var(--paper-2); }
.connect { font-family: var(--sans-ja); font-size: 15px; padding: 10px 14px; border: 1px dashed var(--ai); border-radius: 10px; color: var(--ai); background: var(--ai-soft); }

/* ── 測驗 ── */
.quiz .q { font-size: 18px; margin-bottom: 12px; }
.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(--ai); }
.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(--matcha); background: var(--matcha-soft); }
.opt.right .n::after { content: "✓"; }
.opt.right .n { color: var(--matcha); border-color: var(--matcha); font-size: 0; }
.opt.right .n::after { font-size: 13px; }
.opt.bad { border-color: var(--shu); background: var(--shu-soft); }
.opt.bad .n { color: var(--shu); border-color: var(--shu); font-size: 0; }
.opt.bad .n::after { content: "✗"; font-size: 13px; }

/* ── 首頁 ── */
.today { display: grid; grid-template-columns: 1.3fr 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: 19px; background: var(--paper-2); flex: none; }
.task.done .k { background: var(--matcha); color: #fff; }
.task .t { font-weight: 500; }
.task .s { font-size: 13px; color: var(--ink-3); }
.ichibun { position: relative; overflow: hidden; }
.ichibun .q { font-family: var(--serif); font-size: 21px; line-height: 1.9; margin: 6px 0 10px; padding-right: 44px; }
.ichibun .stamp { position: absolute; right: 16px; top: 14px; color: var(--shu); border: 2px solid var(--shu); border-radius: 6px; font-family: var(--serif); font-size: 13px; padding: 4px 3px; writing-mode: vertical-rl; letter-spacing: .2em; opacity: .85; transform: rotate(4deg); }
.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: 30px; 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(--shu) 30%, var(--paper-2)); }
.heat i[data-l="2"] { background: color-mix(in srgb, var(--shu) 55%, var(--paper-2)); }
.heat i[data-l="3"] { background: color-mix(in srgb, var(--shu) 80%, var(--paper-2)); }
.heat i[data-l="4"] { background: var(--shu); }

/* ── 複習 ── */
.brush { height: 8px; border-radius: 6px; background: var(--paper-2); overflow: hidden; }
.brush > i { display: block; height: 100%; background: linear-gradient(90deg, var(--ink) 0%, var(--ink-2) 100%); border-radius: 6px; transition: width .4s; clip-path: polygon(0 20%, 100% 0, 100% 100%, 0 85%); }
.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(36px, 7vw, 56px); line-height: 1.25; }
.flash .front.zhq { font-family: var(--sans-tc); font-size: 24px; }
.flash .type { font-size: 12px; letter-spacing: .2em; color: var(--ink-3); }
.flash .back { width: 100%; max-width: 620px; 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: 620px; }
.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(--shu); } .rate .r2 b { color: var(--kin); } .rate .r3 b { color: var(--matcha); } .rate .r4 b { color: var(--ai); }
.new-badge { color: var(--shu); border: 1px solid var(--shu); 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) 92%, 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: 28px 30px; font-family: var(--serif); line-height: 2.1; letter-spacing: .04em; }
.reader.vertical { writing-mode: vertical-rl; width: 100%; height: min(72vh, 680px); overflow-x: auto; overflow-y: hidden; line-height: 2.2; padding: 30px 26px; }
.reader h3 { font-size: 1.1em; margin: 0 0 1em; color: var(--shu); letter-spacing: .3em; }
.reader.vertical h3 { margin: 0 0 0 1.4em; }
.reader p { margin: 0 0 .9em; text-indent: 1em; position: relative; }
.reader.vertical p { margin: 0 0 0 .9em; }
.reader rt { font-size: .5em; color: var(--ink-3); font-family: var(--sans-ja); }
.reader.nofuri rt { visibility: hidden; }
.reader .gl { border-bottom: 1.5px dotted var(--shu); cursor: pointer; }
.reader.vertical .gl { border-bottom: 0; border-left: 1.5px dotted var(--shu); }
.reader .gl:hover, .reader .gl.on { background: var(--shu-soft); }
.reader .say { position: absolute; left: -26px; top: .45em; width: 22px; height: 22px; border: 0; background: none; cursor: pointer; color: var(--ink-3); padding: 0; opacity: .5; }
.reader .say:hover { opacity: 1; color: var(--ai); }
.reader.vertical .say { left: auto; top: -24px; right: .2em; }
.reader p.speaking { background: var(--ai-soft); border-radius: 6px; }
.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; }

/* ── 聽力 ── */
.listen-stage { text-align: center; padding: 26px 18px; }
.play-big { width: 92px; height: 92px; border-radius: 50%; border: 0; background: var(--ai); color: #fff; cursor: pointer; display: inline-grid; place-items: center; box-shadow: 0 8px 22px color-mix(in srgb, var(--ai) 40%, transparent); }
.play-big svg { width: 38px; height: 38px; }
.play-big.rec { background: var(--shu); }
.diff { font-size: 19px; line-height: 2; letter-spacing: .03em; }
.diff .miss { background: var(--shu-soft); color: var(--shu); text-decoration: underline wavy; }
.diff .extra { color: var(--ink-3); text-decoration: line-through; }
.mask-0 .reveal-ja, .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; }
.res:hover { background: var(--paper-2); }
.res .p { font-family: var(--serif); font-size: 18px; min-width: 9em; }
mark { background: color-mix(in srgb, var(--kin) 35%, transparent); color: inherit; border-radius: 3px; }

/* ── 流行語 ── */
.slang .w { font-family: var(--serif); font-size: 26px; }
.risk-需注意 { color: var(--kin); border-color: var(--kin); }
.risk-高風險 { color: var(--shu); border-color: var(--shu); }
.status { font-size: 11px; letter-spacing: .1em; }

table.syn { width: 100%; border-collapse: collapse; }
table.syn td, table.syn th { padding: 10px 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
table.syn th { font-family: var(--serif); font-size: 18px; white-space: nowrap; font-weight: 600; }

#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%); }

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

/* 詳細頁：上一個／下一個 */
.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); }
.pager .pg svg { width: 18px; height: 18px; flex: none; color: var(--ai); }
.pager .pg:hover { border-color: var(--ai); }
.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; -webkit-tap-highlight-color: transparent; }
.copy:hover { background: var(--ai-soft); }
.copy:focus-visible { outline: 2px solid var(--ai); outline-offset: 2px; }
.copy.copied { background: var(--matcha-soft, var(--ai-soft)); }
