:root {
  color-scheme: light;
  --bg: #f7f8f6;
  --ink: #151716;
  --muted: #66706a;
  --line: #d6dcd7;
  --soft: #eef1ec;
  --board: #1f4738;
  --board-dark: #16362b;
  --accent: #245f8d;
  --capture: #b67b24;
  --danger: #a13d32;
  --disabled: #657168;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

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

body {
  background: var(--bg);
  color: var(--ink);
}

body.is-playing {
  height: 100dvh;
  overflow: hidden;
}

button,
input,
select,
textarea {
  font: inherit;
  font-size: 0.95rem;
}

button,
select,
input,
textarea {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
}

button,
select,
input {
  height: 34px;
}

button {
  padding: 0 12px;
  cursor: pointer;
  font-weight: 750;
}

button:disabled,
select:disabled,
input:disabled {
  cursor: not-allowed;
  opacity: 0.56;
}

button:hover:not(:disabled) {
  border-color: var(--accent);
}

button:focus-visible,
select:focus,
input:focus,
textarea:focus,
.pit:focus-visible {
  outline: 3px solid rgba(36, 95, 141, 0.2);
  border-color: var(--accent);
}

a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 750;
}

a:hover {
  text-decoration: underline;
}

h1,
h2,
h3,
p,
ol {
  margin: 0;
}

code,
textarea,
.move-log {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
}

.setup-page {
  width: min(980px, calc(100vw - 28px));
  margin: 0 auto;
  padding: 14px 0 28px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.wordmark {
  color: var(--ink);
  font-size: 1.2rem;
  letter-spacing: 0;
}

.top-links {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.muted-link {
  color: var(--muted);
  font-weight: 750;
}

.language-control {
  display: flex;
  align-items: center;
  gap: 7px;
}

.language-control select {
  width: auto;
  min-width: 142px;
  font-size: 0.95rem;
}

.language-control span,
.setup-form label > span,
.time-control em {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 850;
  text-transform: uppercase;
}

.setup-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 28px;
  padding: 26px 0;
  border-bottom: 1px solid var(--line);
}

.setup-form {
  display: grid;
  gap: 12px;
}

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

.setup-form label {
  min-width: 0;
  display: grid;
  gap: 5px;
}

select,
input {
  width: 100%;
  padding: 0 9px;
}

textarea {
  width: 100%;
  min-height: 72px;
  resize: vertical;
  padding: 8px 9px;
  line-height: 1.35;
}

.time-control em {
  display: none;
  align-items: center;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--soft);
  padding: 0 9px;
  font-style: normal;
}

.time-control.is-timeless input {
  display: none;
}

.time-control.is-timeless em {
  display: flex;
}

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

.primary-button {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
}

.engine-status {
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.3;
}

.engine-status:empty {
  display: none;
}

.engine-status.error {
  color: var(--danger);
}

.instructions {
  display: grid;
  align-content: start;
  gap: 12px;
}

.instructions h1 {
  font-size: clamp(1.65rem, 4vw, 2.8rem);
  line-height: 1.02;
  letter-spacing: 0;
}

.instructions p,
.instructions li,
.format-notes p {
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.45;
}

.instructions ol {
  display: grid;
  gap: 6px;
  padding-left: 20px;
}

.format-notes {
  padding-top: 22px;
  display: grid;
  gap: 14px;
}

.format-notes h2 {
  font-size: 1.05rem;
}

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

.format-grid article {
  display: grid;
  gap: 8px;
  min-width: 0;
}

.format-grid h3 {
  font-size: 0.9rem;
}

.format-grid code {
  display: block;
  overflow: auto;
  white-space: nowrap;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  padding: 8px;
  font-size: 0.8rem;
}

.game-page {
  width: 100vw;
  height: 100dvh;
  padding: 8px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 230px;
  gap: 8px;
  align-items: stretch;
}

.board-zone,
.moves-zone {
  min-width: 0;
  min-height: 0;
}

.board-zone {
  position: relative;
  display: grid;
  grid-template-rows: 32px minmax(0, 1fr);
  align-self: stretch;
  gap: 6px;
}

.scoreline {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  font-size: 0.86rem;
  color: var(--muted);
}

.scoreline > span:nth-child(2) {
  color: var(--ink);
  font-weight: 850;
}

.game-over .scoreline > span:nth-child(2) {
  color: var(--danger);
  font-weight: 950;
}

.scoreline > span:last-child {
  text-align: right;
}

.scoreline strong {
  color: var(--ink);
  font-size: 1rem;
}

.board {
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  border-radius: 6px;
  background: linear-gradient(145deg, var(--board), var(--board-dark));
  border: 1px solid #102820;
  padding: 8px;
  display: grid;
  grid-template-rows: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.game-over .board {
  border-color: var(--danger);
  box-shadow: inset 0 0 0 2px rgba(161, 61, 50, 0.28);
}

.game-end {
  position: absolute;
  left: 50%;
  top: 46px;
  z-index: 2;
  transform: translateX(-50%);
  max-width: min(460px, calc(100% - 24px));
  border: 1px solid rgba(161, 61, 50, 0.4);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.96);
  color: var(--danger);
  padding: 8px 12px;
  text-align: center;
  font-size: 0.92rem;
  font-weight: 900;
}

