:root {
  --wood-dark: #5c3d2e;
  --wood-mid: #8b6914;
  --wood-light: #c4a574;
  --grid-line: #3d2918;
  --text: #2a1810;
  --bg-page: #1e1510;
  --accent: #2d6a4f;
  --danger: #9b2c2c;
  --radius: 12px;
  --cell-size: min(2.1rem, 5.5vw);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Segoe UI", "PingFang TC", "Microsoft JhengHei", sans-serif;
  color: var(--text);
  background:
    radial-gradient(ellipse 120% 80% at 50% 0%, #2a2218 0%, var(--bg-page) 55%);
  line-height: 1.5;
}

.app {
  max-width: 42rem;
  margin: 0 auto;
  padding: 1.25rem 1rem 2rem;
}

.header {
  text-align: center;
  margin-bottom: 1rem;
}

.header h1 {
  margin: 0;
  font-size: 1.75rem;
  font-weight: 700;
  color: #e8dcc8;
  letter-spacing: 0.08em;
}

.subtitle {
  margin: 0.35rem 0 0;
  font-size: 0.9rem;
  color: #a89880;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1.25rem;
  align-items: center;
  justify-content: center;
  margin-bottom: 0.75rem;
}

.control-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.control-row.actions {
  gap: 0.5rem;
}

label[for="difficulty"] {
  color: #c9b99a;
  font-size: 0.9rem;
}

select#difficulty {
  padding: 0.4rem 2rem 0.4rem 0.6rem;
  border-radius: 8px;
  border: 1px solid #5a4a38;
  background: #2f261c;
  color: #e8dcc8;
  font-size: 0.95rem;
  cursor: pointer;
}

.btn {
  padding: 0.45rem 1rem;
  border-radius: 8px;
  border: 1px solid transparent;
  font-size: 0.9rem;
  cursor: pointer;
  font-family: inherit;
}

.btn.primary {
  background: var(--accent);
  color: #fff;
  border-color: #1b4332;
}

.btn.primary:hover {
  filter: brightness(1.08);
}

.btn.ghost {
  background: transparent;
  color: #c9b99a;
  border-color: #5a4a38;
}

.btn.ghost:hover {
  background: rgba(255, 255, 255, 0.06);
}

.status {
  text-align: center;
  min-height: 1.5em;
  margin: 0.5rem 0 1rem;
  font-weight: 600;
  color: #e8dcc8;
}

.status.thinking {
  color: #c4a574;
}

.status.win {
  color: #7dd87d;
}

.status.lose {
  color: #f0a0a0;
}

.status.draw {
  color: #b8b8e8;
}

.board-wrap {
  display: flex;
  justify-content: center;
  margin-bottom: 1.5rem;
}

.board {
  display: grid;
  grid-template-columns: repeat(15, var(--cell-size));
  grid-template-rows: repeat(15, var(--cell-size));
  gap: 0;
  padding: 0.55rem;
  border-radius: var(--radius);
  background-color: var(--wood-mid);
  background-image:
    repeating-linear-gradient(
      90deg,
      transparent 0,
      transparent 2px,
      rgba(60, 40, 25, 0.08) 2px,
      rgba(60, 40, 25, 0.08) 3px
    ),
    repeating-linear-gradient(
      0deg,
      transparent 0,
      transparent 2px,
      rgba(40, 28, 18, 0.1) 2px,
      rgba(40, 28, 18, 0.1) 3px
    ),
    linear-gradient(145deg, var(--wood-light) 0%, var(--wood-mid) 45%, var(--wood-dark) 100%);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.15),
    0 8px 24px rgba(0, 0, 0, 0.45),
    0 2px 0 rgba(0, 0, 0, 0.2);
  border: 3px solid #2a1a12;
}

.board.locked {
  pointer-events: none;
  opacity: 0.92;
}

.cell {
  position: relative;
  width: var(--cell-size);
  height: var(--cell-size);
  padding: 0;
  margin: 0;
  border: none;
  background: transparent;
  cursor: pointer;
  z-index: 1;
}

.cell:focus-visible {
  outline: 2px solid #7dd87d;
  outline-offset: -2px;
  z-index: 3;
}

.cell::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(var(--grid-line), var(--grid-line)) center / 100% 1px no-repeat,
    linear-gradient(var(--grid-line), var(--grid-line)) center / 1px 100% no-repeat;
  opacity: 0.85;
}

.cell.hoshi::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 22%;
  height: 22%;
  max-width: 5px;
  max-height: 5px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: var(--grid-line);
  opacity: 0.75;
  z-index: 0;
}

.cell .stone {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 78%;
  height: 78%;
  transform: translate(-50%, -50%) scale(0);
  border-radius: 50%;
  pointer-events: none;
  z-index: 2;
  transition: transform 0.12s ease-out;
}

.cell.has-stone .stone {
  transform: translate(-50%, -50%) scale(1);
}

.cell.black .stone {
  background: radial-gradient(circle at 32% 28%, #666 0%, #111 45%, #000 100%);
  box-shadow:
    inset -2px -3px 4px rgba(255, 255, 255, 0.12),
    0 2px 4px rgba(0, 0, 0, 0.5);
}

.cell.white .stone {
  background: radial-gradient(circle at 32% 28%, #fff 0%, #e8e8e8 40%, #b8b8b8 100%);
  box-shadow:
    inset -2px -2px 3px rgba(0, 0, 0, 0.15),
    0 2px 4px rgba(0, 0, 0, 0.35);
}

.stats h2 {
  margin: 0 0 0.5rem;
  font-size: 1.1rem;
  color: #e8dcc8;
}

.stats-summary {
  font-size: 0.9rem;
  color: #a89880;
  margin-bottom: 0.75rem;
}

.stats-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
  color: #d4c8b4;
}

.stats-table th,
.stats-table td {
  padding: 0.4rem 0.5rem;
  text-align: center;
  border: 1px solid #4a3c2e;
}

.stats-table th {
  background: #2a2218;
  color: #c9b99a;
  font-weight: 600;
}

.stats-table tbody tr:nth-child(even) {
  background: rgba(255, 255, 255, 0.03);
}

@media (max-width: 380px) {
  :root {
    --cell-size: min(1.85rem, 5vw);
  }
}
