:root {
  color-scheme: dark;
  --bg: #0b1014;
  --panel: #111920;
  --panel-strong: #151f27;
  --ink: #edf4f1;
  --muted: #93a6a6;
  --line: #263844;
  --accent: #4bd6b2;
  --accent-strong: #24b994;
  --amber: #d9a14b;
  --danger: #ff7777;
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.36);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 18% 16%, rgba(75, 214, 178, 0.12), transparent 30rem),
    linear-gradient(135deg, #0b1014 0%, #10171c 52%, #090d10 100%);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(900px, calc(100vw - 32px));
  min-height: 100vh;
  margin: 0 auto;
  padding: 18px 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 316px;
  gap: 16px;
  align-items: start;
}

.play-area,
.side-panel {
  min-width: 0;
}

.top-bar,
.status-panel,
.panel-block {
  border: 1px solid var(--line);
  background: rgba(17, 25, 32, 0.88);
  box-shadow: var(--shadow);
}

.top-bar {
  border-radius: 8px;
  padding: 14px 16px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 16px;
}

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

.top-bar > div:first-child {
  min-width: 0;
}

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

h1,
h2 {
  margin: 0;
  line-height: 1.05;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(1.8rem, 3.2vw, 3rem);
}

h2 {
  font-size: 1.22rem;
}

.turn-chip {
  min-height: 42px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0c1419;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  color: var(--ink);
  font-weight: 800;
  white-space: nowrap;
}

.mini-stone {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: inline-block;
  flex: 0 0 auto;
  vertical-align: -3px;
}

.mini-stone.black {
  background:
    radial-gradient(circle at 36% 28%, #54626a, #050708 62%, #000 100%);
  border: 1px solid #303b42;
}

.mini-stone.white {
  background:
    radial-gradient(circle at 32% 24%, #fff, #d9e1dd 62%, #9fa9a4 100%);
  border: 1px solid #f4fbf7;
}

.board-wrap {
  margin-top: 14px;
  padding: clamp(8px, 1.4vw, 14px);
  border: 1px solid #314756;
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(217, 161, 75, 0.14), transparent 38%),
    #0f171d;
  box-shadow: var(--shadow);
}

#board {
  width: 100%;
  aspect-ratio: 1 / 1;
  display: block;
  border-radius: 6px;
  touch-action: manipulation;
}

