:root {
  --bg: #0f2b1e; --bg2: #143626; --card: #1c4432; --card2: #245640; --line: #2f6b4f;
  --text: #eef7ee; --muted: #9fc2ab; --green: #4caf50; --green2: #2e7d32;
  --orange: #e0913a; --gold: #ffd54f; --red: #e05a5a; --blue: #4fa3e0;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", "Helvetica Neue", Arial, sans-serif;
  overscroll-behavior: none; -webkit-text-size-adjust: 100%; }
body { touch-action: manipulation; -webkit-user-select: none; user-select: none; }
button { font: inherit; color: inherit; }
input { font: inherit; }
h1, h2, h3 { margin: 0; }
h3 { font-size: 15px; color: var(--muted); margin: 16px 0 8px; font-weight: 600; }
h3 small { font-weight: 400; }
p { margin: 8px 0; line-height: 1.5; }
.muted { color: var(--muted); }
.spacer { flex: 1; min-height: 12px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; }
.row.center { justify-content: center; }

#app { min-height: 100vh; min-height: 100dvh; }
.screen { display: none; min-height: 100vh; min-height: 100dvh; flex-direction: column;
  padding: calc(12px + env(safe-area-inset-top)) calc(16px + env(safe-area-inset-right)) calc(16px + env(safe-area-inset-bottom)) calc(16px + env(safe-area-inset-left));
  background: radial-gradient(ellipse at top, var(--bg2), var(--bg) 70%); }
.screen.active { display: flex; }
.content { display: flex; flex-direction: column; flex: 1; max-width: 720px; width: 100%; margin: 0 auto; }
.content.narrow { max-width: 460px; gap: 12px; }
.center-col { display: flex; flex-direction: column; align-items: center; justify-content: center; flex: 1; gap: 16px; text-align: center; }

