:root {
  --bg: #06111f;
  --bg2: #0b1b2e;
  --panel: rgba(13, 27, 45, .86);
  --panel2: rgba(21, 39, 62, .88);
  --text: #edf6ff;
  --muted: #91a7c2;
  --line: rgba(255,255,255,.12);
  --accent: #48cae4;
  --accent2: #80ffdb;
  --danger: #ff5c7a;
  --warning: #ffd166;
  --shadow: 0 24px 80px rgba(0,0,0,.38);
  --radius: 24px;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
  overflow-x: hidden;
  background:
    radial-gradient(circle at top left, rgba(72, 202, 228, .24), transparent 32rem),
    radial-gradient(circle at bottom right, rgba(128, 255, 219, .13), transparent 28rem),
    linear-gradient(135deg, #030712, var(--bg) 45%, #071d2b);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  touch-action: manipulation;
}

.app-shell {
  width: min(1680px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: max(14px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) max(14px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: rgba(2, 8, 23, .66);
  backdrop-filter: blur(18px);
  box-shadow: 0 18px 50px rgba(0,0,0,.2);
}

.topbar h1 {
  margin: 0;
  font-size: clamp(1.25rem, 4vw, 2rem);
  letter-spacing: -.04em;
}

.eyebrow {
  color: var(--accent2);
  font-size: .76rem;
  text-transform: uppercase;
  letter-spacing: .14em;
  font-weight: 800;
}

.screen {
  display: none;
}

.screen.active {
  display: block;
}

.hero-card {
  min-height: calc(100vh - 120px);
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 520px);
  gap: 22px;
  align-items: stretch;
}

.hero-copy,
.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(180deg, rgba(21, 39, 62, .86), rgba(8, 19, 34, .86));
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.hero-copy {
  position: relative;
  overflow: hidden;
  padding: clamp(24px, 5vw, 70px);
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.hero-copy::before {
  content: "";
  position: absolute;
  inset: 18px;
  border-radius: 28px;
  background:
    linear-gradient(rgba(255,255,255,.06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.06) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: radial-gradient(circle at 35% 42%, black, transparent 72%);
  pointer-events: none;
}

.badge {
  position: relative;
  display: inline-flex;
  width: fit-content;
  padding: 8px 12px;
  border: 1px solid rgba(128, 255, 219, .28);
  border-radius: 999px;
  color: var(--accent2);
  background: rgba(128, 255, 219, .08);
  font-weight: 900;
  font-size: .8rem;
}

.hero-copy h2 {
  position: relative;
  max-width: 720px;
  margin: 20px 0 14px;
  font-size: clamp(2.4rem, 8vw, 6.2rem);
  line-height: .9;
  letter-spacing: -.08em;
}

.hero-copy p {
  position: relative;
  max-width: 650px;
  margin: 0;
  color: var(--muted);
  font-size: clamp(1rem, 2vw, 1.3rem);
  line-height: 1.55;
}

.forms-grid {
  display: grid;
  gap: 16px;
}

.panel {
  padding: 18px;
}

.panel h3 {
  margin: 0 0 14px;
  font-size: 1.05rem;
}

label {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: .88rem;
  font-weight: 800;
}

input,
select {
  width: 100%;
  min-height: 48px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  outline: none;
  background: rgba(255,255,255,.06);
  color: var(--text);
}

select option {
  color: #111827;
}

input:focus,
select:focus {
  border-color: rgba(72, 202, 228, .75);
  box-shadow: 0 0 0 4px rgba(72, 202, 228, .12);
}

.primary-btn,
.secondary-btn,
.danger-btn,
.ghost-btn {
  min-height: 46px;
  padding: 0 16px;
  border: 0;
  border-radius: 16px;
  font-weight: 900;
  cursor: pointer;
  transition: transform .15s ease, opacity .15s ease, filter .15s ease;
}

.primary-btn {
  color: #03131d;
  background: linear-gradient(135deg, var(--accent2), var(--accent));
}

.secondary-btn {
  color: var(--text);
  background: rgba(72, 202, 228, .16);
  border: 1px solid rgba(72, 202, 228, .24);
}

.danger-btn {
  color: white;
  background: linear-gradient(135deg, #ff477e, #ff7a59);
}

.ghost-btn {
  color: var(--text);
  background: rgba(255,255,255,.06);
  border: 1px solid var(--line);
}

.primary-btn:hover,
.secondary-btn:hover,
.danger-btn:hover,
.ghost-btn:hover {
  transform: translateY(-1px);
  filter: brightness(1.05);
}

button:disabled {
  opacity: .42;
  cursor: not-allowed;
  transform: none !important;
  filter: none !important;
}

.full {
  width: 100%;
  margin-top: 14px;
}

.tiny {
  min-height: 34px;
  padding: 0 10px;
  border-radius: 12px;
  font-size: .82rem;
}

.lobby-card {
  max-width: 880px;
  margin: 24px auto;
}

.lobby-head {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: flex-start;
}

.lobby-head h2 {
  margin: 12px 0 4px;
  font-size: clamp(1.8rem, 6vw, 3.4rem);
  letter-spacing: -.06em;
}

.lobby-head p {
  margin: 0;
  color: var(--muted);
}

.players-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
  margin: 20px 0;
}

.player-pill,
.player-row {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255,255,255,.05);
}

.player-pill small,
.player-row small {
  margin-left: auto;
  color: var(--muted);
  font-size: .75rem;
}

.color-dot {
  width: 13px;
  height: 13px;
  flex: 0 0 13px;
  border-radius: 50%;
  box-shadow: 0 0 18px currentColor;
}

.lobby-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.game-screen.active {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr) 300px;
  gap: 14px;
  align-items: start;
}

.status-panel,
.log-panel {
  position: sticky;
  top: 94px;
  max-height: calc(100vh - 112px);
  overflow: auto;
}

.game-code {
  color: var(--muted);
  font-size: .9rem;
  margin-bottom: 12px;
}

.turn-info {
  padding: 14px;
  border-radius: 18px;
  background: rgba(255,255,255,.06);
  border: 1px solid var(--line);
  margin-bottom: 14px;
}

.phase {
  color: var(--accent2);
  font-weight: 1000;
  text-transform: uppercase;
  letter-spacing: .12em;
  font-size: .78rem;
  margin-bottom: 8px;
}

.current-player {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.35rem;
  letter-spacing: -.03em;
}

.current-player span {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--player);
  box-shadow: 0 0 26px var(--player);
}

.turn-small,
.reinforcements {
  margin-top: 8px;
  color: var(--muted);
  font-size: .9rem;
}

.reinforcements strong {
  color: var(--warning);
}

.players-status {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
}

.player-row {
  padding: 10px;
  font-size: .88rem;
}

.player-row.active {
  border-color: rgba(128, 255, 219, .45);
  background: rgba(128, 255, 219, .08);
}

.player-row.dead {
  opacity: .45;
  filter: grayscale(1);
}

.selected-info {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
}

.empty-selection,
.hint {
  color: var(--muted);
  padding: 12px;
  border: 1px dashed var(--line);
  border-radius: 14px;
}

.selection-card {
  display: grid;
  gap: 3px;
  padding: 12px;
  border-radius: 16px;
  background: rgba(255,255,255,.06);
  border: 1px solid var(--line);
}

.selection-card small {
  color: var(--accent2);
  text-transform: uppercase;
  letter-spacing: .1em;
  font-weight: 900;
}

.selection-card span {
  color: var(--muted);
  font-size: .86rem;
}

.selection-card.target small {
  color: var(--danger);
}

.actions {
  display: grid;
  gap: 9px;
  margin-bottom: 14px;
}

.map-panel {
  overflow: hidden;
}

.map-toolbar {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 12px;
}

.map-toolbar span {
  display: block;
  color: var(--muted);
  font-size: .82rem;
  margin-top: 2px;
}

.map-buttons {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}

.map-wrap {
  width: 100%;
  height: min(68vh, 760px);
  min-height: 460px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 22px;
  background:
    radial-gradient(circle at 42% 35%, rgba(72,202,228,.18), transparent 28rem),
    radial-gradient(circle at 78% 70%, rgba(128,255,219,.10), transparent 24rem),
    linear-gradient(180deg, rgba(2, 12, 28, .72), rgba(3, 7, 18, .96));
  -webkit-overflow-scrolling: touch;
  touch-action: none;
}

.world-map {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  user-select: none;
}

.ocean-grid {
  opacity: .95;
}

.territories-layer {
  transform-box: fill-box;
}

.territory {
  stroke: rgba(255,255,255,.42);
  stroke-width: 1.45;
  cursor: pointer;
  opacity: .9;
  transition: opacity .16s ease, filter .16s ease, stroke-width .16s ease;
  vector-effect: non-scaling-stroke;
}

.territory:hover {
  opacity: 1;
  filter: brightness(1.18);
}

.territory.mine {
  stroke: rgba(255,255,255,.7);
}

.territory.selected-from {
  stroke: #80ffdb;
  stroke-width: 4.5;
  filter: brightness(1.26) drop-shadow(0 0 10px rgba(128,255,219,.45));
}

.territory.selected-to {
  stroke: #ff5c7a;
  stroke-width: 4.5;
  filter: brightness(1.2) drop-shadow(0 0 10px rgba(255,92,122,.45));
}

.territory.adjacent-target {
  stroke-dasharray: 7 5;
  stroke: rgba(255,255,255,.9);
}

.territory-label {
  pointer-events: auto;
  cursor: pointer;
}

.territory-label .troop-halo {
  fill: rgba(2, 6, 23, .44);
  stroke: rgba(255,255,255,.18);
  stroke-width: 1;
  pointer-events: none;
}

.territory-label circle:not(.troop-halo) {
  stroke: rgba(255,255,255,.92);
  stroke-width: 2.4;
  filter: drop-shadow(0 8px 14px rgba(0,0,0,.34));
}

.troop-text {
  fill: #06111f;
  font-size: 18px;
  font-weight: 1000;
  pointer-events: none;
}

.name-text {
  fill: rgba(255,255,255,.9);
  font-size: 13px;
  font-weight: 900;
  letter-spacing: -.02em;
  paint-order: stroke;
  stroke: rgba(0,0,0,.78);
  stroke-width: 4;
  stroke-linejoin: round;
  pointer-events: none;
}

.territory-label.selected circle:not(.troop-halo) {
  stroke: #fff;
  stroke-width: 4;
}

.battle-box {
  padding: 12px;
  border-radius: 16px;
  background: rgba(255,255,255,.05);
  border: 1px solid var(--line);
}

.battle-box h3 {
  margin: 0 0 10px;
}

.battle-line {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  color: var(--muted);
  margin-bottom: 10px;
}

.dice-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 8px 0;
  color: var(--muted);
}

