:root {
  color-scheme: dark;
  --bg: #080907;
  --panel: #11170f;
  --panel-soft: #192012;
  --ink: #f6f1e4;
  --muted: #aaa792;
  --line: #33402b;
  --acid: #b6f44f;
  --hot: #ff7042;
  --cool: #7ec7d8;
  --warn: #ffd15c;
  --bad: #ff5268;
  --wood: #5e3b21;
  --wood-dark: #24150d;
  --wood-light: #a36c35;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  background:
    linear-gradient(180deg, rgba(8, 9, 7, 0.74), var(--bg)),
    radial-gradient(circle at 18% 12%, rgba(182, 244, 79, 0.16), transparent 28%),
    radial-gradient(circle at 82% 10%, rgba(126, 199, 216, 0.14), transparent 30%),
    var(--bg);
  color: var(--ink);
  font-family:
    "Trebuchet MS", "Gill Sans", Avenir, ui-sans-serif, system-ui, sans-serif;
  letter-spacing: 0;
}

button {
  border: 1px solid var(--line);
  background: var(--panel-soft);
  color: var(--ink);
  cursor: pointer;
  font: inherit;
}

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

button:disabled {
  cursor: default;
  opacity: 0.5;
}

.app-shell {
  width: min(1180px, calc(100% - 28px));
  margin: 0 auto;
  padding: 24px 0 36px;
}

.topbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 18px;
  margin-bottom: 24px;
}

.studio-link {
  color: var(--muted);
  font-size: 14px;
  font-weight: 900;
  text-decoration: none;
}

.studio-link:hover {
  color: var(--ink);
}

.game-title {
  text-align: center;
}

.game-title p,
.stats span {
  margin: 0 0 6px;
  color: var(--acid);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(42px, 7.5vw, 88px);
  line-height: 0.86;
}

.top-actions {
  display: flex;
  flex-wrap: wrap;
  justify-self: end;
  justify-content: flex-end;
  gap: 8px;
}

.audio-button,
.settings-button,
.how-button,
.new-button {
  min-width: 72px;
  min-height: 42px;
  padding: 0 14px;
  font-weight: 900;
}

.audio-button.on {
  border-color: rgba(126, 199, 216, 0.74);
  background: rgba(126, 199, 216, 0.18);
  color: #d9f8fb;
}

.game-layout {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 24px;
  align-items: start;
}

.side-panel {
  position: sticky;
  top: 18px;
  border: 1px solid var(--line);
  background: rgba(17, 23, 15, 0.94);
  padding: 18px;
}

.stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}

.stats div {
  min-height: 72px;
  padding: 12px;
  border: 1px solid var(--line);
  background: #10150d;
}

