:root {
  color-scheme: dark;
  --bg: #111318;
  --panel: #191d25;
  --panel-2: #202633;
  --line: #343b49;
  --text: #f2f5f8;
  --muted: #aeb6c4;
  --red: #ff4d5f;
  --red-soft: #5c202a;
  --blue: #4aa3ff;
  --blue-soft: #1b385a;
  --black-tile: #080a0d;
  --focus: #f8d56b;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, sans-serif;
}

button,
select {
  font: inherit;
}

.app {
  width: min(1320px, calc(100% - 32px));
  min-height: 100vh;
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(420px, 1fr) 390px;
  gap: 28px;
  align-items: center;
  padding: 28px 0;
}

.play-area,
.rules {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.play-area {
  padding: 24px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: start;
  margin-bottom: 18px;
}

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

h1,
h2 {
  margin: 0;
}

h1 {
  font-size: clamp(1.6rem, 3vw, 2.4rem);
}

h2 {
  font-size: 1.1rem;
  margin-bottom: 14px;
}

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

.select-label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 0.85rem;
}

select,
button {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-2);
  color: var(--text);
  padding: 9px 12px;
}

button {
  cursor: pointer;
}

button:hover,
select:hover {
  border-color: #566172;
}

.status-panel {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 18px;
  color: var(--muted);
}

.turn-card {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  font-weight: 700;
}

.turn-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  display: inline-block;
}

.turn-dot.red,
.piece.red,
.legend.red {
  background: var(--red);
}

.turn-dot.blue,
.piece.blue,
.legend.blue {
  background: var(--blue);
}

.scoreboard {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 18px;
}

.score {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  display: grid;
  gap: 4px;
}

.score span {
  color: var(--muted);
  font-size: 0.82rem;
}

.score strong {
  font-size: 1.15rem;
}

.red-score strong {
  color: var(--red);
}

.blue-score strong {
  color: var(--blue);
}

.board {
  display: grid;
  grid-template-columns: repeat(9, minmax(30px, 1fr));
  gap: 5px;
  width: min(76vh, 100%);
  max-width: 680px;
  margin: 0 auto;
}

.cell {
  aspect-ratio: 1;
  border: 2px solid var(--line);
  border-radius: 6px;
  background: var(--black-tile);
  color: var(--text);
  display: grid;
  place-items: center;
  position: relative;
  cursor: pointer;
  transition: transform 120ms ease, border-color 120ms ease, filter 120ms ease;
}

.cell.tile-red {
  background: linear-gradient(145deg, var(--red-soft), #30151a);
  border-color: rgba(255, 77, 95, 0.72);
}

.cell.tile-blue {
  background: linear-gradient(145deg, var(--blue-soft), #111f32);
  border-color: rgba(74, 163, 255, 0.72);
}

.cell.placeable:hover {
  transform: translateY(-2px);
  border-color: var(--focus);
}

.cell.blocked {
  cursor: not-allowed;
  filter: saturate(0.72) brightness(0.82);
}

.cell.changed {
  box-shadow: 0 0 0 2px var(--focus) inset;
}

.cell.cleared::after {
  content: "";
  width: 34%;
  height: 34%;
  border-radius: 50%;
  border: 2px solid rgba(248, 213, 107, 0.8);
  position: absolute;
}

.piece {
  width: 58%;
  height: 58%;
  border-radius: 50%;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.35), inset 0 0 0 5px rgba(255, 255, 255, 0.18);
}

.rules {
  padding: 20px;
  align-self: stretch;
  display: grid;
  align-content: center;
  gap: 16px;
}

.rule-section {
  display: grid;
  gap: 9px;
}

.rule-section h3 {
  margin: 0;
  font-size: 0.98rem;
}

.rules p {
  margin: 0;
  color: var(--muted);
  line-height: 1.7;
}

.rule-board {
  width: 100%;
  max-width: 220px;
  justify-self: center;
}

.diagram-bg {
  fill: #0a0c12;
  stroke: var(--line);
  stroke-width: 3;
}

.diagram-grid path {
  fill: none;
  stroke: #343b49;
  stroke-width: 3;
}

.diagram-tile-red {
  fill: var(--red-soft);
}

.diagram-tile-blue {
  fill: var(--blue-soft);
}

.diagram-piece-red {
  fill: var(--red);
}

.diagram-piece-blue {
  fill: var(--blue);
}

.diagram-arrow,
.diagram-stop {
  fill: none;
  stroke: var(--focus);
  stroke-width: 5;
  stroke-linecap: round;
}

.rule-board text {
  fill: var(--text);
  font-size: 13px;
  font-weight: 700;
}

.legend {
  width: 18px;
  height: 18px;
  display: inline-block;
  flex: 0 0 auto;
}

.legend.tile {
  border-radius: 4px;
  border: 1px solid var(--line);
}

.legend.tile.black {
  background: var(--black-tile);
}

.legend.tile.red {
  background: var(--red-soft);
}

.legend.tile.blue {
  background: var(--blue-soft);
}

.legend.piece {
  border-radius: 50%;
  margin-right: -3px;
}

@media (max-width: 820px) {
  .app {
    grid-template-columns: 1fr;
    align-items: start;
  }

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

  .controls {
    justify-content: flex-start;
  }

  .board {
    width: 100%;
  }

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