.die {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  margin-left: 5px;
  border-radius: 9px;
  background: white;
  color: #111827;
  font-weight: 1000;
  box-shadow: inset 0 -4px 0 rgba(0,0,0,.12);
}

.losses {
  color: var(--muted);
  margin-top: 8px;
  font-size: .88rem;
}

.conquered {
  margin-top: 9px;
  padding: 9px;
  border-radius: 12px;
  background: rgba(128,255,219,.12);
  color: var(--accent2);
  font-weight: 900;
}

.log-panel h3 {
  margin: 0 0 10px;
}

.game-log {
  display: grid;
  gap: 8px;
  max-height: calc(100vh - 178px);
  overflow: auto;
  padding-right: 4px;
}

.log-item {
  display: grid;
  gap: 4px;
  padding: 10px;
  border-radius: 14px;
  background: rgba(255,255,255,.045);
  border: 1px solid rgba(255,255,255,.08);
}

.log-item small {
  color: var(--accent2);
  font-weight: 900;
}

.log-item span {
  color: var(--muted);
  font-size: .86rem;
  line-height: 1.35;
}

.winner-box {
  display: grid;
  gap: 8px;
  text-align: center;
}

.winner-title {
  font-size: 1.3rem;
  font-weight: 1000;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: max(18px, env(safe-area-inset-bottom));
  z-index: 50;
  max-width: min(92vw, 520px);
  padding: 13px 16px;
  border-radius: 16px;
  background: rgba(255, 92, 122, .96);
  color: white;
  font-weight: 900;
  box-shadow: 0 18px 50px rgba(0,0,0,.35);
  transform: translate(-50%, 110px);
  opacity: 0;
  transition: all .22s ease;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (max-width: 1180px) {
  .game-screen.active {
    grid-template-columns: 300px minmax(0, 1fr);
  }

  .log-panel {
    grid-column: 1 / -1;
    position: static;
    max-height: none;
  }

  .game-log {
    max-height: 260px;
  }
}

@media (max-width: 860px) {
  .app-shell {
    padding: 10px;
  }

  .topbar {
    border-radius: 18px;
    padding: 12px;
  }

  .hero-card {
    grid-template-columns: 1fr;
    min-height: auto;
  }

  .hero-copy {
    min-height: 360px;
  }

  .game-screen.active {
    display: flex;
    flex-direction: column;
  }

  .status-panel,
  .map-panel,
  .log-panel {
    width: 100%;
    position: static;
    max-height: none;
  }

  .status-panel {
    order: 2;
  }

  .map-panel {
    order: 1;
    padding: 10px;
  }

  .log-panel {
    order: 3;
  }

  .map-toolbar {
    padding: 0 2px;
    align-items: flex-start;
  }

  .map-buttons {
    min-width: 160px;
  }

  .map-wrap {
    height: 60vh;
    min-height: 390px;
    max-height: 620px;
  }

  .actions {
    grid-template-columns: 1fr 1fr;
  }

  .actions #btnEndTurn {
    grid-column: 1 / -1;
  }

  .lobby-head {
    flex-direction: column;
  }
}

@media (max-width: 480px) {
  .topbar {
    align-items: flex-start;
  }

  .topbar .ghost-btn {
    min-height: 38px;
    padding-inline: 10px;
  }

  .hero-copy {
    padding: 24px;
  }

  .hero-copy h2 {
    font-size: 3rem;
  }

  .panel {
    padding: 13px;
    border-radius: 20px;
  }

  .actions {
    grid-template-columns: 1fr;
  }

  .map-toolbar {
    flex-direction: column;
  }

  .map-buttons {
    width: 100%;
    justify-content: stretch;
  }

  .map-buttons .tiny {
    flex: 1;
  }

  .map-wrap {
    height: 56vh;
    min-height: 340px;
  }
}

