:root {
  --paper: #f4fbf8;
  --panel: #ffffff;
  --ink: #25211e;
  --muted: #6f7b76;
  --line: #bfd1cc;
  --line-strong: #6d817a;
  --p1: #e94f43;
  --p1-soft: rgba(233, 79, 67, 0.16);
  --p2: #00877a;
  --p2-soft: rgba(0, 135, 122, 0.16);
  --gold: #f6c945;
  --sky: #79c6d1;
  --turn-color: var(--p1);
  --shadow: 0 22px 55px rgba(37, 33, 30, 0.14);
  color-scheme: light;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  background:
    linear-gradient(90deg, rgba(37, 33, 30, 0.045) 1px, transparent 1px),
    linear-gradient(rgba(37, 33, 30, 0.045) 1px, transparent 1px),
    radial-gradient(circle at 18% 22%, rgba(121, 198, 209, 0.26), transparent 28%),
    linear-gradient(135deg, #f4fbf8 0%, #eaf6ee 46%, #fff7df 100%);
  background-size:
    32px 32px,
    32px 32px,
    auto,
    auto;
  color: var(--ink);
}

button {
  border: 0;
  color: inherit;
  font: inherit;
}

input {
  color: inherit;
  font: inherit;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.game-shell {
  width: min(1180px, calc(100% - 32px));
  min-height: 100vh;
  margin: 0 auto;
  padding: clamp(16px, 3vw, 30px) 0;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: clamp(14px, 2vw, 22px);
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
}

.brand-block {
  display: grid;
  gap: 4px;
}

.kicker {
  color: var(--muted);
  font-size: 0.77rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(2rem, 5vw, 4.2rem);
  line-height: 0.95;
  letter-spacing: 0;
}

.top-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.segmented {
  display: flex;
  align-items: center;
  gap: 4px;
  margin: 0;
  padding: 4px;
  border: 1px solid rgba(37, 33, 30, 0.14);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
  box-shadow: 0 8px 24px rgba(37, 33, 30, 0.07);
}

.segmented legend {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.grid-option,
.mode-option,
.new-game {
  min-height: 42px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 850;
  transition:
    transform 160ms ease,
    box-shadow 160ms ease,
    background-color 160ms ease,
    color 160ms ease;
}

.grid-option,
.mode-option {
  min-width: 68px;
  padding: 0 12px;
  background: transparent;
  color: var(--muted);
}

.mode-option {
  min-width: 112px;
}

.grid-option.active,
.mode-option.active {
  background: var(--ink);
  color: #ffffff;
  box-shadow: 0 8px 18px rgba(37, 33, 30, 0.18);
}

.new-game {
  padding: 0 18px;
  background: var(--gold);
  color: #2d2618;
  box-shadow: 0 10px 24px rgba(180, 132, 12, 0.22);
}

.grid-option:hover,
.mode-option:hover,
.new-game:hover {
  transform: translateY(-1px);
}

.grid-option:focus-visible,
.mode-option:focus-visible,
.new-game:focus-visible,
.player-name-input:focus-visible,
.edge:focus-visible {
  outline: 3px solid var(--turn-color);
  outline-offset: 3px;
}

.play-layout {
  display: grid;
  grid-template-columns: minmax(240px, 310px) minmax(0, 1fr);
  gap: clamp(14px, 2vw, 24px);
  align-items: stretch;
}

.network-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid rgba(37, 33, 30, 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.78);
  box-shadow: 0 10px 26px rgba(37, 33, 30, 0.08);
}

.network-panel {
  flex-wrap: wrap;
}

.network-status {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.network-panel strong {
  white-space: nowrap;
  font-weight: 950;
}

.network-panel span {
  color: var(--muted);
  font-weight: 750;
}

.lobby {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.join-form {
  display: flex;
  align-items: center;
  gap: 6px;
}

.lobby-button {
  min-height: 42px;
  padding: 0 16px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 850;
  transition:
    transform 160ms ease,
    box-shadow 160ms ease;
}

.lobby-button:hover {
  transform: translateY(-1px);
}

.lobby-button.create {
  background: var(--gold);
  color: #2d2618;
  box-shadow: 0 10px 24px rgba(180, 132, 12, 0.22);
}

.lobby-button.join {
  background: var(--ink);
  color: #ffffff;
  box-shadow: 0 8px 18px rgba(37, 33, 30, 0.18);
}

.join-code-input {
  width: 116px;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid rgba(37, 33, 30, 0.18);
  border-radius: 8px;
  background: #ffffff;
  font-weight: 850;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.join-code-input:focus-visible,
.lobby-button:focus-visible,
.copy-link:focus-visible {
  outline: 3px solid var(--turn-color);
  outline-offset: 3px;
}

.room-invite {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.room-code-label {
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 850;
  letter-spacing: 0;
  text-transform: uppercase;
}

.room-code {
  padding: 4px 10px;
  border-radius: 8px;
  background: var(--ink);
  color: #ffffff;
  font-size: 1.1rem;
  font-weight: 950;
  letter-spacing: 0.16em;
}

.copy-link {
  min-height: 38px;
  padding: 0 14px;
  border-radius: 8px;
  cursor: pointer;
  background: rgba(0, 135, 122, 0.14);
  color: var(--p2);
  font-weight: 850;
  transition: background-color 160ms ease;
}

.copy-link:hover {
  background: rgba(0, 135, 122, 0.22);
}

.grid-option:disabled,
.mode-option:disabled,
.new-game:disabled {
  cursor: not-allowed;
  opacity: 0.45;
  transform: none;
  box-shadow: none;
}

.score-panel,
.board-frame {
  border: 1px solid rgba(37, 33, 30, 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.78);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.score-panel {
  padding: 16px;
  display: grid;
  grid-template-rows: auto auto auto 1fr;
  gap: 14px;
  align-content: start;
}

.turn-strip {
  min-height: 82px;
  padding: 14px;
  border-radius: 8px;
  background:
    linear-gradient(90deg, var(--turn-color), rgba(255, 255, 255, 0)),
    var(--ink);
  color: #ffffff;
  display: grid;
  gap: 4px;
  align-content: center;
  overflow: hidden;
}

.turn-label {
  font-size: 0.78rem;
  font-weight: 800;
  opacity: 0.74;
  text-transform: uppercase;
  letter-spacing: 0;
}

.turn-name {
  font-size: clamp(1.28rem, 2vw, 1.7rem);
  font-weight: 900;
  line-height: 1;
}

.turn-note {
  color: rgba(255, 255, 255, 0.78);
  font-size: 0.9rem;
  font-weight: 700;
}

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

.player-card {
  --player-color: var(--p1);
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: center;
  min-height: 76px;
  padding: 12px;
  border: 1px solid rgba(37, 33, 30, 0.12);
  border-left: 6px solid var(--player-color);
  border-radius: 8px;
  background: var(--panel);
  transition:
    border-color 160ms ease,
    box-shadow 160ms ease,
    transform 160ms ease;
}

.player-card.active {
  border-color: color-mix(in srgb, var(--player-color), #ffffff 34%);
  box-shadow:
    inset 0 0 0 2px color-mix(in srgb, var(--player-color), transparent 54%),
    0 12px 24px rgba(37, 33, 30, 0.1);
  transform: translateX(2px);
}

.player-token {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--player-color);
  box-shadow: inset 0 0 0 4px rgba(255, 255, 255, 0.38);
}

.player-meta {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.player-name-field {
  min-width: 0;
}

.player-name-input {
  width: 100%;
  min-width: 0;
  border: 0;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  background: transparent;
  font-weight: 900;
  line-height: 1.2;
  text-overflow: ellipsis;
}

.player-name-input:hover,
.player-name-input:focus {
  border-bottom-color: color-mix(in srgb, var(--player-color), transparent 44%);
}

.player-name-input:focus {
  background: color-mix(in srgb, var(--player-color), transparent 94%);
}

.player-status {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

.player-score {
  min-width: 48px;
  text-align: right;
  font-size: 2.2rem;
  font-weight: 950;
  line-height: 1;
}

.game-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.game-stats div {
  min-height: 76px;
  padding: 12px;
  border: 1px dashed rgba(37, 33, 30, 0.2);
  border-radius: 8px;
  background: rgba(244, 251, 248, 0.84);
  display: grid;
  align-content: center;
  gap: 5px;
}

.game-stats .mode-stat {
  grid-column: 1 / -1;
  min-height: 62px;
}

.stat-label {
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 850;
  letter-spacing: 0;
  text-transform: uppercase;
}

.game-stats strong {
  font-size: 1.3rem;
}

.result-panel {
  align-self: end;
  min-height: 96px;
  padding: 14px;
  border-radius: 8px;
  background: #25211e;
  color: #ffffff;
}

.result-panel strong {
  display: block;
  margin-bottom: 6px;
  font-size: 1.2rem;
}

.result-panel span {
  color: rgba(255, 255, 255, 0.75);
  font-weight: 700;
}

.board-stage {
  min-width: 0;
  display: grid;
  place-items: center;
}

.board-frame {
  width: min(100%, 760px, calc(100vh - 150px));
  min-width: 280px;
  aspect-ratio: 1 / 1;
  padding: clamp(10px, 2vw, 20px);
  display: grid;
  place-items: center;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.94), rgba(244, 251, 248, 0.9)),
    repeating-linear-gradient(
      45deg,
      rgba(37, 33, 30, 0.035) 0 2px,
      transparent 2px 18px
    );
}

.board {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
  touch-action: manipulation;
}

.box-fill {
  opacity: 0.94;
  transform-origin: center;
}

.box-fill.player-0 {
  fill: var(--p1-soft);
}

.box-fill.player-1 {
  fill: var(--p2-soft);
}

.claimed-box.latest-box {
  animation: boxPop 340ms cubic-bezier(0.2, 1.2, 0.2, 1);
}

.box-initial {
  pointer-events: none;
  fill: var(--ink);
  font-size: 30px;
  font-weight: 950;
  opacity: 0.82;
  paint-order: stroke;
  stroke: rgba(255, 255, 255, 0.72);
  stroke-linejoin: round;
  stroke-width: 5;
  user-select: none;
}

.box-initial.player-0 {
  fill: color-mix(in srgb, var(--p1), var(--ink) 28%);
}

.box-initial.player-1 {
  fill: color-mix(in srgb, var(--p2), var(--ink) 28%);
}

.edge {
  cursor: pointer;
}

.edge.claimed,
.edge.disabled {
  cursor: default;
}

.edge.disabled {
  opacity: 0.62;
}

.edge-track,
.edge-mark {
  vector-effect: non-scaling-stroke;
  stroke-linecap: round;
}

.edge-track {
  stroke: var(--line);
  stroke-width: 7;
  opacity: 0.66;
}

.edge-mark {
  stroke: transparent;
  stroke-width: 8;
  transition:
    stroke 140ms ease,
    opacity 140ms ease,
    stroke-width 140ms ease;
}

.edge-hit {
  fill: rgba(37, 33, 30, 0.001);
  pointer-events: all;
  stroke: none;
}

.edge.open:not(.disabled):hover .edge-mark,
.edge.open:not(.disabled):focus-visible .edge-mark {
  stroke: var(--turn-color);
  opacity: 0.58;
  stroke-width: 10;
}

.edge.player-0 .edge-mark,
.edge.player-1 .edge-mark {
  opacity: 1;
  stroke-width: 9;
}

.edge.player-0 .edge-mark {
  stroke: var(--p1);
}

.edge.player-1 .edge-mark {
  stroke: var(--p2);
}

.edge.latest .edge-mark {
  animation: lineDraw 260ms ease-out;
}

.edge.cleared .edge-track {
  animation: clearedLine 760ms ease-out;
}

.dot {
  fill: var(--ink);
  stroke: #ffffff;
  stroke-width: 4;
  vector-effect: non-scaling-stroke;
  filter: drop-shadow(0 3px 4px rgba(37, 33, 30, 0.22));
}

.mine-burst {
  pointer-events: none;
}

.blast-ring,
.blast-core,
.blast-spark {
  vector-effect: non-scaling-stroke;
  transform-box: fill-box;
  transform-origin: center;
}

.blast-ring {
  fill: none;
  stroke: var(--gold);
  stroke-width: 7;
  opacity: 0;
  animation: blastRing 760ms ease-out forwards;
}

.blast-core {
  fill: #25211e;
  stroke: #ffffff;
  stroke-width: 5;
  opacity: 0;
  animation: blastCore 720ms ease-out forwards;
}

.blast-spark {
  stroke: #e94f43;
  stroke-linecap: round;
  stroke-width: 6;
  opacity: 0;
  animation: blastSpark 640ms ease-out forwards;
}

@keyframes lineDraw {
  from {
    opacity: 0.25;
    stroke-width: 3;
  }
  to {
    opacity: 1;
    stroke-width: 9;
  }
}

@keyframes clearedLine {
  0% {
    opacity: 1;
    stroke: var(--gold);
    stroke-width: 14;
  }
  60% {
    opacity: 0.92;
    stroke: #e94f43;
    stroke-width: 11;
  }
  100% {
    opacity: 0.66;
    stroke: var(--line);
    stroke-width: 7;
  }
}

@keyframes blastRing {
  0% {
    opacity: 0.95;
    transform: scale(0.2);
  }
  100% {
    opacity: 0;
    transform: scale(4.8);
  }
}

@keyframes blastCore {
  0% {
    opacity: 0;
    transform: scale(0.2);
  }
  24% {
    opacity: 1;
    transform: scale(1.18);
  }
  100% {
    opacity: 0;
    transform: scale(0.72);
  }
}

@keyframes blastSpark {
  0% {
    opacity: 0;
    stroke-width: 2;
  }
  18% {
    opacity: 1;
    stroke-width: 8;
  }
  100% {
    opacity: 0;
    stroke-width: 1;
  }
}

@keyframes boxPop {
  0% {
    opacity: 0;
    transform: scale(0.7);
  }
  100% {
    opacity: 0.94;
    transform: scale(1);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 1ms !important;
    scroll-behavior: auto !important;
    transition-duration: 1ms !important;
  }
}

@media (max-width: 860px) {
  .game-shell {
    width: min(100% - 22px, 680px);
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .network-panel {
    align-items: flex-start;
    flex-direction: column;
  }

  .top-actions {
    justify-content: space-between;
  }

  .segmented {
    flex: 1 1 220px;
  }

  .grid-option,
  .mode-option {
    flex: 1;
  }

  .new-game {
    flex: 1 1 130px;
  }

  .play-layout {
    grid-template-columns: 1fr;
  }

  .board-stage {
    order: 1;
  }

  .score-panel {
    order: 2;
    grid-template-rows: auto auto auto;
  }

  .board-frame {
    width: min(100%, calc(100vh - 215px));
  }
}

@media (max-width: 520px) {
  .game-shell {
    min-height: auto;
    padding: 14px 0;
  }

  .top-actions,
  .segmented {
    width: 100%;
  }

  .top-actions {
    gap: 8px;
  }

  .grid-option,
  .mode-option,
  .new-game {
    min-height: 40px;
    padding-inline: 10px;
  }

  .board-frame {
    min-width: 0;
    width: 100%;
    padding: 9px;
  }

  .score-panel {
    padding: 12px;
  }

  .turn-strip {
    min-height: 72px;
  }

  .player-card {
    min-height: 68px;
  }

  .player-score {
    font-size: 1.9rem;
  }
}
