: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; }
body { padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
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, #history { 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; text-align: right; }
.pick-group { font-size: 10px; letter-spacing: .2em; text-transform: uppercase; color: var(--muted); margin-top: 6px; }
.seat .deck-name { color: var(--muted); font-size: 11px; }
.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 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); }

/* the battlefield: one column per area, enemy side on top, yours below */
.areas { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; align-items: stretch; min-height: 320px; }
.area { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: 12px; background: rgba(255,255,255,.015); overflow: hidden; }
.area-title { font-size: 10px; letter-spacing: .25em; text-transform: uppercase; color: var(--muted); text-align: center; padding: 3px 0; border-bottom: 1px solid var(--line); }
.side { position: relative; flex: 1; display: flex; flex-wrap: wrap; gap: 6px; align-content: center; justify-content: center; padding: 8px 8px 16px; min-height: 130px; border: 2px dashed transparent; border-radius: 10px; margin: 4px; transition: box-shadow .15s, border-color .15s; }
.side.enemy { align-content: flex-start; }
.side.ally { align-content: flex-end; }
.side .cap { position: absolute; bottom: 2px; right: 8px; font-size: 10px; color: var(--muted); }
.side .cap.open { color: var(--good); }
.side.targetable { border-color: var(--accent); box-shadow: var(--glow); cursor: pointer; }
.side.flash { animation: flash .5s; }
@keyframes flash { 0%{background:rgba(255,255,255,.25)} 100%{background:transparent} }
.area .battle-line { margin: 0 8px; }
.ship-token.attackable { cursor: pointer; }
.ship-token.attackable .ship-svg { filter: drop-shadow(0 0 6px rgba(89,224,138,.9)); }
.ship-token.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))} }
.ship-token.attacking .ship-svg { filter: drop-shadow(0 0 12px rgba(255,255,255,1)); animation: none; }
.ship-token.targetable { cursor: pointer; }
.ship-token.using .ship-svg { filter: drop-shadow(0 0 12px rgba(156,196,255,1)); }
.ship-token, .mini { position: relative; }
.abil-btn { position: absolute; right: 2px; bottom: 2px; font: 700 11px system-ui, sans-serif; color: #fff; background: #0f2f6b; border: 1px solid #9cc4ff; border-radius: 10px; padding: 1px 6px; cursor: pointer; line-height: 1.3; }
.abil-btn:hover, .abil-btn.active { background: #1d4fb0; box-shadow: 0 0 8px rgba(156,196,255,.9); }
.mini .abil-btn { right: -4px; bottom: -4px; padding: 0 4px; font-size: 10px; }
.flagship { position: relative; }
.flagship .flag-abil { right: 8px; bottom: 8px; }
.ship-token.targetable .ship-svg { filter: drop-shadow(0 0 4px var(--accent)) drop-shadow(0 0 10px var(--accent)); }
.ship-token.threat .ship-svg { filter: drop-shadow(0 0 8px rgba(255,107,107,.9)); }
.ship-token.flash { animation: tokflash .5s; }
@keyframes tokflash { 0%{transform:scale(1.08)} 100%{transform:none} }
.ship-token { width: 88px; height: 110px; 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: 220px; height: auto; }
#preview .hint { color: var(--muted); font-size: 12px; align-self: center; text-align: center; }
.preview-body { width: 100%; display: flex; flex-direction: column; align-items: center; }
.preview-head { position: relative; width: 100%; margin-bottom: 8px; padding: 6px 26px 6px 8px; border-radius: 8px; background: rgba(255,255,255,.04); border: 1px solid var(--line); font-size: 12px; line-height: 1.35; }
.preview-from { display: block; font-size: 10px; letter-spacing: .08em; text-transform: uppercase; color: var(--accent); font-weight: 700; }
.preview-text { color: var(--text); }
.preview-close { position: absolute; top: 4px; right: 4px; width: 20px; height: 20px; padding: 0; line-height: 18px; border-radius: 50%; font-size: 14px; }
.glossary { width: 100%; margin: 8px 0 0; font-size: 12px; line-height: 1.4; color: var(--muted); }
.glossary dt { display: inline; color: var(--text); font-weight: 700; }
.glossary dt::after { content: ' — '; color: var(--muted); font-weight: 400; }
.glossary dd { display: inline; margin: 0; }
.glossary dd::after { content: ''; display: block; height: 4px; }
#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.sprout { color: #a8f09a; }
#log .ev.deploy, #log .ev.tactic, #log .ev.station, #log .ev.module { color: var(--text); }
#log .ev.new { animation: fadein .4s; }
#log .ev.has-card { cursor: pointer; border-radius: 4px; margin: 0 -4px; padding: 0 4px; }
#log .ev.has-card:hover { background: rgba(255,255,255,.06); text-decoration: underline dotted; text-underline-offset: 3px; }
#log .ev.has-card.pinned { background: rgba(90,208,255,.12); outline: 1px solid var(--accent); }
@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; }
.overlay-card { max-width: 560px; max-height: 90vh; overflow-y: auto; }
#debrief { text-align: left; margin: 14px 0 18px; font-size: 13px; }
#debrief h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 14px 0 6px; }
#debrief .debrief-wait { color: var(--muted); text-align: center; animation: pulse 1.2s ease-in-out infinite; }
#debrief .moments { margin: 0; padding-left: 20px; }
#debrief .moments li { margin-bottom: 8px; }
#debrief .m-turn { font-weight: 600; }
#debrief .m-line { line-height: 1.4; }
#debrief .val { color: var(--muted); font-variant-numeric: tabular-nums; margin-left: 4px; }
#debrief .val.good { color: var(--good); }
#debrief .habits { margin: 0; padding-left: 20px; }
#debrief .habits li { margin-bottom: 4px; line-height: 1.4; }
#debrief .small { font-size: 11px; margin-top: 6px; }
@keyframes pulse { 0%, 100% { opacity: .5; } 50% { opacity: 1; } }

@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; }
  .areas { min-height: 260px; }
  .ship-token { width: 72px; height: 90px; }
}