.title { font-size: clamp(42px, 10vw, 72px); font-weight: 900; letter-spacing: 2px; text-shadow: 0 4px 0 rgba(0,0,0,.35); line-height: 1.1; }
.t-frog { color: #7ee081; } .t-turtle { color: #f0b060; } .t-vs { color: #fff; font-size: .6em; margin: 0 6px; }
.subtitle { color: var(--muted); font-size: 16px; margin: 0; }
.version { font-size: 12px; }

.chips { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.chip { background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.12); border-radius: 999px; padding: 8px 14px; font-size: 14px; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.chip.gold { color: var(--gold); }
.chip.item { cursor: pointer; }
.chip.item.selected { background: var(--green2); border-color: #81c784; }
.chip.item small { color: var(--muted); }
.chips.disabled { opacity: .5; pointer-events: none; }
button.chip { cursor: pointer; }

.menu-buttons { display: flex; flex-direction: column; gap: 12px; width: 100%; max-width: 360px; }
.btn { border: 0; border-radius: 14px; padding: 12px 18px; font-size: 16px; font-weight: 700; background: var(--card2); color: var(--text); cursor: pointer;
  box-shadow: 0 3px 0 rgba(0,0,0,.35); transition: transform .05s, filter .1s; }
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(0,0,0,.35); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.big { padding: 16px 20px; font-size: 19px; min-height: 58px; }
.btn.small { padding: 8px 12px; font-size: 14px; }
.btn.primary { background: var(--green); color: #05230c; }
.btn.accent { background: var(--orange); color: #2a1500; }
.btn.danger { background: var(--red); color: #fff; }
.btn.ghost { background: transparent; box-shadow: none; border: 1px solid rgba(255,255,255,.18); font-weight: 600; }
.btn.buy { background: var(--gold); color: #3a2a00; }
.btn.upgrade { background: var(--blue); color: #001a2e; }

.bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding-bottom: 8px; border-bottom: 1px solid rgba(255,255,255,.08); margin-bottom: 8px; }
.bar h2 { font-size: 20px; }
.code { font-family: ui-monospace, Menlo, monospace; letter-spacing: 4px; color: var(--gold); font-size: 24px; }

.faction-row { display: flex; gap: 12px; }
.faction-card { flex: 1; background: var(--card); border: 2px solid transparent; border-radius: 16px; padding: 14px; cursor: pointer; text-align: center; }
.faction-card.selected { border-color: var(--gold); background: var(--card2); }
.faction-card .emoji { font-size: 40px; }
.faction-card .fname { font-size: 20px; font-weight: 800; margin-top: 4px; }
.faction-card .fsub { font-size: 13px; color: var(--muted); }

.seg-row { display: flex; background: var(--card); border-radius: 12px; padding: 4px; gap: 4px; }
.seg { flex: 1; border: 0; background: transparent; border-radius: 9px; padding: 10px; font-weight: 700; cursor: pointer; color: var(--muted); }
.seg.selected { background: var(--green); color: #05230c; }

.lineup { display: flex; gap: 8px; flex-wrap: wrap; }
.lineup-unit { background: var(--card); border-radius: 12px; padding: 6px; width: 76px; text-align: center; }
.lineup-unit canvas { width: 56px; height: 56px; display: block; margin: 0 auto; }
.lineup-label { font-size: 11px; color: var(--muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.join-row { display: flex; gap: 10px; }
#join-code { flex: 1; min-width: 0; border-radius: 14px; border: 2px solid var(--line); background: #0b1f16; color: var(--gold); font-size: 26px; text-align: center; letter-spacing: 6px; text-transform: uppercase; padding: 8px; font-family: ui-monospace, Menlo, monospace; }
.queued-box { display: none; align-items: center; gap: 10px; background: var(--card); border-radius: 14px; padding: 12px 14px; }
.queued-box.show { display: flex; }
.spinner { width: 18px; height: 18px; border: 3px solid rgba(255,255,255,.2); border-top-color: var(--gold); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.players { display: flex; align-items: stretch; gap: 10px; }
.pcard { flex: 1; background: var(--card); border-radius: 16px; padding: 14px; text-align: center; border: 2px solid transparent; }
.pcard.ready { border-color: var(--green); }
.pcard.offline { opacity: .5; }
.pcard.empty { border-style: dashed; border-color: rgba(255,255,255,.15); }
.pcard .pemoji { font-size: 40px; }
.pcard .pname { font-weight: 800; font-size: 17px; margin-top: 4px; word-break: break-all; }
.pcard .pfaction { color: var(--muted); font-size: 13px; }
.pcard .pstate { margin-top: 6px; font-size: 14px; }
.vs { align-self: center; font-weight: 900; color: var(--gold); font-size: 20px; }

.tabs { display: flex; gap: 6px; margin-bottom: 8px; }
.tab { flex: 1; border: 0; border-radius: 12px; padding: 10px 4px; background: var(--card); color: var(--muted); font-weight: 700; cursor: pointer; font-size: 15px; }
.tab.selected { background: var(--green); color: #05230c; }

.card { background: var(--card); border-radius: 16px; padding: 12px; display: flex; gap: 12px; align-items: center; margin-bottom: 10px; }
.card.locked { opacity: .85; }
.card .portrait { width: 72px; height: 72px; flex: none; background: rgba(0,0,0,.2); border-radius: 12px; }
.card .info { flex: 1; min-width: 0; }
.card .name { font-weight: 800; font-size: 17px; display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap; }
.card .name .ttl { color: var(--muted); font-size: 12px; font-weight: 600; }
.card .name .lv { color: var(--gold); font-size: 13px; margin-left: auto; }
.card .desc { font-size: 12px; color: var(--muted); margin: 2px 0 4px; line-height: 1.4; }
.card .stats { font-size: 12px; color: #cfe6d6; display: flex; flex-wrap: wrap; gap: 4px 10px; }
.card .stats b { color: #fff; font-weight: 600; }
.card .traits { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 4px; }
.card .trait { font-size: 11px; background: rgba(79,163,224,.25); border-radius: 6px; padding: 2px 6px; color: #bfe0ff; }
.card .actions { flex: none; display: flex; flex-direction: column; gap: 6px; align-items: stretch; min-width: 96px; }
.card .actions .btn { padding: 10px 8px; font-size: 14px; line-height: 1.2; }
.card .actions .btn small { display: block; font-size: 11px; font-weight: 600; opacity: .85; }
.card .actions .max { text-align: center; color: var(--gold); font-weight: 800; }
.card .icon { font-size: 40px; width: 56px; text-align: center; flex: none; }
.card .own { color: var(--gold); font-weight: 700; font-size: 13px; }
.lvbar { display: flex; gap: 3px; margin-top: 6px; }
.lvbar i { flex: 1; height: 6px; border-radius: 3px; background: rgba(255,255,255,.12); }
.lvbar i.on { background: var(--gold); }

#scr-battle.active { padding: 0; display: block; background: #000; position: fixed; inset: 0; overflow: hidden; }
#game { display: block; position: absolute; touch-action: none; }
#rotate-hint { display: none; position: absolute; inset: 0; background: rgba(0,0,0,.92); color: #fff; align-items: center; justify-content: center; flex-direction: column; gap: 16px; font-size: 20px; font-weight: 700; z-index: 5; text-align: center; padding: 20px; }
#rotate-hint.show { display: flex; }
.rot-icon { font-size: 64px; animation: rot 1.6s ease-in-out infinite alternate; }
@keyframes rot { from { transform: rotate(0); } to { transform: rotate(-90deg); } }

#result-title { font-size: 48px; font-weight: 900; text-shadow: 0 4px 0 rgba(0,0,0,.35); }
#result-title.win { color: var(--gold); } #result-title.lose { color: #ef9a9a; } #result-title.draw { color: #cfd8dc; }
.result-box { background: var(--card); border-radius: 16px; padding: 16px 24px; font-size: 16px; line-height: 1.8; min-width: 260px; }
.result-box .reward { font-size: 26px; font-weight: 900; color: var(--gold); }

.modal { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.7); z-index: 20; padding: 20px; align-items: center; justify-content: center; }
.modal.open { display: flex; }
.modal-box { background: var(--bg2); border-radius: 18px; padding: 20px; max-width: 520px; width: 100%; max-height: 90vh; overflow: auto; }
.modal-box ul { padding-left: 18px; line-height: 1.7; font-size: 15px; }
.modal-box .btn { width: 100%; margin-top: 10px; }

#toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px); background: rgba(0,0,0,.85); color: #fff; padding: 10px 18px; border-radius: 999px; font-size: 15px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 50; max-width: 90vw; text-align: center; }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 480px) {
  .card { flex-wrap: wrap; }
  .card .actions { flex-direction: row; width: 100%; }
  .card .actions .btn { flex: 1; }
}
