:root {
  color-scheme: light;
  --bg: #f4f2ed;
  --panel: #ffffff;
  --panel-strong: #f8fafc;
  --ink: #1f2937;
  --muted: #6b7280;
  --line: #d7d1c6;
  --board: #d9a95f;
  --board-dark: #9d6b2d;
  --accent: #0f766e;
  --accent-strong: #115e59;
  --danger: #b91c1c;
  --shadow: 0 24px 70px rgba(31, 41, 55, 0.16);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(135deg, rgba(15, 118, 110, 0.12), transparent 34%),
    linear-gradient(315deg, rgba(185, 28, 28, 0.08), transparent 30%),
    var(--bg);
  color: var(--ink);
  font-family:
    Inter, "Segoe UI", "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
}

button,
select {
  font: inherit;
}

.app-shell {
  width: min(1180px, calc(100vw - 32px));
  min-height: 100vh;
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(320px, 1fr) 320px;
  gap: 24px;
  align-items: center;
  padding: 24px 0;
}

.game-area {
  display: grid;
  place-items: center;
  min-width: 0;
}

.board-frame {
  width: min(72vh, 100%);
  max-width: 760px;
  aspect-ratio: 1;
  padding: clamp(10px, 1.8vw, 18px);
  border: 1px solid rgba(89, 55, 21, 0.28);
  border-radius: 8px;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.22), transparent 34%, rgba(91, 52, 13, 0.11)),
    repeating-linear-gradient(90deg, rgba(109, 68, 22, 0.1) 0 2px, transparent 2px 18px),
    linear-gradient(135deg, #e7bf75, var(--board));
  box-shadow: var(--shadow), inset 0 0 0 1px rgba(255, 255, 255, 0.35);
}

#board {
  width: 100%;
  height: 100%;
  display: block;
  border-radius: 6px;
  cursor: pointer;
  touch-action: manipulation;
}

.side-panel {
  align-self: stretch;
  max-height: min(720px, calc(100vh - 48px));
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 22px;
  border: 1px solid rgba(148, 163, 184, 0.34);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.88);
  box-shadow: 0 18px 46px rgba(31, 41, 55, 0.11);
  backdrop-filter: blur(10px);
}

.title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(30px, 5vw, 42px);
  line-height: 1;
  letter-spacing: 0;
}

.turn-badge {
  min-width: 92px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel-strong);
  font-weight: 800;
  white-space: nowrap;
}

.stone-dot {
  width: 18px;
  height: 18px;
  flex: 0 0 18px;
  border-radius: 50%;
  box-shadow: inset -2px -2px 5px rgba(0, 0, 0, 0.2);
}

.stone-dot.black {
  background: radial-gradient(circle at 34% 28%, #72757d, #111827 62%, #030712);
}

.stone-dot.white {
  border: 1px solid #cbd5e1;
  background: radial-gradient(circle at 34% 28%, #ffffff, #e5e7eb 68%, #cbd5e1);
  box-shadow: inset -2px -2px 5px rgba(148, 163, 184, 0.32);
}

.status-box {
  min-height: 52px;
  display: flex;
  align-items: center;
  padding: 12px 14px;
  border-left: 4px solid var(--accent);
  border-radius: 6px;
  background: #ecfdf5;
  color: #064e3b;
  font-weight: 800;
}

.status-box.win {
  border-left-color: var(--danger);
  background: #fef2f2;
  color: #7f1d1d;
}

.status-box.draw {
  border-left-color: #64748b;
  background: #f8fafc;
  color: #334155;
}

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

label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

select {
  width: 100%;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  outline: none;
}

select:focus-visible,
button:focus-visible,
#board:focus-visible {
  outline: 3px solid rgba(15, 118, 110, 0.26);
  outline-offset: 2px;
}

.metrics {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.metrics > div {
  min-height: 72px;
  display: grid;
  align-content: center;
  gap: 6px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-strong);
}

.metrics span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.metrics strong {
  font-size: 24px;
  line-height: 1;
}

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

button {
  min-height: 44px;
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: white;
  font-weight: 900;
  cursor: pointer;
  transition:
    transform 120ms ease,
    background 120ms ease,
    box-shadow 120ms ease;
}

button:hover {
  background: var(--accent-strong);
  box-shadow: 0 10px 20px rgba(15, 118, 110, 0.18);
}

button:active {
  transform: translateY(1px);
}

button.secondary {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
}

button.secondary:hover {
  background: #f8fafc;
  box-shadow: 0 10px 20px rgba(31, 41, 55, 0.08);
}

.help-button {
  width: 100%;
  border: 1px solid rgba(15, 118, 110, 0.28);
  background: #f0fdfa;
  color: var(--accent-strong);
}

.help-button:hover {
  background: #ccfbf1;
  box-shadow: 0 10px 20px rgba(15, 118, 110, 0.12);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
  box-shadow: none;
}

.move-list {
  min-height: 0;
  overflow: auto;
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 8px;
}

.move-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 34px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: #334155;
  font-size: 13px;
}

.move-list b {
  color: var(--ink);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(17, 24, 39, 0.48);
}

.modal-backdrop[hidden] {
  display: none;
}

.help-modal {
  width: min(620px, 100%);
  max-height: min(720px, calc(100vh - 40px));
  overflow: hidden;
  display: flex;
  flex-direction: column;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 28px 70px rgba(15, 23, 42, 0.28);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
}

.modal-header h2 {
  margin: 0;
  font-size: 22px;
  line-height: 1.2;
}

.icon-button {
  width: 38px;
  min-height: 38px;
  flex: 0 0 38px;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: #fff;
  color: var(--ink);
  font-size: 24px;
  line-height: 1;
}

.icon-button:hover {
  background: #f8fafc;
  box-shadow: 0 8px 18px rgba(31, 41, 55, 0.08);
}

.modal-content {
  overflow: auto;
  padding: 20px;
}

.modal-content h3 {
  margin: 0 0 10px;
  font-size: 16px;
}

.modal-content h3:not(:first-child) {
  margin-top: 18px;
}

.modal-content ul {
  margin: 0;
  padding-left: 20px;
  color: #374151;
  line-height: 1.72;
}

.modal-content li + li {
  margin-top: 4px;
}

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
    align-items: start;
    padding: 16px 0;
  }

  .board-frame {
    width: min(100%, calc(100vh - 300px));
    min-width: min(100%, 320px);
  }

  .side-panel {
    max-height: none;
  }

  .move-list {
    max-height: 180px;
  }
}

@media (max-width: 520px) {
  .app-shell {
    width: min(100vw - 20px, 460px);
    gap: 14px;
  }

  .side-panel {
    padding: 16px;
    gap: 14px;
  }

  .title-row {
    align-items: center;
  }

  h1 {
    font-size: 32px;
  }

  .turn-badge {
    min-width: 82px;
    padding: 8px 10px;
  }

  .modal-backdrop {
    padding: 12px;
  }

  .modal-header {
    padding: 16px;
  }

  .modal-header h2 {
    font-size: 19px;
  }

  .modal-content {
    padding: 16px;
  }
}