.stats strong {
  display: block;
  max-width: 100%;
  overflow: hidden;
  font-size: clamp(18px, 2.5vw, 24px);
  font-variant-numeric: tabular-nums;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mode-group {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}

.segment,
.actions button {
  min-height: 42px;
  font-weight: 900;
}

.segment.active {
  border-color: rgba(182, 244, 79, 0.72);
  background: rgba(182, 244, 79, 0.18);
  color: #eaffc8;
}

.brief-panel {
  min-height: 116px;
  margin-bottom: 14px;
  padding: 12px;
  border: 1px solid rgba(255, 112, 66, 0.45);
  background:
    linear-gradient(135deg, rgba(255, 112, 66, 0.16), transparent 54%),
    #10150d;
  color: #f8d8c7;
  line-height: 1.4;
}

.actions {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.board-wrap {
  display: grid;
  gap: 16px;
}

.mancala-board {
  display: grid;
  grid-template-columns: minmax(76px, 0.48fr) repeat(6, minmax(72px, 1fr)) minmax(76px, 0.48fr);
  grid-template-rows: repeat(2, minmax(132px, auto));
  gap: clamp(8px, 1.8vw, 16px);
  min-height: 360px;
  padding: clamp(14px, 2.2vw, 26px);
  border: 3px solid var(--ink);
  background:
    linear-gradient(135deg, rgba(255, 209, 92, 0.12), transparent 42%),
    linear-gradient(180deg, var(--wood-light), var(--wood) 42%, var(--wood-dark));
  box-shadow:
    inset 0 2px rgba(246, 241, 228, 0.22),
    inset 0 -22px rgba(0, 0, 0, 0.18);
}

.pit-row {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: clamp(8px, 1.4vw, 14px);
  grid-column: 2 / 8;
}

.pit-row-north {
  grid-row: 1;
}

.pit-row-south {
  grid-row: 2;
}

.pit,
.store {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  border: 2px solid rgba(246, 241, 228, 0.18);
  background:
    radial-gradient(circle at 50% 42%, rgba(0, 0, 0, 0.38), rgba(0, 0, 0, 0.12) 58%, transparent 60%),
    linear-gradient(180deg, rgba(0, 0, 0, 0.36), rgba(255, 255, 255, 0.05));
  box-shadow:
    inset 0 12px 30px rgba(0, 0, 0, 0.44),
    inset 0 -7px rgba(255, 255, 255, 0.05),
    0 8px 18px rgba(0, 0, 0, 0.16);
}

.pit {
  aspect-ratio: 1 / 1;
  border-radius: 50%;
}

.pit.legal {
  border-color: rgba(182, 244, 79, 0.74);
}

.pit.last,
.store.last {
  border-color: rgba(255, 209, 92, 0.9);
  box-shadow:
    inset 0 12px 30px rgba(0, 0, 0, 0.44),
    0 0 0 3px rgba(255, 209, 92, 0.38),
    0 18px 34px rgba(255, 209, 92, 0.16);
}

.pit.captured {
  border-color: rgba(255, 82, 104, 0.92);
  box-shadow:
    inset 0 12px 30px rgba(0, 0, 0, 0.44),
    0 0 0 3px rgba(255, 82, 104, 0.34),
    0 18px 34px rgba(255, 82, 104, 0.14);
}

.pit.hinted {
  box-shadow:
    inset 0 12px 30px rgba(0, 0, 0, 0.44),
    0 0 0 3px rgba(255, 209, 92, 0.8),
    0 12px 30px rgba(255, 209, 92, 0.2);
}

.pit:disabled {
  opacity: 0.86;
}

.store {
  grid-row: 1 / 3;
  min-height: 100%;
  border-radius: 999px;
}

.store-north {
  grid-column: 1;
}

.store-south {
  grid-column: 8;
}

.pit-count,
.store-count {
  position: absolute;
  inset: auto 8px 8px auto;
  z-index: 2;
  display: inline-grid;
  place-items: center;
  min-width: 28px;
  height: 28px;
  padding: 0 7px;
  border: 1px solid rgba(246, 241, 228, 0.18);
  border-radius: 999px;
  background: rgba(8, 9, 7, 0.72);
  color: var(--ink);
  font-size: 13px;
  font-weight: 950;
  font-variant-numeric: tabular-nums;
}

.stones {
  position: absolute;
  inset: 14%;
}

.stone {
  position: absolute;
  width: clamp(13px, 1.8vw, 20px);
  height: clamp(13px, 1.8vw, 20px);
  border: 1px solid rgba(8, 9, 7, 0.34);
  border-radius: 50%;
  background: var(--stone-color, var(--warn));
  box-shadow:
    inset -3px -4px rgba(0, 0, 0, 0.2),
    inset 2px 2px rgba(255, 255, 255, 0.34),
    0 3px 6px rgba(0, 0, 0, 0.28);
}

.capture-strip {
  min-height: 50px;
  padding: 14px;
  border: 1px solid var(--line);
  background: rgba(17, 23, 15, 0.9);
  color: var(--muted);
  font-weight: 850;
  line-height: 1.35;
}

@media (min-width: 1500px) {
  .app-shell {
    width: min(1760px, calc(100% - 64px));
  }

  .game-layout {
    grid-template-columns: 340px minmax(0, 1fr);
    gap: 32px;
  }

  .mancala-board,
  .capture-strip {
    width: min(100%, 1320px);
    justify-self: center;
  }

  .mancala-board {
    grid-template-rows: repeat(2, minmax(170px, auto));
    min-height: 460px;
  }

  .stone {
    width: clamp(16px, 0.72vw, 26px);
    height: clamp(16px, 0.72vw, 26px);
  }
}

@media (min-width: 2600px) and (min-height: 1400px) {
  .app-shell {
    width: min(2240px, calc(100% - 96px));
  }

  .game-layout {
    grid-template-columns: 380px minmax(0, 1fr);
    gap: 40px;
  }

  .mancala-board,
  .capture-strip {
    width: min(100%, 1500px);
  }

  .mancala-board {
    grid-template-rows: repeat(2, minmax(205px, auto));
    min-height: 560px;
  }

  .stone {
    width: clamp(18px, 0.6vw, 30px);
    height: clamp(18px, 0.6vw, 30px);
  }
}

.result-dialog,
.settings-dialog {
  width: min(430px, calc(100% - 28px));
  border: 1px solid var(--acid);
  background: var(--panel);
  color: var(--ink);
  padding: 24px;
}

.settings-dialog {
  width: min(520px, calc(100% - 28px));
}

.result-dialog:not([open]),
.settings-dialog:not([open]) {
  display: none;
}

.result-dialog[open],
.settings-dialog[open] {
  display: block;
  position: fixed;
  inset: 50% auto auto 50%;
  z-index: 40;
  max-height: calc(100vh - 28px);
  overflow: auto;
  transform: translate(-50%, -50%);
}

.result-dialog::backdrop,
.settings-dialog::backdrop {
  background: rgba(0, 0, 0, 0.72);
}

.result-dialog h2,
.settings-dialog h2 {
  margin-bottom: 10px;
  font-size: 32px;
}

.result-dialog p,
.settings-dialog p {
  color: var(--muted);
  line-height: 1.5;
}

.result-score {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 18px 0;
}

.result-score div,
.setting-row {
  padding: 12px;
  border: 1px solid var(--line);
  background: #10150d;
}

.result-score span,
.setting-row label {
  display: block;
  margin-bottom: 5px;
  color: var(--acid);
  font-size: 11px;
  font-weight: 950;
  text-transform: uppercase;
}

.result-score strong {
  display: block;
  font-size: 28px;
  font-variant-numeric: tabular-nums;
}

.result-note {
  min-height: 46px;
  padding: 12px;
  border: 1px solid rgba(255, 112, 66, 0.42);
  background: rgba(255, 112, 66, 0.12);
  color: #f8d8c7 !important;
}

.setting-row {
  display: grid;
  grid-template-columns: 80px minmax(0, 1fr) 58px;
  align-items: center;
  gap: 12px;
  min-height: 58px;
  margin-bottom: 12px;
}

.setting-row label {
  margin: 0;
}

.setting-row input {
  width: 100%;
  accent-color: var(--acid);
}

.setting-row strong {
  font-weight: 900;
}

.result-dialog button,
.settings-dialog button {
  width: 100%;
  min-height: 46px;
  background: var(--acid);
  color: #101608;
  font-weight: 900;
}

@media (max-width: 900px) {
  .topbar {
    grid-template-columns: 1fr auto;
    gap: 12px;
    margin-bottom: 16px;
  }

  .game-title {
    grid-column: 1 / -1;
    grid-row: 1;
    text-align: left;
  }

  .studio-link,
  .top-actions {
    grid-row: 2;
  }

  .top-actions {
    width: 100%;
  }

  .top-actions button {
    flex: 1 1 112px;
    min-width: 0;
    padding: 0 10px;
  }

  .game-layout {
    grid-template-columns: 1fr;
    gap: 16px;
  }

  .side-panel {
    position: static;
    order: 2;
  }

  .board-wrap {
    order: 1;
  }
}

@media (max-width: 680px) {
  .app-shell {
    width: min(100% - 16px, 1180px);
    padding-top: 12px;
  }

  h1 {
    font-size: clamp(38px, 14vw, 58px);
  }

  .mancala-board {
    grid-template-columns: repeat(6, minmax(44px, 1fr));
    grid-template-rows: 74px repeat(2, minmax(62px, auto)) 74px;
    gap: 8px;
    min-height: 0;
    padding: 10px;
  }

  .store {
    min-height: 72px;
    border-radius: 28px;
  }

  .store-north {
    grid-column: 1 / 7;
    grid-row: 1;
  }

  .store-south {
    grid-column: 1 / 7;
    grid-row: 4;
  }

  .pit-row {
    grid-column: 1 / 7;
    gap: 7px;
  }

  .pit-row-north {
    grid-row: 2;
  }

  .pit-row-south {
    grid-row: 3;
  }

  .pit-count,
  .store-count {
    inset: auto 4px 4px auto;
    min-width: 23px;
    height: 23px;
    font-size: 12px;
  }

  .stats {
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
  }

  .stats div {
    min-height: 58px;
    padding: 8px;
  }

  .stats span {
    font-size: 10px;
  }

  .stats strong {
    font-size: 17px;
  }
}
