:root {
  --bg: #171a29; --panel: #222639; --card: #2b3048; --card2: #343a57; --line: #3f4566;
  --text: #f1f2f8; --mute: #a3a8c3; --gold: #ffcc4d; --gem: #6fd6ff; --ok: #5ad16a; --bad: #ff5d6c;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: "Segoe UI", "Microsoft JhengHei", "PingFang TC", "Noto Sans TC", sans-serif; overflow: hidden; }
button { font: inherit; color: inherit; cursor: pointer; }
.hidden { display: none !important; }
.mute { color: var(--mute); }
.small { font-size: 12.5px; }

#app { height: 100vh; height: 100dvh; display: flex; flex-direction: column; }
#stage { position: relative; width: 100%; flex: none; container-type: inline-size; background: #000; overflow: hidden; user-select: none; }
#view { position: relative; width: 100%; aspect-ratio: 1376 / 768; }
#bar { position: absolute; left: 0; right: 0; bottom: 0; pointer-events: none; }
#bar > * { pointer-events: auto; }
#game { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#loading { position: absolute; inset: 0; display: grid; place-items: center; font-size: 20px; background: #1a1c2c; }
#panel { flex: 1; min-height: 0; display: flex; flex-direction: column; background: var(--panel); border-top: 2px solid var(--line); }

@media (min-width: 900px) and (min-aspect-ratio: 5/4) {
  #app { flex-direction: row; }
  #stage { width: auto; height: auto; flex: 1; align-self: center; }
  #panel { width: 400px; flex: none; height: 100dvh; border-top: 0; border-left: 2px solid var(--line); }
}
@media (max-height: 520px) and (orientation: landscape) {
  #app { flex-direction: row; }
  #stage { width: calc(100dvh * 1376 / 768); max-width: 70vw; flex: none; align-self: center; }
  #panel { flex: 1; height: 100dvh; border-top: 0; border-left: 2px solid var(--line); }
}

/* ---------- HUD ---------- */
#hud { position: absolute; left: 0; right: 0; top: 0; display: flex; justify-content: flex-end; align-items: flex-start; gap: 1cqw; padding: 1cqw 1.2cqw; pointer-events: none; font-size: max(11px, 1.45cqw); }
#hud > *, #hudb > * { pointer-events: auto; }
#hudb { position: absolute; left: 1cqw; bottom: 1cqw; width: 27cqw; display: flex; flex-direction: column; gap: .5cqw; font-size: max(11px, 1.45cqw); pointer-events: none; }
.wallbox { background: rgba(10, 12, 25, .72); border-radius: 8px; padding: .5cqw .8cqw; display: flex; align-items: center; gap: .6cqw; border: 1px solid rgba(255,255,255,.12); }
.wallbox.hit { animation: hit .3s; }
@keyframes hit { 0% { background: rgba(200, 30, 40, .85); } 100% { background: rgba(10, 12, 25, .72); } }
.wallbox .lbl { white-space: nowrap; font-weight: 700; }
.bar { position: relative; flex: 1; height: max(14px, 1.9cqw); background: #3a1820; border-radius: 6px; overflow: hidden; }
.bar i { position: absolute; left: 0; top: 0; bottom: 0; background: linear-gradient(#7ee38a, #3fb04f); transition: width .15s; }
.bar b { position: absolute; left: 0; top: 0; height: 35%; background: #ffe9a0; opacity: .9; }
.bar span { position: absolute; inset: 0; display: grid; place-items: center; font-size: max(10px, 1.2cqw); font-weight: 700; text-shadow: 0 1px 2px #000; }
.bar.thin { height: max(6px, .8cqw); background: rgba(0,0,0,.5); }
.bar.thin i { background: linear-gradient(90deg, #ffcc4d, #ff8a3d); }
.res { display: flex; gap: .6cqw; }
.res span { background: rgba(10, 12, 25, .72); border-radius: 8px; padding: .3cqw .8cqw; border: 1px solid rgba(255,255,255,.12); white-space: nowrap; }
.res span:first-child b { color: var(--gold); } .res span:last-child b { color: var(--gem); }
.hud-c { position: absolute; left: 50%; top: 1cqw; transform: translateX(-50%); width: 30cqw; text-align: center; background: rgba(10, 12, 25, .6); border-radius: 8px; padding: .4cqw .8cqw; }
.lvname { font-weight: 800; font-size: 1.15em; margin-bottom: .3cqw; text-shadow: 0 1px 2px #000; }
.hud-r { display: flex; flex-direction: column; align-items: flex-end; gap: .5cqw; }
.hbtn { background: rgba(10, 12, 25, .78); border: 1px solid rgba(255,255,255,.18); border-radius: 8px; padding: .45cqw .8cqw; font-size: max(11px, 1.3cqw); white-space: nowrap; }
.hbtn.on { background: rgba(60, 140, 70, .85); border-color: #8fe39a; }
.hbtn:hover { filter: brightness(1.2); }

#banner { position: absolute; left: 0; right: 0; top: 34%; text-align: center; font-size: 4.2cqw; font-weight: 900; pointer-events: none; opacity: 0; text-shadow: 0 3px 0 #000, 0 0 14px rgba(0,0,0,.7); -webkit-text-stroke: 1px rgba(0,0,0,.6); }
#banner.show { animation: ban 1.6s ease-out; }
@keyframes ban { 0% { opacity: 0; transform: scale(1.4); } 15% { opacity: 1; transform: scale(1); } 75% { opacity: 1; } 100% { opacity: 0; transform: translateY(-2cqw); } }

#skills { position: absolute; bottom: 1.2cqw; left: 31cqw; display: flex; gap: 1cqw; }
.skill { position: relative; width: max(42px, 6.4cqw); aspect-ratio: 1; padding: 0; border: 2px solid rgba(255,255,255,.35); border-radius: 12px; background: #111; overflow: hidden; box-shadow: 0 3px 8px rgba(0,0,0,.5); }
.skill img { width: 100%; height: 100%; display: block; }
.skill .cd { position: absolute; inset: 0; background: conic-gradient(rgba(0,0,0,.72) var(--p, 0%), transparent 0); }
.skill.ready { border-color: #ffe27a; box-shadow: 0 0 12px rgba(255, 220, 90, .8); animation: glow 1.2s infinite alternate; }
@keyframes glow { to { box-shadow: 0 0 4px rgba(255, 220, 90, .4); } }
.skill .key { position: absolute; left: 3px; top: 1px; font-size: max(10px, 1.1cqw); font-weight: 800; text-shadow: 0 1px 2px #000; }
.skill .lock { display: none; position: absolute; inset: 0; place-items: center; font-size: max(16px, 2.4cqw); background: rgba(0,0,0,.6); }
.skill.locked .lock { display: grid; }

/* ---------- 面板 ---------- */
.tabs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; padding: 8px 8px 0; }
.tabs button { background: var(--card); border: 1px solid var(--line); border-radius: 10px 10px 0 0; padding: 9px 4px; font-weight: 700; font-size: 14px; }
.tabs button.on { background: var(--card2); border-bottom-color: var(--card2); color: var(--gold); }
.buyn { padding: 6px 10px; font-size: 13px; color: var(--mute); display: flex; align-items: center; gap: 6px; }
.buyn button { background: var(--card); border: 1px solid var(--line); border-radius: 6px; padding: 3px 9px; font-size: 13px; }
.buyn button.on { background: #5b4a12; border-color: var(--gold); color: var(--gold); }
.tabbody { flex: 1; overflow-y: auto; padding: 6px 10px 18px; -webkit-overflow-scrolling: touch; }
.sum { background: rgba(0,0,0,.2); border-radius: 8px; padding: 7px 10px; margin: 4px 0 8px; font-size: 13px; }
.sum b { color: var(--gold); }
.card { display: flex; gap: 10px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 9px; margin-bottom: 8px; align-items: flex-start; }
.card.slim { align-items: center; }
.card h4 { margin: 0 0 3px; font-size: 15px; }
.card p { margin: 2px 0; }
.card .info { flex: 1; min-width: 0; }
.lv { color: var(--gold); font-size: 13px; }
.tag { display: inline-block; font-size: 11px; background: rgba(255, 204, 77, .15); color: var(--gold); border-radius: 6px; padding: 1px 6px; font-weight: 600; white-space: nowrap; }
.tag.ok { background: rgba(90, 209, 106, .15); color: var(--ok); }
.porwrap { position: relative; flex: none; }
.por { width: 66px; height: 92px; object-fit: contain; display: block; background: radial-gradient(circle at 50% 70%, #45507a, #2b3048 70%); border-radius: 10px; }
.por.dim { filter: grayscale(1) brightness(.5); }
.lockcard { opacity: .8; }
.gbtn { position: absolute; right: -4px; bottom: -4px; width: 24px; height: 24px; border-radius: 50%; border: 1px solid var(--line); background: var(--card2); font-size: 13px; padding: 0; }
.row { display: flex; gap: 8px; align-items: center; margin-top: 5px; }
.row.wrap { flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.buy { display: inline-flex; flex-direction: column; align-items: center; min-width: 92px; background: linear-gradient(#3fae55, #2d8a40); border: 1px solid #6fdc84; border-radius: 9px; padding: 4px 10px; line-height: 1.2; flex: none; }
.buy span { font-size: 12px; }
.buy b { font-size: 13.5px; }
.buy.no { background: #3a3f5c; border-color: #4c5276; color: #9aa0c0; }
.buy.hire { background: linear-gradient(#e8a23a, #b87414); border-color: #ffd27a; }
.buy.sm { min-width: 70px; padding: 3px 8px; }
.buy:active { transform: scale(.96); }
.buy.shake { animation: shake .3s; }
@keyframes shake { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }
.skrow { display: flex; gap: 8px; align-items: center; margin-top: 7px; padding-top: 7px; border-top: 1px dashed var(--line); }
.skinfo { flex: 1; min-width: 0; font-size: 13px; }
.ic { width: 46px; height: 46px; border-radius: 10px; flex: none; display: inline-grid; place-items: center; }
.ic.sm { width: 34px; height: 34px; border-radius: 8px; }
.ic.big { width: 50px; height: 50px; font-size: 30px; background: var(--card2); }
img.ic.big { background: none; }
.emo { line-height: 1; }

.diffs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin: 4px 0 6px; }
.diff { background: var(--card); border: 2px solid var(--line); border-radius: 10px; padding: 7px 4px; display: flex; flex-direction: column; gap: 2px; }
.diff b { color: var(--c); font-size: 15px; } .diff span { font-size: 11.5px; color: var(--mute); }
.diff.on { border-color: var(--c); background: var(--card2); }
.diff.locked { opacity: .55; }
.pager { display: flex; align-items: center; gap: 8px; margin: 8px 0; flex-wrap: wrap; }
.pager > button:not(.buy) { background: var(--card); border: 1px solid var(--line); border-radius: 6px; padding: 4px 10px; }
.pager button:disabled { opacity: .35; }
.pager .buy { margin-left: auto; }
.lvgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(52px, 1fr)); gap: 5px; }
.lvb { padding: 7px 0; border-radius: 8px; border: 1px solid var(--line); background: #262a40; font-size: 13px; font-weight: 600; }
.lvb.done { background: #23462c; border-color: #3f8a50; }
.lvb.next { background: #5b4a12; border-color: var(--gold); color: var(--gold); }
.lvb.lock { opacity: .35; }
.lvb.cur { outline: 2px solid #fff; outline-offset: 1px; }

/* ---------- 彈窗 / 提示 ---------- */
.modal { position: fixed; inset: 0; background: rgba(5, 6, 15, .7); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal-box { background: var(--panel); border: 2px solid var(--line); border-radius: 16px; padding: 18px 20px; width: min(480px, 100%); max-height: 90vh; overflow-y: auto; box-shadow: 0 10px 40px rgba(0,0,0,.6); }
.modal-box h3 { margin: 0 0 10px; font-size: 20px; } .modal-box h4 { margin: 14px 0 4px; }
.modal-box .big { font-size: 28px; font-weight: 800; color: var(--gold); margin: 8px 0; }
.tips { padding-left: 20px; line-height: 1.7; }
.opt { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin: 8px 0; }
.btn { background: var(--card2); border: 1px solid var(--line); border-radius: 9px; padding: 8px 14px; font-weight: 600; }
.btn.gold { background: linear-gradient(#ffcf5a, #e09a1a); color: #2a1a00; border-color: #ffe39a; }
.btn.danger { background: #5a2430; border-color: #a8475a; }
.btn:disabled { opacity: .5; }
.code { width: 100%; margin-top: 8px; background: #121522; color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 8px; font-family: monospace; font-size: 12px; }
.links { margin-top: 14px; font-size: 13px; } .links a { color: var(--gem); }
#toasts { position: fixed; left: 50%; bottom: 14px; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 6px; z-index: 60; pointer-events: none; width: max-content; max-width: 94vw; }
.toast { background: rgba(20, 22, 38, .94); border: 1px solid var(--line); border-radius: 10px; padding: 8px 14px; font-size: 14px; box-shadow: 0 4px 14px rgba(0,0,0,.5); transition: opacity .4s, transform .4s; text-align: center; }
.toast.out { opacity: 0; transform: translateY(8px); }

/* 窄螢幕（手機直向）：技能列與城牆/資源移到戰場下方 */
@media (max-width: 760px) and (orientation: portrait) {
  #bar { position: static; display: flex; align-items: center; gap: 8px; padding: 6px 8px; background: #11131f; border-top: 1px solid var(--line); }
  #hudb { position: static; width: auto; flex: 1; min-width: 0; font-size: 12px; gap: 4px; }
  #skills { position: static; transform: none; gap: 5px; }
  .skill { width: 44px; border-radius: 10px; }
  .skill .key { display: none; }
  .bar { height: 15px; } .bar span { font-size: 10.5px; }
  .res span { padding: 2px 6px; font-size: 12px; }
  .hbtn .t { display: none; }
  .hbtn { padding: 3px 6px; font-size: 13px; }
  .hud-c { width: 38cqw; left: 61%; font-size: 12px; }
  #banner { font-size: 6cqw; }
}
@media (max-width: 380px) and (orientation: portrait) { .skill { width: 38px; } }
