*{box-sizing:border-box}
html,body{margin:0;height:100%}
body{background:var(--bg);color:var(--text);font-family:var(--font-ui);font-size:calc(15px * var(--scale,1));line-height:1.55;transition:background-color .3s,color .3s}
button,input,select,textarea{font:inherit;color:inherit}
a{color:var(--accent-strong)}
:focus-visible{outline:2px solid var(--accent-strong);outline-offset:2px}
*::-webkit-scrollbar{width:8px;height:8px}*::-webkit-scrollbar-thumb{background:var(--border-strong);border-radius:8px}*{scrollbar-width:thin;scrollbar-color:var(--border-strong) transparent}

/* ---------- 外框與導覽（版面 data-layout：rail / side / top） ---------- */
.shell{display:grid;min-height:100vh}
.nav{display:flex;gap:6px;background:var(--surface-2);border-color:var(--border)}
.nav a{display:flex;align-items:center;gap:10px;padding:9px 12px;border-radius:calc(var(--radius) * .6);color:var(--muted);text-decoration:none;white-space:nowrap;font-size:.93em}
.nav a:hover{background:var(--accent-soft);color:var(--text)}
.nav a.active{background:var(--accent-strong);color:var(--on-accent)}
.nav .ico{width:20px;text-align:center;font-size:1.05em}
.nav .group{font-size:.72em;color:var(--muted);letter-spacing:.12em;margin:14px 12px 2px}
.brand{display:flex;align-items:center;gap:10px;font-family:var(--font-head);font-weight:700;font-size:1.15em;padding:6px 10px 14px}
.logo{width:34px;height:34px;border-radius:10px;background:var(--accent-strong);color:var(--on-accent);display:grid;place-items:center;font-size:17px;flex:none}
[data-theme="matcha"] .logo,[data-theme="celadon"] .logo{border-radius:4px;transform:rotate(-4deg);background:#C26B4E;color:#fff}
[data-theme="rose"] .logo{border-radius:50%}
.main{min-width:0;padding:22px 28px 40px}
[data-layout="side"] .shell{grid-template-columns:236px 1fr}
[data-layout="side"] .nav{flex-direction:column;padding:22px 14px;border-right:1px solid var(--border);position:sticky;top:0;height:100vh;overflow:auto}
[data-layout="rail"] .shell{grid-template-columns:78px 1fr}
[data-layout="rail"] .nav{flex-direction:column;align-items:center;padding:16px 8px;border-right:1px solid var(--border);position:sticky;top:0;height:100vh;overflow:auto}
[data-layout="rail"] .nav .lbl,[data-layout="rail"] .nav .group,[data-layout="rail"] .brand b{display:none}
[data-layout="rail"] .nav a{padding:10px;justify-content:center}
[data-layout="top"] .shell{grid-template-rows:auto 1fr}
[data-layout="top"] .nav{flex-wrap:wrap;align-items:center;padding:10px 24px;border-bottom:1px solid var(--border);background:var(--surface)}
[data-layout="top"] .nav .group{display:none}
[data-layout="top"] .brand{padding:0 14px 0 0}
[data-layout="top"] .main{max-width:1200px;margin:0 auto;width:100%}

/* ---------- 共用元件 ---------- */
.card{background:var(--surface);border:1px solid var(--border);border-radius:var(--radius);box-shadow:var(--shadow);padding:18px 20px}
.btn{border:1px solid var(--border-strong);background:var(--surface);border-radius:calc(var(--radius) * .55 + 4px);padding:7px 14px;cursor:pointer;display:inline-flex;align-items:center;gap:6px;transition:transform .12s,background .15s;min-height:36px}
.btn:hover{background:var(--accent-soft)}.btn:active{transform:translateY(1px)}
.btn.primary{background:var(--accent-strong);color:var(--on-accent);border-color:var(--accent-strong)}
.btn.on{background:var(--accent-soft);border-color:var(--accent);color:var(--accent-strong);font-weight:600}
.btn.small{padding:4px 10px;min-height:30px;font-size:.88em}
.btn:disabled{opacity:.45;cursor:not-allowed}
.row{display:flex;gap:8px;align-items:center;flex-wrap:wrap}
.grow{flex:1}
input[type=text],input[type=url],input[type=number],select,textarea{background:var(--surface);border:1px solid var(--border-strong);border-radius:10px;padding:8px 12px;min-height:38px;max-width:100%}
textarea{width:100%;min-height:120px;resize:vertical}
h1{font-family:var(--font-head);font-size:1.6em;margin:0 0 4px}h2{font-family:var(--font-head);font-size:1.2em;margin:0 0 10px}
.muted{color:var(--muted)}.small{font-size:.85em}
.notice{background:var(--accent-soft);border-radius:12px;padding:10px 14px;margin:10px 0;font-size:.92em}
.notice.warn{background:color-mix(in srgb,var(--again) 18%,var(--surface))}
.pill{display:inline-block;padding:2px 10px;border-radius:99px;background:var(--accent-soft);color:var(--accent-strong);font-size:.8em}
.toast{position:fixed;left:50%;bottom:26px;transform:translateX(-50%);background:var(--text);color:var(--bg);padding:10px 18px;border-radius:12px;z-index:99;opacity:0;transition:opacity .2s;pointer-events:none;max-width:90vw}
.toast.show{opacity:1}
.tabs{display:flex;gap:6px;margin:12px 0}
.grid2{display:grid;grid-template-columns:repeat(auto-fit,minmax(280px,1fr));gap:16px}

/* ---------- 學習畫面 ---------- */
.study{display:grid;grid-template-columns:minmax(260px,var(--split,50%)) 14px minmax(320px,1fr);gap:0 6px;align-items:start}
.stage{position:sticky;top:12px;min-width:0}
.splitter{align-self:stretch;cursor:col-resize;position:relative;touch-action:none;min-height:240px;border-radius:8px}
.splitter::after{content:"";position:absolute;top:0;bottom:0;left:5px;width:4px;border-radius:4px;background:var(--border);transition:background .15s}
.splitter:hover::after,.splitter:focus-visible::after,body.dragging .splitter::after{background:var(--accent)}
body.dragging,body.dragging *{user-select:none;cursor:inherit}
body.dragging iframe,body.dragging video{pointer-events:none}
.study.stacked{display:flex;flex-direction:column;gap:0;align-items:stretch}
.study.stacked .stage{position:static;flex:none}
.study.stacked .video-box{height:var(--vh,30vh);aspect-ratio:auto;width:min(100%,calc(var(--vh,30vh) * 16 / 9));margin:0 auto}
.study.stacked .audio-box{padding:12px}
.study.stacked .audio-box .big{font-size:26px}
.study.stacked .controls{margin-top:6px}
.study.stacked .now{margin-top:6px;padding:8px 12px}
.study.stacked .now>.small,.study.stacked .now .en,.study.stacked .now .zh{display:none}
.study.stacked .now .speak{margin-top:0}
.study.stacked .splitter{flex:none;min-height:0;height:16px;cursor:row-resize}
.study.stacked .splitter::after{top:6px;bottom:auto;height:4px;left:35%;right:35%;width:auto}
.study.stacked .panel{flex:1;min-height:140px;max-height:none}
.study.stacked.no-video .splitter{visibility:hidden;height:10px}
.study.stacked .ad-slot{display:none}
.video-box{background:#000;border-radius:var(--radius);overflow:hidden;aspect-ratio:16/9}
.video-box iframe,.video-box video,.video-box>div{width:100%;height:100%;border:0;display:block}
.audio-box{border-radius:var(--radius);background:linear-gradient(135deg,var(--accent-soft),var(--surface-2));padding:26px;text-align:center}
.audio-box .big{font-size:42px}
.controls{margin-top:12px;display:flex;gap:6px;align-items:center;flex-wrap:wrap}
.timeline{flex:1 1 160px;height:6px;border-radius:6px;background:var(--surface-2);position:relative;cursor:pointer;min-width:120px}
.timeline .fill{position:absolute;inset:0 auto 0 0;background:var(--accent);border-radius:6px}
.timeline .tick{position:absolute;top:-3px;width:2px;height:12px;background:var(--accent-strong)}
.now{margin-top:12px}
.now .en{font-family:var(--font-en);font-size:1.35em;line-height:1.45}
.now .zh{font-family:var(--font-zh);color:var(--muted);margin-top:4px}
.speak{margin-top:12px}
.marks span{padding:1px 4px;border-radius:4px;margin-right:2px}
.marks .ok{background:color-mix(in srgb,var(--good) 25%,transparent)}
.marks .ng{background:color-mix(in srgb,var(--again) 25%,transparent);text-decoration:line-through}
.panel{display:flex;flex-direction:column;max-height:calc(100vh - 60px);padding:0;overflow:hidden}
.panel-head{display:flex;gap:6px;align-items:center;flex-wrap:wrap;padding:12px 14px;border-bottom:1px solid var(--border)}
.sents{overflow:auto;padding:6px 8px 40vh;flex:1;position:relative}
.sent{display:grid;grid-template-columns:44px 1fr auto;gap:8px;padding:9px 10px;border-radius:calc(var(--radius) * .6);cursor:pointer;border-left:3px solid transparent;transition:background .25s}
.sent:hover{background:var(--surface-2)}
.sent.cur{background:var(--current);border-left-color:var(--accent)}
.sent .ts{font-size:.78em;color:var(--muted);padding-top:3px;font-variant-numeric:tabular-nums}
.sent .en{font-family:var(--font-en);font-size:1.08em}
.sent .zh{font-family:var(--font-zh);font-size:.88em;color:var(--muted);margin-top:2px}
body.zh-blur .sent .zh,body.zh-blur .now .zh{filter:blur(5px);transition:filter .2s}
body.zh-blur .sent:hover .zh,body.zh-blur .now:hover .zh{filter:none}
body.zh-hide .sent .zh,body.zh-hide .now .zh{display:none}
body.en-blur .sent .en,body.en-blur .now .en{filter:blur(6px)}
body.en-blur .sent:hover .en{filter:none}
.word-mode .sent .en [data-w]{cursor:pointer;border-radius:3px}
.word-mode .sent .en [data-w]:hover{background:var(--word-bg)}
[data-w].saved{background:var(--word-bg);box-shadow:inset 0 -2px 0 var(--word-line);border-radius:3px}
[data-w].flash{animation:flash .6s}
@keyframes flash{0%{background:var(--accent);color:var(--on-accent)}100%{background:var(--word-bg)}}
.chk{width:24px;height:24px;border-radius:7px;border:1.5px solid var(--border-strong);background:var(--surface);display:grid;place-items:center;cursor:pointer;padding:0;color:var(--on-accent);font-size:14px}
.chk[aria-checked="true"]{background:var(--accent-strong);border-color:var(--accent-strong);animation:pop .35s}
[data-theme="matcha"] .chk[aria-checked="true"],[data-theme="celadon"] .chk[aria-checked="true"]{background:#C26B4E;border-color:#C26B4E;border-radius:50%;animation:stamp .4s}
[data-theme="rose"] .chk{border-radius:50%}
@keyframes pop{0%{transform:scale(.72)}50%{transform:scale(1.2)}100%{transform:scale(1)}}
@keyframes stamp{0%{transform:scale(1.7) rotate(-12deg);opacity:.3}100%{transform:none;opacity:1}}
.hide-chk .chk{display:none}

/* ---------- 複習 ---------- */
.review{max-width:820px;margin:0 auto}
.counts{display:flex;gap:14px;font-size:.88em}
.counts b{font-weight:700}
.flash-card{min-height:340px;display:flex;flex-direction:column;align-items:center;justify-content:center;text-align:center;padding:40px 30px;transition:transform .45s ease-out;transform:perspective(1200px) rotateX(var(--rx,0deg)) rotateY(var(--ry,0deg))}
.flash-card .q{font-family:var(--font-en);font-size:1.9em;line-height:1.35}
.flash-card .word{font-family:var(--font-en);font-size:2.8em}
.flash-card .a{font-family:var(--font-zh);font-size:1.4em;margin-top:6px}
.flash-card hr{width:60%;border:0;border-top:1px solid var(--border);margin:22px 0}
[data-theme="terracotta"] .flash-card{border-radius:999px 999px var(--radius) var(--radius)/230px 230px var(--radius) var(--radius)}
[data-theme="journal"] .flash-card{background-image:repeating-linear-gradient(to bottom,transparent 0 31px,rgba(126,163,192,.25) 31px 32px);border-left:3px solid #E9A3A0}
.rates{display:grid;grid-template-columns:repeat(4,1fr);gap:10px;margin-top:16px}
.rate{--c:var(--good);background:color-mix(in srgb,var(--c) 15%,var(--surface));border:1px solid color-mix(in srgb,var(--c) 50%,transparent);border-radius:calc(var(--radius) * .6);padding:10px;cursor:pointer;min-height:58px}
[data-theme="oat"] .rate{box-shadow:0 5px 0 color-mix(in srgb,var(--c) 45%,var(--surface))}
.rate small{display:block;color:var(--muted)}
.rate b{font-size:1.05em}

/* ---------- 清單 / 統計 ---------- */
table{width:100%;border-collapse:collapse}
td,th{padding:8px;border-bottom:1px solid var(--border);text-align:left;vertical-align:top;font-size:.93em}
th{color:var(--muted);font-weight:600}
.heat{display:grid;grid-template-rows:repeat(7,12px);grid-auto-flow:column;gap:3px}
.heat i{width:12px;height:12px;border-radius:3px;background:var(--surface-2)}
.stat{font-size:2em;font-family:var(--font-head);color:var(--accent-strong)}
.lib{display:grid;grid-template-columns:repeat(auto-fill,minmax(210px,1fr));gap:12px;margin-top:12px}
.lib .item{cursor:pointer}
.lib img{width:100%;border-radius:calc(var(--radius) * .6);aspect-ratio:16/9;object-fit:cover;background:var(--surface-2)}

/* ---------- 主題畫廊 ---------- */
.themes{display:grid;grid-template-columns:repeat(auto-fill,minmax(170px,1fr));gap:12px}
.theme-card{border:2px solid var(--border);border-radius:var(--radius);padding:12px;cursor:pointer;background:var(--bg);color:var(--text);text-align:left;transition:transform .15s}
.theme-card:hover{transform:translateY(-4px)}
.theme-card.sel{border-color:var(--accent)}
.theme-card .sw{display:flex;gap:4px;margin:8px 0}.theme-card .sw i{width:22px;height:22px;border-radius:50%;border:1px solid var(--border)}
.theme-card .mini{background:var(--surface);border-radius:8px;padding:6px 8px;font-family:var(--font-en);font-size:.8em}
.theme-card .mini .c{background:var(--current);border-left:3px solid var(--accent);padding:2px 4px;margin-top:3px}

/* ---------- 預留分頁 / 廣告 ---------- */
.future{max-width:760px}
.future li{margin:4px 0}
.ad-slot{margin:18px 0;min-height:90px}

/* ---------- 響應式 ---------- */
@media (max-width:768px){
  [data-layout] .shell{display:block}
  [data-layout] .nav{position:fixed;bottom:0;left:0;right:0;top:auto;height:auto;flex-direction:row;overflow-x:auto;z-index:50;padding:6px;border:0;border-top:1px solid var(--border)}
  [data-layout] .nav .brand,[data-layout] .nav .group{display:none}
  [data-layout] .nav a{flex-direction:column;gap:2px;font-size:.72em;padding:6px 8px}
  [data-layout] .nav .lbl{display:block}
  .main{padding:14px 12px 90px}
  .chk{width:36px;height:36px}
  .rates{grid-template-columns:repeat(2,1fr)}
}
@media (prefers-reduced-motion:reduce){*,*::before,*::after{animation:none!important;transition:none!important}}
