:root {
  color-scheme: dark;
  --bg: #10151c;
  --bg-2: #172434;
  --panel: rgba(18, 28, 40, 0.88);
  --panel-strong: #0d141d;
  --ink: #edf5ff;
  --muted: #98aabd;
  --line: rgba(191, 215, 241, 0.24);
  --gold: #f1c96b;
  --gold-2: #ffe8a8;
  --danger: #ff7066;
  --blue: #58a5ff;
  --active-team-color: #58a5ff;
  --active-team-glow: rgba(88, 165, 255, 0.42);
  --active-team-glow-soft: rgba(88, 165, 255, 0.14);
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.35);
  font-family: ui-rounded, "Avenir Next", "Trebuchet MS", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(88, 165, 255, 0.28), transparent 34rem),
    radial-gradient(circle at 75% 20%, rgba(241, 201, 107, 0.18), transparent 28rem),
    linear-gradient(145deg, var(--bg), #0a0e14 72%);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background: radial-gradient(circle at 82% 34%, var(--active-team-glow-soft), transparent 26rem);
  pointer-events: none;
  transition: background 180ms ease;
}

button {
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 18px;
  color: var(--ink);
  background: linear-gradient(180deg, #26384f, #172333);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.22);
  font: inherit;
  font-weight: 800;
  letter-spacing: 0;
  cursor: pointer;
  touch-action: manipulation;
}

select,
input {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 0 14px;
  color: var(--ink);
  background: linear-gradient(180deg, #26384f, #172333);
  font: inherit;
  font-weight: 800;
}

input::placeholder {
  color: color-mix(in srgb, var(--muted) 76%, transparent);
}

button:active {
  transform: translateY(1px) scale(0.99);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
  transform: none;
}

.shell {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: clamp(18px, 4vw, 44px);
}

.hero {
  display: grid;
  gap: 8px;
  margin-bottom: clamp(18px, 3vw, 34px);
}

.eyebrow {
  margin: 0;
  color: var(--gold-2);
  font-size: 0.82rem;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(2.4rem, 8vw, 6.8rem);
  line-height: 0.92;
  letter-spacing: 0;
}

.lede {
  max-width: 720px;
  color: var(--muted);
  font-size: clamp(1rem, 2vw, 1.25rem);
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 360px);
  gap: clamp(16px, 3vw, 28px);
  align-items: stretch;
}

.board-card,
.panel {
  border: 1px solid var(--line);
  border-radius: 30px;
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.board-card {
  min-height: min(76vh, 820px);
  overflow: hidden;
  position: relative;
  box-shadow:
    var(--shadow),
    0 0 50px var(--active-team-glow),
    inset 0 0 0 1px var(--active-team-glow-soft);
  transition: box-shadow 180ms ease, border-color 180ms ease;
}

.board-card::before {
  content: "";
  position: absolute;
  inset: 18px;
  border-radius: 24px;
  background:
    linear-gradient(120deg, transparent, rgba(255, 255, 255, 0.05), transparent),
    radial-gradient(circle at 50% 45%, rgba(241, 201, 107, 0.10), transparent 28rem);
  pointer-events: none;
}

#game-board {
  display: block;
  width: 100%;
  height: min(76vh, 820px);
  min-height: 520px;
  position: relative;
  touch-action: none;
  cursor: pointer;
}

.panel {
  display: grid;
  gap: 16px;
  align-content: start;
  padding: 18px;
}

.turn-card,
.mode-card,
.online-card,
.setup-card,
.rules-card,
.history-card {
  border: 1px solid var(--line);
  border-radius: 22px;
  background: rgba(7, 12, 18, 0.45);
  padding: 16px;
}

.mode-card {
  display: grid;
  gap: 8px;
}

.setup-card[hidden] {
  display: none;
}

.setup-card {
  display: grid;
  gap: 14px;
}

.setup-heading {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

.setup-heading h2 {
  margin: 0;
}

#local-play-button {
  min-height: 38px;
  padding: 0 14px;
  font-size: 0.88rem;
}

.setup-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 112px;
  gap: 12px;
}

.setup-field {
  display: grid;
  gap: 8px;
}

.setup-grid > .primary-action,
.join-row {
  grid-column: 1 / -1;
}

.online-card[hidden] {
  display: none;
}

.online-card {
  display: grid;
  gap: 10px;
}

#online-room-label {
  font-size: 1.15rem;
}

