:root {
  --blue: #2f6fd6;
  --blue-soft: #dce9ff;
  --green: #1f9a55;
  --green-soft: #d8f5e4;
  --gray: #8e98a4;
  --ink: #23324a;
  --paper: #fffdf8;
  --gold: #f2b52c;
  --danger: #e2574c;
  --dock-h: min(36dvh, 236px);
  --font: "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", "Heiti TC", system-ui, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: #cfe6ff; color: var(--ink); font-family: var(--font); }
body { overscroll-behavior: none; }
button { font: inherit; color: inherit; cursor: pointer; }
.hidden { display: none !important; }
.small { font-size: 12px; opacity: .8; }
.center { text-align: center; }

#app { position: relative; max-width: 480px; height: 100dvh; margin: 0 auto; overflow: hidden; background: #cfe6ff; }
.screen { position: absolute; inset: 0; }

/* 首頁 */
.title-bg { position: absolute; inset: 0; background: url(../assets/bg_cityhall.webp) center top / cover; filter: saturate(1.05); }
.title-bg::after { content: ""; position: absolute; inset: 0; background: linear-gradient(to bottom, rgba(255,255,255,0) 20%, rgba(255,253,248,.9) 55%); }
.panel { position: relative; padding: 24px 16px 56px; display: flex; flex-direction: column; gap: 12px; }
.title-panel { justify-content: flex-end; height: 100%; }
#closed .panel { justify-content: center; height: 100%; text-align: center; }
.logo { margin: 0; text-align: center; font-size: 48px; font-weight: 900; letter-spacing: 4px; color: var(--ink);
  text-shadow: 0 3px 0 #fff, 3px 0 0 #fff, -3px 0 0 #fff, 0 -3px 0 #fff, 2px 2px 0 #fff, -2px 2px 0 #fff, 2px -2px 0 #fff, -2px -2px 0 #fff, 0 6px 0 rgba(0,0,0,.15); }
.logo .b { color: var(--blue); } .logo .g { color: var(--green); }
.tagline { margin: 0; text-align: center; font-weight: 700; }
.pick { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.pick-btn { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 10px 6px 12px; border-radius: 20px; border: 3px solid; background: #fff; box-shadow: 0 4px 0 rgba(0,0,0,.12); }
.pick-btn img { height: 120px; width: auto; object-fit: contain; }
.pick-btn.blue { border-color: var(--blue); background: var(--blue-soft); }
.pick-btn.green { border-color: var(--green); background: var(--green-soft); }
.pick-btn:active { transform: translateY(2px); box-shadow: 0 2px 0 rgba(0,0,0,.12); }
.nameplate { font-weight: 900; font-size: 18px; }
.links { display: flex; justify-content: center; gap: 8px; flex-wrap: wrap; }
.link { background: rgba(255,255,255,.85); border: 1px solid #c9d3e0; border-radius: 999px; padding: 8px 14px; font-size: 14px; text-decoration: none; color: var(--ink); min-height: 40px; display: inline-flex; align-items: center; }
.disclaimer { font-size: 11px; line-height: 1.5; background: rgba(255,255,255,.85); border-radius: 12px; padding: 8px 10px; margin: 0; }

#footer { position: absolute; left: 0; right: 0; bottom: 0; display: flex; justify-content: space-between; gap: 8px; padding: 6px 12px calc(6px + env(safe-area-inset-bottom)); font-size: 11px; background: rgba(255,253,248,.92); }
#footer a { color: var(--ink); }
body.in-battle #footer { display: none; }

/* 對戰 */
#battle .bg { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; object-position: center top; }
#crowd { position: absolute; inset: 0; width: 100%; height: 100%; }
.topbar { position: absolute; top: 0; left: 0; right: 0; display: flex; align-items: center; gap: 8px; padding: calc(6px + env(safe-area-inset-top)) 8px 6px; font-size: 13px; font-weight: 700; background: linear-gradient(rgba(255,255,255,.85), rgba(255,255,255,0)); z-index: 5; }
.topbar #neutral { margin-left: auto; background: #eef1f5; border-radius: 999px; padding: 2px 8px; }
.timer { min-width: 34px; text-align: center; border-radius: 999px; padding: 2px 6px; background: #fff; border: 2px solid var(--ink); }
.timer.low { border-color: var(--danger); color: var(--danger); animation: pulse .6s infinite alternate; }
.icon-btn { width: 36px; height: 36px; border-radius: 50%; border: 0; background: rgba(255,255,255,.9); font-size: 16px; }

.info { position: absolute; z-index: 4; width: 52%; padding: 8px 10px; border-radius: 14px; background: rgba(255,253,248,.93); box-shadow: 0 3px 0 rgba(0,0,0,.12); border: 2px solid; font-size: 12px; }
.info.opp { top: calc(48px + env(safe-area-inset-top)); left: 8px; }
.info.me { right: 8px; bottom: calc(var(--dock-h) + 8px); }
.info.blue { border-color: var(--blue); }
.info.green { border-color: var(--green); }
.info .row { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.info .who { font-weight: 900; font-size: 14px; }
.info .count { font-weight: 900; font-size: 18px; }
.bar { height: 8px; border-radius: 999px; background: #e3e7ee; overflow: hidden; margin-top: 4px; }
.bar > i { display: block; height: 100%; border-radius: 999px; transition: width .4s; }
.bar.sup > i { background: currentColor; }
.bar.voice > i { background: linear-gradient(90deg, #ffb347, #ff5e3a); }
.bar.voice.full > i { animation: pulse .5s infinite alternate; }
.info .statuses { margin-top: 4px; min-height: 16px; display: flex; gap: 4px; flex-wrap: wrap; }
.chip { font-size: 11px; background: #f1f3f7; border-radius: 999px; padding: 1px 6px; }
.chip.bad { background: #ffe6e3; }
.chip.good { background: #fff3cf; }

.mascot { position: absolute; z-index: 3; pointer-events: none; transition: transform .25s; filter: drop-shadow(0 6px 4px rgba(0,0,0,.18)); }
.mascot.opp { right: 5%; top: 21%; height: 21%; }
.mascot.me { left: 2%; bottom: calc(var(--dock-h) - 2%); height: 33%; }
.platform { position: absolute; z-index: 2; border-radius: 50%; opacity: .9; }
.opp-plat { right: 2%; top: 38.5%; width: 34%; height: 5%; }
.me-plat { left: -4%; bottom: calc(var(--dock-h) - 4%); width: 52%; height: 8%; }
.platform.blue { background: radial-gradient(ellipse at center, #8db6ff 0, #2f6fd6 70%, rgba(47,111,214,0) 72%); }
.platform.green { background: radial-gradient(ellipse at center, #8fe3b3 0, #1f9a55 70%, rgba(31,154,85,0) 72%); }
.mascot.hit { animation: shake .4s; }
.mascot.joy { animation: hop .45s; }
.mascot.big { animation: glow 1s; }

.field-banner { position: absolute; z-index: 4; top: calc(48px + env(safe-area-inset-top)); right: 8px; background: #2a1e4a; color: #ffe27a; font-weight: 900; font-size: 12px; padding: 6px 10px; border-radius: 999px; box-shadow: 0 0 12px #ffcf3d; }
#battle.night .bg { filter: brightness(.55) saturate(1.3) hue-rotate(-15deg); }

#toasts { position: absolute; z-index: 8; left: 50%; top: 46%; transform: translate(-50%, -50%); display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; width: 92%; }
.toast { background: rgba(35,50,74,.9); color: #fff; padding: 7px 14px; border-radius: 999px; font-size: 14px; font-weight: 700; animation: toast 1.8s forwards; text-align: center; }
.toast.blue { background: rgba(47,111,214,.95); }
.toast.green { background: rgba(31,154,85,.95); }
.toast.big { font-size: 20px; padding: 10px 18px; border: 2px solid var(--gold); }

/* 手牌區 */
.dock { position: absolute; z-index: 6; left: 0; right: 0; bottom: 0; height: var(--dock-h); padding: 6px 8px calc(8px + env(safe-area-inset-bottom)); background: linear-gradient(rgba(255,253,248,.0), rgba(255,253,248,.95) 22%); display: flex; flex-direction: column; gap: 6px; justify-content: flex-end; }
.dock-row { display: flex; align-items: center; gap: 8px; }
.ap { display: flex; gap: 3px; flex-wrap: wrap; flex: 1; align-items: center; font-size: 12px; font-weight: 700; }
.ap i { width: 13px; height: 13px; border-radius: 50%; background: var(--gold); border: 2px solid #b67f00; display: inline-block; }
.ap i.used { background: #e6e1d4; border-color: #c9c2b0; }
.end-btn, .ult-btn { min-height: 42px; border-radius: 999px; padding: 0 16px; font-weight: 900; border: 0; box-shadow: 0 3px 0 rgba(0,0,0,.18); }
.end-btn { background: var(--ink); color: #fff; }
.end-btn:disabled { opacity: .4; }
.ult-btn { background: linear-gradient(90deg, #ffb347, #ff5e3a); color: #fff; animation: pulse .6s infinite alternate; }
.hand { display: grid; grid-template-columns: repeat(5, 1fr); gap: 5px; min-height: 0; flex: 1; max-height: 150px; }
.card { position: relative; border-radius: 10px; border: 3px solid var(--gray); background: var(--paper); padding: 18px 4px 4px; display: flex; flex-direction: column; align-items: center; text-align: center; gap: 2px; overflow: hidden; box-shadow: 0 3px 0 rgba(0,0,0,.15); transition: transform .15s; min-height: 0; }
.card.blue { border-color: var(--blue); }
.card.green { border-color: var(--green); }
.card.cant { filter: grayscale(.7); opacity: .6; }
.card:not(.cant):active { transform: translateY(-4px); }
.card .cost { position: absolute; top: 2px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: var(--gold); border: 2px solid #b67f00; font-weight: 900; font-size: 12px; line-height: 16px; }
.card .cost.up { background: var(--danger); border-color: #8f2a22; color: #fff; }
.card .rar { position: absolute; top: 3px; right: 4px; font-size: 10px; color: #c28a00; }
.card .ico { font-size: 22px; line-height: 1; }
.card .nm { font-weight: 900; font-size: 11px; line-height: 1.15; }
.card .tx { font-size: 9.5px; line-height: 1.2; opacity: .85; display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
.card.epic { background: linear-gradient(160deg, #fff7d6, var(--paper) 50%); }

/* 彈窗 */
.modal { position: absolute; inset: 0; z-index: 20; background: rgba(20,28,40,.55); display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal-box { width: 100%; max-height: 90dvh; overflow: auto; background: var(--paper); border-radius: 20px; padding: 18px 16px; box-shadow: 0 10px 30px rgba(0,0,0,.3); }
.modal-box h2 { margin: 0 0 8px; font-size: 20px; }
.modal-box p, .modal-box li { font-size: 14px; line-height: 1.6; }
.modal-box ul { padding-left: 20px; margin: 6px 0; }
.btns { display: flex; gap: 8px; margin-top: 12px; }
.btn { flex: 1; min-height: 46px; border-radius: 14px; border: 0; font-weight: 900; background: #e9edf3; }
.btn.primary { background: var(--ink); color: #fff; }
.btn.blue { background: var(--blue); color: #fff; }
.btn.green { background: var(--green); color: #fff; }
.btn:disabled { opacity: .4; }
.big-card { border: 4px solid var(--gray); border-radius: 18px; padding: 14px; text-align: center; background: var(--paper); }
.big-card.blue { border-color: var(--blue); } .big-card.green { border-color: var(--green); }
.big-card .ico { font-size: 44px; }
.big-card .nm { font-size: 22px; font-weight: 900; }
.big-card .meta { font-size: 12px; opacity: .7; }
.big-card .tx { font-size: 16px; margin: 8px 0; font-weight: 700; }
.big-card .fl { font-size: 13px; font-style: italic; opacity: .75; }
.ult-list { display: flex; flex-direction: column; gap: 8px; }
.ult-item { text-align: left; border: 2px solid #e2c06a; background: #fffaf0; border-radius: 14px; padding: 10px 12px; min-height: 48px; }
.ult-item b { display: block; font-size: 16px; }
.ult-item span { font-size: 13px; opacity: .8; }
.ult-item:disabled { opacity: .45; }
.result-img { display: block; height: 180px; margin: 0 auto 6px; }
.score { font-size: 28px; font-weight: 900; text-align: center; }
.score .b { color: var(--blue); } .score .g { color: var(--green); }

@keyframes pulse { from { filter: brightness(1); } to { filter: brightness(1.25); } }
@keyframes shake { 0%,100% { transform: translateX(0); } 20% { transform: translateX(-8px) rotate(-3deg); } 40% { transform: translateX(8px) rotate(3deg); } 60% { transform: translateX(-5px); } 80% { transform: translateX(5px); } }
@keyframes hop { 0%,100% { transform: translateY(0); } 40% { transform: translateY(-14px); } }
@keyframes glow { 0%,100% { filter: drop-shadow(0 6px 4px rgba(0,0,0,.18)); } 50% { filter: drop-shadow(0 0 22px #ffcf3d) brightness(1.15); transform: scale(1.06); } }
@keyframes toast { 0% { opacity: 0; transform: translateY(10px) scale(.9); } 12% { opacity: 1; transform: none; } 80% { opacity: 1; } 100% { opacity: 0; transform: translateY(-14px); } }

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
@media (min-height: 760px) { .card .tx { font-size: 10.5px; } .card .nm { font-size: 12px; } }

/* 連線模式 */
.input { width: 100%; min-height: 46px; border-radius: 12px; border: 2px solid #c9d3e0; padding: 0 12px; font: inherit; font-size: 16px; background: #fff; }
.input:focus { outline: none; border-color: var(--ink); }
.btns.col { flex-direction: column; }
.row-join { display: flex; gap: 8px; margin-top: 8px; }
.row-join .input { flex: 1; text-transform: uppercase; letter-spacing: 3px; }
.row-join .btn { flex: 0 0 80px; }
.modal-box hr { border: 0; border-top: 1px dashed #d5dbe5; margin: 14px 0 10px; }
.err { color: var(--danger); min-height: 1em; margin: 4px 0; opacity: 1; }
.code { font-size: 40px; font-weight: 900; letter-spacing: 8px; text-align: center; padding: 10px; background: #fff; border: 3px dashed var(--ink); border-radius: 16px; margin: 6px 0 10px; }
.nick { font-weight: 700; opacity: .9; margin-bottom: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#ts-box { display: flex; justify-content: center; min-height: 70px; margin: 10px 0; }
