/* 字靈搜神記（原名形音義抓寶）：沿用滄浪闖關的水墨配色與字型 */
:root{
  --bg:#EAF0EE; --surface:#F8FAF9; --ink:#1B2725; --muted:#566764; --line:#C6D1CD;
  --river:#2E6C8C; --frost:#DBE5E9;
  --good:#2A774B; --bad:#AE4337; --gold:#8C6A0E; --warn:#9A5B12;
  --r1:#566764; --r2:#2E6C8C; --r3:#8C6A0E; --r4:#B2392C;
  --display:"Noto Serif TC","Songti TC","PMingLiU",serif;
  --body:"Noto Sans TC","PingFang TC","Microsoft JhengHei",sans-serif;
  --inkop:1;
}
@media (prefers-color-scheme: dark){
  :root:not([data-theme="light"]){
    --bg:#0E1615; --surface:#16201E; --ink:#E3EBE9; --muted:#97A8A4; --line:#2A3835;
    --river:#5DA5C9; --frost:#1A272B; --good:#67C08A; --bad:#E07A6C; --gold:#DDB349; --warn:#E0A05A;
    --r1:#97A8A4; --r2:#5DA5C9; --r3:#DDB349; --r4:#E8705F;
    --inkop:.25; color-scheme:dark;
  }
}
:root[data-theme="dark"]{
  --bg:#0E1615; --surface:#16201E; --ink:#E3EBE9; --muted:#97A8A4; --line:#2A3835;
  --river:#5DA5C9; --frost:#1A272B; --good:#67C08A; --bad:#E07A6C; --gold:#DDB349; --warn:#E0A05A;
  --r1:#97A8A4; --r2:#5DA5C9; --r3:#DDB349; --r4:#E8705F;
  --inkop:.25; color-scheme:dark;
}
*{box-sizing:border-box}
html{min-height:100%}
body{
  margin:0 auto; max-width:760px; min-height:100vh; background:var(--bg); color:var(--ink);
  font-family:var(--body); font-size:18px; line-height:1.6;
  padding-left:max(16px, env(safe-area-inset-left, 0px)); padding-right:max(16px, env(safe-area-inset-right, 0px));
  padding-block:12px 40px; position:relative;
}
body::before{content:""; position:fixed; inset:0; background:url("../assets/bg-ink.svg") center bottom/cover no-repeat; opacity:var(--inkop); pointer-events:none; z-index:-1}
button{font:inherit; color:var(--ink); background:var(--surface); border:1px solid var(--line); border-radius:10px; padding:.5em 1em; cursor:pointer; touch-action:manipulation}
button:hover:not([disabled]){border-color:var(--ink)}
button:focus-visible, select:focus-visible, input:focus-visible{outline:3px solid var(--river); outline-offset:2px}
button[disabled]{opacity:.45; cursor:not-allowed}
.primary{background:var(--ink); color:var(--bg); border-color:var(--ink); font-weight:500}
.danger{color:var(--bad); border-color:var(--bad)}
.ghost{background:transparent; font-size:.9rem; padding:.3em .8em}
select, input{font:inherit; padding:.4em .6em; border-radius:8px; border:1px solid var(--line); background:var(--surface); color:var(--ink); max-width:100%}
h1,h2,h3{font-family:var(--display); font-weight:700; margin:0; line-height:1.3}
.muted{color:var(--muted)} .small{font-size:.9rem} .center{text-align:center}
.hidden{display:none !important}
.card{background:var(--surface); border:1px solid var(--line); border-radius:16px; padding:16px; display:grid; gap:10px}
.card p{margin:0}
.row{display:grid; gap:10px} .row.wrap{display:flex; flex-wrap:wrap; gap:8px}
.wide{width:100%; font-size:1.15rem; padding:.7em 1em; border-radius:12px}
.big{font-family:var(--display); font-weight:700; font-size:1.35rem; margin:0}
main{display:flex; flex-direction:column; gap:14px}
.view{display:flex; flex-direction:column; gap:14px}
.sec{font-size:1.2rem; margin-top:4px}

