:root {
  --bg: #070a14;
  --panel: #10162a;
  --panel-2: #171e36;
  --line: #2a3352;
  --text: #e6e9f2;
  --muted: #8b93ad;
  --accent: #5ad0ff;
  --good: #59e08a;
  --bad: #ff6b6b;
  --glow: 0 0 0 3px rgba(90,208,255,.75), 0 0 18px rgba(90,208,255,.6);
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; background: radial-gradient(1200px 800px at 70% -10%, #1a2350 0%, var(--bg) 60%); color: var(--text); font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
button { font: inherit; color: var(--text); background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 8px 14px; cursor: pointer; }
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: #1e4d7a; border-color: #2f7fbf; }
input { font: inherit; color: var(--text); background: #0b1020; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--bad); min-height: 1.2em; }
.screen { min-height: 100%; }

/* lobby */
#lobby, #waiting { display: flex; align-items: center; justify-content: center; padding: 24px; }
.lobby-card { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 28px 32px; width: min(680px, 100%); box-shadow: 0 20px 60px rgba(0,0,0,.5); }
.lobby-card h1 { margin: 0; letter-spacing: .3em; font-weight: 800; color: var(--accent); }
.tagline { margin: 4px 0 20px; color: var(--muted); }
.lobby-card label { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; font-size: 13px; color: var(--muted); }
.row { display: flex; gap: 20px; margin-bottom: 18px; flex-wrap: wrap; }
.col { flex: 1; min-width: 240px; }
.label { font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.faction-pick { display: flex; flex-direction: column; gap: 6px; }
.faction-pick button { text-align: left; display: flex; align-items: center; gap: 10px; }
.faction-pick button.selected { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.faction-pick .swatch { width: 14px; height: 14px; border-radius: 50%; display: inline-block; }
.faction-pick .desc { color: var(--muted); font-size: 12px; margin-left: auto; }
.buttons { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.join-row { display: flex; gap: 6px; margin-left: auto; }
.join-row input { width: 130px; text-transform: uppercase; letter-spacing: .15em; }
details { margin-top: 18px; color: var(--muted); font-size: 13px; }
details ul { padding-left: 18px; }
details b { color: var(--text); }
.code { font-size: 42px; letter-spacing: .35em; font-weight: 800; color: var(--accent); margin: 10px 0 16px; }

/* game layout */
#game { display: grid; grid-template-columns: 1fr 300px; height: 100vh; }
#board { display: grid; grid-template-rows: 36px auto 1fr 22px 1fr auto 230px; padding: 0 16px 8px; gap: 4px; min-width: 0; }
#topbar { display: flex; gap: 18px; align-items: center; font-size: 13px; }
.brand { letter-spacing: .3em; font-weight: 800; color: var(--accent); }
#turn-label { margin-left: auto; font-weight: 700; }
#turn-label.yours { color: var(--good); }

.zone { display: flex; gap: 16px; align-items: center; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 8px 14px; }
.flagship { min-width: 220px; }
.flagship .name { font-weight: 700; font-size: 13px; margin-bottom: 4px; }
.hullbar { height: 14px; background: #2a1a1a; border-radius: 7px; overflow: hidden; border: 1px solid #5a2a2a; position: relative; }
.hullbar .fill { height: 100%; background: linear-gradient(90deg, #59e08a, #2fb865); transition: width .4s; }
.hullbar .num { position: absolute; inset: 0; text-align: center; font-size: 11px; line-height: 14px; font-weight: 700; color: #fff; text-shadow: 0 1px 2px #000; }
.flagship.targetable .hullbar { box-shadow: var(--glow); cursor: pointer; }
.flagship.hit .hullbar { animation: shake .35s; }
@keyframes shake { 0%{transform:translateX(0)} 25%{transform:translateX(-4px)} 50%{transform:translateX(4px)} 75%{transform:translateX(-3px)} 100%{transform:translateX(0)} }
.zone-info { display: flex; gap: 14px; flex-wrap: wrap; flex: 1; align-items: center; }
.seat { display: flex; gap: 8px; align-items: center; font-size: 12px; padding: 4px 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel-2); }
.seat.current { border-color: var(--accent); }
.seat .nm { font-weight: 700; }
.seat .pill { background: #0b1020; border-radius: 6px; padding: 1px 6px; color: var(--muted); }
.mini-row { display: flex; gap: 4px; align-items: center; }
.mini { width: 40px; height: 56px; }
.mini svg { width: 100%; height: 100%; display: block; }
.mini-label { font-size: 11px; color: var(--muted); }

.lanes { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; align-items: stretch; min-height: 150px; }
.lane { position: relative; border: 2px dashed var(--line); border-radius: 12px; display: flex; align-items: center; justify-content: center; background: rgba(255,255,255,.015); transition: box-shadow .15s, border-color .15s; }
.lane .lane-num { position: absolute; top: 4px; left: 8px; font-size: 10px; color: var(--muted); }
.lane.targetable { border-color: var(--accent); box-shadow: var(--glow); cursor: pointer; }
.lane.attackable { cursor: pointer; }
.lane.attackable .ship-svg { filter: drop-shadow(0 0 6px rgba(89,224,138,.9)); }
.lane.ready-pulse .ship-svg { animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 0%,100%{filter:drop-shadow(0 0 3px rgba(89,224,138,.6))} 50%{filter:drop-shadow(0 0 12px rgba(89,224,138,1))} }
.lane.threat { border-color: var(--bad); box-shadow: 0 0 0 3px rgba(255,107,107,.6); }
.lane.flash { animation: flash .5s; }
@keyframes flash { 0%{background:rgba(255,255,255,.25)} 100%{background:rgba(255,255,255,.015)} }
.ship-token { width: 112px; height: 140px; position: relative; }
.ship-token svg { width: 100%; height: 100%; display: block; }
.ship-token.stunned::after { content: "STUNNED"; position: absolute; top: 45%; left: 0; right: 0; text-align: center; font-size: 11px; font-weight: 800; color: #ffd166; text-shadow: 0 0 6px #000; letter-spacing: .1em; }
.ship-token.exhausted svg { opacity: .6; }
.ship-token.ally-owned-other::before { content: "ally"; position: absolute; top: -8px; right: -6px; font-size: 9px; background: var(--accent); color: #000; border-radius: 6px; padding: 1px 5px; font-weight: 700; }
.battle-line { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 10px; letter-spacing: .3em; text-transform: uppercase; }
.battle-line::before, .battle-line::after { content: ""; flex: 1; height: 1px; background: linear-gradient(90deg, transparent, var(--line), transparent); }

#hand-area { display: grid; grid-template-columns: 60px 1fr 150px; gap: 12px; align-items: center; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px; }
#energy { display: flex; flex-direction: column; align-items: center; gap: 4px; }
#energy .big { font-size: 26px; font-weight: 800; color: var(--accent); }
#energy .pips { display: grid; grid-template-columns: repeat(2, 12px); gap: 3px; }
#energy .pip { width: 12px; height: 12px; border-radius: 50%; background: #1e2a48; border: 1px solid var(--line); }
#energy .pip.on { background: var(--accent); box-shadow: 0 0 6px var(--accent); }
#hand { display: flex; gap: 8px; overflow-x: auto; padding: 6px 4px; min-height: 210px; align-items: flex-end; }
.hand-card { width: 138px; flex: 0 0 auto; transition: transform .12s; position: relative; }
.hand-card svg { width: 100%; height: auto; display: block; }
.hand-card.playable { cursor: pointer; }
.hand-card.playable:hover { transform: translateY(-10px); }
.hand-card.playable .card-svg { filter: drop-shadow(0 0 5px rgba(90,208,255,.7)); }
.hand-card.selected { transform: translateY(-14px) scale(1.04); }
.hand-card.selected .card-svg { filter: drop-shadow(0 0 10px rgba(255,255,255,.9)); }
.hand-card.unplayable svg { opacity: .55; }
#hand-side { display: flex; flex-direction: column; gap: 8px; align-items: stretch; }
#status { font-size: 12px; color: var(--muted); min-height: 3em; }

#side { display: flex; flex-direction: column; gap: 10px; padding: 10px 12px 10px 0; min-height: 0; }
#preview { width: 100%; min-height: 200px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 8px; display: flex; justify-content: center; }
#preview svg { width: 100%; max-width: 250px; height: auto; }
#preview .hint { color: var(--muted); font-size: 12px; align-self: center; text-align: center; }
#log { flex: 1; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 8px 10px; overflow-y: auto; font-size: 12px; line-height: 1.45; min-height: 0; }
#log .ev { color: var(--muted); }
#log .ev.turn { color: var(--accent); font-weight: 700; margin-top: 6px; }
#log .ev.hit-flagship, #log .ev.destroyed, #log .ev.destroy { color: var(--bad); }
#log .ev.ambush { color: #ffd166; font-weight: 700; }
#log .ev.deploy, #log .ev.tactic, #log .ev.station, #log .ev.module { color: var(--text); }
#log .ev.new { animation: fadein .4s; }
@keyframes fadein { from { opacity: 0; transform: translateX(6px);} to { opacity: 1; transform: none; } }

#overlay { position: fixed; inset: 0; background: rgba(0,0,0,.7); display: flex; align-items: center; justify-content: center; z-index: 10; }
.overlay-card { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 28px 40px; text-align: center; }
.overlay-card h2 { margin: 0 0 8px; font-size: 32px; }

@media (max-width: 1100px) {
  #game { grid-template-columns: 1fr; height: auto; }
  #side { flex-direction: row; padding: 0 16px 16px; }
  #preview { width: 220px; }
  #log { height: 260px; }
}
