:root {
  color-scheme: dark;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
  --background: #181a19;
  --surface: #232522;
  --surface-hover: #2b2d29;
  --surface-active: #30322e;
  --text: #efebe3;
  --muted: #aaa69d;
  --quiet: #85877f;
  --line: rgba(239, 235, 227, 0.11);
  --line-strong: rgba(239, 235, 227, 0.18);
  --accent: #c7a06a;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
}

body {
  min-width: 300px;
  overflow-x: hidden;
  background: var(--background);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button {
  font: inherit;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.app {
  width: 100%;
  min-height: 100svh;
  padding: clamp(18px, 3.2svh, 32px) max(18px, env(safe-area-inset-right)) clamp(18px, 3.2svh, 32px) max(18px, env(safe-area-inset-left));
  display: flex;
  align-items: center;
  justify-content: center;
}

.game-layout {
  --board-size: min(calc(100svh - 100px), 700px, calc(100vw - 304px));
  display: grid;
  grid-template-columns: var(--board-size) 208px;
  grid-template-rows: minmax(28px, auto) var(--board-size);
  grid-template-areas:
    "brand turn"
    "board controls";
  gap: 12px 24px;
  align-items: stretch;
}

.brand {
  grid-area: brand;
  min-width: 0;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 0.96rem;
  font-weight: 680;
  line-height: 1;
  letter-spacing: -0.01em;
}

.brand-size {
  color: var(--muted);
  font-size: 0.82em;
  font-weight: 560;
  letter-spacing: 0.025em;
}

.brand-mark {
  position: relative;
  width: 23px;
  height: 15px;
  margin-right: 1px;
  display: inline-block;
}

.brand-mark-stone {
  position: absolute;
  top: 1px;
  width: 13px;
  height: 13px;
  border-radius: 50%;
}

.brand-mark-stone.black {
  left: 0;
  z-index: 1;
  background: radial-gradient(circle at 35% 30%, #30332f, #20231f 62%, #121513);
  border: 1px solid #3a3c38;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.55);
}

.brand-mark-stone.white {
  right: 0;
  background: radial-gradient(circle at 35% 30%, #eee8de, #ded5c9 68%, #c8bdaf);
  border: 1px solid #bcb5a9;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.42);
}

.turn-state {
  grid-area: turn;
  min-width: 0;
  padding-left: 22px;
  border-left: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 9px;
}

.turn-stone {
  flex: 0 0 auto;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #30332f, #20231f 62%, #121513);
  border: 1px solid #343631;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
  transition:
    background-color 100ms ease,
    border-color 100ms ease,
    box-shadow 100ms ease;
}

.turn-state[data-turn="white"] .turn-stone {
  background: radial-gradient(circle at 35% 30%, #eee8de, #ded5c9 68%, #c8bdaf);
  border-color: #bcb3a6;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.38);
}

.turn-state[data-turn="white"] #status {
  color: var(--quiet);
}

.turn-state[data-turn="finished"] .turn-stone {
  background: var(--accent);
  border-color: rgba(255, 236, 204, 0.42);
  box-shadow: 0 0 0 3px rgba(199, 160, 106, 0.09);
}

#status {
  min-width: 0;
  margin: 0;
  color: var(--muted);
  font-size: 0.79rem;
  font-weight: 500;
  line-height: 1.35;
  letter-spacing: 0.005em;
  font-variant-numeric: tabular-nums;
}

.board-shell {
  grid-area: board;
  position: relative;
  width: var(--board-size);
  height: var(--board-size);
  min-width: 0;
  overflow: hidden;
  border: 0;
  border-radius: 6px;
  background: #c99b5d;
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.04) inset,
    0 2px 4px rgba(0, 0, 0, 0.2),
    0 18px 42px rgba(0, 0, 0, 0.27);
}

#board {
  display: block;
  width: 100%;
  height: 100%;
  max-width: 100%;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

#board.is-disabled {
  cursor: default;
}

#board:focus-visible {
  outline: 2px solid rgba(231, 196, 141, 0.9);
  outline-offset: -4px;
}

.controls {
  grid-area: controls;
  min-width: 0;
  height: 100%;
  padding: 15px 0 0 22px;
  border-left: 1px solid var(--line);
  display: flex;
  flex-direction: column;
}

.captures {
  color: var(--muted);
  font-size: 0.79rem;
}

.captures-title {
  margin: 0 0 10px;
  color: var(--quiet);
  font-size: 0.66rem;
  font-weight: 720;
  line-height: 1;
  letter-spacing: 0.105em;
  text-transform: uppercase;
}

.capture-row {
  min-height: 38px;
  display: grid;
  grid-template-columns: 18px 1fr auto;
  align-items: center;
  gap: 9px;
  border-bottom: 1px solid var(--line);
}

.capture-name {
  color: var(--muted);
  font-weight: 500;
}

.capture-row output {
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 620;
  font-variant-numeric: tabular-nums;
}

.mini-stone {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.55);
}

