:root {
  color-scheme: light;
  --ink: #17201d;
  --muted: #5d6a65;
  --panel: #f7f4ee;
  --surface: rgba(255, 252, 246, 0.84);
  --card: #fffaf1;
  --button: #fffdf8;
  --line: #d8d0c3;
  --x: #1d6f8f;
  --o: #b54635;
  --board: #26352f;
  --tile: #fbfaf6;
  --focus: #e9b44c;
  --shadow: rgba(42, 35, 24, 0.13);
  --page:
    linear-gradient(135deg, rgba(29, 111, 143, 0.14), transparent 34%),
    linear-gradient(315deg, rgba(181, 70, 53, 0.13), transparent 30%),
    #ebe4d8;
}

html.dark-theme,
body.dark-theme {
  color-scheme: dark;
  --ink: #f1eee7;
  --muted: #c2bbb0;
  --panel: #1f2926;
  --surface: rgba(28, 35, 32, 0.9);
  --card: #26312d;
  --button: #202a27;
  --line: #48524d;
  --board: #111a18;
  --tile: #f4efe4;
  --focus: #f0bc55;
  --shadow: rgba(0, 0, 0, 0.32);
  --page:
    linear-gradient(135deg, rgba(29, 111, 143, 0.2), transparent 34%),
    linear-gradient(315deg, rgba(181, 70, 53, 0.16), transparent 30%),
    #141917;
}

* {
  box-sizing: border-box;
}

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

button {
  font: inherit;
}

button:disabled {
  cursor: default;
}

.site-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  width: min(1120px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 14px 0 0;
}

.site-nav a {
  color: var(--ink);
  text-decoration: none;
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: max-content;
  font-size: 1.1rem;
  font-weight: 950;
}
.brand-mark img {
  width: 38px;
  height: 38px;
  object-fit: contain;
}

.nav-links {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.nav-links a {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  border: 1px solid #bfb5a4;
  border-radius: 8px;
  background: var(--button);
  padding: 0 12px;
  font-weight: 800;
}

.nav-links a:hover,
.nav-links a[aria-current="page"] {
  border-color: var(--focus);
  box-shadow: 0 0 0 3px rgba(233, 180, 76, 0.22);
}

.game-shell {
  width: min(1120px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 14px 0 28px;
}

.scorebar,
.topbar,
.workspace,
.move-log-panel {
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: 0 22px 52px var(--shadow);
}

.topbar {
  display: grid;
  grid-template-columns: minmax(190px, 0.8fr) minmax(420px, 1.8fr) auto;
  align-items: stretch;
  gap: 16px;
  padding: 18px 20px;
  border-radius: 8px 8px 0 0;
}

.brand-block {
  display: grid;
  align-content: center;
}

.brand-block h1 {
  margin: 0;
  font-size: clamp(2.1rem, 5vw, 3.7rem);
  line-height: 0.95;
}

.rules-summary {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
}

.rules-summary div {
  display: grid;
  gap: 4px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
}

.rules-summary span {
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.35;
}

.theme-toggle {
  align-self: start;
}

.scorebar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 18px 20px;
  border-top: 0;
}

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

h2 {
  margin: 0;
  font-size: clamp(1.8rem, 4vw, 3rem);
  line-height: 1;
}

.score-pair {
  display: flex;
  gap: 10px;
}

.score-card {
  display: grid;
  grid-template-columns: auto auto;
  align-items: center;
  gap: 10px;
  min-width: 92px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
}

.score-card span {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 50%;
  color: white;
  font-weight: 900;
}

.score-card strong {
  font-size: 1.7rem;
}

.x-score span {
  background: var(--x);
}

.o-score span {
  background: var(--o);
}

.turn-card span {
  background: var(--board);
}

.workspace {
  display: grid;
  grid-template-columns: 250px 1fr;
  min-height: 580px;
  border-top: 0;
}

.panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 18px;
  border-right: 1px solid var(--line);
  background: var(--panel);
}

.action-group {
  display: grid;
  gap: 8px;
}

.action-button,
.reset-button,
.small-button {
  min-height: 46px;
  border: 1px solid #bfb5a4;
  border-radius: 8px;
  background: var(--button);
  color: var(--ink);
  cursor: pointer;
  font-weight: 800;
}

.action-button {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 12px;
  text-align: left;
}

.action-button:hover,
.reset-button:hover,
.small-button:hover,
.cell:not(.disabled):not(:disabled):hover {
  border-color: var(--focus);
  box-shadow: 0 0 0 3px rgba(233, 180, 76, 0.22);
}