/* tutorial coach marks */
#coach { position: fixed; inset: 0; z-index: 20; pointer-events: none; }
#coach-mask { position: absolute; border-radius: 12px; box-shadow: 0 0 0 9999px rgba(0,0,0,.62), 0 0 0 3px var(--accent), 0 0 24px rgba(90,208,255,.7); transition: all .25s; pointer-events: none; }
#coach-mask.none { box-shadow: 0 0 0 9999px rgba(0,0,0,.62); width: 0 !important; height: 0 !important; }
#coach-card { position: absolute; width: 330px; max-width: calc(100vw - 24px); background: var(--panel); border: 1px solid var(--accent); border-radius: 12px; padding: 14px 16px; box-shadow: 0 20px 60px rgba(0,0,0,.6); pointer-events: auto; transition: top .25s, left .25s; }
#coach-card h3 { margin: 2px 0 6px; font-size: 16px; color: var(--accent); }
#coach-card p { margin: 0 0 12px; font-size: 13px; line-height: 1.45; }
#coach-card p b { color: var(--text); }
#coach-step { font-size: 10px; letter-spacing: .15em; text-transform: uppercase; }
.coach-buttons { display: flex; gap: 8px; }
.coach-buttons #coach-skip { margin-right: auto; font-size: 12px; }
#coach-card.waiting #coach-next { display: none; }
#coach-card .do { display: inline-block; margin-top: 4px; color: var(--good); font-weight: 700; }

/* Past games: the list, then one recap (result, coach's moments, the turns). */
button.link { background: none; border: none; color: var(--muted); text-decoration: underline; cursor: pointer; padding: 4px 0; font-size: 13px; }
button.link:hover { color: var(--text); }
.history-card { width: min(760px, 100%); }
.history-head { display: flex; align-items: center; gap: 14px; margin-bottom: 12px; }
.history-head h2 { margin: 0; }
.games { display: flex; flex-direction: column; gap: 6px; }
.games button { display: grid; grid-template-columns: 64px 1fr auto; gap: 12px; align-items: center; text-align: left; padding: 10px 12px; }
.games .result { font-weight: 800; letter-spacing: .1em; }
.games .result.win { color: var(--good, #6fd28f); }
.games .result.loss { color: var(--bad, #e06c6c); }
.games .who { display: flex; flex-direction: column; gap: 2px; }
.games .when { color: var(--muted); font-size: 12px; text-align: right; }
.recap-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 14px; margin: 6px 0 14px; }
.recap-head .result { font-size: 22px; font-weight: 800; letter-spacing: .1em; }
.timeline { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 4px; }
.timeline li { display: grid; grid-template-columns: 52px 1fr auto; gap: 10px; padding: 6px 8px; border-radius: 8px; background: rgba(255,255,255,.03); font-size: 13px; }
.timeline li.ai { background: rgba(224,108,108,.06); }
.timeline li.flag { outline: 1px solid var(--accent); }
.timeline .t { color: var(--muted); font-weight: 700; }
.timeline .acts { color: var(--text); }
.timeline .acts .muted { display: block; }
.timeline .hull { color: var(--muted); white-space: nowrap; }
.player-id { margin-top: 14px; word-break: break-all; }
.player-id code { user-select: all; }
