:root {
  --glass: rgba(10, 12, 16, .56);
  --glass-strong: rgba(10, 12, 16, .82);
  --line: rgba(255, 255, 255, .13);
  --text: #f4f6fa;
  --dim: rgba(255, 255, 255, .34);
  --bad: #ff6b6b;
  --good: #8ff0b0;
  --glow: 0 0 16px rgba(255, 255, 255, .45);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: #0b0d10; color: var(--text); font-family: "Noto Sans TC", "PingFang TC", sans-serif; overflow: hidden; }
[hidden] { display: none !important; }
#scene { position: fixed; inset: 0; }
#scene canvas { display: block; }

.glass {
  background: var(--glass); border: 1px solid var(--line); border-radius: 18px;
  backdrop-filter: blur(18px) saturate(1.2); -webkit-backdrop-filter: blur(18px) saturate(1.2);
  box-shadow: 0 12px 44px rgba(0, 0, 0, .35), inset 0 1px 0 rgba(255, 255, 255, .08);
}
button { font: inherit; color: var(--text); background: rgba(255, 255, 255, .06); border: 1px solid var(--line); border-radius: 12px; padding: 10px 18px; cursor: pointer; transition: background .25s, box-shadow .25s, border-color .25s, color .25s, opacity .3s, transform .15s; }
button:hover { background: rgba(255, 255, 255, .12); }
button:active { transform: scale(.98); }
button.on { border-color: rgba(255, 255, 255, .75); box-shadow: var(--glow); background: rgba(255, 255, 255, .14); }
button:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
button.primary { background: #fff; color: #0b0d10; border: 0; font-weight: 700; box-shadow: 0 0 30px rgba(255, 255, 255, .4); }
button.primary:hover { background: #e9edf3; }

/* ── HUD：打字時自動淡出（Monkeytype 的專注模式） ── */
#hud { position: fixed; top: 20px; left: 20px; right: 80px; display: flex; gap: 12px; align-items: stretch; pointer-events: none; }
#hud > * { pointer-events: auto; }
/* 打字時 HUD 一直顯示（不淡出） */
.hud-l { padding: 12px 18px; }
.brand { font-weight: 900; font-size: 19px; letter-spacing: .1em; text-shadow: var(--glow); }
.tags { display: flex; gap: 6px; margin-top: 6px; }
.tags span { font-size: 13px; padding: 2px 9px; border-radius: 99px; background: rgba(255, 255, 255, .08); border: 1px solid var(--line); }
.tags span:empty { display: none; }
.hud-r { padding: 10px 14px; display: flex; gap: 16px; align-items: center; }
.stat { text-align: center; min-width: 58px; }
.stat b { display: block; font-size: 24px; font-variant-numeric: tabular-nums; text-shadow: var(--glow); }
.stat span { font-size: 12px; color: var(--dim); }
.icon-btn { padding: 7px 12px; font-size: 14px; }

/* ── 打字區 ── */
#typer { position: fixed; left: 50%; bottom: 5vh; transform: translateX(-50%); width: min(960px, calc(100vw - 48px)); padding: 16px 30px 26px; transition: opacity .4s; }
.typer-head { display: flex; justify-content: space-between; align-items: center; font-size: 14px; margin-bottom: 12px; color: rgba(255, 255, 255, .7); transition: opacity .6s; }
body.focus .typer-head { opacity: .35; }
#step-name { font-weight: 700; letter-spacing: .08em; }
#step-name.repair { color: #ffb86b; text-shadow: 0 0 12px rgba(255, 184, 107, .6); }
#dots { display: flex; gap: 6px; }
#dots i { width: 7px; height: 7px; border-radius: 50%; background: rgba(255, 255, 255, .16); transition: background .4s, box-shadow .4s, transform .4s; }
#dots i.done { background: rgba(255, 255, 255, .7); }
#dots i.now { background: #fff; box-shadow: 0 0 10px #fff; transform: scale(1.3); }

#words { --combo: 0; position: relative; font-size: 34px; line-height: 1.75; letter-spacing: .07em; min-height: 60px; cursor: text; word-break: break-all; user-select: none; }
#words .ch { position: relative; display: inline-block; color: var(--dim); transition: color .22s ease, text-shadow .3s ease; }
#words .ch.enter { animation: chIn .45s cubic-bezier(.2, .8, .2, 1) both; }
#words .ch.ok { color: #fff; text-shadow: 0 0 calc(8px + var(--combo) * 12px) rgba(255, 255, 255, calc(.35 + var(--combo) * .35)); animation: lit .4s ease-out; }
#words .ch.bad { color: var(--bad); text-shadow: 0 0 12px rgba(255, 107, 107, .55); animation: pop .25s ease-out; }
#words .ch.bad::after { content: attr(data-want); position: absolute; left: 50%; top: -.62em; transform: translateX(-50%); font-size: .42em; line-height: 1; letter-spacing: 0; color: rgba(255, 255, 255, .7); }
@keyframes chIn { from { opacity: 0; transform: translateY(10px); filter: blur(4px); } }
@keyframes lit { from { text-shadow: 0 0 26px #fff, 0 0 4px #fff; transform: translateY(-3px); } }
@keyframes pop { 40% { transform: scale(1.18); } }
#words.shake { animation: shake .28s ease; }
@keyframes shake { 20% { transform: translateX(-4px); } 50% { transform: translateX(3px); } 80% { transform: translateX(-1px); } }

.caret { position: absolute; left: 0; top: 0; width: 3px; border-radius: 2px; background: #fff;
  box-shadow: 0 0 calc(6px + var(--combo) * 22px) rgba(255, 255, 255, calc(.55 + var(--combo) * .45));
  transition: transform .13s cubic-bezier(.2, .8, .2, 1), box-shadow .3s; animation: blink 1.1s ease-in-out infinite; pointer-events: none; }
body.focus .caret { animation: none; }
.caret.composing { opacity: 0; }
@keyframes blink { 0%, 45% { opacity: 1; } 60%, 90% { opacity: .15; } }
.comp { position: absolute; left: 0; top: 0; white-space: nowrap; pointer-events: none; color: #fff; text-shadow: 0 0 14px rgba(255, 255, 255, .85), 0 0 3px rgba(255, 255, 255, .9); border-bottom: 2px solid rgba(255, 255, 255, .85); }
.comp:empty { display: none; }
#words .ch.cmp { color: transparent; text-shadow: none; }
#words .ch.cmp::before { content: attr(data-c); position: absolute; left: 0; top: 0; width: 100%; color: #fff; text-shadow: 0 0 14px rgba(255, 255, 255, .85), 0 0 3px rgba(255, 255, 255, .9); border-bottom: 2px solid rgba(255, 255, 255, .85); }
#inp { position: absolute; left: 0; top: 0; width: 24px; height: 40px; opacity: 0; border: 0; padding: 0; font-size: 30px; pointer-events: none; caret-color: transparent; }

.spark { position: fixed; left: 0; top: 0; width: 10px; height: 10px; margin: -5px 0 0 -5px; border-radius: 50%; background: #fff; box-shadow: 0 0 12px 4px rgba(255, 255, 255, .8), 0 0 30px 8px rgba(160, 200, 255, .35); pointer-events: none; z-index: 5; }

/* ── 颱風時的損壞標籤 ── */
#labels { position: fixed; inset: 0; pointer-events: none; }
.dmg { position: absolute; left: 0; top: 0; padding: 6px 12px; border-radius: 10px; font-size: 14px; font-weight: 700; white-space: nowrap; color: #fff;
  background: rgba(120, 18, 18, .72); border: 1px solid rgba(255, 120, 120, .6); box-shadow: 0 0 18px rgba(255, 80, 80, .45);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); opacity: 0; transition: opacity .4s; }
.dmg.show { opacity: 1; animation: dmgIn .45s cubic-bezier(.2, .9, .3, 1.3); }
.dmg em { font-style: normal; font-weight: 400; opacity: .85; margin-left: 6px; }
@keyframes dmgIn { from { transform: var(--pos) scale(.6); } }

#toast { position: fixed; left: 50%; top: 20%; transform: translate(-50%, -50%); font-size: 34px; font-weight: 900; letter-spacing: .16em; text-shadow: 0 0 30px rgba(255, 255, 255, .7); pointer-events: none; opacity: 0; transition: opacity .5s, transform .5s; white-space: nowrap; }
#toast.show { opacity: 1; transform: translate(-50%, -60%); }

/* ── 開始／結算 ── */
.overlay { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(5, 6, 8, .32); z-index: 10; }
.card { padding: 34px 40px; width: min(520px, calc(100vw - 48px)); text-align: center; animation: cardIn .5s cubic-bezier(.2, .8, .2, 1); }
.card.wide { width: min(760px, calc(100vw - 48px)); }
@keyframes cardIn { from { opacity: 0; transform: translateY(16px) scale(.98); } }
.card h1 { margin: 0; font-size: 42px; font-weight: 900; letter-spacing: .14em; text-shadow: 0 0 24px rgba(255, 255, 255, .5); }
.card h1.small { font-size: 26px; }
.card .sub { margin: 6px 0 26px; font-size: 16px; color: rgba(255, 255, 255, .6); letter-spacing: .2em; }
#buildings { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; margin: 0 0 18px; }
.bcard { display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 12px 4px; border-radius: 14px; }
.bcard b { font-size: 17px; letter-spacing: .08em; }
.bcard .lv { font-size: 10px; letter-spacing: 2px; opacity: .8; }
.bcard .meta { font-size: 12px; color: rgba(255, 255, 255, .6); white-space: nowrap; }
.card:has(#buildings) { width: min(640px, calc(100vw - 48px)); }
.row { display: flex; gap: 10px; justify-content: center; margin: 12px 0; }
.row label { align-self: center; width: 56px; text-align: left; font-size: 15px; }
.row button { flex: 1; }
#go, #resume { margin-top: 20px; width: 100%; padding: 14px; font-size: 18px; }
#restart { margin-top: 10px; width: 100%; }
#verdict { font-size: 26px; font-weight: 900; letter-spacing: .12em; text-shadow: var(--glow); }
#verdict.fail { color: #ffb0b0; text-shadow: 0 0 18px rgba(255, 90, 90, .5); }
.grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin: 22px 0 16px; }
.grid div { padding: 12px 6px; border: 1px solid var(--line); border-radius: 14px; background: rgba(255, 255, 255, .04); }
.grid b { display: block; font-size: 26px; text-shadow: var(--glow); }
.grid span { font-size: 13px; color: rgba(255, 255, 255, .6); }
.cols { display: grid; grid-template-columns: 1.3fr 1fr; gap: 16px; text-align: left; }
.cols h3 { margin: 0 0 8px; font-size: 15px; letter-spacing: .1em; }
.cols ul { list-style: none; margin: 0; padding: 0; font-size: 13.5px; max-height: 40vh; overflow: auto; }
.cols li { display: flex; justify-content: space-between; gap: 10px; padding: 3px 0; border-bottom: 1px solid rgba(255, 255, 255, .06); }
.cols li.ok span:last-child { color: var(--good); }
.cols li.bad span:last-child { color: var(--bad); }

.loader { width: 44px; height: 44px; border-radius: 50%; border: 3px solid rgba(255, 255, 255, .15); border-top-color: #fff; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
#narrow { display: none; }
@media (max-width: 760px) { #narrow { display: flex; z-index: 20; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; }
  .caret, #words .ch, #toast, .fold, #snd path { transition: none !important; }
}

/* ── 主選單：靠左，讓右邊的工地露出來；背景是正在動的遊戲 ── */
.overlay.menu { justify-content: center; background: rgba(5, 6, 8, .18); }
.menu-card { width: min(640px, calc(100vw - 48px)); text-align: left; max-height: calc(100vh - 48px); overflow: auto; }
.menu-card h1, .menu-card .sub { text-align: center; }
.menu-card #go, .menu-card #resume { margin-top: 16px; }
.menu-foot { display: flex; gap: 10px; margin-top: 10px; }
.menu-foot button { flex: 1; }
#buildings { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; margin: 0 0 6px; }
.cats-row { align-items: flex-start; }
.cats-row label { padding-top: 8px; }
.pills { flex: 1; display: flex; flex-wrap: wrap; gap: 8px; }
.pills button { padding: 7px 13px; font-size: 14px; border-radius: 99px; flex: 0 0 auto; }
.articles { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 4px 0 4px 66px; max-height: 236px; overflow: auto; padding-right: 4px; }   /* 文章變多了，清單在框內捲動 */
.articles button { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 9px 12px; font-size: 14px; text-align: left; }
.articles i { font-style: normal; font-size: 12px; opacity: .7; white-space: nowrap; }
.articles .bar { height: 3px; background: rgba(255, 255, 255, .12); border-radius: 2px; margin-top: 5px; overflow: hidden; }
.articles .bar b { display: block; height: 100%; background: #fff; box-shadow: 0 0 8px #fff; }
#custom-box { margin: 4px 0 4px 66px; }
#custom-text, #fb-text { width: 100%; min-height: 110px; resize: vertical; font: inherit; font-size: 15px; line-height: 1.6; color: #fff; background: rgba(0, 0, 0, .35); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
/* ── 彈窗（設定、排行榜） ── */
.overlay.modal { z-index: 12; background: rgba(5, 6, 8, .45); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); }
.mtitle { margin: 0 0 16px; font-size: 24px; font-weight: 900; letter-spacing: .12em; text-shadow: var(--glow); }
.close-btn { width: 100%; margin-top: 14px; }
.lb { width: min(720px, calc(100vw - 48px)); }
.tabs { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin-bottom: 8px; }
.tabs button { padding: 6px 13px; font-size: 14px; border-radius: 99px; }
.rows { margin-top: 10px; text-align: left; height: min(46vh, 430px); overflow: auto; transition: opacity .2s ease; }
.rows.loading { opacity: .35; }
.r { display: grid; grid-template-columns: 52px 1fr 1fr 70px 64px 64px; align-items: center; padding: 8px 12px; border-radius: 12px; font-variant-numeric: tabular-nums; }
.r:nth-child(even) { background: rgba(255, 255, 255, .03); }
.r .rk { font-weight: 900; font-size: 18px; }
.r .nk, .r .loc { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding-right: 8px; }
.r .loc { color: rgba(255, 255, 255, .75); }
.r.top1 .rk { color: #ffd76a; text-shadow: 0 0 12px rgba(255, 215, 106, .7); }
.r.top2 .rk { color: #e3e8ee; text-shadow: 0 0 10px rgba(255, 255, 255, .5); }
.r.top3 .rk { color: #e7a874; text-shadow: 0 0 10px rgba(231, 168, 116, .6); }
.r .sc { font-weight: 900; font-size: 18px; text-align: right; text-shadow: var(--glow); }
.r span:nth-child(4), .r span:nth-child(5) { text-align: right; opacity: .75; font-size: 14px; }
.r.me { background: rgba(255, 255, 255, .12); border: 1px solid rgba(255, 255, 255, .5); box-shadow: 0 0 20px rgba(255, 255, 255, .2); }
.r.head { font-size: 12px; opacity: .6; background: none !important; }
.r.head span:nth-child(3) { text-align: right; }
.gap { text-align: center; opacity: .55; padding: 10px; }
/* ── 結算：上傳成績 ── */
.rank-hit { margin: 4px 0 12px; padding: 14px; border-radius: 14px; border: 1px solid rgba(255, 215, 106, .5); background: rgba(255, 215, 106, .08); text-align: center; }
.rank-hit b { display: block; font-size: 32px; font-weight: 900; color: #ffd76a; text-shadow: 0 0 20px rgba(255, 215, 106, .6); }
.nick-row { display: flex; gap: 8px; margin: 6px 0; align-items: center; }
.nick-row label { font-size: 15px; padding: 0 4px; }
.nick-row input { flex: 1; font: inherit; font-size: 16px; color: #fff; background: rgba(0, 0, 0, .35); border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; }
.nick-row .primary { padding: 10px 22px; }
.up-msg { min-height: 1.2em; font-size: 14px; color: #ffb0b0; text-align: center; }
.res-btns { display: flex; gap: 10px; margin-top: 12px; }
.res-btns button { flex: 1; padding: 14px; font-size: 17px; }
/* 單詞模式：詞跟詞之間留空，不用打空白 */
#words .ch.wend { margin-right: .7em; }

/* ── 天災：警報橫幅與驗收面板 ── */
#alarm { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; z-index: 8; pointer-events: none; background: rgba(120, 10, 10, .18); animation: alarmBg .8s steps(2) infinite; }
.alarm-in { padding: 26px 48px; border-radius: 18px; text-align: center; background: rgba(40, 6, 6, .72); border: 1px solid rgba(255, 110, 110, .7); box-shadow: 0 0 60px rgba(255, 60, 60, .45); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); }
#alarm-title { font-size: 36px; font-weight: 900; letter-spacing: .14em; color: #fff; text-shadow: 0 0 24px rgba(255, 80, 80, .9); }
#alarm-sub { margin-top: 8px; font-size: 17px; color: #ffd9d9; }
@keyframes alarmBg { 50% { background: rgba(120, 10, 10, .02); } }
#dz { position: fixed; top: 20px; right: 20px; width: min(380px, calc(100vw - 40px)); padding: 16px 18px; z-index: 7; }
.dz-head { font-size: 20px; font-weight: 900; letter-spacing: .12em; text-shadow: var(--glow); margin-bottom: 8px; }
.dz-nums { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 12px; font-variant-numeric: tabular-nums; margin-bottom: 8px; }
.dz-nums b { font-size: 16px; }
.dz-nums b:last-child { grid-column: span 2; font-weight: 500; font-size: 14px; }
#dz-wave { width: 100%; height: 56px; display: block; margin-bottom: 8px; border-radius: 8px; background: rgba(0, 0, 0, .3); }
#dz-rows { max-height: 46vh; overflow: auto; }
.dz-row { display: grid; grid-template-columns: 1fr 1fr 48px 56px; gap: 6px; padding: 6px 4px; font-size: 13.5px; opacity: .45; border-bottom: 1px solid rgba(255, 255, 255, .06); transition: opacity .3s, background .3s; }
.dz-row .v { text-align: right; font-variant-numeric: tabular-nums; }
.dz-row .s { text-align: right; font-weight: 700; }
.dz-row.checking { opacity: 1; background: rgba(255, 255, 255, .06); }
.dz-row.checking .s { animation: blink 0.8s ease-in-out infinite; }
.dz-row.pass, .dz-row.warn, .dz-row.fail { opacity: 1; }
.dz-row.pass .s { color: var(--good); }
.dz-row.warn .s { color: #ffd76a; }
.dz-row.fail { background: rgba(255, 80, 80, .1); }
.dz-row.fail .s, .dz-row.fail .v { color: var(--bad); }
/* 練習／排位戰切換；排位戰時鎖住的建築和題目 */
.play-tabs { margin: 4px 0 12px; }
.play-tabs button { padding: 8px 28px; font-size: 15px; }
.bcard:disabled { opacity: .3; cursor: not-allowed; }
.pills button:disabled { cursor: default; }
.pills button:disabled:not(.on) { opacity: .3; }

/* 選單裡會出現/收起的區塊：高度平滑展開，不會一下子跳 */
.fold { display: grid; grid-template-rows: 1fr; opacity: 1; transition: grid-template-rows .35s cubic-bezier(.2, .8, .2, 1), opacity .3s ease; }
.fold > * { min-height: 0; overflow: hidden; }
.fold.shut { grid-template-rows: 0fr; opacity: 0; pointer-events: none; }

/* 右上角音量鍵：關掉時聲波收起、打叉畫出來 */
.snd-btn { position: fixed; top: 20px; right: 20px; z-index: 30; width: 46px; height: 46px; padding: 0; border-radius: 50%; display: grid; place-items: center; transition: opacity .6s ease, box-shadow .25s, background .25s; }
.snd-btn svg { width: 24px; height: 24px; fill: none; stroke: #fff; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; overflow: visible; }
.snd-btn .spk { fill: #fff; stroke: none; }
.snd-btn .w1, .snd-btn .w2 { transform-origin: 12px 12px; transition: opacity .3s ease, transform .35s cubic-bezier(.2, .8, .2, 1); }
.snd-btn .w2 { transition-delay: .05s; }
.snd-btn .x { stroke-dasharray: 8; stroke-dashoffset: 8; opacity: 0; transition: stroke-dashoffset .35s ease .1s, opacity .2s ease .1s; }
.snd-btn.off .w1, .snd-btn.off .w2 { opacity: 0; transform: scale(.4); }
.snd-btn.off .w2 { transition-delay: 0s; }
.snd-btn.off .x { stroke-dashoffset: 0; opacity: 1; }
.snd-btn.off .spk { opacity: .6; }
.snd-btn.pop { animation: snd-pop .35s cubic-bezier(.2, .8, .2, 1); }
@keyframes snd-pop { 40% { transform: scale(.86); } 100% { transform: scale(1); } }

/* 意見回饋 */
.card.fb { width: min(520px, calc(100vw - 32px)); }
#fb-text { min-height: 150px; margin: 6px 0; display: block; }

/* 個人資料：第一次進網站一定要先建立（點背景、按 Esc 不會關） */
.overlay.locked { z-index: 14; background: rgba(5, 6, 8, .55); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
.card.prof { width: min(520px, calc(100vw - 32px)); }
.p-where { text-align: center; font-size: 20px; font-weight: 700; letter-spacing: .08em; padding: 6px 0 2px; text-shadow: var(--glow); }
#profile select, #profile .nick-row input { flex: 1; font: inherit; font-size: 16px; color: #fff; background: rgba(0, 0, 0, .35); border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; }
#profile select option { color: #000; }
.me-chip { display: block; margin: 0 auto 10px; padding: 5px 16px; font-size: 14px; border-radius: 99px; }
.up-who { flex: 1; font-size: 16px; padding-left: 4px; }

/* 暫停 */
.overlay.pause { z-index: 13; background: rgba(5, 6, 8, .5); backdrop-filter: blur(5px); -webkit-backdrop-filter: blur(5px); }
.pause .card { width: min(380px, calc(100vw - 32px)); text-align: center; }
.pause h1 { margin: 0 0 18px; letter-spacing: .3em; }
.pause .res-btns { flex-direction: column; }

/* 排位戰規則 */
.intro { list-style: none; margin: 12px 0; padding: 0; display: grid; gap: 8px; }
.intro li { display: flex; align-items: center; gap: 14px; padding: 10px 16px; border: 1px solid var(--line); border-radius: 12px; background: rgba(255, 255, 255, .05); }
.intro b { min-width: 96px; font-size: 15px; letter-spacing: .06em; text-shadow: var(--glow); }
.intro span { font-size: 14px; }

/* 標題旁的小熊房子 logo：跟字的視覺中心對齊（字距會在最後一個字後面多留空，用負邊距抵掉） */
.title, .brand { display: flex; align-items: center; justify-content: center; }
.title { gap: .3em; }
.title .logo { width: 1.3em; height: 1.3em; transform: translateY(-.04em); filter: drop-shadow(0 0 14px rgba(120, 170, 255, .35)); }
.title span, .brand span { margin-right: -.14em; }
.brand { justify-content: flex-start; gap: 8px; }
.brand span { margin-right: -.1em; }
.brand .logo { width: 26px; height: 26px; }
