:root {
  color-scheme: light;
  --paper: #f7f3ea;
  --ink: #1f2a32;
  --muted: #66747d;
  --line: #283842;
  --accent-o: #e84f45;
  --accent-x: #2077b5;
  --gold: #d49b22;
  --panel: #fffdf8;
  --shadow: 0 24px 70px rgba(31, 42, 50, 0.16);
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  font-family: "Segoe UI", "Yu Gothic UI", "Hiragino Sans", Meiryo, sans-serif;
  background:
    linear-gradient(90deg, rgba(32, 119, 181, 0.08) 1px, transparent 1px),
    linear-gradient(rgba(232, 79, 69, 0.07) 1px, transparent 1px),
    var(--paper);
  background-size: 38px 38px;
  color: var(--ink);
}

button,
input {
  font: inherit;
}

.game-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.game-panel {
  width: min(100%, 560px);
  padding: clamp(20px, 4vw, 36px);
  background: var(--panel);
  border: 2px solid rgba(31, 42, 50, 0.12);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

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

.eyebrow {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
}

h1 {
  margin: 0;
  font-size: clamp(2.1rem, 7vw, 4.2rem);
  line-height: 1;
  letter-spacing: 0;
}

.icon-button,
.text-button {
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  transition: transform 140ms ease, background 140ms ease, color 140ms ease;
}

.icon-button {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  background: var(--ink);
  color: white;
  font-size: 1.45rem;
}

.text-button {
  min-height: 42px;
  padding: 0 16px;
  background: var(--ink);
  color: white;
  font-weight: 800;
}

.quiet {
  background: rgba(31, 42, 50, 0.08);
  color: var(--ink);
}

.icon-button:hover,
.text-button:hover,
.cell:hover {
  transform: translateY(-1px);
}

.status-row {
  margin-top: 24px;
}

.role-label {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 800;
}

.turn-label {
  margin: 0;
  min-height: 32px;
  display: flex;
  align-items: center;
  font-size: clamp(1.2rem, 4vw, 1.55rem);
  font-weight: 900;
}

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

.score-card {
  min-width: 0;
  padding: 12px 10px;
  border: 2px solid rgba(31, 42, 50, 0.1);
  border-radius: 8px;
  background: #f8fbfb;
  text-align: center;
}

.score-card span,
.score-card strong {
  display: block;
}

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

.score-card strong {
  margin-top: 2px;
  font-size: 1.8rem;
  line-height: 1;
}

.score-card.active {
  border-color: var(--gold);
  background: #fff7df;
}

.board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 10px;
  aspect-ratio: 1;
}

.cell {
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  border: 3px solid var(--line);
  border-radius: 8px;
  background: #fdfaf2;
  color: var(--ink);
  cursor: pointer;
  font-size: clamp(3rem, 18vw, 6.5rem);
  font-weight: 900;
  line-height: 1;
  overflow: hidden;
  transition: transform 140ms ease, background 140ms ease, border-color 140ms ease;
}

.cell.mark-o {
  color: var(--accent-o);
}

.cell.mark-x {
  color: var(--accent-x);
}

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

.cell:disabled {
  cursor: default;
}

.controls {
  margin-top: 20px;
}

.difficulty {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  flex: 1;
}

.difficulty-button {
  min-width: 0;
  min-height: 42px;
  padding: 0 8px;
  border: 2px solid rgba(31, 42, 50, 0.12);
  border-radius: 8px;
  background: #f8fbfb;
  color: var(--ink);
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 900;
  line-height: 1.15;
  transition: background 140ms ease, border-color 140ms ease, transform 140ms ease;
}

.difficulty-button:hover {
  transform: translateY(-1px);
}

.difficulty-button.active {
  border-color: var(--gold);
  background: #fff7df;
}

@media (max-width: 460px) {
  .game-shell {
    padding: 14px;
  }

  .topbar,
  .status-row,
  .controls {
    align-items: stretch;
  }

  .status-row,
  .controls {
    flex-direction: column;
  }

  .text-button {
    width: 100%;
  }

  .difficulty {
    width: 100%;
  }

  .scoreboard {
    gap: 8px;
  }

  .score-card {
    padding-inline: 6px;
  }
}
