/* ===== PhonoRead web · 方向 A 暖纸书卷 ===== */
:root{
  --bg:#ECE7DE; --app:#FAF6EE; --paper:#FCF8F0; --raised:#FFFDF7; --raised2:#FFFDF8;
  --ink:#332D24; --ink2:#3A332A; --t1:#4A4234; --t2:#5C5343; --t3:#6B6150;
  --muted:#9A8E7B; --muted2:#B08D6E; --muted3:#8A7E6B;
  --hair:#ECE2CF; --line2:#E2D9C8; --chip:#E5D9C2; --dashed:#D8C9AC;
  --rust:#B45F2E; --cream:#FFF9EF; --hl:#F6E3CE; --hl2:#F6E8DA; --seg:#F1EADC; --soft:#F3ECDD;
  --p0:oklch(0.52 0.13 50); --p1:oklch(0.52 0.11 145); --p2:oklch(0.52 0.11 250); --p3:oklch(0.52 0.11 330);
  --p0w:oklch(0.52 0.13 50 / 0.55); --p1w:oklch(0.52 0.11 145 / 0.55); --p2w:oklch(0.52 0.11 250 / 0.55); --p3w:oklch(0.52 0.11 330 / 0.55);
  --ipamute:#9A8E7B;
  --serif:'Source Serif 4', Georgia, 'Songti SC', serif;
  --ui:-apple-system, BlinkMacSystemFont, 'PingFang SC', 'Helvetica Neue', sans-serif;
}
*{box-sizing:border-box}
html,body{height:100%}
body{margin:0;background:var(--bg);color:var(--ink);font-family:var(--ui);-webkit-font-smoothing:antialiased;text-rendering:optimizeLegibility}
button{font-family:inherit;cursor:pointer;border:none;background:none;color:inherit}
.ic{flex:none}
.view{min-height:100dvh;display:flex;flex-direction:column}
[hidden]{display:none!important}

/* ---------- shared bits ---------- */
.btn{border-radius:10px;font-weight:700;font-size:13px;padding:9px 16px;transition:filter .12s,transform .04s}
.btn:active{transform:translateY(1px)}
.btn--primary{background:var(--rust);color:var(--cream)}
.btn--primary:hover{filter:brightness(1.05)}
.btn--ghost{background:transparent;border:1px solid var(--chip);color:var(--t2)}
.dot{width:7px;height:7px;border-radius:99px;display:inline-block}
.dot--green{background:var(--p1)}
.linkbtn{color:var(--rust);font-weight:700;font-size:inherit;padding:0}
.linkbtn:hover{text-decoration:underline}

.seg{display:inline-flex;background:var(--seg);border-radius:99px;padding:3px;gap:0}
.seg__opt{font-size:12.5px;font-weight:600;color:var(--muted);padding:5px 13px;border-radius:99px;white-space:nowrap}
.seg__opt.is-active{color:var(--cream);background:var(--rust);font-weight:700}
.seg--sm .seg__opt{font-size:11px;padding:3px 9px}
.seg--block{display:flex;border-radius:11px;padding:3px;width:100%}
.seg--block .seg__opt{flex:1;text-align:center;border-radius:9px;font-size:13px;padding:8px 0}