.action-button.active {
  background: var(--board);
  border-color: var(--board);
  color: white;
}

.action-icon {
  display: grid;
  width: 28px;
  height: 28px;
  place-items: center;
  border-radius: 50%;
  background: rgba(23, 32, 29, 0.1);
  font-size: 1.1rem;
}

.active .action-icon {
  background: rgba(255, 255, 255, 0.16);
}

.status-card {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
}

.status-card strong {
  font-size: 1.55rem;
}

.control-card {
  display: grid;
  gap: 8px;
}

.control-card label {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.control-card select {
  min-height: 40px;
  width: 100%;
  border: 1px solid #bfb5a4;
  border-radius: 8px;
  background: var(--button);
  color: var(--ink);
  font: inherit;
  font-weight: 700;
  padding: 0 10px;
}

.count-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.reset-button {
  margin-top: auto;
}

.board-wrap {
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 18px;
  padding: 28px;
}

.board {
  --cols: 3;
  --rows: 3;
  display: grid;
  grid-template-columns: repeat(var(--cols), minmax(58px, 92px));
  grid-template-rows: repeat(var(--rows), minmax(58px, 92px));
  gap: 12px;
  width: fit-content;
  max-width: 100%;
  min-height: 260px;
  padding: 12px;
  border-radius: 8px;
  background: var(--board);
  overflow: auto;
}

.cell {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  border: 2px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  cursor: pointer;
}

.cell.disabled {
  cursor: default;
  opacity: 0.38;
}

.cell.removable {
  border-color: var(--focus);
  box-shadow: inset 0 0 0 2px rgba(233, 180, 76, 0.38);
}

.tile {
  display: grid;
  width: min(82%, 94px);
  aspect-ratio: 1;
  place-items: center;
  border: 3px solid #efe7da;
  border-radius: 8px;
  background: var(--tile);
  box-shadow: 0 10px 18px rgba(0, 0, 0, 0.18);
  color: var(--x);
  font-size: clamp(2.6rem, 10vw, 4.5rem);
  font-weight: 950;
  line-height: 1;
}

.tile.o {
  color: var(--o);
}

.tile.selected {
  outline: 4px solid var(--focus);
  outline-offset: 3px;
}

.tile.last {
  border-color: var(--focus);
}

.tile.scoring {
  animation: scorePulse 0.8s ease-in-out infinite alternate;
  border-color: var(--focus);
  box-shadow: 0 0 0 5px rgba(233, 180, 76, 0.34), 0 14px 24px rgba(0, 0, 0, 0.24);
}

.message {
  width: min(620px, 100%);
  min-height: 48px;
  margin: 0;
  padding: 13px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  color: var(--ink);
  text-align: center;
  font-weight: 700;
}

.message.win {
  background: #26352f;
  border-color: #26352f;
  color: white;
}

.move-log-panel {
  display: grid;
  gap: 12px;
  padding: 16px 20px;
  border-top: 0;
  border-radius: 0 0 8px 8px;
}

.move-log-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.move-log-header h2 {
  margin: 0;
  font-size: 1.35rem;
}

.small-button {
  min-height: 38px;
  padding: 0 12px;
  white-space: nowrap;
}

.move-log {
  display: grid;
  gap: 8px;
  max-height: 220px;
  margin: 0;
  padding: 0 0 0 24px;
  overflow: auto;
}

.move-log li {
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  color: var(--ink);
  font-size: 0.95rem;
  line-height: 1.35;
}

.move-log li:last-child {
  border-color: var(--focus);
}

@keyframes scorePulse {
  from {
    transform: scale(1);
  }

  to {
    transform: scale(1.08);
  }
}

@media (max-width: 760px) {
  .game-shell {
    width: min(100vw - 18px, 520px);
    padding: 9px 0 18px;
  }

  .site-nav {
    align-items: flex-start;
    flex-direction: column;
    width: min(100vw - 18px, 520px);
    padding-top: 9px;
  }

  .nav-links {
    justify-content: flex-start;
  }

  .topbar,
  .scorebar {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar {
    display: flex;
  }

  .rules-summary {
    grid-template-columns: 1fr;
  }

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

  .panel {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .action-group {
    grid-template-columns: repeat(3, 1fr);
  }

  .action-button {
    justify-content: center;
    padding: 0 8px;
  }

  .action-icon {
    display: none;
  }

  .board-wrap {
    padding: 18px 12px;
  }

  .board {
    max-width: min(92vw, 390px);
    gap: 8px;
    padding: 8px;
  }

  .move-log-header {
    align-items: flex-start;
    flex-direction: column;
  }
}