.pit-row {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(9, minmax(0, 1fr));
  gap: 6px;
}

.pit {
  position: relative;
  height: auto;
  min-width: 0;
  min-height: 0;
  border-color: rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  display: grid;
  grid-template-rows: 22px 1fr 26px;
  gap: 3px;
  padding: 6px;
  overflow: hidden;
}

.pit.black {
  background: rgba(0, 0, 0, 0.12);
}

.pit.legal-human {
  border-color: var(--capture);
  box-shadow: inset 0 0 0 2px rgba(182, 123, 36, 0.5);
}

.pit.legal-human:hover {
  background: rgba(182, 123, 36, 0.22);
}

.pit:disabled:not(.tuzdyk-cell) {
  opacity: 0.92;
}

.pit-label {
  justify-self: start;
  width: 22px;
  height: 22px;
  border-radius: 999px;
  display: inline-grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.18);
  font-size: 0.72rem;
  font-weight: 900;
}

.stone-field {
  align-self: center;
  justify-self: center;
  width: min(78px, 100%);
  display: grid;
  grid-template-columns: repeat(6, minmax(5px, 1fr));
  gap: 4px;
  place-items: center;
}

.stone {
  width: clamp(6px, 0.82vw, 12px);
  aspect-ratio: 1;
  border-radius: 50%;
  background: #eee8d3;
  box-shadow: inset -2px -2px 4px rgba(0, 0, 0, 0.18);
}

.black .stone {
  background: #1d2421;
  box-shadow: inset 2px 2px 4px rgba(255, 255, 255, 0.12);
}

.pit-count {
  justify-self: end;
  align-self: end;
  font-size: clamp(0.95rem, 1.35vw, 1.25rem);
  font-weight: 900;
  line-height: 1;
}

.tuzdyk-cell {
  background:
    repeating-linear-gradient(135deg, rgba(255, 255, 255, 0.14) 0 7px, rgba(255, 255, 255, 0.04) 7px 14px),
    var(--disabled);
  color: rgba(255, 255, 255, 0.58);
  opacity: 0.72;
}

.tuzdyk-cell .pit-label {
  background: rgba(0, 0, 0, 0.18);
}

.moves-zone {
  align-self: stretch;
  border-left: 1px solid var(--line);
  padding-left: 8px;
  display: grid;
  grid-template-rows: 34px minmax(0, 1fr);
  gap: 6px;
}

.move-tools {
  display: flex;
  gap: 6px;
  align-items: center;
}

.move-tools button {
  min-width: 34px;
  padding: 0 9px;
}

.move-tools .analysis-link-button {
  min-width: 90px;
}

.move-tools svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.move-log {
  min-height: 0;
  margin: 0;
  padding: 0;
  overflow: auto;
  list-style: none;
  font-size: 0.9rem;
  line-height: 1.28;
}

.move-row {
  display: grid;
  grid-template-columns: 36px 1fr 1fr;
  gap: 5px;
  padding: 4px 0;
  border-bottom: 1px solid rgba(214, 220, 215, 0.75);
}

.move-number {
  color: var(--muted);
}

.move-code {
  color: var(--ink);
  font-weight: 850;
}

@media (max-width: 820px) {
  .setup-page {
    width: min(100% - 18px, 680px);
    padding-top: 10px;
  }

  .topbar,
  .setup-layout,
  .format-grid {
    grid-template-columns: 1fr;
  }

  .topbar {
    align-items: flex-start;
  }

  .setup-layout {
    display: grid;
    gap: 18px;
    padding: 18px 0;
  }

  .instructions {
    order: -1;
  }

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

  .game-page {
    padding: 6px;
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr) 150px;
    gap: 6px;
  }

  .board-zone {
    grid-template-rows: 28px minmax(0, 1fr);
  }

  .moves-zone {
    border-left: 0;
    border-top: 1px solid var(--line);
    padding-left: 0;
    padding-top: 6px;
    grid-template-columns: 92px minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr);
  }

  .move-tools {
    align-content: start;
    align-items: start;
    flex-wrap: wrap;
  }

  .board {
    padding: 6px;
    gap: 6px;
  }

  .pit-row {
    gap: 4px;
  }

  .pit {
    grid-template-rows: 19px 1fr 22px;
    gap: 2px;
    padding: 4px;
  }

  .pit-label {
    width: 19px;
    height: 19px;
    font-size: 0.64rem;
  }

  .stone-field {
    width: 27px;
    grid-template-columns: repeat(3, minmax(4px, 1fr));
    gap: 2px;
  }

  .stone {
    width: 6px;
  }

  .stone:nth-child(n + 10) {
    display: none;
  }

  .pit-count {
    font-size: 0.82rem;
  }
}

@media (max-width: 520px) {
  .topbar {
    display: grid;
  }

  .top-links {
    gap: 9px;
  }

  .instructions h1 {
    font-size: 1.8rem;
  }

  .scoreline {
    font-size: 0.75rem;
  }

  .game-page {
    grid-template-rows: minmax(0, 1fr) 135px;
  }
}