.status-panel {
  margin-top: 14px;
  border-radius: 8px;
  padding: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.status-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.label {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

#statusText {
  margin: 0;
  color: var(--ink);
  font-weight: 700;
}

.side-panel {
  display: grid;
  gap: 14px;
  position: sticky;
  top: 18px;
}

.panel-block {
  border-radius: 8px;
  padding: 14px;
}

.panel-heading {
  margin-bottom: 16px;
}

.panel-heading.compact {
  margin-bottom: 12px;
}

.options-form {
  display: grid;
  gap: 15px;
}

fieldset {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

legend,
.field > span {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0c1318;
}

.segmented.four {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.segmented.compact {
  min-width: 218px;
  gap: 4px;
  padding: 3px;
}

.segmented label {
  min-width: 0;
}

.segmented input {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
}

.segmented span {
  min-height: 40px;
  padding: 8px 10px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--muted);
  font-weight: 800;
  text-align: center;
  white-space: nowrap;
}

.segmented.compact span {
  min-height: 36px;
  padding: 7px 9px;
}

.segmented input:checked + span {
  color: #06120f;
  background: var(--accent);
}

.segmented input:focus-visible + span {
  outline: 2px solid #f1fff9;
  outline-offset: 2px;
}

.play-choice span {
  padding-inline: 6px;
  font-size: 0.78rem;
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.field input,
.field select {
  width: 100%;
  min-height: 42px;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0c1318;
  padding: 8px 10px;
}

.toggle-field {
  min-height: 72px;
  padding-top: 1px;
  display: grid;
  align-content: end;
  gap: 8px;
}

.toggle-field > span:first-child {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.toggle-field input {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
}

.toggle-track {
  width: 74px;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0c1318;
  position: relative;
}

.toggle-track::before {
  content: "";
  position: absolute;
  top: 5px;
  left: 5px;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--muted);
  transition: transform 160ms ease, background 160ms ease;
}

.toggle-field input:checked + .toggle-track {
  border-color: var(--accent-strong);
  background: rgba(75, 214, 178, 0.18);
}

.toggle-field input:checked + .toggle-track::before {
  background: var(--accent);
  transform: translateX(32px);
}

.toggle-field input:focus-visible + .toggle-track {
  outline: 2px solid rgba(75, 214, 178, 0.48);
  outline-offset: 2px;
}

.field input:focus,
.field select:focus {
  outline: 2px solid rgba(75, 214, 178, 0.48);
  border-color: var(--accent);
}

.primary-button,
.ghost-button {
  min-height: 42px;
  border-radius: 8px;
  font-weight: 900;
}

.primary-button {
  color: #06120f;
  border: 1px solid var(--accent-strong);
  background: linear-gradient(180deg, var(--accent), var(--accent-strong));
}

.primary-button:hover {
  filter: brightness(1.06);
}

.ghost-button {
  color: var(--ink);
  border: 1px solid var(--line);
  background: #0c1318;
  padding: 0 14px;
}

.ghost-button:hover {
  border-color: var(--accent);
}

.ghost-button:disabled {
  cursor: not-allowed;
  opacity: 0.42;
}

.score-block {
  background: rgba(21, 31, 39, 0.88);
}

.score-row {
  min-height: 46px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-top: 1px solid var(--line);
}

.score-row div {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
  font-weight: 800;
}

.score-row strong {
  font-size: 1.45rem;
}

.target-note {
  margin: 10px 0 0;
  color: var(--muted);
  line-height: 1.4;
}

.rule-block {
  color: var(--muted);
  line-height: 1.5;
}

.rule-block p {
  margin: 0;
}

.rule-block p + p {
  margin-top: 10px;
}

.disabled {
  opacity: 0.48;
}

body.theme-light {
  color-scheme: light;
  --bg: #f3f0e8;
  --panel: #fffaf1;
  --panel-strong: #fff5e4;
  --ink: #172126;
  --muted: #687676;
  --line: #d4cab9;
  --accent: #087f69;
  --accent-strong: #066f5b;
  --shadow: 0 18px 48px rgba(74, 56, 30, 0.18);
  background:
    radial-gradient(circle at 18% 16%, rgba(8, 127, 105, 0.16), transparent 30rem),
    linear-gradient(135deg, #f6f2e8 0%, #efe6d5 55%, #f9f4ea 100%);
}

body.theme-light .top-bar,
body.theme-light .status-panel,
body.theme-light .panel-block {
  background: rgba(255, 250, 241, 0.92);
}

body.theme-light .turn-chip,
body.theme-light .segmented,
body.theme-light .field input,
body.theme-light .field select,
body.theme-light .ghost-button,
body.theme-light .toggle-track {
  color: var(--ink);
  background: #fff7e9;
}

body.theme-light .segmented input:checked + span,
body.theme-light .primary-button {
  color: #fff;
}

body.theme-light .board-wrap {
  border-color: #ccb784;
  background:
    linear-gradient(135deg, rgba(8, 127, 105, 0.13), transparent 38%),
    #f2e6cf;
}

@media (max-width: 920px) {
  .app-shell {
    grid-template-columns: 1fr;
    width: min(760px, calc(100vw - 24px));
    padding: 14px 0 24px;
  }

  .side-panel {
    position: static;
  }
}

@media (max-width: 560px) {
  .segmented.four {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .top-bar,
  .status-panel {
    align-items: stretch;
    display: flex;
    flex-direction: column;
  }

  .turn-chip,
  .ghost-button,
  .game-switch,
  .status-actions {
    width: 100%;
    justify-content: center;
  }

  .top-controls,
  .status-actions {
    flex-direction: column;
  }

  .segmented.compact {
    width: 100%;
  }

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