/* 頂列 */
.top{display:flex; justify-content:space-between; align-items:center; gap:12px; flex-wrap:wrap}
.top h1{font-size:1.6rem; letter-spacing:.1em}
.purse{display:flex; gap:14px; font-size:1rem; align-items:center}
.purse b{font-variant-numeric:tabular-nums; font-size:1.15rem}
.coin{display:inline-block; width:1em; height:1em; border-radius:50%; background:var(--gold); vertical-align:-.12em; margin-right:4px; position:relative}
.coin::after{content:""; position:absolute; inset:32%; background:var(--surface); border-radius:2px}
.rank{margin:2px 0 10px; color:var(--muted); font-size:.95rem}
.rank b{color:var(--ink); font-family:var(--display)}
.tabs{display:grid; grid-template-columns:repeat(5, minmax(0,1fr)); gap:6px; margin-bottom:14px; position:sticky; top:0; z-index:5; background:var(--bg); padding:6px 0}
.tabs button{padding:.5em .2em; font-size:1rem; border-radius:10px}
.tabs button.cur{background:var(--ink); color:var(--bg); border-color:var(--ink)}

/* 稀有度 */
.r{display:inline-block; font-size:.85rem; font-weight:700; padding:.1em .7em; border-radius:999px; color:#fff; white-space:nowrap}
.r1{background:var(--r1)} .r2{background:var(--r2)} .r3{background:var(--r3)} .r4{background:var(--r4)}
.legend{display:flex; flex-wrap:wrap; gap:6px}
.kindtag{font-size:.85rem; border:1px solid var(--line); border-radius:999px; padding:.05em .7em; background:var(--surface)}

/* 獵場 */
.grounds{display:grid; grid-template-columns:repeat(2, minmax(0,1fr)); gap:10px}
.ground{display:grid; gap:4px; text-align:left; padding:14px; border-radius:14px; border-width:2px; min-width:0; min-height:120px;
  background-color:var(--surface); background-size:cover; background-position:center}
.ground .gname{font-family:var(--display); font-weight:700; font-size:1.25rem}
.ground .gdesc{color:var(--muted); font-size:.88rem; line-height:1.45}
.ground .gnum{font-size:.85rem; color:var(--muted)}
.ground.g-音{border-color:var(--river)} .ground.g-形{border-color:var(--good)} .ground.g-義{border-color:var(--gold)}
.ground.g-殿{border-color:var(--r4)} .ground.g-亂{border-color:var(--ink)} .ground.g-逃{border-color:var(--bad)}
.filters label{display:grid; gap:4px; font-size:.95rem}
.filters .chk{display:flex; gap:8px; align-items:center}
.chk input{width:1.2em; height:1.2em}

/* 遭遇 */
.encbar{display:flex; justify-content:space-between; align-items:center; gap:8px}
.combo{font-weight:700; color:var(--gold)}
.spirit-stage{position:relative; height:230px; display:grid; place-items:center; border-radius:18px; overflow:hidden;
  background:radial-gradient(circle at 50% 55%, color-mix(in srgb, var(--rc, var(--r1)) 18%, var(--surface)) 0%, var(--surface) 70%);
  border:1px solid var(--line)}
.spirit-stage .ring{position:absolute; width:150px; height:150px; border-radius:50%;
  border:7px solid var(--rc, var(--r1)); border-right-color:transparent; opacity:.55; transform:rotate(-30deg);
  animation:spin 9s linear infinite}
.spirit-box{position:absolute; inset:0; display:flex; justify-content:center; align-items:flex-end; padding-bottom:3%; pointer-events:none}
.spirit-img{height:90%; width:auto; max-width:92%; object-fit:contain; animation:float 3s ease-in-out infinite}
.spirit-stage:has(.spirit-img:not(.hidden)) .ring{display:none}
.spirit-stage:has(.spirit-img:not(.hidden)) .glyph{position:absolute; right:12px; bottom:12px; font-size:48px; padding:6px 10px;
  background:color-mix(in srgb, var(--surface) 88%, transparent); border:2px solid var(--rc); border-radius:12px; animation:none}
.spirit-stage:has(.spirit-img:not(.hidden)) .glyph.zy{font-size:26px}
.spirit-stage.fled .spirit-img{animation:flee .9s ease-in forwards}
.hero{width:100%; aspect-ratio:16/9; object-fit:cover; border-radius:16px; border:1px solid var(--line)}
.glyph{position:relative; font-family:var(--display); font-weight:900; font-size:88px; line-height:1; color:var(--rc, var(--ink));
  animation:float 3s ease-in-out infinite; text-shadow:0 3px 0 color-mix(in srgb, var(--rc) 25%, transparent)}
.glyph.zy{font-size:44px; letter-spacing:.05em}
.spirit-meta{position:absolute; left:10px; top:10px; display:flex; gap:6px}
.seal{position:absolute; right:22%; top:30%; width:72px; height:72px; display:grid; place-items:center; font-family:var(--display);
  font-weight:900; font-size:44px; color:#fff; background:var(--r4); border-radius:12px; transform:rotate(-12deg) scale(0); opacity:0}
.spirit-stage.caught .seal{animation:stamp .55s cubic-bezier(.2,1.6,.4,1) forwards}
.spirit-stage.fled .glyph{animation:flee .9s ease-in forwards}
.spirit-stage.fled .ring{animation:none; opacity:.15}
@keyframes spin{to{transform:rotate(330deg)}}
@keyframes float{0%,100%{transform:translateY(0)}50%{transform:translateY(-8px)}}
@keyframes stamp{0%{transform:rotate(-12deg) scale(2.4); opacity:0}100%{transform:rotate(-12deg) scale(1); opacity:.92}}
@keyframes flee{to{transform:translate(160px,-70px) scale(.3); opacity:0}}
@media (prefers-reduced-motion: reduce){ .ring,.glyph{animation:none !important} }

.qhead{display:flex; flex-wrap:wrap; gap:6px 10px; align-items:center}
.src{color:var(--muted); font-size:.9rem}
.tag{display:inline-block; font-size:.85rem; font-weight:700; padding:.1em .7em; border-radius:999px; color:#fff}
.tag.multi{background:var(--bad)}
.stem{font-size:1.15rem; font-weight:500; line-height:1.65; overflow-wrap:anywhere}
.opts{display:grid; gap:10px}
.opt{display:flex; gap:12px; align-items:flex-start; text-align:left; padding:13px 14px; border-radius:12px; border-width:2px;
  font-size:1.1rem; line-height:1.5; min-height:54px; overflow-wrap:anywhere}
.opt .k{font-weight:700; color:var(--muted); min-width:1.3em}
.opt.sel{border-color:var(--river); background:color-mix(in srgb, var(--river) 14%, var(--surface))}
.opt.right{border-color:var(--good); background:color-mix(in srgb, var(--good) 14%, var(--surface))}
.opt.wrong{border-color:var(--bad); background:color-mix(in srgb, var(--bad) 12%, var(--surface))}
.opt.gone{opacity:.3; text-decoration:line-through}
.opt[disabled]{opacity:1; cursor:default}
.opt.gone[disabled]{opacity:.3}
u{text-decoration-thickness:2px; text-underline-offset:3px}
.tools{display:flex; flex-wrap:wrap; gap:8px; align-items:center}
.tools button{font-size:.95rem}
.tools #q-submit{margin-left:auto}
.verdict{font-family:var(--display); font-weight:700; font-size:1.4rem; margin:4px 0}
.verdict.ok{color:var(--good)} .verdict.no{color:var(--bad)} .verdict.part{color:var(--gold)}
.exp{background:var(--frost); border-radius:10px; padding:12px 14px; line-height:1.65; font-size:1rem; overflow-wrap:anywhere}
#q-result{display:grid; gap:10px}

/* 結算 */
.sumgrid{display:grid; grid-template-columns:repeat(3, minmax(0,1fr)); gap:8px}
.sumgrid div{background:var(--frost); border-radius:10px; padding:8px}
.sumgrid b{display:block; font-family:var(--display); font-size:1.5rem}
.review{display:grid; gap:10px}
.mini{display:grid; grid-template-columns:auto minmax(0,1fr); gap:10px; align-items:center; padding:10px 12px}
.mini .mg{font-family:var(--display); font-weight:900; font-size:1.8rem; width:48px; text-align:center; color:var(--rc)}
.mini .mt{min-width:0; font-size:.95rem}
.mini .mt .s{display:block; overflow:hidden; text-overflow:ellipsis; white-space:nowrap}

/* 圖鑑 */
.dexstat{display:grid; grid-template-columns:repeat(4, minmax(0,1fr)); gap:6px; text-align:center; font-size:.85rem}
.dexstat b{display:block; font-size:1.1rem; font-family:var(--display)}
.dex{display:grid; grid-template-columns:repeat(auto-fill, minmax(76px, 1fr)); gap:8px}
.cell{aspect-ratio:1; display:grid; place-items:center; border-radius:12px; border:2px solid var(--line); background:var(--surface);
  font-family:var(--display); font-weight:900; font-size:1.9rem; position:relative; padding:0; color:var(--rc)}
.cell.zy{font-size:.95rem}
.cell.no{color:var(--line); border-style:dashed}
.cell.esc{border-color:var(--bad); border-style:dashed; color:var(--bad)}
.cell .cap{position:absolute; bottom:3px; left:0; right:0; font-family:var(--body); font-weight:500; font-size:.62rem; color:var(--muted); text-align:center; white-space:nowrap; overflow:hidden}
.cell .st{position:absolute; top:2px; right:5px; font-size:.65rem; color:var(--gold); font-family:var(--body)}
.badges{display:flex; flex-wrap:wrap; gap:6px; max-height:7.6em; overflow:auto}
.badges:empty{display:none}
.badge{font-size:.8rem; padding:.1em .6em; border-radius:8px; border:1px solid var(--r4); color:var(--r4); background:var(--surface)}
.badge.off{border-color:var(--line); color:var(--muted); border-style:dashed}

/* 商店 */
.shop{display:grid; gap:10px}
.item{display:grid; grid-template-columns:minmax(0,1fr) auto; gap:4px 12px; align-items:center}
.item h3{font-size:1.15rem}
.item p{grid-column:1; color:var(--muted); font-size:.92rem}
.item button{grid-row:1 / span 2; grid-column:2; white-space:nowrap}

/* 戰績 */
.bars{display:grid; gap:8px}
.bar{display:grid; grid-template-columns:3.5em minmax(0,1fr) 5.5em; gap:8px; align-items:center; font-size:.95rem}
.track{height:14px; border-radius:7px; background:var(--line); overflow:hidden}
.fill{height:100%; background:var(--good); border-radius:7px}

.toast{position:fixed; left:50%; bottom:24px; transform:translateX(-50%) translateY(120px); background:var(--ink); color:var(--bg);
  padding:.6em 1.2em; border-radius:999px; font-weight:500; transition:transform .3s; z-index:20; max-width:calc(100% - 32px); text-align:center}
.toast.on{transform:translateX(-50%) translateY(0)}
.modal{position:fixed; inset:0; background:color-mix(in srgb, var(--ink) 55%, transparent); display:grid; place-items:center; padding:16px; z-index:30}
.mbody{max-width:640px; width:100%; max-height:85vh; overflow:auto}
@media (max-width:420px){
  body{font-size:17px}
  .glyph{font-size:72px}
  .grounds{grid-template-columns:minmax(0,1fr)}
  .dexstat{grid-template-columns:repeat(2, minmax(0,1fr))}
}

/* ---------- 主角形象與升級劇情 ---------- */
.rank{display:flex; align-items:center; gap:10px}
.avatar{width:44px; height:44px; border-radius:50%; object-fit:cover; object-position:top; border:2px solid var(--gold); background:var(--surface); flex:none}
.soon{color:var(--r4); font-weight:700}
.mbody.story{background:linear-gradient(var(--surface), color-mix(in srgb, var(--gold) 8%, var(--surface))); border:2px solid var(--gold); text-align:left}
.scroll-story .herald{font-family:var(--display); font-weight:900; font-size:1.5rem; color:var(--r4); text-align:center; letter-spacing:.3em; margin:0}
.hero-stage{position:relative; height:240px; display:flex; justify-content:center; align-items:flex-end; margin:4px 0}
.hero-stage img{height:100%; object-fit:contain}
.hero-now{animation:heroIn .9s .35s cubic-bezier(.2,1.3,.4,1) both; filter:drop-shadow(0 6px 12px color-mix(in srgb, var(--gold) 45%, transparent))}
.hero-prev{position:absolute; animation:heroOut .7s ease-in both; opacity:.5}
.hero-prev + .hero-now{position:relative}
@keyframes heroIn{0%{transform:scale(.6) translateY(30px); opacity:0}100%{transform:none; opacity:1}}
@keyframes heroOut{0%{opacity:.9; transform:none}100%{opacity:0; transform:scale(1.15); filter:blur(6px)}}
.newrank{text-align:center; margin:0}
.newrank small{display:block; color:var(--muted)}
.newrank b{font-family:var(--display); font-size:2.6rem; color:var(--gold); animation:stamp .6s .9s cubic-bezier(.2,1.6,.4,1) both; display:inline-block}
.ladder{display:flex; flex-wrap:wrap; justify-content:center; gap:4px; list-style:none; padding:0; margin:8px 0 12px; font-size:.8rem}
.ladder li{padding:.1em .5em; border:1px dashed var(--line); border-radius:8px; color:var(--muted)}
.ladder li.past{border-style:solid; color:var(--ink)}
.ladder li.now{border:2px solid var(--r4); color:var(--r4); font-weight:700}
.scroll-story h3{text-align:center}
.scroll-story .scene{text-align:center; color:var(--muted); font-size:.9rem; margin:0 0 .5em}
.lore{border-left:4px solid var(--river); background:var(--frost); padding:.5em .8em; border-radius:6px; margin:.8em 0; font-size:.95rem}
.lore b{display:block; color:var(--river)}
.gift{color:var(--gold); font-weight:700; text-align:center}
.me-hero{display:flex; align-items:flex-end; gap:12px}
.me-portrait{width:110px; height:140px; object-fit:contain}
.road{display:grid; grid-template-columns:repeat(auto-fill, minmax(96px, 1fr)); gap:8px; margin:.5em 0 1em}
.road button{display:flex; flex-direction:column; align-items:center; padding:.4em; font-family:var(--display); font-weight:700}
.road button small{font-family:var(--body); font-weight:400; font-size:.72rem; color:var(--muted)}
.road button.now{border:2px solid var(--r4)}
.road-img{width:64px; height:80px; object-fit:contain}
.road-lock{width:64px; height:80px; display:grid; place-items:center; font-size:2rem; color:var(--line)}
@media (prefers-reduced-motion: reduce){.hero-now,.hero-prev,.newrank b{animation:none}}
.hero-stage:empty{display:none}
.mbody.story{overflow-x:hidden}

/* ---------- 故事頁 ---------- */
.goto{text-align:center; color:var(--river); font-weight:700; margin:.2em 0}
.story-intro{display:flow-root}
.story-hero{float:right; width:84px; margin:0 0 6px 10px}
.cast{display:grid; gap:8px; margin-bottom:12px}
.cast-card{display:flex; gap:12px; align-items:center; background:var(--surface); border:1px solid var(--line); border-radius:12px; padding:8px 12px}
.cast-card img{width:56px; height:72px; object-fit:contain; flex:none}
.cast-card p{margin:0; font-size:.92rem; color:var(--muted)}
.cast-ink{width:56px; height:56px; flex:none; display:grid; place-items:center; border-radius:50%; background:var(--ink); color:var(--bg); font-family:var(--display); font-size:1.6rem; font-weight:900}
.chaps{display:grid; gap:8px}
.chap{display:flex; gap:12px; align-items:center; text-align:left; padding:6px 12px}
.chap b{display:block; font-family:var(--display)}
.chap small{color:var(--muted)}
.chap-img{width:48px; height:64px; object-fit:contain; flex:none}
.chap .road-lock{width:48px; height:64px; font-size:1.5rem}

/* 墨寶鋪道具圖 */
.item .item-img{width:72px; height:72px; object-fit:contain; flex:none}
.item .item-txt{flex:1; min-width:0}
.item{grid-template-columns:auto minmax(0,1fr) auto}
.item p{grid-column:auto}
.item button{grid-row:auto; grid-column:auto}
.item{grid-template-columns:60px minmax(0,1fr); gap:6px 12px}
.item .item-img{width:60px; height:60px; grid-row:1 / span 2}
.item button{grid-column:2; justify-self:start}
@media (min-width:520px){
  .item{grid-template-columns:72px minmax(0,1fr) auto}
  .item .item-img{width:72px; height:72px; grid-row:auto}
  .item button{grid-column:3}
}
.cast-card img{width:64px; height:84px}

/* 2026-11 審查：手機點擊區、分頁列、注音不拆行 */
#enc-quit{min-height:44px}
.chk input[type=checkbox]{width:24px; height:24px; vertical-align:middle}
.nw{white-space:nowrap}
@media (max-width:420px){ .tabs button{font-size:.9rem; white-space:nowrap} }
@media (max-width:360px){ .tabs button{font-size:.78rem; padding:.5em 0} }