#online-player-label {
  color: var(--muted);
  line-height: 1.4;
}

.online-roster {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.team-chip {
  min-height: 30px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 10px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.06);
  font-size: 0.86rem;
  font-weight: 800;
}

.team-swatch {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--team-color);
  box-shadow: 0 0 12px var(--team-color);
}

.turn-card {
  border-color: color-mix(in srgb, var(--active-team-color) 62%, var(--line));
  box-shadow:
    0 0 34px var(--active-team-glow),
    inset 0 0 42px var(--active-team-glow-soft);
  transition: border-color 180ms ease, box-shadow 180ms ease;
}

.label {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

#turn-label {
  display: block;
  font-size: 1.55rem;
}

.timer-meter {
  display: grid;
  grid-template-columns: 44px 1fr;
  gap: 10px;
  align-items: center;
  margin-top: 12px;
}

#timer-label {
  color: var(--gold-2);
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

.timer-track {
  height: 10px;
  overflow: hidden;
  border: 1px solid color-mix(in srgb, var(--active-team-color) 55%, var(--line));
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
}

#timer-fill {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--active-team-color), var(--gold));
  box-shadow: 0 0 18px var(--active-team-glow);
  transform-origin: left center;
  transition: transform 120ms linear;
}

#status-label {
  margin-top: 8px;
  color: var(--muted);
  line-height: 1.45;
}

.controls {
  display: grid;
  gap: 10px;
}

h2 {
  margin-bottom: 10px;
  font-size: 1rem;
  letter-spacing: 0;
}

ul,
ol {
  margin: 0;
  padding-left: 20px;
  color: var(--muted);
  line-height: 1.45;
}

li + li {
  margin-top: 7px;
}

.history-card {
  max-height: 260px;
  overflow: auto;
}

#history-list:empty::before {
  content: "No moves yet.";
  color: var(--muted);
}

.promotion-modal[hidden] {
  display: none;
}

.promotion-modal {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(5, 8, 12, 0.72);
  backdrop-filter: blur(12px);
}

.promotion-dialog {
  width: min(420px, 100%);
  border: 1px solid color-mix(in srgb, var(--active-team-color) 70%, var(--line));
  border-radius: 28px;
  padding: 22px;
  background: linear-gradient(180deg, rgba(26, 39, 56, 0.98), rgba(10, 16, 24, 0.98));
  box-shadow:
    var(--shadow),
    0 0 46px var(--active-team-glow);
}

.promotion-dialog p {
  margin-top: 8px;
  color: var(--muted);
  line-height: 1.45;
}

.promotion-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 18px;
}

#lobby-status {
  color: var(--muted);
  line-height: 1.45;
}

.seat-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.seat-option {
  min-height: 48px;
  padding: 0;
}

.seat-option.is-selected,
.primary-action {
  border-color: color-mix(in srgb, var(--active-team-color) 76%, var(--line));
  background: linear-gradient(180deg, color-mix(in srgb, var(--active-team-color) 62%, #26384f), #172333);
  box-shadow:
    0 10px 24px rgba(0, 0, 0, 0.22),
    0 0 24px var(--active-team-glow);
}

.join-row {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 118px;
  gap: 12px;
}

.lobby-card {
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

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

.lobby-heading .label {
  margin: 0;
}

#refresh-lobbies-button {
  min-height: 36px;
  padding: 0 14px;
  font-size: 0.88rem;
}

.lobby-list {
  display: grid;
  gap: 8px;
}

.lobby-entry {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 10px;
  background: rgba(255, 255, 255, 0.04);
}

.lobby-entry strong {
  display: block;
}

.lobby-entry span {
  color: var(--muted);
  font-size: 0.9rem;
}

@media (max-width: 980px) {
  .game-layout {
    grid-template-columns: 1fr;
  }

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

  .turn-card,
  .mode-card,
  .online-card,
  .setup-card,
  .history-card {
    grid-column: 1 / -1;
  }
}

@media (max-width: 640px) {
  .shell {
    padding: 14px;
  }

  .board-card {
    border-radius: 22px;
    min-height: 72vh;
  }

  #game-board {
    height: 72vh;
    min-height: 430px;
  }

  .panel {
    grid-template-columns: 1fr;
    border-radius: 22px;
    padding: 14px;
  }

  .setup-grid,
  .join-row,
  .lobby-entry {
    grid-template-columns: 1fr;
  }
}
