:root {
  --bg: #0b0f1a;
  --bg2: #121828;
  --bg3: #1b2338;
  --line: #2a3450;
  --text: #e6ebf5;
  --muted: #8a94ab;
  --accent: #7c9cff;
  --good: #3ecf8e;
  --bad: #ff5a5f;
  --vanguard: #4d8dff;
  --swarm: #3ecf8e;
  --syndicate: #ff5a5f;
  --drifters: #f5b942;
  --neutral: #a8b0c2;
  --starter: #5d6679;
  --cw: 104px;
  --ch: 172px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.35 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
body { background: radial-gradient(1200px 600px at 70% -10%, #1d2550 0%, transparent 60%), radial-gradient(800px 500px at -10% 110%, #2a1640 0%, transparent 60%), var(--bg); min-height: 100vh; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
button { font: inherit; color: inherit; }
input, select { font: inherit; color: var(--text); background: var(--bg3); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; width: 100%; }
input:focus, select:focus { outline: 2px solid var(--accent); border-color: transparent; }

.btn { background: var(--bg3); border: 1px solid var(--line); border-radius: 10px; padding: 9px 14px; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--accent); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: linear-gradient(180deg, #6f8dff, #4b67e6); border-color: #6f8dff; color: #fff; font-weight: 600; }
.btn.danger { border-color: var(--bad); color: var(--bad); }
.btn.big { padding: 13px 18px; font-size: 16px; width: 100%; }
.btn.small { padding: 6px 10px; font-size: 13px; }
.btn.ghost { background: transparent; }
.btn.link { background: none; border: none; color: var(--accent); padding: 6px; }

.screen { max-width: 980px; margin: 0 auto; padding: 0 0 90px; }
.bar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 12px; background: rgba(11, 15, 26, .92); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.room-code b { font-family: ui-monospace, monospace; letter-spacing: 3px; font-size: 18px; color: var(--accent); }

/* Home */
.home-wrap { max-width: 380px; margin: 0 auto; padding: 12vh 20px 40px; display: flex; flex-direction: column; gap: 14px; }
.logo { margin: 0; font-size: 44px; letter-spacing: 4px; text-align: center; font-weight: 800; }
.logo span { display: block; font-size: 22px; letter-spacing: 14px; color: var(--accent); margin-top: -4px; }
.tag { text-align: center; color: var(--muted); margin: 0 0 12px; }
.field { display: flex; flex-direction: column; gap: 6px; color: var(--muted); font-size: 13px; }
.or { text-align: center; color: var(--muted); font-size: 13px; }
.join-row { display: flex; gap: 8px; }
.join-row input { text-transform: uppercase; letter-spacing: 4px; font-family: ui-monospace, monospace; text-align: center; font-size: 18px; }
.join-row .btn { width: auto; }

/* Lobby */
.lobby-body { padding: 12px; display: grid; gap: 12px; grid-template-columns: 1fr; }
@media (min-width: 760px) { .lobby-body { grid-template-columns: 1fr 1fr; } }
.panel { background: var(--bg2); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; }
.panel h2 { margin: 0 0 10px; font-size: 15px; text-transform: uppercase; letter-spacing: 1.5px; color: var(--muted); }
.panel h2 small { text-transform: none; letter-spacing: 0; font-weight: normal; }
.banner { grid-column: 1 / -1; background: #1d2a4d; border: 1px solid var(--accent); border-radius: 12px; padding: 10px 14px; display: flex; gap: 10px; align-items: center; justify-content: space-between; }
.members { list-style: none; margin: 0 0 10px; padding: 0; }
.members li { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.members li:last-child { border-bottom: none; }
.members .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--good); flex: none; }
.dot.off { background: #555; }
.pill { font-size: 11px; padding: 2px 7px; border-radius: 20px; background: var(--bg3); color: var(--muted); border: 1px solid var(--line); }
.pill.host { color: var(--drifters); border-color: var(--drifters); }
.toggle { display: flex; gap: 8px; align-items: center; color: var(--muted); font-size: 14px; }
.toggle input { width: auto; }
.rules { display: grid; gap: 10px; margin-bottom: 12px; }
.rules label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.rules .sets label { flex-direction: row; align-items: flex-start; gap: 8px; color: var(--text); }
.rules .sets input { width: auto; margin-top: 3px; }
.rules .sets small { color: var(--muted); display: block; }
.hint { color: var(--muted); font-size: 13px; margin: 8px 0 0; }
.tabs { display: flex; gap: 6px; margin-bottom: 8px; }
.tab { background: none; border: 1px solid var(--line); border-radius: 20px; padding: 4px 12px; cursor: pointer; color: var(--muted); }
.tab.active { color: var(--text); border-color: var(--accent); }
.lb { width: 100%; border-collapse: collapse; font-size: 14px; }
.lb th { text-align: left; color: var(--muted); font-weight: normal; font-size: 12px; padding: 4px; }
.lb td { padding: 6px 4px; border-top: 1px solid var(--line); }
.lb td.n { text-align: right; font-variant-numeric: tabular-nums; }
.chat { max-height: 200px; overflow-y: auto; font-size: 14px; margin-bottom: 8px; display: flex; flex-direction: column; gap: 4px; }
.chat b { color: var(--accent); }
.chat-form { display: flex; gap: 6px; }

/* Game */
.turn-info { text-align: center; font-size: 14px; flex: 1; }
.turn-info b { color: var(--accent); }
.turn-info.mine b { color: var(--good); }
.opponents { display: flex; gap: 10px; overflow-x: auto; padding: 10px 12px; scroll-snap-type: x proximity; }
.opp { flex: 0 0 auto; min-width: 170px; max-width: 320px; background: var(--bg2); border: 1px solid var(--line); border-radius: 14px; padding: 10px; scroll-snap-align: start; }
.opp.current { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.opp.out { opacity: .45; }
.opp .top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.opp .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.opp .auth { font-size: 22px; font-weight: 700; color: var(--good); }
.opp .meta { font-size: 12px; color: var(--muted); margin: 2px 0 6px; }
.opp .bases { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.opp .atk { width: 100%; margin-top: 8px; }
.zone { padding: 4px 12px 6px; }
.zone.mine { background: linear-gradient(180deg, transparent, rgba(124, 156, 255, .06)); border-top: 1px solid var(--line); margin-top: 6px; padding-top: 10px; }
.zone-head { display: flex; justify-content: space-between; font-size: 12px; text-transform: uppercase; letter-spacing: 1.4px; color: var(--muted); margin: 6px 0; }
.row { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 8px; min-height: 40px; }
.row.small-cards .card { --cw: 88px; --ch: 146px; font-size: 10px; }
.row:empty::after { content: '—'; color: var(--muted); align-self: center; }
.stats { display: flex; gap: 8px; flex-wrap: wrap; }
.stat { background: var(--bg2); border: 1px solid var(--line); border-radius: 12px; padding: 6px 12px; display: flex; align-items: baseline; gap: 6px; }
.stat b { font-size: 22px; }
.stat.auth b { color: var(--good); }
.stat.cred b { color: var(--drifters); }
.stat.atk b { color: var(--bad); }
.stat.small { font-size: 12px; color: var(--muted); }
.action-bar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; display: flex; gap: 10px; justify-content: center; padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); background: rgba(11, 15, 26, .95); border-top: 1px solid var(--line); }
.action-bar .btn { flex: 1; max-width: 240px; padding: 12px; }
.pending { margin: 6px 12px; background: #2b2245; border: 1px solid #9a7cff; border-radius: 12px; padding: 10px 12px; display: flex; gap: 10px; align-items: center; justify-content: space-between; }

/* Cards */
.card { flex: 0 0 auto; width: var(--cw); height: var(--ch); border-radius: 10px; padding: 6px; background: linear-gradient(160deg, var(--bg3), #0f1422); border: 1.5px solid var(--fc, var(--line)); display: flex; flex-direction: column; gap: 3px; font-size: 11px; position: relative; cursor: pointer; user-select: none; transition: transform .1s; overflow: hidden; }
.card:active { transform: scale(.97); }
.card::before { content: ''; position: absolute; inset: 0 0 auto 0; height: 3px; background: var(--fc); }
.card.f-vanguard { --fc: var(--vanguard); }
.card.f-swarm { --fc: var(--swarm); }
.card.f-syndicate { --fc: var(--syndicate); }
.card.f-drifters { --fc: var(--drifters); }
.card.f-neutral { --fc: var(--neutral); }
.card.f-starter { --fc: var(--starter); }
.card.wild { border-image: linear-gradient(135deg, var(--vanguard), var(--swarm), var(--syndicate), var(--drifters)) 1; border-radius: 0; }
.card .c-top { display: flex; gap: 4px; align-items: flex-start; }
.card .c-cost { flex: none; width: 20px; height: 20px; border-radius: 50%; background: var(--drifters); color: #1a1200; font-weight: 800; display: grid; place-items: center; font-size: 11px; }
.card .c-name { font-weight: 700; font-size: 1.08em; line-height: 1.15; }
.card .c-type { color: var(--muted); font-size: .9em; }
.card .c-type .def { color: var(--text); font-weight: 700; }
.card .fx { background: rgba(255, 255, 255, .04); border-radius: 6px; padding: 3px 4px; }
.card .fx.ally { border-left: 2px solid var(--fc); }
.card .fx.ally.on { background: color-mix(in srgb, var(--fc) 25%, transparent); }
.card .fx.scrap { border-left: 2px solid #888; }
.card .fx i { font-style: normal; color: var(--muted); font-size: .9em; }
.card.afford { box-shadow: 0 0 0 2px var(--drifters), 0 0 14px rgba(245, 185, 66, .35); }
.card.dim { opacity: .5; }
.card.sel { box-shadow: 0 0 0 3px #9a7cff; transform: translateY(-4px); }
.card.mini { --cw: 74px; --ch: 100px; font-size: 9px; padding: 4px; }
.card.mini .c-cost { width: 16px; height: 16px; font-size: 9px; }
.card.base .c-type::before { content: '⬢ '; }
.card .zone-tag { position: absolute; right: 4px; bottom: 3px; font-size: 9px; color: var(--muted); }

/* Modal / toast */
.modal { position: fixed; inset: 0; z-index: 20; background: rgba(0, 0, 0, .6); display: flex; align-items: flex-end; justify-content: center; }
@media (min-width: 700px) { .modal { align-items: center; } }
.sheet { background: var(--bg2); border: 1px solid var(--line); border-radius: 18px 18px 0 0; width: 100%; max-width: 560px; max-height: 86vh; overflow-y: auto; padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); }
@media (min-width: 700px) { .sheet { border-radius: 18px; } }
.sheet h3 { margin: 0 0 10px; }
.sheet .btns { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.sheet .btns .btn { flex: 1; }
.sheet .bigcard { display: flex; justify-content: center; margin: 4px 0 8px; }
.sheet .bigcard .card { --cw: 200px; height: auto; min-height: 170px; font-size: 14px; cursor: default; }
.sheet .grid { display: flex; flex-wrap: wrap; gap: 8px; }
.sheet .log { font-size: 13px; display: flex; flex-direction: column; gap: 3px; }
.sheet .log div:nth-child(odd) { color: #c8cfe0; }
.stepper { display: flex; align-items: center; gap: 10px; justify-content: center; font-size: 28px; font-weight: 700; margin: 10px 0; }
.stepper .btn { font-size: 20px; width: 48px; }
.results { list-style: none; padding: 0; margin: 0; }
.results li { display: flex; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 16px; }
.results li:first-child { font-size: 20px; font-weight: 700; color: var(--drifters); }
.toast { position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%); z-index: 30; background: #3a1c24; border: 1px solid var(--bad); padding: 10px 16px; border-radius: 12px; max-width: 90vw; }
.toast.ok { background: #16322a; border-color: var(--good); }
.conn { position: fixed; top: 0; left: 0; right: 0; z-index: 40; text-align: center; background: #6b4b00; padding: 4px; font-size: 13px; }
.howto h4 { margin: 14px 0 4px; }
.howto p, .howto li { color: #c8cfe0; font-size: 14px; }

/* v2: art, decks, bots */
.card .c-art { margin: -6px -6px 2px; height: 42px; overflow: hidden; border-radius: 8px 8px 0 0; background: #05070d; flex: none; }
.card .c-art img { width: 100%; height: 100%; object-fit: cover; display: block; pointer-events: none; }
.card.mini .c-art { margin: -4px -4px 2px; height: 26px; }
.row.small-cards .card .c-art { height: 32px; }
.sheet .bigcard .card .c-art { height: 120px; }
.pill.deck { max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bot-row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-top: 10px; font-size: 13px; }
.action-bar .hint-btn { flex: 0 0 auto; max-width: 60px; }
.join-row select { width: auto; flex: 1; }
.home-wrap a.btn { text-decoration: none; }
a.btn { text-decoration: none; display: inline-block; }

/* v3: classic mode */
.force { display: flex; align-items: center; gap: 8px; justify-content: center; padding: 8px 12px 0; font-size: 12px; flex-wrap: wrap; }
.force .ftrack { display: flex; gap: 4px; }
.force .fcell { width: 16px; height: 16px; border-radius: 50%; border: 1px solid var(--line); background: var(--bg3); }
.force .fcell.mid { border-color: var(--muted); }
.force .fcell.on { background: #e8ecff; box-shadow: 0 0 10px #9fb4ff; border-color: #fff; }
.force .fside { font-weight: 700; max-width: 110px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.force .fwith { color: var(--muted); }
.force .fwith.yes { color: #cfe0ff; font-weight: 700; }
.opp.classic { border-top: 3px solid var(--fc); }
.opp.mate { opacity: .85; border-style: dashed; }
.wbar { background: var(--bg3); border-radius: 8px; padding: 5px 8px; margin: 4px 0; cursor: pointer; }
.wbar.empty { color: var(--muted); font-size: 12px; cursor: default; }
.wbar .wname { display: flex; justify-content: space-between; gap: 6px; font-size: 13px; }
.wbar .whp { height: 6px; background: #2a1820; border-radius: 4px; overflow: hidden; margin-top: 4px; }
.wbar .whp span { display: block; height: 100%; background: linear-gradient(90deg, #ff5a5f, #3ecf8e); }
.card.world { --fc: #9fb4ff; }
.card .c-hp { flex: none; min-width: 22px; height: 20px; border-radius: 10px; padding: 0 5px; background: #3ecf8e; color: #062016; font-weight: 800; display: grid; place-items: center; font-size: 11px; }
.card.enemy { opacity: .7; }
.card.enemy.afford { opacity: 1; box-shadow: 0 0 0 2px var(--bad), 0 0 14px rgba(255, 90, 95, .35); }
.card .fx.force { border-left: 2px solid #9fb4ff; }
.pill.side-A { color: #9fb4ff; border-color: #9fb4ff; }
.pill.side-B { color: #ffb38a; border-color: #ffb38a; }
.b-two { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.code-row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-top: 10px; }
.code-row input { width: 130px; flex: none; font-family: ui-monospace, monospace; letter-spacing: 2px; }

/* ---------- move animations (other players' and AI turns) */
.fx-layer { position: fixed; inset: 0; pointer-events: none; z-index: 40; overflow: hidden; }
.fx-ghost { position: fixed; margin: 0; --cw: 150px; --ch: 236px; font-size: 13px; cursor: default; box-shadow: 0 18px 50px rgba(0, 0, 0, .6), 0 0 0 1px rgba(255, 255, 255, .06); will-change: transform, opacity; transform-origin: 50% 50%; }
.fx-ghost .c-art { height: 64px; }
.fx-ghost.fx-bought { box-shadow: 0 18px 50px rgba(0, 0, 0, .6), 0 0 0 2px var(--drifters), 0 0 30px rgba(245, 185, 66, .45); }
.fx-land { animation: fx-land .35s ease-out; }
@keyframes fx-land { from { transform: scale(1.12); box-shadow: 0 0 0 2px var(--accent), 0 0 22px var(--accent); } to { transform: none; box-shadow: none; } }
.fx-deal { animation: fx-deal .5s cubic-bezier(.2,.8,.3,1.2) both; animation-delay: .35s; }
@keyframes fx-deal { from { transform: translateY(-24px) rotateY(80deg); opacity: 0; } to { transform: none; opacity: 1; } }

.fx-bolt { position: fixed; width: 22px; height: 22px; border-radius: 50%; background: radial-gradient(circle, #fff 0%, #ffb3b5 30%, #ff5a5f 60%, transparent 72%); box-shadow: 0 0 18px 6px rgba(255, 90, 95, .7); }
.fx-burst { position: fixed; width: 12px; height: 12px; margin: -6px 0 0 -6px; border-radius: 50%; --bc: #ff5a5f; border: 3px solid var(--bc); box-shadow: 0 0 20px var(--bc); animation: fx-burst .5s ease-out forwards; }
@keyframes fx-burst { from { transform: scale(.3); opacity: 1; } to { transform: scale(9); opacity: 0; border-width: 1px; } }
.fx-float { position: fixed; transform: translate(-50%, -50%); font-weight: 900; font-size: 30px; color: #ff6b70; text-shadow: 0 2px 0 #3a0508, 0 0 14px rgba(255, 90, 95, .8); white-space: nowrap; animation: fx-float 1.1s ease-out forwards; }
.fx-float.big { font-size: 22px; color: #fff; text-shadow: 0 0 16px #ff5a5f, 0 2px 0 #000; }
@keyframes fx-float { 0% { transform: translate(-50%, -20%) scale(.6); opacity: 0; } 20% { transform: translate(-50%, -60%) scale(1.2); opacity: 1; } 100% { transform: translate(-50%, -160%) scale(1); opacity: 0; } }
.fx-hit { animation: fx-shake .4s ease-in-out; }
.fx-hit-hard { animation: fx-shake-hard .5s ease-in-out; }
@keyframes fx-shake { 0%, 100% { transform: none; } 20% { transform: translateX(-6px); } 40% { transform: translateX(5px); } 60% { transform: translateX(-3px); } 80% { transform: translateX(2px); } }
@keyframes fx-shake-hard { 0%, 100% { transform: none; } 15% { transform: translate(-9px, 3px); } 30% { transform: translate(8px, -3px); } 45% { transform: translate(-6px, 2px); } 60% { transform: translate(5px, -1px); } 80% { transform: translate(-2px, 0); } }
.fx-vignette { position: fixed; inset: 0; box-shadow: inset 0 0 120px 30px rgba(255, 40, 50, .55); animation: fx-fade .7s ease-out forwards; }
@keyframes fx-fade { from { opacity: 1; } to { opacity: 0; } }

.fx-turn { position: fixed; left: 0; right: 0; top: 38%; display: flex; justify-content: center; animation: fx-turn 1.3s cubic-bezier(.2,.8,.3,1) forwards; }
.fx-turn span { padding: 10px 26px; border-radius: 40px; background: rgba(18, 24, 40, .92); border: 1px solid var(--line); font-size: 20px; font-weight: 700; letter-spacing: .5px; box-shadow: 0 10px 40px rgba(0, 0, 0, .5); }
.fx-turn.mine span { font-size: 30px; padding: 14px 34px; border-color: var(--accent); color: #fff; box-shadow: 0 0 0 1px var(--accent), 0 0 40px rgba(124, 156, 255, .5); }
@keyframes fx-turn { 0% { transform: translateX(40px) scale(.9); opacity: 0; } 18% { transform: none; opacity: 1; } 75% { transform: none; opacity: 1; } 100% { transform: translateX(-40px); opacity: 0; } }

.fx-caption { position: fixed; left: 50%; bottom: 88px; transform: translate(-50%, 10px); z-index: 41; pointer-events: none; max-width: min(92vw, 460px); background: rgba(18, 24, 40, .94); border: 1px solid var(--line); border-radius: 12px; padding: 7px 14px; font-size: 13px; text-align: center; opacity: 0; transition: opacity .25s, transform .25s; }
.fx-caption.show { opacity: 1; transform: translate(-50%, 0); }
.fx-caption div + div { color: var(--muted); }

.thinking { display: inline-flex; gap: 3px; margin-left: 6px; vertical-align: middle; }
.thinking i { width: 5px; height: 5px; border-radius: 50%; background: var(--accent); animation: fx-dot 1s infinite ease-in-out; }
.thinking i:nth-child(2) { animation-delay: .15s; }
.thinking i:nth-child(3) { animation-delay: .3s; }
@keyframes fx-dot { 0%, 80%, 100% { opacity: .25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }

@media (prefers-reduced-motion: reduce) {
  .fx-deal, .fx-land, .fx-hit, .fx-hit-hard, .thinking i { animation: none; }
}
