:root {
  color-scheme: light dark;
  font-family: "Noto Sans TC", "PingFang TC", "Heiti TC", "Microsoft JhengHei", sans-serif;
  --accent: #3478f6;
  --accent-dark: #2457b2;
  --board-border: rgba(0, 0, 0, 0.15);
  --win: #fdd663;
  --background: #f6f7fb;
  --text: #1f1f1f;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--background);
  color: var(--text);
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 2rem 1rem;
}

.app {
  background: white;
  border-radius: 16px;
  box-shadow: 0 20px 40px rgba(23, 43, 77, 0.15);
  padding: 2rem;
  max-width: 480px;
  width: 100%;
  text-align: center;
}

h1 {
  margin-top: 0;
  margin-bottom: 0.5rem;
  font-size: clamp(2rem, 4vw, 2.75rem);
}

.status {
  margin: 0 0 0.5rem;
  font-weight: 600;
  font-size: 1.2rem;
}

.message {
  min-height: 1.5rem;
  margin: 0 0 1rem;
  color: #d93025;
  font-weight: 500;
}

.settings {
  display: grid;
  gap: 1rem;
  margin: 1.5rem 0;
  text-align: left;
}

.settings__group {
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 12px;
  padding: 0.75rem 1rem;
  display: grid;
  gap: 0.5rem;
  background: rgba(52, 120, 246, 0.05);
}

.settings__group legend {
  font-weight: 600;
  font-size: 0.95rem;
  padding: 0 0.5rem;
}

.settings__group--inline {
  display: grid;
  gap: 0.5rem;
}

.option {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.95rem;
}

.option input[type='radio'] {
  accent-color: var(--accent);
}

.option.disabled {
  opacity: 0.5;
}

.settings__group select {
  border-radius: 999px;
  border: 1px solid rgba(0, 0, 0, 0.1);
  padding: 0.4rem 0.75rem;
  font: inherit;
  background: white;
  color: inherit;
}

.settings__group select:disabled {
  opacity: 0.6;
  background: #f1f3f4;
}

.settings__hint {
  margin: -0.5rem 0 0;
  font-size: 0.85rem;
  color: #555;
}

.settings__hint.hidden {
  display: none;
}

.board {
  display: grid;
  gap: 0.75rem;
}

.board-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.75rem;
}

.cell {
  border: none;
  border-radius: 12px;
  font-size: clamp(1.8rem, 5vw, 2.8rem);
  font-weight: 700;
  color: var(--text);
  background: white;
  box-shadow: inset 0 0 0 1px var(--board-border);
  height: clamp(70px, 20vw, 110px);
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.cell:hover,
.cell:focus {
  outline: none;
  transform: translateY(-3px);
  box-shadow: inset 0 0 0 1px var(--accent), 0 10px 20px rgba(52, 120, 246, 0.15);
}

.cell.win {
  background: var(--win);
  box-shadow: inset 0 0 0 2px var(--accent-dark);
}

.cell[disabled],
.cell.disabled {
  cursor: not-allowed;
  opacity: 0.6;
  transform: none;
  box-shadow: inset 0 0 0 1px var(--board-border);
}

.controls {
  display: flex;
  justify-content: center;
  gap: 1rem;
  margin-top: 1.5rem;
  flex-wrap: wrap;
}

button {
  font: inherit;
}

.controls button,
#close-history {
  padding: 0.65rem 1.25rem;
  border-radius: 999px;
  border: none;
  cursor: pointer;
  background: var(--accent);
  color: white;
  font-weight: 600;
  letter-spacing: 0.05em;
  transition: background 0.2s ease, transform 0.2s ease;
}

.controls button:hover,
.controls button:focus,
#close-history:hover,
#close-history:focus {
  background: var(--accent-dark);
  outline: none;
  transform: translateY(-2px);
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 1.5rem;
  backdrop-filter: blur(6px);
}

.modal.hidden {
  display: none;
}

.modal__content {
  background: white;
  border-radius: 20px;
  padding: 1.5rem;
  max-width: 420px;
  width: 100%;
  box-shadow: 0 20px 40px rgba(15, 23, 42, 0.35);
  text-align: left;
}

.history-list {
  list-style: none;
  padding: 0;
  margin: 0 0 1rem;
  display: grid;
  gap: 0.75rem;
}

.history-list li {
  background: rgba(52, 120, 246, 0.08);
  border-radius: 12px;
  padding: 0.75rem 1rem;
  line-height: 1.5;
}

@media (max-width: 480px) {
  .app {
    padding: 1.5rem;
  }

  .settings {
    margin: 1.25rem 0;
  }

  .cell {
    height: clamp(60px, 24vw, 96px);
  }
}
