:root {
  --ink: #1d2228;
  --muted: #66717f;
  --line: #5b4632;
  --wood: #d9a860;
  --wood-dark: #bb8240;
  --paper: #faf7f1;
  --accent: #2f7d68;
  --cell: clamp(18px, min(calc((100vw - 44px) / 15), calc((100dvh - 232px) / 15)), 38px);
}

* {
  box-sizing: border-box;
}

body {
  width: 100vw;
  height: 100dvh;
  min-height: 0;
  margin: 0;
  overflow: hidden;
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  background:
    linear-gradient(120deg, rgba(47, 125, 104, 0.13), transparent 34%),
    linear-gradient(280deg, rgba(214, 74, 61, 0.11), transparent 36%),
    var(--paper);
  display: grid;
  place-items: center;
  padding: clamp(8px, 2vmin, 18px);
}

.app {
  width: min(100%, 1180px);
  height: 100%;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: clamp(8px, 1.6vmin, 14px);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 0;
}

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

.status {
  min-height: 0;
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 17px;
  font-weight: 700;
}

.status.win {
  color: var(--accent);
}

.controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.mode-switch {
  display: grid;
  grid-template-columns: repeat(2, 58px);
  width: fit-content;
  min-height: 44px;
  padding: 3px;
  border: 1px solid rgba(29, 34, 40, 0.13);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.62);
  box-shadow: 0 8px 24px rgba(29, 34, 40, 0.07);
}

.mode-button {
  min-width: 58px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 15px;
  font-weight: 800;
  cursor: pointer;
}

.game-reviews {
  display: grid;
  gap: 8px;
}

.game-reviews:empty {
  display: none;
}

.review-item {
  padding: 10px 12px;
  border: 1px solid rgba(29, 34, 40, 0.13);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
  box-shadow: 0 8px 22px rgba(29, 34, 40, 0.07);
}

.review-item h3 {
  margin: 0 0 6px;
  font-size: 14px;
  line-height: 1.2;
}

.review-item p {
  margin: 3px 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
  line-height: 1.4;
}

.mode-button.active {
  background: var(--accent);
  color: white;
}

.file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.icon-button {
  width: 44px;
  height: 44px;
  border: 1px solid rgba(29, 34, 40, 0.15);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
  color: var(--ink);
  font-size: 24px;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(29, 34, 40, 0.08);
}

.icon-button:hover {
  border-color: rgba(47, 125, 104, 0.42);
  color: var(--accent);
}

.icon-button.muted {
  color: var(--muted);
  opacity: 0.72;
}

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

.icon-button.small {
  width: 38px;
  height: 38px;
  font-size: 22px;
}

.undo-button {
  min-width: 86px;
  height: 38px;
  padding: 0 12px;
  border: 1px solid rgba(29, 34, 40, 0.15);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
  color: var(--ink);
  font-size: 14px;
  font-weight: 900;
  letter-spacing: 0;
  cursor: pointer;
  white-space: nowrap;
  box-shadow: 0 8px 24px rgba(29, 34, 40, 0.08);
}

.undo-button:hover {
  border-color: rgba(47, 125, 104, 0.42);
  color: var(--accent);
}

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

.games {
  display: grid;
  grid-template-columns: 1fr;
  gap: clamp(8px, 1.6vmin, 14px);
  min-height: 0;
  align-items: center;
}

.games.two-player {
  --cell: clamp(18px, min(calc((100vw - 44px) / 15), calc((100dvh - 238px) / 15)), 46px);
}

.games.dual {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: start;
}

.game-panel {
  width: 100%;
  min-height: 0;
  overflow: visible;
  padding: clamp(2px, 1vmin, 8px);
}

