:root {
  color-scheme: light;
  --ink: #201a14;
  --muted: #6f604f;
  --line: rgba(55, 35, 18, 0.76);
  --wood-a: #f4d48e;
  --wood-b: #dfad5b;
  --wood-c: #c88938;
  --accent: #7d341f;
  --panel: rgba(255, 250, 239, 0.82);
  --shadow: 0 22px 60px rgba(70, 42, 15, 0.2);
}

* {
  box-sizing: border-box;
}

html,
body {
  max-width: 100%;
  overflow-x: hidden;
}

body {
  margin: 0;
  min-height: 100vh;
  background: linear-gradient(135deg, #f8f2e7 0%, #efe0ca 48%, #f7eddd 100%);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

[hidden] {
  display: none !important;
}

button,
select {
  font: inherit;
}

.app-shell {
  width: min(1120px, 100%);
  max-width: calc(100vw - 24px);
  margin: 0 auto;
  padding: clamp(18px, 4vw, 40px) 0;
}

.hero {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.hero h1 {
  margin: 0;
  font-size: clamp(2.2rem, 7vw, 4.7rem);
  line-height: 0.92;
  letter-spacing: 0;
}

.hero p {
  max-width: 560px;
  margin: 10px 0 0;
  color: var(--muted);
  font-size: clamp(1rem, 2.4vw, 1.18rem);
}

.controls,
.game-panel {
  background: var(--panel);
  border: 1px solid rgba(95, 62, 24, 0.17);
  box-shadow: 0 12px 34px rgba(75, 46, 18, 0.1);
  backdrop-filter: blur(12px);
}

.controls {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  padding: 14px;
  border-radius: 8px;
  margin-bottom: 16px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

select {
  width: 100%;
  min-height: 44px;
  border: 1px solid rgba(63, 43, 22, 0.24);
  border-radius: 7px;
  background: #fffaf0;
  color: var(--ink);
  padding: 0 12px;
}

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

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

.status {
  margin: 0;
  font-size: clamp(1.15rem, 3.2vw, 1.6rem);
  font-weight: 800;
}

.message {
  min-height: 1.3em;
  margin: 5px 0 0;
  color: var(--accent);
  font-weight: 700;
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

button {
  min-height: 44px;
  border: 0;
  border-radius: 7px;
  background: #2f241b;
  color: #fff8ea;
  padding: 0 16px;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 8px 16px rgba(47, 36, 27, 0.16);
}

button:hover {
  background: #463421;
}

button:focus-visible,
select:focus-visible,
.intersection:focus-visible {
  outline: 3px solid rgba(125, 52, 31, 0.44);
  outline-offset: 2px;
}

.board-wrap {
  display: grid;
  place-items: center;
  width: 100%;
  max-width: 100%;
  overflow: hidden;
}

.board {
  --size: 15;
  --cell: calc((100% - (var(--pad) * 2)) / (var(--size) - 1));
  --preview-size: calc(var(--cell) * 0.38);
  position: relative;
  width: min(100%, 76vh, 780px);
  max-width: 100%;
  aspect-ratio: 1;
  border-radius: 8px;
  border: clamp(8px, 1.9vw, 18px) solid #b8752d;
  background:
    linear-gradient(90deg, rgba(95, 52, 18, 0.09) 0 1px, transparent 1px 27px),
    linear-gradient(7deg, rgba(255, 255, 255, 0.16), transparent 34%),
    repeating-linear-gradient(92deg, rgba(113, 63, 21, 0.08) 0 3px, transparent 3px 20px),
    linear-gradient(135deg, var(--wood-a), var(--wood-b) 58%, var(--wood-c));
  box-shadow: var(--shadow), inset 0 0 0 1px rgba(82, 44, 15, 0.18);
  touch-action: manipulation;
}

.grid-lines {
  position: absolute;
  inset: var(--pad);
  pointer-events: none;
}

.point-layer {
  position: absolute;
  inset: var(--pad);
}

.grid-line {
  position: absolute;
  background: var(--line);
}

.grid-line.vertical {
  top: 0;
  bottom: 0;
  width: 1px;
  transform: translateX(-0.5px);
}

.grid-line.horizontal {
  left: 0;
  right: 0;
  height: 1px;
  transform: translateY(-0.5px);
}

.intersection,
.star,
.stone {
  position: absolute;
  transform: translate(-50%, -50%);
}

.intersection {
  width: min(9.5vw, calc(var(--cell) * 0.9));
  height: min(9.5vw, calc(var(--cell) * 0.9));
  border: 0;
  border-radius: 50%;
  padding: 0;
  background: transparent;
  box-shadow: none;
  z-index: 3;
  -webkit-tap-highlight-color: transparent;
}

.intersection:hover,
.intersection:active {
  background: transparent;
  box-shadow: none;
}

.intersection.empty::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: var(--preview-size);
  height: var(--preview-size);
  aspect-ratio: 1;
  border-radius: 50%;
  opacity: 0;
  background: rgba(0, 0, 0, 0.52);
  transform: translate(-50%, -50%);
  transition: opacity 120ms ease;
  pointer-events: none;
}

.intersection.empty:hover::after {
  opacity: 1;
}

.star {
  width: clamp(5px, 1vw, 8px);
  height: clamp(5px, 1vw, 8px);
  border-radius: 50%;
  background: rgba(50, 30, 14, 0.84);
  z-index: 1;
}

.stone {
  width: calc(var(--cell) * 0.74);
  height: calc(var(--cell) * 0.74);
  border-radius: 50%;
  z-index: 2;
  pointer-events: none;
}

.stone.black {
  background:
    radial-gradient(circle at 34% 26%, rgba(255, 255, 255, 0.22), transparent 16%),
    radial-gradient(circle at 58% 68%, #050505, #14110f 46%, #302a25 76%, #050505);
  box-shadow: 0 7px 10px rgba(24, 16, 10, 0.33), inset -5px -7px 10px rgba(0, 0, 0, 0.55);
}

.stone.white {
  background:
    radial-gradient(circle at 32% 24%, #ffffff, rgba(255, 255, 255, 0.42) 18%, transparent 28%),
    radial-gradient(circle at 58% 64%, #fffef6, #eee8d9 62%, #c8c1b2);
  border: 1px solid rgba(115, 111, 103, 0.52);
  box-shadow: 0 7px 10px rgba(24, 16, 10, 0.22), inset -5px -7px 11px rgba(130, 124, 112, 0.22);
}

.stone.winning {
  outline: 3px solid #c43821;
  outline-offset: 3px;
}

@media (max-width: 720px) {
  .hero,
  .status-row {
    display: grid;
    align-items: start;
  }

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

  .action-row {
    justify-content: stretch;
  }

  .action-row button {
    flex: 1 1 160px;
  }
}

@media (hover: none), (pointer: coarse) {
  .intersection,
  .intersection:hover,
  .intersection:active,
  .intersection:focus {
    background: transparent !important;
    box-shadow: none !important;
    outline: 0;
  }

  .intersection.empty::after {
    display: none !important;
  }
}