.mini-stone.black {
  background: radial-gradient(circle at 35% 30%, #30332f, #20231f 62%, #121513);
  border: 1px solid #363833;
}

.mini-stone.white {
  background: radial-gradient(circle at 35% 30%, #eee8de, #ded5c9 68%, #c8bdaf);
  border: 1px solid #bcb5a9;
}

.action-stack {
  margin-top: auto;
  display: grid;
  gap: 9px;
}

.action {
  width: 100%;
  min-height: 46px;
  padding: 10px 14px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.025) inset;
  cursor: pointer;
  font-size: 0.84rem;
  font-weight: 650;
  line-height: 1.2;
  letter-spacing: 0.005em;
  transition:
    background-color 90ms ease,
    border-color 90ms ease,
    color 90ms ease,
    transform 80ms ease;
}

.action:hover:not(:disabled) {
  background: var(--surface-hover);
}

.action:active:not(:disabled) {
  transform: translateY(1px);
  background: var(--surface-active);
}

.action:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.action:disabled {
  cursor: default;
  opacity: 0.42;
}

.action.secondary {
  border-color: var(--line-strong);
  background: transparent;
  color: var(--muted);
  box-shadow: none;
}

.action.secondary:hover:not(:disabled) {
  border-color: rgba(239, 235, 227, 0.28);
  background: rgba(255, 255, 255, 0.025);
  color: var(--text);
}

@media (max-width: 880px), (orientation: portrait) and (max-width: 1100px) {
  .app {
    min-height: 100svh;
    padding:
      max(12px, env(safe-area-inset-top))
      max(12px, env(safe-area-inset-right))
      max(16px, env(safe-area-inset-bottom))
      max(12px, env(safe-area-inset-left));
    align-items: flex-start;
  }

  .game-layout {
    --board-size: min(100%, 720px);
    width: min(100%, 720px);
    margin: 0 auto;
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-rows: minmax(24px, auto) auto auto;
    grid-template-areas:
      "brand turn"
      "board board"
      "controls controls";
    gap: 9px 12px;
  }

  .brand {
    font-size: 0.91rem;
  }

  .brand-mark {
    width: 21px;
    height: 14px;
  }

  .brand-mark-stone {
    width: 12px;
    height: 12px;
  }

  .turn-state {
    justify-self: end;
    padding: 0;
    border: 0;
    gap: 7px;
  }

  .turn-stone {
    width: 9px;
    height: 9px;
  }

  #status {
    font-size: 0.76rem;
    text-align: right;
  }

  .board-shell {
    justify-self: center;
    width: var(--board-size);
    height: auto;
    aspect-ratio: 1;
    border-radius: 5px;
    box-shadow:
      0 1px 0 rgba(255, 255, 255, 0.035) inset,
      0 2px 3px rgba(0, 0, 0, 0.18),
      0 12px 28px rgba(0, 0, 0, 0.22);
  }

  .controls {
    justify-self: center;
    width: var(--board-size);
    height: auto;
    padding: 0;
    border: 0;
    display: grid;
    grid-template-columns: 1fr;
    gap: 9px;
  }

  .captures {
    display: grid;
    grid-template-columns: auto 1fr 1fr;
    align-items: center;
    gap: 12px;
    padding: 1px 2px 8px;
    border-bottom: 1px solid var(--line);
  }

  .captures-title {
    margin: 0;
  }

  .capture-row {
    min-height: 27px;
    grid-template-columns: 17px auto auto;
    justify-content: end;
    gap: 7px;
    border: 0;
  }

  .capture-row output {
    min-width: 1ch;
    margin-left: 2px;
  }

  .action-stack {
    margin: 0;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 9px;
  }

  .action {
    min-height: 46px;
    white-space: nowrap;
  }
}

@media (max-width: 430px) {
  .app {
    padding-left: max(10px, env(safe-area-inset-left));
    padding-right: max(10px, env(safe-area-inset-right));
  }

  .game-layout {
    gap: 8px 8px;
  }

  .brand {
    gap: 6px;
    font-size: 0.88rem;
  }

  .brand-mark {
    width: 20px;
  }

  #status {
    font-size: 0.73rem;
  }

  .captures {
    gap: 8px;
    padding-bottom: 7px;
  }

  .captures-title {
    font-size: 0.62rem;
  }

  .capture-row {
    grid-template-columns: 16px auto auto;
    gap: 6px;
    font-size: 0.75rem;
  }

  .mini-stone {
    width: 15px;
    height: 15px;
  }

  .action {
    min-height: 45px;
    padding-inline: 7px;
    font-size: 0.81rem;
  }
}

@media (max-height: 520px) and (min-width: 600px),
  (orientation: landscape) and (min-width: 500px) and (max-width: 880px) {
  .app {
    min-height: 100svh;
    padding:
      max(10px, env(safe-area-inset-top))
      max(16px, env(safe-area-inset-right))
      max(10px, env(safe-area-inset-bottom))
      max(16px, env(safe-area-inset-left));
    align-items: center;
  }

  .game-layout {
    --board-size: min(calc(100svh - 54px), 620px, calc(100vw - 270px));
    width: auto;
    margin: 0;
    grid-template-columns: var(--board-size) 190px;
    grid-template-rows: minmax(24px, auto) var(--board-size);
    grid-template-areas:
      "brand turn"
      "board controls";
    gap: 8px 20px;
  }

  .turn-state {
    justify-self: stretch;
    padding-left: 18px;
    border-left: 1px solid var(--line);
  }

  .board-shell {
    width: var(--board-size);
    height: var(--board-size);
  }

  .controls {
    width: auto;
    height: 100%;
    padding: 10px 0 0 18px;
    border-left: 1px solid var(--line);
    display: flex;
  }

  .captures {
    display: block;
    padding: 0;
    border: 0;
  }

  .captures-title {
    margin-bottom: 7px;
  }

  .capture-row {
    min-height: 30px;
    display: grid;
    grid-template-columns: 17px 1fr auto;
    justify-content: stretch;
    border-bottom: 1px solid var(--line);
  }

  .action-stack {
    margin-top: auto;
    display: grid;
    grid-template-columns: 1fr;
  }

  .action {
    min-height: 44px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .action,
  .turn-stone {
    transition: none;
  }
}
