/* ============================================================ STARFALL UI ===
   Deep-indigo tactical holo-display. The board is the hero; chrome stays quiet.
   Display/HUD face: Chakra Petch. Body: Inter.
   ========================================================================== */

:root {
  /* space + chrome */
  --bg:        #070b16;
  --bg-2:      #0a1020;
  --panel:     rgba(13, 20, 38, 0.88);
  --panel-2:   rgba(18, 27, 49, 0.92);
  --line:      #223052;
  --line-soft: #18233e;
  --ink:       #e8eef9;
  --ink-2:     #8696bb;
  --ink-dim:   #566189;
  --accent:    #67e8f9;   /* plasma cyan — selection/focus only */
  --danger:    #ff7a7a;

  /* faction colours */
  --f0: #2dd4bf;  --f0-edge: #0f766e;  --f0-lit: #5eead4;
  --f1: #fb5e5e;  --f1-edge: #b1342f;  --f1-lit: #ff8a8a;
  --f2: #f5b13d;  --f2-edge: #b5781a;  --f2-lit: #fcd77f;
  --f3: #a78bfa;  --f3-edge: #6d3fd4;  --f3-lit: #c4b5fd;

  --r: 14px;
  --shadow: 0 18px 50px rgba(0,0,0,.55);
  --font-hud: "Chakra Petch", "Bahnschrift", "Segoe UI", system-ui, sans-serif;
  --font-body: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font-body);
  color: var(--ink);
  background: var(--bg);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* starfield + nebula sit behind everything */
#stars { position: fixed; inset: 0; z-index: 0; display: block; }
#nebula {
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background:
    radial-gradient(60% 50% at 12% 8%,  rgba(45,212,191,.10), transparent 70%),
    radial-gradient(55% 50% at 92% 96%, rgba(167,139,250,.12), transparent 70%),
    radial-gradient(80% 60% at 50% 120%, rgba(80,120,200,.10), transparent 70%);
}
#app { position: relative; z-index: 1; height: 100%; }

/* shared ------------------------------------------------------------------- */
.hud-font { font-family: var(--font-hud); }
button { font-family: var(--font-hud); cursor: pointer; }
.hidden { display: none !important; }

.wordmark {
  font-family: var(--font-hud);
  font-weight: 700;
  letter-spacing: .28em;
  text-transform: uppercase;
}
.wordmark .glint { color: var(--f0); text-shadow: 0 0 16px rgba(45,212,191,.6); }

.btn {
  font-family: var(--font-hud);
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  font-size: 13px;
  color: var(--ink);
  background: linear-gradient(180deg, rgba(103,232,249,.16), rgba(103,232,249,.06));
  border: 1px solid rgba(103,232,249,.45);
  border-radius: 10px;
  padding: 11px 18px;
  transition: transform .12s ease, background .15s ease, border-color .15s ease;
}
.btn:hover { background: rgba(103,232,249,.22); transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn.ghost {
  background: transparent; border-color: var(--line);
  color: var(--ink-2); text-transform: none; letter-spacing: 0; font-weight: 500;
  font-family: var(--font-body);
}
.btn.ghost:hover { color: var(--ink); border-color: var(--ink-2); background: rgba(255,255,255,.03); }
.btn[disabled] { opacity: .4; cursor: not-allowed; transform: none; }

/* ============================================================ LOBBY screen == */
#lobby {
  height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
  overflow-y: auto;
}
.card {
  width: min(560px, 100%);
  background: var(--panel);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 34px 30px 30px;
}
.brand-row { text-align: center; margin-bottom: 6px; }
.brand-row .wordmark { font-size: clamp(30px, 7vw, 46px); }
.tagline {
  text-align: center; color: var(--ink-2); margin: 4px 0 4px;
  font-family: var(--font-hud); letter-spacing: .18em; text-transform: uppercase;
  font-size: 12px;
}
.lede { text-align: center; color: var(--ink-dim); font-size: 13.5px; line-height: 1.5;
  margin: 14px auto 26px; max-width: 42ch; }

.field { margin-bottom: 20px; }
.field > label {
  display: block; font-family: var(--font-hud); font-size: 11px;
  letter-spacing: .14em; text-transform: uppercase; color: var(--ink-2);
  margin-bottom: 9px;
}
.field .sub { color: var(--accent); font-weight: 600; }

