:root {
  --bg: #11141d;
  --panel: #1a1f2d;
  --panel-2: #232a3b;
  --line: #2f3850;
  --text: #eef1f8;
  --muted: #8d97ad;
  --accent: #ffd166;
  --danger: #ff6b6b;
  --ok: #4ade80;
  --radius: 14px;
  --font-display: 'Fredoka', ui-rounded, 'Segoe UI', system-ui, sans-serif;
  --font: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3, .display { font-family: var(--font-display); font-weight: 600; margin: 0; }
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }

button {
  border: 0;
  border-radius: 12px;
  padding: 12px 18px;
  background: var(--panel-2);
  cursor: pointer;
  font-weight: 600;
  transition: transform .08s, background .15s, opacity .15s;
}
button:active:not(:disabled) { transform: scale(.97); }
button:disabled { opacity: .4; cursor: default; }
button.primary { background: var(--accent); color: #1a1405; }
button.ghost { background: transparent; color: var(--muted); }
button.danger { background: transparent; color: var(--danger); }

input {
  background: var(--panel-2);
  border: 2px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  outline: none;
  min-width: 0;
}
input:focus { border-color: var(--accent); }

.swatch {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 4px;
  flex: none;
}
.muted { color: var(--muted); }
.error { color: var(--danger); min-height: 1.2em; }

/* ---- board ------------------------------------------------------------- */

.board { width: 100%; height: 100%; display: block; overflow: visible; }
.board.clip { overflow: hidden; }
.board.zoomable { touch-action: none; cursor: grab; }
.spawner-label { font: 700 3.2px var(--font); fill: #fff; paint-order: stroke; stroke: rgba(0, 0, 0, .55); stroke-width: .8px; pointer-events: none; }
.tile { transition: fill .45s ease; stroke: rgba(0, 0, 0, .25); stroke-width: .4; }
.tile.pop { animation: pop .55s ease; transform-box: fill-box; transform-origin: center; }
@keyframes pop {
  0% { transform: scale(1); }
  40% { transform: scale(1.22); filter: brightness(1.6); }
  100% { transform: scale(1); }
}

.hl { fill: transparent; stroke-width: 1.4; pointer-events: all; cursor: pointer; }
.hl-move { stroke: #fff; animation: pulse 1.1s ease-in-out infinite; }
.hl-target { stroke: #fff; stroke-width: 2.2; fill: rgba(255, 255, 255, .25); }
.hl-attack { stroke: #ffb3b3; stroke-dasharray: 2 1.5; fill: rgba(255, 107, 107, .18); pointer-events: none; }
@keyframes pulse { 50% { stroke-opacity: .3; } }

.pawn { transition: transform .8s cubic-bezier(.5, -0.3, .4, 1.3); pointer-events: none; }
.pawn-shadow { fill: rgba(0, 0, 0, .45); }
.pawn-ring { fill: #fff; stroke: #10131b; stroke-width: .8; }
.pawn-label { font: 700 5.5px var(--font-display); fill: #fff; paint-order: stroke; stroke: rgba(0, 0, 0, .35); stroke-width: 1px; }
.pawn.offline { opacity: .4; }
.pawn.me .pawn-ring { stroke: var(--accent); stroke-width: 1.4; }
.pawn-body { transform-box: fill-box; transform-origin: center; }
.pawn-body.spawning { animation: spawn .6s cubic-bezier(.3, 1.6, .5, 1); }
.pawn-body.dying { animation: die .55s ease-in forwards; }
@keyframes spawn { from { transform: scale(0); } }
@keyframes die {
  30% { transform: scale(1.35); opacity: 1; }
  to { transform: scale(.1); opacity: 0; }
}

.spawner { fill: rgba(255, 255, 255, .1); stroke: rgba(255, 255, 255, .75); stroke-width: .9; stroke-dasharray: 2.2 1.3; pointer-events: none; }

.shield {
  fill: rgba(255, 255, 255, .14);
  stroke-width: 1.6;
  transform-box: fill-box;
  transform-origin: center;
  animation: shield 1.3s ease-out forwards;
  pointer-events: none;
}
@keyframes shield {
  0% { transform: scale(.3); opacity: 0; }
  25% { transform: scale(1); opacity: 1; }
  75% { opacity: 1; }
  100% { opacity: 0; }
}
.blocked-flash { fill: #9ecbff; pointer-events: none; animation: flash .9s ease-out forwards; }
.broken-flash { fill: #ffb347; pointer-events: none; animation: flash .9s ease-out forwards; }

.hl-selected { stroke: var(--accent); stroke-width: 2.2; fill: rgba(255, 209, 102, .2); }
.hl-defend { stroke: #9ecbff; stroke-width: 1.2; fill: rgba(158, 203, 255, .18); pointer-events: none; }
.order-arrow { stroke: #fff; stroke-width: 1.4; stroke-linecap: round; pointer-events: none; }
.order-arrow-bg { stroke: rgba(0, 0, 0, .5); stroke-width: 2.8; stroke-linecap: round; pointer-events: none; }
.arrowhead { fill: #fff; }
.order-marker { pointer-events: none; }
.order-marker circle { fill: #10131b; stroke: #fff; stroke-width: .6; }
.order-marker text { font: 700 4.2px var(--font); fill: #fff; }

.shockwave {
  fill: none;
  stroke-width: 1.6;
  transform-box: fill-box;
  transform-origin: center;
  animation: shock .8s ease-out forwards;
  pointer-events: none;
}
@keyframes shock {
  from { transform: scale(.2); opacity: 1; }
  to { transform: scale(1); opacity: 0; }
}
.clash { pointer-events: none; }
.clash-flash { fill: #fff; animation: flash .7s ease-out forwards; }
.clash-x { stroke: #fff; stroke-width: 1.8; stroke-linecap: round; filter: drop-shadow(0 0 1px #000); animation: clash-in .3s ease-out; }
@keyframes flash { from { opacity: .85; } to { opacity: 0; } }
@keyframes clash-in { from { opacity: 0; } }

/* ---- landing page -------------------------------------------------------- */

.landing {
  max-width: 920px;
  margin: 0 auto;
  padding: 48px 16px;
  display: grid;
  gap: 20px;
  grid-template-columns: 1fr 1fr;
}
.landing header { grid-column: 1 / -1; text-align: center; margin-bottom: 12px; }
.landing h1 { font-size: 64px; letter-spacing: 1px; }
.landing h1 span { color: var(--accent); }
.card {
  background: var(--panel);
  border-radius: var(--radius);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.card p { margin: 0; color: var(--muted); line-height: 1.45; }
.card .row { display: flex; gap: 10px; }
.card .row input { flex: 1; text-transform: uppercase; letter-spacing: 6px; font-size: 22px; text-align: center; font-weight: 700; }
.rules { grid-column: 1 / -1; }
.rules ol { margin: 0; padding-left: 20px; color: var(--muted); line-height: 1.6; }
.rules b { color: var(--text); }
@media (max-width: 700px) {
  .landing { grid-template-columns: 1fr; padding-top: 28px; }
  .landing h1 { font-size: 48px; }
}

/* ---- big screen ---------------------------------------------------------- */

.screen { height: 100vh; overflow: hidden; }
.screen-lobby {
  height: 100%;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 48px;
  padding: 56px 72px;
  align-items: center;
}
.screen-lobby .join-box { display: flex; flex-direction: column; gap: 20px; align-items: flex-start; }
.screen-lobby h1 { font-size: 72px; }
.screen-lobby h1 span { color: var(--accent); }
.big-code {
  font-family: var(--font-display);
  font-size: 128px;
  line-height: 1;
  letter-spacing: 16px;
  color: var(--accent);
}
.join-url { font-size: 24px; }
.join-url b { color: var(--text); }
.qr { width: 220px; height: 220px; background: #fff; border-radius: 12px; padding: 8px; }
.screen-lobby .players-box { background: var(--panel); border-radius: var(--radius); padding: 28px; align-self: stretch; display: flex; flex-direction: column; gap: 16px; }
.lobby-players { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.lobby-player {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--panel-2);
  border-radius: 12px;
  padding: 14px 16px;
  font-size: 22px;
  font-weight: 600;
  animation: slide-in .3s ease;
}
.lobby-player .swatch { width: 26px; height: 26px; border-radius: 50%; }
.lobby-player.offline { opacity: .45; }
.tag { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; color: var(--accent); background: rgba(255, 209, 102, .12); padding: 3px 7px; border-radius: 6px; }
.tag.off { color: var(--danger); background: rgba(255, 107, 107, .12); }
@keyframes slide-in { from { transform: translateY(8px); opacity: 0; } }
.lobby-status { font-size: 22px; color: var(--muted); margin-top: auto; }

.screen-game { height: 100%; display: grid; grid-template-columns: 1fr 380px; }
.screen-board { padding: 32px; min-height: 0; min-width: 0; position: relative; }
.sidebar {
  background: var(--panel);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  overflow-y: auto;
}
.sidebar .brand { display: flex; justify-content: space-between; align-items: baseline; }
.sidebar .brand h2 { font-size: 30px; }
.sidebar .brand h2 span { color: var(--accent); }
.code-chip { font-family: var(--font-display); font-size: 20px; letter-spacing: 3px; color: var(--accent); }
.round { font-family: var(--font-display); font-size: 40px; }
.round small { font-size: 22px; color: var(--muted); }
.phase-banner { font-size: 18px; padding: 12px 14px; border-radius: 10px; background: var(--panel-2); }
.phase-banner.resolving { background: var(--accent); color: #1a1405; font-weight: 700; }
.score-list { display: flex; flex-direction: column; gap: 8px; }
.score-row { display: grid; grid-template-columns: 20px 1fr auto 26px; gap: 10px; align-items: center; font-size: 18px; }
.score-row .swatch { width: 20px; height: 20px; border-radius: 50%; }
.score-row .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.score-row .bar { grid-column: 2 / 4; height: 6px; background: var(--panel-2); border-radius: 3px; overflow: hidden; margin-top: -4px; }
.score-row .bar div { height: 100%; transition: width .5s; }
.score-row .score { font-family: var(--font-display); font-size: 22px; }
.score-row .status { text-align: center; }
.score-row.offline .name { opacity: .5; }
.status-ok { color: var(--ok); }
.status-wait { color: var(--muted); animation: blink 1.4s infinite; }
.status-off { color: var(--danger); }
@keyframes blink { 50% { opacity: .3; } }
.log h3 { font-size: 16px; color: var(--muted); margin-bottom: 8px; }
.log ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; font-size: 16px; }
.log li { display: flex; gap: 8px; align-items: center; }

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 12, 18, .78);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  padding: 16px;
}
.final { background: var(--panel); border-radius: 20px; padding: 40px 56px; min-width: 460px; text-align: center; animation: slide-in .4s ease; }
.final h1 { font-size: 56px; margin-bottom: 4px; }
.final .end-reason { color: var(--accent); font-size: 20px; font-weight: 600; margin-bottom: 4px; }
.final ol { list-style: none; padding: 0; margin: 28px 0 0; display: flex; flex-direction: column; gap: 10px; text-align: left; }
.final li { display: grid; grid-template-columns: 40px 28px 1fr auto; gap: 12px; align-items: center; font-size: 26px; padding: 10px 16px; background: var(--panel-2); border-radius: 12px; }
.final li.first { outline: 3px solid var(--accent); }
.final .place { font-family: var(--font-display); color: var(--muted); }
.final .swatch { width: 28px; height: 28px; border-radius: 50%; }

/* ---- phone --------------------------------------------------------------- */

.phone { height: 100dvh; display: flex; flex-direction: column; overflow: hidden; max-width: 560px; margin: 0 auto; }
.join-view { padding: 32px 20px; display: flex; flex-direction: column; gap: 14px; overflow-y: auto; }
.join-view h1 { font-size: 44px; text-align: center; margin-bottom: 10px; }
.join-view h1 span { color: var(--accent); }
.join-view label { font-size: 14px; color: var(--muted); font-weight: 600; margin-bottom: -6px; }
.join-view input { font-size: 20px; }
.join-view #codeInput { text-transform: uppercase; letter-spacing: 8px; text-align: center; font-weight: 700; font-size: 28px; }
.join-view button { font-size: 20px; padding: 16px; }

.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: var(--panel);
  font-weight: 600;
  flex: none;
}
.topbar .me { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
.topbar .me span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .swatch { width: 18px; height: 18px; border-radius: 50%; }
.topbar .info { color: var(--muted); font-size: 14px; white-space: nowrap; }
.topbar .info b { color: var(--text); }

.conn-banner { background: var(--danger); color: #fff; text-align: center; font-size: 14px; font-weight: 600; padding: 6px; flex: none; }

.pane { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.hint { text-align: center; font-size: 17px; font-weight: 600; }

.game-panel { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.orders-bar { flex: none; padding: 10px 16px 6px; display: flex; flex-direction: column; gap: 8px; }
.unit-list { flex: 1; min-height: 0; overflow-y: auto; padding: 6px 16px 12px; display: flex; flex-direction: column; gap: 8px; }
.unit-list h3 { font-size: 14px; color: var(--muted); margin-top: 8px; }
.unit-card {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  background: var(--panel);
  padding: 10px 12px;
}
.unit-card:disabled { opacity: 1; }
.unit-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.unit-text b { font-size: 16px; }
.unit-text small { color: var(--muted); font-weight: 500; font-size: 13px; }
.unit-icon {
  flex: none;
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  font-family: var(--font-display);
  font-weight: 700;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, .5);
}
.pawn-icon { border-radius: 50%; border: 3px solid #fff; }
.spawner-icon { clip-path: polygon(50% 0, 100% 25%, 100% 75%, 50% 100%, 0 75%, 0 25%); background: var(--panel-2); outline: 2px dashed rgba(255, 255, 255, .7); outline-offset: -5px; }
.order-badge { font-size: 12px; font-weight: 700; padding: 4px 8px; border-radius: 999px; background: var(--panel-2); }
.order-badge.attack { color: #ffb3b3; }
.order-badge.defend { color: #9ecbff; }
.order-badge.spawn { color: var(--ok); }
.chevron { color: var(--muted); font-size: 22px; }

.focus { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.focus-head { flex: none; display: flex; align-items: center; gap: 12px; padding: 8px 16px; }
.focus-head > div { display: flex; flex-direction: column; min-width: 0; }
.focus-head b { font-family: var(--font-display); font-size: 20px; }
.focus-head small { color: var(--muted); font-size: 13px; }
.focus-head .back { padding: 8px 12px; flex: none; }
.focus-board { flex: 1; min-height: 0; position: relative; margin: 0 16px; background: #0b0e15; border-radius: var(--radius); overflow: hidden; }
.zoom-buttons { position: absolute; right: 10px; bottom: 10px; display: flex; flex-direction: column; gap: 8px; }
.zoom-buttons button { width: 44px; height: 44px; padding: 0; font-size: 22px; background: rgba(35, 42, 59, .9); }
.focus-actions { flex: none; padding: 12px 16px; display: flex; flex-direction: column; gap: 8px; }

.info-panel { flex: 1; min-height: 0; overflow-y: auto; padding: 24px 16px; display: flex; flex-direction: column; gap: 12px; justify-content: center; }
.panel-footer { flex: none; padding: 8px 16px 12px; display: flex; flex-direction: column; gap: 10px; }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.action-btn { display: flex; flex-direction: column; gap: 4px; padding: 16px 10px; font-size: 22px; font-family: var(--font-display); border: 2px solid transparent; }
.action-btn small { font-family: var(--font); font-size: 12px; font-weight: 500; color: var(--muted); }
.actions.three { grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.actions.three .action-btn { font-size: 18px; padding: 12px 4px; }
.action-btn { border-color: var(--line); }
.action-btn.attack { border-color: rgba(255, 107, 107, .55); }
.action-btn.defend { border-color: rgba(158, 203, 255, .55); }
.action-btn.spawn { border-color: rgba(74, 222, 128, .55); font-size: 18px; padding: 12px; }
.action-btn.wide { width: 100%; }
.orders-head { display: flex; justify-content: space-between; align-items: baseline; }
.orders-head b { font-family: var(--font-display); font-size: 18px; }
.order-slots { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.order-slot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  background: var(--panel-2);
  border-radius: 10px;
  padding: 6px 6px 6px 12px;
  font-weight: 600;
  font-size: 15px;
  min-height: 40px;
}
.order-slot.empty { background: transparent; border: 2px dashed var(--line); color: var(--muted); font-weight: 500; justify-content: center; padding: 6px; }
.order-slot .remove { padding: 4px 9px; background: transparent; color: var(--muted); }
.order-slot > span { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.order-slot small { color: var(--muted); font-size: 11px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.context { min-height: 74px; display: flex; flex-direction: column; justify-content: center; gap: 8px; }
.context .hint { font-size: 15px; }
.context-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; background: var(--panel); border-radius: 10px; padding: 8px 8px 8px 14px; font-weight: 600; }
.context-row button { padding: 8px 12px; }
.ready-btn { font-size: 18px; padding: 14px; }
.small { font-size: 13px; }
.center { text-align: center; }
.locked { display: flex; align-items: center; justify-content: space-between; gap: 12px; background: var(--panel); border-radius: 12px; padding: 12px 14px; }
.locked b { font-family: var(--font-display); font-size: 20px; color: var(--ok); }
.ready-chips { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.chip { display: inline-flex; align-items: center; gap: 6px; background: var(--panel); border-radius: 999px; padding: 5px 10px; font-size: 13px; font-weight: 600; }
.chip .swatch { width: 10px; height: 10px; border-radius: 50%; }
.chip.done { color: var(--ok); }
.chip.off { opacity: .5; }

.lobby-panel { flex: 1; overflow-y: auto; padding: 20px 16px; display: flex; flex-direction: column; gap: 18px; }
.lobby-panel .room { text-align: center; }
.lobby-panel .room .code { font-family: var(--font-display); font-size: 44px; letter-spacing: 8px; color: var(--accent); }
.player-list { display: flex; flex-direction: column; gap: 8px; }
.player-item { display: flex; align-items: center; gap: 10px; background: var(--panel); border-radius: 12px; padding: 10px 12px; font-weight: 600; }
.player-item .swatch { width: 18px; height: 18px; border-radius: 50%; }
.player-item .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player-item.offline { opacity: .5; }
.player-item button { padding: 4px 10px; }
.setting { display: flex; flex-direction: column; gap: 8px; }
.setting > span { font-size: 14px; color: var(--muted); font-weight: 600; }
.segmented { display: flex; gap: 6px; }
.segmented button { flex: 1; padding: 10px 0; }
.segmented button.on { background: var(--accent); color: #1a1405; }
.segmented button:disabled.on { opacity: .8; }

.results { display: flex; flex-direction: column; gap: 6px; }
.results .row { display: grid; grid-template-columns: 26px 16px 1fr auto; gap: 10px; align-items: center; background: var(--panel); padding: 8px 12px; border-radius: 10px; font-weight: 600; }
.results .row.me { outline: 2px solid var(--accent); }

.tabs { display: grid; grid-template-columns: 1fr 1fr; flex: none; background: var(--panel); padding-bottom: env(safe-area-inset-bottom); }
.tabs button { border-radius: 0; background: transparent; color: var(--muted); padding: 14px; position: relative; }
.tabs button.on { color: var(--text); box-shadow: inset 0 3px 0 var(--accent); }
.badge { display: inline-block; min-width: 20px; padding: 1px 6px; margin-left: 6px; border-radius: 999px; background: var(--danger); color: #fff; font-size: 12px; }

.channels { display: flex; gap: 8px; overflow-x: auto; padding: 12px 16px; flex: none; scrollbar-width: none; }
.channels button { white-space: nowrap; padding: 8px 12px; border-radius: 999px; font-size: 14px; display: inline-flex; align-items: center; gap: 6px; }
.channels button.on { background: var(--text); color: var(--bg); }
.channels .swatch { width: 10px; height: 10px; border-radius: 50%; }
.channels .badge { margin-left: 0; }
.messages { flex: 1; overflow-y: auto; padding: 4px 16px 12px; display: flex; flex-direction: column; gap: 8px; }
.messages .empty { margin: auto; text-align: center; color: var(--muted); padding: 24px; }
.msg { max-width: 82%; align-self: flex-start; background: var(--panel); padding: 8px 12px; border-radius: 14px 14px 14px 4px; overflow-wrap: anywhere; }
.msg.mine { align-self: flex-end; background: var(--panel-2); border-radius: 14px 14px 4px 14px; }
.msg .from { font-size: 12px; font-weight: 700; margin-bottom: 2px; }
.msg .text { line-height: 1.35; }
.chat-form { display: flex; gap: 8px; padding: 10px 16px; background: var(--panel); flex: none; }
.chat-form input { flex: 1; font-size: 16px; }

.toast {
  position: fixed;
  left: 50%;
  top: 64px;
  transform: translateX(-50%);
  width: calc(100% - 32px);
  max-width: 520px;
  background: var(--panel-2);
  border-left: 4px solid var(--accent);
  border-radius: 10px;
  padding: 10px 14px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .4);
  z-index: 20;
  animation: slide-in .25s ease;
  overflow-wrap: anywhere;
}
.toast b { display: block; font-size: 13px; }

.notice { background: var(--panel); border-radius: 16px; padding: 24px; max-width: 360px; display: flex; flex-direction: column; gap: 14px; text-align: center; }