.switch{width:42px;height:24px;border-radius:99px;background:#E0D5BE;position:relative;flex:none;transition:background .16s}
.switch span{width:19px;height:19px;border-radius:99px;background:var(--cream);position:absolute;top:2.5px;left:2.5px;transition:left .16s}
.switch.is-on{background:var(--rust)}
.switch.is-on span{left:20.5px}

.iconbtn{width:36px;height:36px;border-radius:99px;background:var(--soft);display:flex;align-items:center;justify-content:center;flex:none;transition:filter .12s}
.iconbtn:hover{filter:brightness(.97)}
.iconbtn--aa{font-family:var(--serif);font-size:14px;font-weight:700;color:var(--t2)}
.iconbtn--aa.is-active{background:var(--rust);color:var(--cream)}

/* ---------- HOME ---------- */
.view--home{background:var(--app);align-items:stretch}
.topbar{height:64px;flex:none;display:flex;align-items:center;justify-content:space-between;padding:0 clamp(20px,4vw,36px);border-bottom:1px solid var(--hair)}
.brand{display:flex;align-items:center;gap:11px}
.brand__mark{width:34px;height:34px;border-radius:9px;background:var(--paper);border:1px solid var(--line2);display:flex;align-items:center;justify-content:center;font-family:var(--serif);font-weight:700;font-size:17px;color:var(--rust)}
.brand__name{font-family:var(--serif);font-size:19px;font-weight:700}
.topbar__badge{display:flex;align-items:center;gap:8px;font-size:13px;color:var(--muted);font-weight:600}

.hero{flex:1;display:flex;flex-direction:column;align-items:center;justify-content:center;padding:48px 22px 64px;text-align:center}
.hero__dots{display:flex;gap:5px;margin-bottom:22px}
.pd{width:30px;height:5px;border-radius:99px}
.pd--0{background:var(--p0w)} .pd--1{background:var(--p1w)} .pd--2{background:var(--p2w)} .pd--3{background:var(--p3w)}
.hero__kicker{font-size:13px;letter-spacing:1px;color:var(--muted2);font-weight:700;margin-bottom:14px}
.hero__title{font-family:var(--serif);font-size:clamp(30px,5vw,42px);font-weight:700;margin:0 0 16px;line-height:1.2}
.accent{color:var(--rust)}
.hero__sub{font-size:15px;color:var(--t3);max-width:520px;line-height:1.75;margin:0 0 40px}

.import{width:min(600px,100%);background:var(--raised);border:1.5px dashed var(--dashed);border-radius:18px;padding:26px 28px;box-shadow:0 12px 36px rgba(90,70,40,.08);text-align:left}
.import.dragover{border-color:var(--rust);background:#FFF8EE}
.import__row{display:flex;align-items:center;gap:12px;background:#F4EDDD;border-radius:12px;padding:8px 8px 8px 16px;margin-bottom:16px}
.import__input{flex:1;border:none;background:none;outline:none;font-size:14px;color:var(--ink);min-width:0}
.import__input::placeholder{color:var(--muted)}
.import__go{padding:9px 18px}
.import__or{display:flex;align-items:center;gap:14px;color:#B5A78D;font-size:12px}
.import__or .line{flex:1;height:1px;background:var(--hair)}
.import__alt{display:flex;gap:12px;margin-top:16px}
.chip{flex:1;display:flex;align-items:center;justify-content:center;gap:8px;border:1px solid var(--chip);border-radius:11px;padding:12px 0;font-size:13.5px;font-weight:600;color:var(--t2);background:none;transition:background .12s}
.chip:hover{background:#FBF6EC}
.hero__foot{font-size:13px;color:var(--muted);margin-top:22px}

/* ---------- READER ---------- */
.view--reader{background:var(--bg)}
.reader{flex:1;display:flex;flex-direction:column;min-height:0;background:var(--app);position:relative;width:100%;max-width:1200px;margin:0 auto;box-shadow:0 0 60px rgba(90,70,40,.07)}
.rtoolbar{height:58px;flex:none;display:flex;align-items:center;justify-content:space-between;padding:0 clamp(14px,3vw,28px);border-bottom:1px solid var(--hair);background:var(--paper);position:relative;z-index:6}
.rtoolbar__left{display:flex;align-items:center;gap:14px;min-width:0}
.rtoolbar__src{font-size:13.5px;color:var(--t3);font-weight:600;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.rtoolbar .iconbtn{width:32px;height:32px}
.rtoolbar__right{display:flex;align-items:center;gap:10px}

.rbody{flex:1;display:flex;min-height:0;overflow:hidden}
.rscroll{flex:1;overflow-y:auto;display:block;padding:40px 24px 88px;scroll-behavior:smooth}
.article{max-width:620px;margin:0 auto}
.article__title{font-family:var(--serif);font-size:clamp(24px,3.4vw,32px);font-weight:700;line-height:1.25;margin:0 0 12px}
.article__meta{font-size:13px;color:var(--muted);margin-bottom:30px;display:flex;gap:14px;flex-wrap:wrap}
.article__body{font-family:var(--serif);font-size:20px;line-height:2.55;color:var(--ink2);text-wrap:pretty}
.article__body p{margin:0 0 24px}
/* breathing room scales with how much is annotated */
.article.mode-all .article__body{line-height:3.15}
.article.mode-all .article__body p{margin-bottom:34px}
.article.mode-off .article__body{line-height:1.95}
.article.mode-off .article__body p{margin-bottom:20px}
.article__body p:last-child{margin-bottom:0}
.sent-cn{display:block;font-family:var(--ui);font-size:13.5px;line-height:1.7;color:var(--muted3);margin:6px 0 0;padding-left:2px}

/* word + ruby annotation */
.w{cursor:pointer;border-radius:4px;transition:background .1s}
.w:hover{background:#F1E7D4}
.w.is-active{background:var(--hl)}
ruby.ann{ruby-position:under}
ruby.ann>ruby{ruby-position:over;ruby-align:center}
.seg-g{border-bottom:2px solid transparent}
.seg-ipa{font-size:12px;font-weight:400;font-family:var(--ui)}
rt.cn{font-size:11.5px;font-weight:600;color:var(--muted3);font-family:var(--ui);padding-top:3px}
.seg-g.c0{border-bottom-color:var(--p0w)} .seg-ipa.c0{color:var(--p0)}
.seg-g.c1{border-bottom-color:var(--p1w)} .seg-ipa.c1{color:var(--p1)}
.seg-g.c2{border-bottom-color:var(--p2w)} .seg-ipa.c2{color:var(--p2)}
.seg-g.c3{border-bottom-color:var(--p3w)} .seg-ipa.c3{color:var(--p3)}
/* coloring off */
.article.no-color .seg-g{border-bottom-color:#D8C9AC}
.article.no-color .seg-ipa{color:var(--ipamute)}
/* word translation off */
.article.no-wordcn rt.cn{display:none}

/* ---------- right rail ---------- */
.rail{width:318px;flex:none;border-left:1px solid var(--hair);background:var(--paper);display:flex;flex-direction:column;min-height:0}
.rail__inner{flex:1;overflow-y:auto;padding:22px 22px 0}
.sheet-handle{display:none}
.rail__label{font-size:11.5px;font-weight:700;color:var(--muted2);letter-spacing:.5px;margin-bottom:14px}
.wordcard{background:var(--raised);border:1px solid var(--hair);border-radius:14px;padding:18px 18px 20px}
.wordcard__head{display:flex;align-items:baseline;justify-content:space-between;gap:8px}
.wordcard__word{font-family:var(--serif);font-size:24px;font-weight:700;word-break:break-word}
.wordcard__tools{display:flex;align-items:center;gap:7px;flex:none}
.playdot{width:26px;height:26px;border-radius:99px;background:var(--hl2);display:flex;align-items:center;justify-content:center}
.wordcard__ipa{font-size:15px;margin:8px 0 14px;font-weight:400}
.wordcard__ipa .sl{color:var(--t2)} .wordcard__ipa .dotsep{color:#C9BBA0}
.wordcard__gloss{font-size:14px;color:var(--t1);line-height:1.7}
.wordcard__gloss b{font-weight:700}
.wordcard__eg{font-size:13px;color:var(--muted3);line-height:1.7;margin-top:8px;font-family:var(--serif);font-style:italic}
.wordcard__actions{display:flex;gap:10px;margin-top:16px}
.wordcard__save{flex:1;text-align:center}
.wordcard__icon{width:42px;display:flex;align-items:center;justify-content:center;padding:0}
.wordcard-empty{font-size:13px;color:var(--muted);line-height:1.7;background:var(--raised);border:1px dashed var(--chip);border-radius:14px;padding:16px 18px}
.aicard{margin-top:16px;background:var(--raised);border:1px solid var(--hair);border-radius:14px;padding:16px 18px}
.aicard__head{display:flex;align-items:center;gap:8px;margin-bottom:8px}
.aibadge{width:18px;height:18px;border-radius:99px;background:var(--hl2);display:flex;align-items:center;justify-content:center;font-size:11px;font-weight:800;color:var(--rust)}
.aicard__head span:last-child{font-size:12.5px;font-weight:700;color:var(--t3)}
.aicard__q{font-size:13px;color:var(--muted3);line-height:1.6;cursor:pointer}
.aicard__q:hover{color:var(--t2)}

.playbar{flex:none;padding:18px 22px 22px;border-top:1px solid var(--hair);display:flex;align-items:center;gap:14px}
.playbar__btn{width:44px;height:44px;border-radius:99px;background:var(--rust);display:flex;align-items:center;justify-content:center;box-shadow:0 6px 16px rgba(180,95,46,.3);flex:none}
.playbar__mid{flex:1;min-width:0}
.playbar__label{font-size:12.5px;font-weight:700;color:var(--t2);margin-bottom:6px}
.playbar__track{height:4px;background:#F0E7D6;border-radius:99px;overflow:hidden}
.playbar__fill{width:0%;height:100%;background:var(--rust);border-radius:99px;transition:width .25s}
.playbar__speed{font-size:12px;font-weight:600;color:var(--muted);flex:none;padding:4px 6px;border-radius:8px}
.playbar__speed:hover{background:var(--soft)}

/* ---------- settings popover ---------- */
.settings{position:absolute;top:66px;right:22px;width:320px;background:var(--raised);border:1px solid #E8DECA;border-radius:16px;box-shadow:0 18px 50px rgba(60,45,25,.22);padding:20px 20px 22px;z-index:9}
.settings__arrow{position:absolute;top:-7px;right:22px;width:14px;height:14px;background:var(--raised);border-left:1px solid #E8DECA;border-top:1px solid #E8DECA;transform:rotate(45deg)}
.settings__title{font-family:var(--serif);font-size:18px;font-weight:700;margin-bottom:18px}
.settings__group{margin-bottom:20px}
.settings__glabel{font-size:12px;font-weight:700;color:var(--muted2);margin-bottom:8px}
.srow{display:flex;align-items:center;justify-content:space-between;gap:12px;padding:11px 0;border-top:1px solid var(--seg);cursor:pointer}
.srow--last{cursor:default}
.srow__t{font-size:14px;font-weight:600;color:var(--t1)}
.srow__s{font-size:11.5px;color:var(--muted);margin-top:2px}

.scrim{position:absolute;inset:58px 0 0;background:rgba(50,38,24,.10);z-index:5}

/* ---------- modal / toast ---------- */
.modal{position:fixed;inset:0;background:rgba(50,38,24,.32);display:flex;align-items:center;justify-content:center;z-index:40;padding:24px}
.modal__card{width:min(560px,100%);background:var(--raised);border-radius:18px;padding:24px;box-shadow:0 24px 60px rgba(40,28,12,.3)}
.modal__title{font-family:var(--serif);font-size:20px;font-weight:700;margin-bottom:14px}
.modal__area{width:100%;height:220px;resize:vertical;border:1px solid var(--chip);border-radius:12px;padding:14px;font-size:14px;line-height:1.6;font-family:var(--ui);color:var(--ink);background:#FFFDF8;outline:none}
.modal__area:focus{border-color:var(--rust)}
.modal__actions{display:flex;justify-content:flex-end;gap:10px;margin-top:16px}
.toast{position:fixed;left:50%;bottom:34px;transform:translateX(-50%);background:#332D24;color:#F6EFE2;font-size:13.5px;font-weight:600;padding:11px 20px;border-radius:99px;box-shadow:0 10px 30px rgba(40,28,12,.3);z-index:60;opacity:0;transition:opacity .2s,transform .2s}
.toast.show{opacity:1}

/* ---------- responsive: ≤720px → mobile ---------- */
@media (max-width:720px){
  .rbody{display:block;overflow:visible}
  .rscroll{padding:24px 20px 120px;justify-content:flex-start}
  .article__body{font-size:18px}
  .scrim{inset:0}

  /* lookup rail → bottom sheet that contains a persistent play bar */
  .rail{position:fixed;left:0;right:0;bottom:0;top:auto;width:auto;border-left:none;border-radius:22px 22px 0 0;box-shadow:0 -10px 36px rgba(60,45,25,.18);background:var(--raised);z-index:30;max-height:80vh}
  .rail__inner{max-height:0;overflow:hidden;padding:0 22px;transition:max-height .26s ease,padding .26s ease}
  .rail.is-open .rail__inner{max-height:58vh;overflow-y:auto;padding:10px 22px 6px}
  .sheet-handle{display:block;width:38px;height:4.5px;background:#DDD2BC;border-radius:99px;margin:0 auto 12px}
  .rail__label{display:none}
  .wordcard{border:none;padding:4px 0 8px;background:none}
  .wordcard-empty{display:none}
  .playbar{padding:14px 22px calc(16px + env(safe-area-inset-bottom))}

  /* settings → bottom sheet */
  .settings{position:fixed;top:auto;left:0;right:0;bottom:0;width:auto;border-radius:22px 22px 0 0;box-shadow:0 -12px 40px rgba(60,45,25,.2);padding:10px 22px calc(26px + env(safe-area-inset-bottom));z-index:35}
  .settings__arrow{display:none}
  .settings .sheet-handle{display:block;margin-bottom:16px}
  .scrim{z-index:29}
  .modal{padding:0;align-items:flex-end}
  .modal__card{width:100%;border-radius:18px 18px 0 0}
}