.board-header {
  width: calc(var(--cell) * 15);
  max-width: 100%;
  min-height: 0;
  margin: 0 auto clamp(4px, 1vmin, 8px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

h2 {
  margin: 0;
  font-size: 18px;
  line-height: 1.1;
  letter-spacing: 0;
}

.stone-legend {
  min-height: 0;
  margin: 5px 0 0;
  display: flex;
  flex-wrap: wrap;
  gap: 6px 12px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 800;
}

.stone-legend span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.legend-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(29, 34, 40, 0.22);
}

.black-dot {
  background: #111418;
}

.white-dot {
  background: #f7f8f8;
  border: 1px solid rgba(29, 34, 40, 0.22);
}

.game-time {
  width: fit-content;
  min-height: 0;
  margin: 6px 0 0;
  padding: 3px 8px;
  border-radius: 7px;
  background: rgba(29, 34, 40, 0.08);
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-size: 15px;
  font-weight: 900;
  line-height: 1.2;
}

.game-time.running {
  background: rgba(47, 125, 104, 0.12);
  color: var(--accent);
}

.board-status {
  min-height: 0;
  width: fit-content;
  max-width: 100%;
  margin: 7px 0 0;
  padding: 5px 10px;
  border: 1px solid rgba(29, 34, 40, 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.66);
  color: var(--ink);
  font-size: 18px;
  font-weight: 900;
  line-height: 1.2;
  overflow-wrap: anywhere;
  box-shadow: 0 6px 16px rgba(29, 34, 40, 0.07);
}

.board-status::before {
  content: "";
  display: inline-block;
  width: 13px;
  height: 13px;
  margin-right: 7px;
  border-radius: 50%;
  vertical-align: -1px;
}

.board-status.black-turn::before {
  background: #111418;
}

.board-status.white-turn {
  background: rgba(255, 255, 255, 0.86);
}

.board-status.white-turn::before {
  background: #f7f8f8;
  border: 1px solid rgba(29, 34, 40, 0.26);
}

.board-status.thinking::before {
  background: var(--accent);
}

.board-status.win {
  border-color: rgba(47, 125, 104, 0.34);
  background: rgba(47, 125, 104, 0.1);
  color: var(--accent);
}

.board {
  position: relative;
  box-sizing: content-box;
  width: calc(var(--cell) * 15);
  height: calc(var(--cell) * 15);
  overflow: hidden;
  contain: layout paint;
  isolation: isolate;
  display: grid;
  grid-template-columns: repeat(15, var(--cell));
  grid-template-rows: repeat(15, var(--cell));
  background:
    radial-gradient(circle at 26% 18%, rgba(255, 255, 255, 0.2), transparent 32%),
    linear-gradient(135deg, var(--wood), var(--wood-dark));
  border: 2px solid #7b4f26;
  border-radius: 8px;
  box-shadow: 0 22px 48px rgba(64, 42, 21, 0.22);
}

.board-frame {
  width: calc(var(--cell) * 15);
  max-width: 100%;
  margin: 0 auto;
}

.coord-row {
  display: none;
  grid-template-columns: 26px repeat(15, var(--cell));
  align-items: center;
  height: 22px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  text-align: center;
}

.board-body {
  display: block;
}

.board-wrap {
  position: relative;
  width: calc(var(--cell) * 15);
  height: calc(var(--cell) * 15);
}

.coord-col {
  display: none;
  grid-template-rows: repeat(15, var(--cell));
  align-items: center;
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  text-align: center;
}

.point {
  position: relative;
  width: var(--cell);
  height: var(--cell);
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
}

.point::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(var(--line), var(--line)) center / 100% 1px no-repeat,
    linear-gradient(90deg, var(--line), var(--line)) center / 1px 100% no-repeat;
  opacity: 0.78;
}

.point.edge-top::before {
  background:
    linear-gradient(var(--line), var(--line)) center / 100% 1px no-repeat,
    linear-gradient(90deg, var(--line), var(--line)) bottom / 1px 50% no-repeat;
}

.point.edge-bottom::before {
  background:
    linear-gradient(var(--line), var(--line)) center / 100% 1px no-repeat,
    linear-gradient(90deg, var(--line), var(--line)) top / 1px 50% no-repeat;
}

.point.edge-left::before {
  background:
    linear-gradient(var(--line), var(--line)) right / 50% 1px no-repeat,
    linear-gradient(90deg, var(--line), var(--line)) center / 1px 100% no-repeat;
}

.point.edge-right::before {
  background:
    linear-gradient(var(--line), var(--line)) left / 50% 1px no-repeat,
    linear-gradient(90deg, var(--line), var(--line)) center / 1px 100% no-repeat;
}

