:root {
  color-scheme: light;
  --ink: #17212b;
  --muted: #5e6978;
  --line: #d8dee8;
  --paper: #f7f3ea;
  --panel: #ffffff;
  --accent: #0f766e;
  --accent-dark: #0b5f5a;
  --x: #d14343;
  --o: #2563eb;
  --win: #f3bd2f;
  --shadow: 0 24px 70px rgba(23, 33, 43, 0.15);
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    linear-gradient(135deg, rgba(15, 118, 110, 0.18), transparent 34%),
    linear-gradient(315deg, rgba(209, 67, 67, 0.13), transparent 28%),
    var(--paper);
}

button,
input {
  font: inherit;
}

.shell {
  width: min(1120px, calc(100vw - 32px));
  min-height: 100vh;
  margin: 0 auto;
  padding: 32px 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 24px;
  align-items: center;
}

.game-panel,
.side-panel {
  background: rgba(255, 255, 255, 0.86);
  border: 1px solid rgba(216, 222, 232, 0.9);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.game-panel {
  border-radius: 8px;
  padding: clamp(20px, 3vw, 32px);
}

.side-panel {
  border-radius: 8px;
  padding: 24px;
}

.topbar,
.status-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.eyebrow,
.label {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(2.25rem, 7vw, 5rem);
  line-height: 0.9;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 20px;
  font-size: 1.2rem;
}

.icon-button {
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: var(--panel);
  cursor: pointer;
}

.icon-button:hover,
.icon-button:focus-visible {
  border-color: var(--accent);
  color: var(--accent-dark);
}

.controls {
  margin: 28px 0 22px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

fieldset {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

legend {
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.segmented {
  min-height: 42px;
  padding: 4px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #eef2f6;
}

.segmented:has(input[name="difficulty"]) {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

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

.segmented label {
  min-width: 0;
  display: block;
}

.segmented input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented span {
  min-height: 32px;
  padding: 7px 8px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  color: var(--muted);
  font-size: clamp(0.75rem, 1.7vw, 0.9rem);
  font-weight: 800;
  text-align: center;
  white-space: nowrap;
  cursor: pointer;
}

.segmented input:checked + span {
  color: #ffffff;
  background: var(--accent);
}

.segmented input:focus-visible + span {
  outline: 3px solid rgba(15, 118, 110, 0.28);
}

.is-muted {
  opacity: 0.45;
}

.is-muted .segmented span {
  cursor: default;
}

.status-row {
  min-height: 64px;
  padding: 12px 0 18px;
  border-top: 1px solid var(--line);
}

.status {
  margin-bottom: 0;
  font-size: clamp(1.2rem, 2.4vw, 1.65rem);
  font-weight: 850;
}

#newRoundButton {
  min-height: 42px;
  padding: 0 16px;
  border: 0;
  border-radius: 8px;
  color: #ffffff;
  background: var(--ink);
  font-weight: 800;
  cursor: pointer;
}

#newRoundButton:hover,
#newRoundButton:focus-visible {
  background: var(--accent-dark);
}

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

.board {
  width: min(100%, 560px);
  aspect-ratio: 1;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: clamp(8px, 1.8vw, 14px);
}

.cell {
  position: relative;
  display: grid;
  place-items: center;
  border: 2px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #ffffff;
  cursor: pointer;
  transition: transform 140ms ease, border-color 140ms ease, box-shadow 140ms ease;
}

.cell:hover:not(:disabled),
.cell:focus-visible {
  z-index: 1;
  border-color: var(--accent);
  box-shadow: 0 10px 24px rgba(15, 118, 110, 0.16);
  transform: translateY(-2px);
}

.cell:disabled {
  cursor: default;
}

.cell::before,
.cell::after {
  content: "";
  position: absolute;
  opacity: 0;
}

.cell.x::before,
.cell.x::after {
  width: 70%;
  height: 12%;
  border-radius: 999px;
  background: var(--x);
  opacity: 1;
}

.cell.x::before {
  transform: rotate(45deg);
}

.cell.x::after {
  transform: rotate(-45deg);
}

.cell.o::before {
  width: 62%;
  height: 62%;
  border: clamp(10px, 1.7vw, 16px) solid var(--o);
  border-radius: 50%;
  opacity: 1;
}

.cell.win {
  border-color: var(--win);
  background: #fff8df;
}

.score-grid {
  display: grid;
  gap: 12px;
}

.score,
.match-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.score {
  min-height: 82px;
  padding: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

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

.mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  color: #ffffff;
  font-size: 1.3rem;
  font-weight: 900;
}

.x-mark {
  background: var(--x);
}

.o-mark {
  background: var(--o);
}

.draw-mark {
  background: var(--ink);
}

.match-card {
  margin-top: 14px;
  padding: 16px;
}

.match-card p:last-child {
  margin-bottom: 0;
  font-weight: 800;
}

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

  .side-panel {
    order: -1;
  }

  .score-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 640px) {
  .shell {
    width: min(100vw - 20px, 520px);
    padding: 10px 0;
    gap: 10px;
  }

  .game-panel,
  .side-panel {
    padding: 16px;
  }

  .topbar {
    align-items: flex-start;
  }

  .controls {
    grid-template-columns: 1fr;
    margin-top: 22px;
  }

  .status-row {
    align-items: flex-start;
    flex-direction: column;
  }

  #newRoundButton {
    width: 100%;
  }

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

  .score {
    min-height: 64px;
  }
}
