:root {
  color-scheme: light;
  font-family: system-ui, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  --ink: #25292e;
  --muted: #61676f;
  --paper: #f7f3e9;
  --card: #fffdf7;
  --border: #e3ded2;
  --blue: #275cbe;
  --blue-light: #e5eeff;
  --coral: #b54232;
  --coral-light: #fbe9e2;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: radial-gradient(ellipse at top left, #fffaf0, var(--paper) 55%);
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

button:focus-visible {
  outline: 3px solid var(--ink);
  outline-offset: 3px;
}

[hidden] {
  display: none !important;
}

.layout {
  max-width: 1040px;
  margin-inline: auto;
  padding: clamp(24px, 6vw, 64px) clamp(12px, 4vw, 32px) 32px;
}

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

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(2.25rem, 8vw, 4rem);
  letter-spacing: -0.085em;
  line-height: 1.05;
}

.masthead > div p {
  color: var(--muted);
  line-height: 1.6;
  margin-top: 12px;
  word-break: keep-all;
}

.connection {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: none;
  min-height: 32px;
  padding: 0 12px;
  margin-top: 3px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--card);
  color: var(--muted);
  font-size: 0.8125rem;
  font-weight: 650;
}

.connection::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #a06b19;
}

.connection[data-online="true"]::before {
  background: #24764b;
}

.game {
  display: grid;
  grid-template-columns: minmax(240px, 0.48fr) minmax(0, 1fr);
  align-items: start;
  gap: 18px;
}

.scoreboard,
.stage {
  min-width: 0;
  padding: clamp(14px, 2.6vw, 24px);
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--card);
  box-shadow: 0 10px 24px #3729130a;
}

h2 {
  font-size: 1.06rem;
  letter-spacing: -0.02em;
}

.team-buttons {
  display: grid;
  gap: 8px;
  margin-top: 14px;
}

[data-team="blue"] {
  --team-color: var(--blue);
  --team-background: var(--blue-light);
  --mark-angle: 0deg;
  --mark-radius: 50%;
}

[data-team="coral"] {
  --team-color: var(--coral);
  --team-background: var(--coral-light);
  --mark-angle: 45deg;
  --mark-radius: 2px;
}

.team {
  display: grid;
  grid-template-columns: 20px minmax(0, 1fr) auto;
  align-items: center;
  gap: 9px;
  min-height: 54px;
  padding: 8px 10px;
  border: 2px solid transparent;
  border-radius: 10px;
  color: var(--team-color);
  background: var(--team-background);
  font-weight: 700;
  text-align: left;
  white-space: nowrap;
}

.team:hover,
.team[aria-pressed="true"] {
  border-color: var(--team-color);
}

.team-points {
  display: inline-flex;
  align-items: baseline;
  gap: 2px;
  font-size: 0.8125rem;
}

.team strong {
  font-size: 1.375rem;
  font-variant-numeric: tabular-nums;
}

.team-mark,
.cell[data-team]::after {
  width: 12px;
  height: 12px;
  justify-self: center;
  border-radius: var(--mark-radius);
  transform: rotate(var(--mark-angle));
  background: var(--team-color);
}

.score-track {
  display: flex;
  overflow: hidden;
  height: 7px;
  margin-top: 14px;
  border-radius: 4px;
  background: var(--paper);
}

#blue-share {
  background: var(--blue);
}

#coral-share {
  margin-left: auto;
  background: var(--coral);
}

.round-status {
  margin-top: 14px;
  color: var(--muted);
  font-size: 0.875rem;
  line-height: 1.5;
  word-break: keep-all;
}

.round-status[data-winner] {
  color: var(--team-color);
  font-size: 1rem;
  font-weight: 750;
}

.next-round {
  width: 100%;
  min-height: 44px;
  margin-top: 12px;
  padding: 8px 12px;
  border: 0;
  border-radius: 10px;
  background: var(--ink);
  color: white;
  font-weight: 650;
}

.next-round:disabled {
  opacity: 0.6;
  cursor: default;
}

.stage-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}

#remaining {
  color: var(--muted);
  font-size: 0.875rem;
  font-variant-numeric: tabular-nums;
}

.board {
  display: grid;
  grid-template-columns: repeat(var(--board-size, 9), minmax(0, 1fr));
  gap: clamp(3px, 0.8vw, 7px);
  min-width: 0;
  aspect-ratio: 1;
  padding: clamp(5px, 1vw, 10px);
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #ece6d9;
}

.cell {
  display: grid;
  place-items: center;
  min-width: 0;
  aspect-ratio: 1;
  padding: 0;
  border: 1px solid #ddd7cb;
  border-radius: clamp(3px, 1vw, 8px);
  background: var(--card);
  touch-action: manipulation;
}

.cell[aria-disabled="true"] {
  cursor: default;
}

.cell[aria-disabled="false"]:hover {
  border-color: var(--team-color);
  background: var(--team-background);
}

.cell[data-team] {
  border-color: transparent;
  background: var(--team-color);
}

.cell[data-team]::after {
  content: "";
  width: 36%;
  height: 36%;
  background: #ffffffbc;
}

.cell:focus-visible {
  z-index: 1;
  outline-offset: 1px;
}

@media (max-width: 760px) {
  .game {
    grid-template-columns: minmax(0, 1fr);
    gap: 12px;
  }

  .team-buttons {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 420px) {
  .masthead {
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 16px;
  }

  .scoreboard,
  .stage {
    padding: 12px;
  }

  .team {
    grid-template-columns: 14px minmax(0, 1fr) auto;
    gap: 4px;
    padding-inline: 6px;
    font-size: 0.875rem;
  }
}