.point.corner-top-left::before {
  background:
    linear-gradient(var(--line), var(--line)) right / 50% 1px no-repeat,
    linear-gradient(90deg, var(--line), var(--line)) bottom / 1px 50% no-repeat;
}

.point.corner-top-right::before {
  background:
    linear-gradient(var(--line), var(--line)) left / 50% 1px no-repeat,
    linear-gradient(90deg, var(--line), var(--line)) bottom / 1px 50% no-repeat;
}

.point.corner-bottom-left::before {
  background:
    linear-gradient(var(--line), var(--line)) right / 50% 1px no-repeat,
    linear-gradient(90deg, var(--line), var(--line)) top / 1px 50% no-repeat;
}

.point.corner-bottom-right::before {
  background:
    linear-gradient(var(--line), var(--line)) left / 50% 1px no-repeat,
    linear-gradient(90deg, var(--line), var(--line)) top / 1px 50% no-repeat;
}

.point.star::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--line);
  transform: translate(-50%, -50%);
}

.point.stone::after {
  content: "";
  position: absolute;
  z-index: 1;
  top: 50%;
  left: 50%;
  width: calc(var(--cell) * 0.78);
  height: calc(var(--cell) * 0.78);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  opacity: 1;
  backface-visibility: hidden;
  box-shadow: 0 4px 9px rgba(29, 34, 40, 0.25);
}

.point.black::after {
  background:
    radial-gradient(circle at 34% 28%, #5d6268, transparent 22%),
    linear-gradient(145deg, #30343a, #080a0d);
}

.point.white::after {
  background:
    radial-gradient(circle at 34% 28%, #ffffff 0 18%, #f7f8f8 34%, #d8dce0 100%);
  border: 1px solid rgba(29, 34, 40, 0.17);
  box-shadow:
    inset -5px -6px 10px rgba(29, 34, 40, 0.08),
    inset 4px 4px 8px rgba(255, 255, 255, 0.96),
    0 4px 9px rgba(29, 34, 40, 0.22);
}

.point.last::after {
  outline: 3px solid rgba(47, 125, 104, 0.58);
  outline-offset: 2px;
}

.point.win::after {
  outline: 3px solid #d64a3d;
  outline-offset: 2px;
}

.point:not(.stone):hover {
  background: rgba(255, 255, 255, 0.18);
}

.point:focus-visible {
  outline: 3px solid rgba(47, 125, 104, 0.75);
  outline-offset: -3px;
}

.end-overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: none;
  place-items: center;
  padding: calc(var(--cell) * 0.9);
  background: transparent;
  border-radius: 8px;
  pointer-events: none;
}

.end-overlay.visible {
  display: grid;
}

.end-panel {
  width: min(100%, 238px);
  display: grid;
  justify-items: center;
  gap: 7px;
  padding: 12px 14px;
  border: 1px solid rgba(255, 255, 255, 0.72);
  border-radius: 8px;
  background: rgba(250, 247, 241, 0.68);
  color: var(--ink);
  text-align: center;
  box-shadow: 0 14px 28px rgba(29, 34, 40, 0.18);
  pointer-events: auto;
}

.end-panel strong {
  font-size: 20px;
  font-weight: 950;
  line-height: 1.15;
}

.end-panel span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
}

.next-game-button {
  min-width: 96px;
  min-height: 36px;
  padding: 0 16px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  font-size: 16px;
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 10px 22px rgba(47, 125, 104, 0.28);
}

.next-game-button:hover {
  filter: brightness(1.05);
}

@media (max-width: 520px) {
  :root {
    --cell: clamp(16px, min(calc((100vw - 28px) / 15), calc((100dvh - 250px) / 15)), 32px);
  }

  body {
    padding: 8px;
    align-items: start;
  }

  .topbar {
    padding-top: 4px;
    align-items: flex-start;
    flex-direction: column;
  }

  .game-panel {
    padding: 0;
  }

  h1 {
    font-size: 28px;
  }

  .status {
    font-size: 13px;
  }

  .board-status {
    font-size: 15px;
    padding: 4px 8px;
  }
}

@media (min-width: 760px) {
  .games.dual {
    --cell: min(3.9vw, 34px);
  }
}

@media (max-width: 920px) {
  .games.dual {
    grid-template-columns: 1fr;
  }
}
