:root {
  --bg: #122318;
  --panel: #1c3324;
  --ink: #f4f1e6;
  --muted: #c5d6c8;
  --accent: #e8c56b;
  --unused: #2f9e57;
  --used1: #3b7ec4;
  --locked: #2b2d31;
  --legal: rgba(255, 236, 130, 0.92);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", "Hiragino Sans", "Noto Sans JP", sans-serif;
  touch-action: manipulation;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

body {
  min-height: 100dvh;
}

.hidden {
  display: none !important;
}

#app {
  min-height: 100dvh;
  min-height: 100svh;
  padding: calc(12px + env(safe-area-inset-top)) 12px
    calc(12px + env(safe-area-inset-bottom));
}

h1,
h2,
p {
  margin: 0;
}

button {
  font: inherit;
  cursor: pointer;
}

.screen {
  max-width: 720px;
  margin: 0 auto;
}

.panel {
  background: var(--panel);
  border-radius: 18px;
  padding: 22px 18px 20px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.28);
}

.eyebrow {
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.08em;
}

.title-screen h1 {
  margin-top: 6px;
  font-size: clamp(28px, 7vw, 40px);
}

.lead {
  margin-top: 8px;
  color: var(--muted);
  line-height: 1.5;
}

.block {
  margin-top: 22px;
}

.block h2 {
  font-size: 14px;
  margin-bottom: 8px;
}