.seg { display: flex; gap: 8px; flex-wrap: wrap; }
.seg button {
  flex: 1 1 0; min-width: 54px;
  background: rgba(255,255,255,.02);
  border: 1px solid var(--line-soft);
  color: var(--ink-2);
  border-radius: 10px; padding: 12px 6px;
  font-size: 15px; font-weight: 600; letter-spacing: .04em;
  transition: all .14s ease;
}
.seg button:hover { color: var(--ink); border-color: var(--line); }
.seg button[aria-pressed="true"] {
  color: var(--bg); background: var(--accent);
  border-color: var(--accent); box-shadow: 0 0 18px rgba(103,232,249,.35);
}
.seg.small button { font-size: 13px; }

.names { display: grid; gap: 10px; }
.names input {
  width: 100%; background: rgba(255,255,255,.03);
  border: 1px solid var(--line-soft); border-radius: 10px;
  color: var(--ink); padding: 11px 13px; font-size: 14px;
  font-family: var(--font-body);
}
.names input::placeholder { color: var(--ink-dim); }
.names input:focus { outline: none; border-color: var(--accent); background: rgba(103,232,249,.05); }
.name-row { display: flex; align-items: center; gap: 10px; }
.name-row .dot { flex: none; }

.dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block;
  box-shadow: 0 0 10px currentColor; }

.actions { margin-top: 26px; display: flex; gap: 12px; }
.actions .btn { flex: 1; padding: 14px; font-size: 14px; }

/* share panel */
.share-title { font-family: var(--font-hud); font-size: 20px; letter-spacing: .06em;
  text-align: center; margin: 4px 0 2px; }
.code-chip {
  display: block; text-align: center; font-family: var(--font-hud);
  font-size: 30px; font-weight: 700; letter-spacing: .42em; color: var(--accent);
  text-shadow: 0 0 22px rgba(103,232,249,.4); margin: 10px 0 4px; padding-left: .42em;
}
.share-note { text-align: center; color: var(--ink-dim); font-size: 13px; margin-bottom: 22px; }
.link-row {
  display: flex; align-items: center; gap: 10px; padding: 12px;
  background: rgba(255,255,255,.02); border: 1px solid var(--line-soft);
  border-radius: 12px; margin-bottom: 10px;
}
.link-row.host { border-color: rgba(103,232,249,.4); background: rgba(103,232,249,.05); }
.link-meta { flex: 1; min-width: 0; }
.link-who { font-family: var(--font-hud); font-size: 13px; letter-spacing: .04em; }
.link-role { font-size: 11px; color: var(--ink-dim); margin-top: 2px; }
.link-url { font-size: 11px; color: var(--ink-2); font-family: ui-monospace, monospace;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 3px; }
.copy-btn { flex: none; font-size: 11px; padding: 8px 12px; border-radius: 8px;
  background: rgba(255,255,255,.04); border: 1px solid var(--line); color: var(--ink-2); }
.copy-btn:hover { color: var(--ink); border-color: var(--ink-2); }
.copy-btn.done { color: var(--f0); border-color: var(--f0); }
.ai-note { text-align: center; color: var(--ink-2); font-size: 12.5px; margin: 14px 0 4px;
  font-family: var(--font-hud); letter-spacing: .04em; }

/* ============================================================ GAME screen === */
#game { height: 100%; display: flex; flex-direction: column; }

.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 10px 16px; background: var(--panel);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line-soft); flex: none;
}
.topbar .brand { display: flex; align-items: baseline; gap: 10px; flex: none; }
.topbar .wordmark { font-size: 17px; }
.topbar .code { font-family: var(--font-hud); font-size: 12px; color: var(--ink-dim);
  letter-spacing: .18em; }

.scoreboard { display: flex; gap: 8px; flex: 1; flex-wrap: wrap; justify-content: center; }
.chip {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 11px; border-radius: 10px;
  background: rgba(255,255,255,.02); border: 1px solid transparent;
  transition: all .2s ease;
}
.chip .emblem { width: 18px; height: 18px; flex: none; }
.chip .nm { font-family: var(--font-hud); font-size: 13px; letter-spacing: .03em; }
.chip .stat { font-family: var(--font-hud); font-size: 13px; color: var(--ink-2);
  display: flex; gap: 8px; }
.chip .stat b { color: var(--ink); font-weight: 600; }
.chip.turn { background: rgba(103,232,249,.07); border-color: rgba(103,232,249,.35);
  box-shadow: 0 0 16px rgba(103,232,249,.18); }
.chip.you .nm::after { content: " · you"; color: var(--accent); font-size: 11px; }
.chip.dead { opacity: .35; }
.chip.dead .nm { text-decoration: line-through; }
.chip .bot-tag { font-size: 9px; color: var(--ink-dim); border: 1px solid var(--line);
  border-radius: 4px; padding: 1px 4px; letter-spacing: .1em; }

