:root {
  --red: #c8322b; --gold: #d9a441; --gold-2: #f0cf7a; --ink: #1f4a4f; --cream: #f4ecdd; --night: #141b24;
  --panel: rgba(20, 27, 36, .86); --line: rgba(217, 164, 65, .45); --text: #f4ecdd; --muted: #b9b2a6;
  --serif: "Noto Serif TC", serif; --sans: "Noto Sans TC", system-ui, sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--night); color: var(--text); font-family: var(--sans); }
#scene { position: fixed; inset: 0; width: 100vw; height: 100vh; touch-action: none; display: block; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
input { font: inherit; color: var(--night); background: var(--cream); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; width: 100%; }
[hidden] { display: none !important; }

.loading { position: fixed; inset: 0; display: grid; place-items: center; font-family: var(--serif); color: var(--gold-2); font-size: 18px; background: var(--night); z-index: 50; text-align: center; padding: 24px; }

/* 進殿 */
.entry { position: fixed; inset: 0; display: grid; place-items: end center; padding: 16px 16px calc(24px + var(--safe-b)); background: linear-gradient(to top, rgba(20,27,36,.92) 30%, rgba(20,27,36,0) 75%); z-index: 20; }
.entry-card { width: min(420px, 100%); text-align: center; display: grid; gap: 12px; }
.eyebrow { margin: 0; letter-spacing: .4em; color: var(--gold); font-size: 12px; }
.entry h1 { margin: 0; font-family: var(--serif); font-size: 34px; letter-spacing: .12em; color: var(--gold-2); text-shadow: 0 2px 14px rgba(0,0,0,.5); }
.slogan { margin: 0 0 6px; font-family: var(--serif); font-size: 17px; line-height: 1.8; color: var(--cream); }
.field { display: grid; gap: 6px; text-align: left; font-size: 13px; color: var(--muted); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 8px 0; }
.row.center { justify-content: center; }
.row.between { justify-content: space-between; }
.seg { padding: 8px 18px; border-radius: 999px; border: 1px solid var(--line); background: rgba(255,255,255,.04); min-height: 40px; }
.seg.on { background: var(--gold); color: var(--night); font-weight: 700; }
.swatch { width: 32px; height: 32px; border-radius: 50%; border: 2px solid rgba(255,255,255,.25); }
.swatch.on { border-color: var(--gold-2); box-shadow: 0 0 0 3px rgba(217,164,65,.35); }
.primary { background: linear-gradient(180deg, #e0b356, #c8902e); color: #2a1a08; font-weight: 700; border-radius: 12px; padding: 12px 18px; min-height: 46px; width: 100%; box-shadow: 0 4px 14px rgba(200,144,46,.3); }
.primary.big { font-size: 18px; letter-spacing: .3em; }
.ghost { border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; min-height: 44px; width: 100%; background: rgba(255,255,255,.04); }
.ghost.small { min-height: 36px; font-size: 13px; margin-top: 8px; }
.link { color: var(--gold-2); text-decoration: underline; font-size: 14px; }
.legal-links a { color: var(--gold-2); }
.note { margin: 6px 0 0; font-size: 12px; color: var(--muted); line-height: 1.6; }

/* HUD */
.top { position: fixed; top: 0; left: 0; right: 0; display: flex; gap: 10px; align-items: flex-start; justify-content: space-between; padding: calc(10px + var(--safe-t)) 12px 0; pointer-events: none; z-index: 5; flex-wrap: wrap; }
.top > * { pointer-events: auto; }
.brand { display: flex; align-items: baseline; gap: 8px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 6px 12px; }
.brand b { font-family: var(--serif); color: var(--gold-2); font-size: 18px; letter-spacing: .1em; }
.brand span { font-size: 12px; color: var(--muted); }
.badge { font-style: normal; font-size: 11px; background: var(--gold); color: var(--night); border-radius: 999px; padding: 1px 8px; }
.stats { display: flex; gap: 6px; }
.stats > div { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 4px 10px; display: grid; text-align: center; min-width: 64px; }
.stats span { font-size: 11px; color: var(--muted); }
.stats b { font-size: 14px; color: var(--gold-2); }
.right { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.online { display: flex; gap: 6px; align-items: center; background: var(--panel); border-radius: 999px; padding: 6px 12px; font-size: 13px; }
.online i { width: 8px; height: 8px; border-radius: 50%; background: #5fd38a; box-shadow: 0 0 8px #5fd38a; }
.online i.off { background: #c8322b; box-shadow: none; }
.pill { background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 6px 14px; font-size: 13px; min-height: 34px; }
.pill.gold { background: var(--gold); color: var(--night); font-weight: 700; }
.feed { position: fixed; left: 12px; top: calc(70px + var(--safe-t)); display: grid; gap: 6px; z-index: 4; pointer-events: none; max-width: 70vw; }
.feed-item { background: rgba(20,27,36,.62); border-left: 3px solid var(--gold); padding: 4px 10px; border-radius: 4px 10px 10px 4px; font-size: 13px; animation: in .3s ease; transition: opacity .6s; }
.feed-item.out { opacity: 0; }
.bar { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(12px + var(--safe-b)); display: flex; gap: 4px; background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 6px; z-index: 5; max-width: calc(100vw - 24px); }
.bar button { display: grid; justify-items: center; gap: 2px; padding: 4px 8px; min-width: 52px; border-radius: 12px; }
.bar button:active { background: rgba(255,255,255,.08); }
.bar i { font-style: normal; font-family: var(--serif); width: 34px; height: 34px; display: grid; place-items: center; border-radius: 50%; border: 1px solid var(--line); color: var(--gold-2); font-size: 16px; }
.bar button.gold i { background: var(--gold); color: var(--night); }
.bar span { font-size: 11px; color: var(--muted); }

/* 面板 */
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 4; }
.sheet { z-index: 25; position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(86px + var(--safe-b)); width: min(480px, calc(100vw - 24px)); max-height: min(calc(100vh - 170px), 720px); overflow: auto; background: var(--panel); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); border: 1px solid var(--line); border-radius: 18px; padding: 18px 16px 16px;  animation: up .25s ease; }
.sheet.dock { max-height: 52vh; }
.sheet .x { position: absolute; top: 8px; right: 10px; width: 36px; height: 36px; font-size: 24px; color: var(--muted); }
.sheet h2 { margin: 0 0 4px; font-family: var(--serif); color: var(--gold-2); font-size: 20px; letter-spacing: .08em; }
.sheet h3 { margin: 16px 0 8px; font-size: 15px; color: var(--cream); display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.sheet h3 small { font-size: 12px; color: var(--muted); font-weight: 400; }
.sheet h3 small.ok { color: #8fe0a8; }
.sheet label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); margin: 8px 0; }
.sub { margin: 0 0 8px; font-size: 13px; color: var(--muted); }
.card { border: 1px solid var(--line); border-radius: 14px; padding: 12px; margin: 10px 0; background: rgba(255,255,255,.03); }
.card h3 { margin-top: 0; }
.dev { background: rgba(200,50,43,.18); border: 1px dashed var(--red); padding: 8px 10px; border-radius: 10px; font-size: 12px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line); border-radius: 999px; padding: 4px 10px; font-size: 12px; }
.upsell { margin-top: 8px; }
.upsell .ghost { font-size: 13px; border-color: var(--gold); color: var(--gold-2); }

/* 自習 */
.study { text-align: center; }
.st-mode { display: flex; gap: 6px; justify-content: center; }
.st-mode button { border: 1px solid var(--line); border-radius: 999px; padding: 6px 14px; font-size: 13px; }
.st-mode button.on { background: var(--ink); border-color: var(--gold); color: var(--gold-2); }
.st-time { font-family: var(--serif); font-size: 64px; letter-spacing: .06em; color: var(--gold-2); margin: 8px 0 0; font-variant-numeric: tabular-nums; }
.st-state { font-size: 13px; color: var(--muted); min-height: 20px; }
.st-btns { display: grid; grid-template-columns: 2fr 1fr; gap: 8px; margin: 12px 0; }
.st-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.st-stats div { border: 1px solid var(--line); border-radius: 10px; padding: 6px; display: grid; }
.st-stats b { color: var(--gold-2); font-size: 15px; }
.st-stats span { font-size: 11px; color: var(--muted); }
.sheet.focus { background: rgba(14,20,28,.72); }

/* 燈牆 */
.lamp-list { list-style: none; padding: 0; margin: 10px 0 0; display: grid; gap: 4px; }
.lamp-list li { display: grid; grid-template-columns: 18px auto 1fr auto; gap: 8px; align-items: center; padding: 6px 8px; border-radius: 8px; background: rgba(255,255,255,.03); font-size: 13px; }
.lamp-list li.gold { background: rgba(217,164,65,.16); border: 1px solid var(--gold); }
.lamp-list li span { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lamp-list li em { font-style: normal; font-size: 12px; color: var(--gold-2); }
.lamp-list .empty { display: block; color: var(--muted); text-align: center; }
.lv { width: 12px; height: 16px; border-radius: 4px; display: block; background: #e06a3a; box-shadow: 0 0 6px #ff9a50; }
.lv2 { background: #e8823a; } .lv3 { background: #f09a3a; } .lv4 { background: #f5b54a; } .lv5 { background: #ffd06a; box-shadow: 0 0 10px #ffd06a; }

/* 籤 */
.lot { text-align: center; padding: 6px 0; }
.lot-no { font-family: var(--serif); color: var(--gold); letter-spacing: .1em; }
.poem { font-family: var(--serif); font-size: 20px; line-height: 2; margin: 12px 0; color: var(--cream); }
.tip { background: rgba(31,74,79,.6); border-radius: 10px; padding: 10px; font-size: 14px; }

/* 商店 */
.buys { display: grid; gap: 6px; }
.buys.three { grid-template-columns: repeat(3, 1fr); }
.buy { display: grid; grid-template-columns: 1fr auto; grid-template-rows: auto auto; text-align: left; gap: 2px 10px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; background: rgba(255,255,255,.03); }
.buy b { font-size: 14px; }
.buy span { font-size: 12px; color: var(--muted); grid-column: 1; }
.buy em { font-style: normal; grid-row: 1 / 3; grid-column: 2; align-self: center; color: var(--night); background: var(--gold); border-radius: 999px; padding: 4px 10px; font-weight: 700; font-size: 13px; }
.buys.three .buy { grid-template-columns: 1fr; text-align: center; }
.buys.three .buy em { grid-row: auto; grid-column: 1; justify-self: center; }
.buy.pts em { background: var(--ink); color: var(--gold-2); border: 1px solid var(--gold); }
.buy.own { opacity: .55; }
.buy:disabled { cursor: default; }

/* 衣櫃 */
.wards { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; }
.ward { border: 1px solid var(--line); border-radius: 12px; padding: 10px; display: grid; text-align: left; gap: 2px; }
.ward b { font-size: 14px; } .ward span { font-size: 12px; color: var(--muted); }
.ward.on { border-color: var(--gold); background: rgba(217,164,65,.14); }
.ward.lock { opacity: .6; }

/* 榜單 */
.rank { list-style: none; padding: 0; margin: 0; display: grid; gap: 4px; }
.rank li { display: grid; grid-template-columns: 26px 1fr auto; gap: 8px; align-items: center; padding: 6px 8px; border-radius: 8px; background: rgba(255,255,255,.03); font-size: 14px; }
.rank li i { font-style: normal; font-family: var(--serif); color: var(--gold); text-align: center; }
.rank li:nth-child(-n+3) i { color: var(--night); background: var(--gold); border-radius: 50%; width: 22px; height: 22px; display: grid; place-items: center; }
.rank li span { color: var(--muted); font-size: 13px; }
.rank .empty { display: block; color: var(--muted); text-align: center; }
.thanks { display: flex; flex-wrap: wrap; gap: 6px; }
.thanks span { border: 1px solid var(--line); border-radius: 999px; padding: 2px 10px; font-size: 13px; }
.code { font-family: ui-monospace, monospace; font-size: 26px; letter-spacing: .15em; text-align: center; color: var(--gold-2); margin-top: 8px; }
.steps { padding-left: 20px; line-height: 1.9; font-size: 14px; }

/* 提示 */
.toasts { position: fixed; left: 50%; transform: translateX(-50%); top: calc(76px + var(--safe-t)); display: grid; gap: 6px; z-index: 30; width: min(420px, calc(100vw - 32px)); pointer-events: none; }
.toast { background: rgba(20,27,36,.92); border: 1px solid var(--gold); border-radius: 12px; padding: 10px 14px; font-size: 14px; text-align: center; animation: in .25s ease; transition: opacity .4s, transform .4s; }
.toast.out { opacity: 0; transform: translateY(-6px); }
@keyframes in { from { opacity: 0; transform: translateY(-6px); } }
@keyframes up { from { opacity: 0; transform: translate(-50%, 16px); } }

@media (max-width: 640px) {
  .stats { order: 3; width: 100%; }
  .stats > div { flex: 1; min-width: 0; }
  .right .pill:not(.gold) { padding: 6px 10px; }
  .feed { top: calc(118px + var(--safe-t)); }
  .sheet { max-height: calc(100vh - 230px - var(--safe-t)); }
  .sheet.dock { max-height: 46vh; }
  .bar button { min-width: 46px; padding: 4px 4px; }
  .bar i { width: 30px; height: 30px; font-size: 14px; }
}

/* 光明文昌燈憑證 */
.lamp-cert { border: 2px solid var(--gold); border-radius: 14px; background: linear-gradient(180deg, rgba(122,28,22,.75), rgba(90,20,16,.75)); padding: 12px 14px; margin: 10px 0; }
.lc-head { font-family: var(--serif); color: var(--gold-2); text-align: center; letter-spacing: .2em; font-size: 16px; border-bottom: 1px solid var(--line); padding-bottom: 6px; margin-bottom: 8px; }
.lamp-cert dl { display: grid; grid-template-columns: 76px 1fr; gap: 4px 10px; margin: 0; font-size: 14px; }
.lamp-cert dt { color: var(--gold); }
.lamp-cert dd { margin: 0; color: #fff2c4; }
.goldtxt { color: var(--gold-2); }
.sheet label input:disabled { opacity: .7; }

.date-chips { margin-top: -2px; margin-bottom: 8px; }
.chip.on { background: var(--gold); color: var(--night); font-weight: 700; }

/* 科舉之路 */
.rank-now { text-align: center; border: 2px solid var(--gold); border-radius: 14px; padding: 12px; background: linear-gradient(180deg, rgba(31,74,79,.8), rgba(20,40,44,.8)); }
.rn-title { font-family: var(--serif); font-size: 34px; color: var(--gold-2); letter-spacing: .3em; }
.rn-sub { font-size: 13px; color: var(--muted); margin: 4px 0 8px; }
.rn-bar { height: 10px; border-radius: 99px; background: rgba(255,255,255,.08); overflow: hidden; }
.rn-bar i { display: block; height: 100%; background: linear-gradient(90deg, #c8902e, #f0cf7a); border-radius: 99px; }
.rank-list { list-style: none; padding: 0; margin: 12px 0 0; display: grid; gap: 4px; }
.rank-list li { display: grid; grid-template-columns: 56px 1fr auto; gap: 8px; align-items: center; padding: 6px 10px; border-radius: 8px; background: rgba(255,255,255,.03); font-size: 14px; }
.rank-list li b { font-family: var(--serif); }
.rank-list li span { color: var(--muted); font-size: 12px; }
.rank-list li.done b { color: var(--gold); }
.rank-list li.cur { border: 1px solid var(--gold); background: rgba(217,164,65,.14); }
.rank-list li.cur em { color: var(--gold-2); font-style: normal; font-size: 12px; }
.rank-list li.future { opacity: .6; grid-template-columns: 1fr; }
.chaps { display: grid; gap: 6px; }
.chap { text-align: left; border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; font-size: 14px; }
.chap.lock { opacity: .5; }
.story { padding: 4px 2px; }
.st-chap { font-family: var(--serif); color: var(--gold); font-size: 13px; letter-spacing: .15em; }
.st-who { display: inline-block; margin-top: 10px; background: var(--ink); border: 1px solid var(--gold); color: var(--gold-2); border-radius: 8px 8px 0 0; padding: 2px 12px; font-size: 14px; }
.st-who.momo { background: #7a1c16; }
.st-text { margin: 0; background: rgba(255,255,255,.05); border: 1px solid var(--line); border-radius: 0 12px 12px 12px; padding: 14px; font-size: 16px; line-height: 1.8; min-height: 80px; }
.st-foot { display: flex; align-items: center; gap: 12px; margin-top: 12px; }
.st-foot span { color: var(--muted); font-size: 12px; white-space: nowrap; }

.mascot-text { font-size: 15px; line-height: 1.9; margin: 8px 0 0; }

.entry-links { gap: 4px; margin: 0; }
.entry-links .sep { color: var(--muted); }
.acct-name { font-family: var(--serif); color: var(--gold-2); font-size: 20px; }

.hall-domain { display: inline-block; background: rgba(200,50,43,.25); border: 1px solid var(--red); color: #ffd0c8; border-radius: 999px; padding: 3px 12px; font-size: 13px; margin: 4px 0; }

/* 聊天 */
.chatlog { position: fixed; left: 12px; bottom: calc(92px + var(--safe-b)); width: min(320px, 70vw); display: grid; gap: 4px; z-index: 4; pointer-events: none; }
.chatlog div { background: rgba(20,27,36,.7); border-radius: 10px; padding: 4px 10px; font-size: 13px; animation: in .25s ease; transition: opacity .8s; }
.chatlog div b { color: var(--gold-2); margin-right: 6px; }
.chatlog div.out { opacity: 0; }
.chatbar { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(86px + var(--safe-b)); width: min(480px, calc(100vw - 24px)); background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 8px; z-index: 6; }
.chatbar .row { margin: 6px 0 0; flex-wrap: nowrap; }
.chatbar .primary { width: auto; min-height: 42px; padding: 8px 16px; }
.chatbar .quick { display: flex; gap: 6px; overflow-x: auto; }
.chatbar .quick button { white-space: nowrap; border: 1px solid var(--line); border-radius: 999px; padding: 4px 10px; font-size: 12px; }
.go-list { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; }
.go-list button { border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; text-align: left; font-size: 14px; }
.go-list button small { display: block; color: var(--muted); font-size: 11px; }
.go-list.floors { grid-template-columns: 1fr; }
.go-list button.on { border-color: var(--gold, #d9a441); background: rgba(217,164,65,.12); }
.go-h { grid-column: 1 / -1; color: var(--gold); font-size: 13px; margin-top: 6px; }

.check { display: flex; align-items: center; gap: 6px; font-size: 13px; margin: 8px 0; }
.check input { width: auto; }
.donate label { display: block; margin-top: 8px; }
/* 第 86 輪 D：樂捐面板說清楚得到什麼、金額按鈕手機好按 */
.donate .chips { gap: 8px; margin-bottom: 8px; }
.donate .chip { min-height: 44px; min-width: 64px; padding: 0 14px; font-size: 15px; }
.dnGet { display: grid; gap: 4px; background: rgba(217,164,65,.12); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; margin-bottom: 10px; font-size: 15px; line-height: 1.5; }
.dnGet b { color: var(--gold-2); }
/* 面板打開時收起左側樓層／今日／活動按鈕，避免蓋住面板文字（文昌殿專用 style.css） */
body:has(#sheet:not([hidden])) .flbar, body:has(#sheet:not([hidden])) .wcToday, body:has(#sheet:not([hidden])) .tevBtn { visibility: hidden; }
