:root {
  color-scheme: light dark;
  --bg: #f4efe3;
  --panel: #fbfaf4;
  --ink: #1d2320;
  --muted: #66736e;
  --line: #cad3c7;
  --board: #28745d;
  --board-dark: #18523f;
  --board-light: #3b9877;
  --accent: #d77c3f;
  --shadow: 0 18px 50px rgba(25, 38, 32, 0.18);
  --app-height: 100vh;
  --board-size: min(100%, 640px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17211d;
    --panel: #202b26;
    --ink: #eef5ef;
    --muted: #a9b8b1;
    --line: #3d4c45;
    --board: #2d8066;
    --board-dark: #143d31;
    --board-light: #44a987;
    --accent: #e6a65d;
    --shadow: 0 18px 50px rgba(0, 0, 0, 0.28);
  }
}

* {
  box-sizing: border-box;
}

body {
  min-height: var(--app-height);
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 20% 15%, rgba(215, 124, 63, 0.18), transparent 28rem),
    linear-gradient(135deg, var(--bg), color-mix(in srgb, var(--bg), var(--board-dark) 18%));
  font-family: "Segoe UI", Arial, sans-serif;
}

button,
input {
  font: inherit;
}

.game-shell {
  min-height: var(--app-height);
  display: grid;
  place-items: center;
  padding: 24px;
}