.tools { display: flex; gap: 6px; flex: none; }
.icon-btn {
  width: 38px; height: 38px; display: grid; place-items: center;
  background: transparent; border: 1px solid var(--line-soft); border-radius: 9px;
  color: var(--ink-2);
}
.icon-btn:hover { color: var(--ink); border-color: var(--line); }
.icon-btn svg { width: 18px; height: 18px; }

/* turn banner */
.banner {
  display: flex; align-items: center; gap: 14px;
  padding: 11px 18px; flex: none;
  border-bottom: 1px solid var(--line-soft);
  background: rgba(10,16,32,.6);
}
.banner .b-main { flex: 1; display: flex; align-items: center; gap: 10px; }
.banner .b-title { font-family: var(--font-hud); font-size: 15px; letter-spacing: .04em; }
.banner .b-hint { color: var(--ink-dim); font-size: 12.5px; }
.banner .pip { width: 9px; height: 9px; border-radius: 50%; background: var(--accent);
  box-shadow: 0 0 10px var(--accent); }
.banner.mine { background: linear-gradient(90deg, rgba(103,232,249,.08), transparent 60%); }
.banner.mine .pip { animation: pulse 1.4s ease-in-out infinite; }
.banner.waiting .b-title { color: var(--ink-2); }
.dots::after { content: "…"; animation: dots 1.4s steps(4) infinite; }
.end-btn { flex: none; }

/* board */
.board-wrap { flex: 1; position: relative; overflow: hidden; display: grid; }
#board { width: 100%; height: 100%; display: block; touch-action: manipulation; }
.board-vignette { position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(120% 90% at 50% 45%, transparent 55%, rgba(4,7,14,.55) 100%); }

/* hex states (applied to <g class="hex">) */
.hex { cursor: default; }
.hex polygon.fill { transition: opacity .2s ease; }
.hex .ring { fill: none; stroke: none; pointer-events: none; }
.hex text { font-family: var(--font-hud); font-weight: 600; fill: #f4f8ff;
  text-anchor: middle; dominant-baseline: central; pointer-events: none;
  paint-order: stroke; stroke: rgba(2,6,15,.55); stroke-width: 2.4px;
  stroke-linejoin: round; }
.board.has-selection .hex.enemy:not(.target) polygon.fill,
.board.has-selection .hex.mine:not(.selected) polygon.fill,
.board.has-selection .hex.other polygon.fill { opacity: .4; }
.hex.selectable { cursor: pointer; }
.hex.targetable { cursor: crosshair; }

.hex.selected .ring {
  stroke: var(--accent); stroke-width: 3; opacity: 1;
  filter: drop-shadow(0 0 7px var(--accent));
  animation: selpulse 1.2s ease-in-out infinite;
}
.hex.target .ring {
  stroke: #fff; stroke-width: 2.5; opacity: .95;
  stroke-dasharray: 5 5;
  filter: drop-shadow(0 0 6px var(--danger));
  animation: spin 6s linear infinite, tgpulse 1s ease-in-out infinite;
}
.hex.flash polygon.fill { animation: capflash .6s ease; }
.hex.bump polygon.fill { animation: bump .5s ease; }

@keyframes pulse { 0%,100%{ transform: scale(1); opacity:1 } 50%{ transform: scale(1.5); opacity:.5 } }
@keyframes selpulse { 0%,100%{ opacity:1 } 50%{ opacity:.55 } }
@keyframes tgpulse { 0%,100%{ opacity:.95 } 50%{ opacity:.45 } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes dots { 0%{content:""} 25%{content:"."} 50%{content:".."} 75%{content:"..."} }
@keyframes capflash { 0%{ filter: brightness(2.4); } 100%{ filter: brightness(1); } }
@keyframes bump { 0%{ transform: scale(1);} 40%{ transform: scale(1.12);} 100%{ transform: scale(1);} }

/* attack resolution overlay */
.resolve {
  position: absolute; inset: 0; z-index: 30; display: grid; place-items: center;
  background: rgba(4,7,14,.5); backdrop-filter: blur(2px);
}
.resolve .duel { display: flex; align-items: center; gap: 18px;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 16px;
  padding: 20px 26px; box-shadow: var(--shadow); }
.duel .side { text-align: center; min-width: 120px; }
.duel .side .who { font-family: var(--font-hud); font-size: 12px; letter-spacing: .1em;
  text-transform: uppercase; margin-bottom: 8px; }
.duel .dice { display: flex; gap: 5px; justify-content: center; flex-wrap: wrap; max-width: 150px; }
.duel .die {
  width: 26px; height: 26px; border-radius: 6px; display: grid; place-items: center;
  font-family: var(--font-hud); font-weight: 700; font-size: 14px;
  background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.18);
  color: #fff;
}
.duel .die.roll { animation: dieroll .5s ease; }
@keyframes dieroll { 0%{ transform: translateY(-8px) rotate(-12deg); opacity:0 } 100%{ transform:none; opacity:1 } }
.duel .sum { font-family: var(--font-hud); font-size: 30px; font-weight: 700; margin-top: 8px; }
.duel .vs { font-family: var(--font-hud); color: var(--ink-dim); font-size: 13px; letter-spacing: .2em; }
.duel .verdict { font-family: var(--font-hud); font-weight: 700; letter-spacing: .14em;
  font-size: 15px; margin-top: 10px; text-transform: uppercase; }