.choices {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.choices.sizes {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

.choices.sizes .choice {
  padding: 12px 6px;
  min-width: 0;
}

.choice {
  border: 2px solid transparent;
  background: #244332;
  color: var(--ink);
  border-radius: 12px;
  padding: 12px 16px;
  min-height: 48px;
  min-width: 44px;
}

.choice.is-selected,
.choice.is-fixed {
  border-color: var(--accent);
  background: #2f5a3d;
}

.hint {
  margin-top: 8px;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.45;
}

.primary {
  width: 100%;
  margin-top: 22px;
  min-height: 52px;
  border: 0;
  border-radius: 14px;
  background: var(--accent);
  color: #1b1408;
  font-weight: 800;
  font-size: 18px;
}

.ghost {
  min-height: 44px;
  border: 1px solid #5d7a64;
  background: transparent;
  color: var(--ink);
  border-radius: 12px;
  padding: 8px 14px;
}

.choices.modes {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.choices.levels {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.choices.colors {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

.choices.levels .choice,
.choices.colors .choice,
.choices.modes .choice {
  min-width: 0;
  padding: 12px 8px;
  line-height: 1.3;
}

.cpu-setup {
  margin-top: 4px;
}

.game-top {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.match-roles {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px 16px;
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
}

.turn-banner.is-thinking {
  background: #2a3d30;
  color: var(--accent);
}

.board.is-cpu-turn {
  pointer-events: none;
}

.primary.rematch {
  margin-top: 10px;
  min-height: 48px;
  font-size: 16px;
}

.scores {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  font-weight: 700;
}

.score-b::before,
.score-w::before {
  content: "";
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: -1px;
}

.score-b::before {
  background: #111;
  box-shadow: 0 0 0 2px #eee;
}

.score-w::before {
  background: #f4f4f4;
  box-shadow: 0 0 0 2px #222;
}

.turn-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin: 0 0 10px;
  min-height: 48px;
  border-radius: 14px;
  font-size: clamp(18px, 5vw, 24px);
  font-weight: 800;
  letter-spacing: 0.04em;
}

.turn-banner.is-black {
  background: #111;
  color: #fff;
  box-shadow: inset 0 0 0 2px #f3f3f3;
}

.turn-banner.is-white {
  background: #f4f4f4;
  color: #111;
  box-shadow: inset 0 0 0 2px #222;
}

.turn-banner.is-over {
  background: #2a3d30;
  color: var(--ink);
}

.turn-stone {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  flex-shrink: 0;
}

.turn-banner.is-black .turn-stone {
  background: #111;
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px #9ad0ff;
}

.turn-banner.is-white .turn-stone {
  background: #fff;
  border: 2px solid #111;
}

.meta {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 12px;
  color: var(--muted);
  margin: 6px 0 10px;
}

.board-wrap {
  width: min(96vw, calc(100dvh - 280px), 560px);
  margin: 0 auto;
}

.board-shell {
  background: #0e1c12;
  border-radius: 12px;
  padding: 6px;
}

.board {
  --size: 8;
  display: grid;
  grid-template-columns: repeat(var(--size), 1fr);
  grid-template-rows: repeat(var(--size), 1fr);
  width: 100%;
  aspect-ratio: 1;
  gap: 3px;
  padding: 0;
  background: transparent;
  border-radius: 8px;
}

.board-bar {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 10px 6px 4px;
}

.board-bar .bar-title {
  width: 100%;
  min-height: 44px;
  border-color: #5d7a64;
  color: var(--ink);
}

.result-inline {
  text-align: center;
  color: #f4f1e6;
  line-height: 1.25;
}

.result-inline p {
  margin: 0;
}

#result-headline {
  font-size: clamp(22px, 6vw, 28px);
  font-weight: 800;
}

#result-score {
  margin-top: 4px;
  font-size: clamp(20px, 5.5vw, 26px);
  font-weight: 700;
  letter-spacing: 0.08em;
}

.cell {
  position: relative;
  border: 0;
  border-radius: 4px;
  padding: 0;
  min-width: 0;
  min-height: 0;
  display: grid;
  place-items: center;
}

.cell.used-0 {
  background: var(--unused);
}

.cell.used-1 {
  background: var(--used1);
}

.cell.used-2 {
  background: var(--locked);
}

.cell.last-placed {
  outline: 2px solid #ffe27a;
  outline-offset: -2px;
}

.stone {
  width: 72%;
  height: 72%;
  border-radius: 50%;
  pointer-events: none;
}

.stone.black {
  background: radial-gradient(circle at 32% 28%, #555 0%, #111 46%, #000 100%);
  border: 2px solid #f3f3f3;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.45), 0 0 0 1px #9ad0ff;
}

.stone.white {
  background: radial-gradient(circle at 32% 28%, #fff 0%, #e8e8e8 55%, #cfcfcf 100%);
  border: 2px solid #222;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.35);
}

.cell.used-2 .stone.black {
  border-color: #fff;
  box-shadow: 0 0 0 2px #9ad0ff, 0 2px 5px rgba(0, 0, 0, 0.6);
}

.legal-mark {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: clamp(14px, 5.2vw, 30px);
  line-height: 1;
  color: #ffe27a;
  text-shadow:
    0 0 2px #000,
    0 1px 0 #000,
    1px 0 0 #000,
    -1px 0 0 #000,
    0 -1px 0 #000;
  pointer-events: none;
  z-index: 2;
}

.legend {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
  margin: 0;
  font-size: 12px;
  color: var(--muted);
}

.swatch {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 3px;
  margin-right: 4px;
  vertical-align: -1px;
}

.swatch.u0 {
  background: var(--unused);
}
.swatch.u1 {
  background: var(--used1);
}
.swatch.u2 {
  background: var(--locked);
}

#toast {
  position: fixed;
  left: 50%;
  top: calc(18px + env(safe-area-inset-top));
  transform: translateX(-50%);
  background: rgba(20, 20, 20, 0.92);
  color: #fff;
  padding: 10px 16px;
  border-radius: 12px;
  white-space: pre-line;
  text-align: center;
  z-index: 20;
  max-width: 90vw;
}

@media (max-width: 480px) {
  .board {
    gap: 2px;
  }

  .choices.sizes {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .board-8 .stone {
    width: 78%;
    height: 78%;
    border-width: 1.5px;
  }

  .choices.levels,
  .choices.modes {
    grid-template-columns: 1fr 1fr;
  }

  .choices.colors {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .choice {
    min-height: 48px;
  }
}
