* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
:root {
  --bg: #14121c; --panel: #1f1c2b; --panel2: #29253a; --line: rgba(255,255,255,.1);
  --text: #ece8f6; --muted: #9c95b4; --gold: #f2c45a; --red: #ff6b6b; --blue: #7cc4ff; --green: #7ee0a3;
  --atk: #e0614e; --skill: #4f8fd9; --power: #e0a33c; --status: #6b6680; --curse: #7a3b8f;
}
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: radial-gradient(ellipse at 50% 0%, #2a2340 0%, var(--bg) 60%, #0a0910 100%) fixed;
  color: var(--text); user-select: none; -webkit-user-select: none; overflow-x: hidden;
}
button { font: inherit; color: inherit; cursor: pointer; border: 1px solid var(--line); background: var(--panel2); border-radius: 10px; padding: 8px 16px; transition: transform .1s, background .15s, border-color .15s, opacity .15s; }
button:hover:not(:disabled) { background: #362f4d; border-color: rgba(242,196,90,.45); }
button:active:not(:disabled) { transform: scale(.96); }
button:disabled { opacity: .4; cursor: default; }
button:focus-visible, a:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.primary { background: linear-gradient(135deg, #f2c45a, #d98a2b); color: #2a1604; font-weight: 700; border-color: transparent; }
.primary:hover:not(:disabled) { background: linear-gradient(135deg, #ffd47a, #e89a3b); }
.hidden { display: none !important; }

#app { max-width: 980px; margin: 0 auto; min-height: 100vh; display: flex; flex-direction: column; }

/* ---------- 顶栏 ---------- */
.topbar { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-bottom: 1px solid var(--line); background: rgba(0,0,0,.25); flex-wrap: wrap; position: sticky; top: 0; z-index: 5; backdrop-filter: blur(6px); }
.topbar .stat { display: flex; align-items: center; gap: 4px; font-size: 14px; font-variant-numeric: tabular-nums; }
.topbar .hpv { color: var(--red); font-weight: 700; }
.topbar .goldv { color: var(--gold); font-weight: 700; }
.topbar .spacer { flex: 1; }
.topbar .relics { display: flex; gap: 2px; flex-wrap: wrap; }
.relic { font-size: 20px; cursor: help; padding: 0 2px; position: relative; }
.potions { display: flex; gap: 4px; }
.potion { width: 34px; height: 34px; padding: 0; font-size: 18px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; }
.potion.empty { opacity: .25; border-style: dashed; }
.tbtn { padding: 5px 10px; font-size: 13px; }
.home-link { width: 32px; height: 32px; display: inline-flex; align-items: center; justify-content: center; border-radius: 9px; border: 1px solid var(--line); background: var(--panel2); color: var(--text); text-decoration: none; }

/* ---------- 标题页 ---------- */
.title { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 30px 16px; position: relative; }
.title .home-link { position: absolute; top: 14px; left: 14px; }
.title h1 { font-size: clamp(40px, 10vw, 64px); margin: 0; letter-spacing: 10px; background: linear-gradient(180deg, #fff, #f2c45a 70%, #b9792b); -webkit-background-clip: text; background-clip: text; color: transparent; filter: drop-shadow(0 6px 30px rgba(242,196,90,.35)); }
.title .tower { font-size: 64px; animation: bob 4s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-8px); } }
.title p { color: var(--muted); line-height: 1.9; max-width: 520px; }
.title .btns { display: flex; flex-direction: column; gap: 10px; min-width: 240px; margin-top: 16px; }
.title .btns button { padding: 12px; font-size: 16px; }
.title .stats { margin-top: 18px; font-size: 13px; color: var(--muted); }

/* ---------- 地图 ---------- */
.mapwrap { flex: 1; overflow-y: auto; padding: 10px 0 30px; }
.maphead { text-align: center; padding: 10px; }
.maphead h2 { margin: 0; font-size: 20px; color: var(--gold); letter-spacing: 3px; }
.maphead p { margin: 4px 0 0; font-size: 13px; color: var(--muted); }
.map { position: relative; margin: 0 auto; width: min(560px, 96vw); }
.map svg { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.node { position: absolute; width: 42px; height: 42px; margin: -21px 0 0 -21px; border-radius: 50%; padding: 0; font-size: 20px; display: flex; align-items: center; justify-content: center; background: var(--panel); border: 2px solid rgba(255,255,255,.15); }
.node.done { opacity: .35; }
.node.cur { border-color: var(--gold); box-shadow: 0 0 0 4px rgba(242,196,90,.25); opacity: 1; }
.node.can { border-color: var(--gold); animation: pulse 1.4s ease-in-out infinite; }
.node.can:hover { transform: scale(1.15); }
.node:disabled { opacity: .55; }
.node.done:disabled { opacity: .3; }
@keyframes pulse { 50% { box-shadow: 0 0 0 7px rgba(242,196,90,.18); } }
.node.boss { width: 70px; height: 70px; margin: -35px 0 0 -35px; font-size: 36px; border-color: #ff6b6b; }
.legend { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px 14px; font-size: 12px; color: var(--muted); padding: 8px 14px; }

/* ---------- 战斗 ---------- */
.combat { flex: 1; display: flex; flex-direction: column; min-height: calc(100vh - 56px); }
.field { flex: 1; display: flex; align-items: flex-end; justify-content: space-between; gap: 10px; padding: 16px 14px 8px; min-height: 230px; }
.side-player { width: 150px; flex: none; }
.enemies { flex: 1; display: flex; justify-content: flex-end; align-items: flex-end; gap: 8px; flex-wrap: wrap; }
.unit { position: relative; text-align: center; padding: 8px 6px; border-radius: 14px; border: 2px solid transparent; min-width: 106px; transition: border-color .15s, background .15s, transform .15s; }
.unit .ava { font-size: 52px; line-height: 1.1; display: block; filter: drop-shadow(0 6px 10px rgba(0,0,0,.5)); }
.unit .nm { font-size: 13px; font-weight: 700; margin-top: 2px; }
.enemy { cursor: default; }
.enemy.targetable { cursor: pointer; border-color: rgba(255,107,107,.4); background: rgba(255,107,107,.06); }
.enemy.targetable:hover, .enemy.hoverT { border-color: var(--red); background: rgba(255,107,107,.14); transform: translateY(-3px); }
.enemy.dead { opacity: 0; pointer-events: none; transform: scale(.7); transition: opacity .5s, transform .5s; }
.hpbar { position: relative; display: flex; align-items: center; justify-content: center; height: 14px; background: rgba(0,0,0,.5); border-radius: 6px; margin: 4px 0 2px; overflow: hidden; border: 1px solid rgba(255,255,255,.12); }
.hpbar i { position: absolute; left: 0; top: 0; bottom: 0; background: linear-gradient(90deg, #c8384a, #ff6b6b); transition: width .3s; }
.hpbar.poisoned i { background: linear-gradient(90deg, #4a9a3b, #7ee0a3); }
.hpbar span { position: relative; font-size: 10px; line-height: 14px; font-weight: 700; text-shadow: 0 1px 2px #000; }
.blockbadge { position: absolute; left: -2px; top: 50%; transform: translateY(-50%); background: #3b6fb0; color: #fff; font-size: 11px; font-weight: 700; border-radius: 6px; padding: 0 5px; line-height: 16px; border: 1px solid #9fd0ff; }
.sts { display: flex; flex-wrap: wrap; gap: 2px; justify-content: center; min-height: 18px; }
.st { font-size: 11px; padding: 0 4px; border-radius: 5px; background: rgba(255,255,255,.08); cursor: help; white-space: nowrap; }
.st.bad { background: rgba(255,107,107,.18); }
.intent { font-size: 13px; font-weight: 700; min-height: 26px; display: flex; align-items: center; justify-content: center; gap: 3px; cursor: help; }
.intent .big { font-size: 20px; }
.intent.atk { color: #ff8a7a; }
.intent.def { color: var(--blue); }
.intent.buff { color: var(--gold); }
.intent.debuff { color: #c49cff; }
.floater { position: absolute; left: 50%; top: 30%; transform: translateX(-50%); font-weight: 800; font-size: 20px; pointer-events: none; animation: floatUp .9s ease-out forwards; text-shadow: 0 2px 4px #000; white-space: nowrap; z-index: 3; }
.floater.dmg { color: #ff6b6b; } .floater.blocked { color: #9fd0ff; } .floater.block { color: #7cc4ff; }
.floater.heal { color: var(--green); } .floater.buff { color: var(--gold); font-size: 14px; } .floater.debuff { color: #c49cff; font-size: 14px; }
@keyframes floatUp { from { opacity: 1; transform: translate(-50%, 0); } to { opacity: 0; transform: translate(-50%, -46px); } }
.shake { animation: shake .35s; }
@keyframes shake { 20% { transform: translateX(-6px); } 40% { transform: translateX(6px); } 60% { transform: translateX(-4px); } 80% { transform: translateX(3px); } }

.bottom { display: flex; align-items: flex-end; gap: 10px; padding: 6px 12px 14px; }
.energy { flex: none; width: 66px; height: 66px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #ffe08a, #e08a2b 70%); color: #2a1604; font-size: 22px; font-weight: 800; display: flex; align-items: center; justify-content: center; box-shadow: 0 0 20px rgba(242,160,60,.5); border: 3px solid #fff3c4; }
.energy.zero { filter: grayscale(.8) brightness(.7); box-shadow: none; }
.piles { display: flex; flex-direction: column; gap: 6px; flex: none; }
.piles button { padding: 5px 8px; font-size: 12px; min-width: 66px; }
.hand { flex: 1; min-width: 0; display: flex; justify-content: center; align-items: flex-end; min-height: 168px; padding: 0 4px; }
.endturn { flex: none; padding: 14px 16px; font-weight: 700; }

/* ---------- 卡牌 ---------- */
.card { position: relative; width: 112px; height: 156px; flex: none; border-radius: 12px; padding: 0; text-align: center; display: flex; flex-direction: column; overflow: hidden; background: #24203a; border: 2px solid #4a4466; box-shadow: 0 6px 16px rgba(0,0,0,.45); transition: transform .15s, box-shadow .15s, margin .15s; }
.hand .card + .card { margin-left: var(--ov, -14px); }
.hand .card:hover, .hand .card.sel { transform: translateY(-24px) scale(1.06); z-index: 2; box-shadow: 0 16px 30px rgba(0,0,0,.6); }
.hand .card.sel { border-color: var(--gold); }
.card.unplayable { filter: saturate(.4) brightness(.75); }
.card .cost { position: absolute; left: 5px; top: 5px; width: 26px; height: 26px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #ffe08a, #d9822b); color: #2a1604; font-weight: 800; font-size: 14px; display: flex; align-items: center; justify-content: center; border: 2px solid #fff3c4; z-index: 1; }
.card .cname { padding: 9px 4px 3px 26px; font-size: 13px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card.up .cname { color: var(--green); }
.card .art { height: 44px; display: flex; align-items: center; justify-content: center; font-size: 26px; margin: 0 7px; border-radius: 8px; }
.card .ctype { font-size: 10px; color: var(--muted); margin: 2px 0; }
.card .cdesc { flex: 1; font-size: 11px; line-height: 1.45; padding: 2px 6px 6px; color: #dcd6ee; display: flex; align-items: center; justify-content: center; }
.card .cdesc b { color: var(--gold); }
.card .cdesc b.buffed { color: var(--green); }
.card .cdesc b.nerfed { color: var(--red); }
.card.atk { border-color: #8a3a30; } .card.atk .art { background: linear-gradient(135deg, #5a2620, #3a1a18); }
.card.skill { border-color: #2f5a8a; } .card.skill .art { background: linear-gradient(135deg, #1f3a5a, #182a40); }
.card.power { border-color: #8a6a2a; } .card.power .art { background: linear-gradient(135deg, #5a4520, #3a2e18); }
.card.status { border-color: #555; } .card.status .art { background: #2a2a33; }
.card.curse { border-color: #6a2a7a; } .card.curse .art { background: linear-gradient(135deg, #3f1a4a, #2a1430); }
.card.rare { box-shadow: 0 0 0 1px var(--gold), 0 6px 16px rgba(0,0,0,.45); }
.card.big { width: 148px; height: 206px; } .card.big .cname { font-size: 15px; } .card.big .art { height: 62px; font-size: 34px; } .card.big .cdesc { font-size: 13px; }

/* ---------- 弹窗 ---------- */
.modal { position: fixed; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center; padding: 14px; background: rgba(6,5,10,.82); backdrop-filter: blur(5px); overflow-y: auto; }
.box { width: min(760px, 100%); background: var(--panel); border: 1px solid rgba(242,196,90,.25); border-radius: 18px; padding: 18px; box-shadow: 0 30px 80px rgba(0,0,0,.6); text-align: center; max-height: 94vh; overflow-y: auto; }
.box h2 { margin: 0 0 6px; color: var(--gold); font-size: 21px; }
.box p { color: var(--muted); font-size: 14px; line-height: 1.8; margin: 0 0 12px; }
.cards { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin: 12px 0; }
.cards .card:hover { transform: translateY(-4px); border-color: var(--gold); }
.row { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 12px; }
.rewards { display: flex; flex-direction: column; gap: 8px; max-width: 360px; margin: 10px auto; }
.rewards button { display: flex; align-items: center; gap: 10px; text-align: left; padding: 10px 14px; }
.rewards .ic { font-size: 22px; }
.choice { display: block; width: 100%; text-align: left; margin: 8px 0; padding: 12px 14px; }
.choice small { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }
.event-icon { font-size: 60px; }
.shop { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; }
.shopitem { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.price { font-size: 13px; color: var(--gold); font-weight: 700; }
.price.no { color: var(--red); }
.shopitem.sold { opacity: .25; pointer-events: none; }
.relicbtn { width: 64px; height: 64px; font-size: 30px; padding: 0; border-radius: 14px; }

.toast { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%) translateY(20px); background: #2e2843; border: 1px solid rgba(242,196,90,.35); padding: 9px 16px; border-radius: 12px; font-size: 14px; z-index: 40; opacity: 0; pointer-events: none; transition: opacity .25s, transform .25s; max-width: 90vw; text-align: center; }
.toast.show { opacity: 1; transform: translateX(-50%); }
.tip { position: fixed; z-index: 50; max-width: 240px; background: #0e0c16; border: 1px solid rgba(242,196,90,.4); border-radius: 10px; padding: 8px 10px; font-size: 12px; line-height: 1.6; pointer-events: none; box-shadow: 0 10px 30px rgba(0,0,0,.6); }
.tip b { color: var(--gold); }

/* ---------- 手机 ---------- */
@media (max-width: 640px) {
  .combat { min-height: 0; }
  .field { flex: 1; flex-direction: column; align-items: stretch; justify-content: center; min-height: 0; padding: 10px 8px 4px; gap: 10px; }
  .enemies { flex: none; justify-content: center; align-items: flex-start; gap: 2px; }
  .side-player { width: auto; display: flex; justify-content: center; }
  .side-player .unit { display: flex; align-items: center; gap: 8px; min-width: 0; width: 100%; max-width: 320px; text-align: left; padding: 4px 8px; }
  .side-player .unit .ava { font-size: 36px; }
  .side-player .unit > div { flex: 1; }
  .unit { min-width: 84px; padding: 4px 2px; }
  .unit .ava { font-size: 40px; }
  .card { width: 92px; height: 132px; }
  .card .art { height: 32px; font-size: 20px; }
  .card .cdesc { font-size: 10px; }
  .hand { min-height: 150px; order: -1; flex: 0 0 100%; padding: 22px 0 0; }
  .bottom { flex-wrap: wrap; justify-content: space-between; align-items: center; padding: 4px 8px 12px; margin-top: auto; }
  .energy { width: 54px; height: 54px; font-size: 18px; }
  .piles { flex-direction: row; }
  .topbar { gap: 8px; padding: 8px 10px; }
  .card.big { width: 120px; height: 172px; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