.game-panel {
  width: min(100%, 780px);
  padding: clamp(18px, 4vw, 32px);
  background: color-mix(in srgb, var(--panel), transparent 4%);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.topbar,
.status-row,
.legend,
.controls,
.score,
.mode-toggle,
.name-form,
.match-row,
.lobby-head,
.player-row,
.match-info {
  display: flex;
  align-items: center;
}

.topbar {
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(2rem, 5vw, 3.4rem);
  line-height: 1;
}

.controls {
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}

.mode-toggle {
  gap: 8px;
  color: var(--muted);
  white-space: nowrap;
}

.mode-toggle input {
  width: 18px;
  height: 18px;
  accent-color: var(--board);
}

.name-form {
  gap: 8px;
}

.name-form input {
  width: 132px;
  min-height: 40px;
  padding: 0 10px;
  color: var(--ink);
  background: color-mix(in srgb, var(--panel), var(--bg) 22%);
  border: 1px solid var(--line);
  border-radius: 6px;
}

button {
  min-height: 40px;
  padding: 0 14px;
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 6px;
  cursor: pointer;
}

button:hover {
  border-color: var(--accent);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.match-row {
  align-items: stretch;
  margin-bottom: 18px;
}

.lobby,
.match-info {
  border: 1px solid var(--line);
  border-radius: 6px;
}

.lobby {
  margin-top: 18px;
  padding: 12px;
}

.lobby-head {
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.lobby h2 {
  margin: 0;
  font-size: 1rem;
}

#connection-status,
.player-state {
  color: var(--muted);
  font-size: 0.9rem;
}

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

.player-row {
  gap: 10px;
  min-height: 42px;
}

.player-row > span:first-child {
  min-width: 0;
  flex: 1;
  overflow-wrap: anywhere;
}

.player-state {
  white-space: nowrap;
}

.player-row button {
  min-height: 34px;
  padding-inline: 12px;
}

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

.match-info {
  align-items: flex-start;
  justify-content: center;
  flex-direction: column;
  gap: 6px;
  padding: 12px;
}

.match-info p {
  margin: 0;
}

.match-info p + p {
  color: var(--muted);
}

.challenge-box {
  display: grid;
  gap: 8px;
  width: 100%;
  margin-top: 6px;
}

.challenge-box:empty {
  display: none;
}

.challenge-box p {
  color: var(--ink);
  font-weight: 600;
}

.challenge-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.status-row {
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.score {
  min-width: 92px;
  gap: 8px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.score strong {
  margin-left: auto;
  font-size: 1.25rem;
}

.message {
  flex: 1;
  margin: 0;
  color: var(--muted);
  text-align: center;
  font-weight: 600;
}

.board-wrap {
  display: grid;
  place-items: center;
}

.board {
  width: var(--board-size);
  aspect-ratio: 1;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 3px;
  padding: 10px;
  background: var(--board-dark);
  border: 8px solid color-mix(in srgb, var(--board-dark), #000 24%);
  border-radius: 8px;
}

.cell {
  position: relative;
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  padding: 0;
  background:
    linear-gradient(135deg, color-mix(in srgb, var(--board), #fff 6%), var(--board));
  border: 1px solid color-mix(in srgb, var(--board-dark), #000 18%);
  border-radius: 4px;
}

.cell:hover {
  border-color: var(--accent);
}

.cell.legal::after {
  content: "";
  width: 24%;
  aspect-ratio: 1;
  border: 2px solid rgba(255, 255, 255, 0.78);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.14);
}

.disc {
  width: 74%;
  aspect-ratio: 1;
  border-radius: 50%;
  box-shadow: inset -8px -10px 16px rgba(0, 0, 0, 0.28), 0 5px 10px rgba(0, 0, 0, 0.28);
}

.disc.black {
  background: radial-gradient(circle at 35% 28%, #626b67, #171a18 62%);
}

.disc.white {
  background: radial-gradient(circle at 35% 28%, #ffffff, #d4d7cf 62%);
  box-shadow: inset -8px -10px 16px rgba(70, 78, 72, 0.18), 0 5px 10px rgba(0, 0, 0, 0.22);
}

.disc.mini {
  width: 20px;
}

.legend {
  justify-content: space-between;
  gap: 12px;
  margin-top: 16px;
  color: var(--muted);
  font-size: 0.95rem;
}

.hint-dot {
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-right: 6px;
  border: 2px solid var(--accent);
  border-radius: 50%;
  vertical-align: -1px;
}

@media (max-width: 620px) {
  :root {
    --bg: #111714;
    --panel: #151d19;
    --ink: #f5f7f1;
    --muted: #b8c5bf;
    --line: rgba(255, 255, 255, 0.13);
    --board: #2f8a6c;
    --board-dark: #143d31;
    --accent: #f0b45e;
  }

  html,
  body {
    width: 100%;
    height: var(--app-height);
    min-height: var(--app-height);
    margin: 0;
    overflow-x: hidden;
    overscroll-behavior: none;
    background:
      radial-gradient(circle at 10% 8%, rgba(47, 138, 108, 0.34), transparent 18rem),
      radial-gradient(circle at 92% 12%, rgba(240, 180, 94, 0.2), transparent 18rem),
      linear-gradient(135deg, #101614, #17221e 52%, #111714);
  }

  .game-shell {
    align-items: start;
    justify-items: stretch;
    width: 100%;
    height: var(--app-height);
    min-height: var(--app-height);
    padding: 0;
    display: block;
    overflow-y: auto;
    background: transparent;
  }

  .game-panel {
    width: 100%;
    max-width: none;
    height: auto;
    min-height: var(--app-height);
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    gap: 8px;
    padding: 8px 0;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    background: transparent;
  }

  .topbar {
    gap: 6px;
    margin: 0 0 0;
    padding-inline: 8px;
  }

  .eyebrow {
    display: none;
    margin-bottom: 2px;
    font-size: 0.68rem;
  }

  h1 {
    font-size: 1.45rem;
  }

  .topbar,
  .status-row,
  .legend,
  .match-row {
    align-items: stretch;
    flex-direction: column;
  }

  .controls {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    justify-content: stretch;
    gap: 4px;
  }

  .name-form {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .name-form input,
  .controls > button {
    width: 100%;
    min-height: 32px;
    padding-inline: 6px;
    font-size: 0.8rem;
    color: var(--ink);
    background: rgba(255, 255, 255, 0.08);
    border-color: var(--line);
  }

  .status-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    margin: 0;
    padding-inline: 8px;
  }

  .message {
    grid-column: 1 / -1;
    order: -1;
    text-align: left;
    font-size: 0.86rem;
  }

  .score {
    min-width: 0;
    padding: 6px 8px;
    background: rgba(255, 255, 255, 0.07);
    border-color: var(--line);
  }

  .match-row {
    margin: 0;
  }

  .match-info {
    padding: 8px;
    gap: 2px;
    font-size: 0.82rem;
    background: rgba(255, 255, 255, 0.07);
    border-block: 1px solid var(--line);
  }

  .match-info,
  .lobby {
    border-radius: 0;
    border-inline: 0;
    margin-inline: 0;
  }

  .board-wrap {
    width: 100%;
    margin-inline: 0;
    display: flex;
    justify-content: center;
    background: rgba(255, 255, 255, 0.05);
    border-block: 1px solid var(--line);
    overflow: hidden;
  }

  .board {
    width: var(--board-size);
    max-width: 100vw;
    gap: 1px;
    padding: 2px;
    border-width: 0;
    border-radius: 0;
  }

  .legend {
    gap: 4px;
    margin: 0;
    padding-inline: 8px;
    font-size: 0.78rem;
  }

  .lobby {
    margin-top: 0;
    padding: 8px;
    background: rgba(255, 255, 255, 0.07);
    border-block: 1px solid var(--line);
  }

  .lobby-head {
    margin-bottom: 8px;
  }

  .players {
    gap: 6px;
  }

  .player-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    min-height: 38px;
    padding: 4px 0;
  }

  .player-state {
    grid-column: 1;
    grid-row: 2;
  }

  .player-row button {
    grid-column: 2;
    grid-row: 1 / span 2;
    align-self: center;
    min-height: 34px;
  }
}