.verdict.win { color: var(--f0); text-shadow: 0 0 14px rgba(45,212,191,.5); }
.verdict.loss { color: var(--danger); text-shadow: 0 0 14px rgba(255,122,122,.4); }

/* toasts + turn report */
.toast-stack { position: absolute; left: 50%; bottom: 22px; transform: translateX(-50%);
  z-index: 25; display: flex; flex-direction: column; gap: 8px; align-items: center;
  pointer-events: none; width: min(440px, 92vw); }
.toast {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 16px; box-shadow: var(--shadow); font-size: 13px; color: var(--ink);
  animation: rise .35s ease; max-width: 100%;
}
.toast .t-head { font-family: var(--font-hud); font-size: 12px; letter-spacing: .08em;
  text-transform: uppercase; color: var(--ink-2); margin-bottom: 6px; }
.toast .t-line { display: flex; align-items: center; gap: 8px; margin: 3px 0; }
.toast .t-line .dot { width: 9px; height: 9px; }
@keyframes rise { from { transform: translateY(12px); opacity: 0; } }

/* victory / rules overlay */
.overlay { position: absolute; inset: 0; z-index: 40; display: grid; place-items: center;
  background: rgba(4,7,14,.78); backdrop-filter: blur(8px); padding: 24px; }
.overlay .panel { width: min(460px, 100%); background: var(--panel); border: 1px solid var(--line);
  border-radius: 20px; box-shadow: var(--shadow); padding: 32px 28px; text-align: center; }
.victory-emblem { width: 84px; height: 84px; margin: 0 auto 12px; }
.victory-title { font-family: var(--font-hud); font-weight: 700; font-size: 26px;
  letter-spacing: .06em; margin-bottom: 6px; }
.victory-sub { color: var(--ink-2); font-size: 13.5px; margin-bottom: 22px; }
.standings { text-align: left; margin: 0 0 24px; display: grid; gap: 8px; }
.standings .row { display: flex; align-items: center; gap: 10px; font-size: 13.5px;
  padding: 8px 12px; background: rgba(255,255,255,.02); border-radius: 10px;
  border: 1px solid var(--line-soft); }
.standings .row .nm { font-family: var(--font-hud); flex: 1; }
.standings .row .sc { font-family: var(--font-hud); color: var(--ink-2); }
.standings .row.win { border-color: rgba(103,232,249,.4); }
.rules-body { text-align: left; color: var(--ink-2); font-size: 13.5px; line-height: 1.6; }
.rules-body h4 { font-family: var(--font-hud); color: var(--ink); margin: 16px 0 6px;
  font-size: 13px; letter-spacing: .08em; text-transform: uppercase; }
.rules-body p { margin: 6px 0; }
.rules-body b { color: var(--ink); }

/* mobile ------------------------------------------------------------------- */
@media (max-width: 640px) {
  .topbar { flex-wrap: wrap; gap: 8px; padding: 8px 12px; }
  .scoreboard { order: 3; width: 100%; }
  .chip .nm { display: none; }
  .chip.turn .nm, .chip.you .nm { display: inline; font-size: 12px; }
  .chip { padding: 5px 9px; }
  .banner { padding: 10px 14px; }
  .banner .b-hint { display: none; }
  .card { padding: 26px 20px 22px; }
  .duel { flex-direction: column; gap: 12px; }
  .duel .vs { order: 0; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; animation-iteration-count: 1 !important; }
  .banner.mine .pip { animation: none; }
}
