:root {
  color-scheme: dark;
  --accent: #f4c45f;
  --red: #d94b4b;
  --green: #3fb47b;
  --blue: #5b8def;
  --ink: #fff8e8;
  --muted: #d6c6a4;
  --panel: #18110dcc;
  --surface: #211712;
  --surface-2: #2d2118;
  --line: #ffffff18;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100svh;
  font-family: Inter, ui-rounded, system-ui, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 18% 8%, #f4c45f38, transparent 28%),
    radial-gradient(circle at 88% 12%, #5b8def2f, transparent 26%),
    linear-gradient(145deg, #070504, #271f18 58%, #15100c);
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

.shell {
  width: min(1280px, 100%);
  min-height: calc(100svh - 32px);
  margin: 0 auto;
  background: linear-gradient(180deg, #211711ee, #130e0bcc);
  border: 1px solid #ffffff20;
  border-radius: 20px;
  padding: clamp(14px, 2.5vw, 26px);
  box-shadow: 0 26px 90px #0009;
  backdrop-filter: blur(16px);
}

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

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: .72rem;
  font-weight: 850;
  letter-spacing: .14em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  max-width: 780px;
  font-size: clamp(2rem, 4vw, 3.35rem);
  line-height: .92;
}

.pitch {
  max-width: 680px;
  color: var(--muted);
  font-size: .92rem;
  line-height: 1.35;
  margin: 8px 0 0;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 14px 0 10px;
}

.setup-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  align-items: center;
  margin: 0 0 10px;
  padding: 7px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #ffffff08;
}

.setup-summary span,
.setup-summary strong {
  display: inline-grid;
  min-height: 30px;
  place-items: center;
  border: 1px solid #ffffff14;
  border-radius: 999px;
  padding: 5px 10px;
  color: var(--muted);
  background: #ffffff08;
  font-size: .72rem;
  font-weight: 900;
}

.setup-summary span {
  color: #18110d;
  background: var(--accent);
}

.stats div,
.panel,
.board-wrap {
  background: color-mix(in srgb, var(--surface) 88%, white 4%);
  border: 1px solid var(--line);
  border-radius: 14px;
}

.stats div { padding: 10px 14px; }
.stats span {
  display: block;
  color: var(--muted);
  font-size: .72rem;
  letter-spacing: .1em;
  text-transform: uppercase;
}
.stats strong { font-size: clamp(1.25rem, 2.4vw, 1.75rem); }

.modes,
.rule-controls {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.rule-controls {
  align-items: center;
  flex-wrap: wrap;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #ffffff08;
}

.rule-controls label {
  align-items: center;
  background: #ffffff0c;
  border: 1px solid #ffffff18;
  border-radius: 999px;
  color: var(--muted);
  display: inline-flex;
  font-size: .82rem;
  font-weight: 850;
  gap: 8px;
  min-height: 44px;
  padding: 10px 14px;
}

.rule-controls select {
  min-height: 32px;
  border: 1px solid #ffffff24;
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--ink);
  font: inherit;
  font-weight: 850;
  padding: 4px 8px;
}

.ad-preview,
.quick-guide {
  border: 1px solid #f4c45f55;
  border-radius: 14px;
  background: #f4c45f12;
}

.ad-preview {
  align-items: center;
  display: grid;
  gap: 8px 18px;
  grid-template-columns: auto auto minmax(220px, 1fr);
  margin: 12px 0;
  padding: 9px 14px;
}

.ad-preview strong,
.quick-guide strong {
  color: var(--accent);
}

.ad-preview span,
.ad-preview small,
.quick-guide li {
  color: var(--muted);
  line-height: 1.45;
}

.ad-preview small {
  font-size: .72rem;
  justify-self: end;
}

.quick-guide {
  margin: 12px 0;
  padding: 12px 14px;
}

.quick-guide ol {
  margin: 8px 0 0 18px;
  padding: 0;
}

button {
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: #18110d;
  cursor: pointer;
  font: inherit;
  font-weight: 850;
  min-height: 44px;
  padding: 11px 16px;
  transition: transform .15s ease, background .15s ease, border-color .15s ease;
}

button:active { transform: translateY(1px) scale(.99); }

.quiet,
.mode {
  background: #ffffff12;
  color: var(--ink);
  border: 1px solid #ffffff12;
}

.mode.active {
  background: var(--accent);
  color: #18110d;
}

.table {
  display: grid;
  grid-template-columns: minmax(520px, 1fr) minmax(320px, 380px);
  gap: 16px;
  align-items: start;
}

.board-wrap {
  min-height: min(72svh, 720px);
  padding: clamp(10px, 2vw, 18px);
  display: grid;
  place-items: center;
  background:
    linear-gradient(45deg, #ffffff05 25%, transparent 25% 75%, #ffffff05 75%),
    linear-gradient(45deg, #ffffff05 25%, transparent 25% 75%, #ffffff05 75%),
    #150f0c;
  background-position: 0 0, 16px 16px;
  background-size: 32px 32px;
}

.board {
  width: min(100%, 690px, 72svh);
  aspect-ratio: 1;
  display: grid;
  grid-template-columns: repeat(15, 1fr);
  grid-template-rows: repeat(15, 1fr);
  gap: clamp(2px, .35vw, 4px);
  padding: clamp(4px, .75vw, 8px);
  border: 1px solid #f4c45f25;
  border-radius: 18px;
  background: radial-gradient(circle at center, #f4c45f18, transparent 28%), #0e0907;
}

.cell {
  min-width: 0;
  border-radius: clamp(4px, .65vw, 7px);
  background: #ffffff10;
  border: 1px solid #ffffff18;
  display: grid;
  place-items: center;
  position: relative;
}

.cell.path { background: #f4c45f22; }
.cell.center {
  background: radial-gradient(circle, #fff4bd, #f4c45f 70%);
  color: #18110d;
  font-size: clamp(.52rem, 1vw, .8rem);
  font-weight: 900;
}
.cell.inactive {
  background: transparent;
  border-color: transparent;
}
.cell.home-lane {
  border-color: #ffffff24;
  background: #ffffff16;
}
.cell.home-lane.p0 { box-shadow: inset 0 0 0 2px #3fb47b66; }
.cell.home-lane.p1 { box-shadow: inset 0 0 0 2px #d94b4b66; }
.cell.home-lane.p2 { box-shadow: inset 0 0 0 2px #5b8def66; }
.cell.home-lane.p3 { box-shadow: inset 0 0 0 2px #f4c45f66; }
.cell.yard {
  background: #ffffff12;
  border-style: dashed;
}
.cell-step {
  position: absolute;
  left: 3px;
  top: 2px;
  color: #fff8e899;
  font-size: clamp(.34rem, .58vw, .48rem);
  font-weight: 900;
  letter-spacing: .03em;
  text-transform: uppercase;
}
.cell.center .cell-step { display: none; }
.cell.safe {
  border-color: #f4c45f;
  box-shadow: inset 0 0 0 2px #f4c45f55;
}
.cell.safe::after {
  content: "◆";
  position: absolute;
  top: 0;
  right: 4px;
  color: var(--accent);
  font-weight: 950;
}
.cell.blockade {
  border-color: #ffffff;
  box-shadow: inset 0 0 0 2px #fff8, 0 0 16px #f4c45f55;
}
.cell.blockade::before {
  content: "B";
  position: absolute;
  right: 3px;
  bottom: 1px;
  color: #ffffff;
  font-size: .48rem;
  font-weight: 950;
}
.token {
  width: clamp(14px, 68%, 28px);
  aspect-ratio: 1;
  border-radius: 50%;
  position: absolute;
  border: 2px solid #fff9;
  box-shadow: 0 0 18px #0008;
  color: #ffffff;
  display: grid;
  font-size: clamp(.36rem, .78vw, .62rem);
  font-weight: 950;
  line-height: 1;
  place-items: center;
  text-shadow: 0 1px 2px #0009;
}
.token.p0 { background: var(--green); }
.token.p1 { background: var(--red); }
.token.p2 { background: var(--blue); }
.token.p3 { background: #f4c45f; }
.token.t0 { transform: translate(-34%, -34%); }
.token.t1 { transform: translate(34%, -34%); }
.token.t2 { transform: translate(-34%, 34%); }
.token.t3 { transform: translate(34%, 34%); }
.token.selectable {
  outline: 3px solid #ffffff;
  outline-offset: 2px;
  box-shadow: 0 0 0 5px #f4c45f88, 0 0 22px #f4c45faa;
}
/*
.cell.player::after,
.cell.rival::before {
  content: "";
  width: 44%;
  aspect-ratio: 1;
  border-radius: 50%;
  position: absolute;
  box-shadow: 0 0 18px #0007;
}
.cell.player::after { background: var(--green); transform: translate(-18%, -18%); }
.cell.rival::before { background: var(--red); transform: translate(18%, 18%); }
*/

.kaudi-board {
  width: min(100%, 560px);
  min-height: 360px;
  border-radius: 22px;
  background:
    linear-gradient(90deg, transparent 49%, #f4c45f22 50%, transparent 51%),
    linear-gradient(0deg, transparent 49%, #f4c45f22 50%, transparent 51%),
    #120d09;
  display: grid;
  place-items: center;
  padding: 22px;
}

.kaudi-score {
  width: min(320px, 100%);
  aspect-ratio: 1;
  border: 2px solid #f4c45f66;
  border-radius: 50%;
  display: grid;
  place-items: center;
  text-align: center;
  color: var(--muted);
}

.kaudi-score strong {
  display: block;
  color: var(--accent);
  font-size: clamp(4rem, 15vw, 7rem);
  line-height: .9;
}

.panel {
  padding: 16px;
  align-self: stretch;
  position: sticky;
  top: 16px;
  max-height: calc(100svh - 48px);
  overflow: auto;
}

.panel h2 {
  margin: 0 0 10px;
  font-size: 1.2rem;
}

.panel p {
  color: var(--muted);
  font-size: .92rem;
  line-height: 1.42;
}

.shells {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 12px 0;
}

.turn-panel {
  display: grid;
  grid-template-columns: 1fr;
  gap: 4px;
  margin: 14px 0;
  padding: 12px 14px;
  border-radius: 14px;
  background: #ffffff0d;
  border: 1px solid #ffffff18;
}

.turn-panel span {
  color: var(--muted);
  font-size: .75rem;
  font-weight: 850;
  letter-spacing: .1em;
  text-transform: uppercase;
}

.turn-panel b { color: var(--accent); }

.board-legend,
.player-status {
  display: grid;
  gap: 8px;
  margin: 12px 0;
}

.board-legend {
  grid-template-columns: 1fr 1fr;
  border: 1px solid #ffffff18;
  border-radius: 14px;
  background: #ffffff0a;
  padding: 8px;
}

.board-legend span,
.player-row {
  align-items: center;
  color: var(--muted);
  display: flex;
  font-size: .78rem;
  font-weight: 800;
  gap: 7px;
}

.legend-token,
.player-row i {
  width: 14px;
  aspect-ratio: 1;
  border-radius: 50%;
  display: inline-block;
  border: 1px solid #fff8;
}

.legend-token.p0,
.player-row.p0 i { background: var(--green); }
.legend-token.p1,
.player-row.p1 i { background: var(--red); }
.legend-token.p2,
.player-row.p2 i { background: var(--blue); }
.legend-token.p3,
.player-row.p3 i { background: #f4c45f; }

.legend-safe,
.legend-last,
.legend-blockade {
  width: 16px;
  height: 16px;
  border-radius: 5px;
  display: inline-block;
}
.legend-safe {
  border: 2px solid var(--accent);
  background: #f4c45f18;
}
.legend-last {
  outline: 3px solid var(--accent);
  outline-offset: -3px;
  background: #ffffff12;
}
.legend-blockade {
  border: 2px solid #fff;
  background: #f4c45f33;
}

.player-row {
  display: grid;
  grid-template-columns: 1.35fr repeat(6, auto);
  justify-content: stretch;
  border: 1px solid #ffffff14;
  border-radius: 12px;
  background: #ffffff08;
  padding: 8px;
}
.player-row.current {
  border-color: #f4c45f88;
  background: #f4c45f15;
}
.player-row span {
  align-items: center;
  color: var(--ink);
  display: flex;
  gap: 7px;
  min-width: 0;
}
.player-row b {
  color: var(--muted);
  font-size: .72rem;
}

.piece-actions {
  display: grid;
  gap: 8px;
  margin: 10px 0;
}

.piece-actions button {
  width: 100%;
  border-radius: 14px;
  background: #ffffff12;
  color: var(--ink);
}

.piece-actions button.best {
  background: var(--accent);
  color: #18110d;
}

.piece-actions button.locked {
  border-color: #ffffff18;
  background: #ffffff08;
  color: var(--muted);
  cursor: not-allowed;
}

.piece-actions button.locked::after {
  content: attr(title);
  display: block;
  font-size: .72rem;
  font-weight: 750;
  line-height: 1.25;
  margin-top: 4px;
  white-space: normal;
}

.cowrie {
  aspect-ratio: 1;
  border-radius: 50% 45% 50% 42%;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #fff7da, #c89a56);
  color: #3a2314;
  font-size: 1.6rem;
  font-weight: 900;
  transform: rotate(var(--turn));
  box-shadow: inset -8px -8px 16px #5b351f44, 0 8px 18px #0007;
}
.cowrie.roll {
  animation: shellRoll .42s ease;
}

.cowrie.closed {
  background: linear-gradient(135deg, #9d6a38, #3d2617);
  color: #f4c45f;
}
.cowrie.pasa {
  aspect-ratio: 2.4 / 1;
  border-radius: 12px;
  grid-column: 1 / -1;
}

footer {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  color: var(--muted);
  font-size: .84rem;
  margin-top: 26px;
}

a {
  color: var(--accent);
  text-decoration: none;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
}

dialog {
  max-width: 460px;
  border: 1px solid #ffffff20;
  border-radius: 20px;
  background: #18110d;
  color: var(--ink);
  padding: 26px;
  box-shadow: 0 30px 100px #000;
}
dialog::backdrop { background: #030201dd; }
.rules-table {
  width: 100%;
  border-collapse: collapse;
  margin: 16px 0;
  color: var(--muted);
  font-size: .9rem;
}
.rules-table th,
.rules-table td {
  border-bottom: 1px solid #ffffff18;
  padding: 8px;
  text-align: left;
}
.rules-table th { color: var(--accent); }
.menu-dialog label {
  display: block;
  margin: 12px 0;
  color: var(--muted);
}
.dialog-actions {
  display: grid;
  gap: 10px;
}
.history {
  max-height: 96px;
  overflow: auto;
  display: grid;
  gap: 6px;
  margin: 10px 0;
  color: var(--muted);
  font-size: .82rem;
}
.history span {
  border-left: 2px solid var(--accent);
  padding-left: 8px;
}

.history-list {
  display: grid;
  gap: 7px;
  max-height: min(420px, 58svh);
  overflow: auto;
  margin: 12px 0;
}

.history-list span {
  border: 1px solid #ffffff14;
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  background: #ffffff08;
  color: var(--muted);
  font-size: .84rem;
  font-weight: 800;
  line-height: 1.25;
  padding: 8px 10px;
}
.cell.last {
  outline: 3px solid var(--accent);
  outline-offset: -3px;
}
.token.capture {
  animation: capturePulse .5s ease;
}
.reward-pop {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 20;
  pointer-events: none;
  transform: translateX(-50%) translateY(30px);
  opacity: 0;
  border: 1px solid #ffffff24;
  border-radius: 999px;
  padding: 12px 18px;
  background: #18110dee;
  color: var(--accent);
  font-weight: 900;
  box-shadow: 0 18px 70px #0008;
}
.reward-pop.show {
  animation: rewardRise 1.4s ease;
}
.result-summary {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 18px;
  margin: 14px 0 18px;
}
.result-summary dt {
  color: var(--muted);
}
.result-summary dd {
  color: var(--accent);
  font-weight: 900;
  margin: 0;
}
body.reduced-motion *,
body.reduced-motion *::before,
body.reduced-motion *::after {
  animation: none !important;
  transition: none !important;
}
@keyframes shellRoll {
  from { transform: rotate(0deg) scale(.7); }
  to { transform: rotate(var(--turn)) scale(1); }
}
@keyframes capturePulse {
  50% { transform: scale(1.5); filter: brightness(1.4); }
}
@keyframes rewardRise {
  0% { opacity: 0; transform: translateX(-50%) translateY(30px); }
  15%, 80% { opacity: 1; transform: translateX(-50%) translateY(0); }
  100% { opacity: 0; transform: translateX(-50%) translateY(-20px); }
}

#throw {
  width: 100%;
  margin-top: 4px;
  box-shadow: 0 12px 28px #0005;
}

#message {
  margin: 10px 0 0;
  min-height: 2.6em;
  border: 1px solid #ffffff14;
  border-radius: 12px;
  background: #ffffff08;
  padding: 10px 12px;
}

@media (max-width: 980px) {
  .table {
    grid-template-columns: 1fr;
  }

  .panel {
    position: static;
    max-height: none;
    order: 2;
  }

  .board-wrap {
    min-height: auto;
    order: 1;
  }

  .board {
    width: min(100%, 620px, calc(100svh - 120px));
  }
}

@media (max-width: 800px) {
  body {
    padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
  }

  .shell {
    min-height: calc(100svh - 16px);
    border-radius: 16px;
    padding: 10px;
    backdrop-filter: none;
  }

  h1 { font-size: clamp(1.75rem, 10vw, 2.65rem); }

  .pitch,
  footer,
  .quick-guide { display: none; }

  .ad-preview { min-height: 48px; padding: 8px 10px; margin: 8px 0; }
  .ad-preview { grid-template-columns: 1fr auto; }
  .ad-preview strong { font-size: .78rem; }
  .ad-preview span { font-size: .68rem; }
  .ad-preview small { display: none; }

  .topbar,
  footer {
    align-items: stretch;
    flex-direction: column;
    gap: 10px;
  }

  .top-actions { justify-content: flex-start; }
  .top-actions .quiet {
    flex: 1 1 0;
    min-width: 72px;
    padding-inline: 10px;
  }

  .stats { margin: 10px 0; gap: 6px; }
  .stats div { padding: 8px; }
  .stats strong { font-size: 1.2rem; }

  .modes,
  .rule-controls {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .rule-controls label {
    border-radius: 12px;
    justify-content: center;
    padding-inline: 10px;
  }

  .board-wrap { padding: 8px; }
  .panel { padding: 12px 12px 74px; }
  .shells { grid-template-columns: repeat(6, 1fr); gap: 6px; margin: 10px 0; }
  .cowrie { min-height: 38px; font-size: .95rem; }

  .board {
    width: min(100%, calc(100vw - 36px));
    gap: 2px;
    padding: 5px;
    border-radius: 14px;
  }

  .cell-step { display: none; }
  .cell.safe::after,
  .cell.blockade::before { font-size: .42rem; }

  .token {
    width: 72%;
    border-width: 1px;
    font-size: .34rem;
  }

  .board-legend {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .player-row {
    grid-template-columns: 1fr 1fr 1fr;
  }

  .player-row span {
    grid-column: 1 / -1;
  }

  .history { max-height: 76px; }

  #throw {
    position: fixed;
    right: max(12px, env(safe-area-inset-right));
    bottom: max(28px, env(safe-area-inset-bottom));
    z-index: 30;
    width: auto;
    min-width: 148px;
    box-shadow: 0 16px 36px #0009;
  }
}

@media (max-width: 520px) {
  .stats { grid-template-columns: repeat(3, 1fr); }
  .stats span { font-size: .62rem; }
  .stats strong { font-size: 1.05rem; }

  .modes,
  .rule-controls { gap: 6px; }

  .mode,
  .rule-controls label {
    font-size: .78rem;
    min-height: 42px;
    padding: 9px 8px;
  }

  .board { gap: 2px; }
  .board-legend { grid-template-columns: 1fr; }

  .player-row {
    grid-template-columns: 1fr 1fr;
  }

  dialog {
    width: calc(100vw - 24px);
    max-height: calc(100svh - 24px);
    overflow: auto;
    padding: 18px;
  }
}

/* M1.7 three-zone play layout */
body {
  padding: 0;
  overflow: hidden;
}

.shell {
  width: 100%;
  min-height: 100svh;
  border: 0;
  border-radius: 0;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  gap: 8px;
  padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
}

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

.eyebrow,
.pitch,
footer,
.panel,
.quick-guide {
  display: none !important;
}

h1 {
  font-size: clamp(1.1rem, 3.5vw, 1.65rem);
  line-height: 1;
}

.top-actions {
  flex-wrap: nowrap;
  gap: 6px;
}

.top-actions button {
  min-height: 38px;
  padding: 8px 10px;
}

.stats {
  position: fixed;
  top: max(8px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 5;
  width: min(330px, 42vw);
  margin: 0;
  gap: 6px;
}

.stats div {
  padding: 6px 8px;
  border-radius: 12px;
}

.stats span {
  font-size: .56rem;
}

.stats strong {
  font-size: .95rem;
}

.ad-preview {
  position: fixed;
  left: max(8px, env(safe-area-inset-left));
  top: calc(max(8px, env(safe-area-inset-top)) + 54px);
  z-index: 4;
  max-width: min(300px, calc(100vw - 16px));
  min-height: 0;
  grid-template-columns: auto auto;
  margin: 0;
  padding: 7px 10px;
  opacity: .88;
}

.ad-preview small {
  display: none;
}

.table {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-items: stretch;
}

.board-wrap {
  min-height: 0;
  height: 100%;
  padding: clamp(6px, 1.3vw, 12px);
}

.board {
  width: min(100%, 720px, calc(100svh - 142px));
}

.kaudi-board {
  min-height: 0;
  width: min(100%, 640px, calc(100svh - 142px));
  aspect-ratio: 1;
}

.action-bar {
  z-index: 10;
  display: grid;
  grid-template-columns: minmax(120px, .8fr) minmax(150px, .9fr) minmax(170px, 1.15fr) auto auto;
  gap: 8px;
  align-items: center;
  border: 1px solid #ffffff18;
  border-radius: 18px;
  background: #18110df2;
  box-shadow: 0 -18px 60px #0008;
  padding: 8px;
}

.action-bar .turn-panel {
  margin: 0;
  padding: 8px 10px;
}

.action-bar .shells {
  grid-template-columns: repeat(6, minmax(28px, 1fr));
  gap: 5px;
  margin: 0;
}

.action-bar .cowrie {
  min-height: 32px;
  font-size: .85rem;
}

.piece-actions {
  grid-template-columns: repeat(4, minmax(78px, 1fr));
  gap: 6px;
  margin: 0;
}

.piece-actions button {
  min-height: 44px;
  border-radius: 12px;
}

.piece-actions button.locked::after {
  content: none;
}

#throw {
  position: static;
  width: auto;
  min-width: 132px;
  margin: 0;
}

#open-history {
  min-width: 104px;
  min-height: 44px;
  border-radius: 8px;
}

#message {
  position: static;
  grid-column: 1 / -1;
  width: 100%;
  transform: none;
  margin: 0;
  min-height: 0;
  padding: 8px 12px;
  border-radius: 999px;
  background: #18110dee;
  color: var(--muted);
  font-size: .82rem;
  text-align: center;
  pointer-events: none;
}

.menu-dialog .modes,
.menu-dialog .rule-controls {
  display: grid;
  grid-template-columns: 1fr;
}

.menu-dialog .rule-controls {
  margin: 12px 0;
}

@media (max-width: 800px) {
  .shell {
    padding: max(6px, env(safe-area-inset-top)) max(6px, env(safe-area-inset-right)) max(6px, env(safe-area-inset-bottom)) max(6px, env(safe-area-inset-left));
  }

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

  .top-actions {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    width: 100%;
  }

  .top-actions button {
    min-width: 0;
    min-width: 44px;
    font-size: .72rem;
    padding-inline: 8px;
  }

  .stats {
    position: static;
    transform: none;
    grid-row: 2;
    grid-column: 1 / -1;
    width: 100%;
  }

  .ad-preview {
    display: grid;
    top: auto;
    bottom: calc(64px + env(safe-area-inset-bottom));
    max-width: 190px;
    grid-template-columns: 1fr;
    pointer-events: none;
  }

  .board-wrap {
    padding: 5px;
  }

  .board,
  .kaudi-board {
    width: min(100%, calc(100svh - 190px), calc(100vw - 18px));
  }

  .action-bar {
    grid-template-columns: 1fr auto;
    gap: 6px;
    border-radius: 14px;
    padding: 6px;
  }

  .action-bar .turn-panel {
    display: none;
  }

  .action-bar .shells {
    grid-template-columns: repeat(6, minmax(24px, 1fr));
  }

  .piece-actions {
    grid-column: 1 / -1;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    order: 3;
  }

  #message {
    font-size: .76rem;
    padding-block: 6px;
  }
}

/* M1.8 identity polish: make Chaupar feel like cloth + cowrie pieces, not Ludo */
.board-wrap {
  background:
    radial-gradient(circle at 50% 50%, #f2c86a18 0 16%, transparent 17%),
    linear-gradient(45deg, #ffffff06 25%, transparent 25% 50%, #ffffff05 50% 75%, transparent 75%),
    #17110d;
  background-size: auto, 18px 18px, auto;
}

.board {
  gap: 3px;
  border: 2px solid #c78f3b55;
  border-radius: 8px;
  background:
    linear-gradient(90deg, transparent 47%, #d9a94c22 47% 53%, transparent 53%),
    linear-gradient(0deg, transparent 47%, #d9a94c22 47% 53%, transparent 53%),
    radial-gradient(circle at center, #f6d48622, transparent 23%),
    #271a12;
  box-shadow:
    inset 0 0 0 2px #0008,
    inset 0 0 40px #0007;
}

.cell {
  border-radius: 4px;
  border-color: #d4a55420;
  background: #20150f;
}

.cell.path {
  background:
    linear-gradient(145deg, #80592b, #3b2415);
  border-color: #f0c46f42;
  box-shadow: inset 0 0 0 1px #0006;
}

.cell.home-lane {
  background:
    linear-gradient(145deg, #3a2a1d, #20150f);
}

.cell.yard {
  background:
    radial-gradient(circle, #f3d28b1a, transparent 54%),
    #211711;
  border-color: #e1b36040;
  border-style: solid;
}

.cell.center {
  border-radius: 50%;
  background:
    radial-gradient(circle, #fff2bd 0 28%, #dba241 29% 64%, #5b3517 65%);
  color: #251405;
}

.cell.safe {
  border-color: #f6d486;
  box-shadow: inset 0 0 0 2px #f6d48699, 0 0 12px #f6d48644;
}

.cell.safe::after {
  content: "";
  width: 28%;
  aspect-ratio: 1;
  border: 2px solid #f6d486;
  border-radius: 2px;
  position: absolute;
  right: 3px;
  top: 3px;
  transform: rotate(45deg);
  background: #271a12;
}

.cell-step {
  color: #fff0bf88;
}

.token {
  border-radius: 48% 52% 45% 55%;
  border: 2px solid #fff4;
  box-shadow:
    inset -3px -4px 0 #0003,
    inset 2px 2px 0 #fff4,
    0 8px 18px #0009;
  color: #fffaf0;
}

.token::after {
  content: "";
  width: 34%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: #ffffff55;
  position: absolute;
  top: 18%;
  left: 20%;
}

.token.p0 { background: linear-gradient(145deg, #68d890, #25794c); }
.token.p1 { background: linear-gradient(145deg, #f06c62, #9c2c2c); }
.token.p2 { background: linear-gradient(145deg, #79a5ff, #2f54aa); }
.token.p3 { background: linear-gradient(145deg, #f4d06a, #a86f13); }

.token.selectable {
  outline: 0;
  box-shadow:
    0 0 0 4px #fff8,
    0 0 0 8px #f6d48666,
    0 0 26px #f6d486aa;
  animation: tokenReady 1s ease-in-out infinite alternate;
}

@keyframes tokenReady {
  from { transform: translate(var(--token-x, 0), var(--token-y, 0)) scale(1); }
  to { transform: translate(var(--token-x, 0), var(--token-y, 0)) scale(1.08); }
}

.token.t0 { --token-x: -34%; --token-y: -34%; transform: translate(var(--token-x), var(--token-y)); }
.token.t1 { --token-x: 34%; --token-y: -34%; transform: translate(var(--token-x), var(--token-y)); }
.token.t2 { --token-x: -34%; --token-y: 34%; transform: translate(var(--token-x), var(--token-y)); }
.token.t3 { --token-x: 34%; --token-y: 34%; transform: translate(var(--token-x), var(--token-y)); }

.action-bar .cowrie {
  border-radius: 48% 52% 45% 55%;
}

@media (max-width: 800px) {
  .board {
    gap: 2px;
  }

  .cell.safe::after {
    width: 24%;
    border-width: 1px;
    right: 2px;
    top: 2px;
  }
}

/* M1.7 visual polish: app-style play screen */
body {
  background:
    linear-gradient(180deg, #171b22 0%, #101219 42%, #16110d 100%);
}

.shell {
  background:
    linear-gradient(180deg, #ffffff08, transparent 30%),
    #11141a;
}

.topbar {
  min-height: 48px;
  border: 1px solid #ffffff12;
  border-radius: 8px;
  background: #ffffff08;
  box-shadow: 0 10px 32px #0004;
  padding: 6px 8px;
}

.topbar h1 {
  letter-spacing: 0;
}

.top-actions button {
  border-radius: 8px;
  background: #ffffff0f;
}

.top-actions button:focus-visible,
.piece-actions button:focus-visible,
#throw:focus-visible {
  outline: 3px solid #f6c453;
  outline-offset: 2px;
}

.stats {
  border: 1px solid #ffffff12;
  border-radius: 8px;
  background: #0f141bf0;
  box-shadow: 0 10px 32px #0005;
  padding: 4px;
}

.stats div {
  border-color: #ffffff12;
  background: #ffffff09;
}

.stats strong {
  color: #f6d486;
}

.ad-preview {
  border-radius: 8px;
  background: #0f141bd9;
  color: #aeb6c2;
  box-shadow: none;
}

.ad-preview strong {
  color: #e9edf5;
}

.table {
  place-items: center;
}

.board-wrap {
  display: grid;
  place-items: center;
  border: 1px solid #ffffff12;
  border-radius: 8px;
  background:
    linear-gradient(180deg, #ffffff0b, #ffffff03),
    #151922;
  box-shadow: inset 0 0 0 1px #0004, 0 24px 70px #0008;
}

.board,
.kaudi-board {
  filter: saturate(1.08) contrast(1.03);
}

.action-bar {
  border-radius: 8px;
  background: #10141cf7;
  box-shadow: 0 -10px 34px #0007;
}

.action-bar .turn-panel,
#message {
  border: 1px solid #ffffff10;
  background: #ffffff08;
}

.action-bar .shells {
  align-items: center;
}

.action-bar .cowrie {
  border-radius: 8px;
  background: #fff4cf;
  color: #301e11;
}

.piece-actions button {
  border-radius: 8px;
  font-weight: 850;
}

#throw {
  border-radius: 8px;
  background: linear-gradient(180deg, #ffd56d, #e8a92c);
  color: #221606;
  box-shadow: 0 8px 22px #0007;
}

#message {
  color: #d4d9e2;
}

@media (min-width: 801px) {
  .shell {
    gap: 10px;
    padding: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  }

  .board-wrap {
    width: min(100%, 780px);
    height: min(100%, calc(100svh - 132px));
  }
}

@media (max-width: 800px) {
  .shell {
    gap: 6px;
  }

  .topbar {
    min-height: 0;
    padding: 6px;
  }

  .topbar h1 {
    text-align: center;
    font-size: 1.04rem;
  }

  .top-actions {
    gap: 4px;
  }

  .top-actions button {
    min-height: 36px;
    padding: 6px 4px;
    font-size: .68rem;
  }

  .stats {
    gap: 4px;
  }

  .stats div {
    padding: 5px 4px;
  }

  .stats strong {
    font-size: .9rem;
  }

  .ad-preview {
    left: max(6px, env(safe-area-inset-left));
    bottom: calc(72px + env(safe-area-inset-bottom));
    max-width: 142px;
    padding: 5px 7px;
    font-size: .62rem;
    opacity: .72;
  }

  .ad-preview span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .board-wrap {
    padding: 4px;
  }

  .board,
  .kaudi-board {
    width: min(100%, calc(100svh - 206px), calc(100vw - 20px));
  }

  .action-bar {
    grid-template-columns: minmax(0, 1fr) minmax(104px, auto);
    align-items: stretch;
    gap: 5px;
    padding: 6px;
  }

  .action-bar .shells {
    grid-template-columns: repeat(6, minmax(20px, 1fr));
  }

  .action-bar .cowrie {
    min-height: 28px;
    font-size: .76rem;
  }

  #throw {
    min-width: 104px;
    min-height: 44px;
    font-size: .82rem;
  }

  #open-history {
    min-width: 86px;
    min-height: 44px;
    font-size: .72rem;
  }

  .piece-actions {
    gap: 5px;
  }

  .piece-actions button {
    min-height: 40px;
    font-size: .76rem;
  }

  #message {
    padding: 5px 8px;
    font-size: .72rem;
    line-height: 1.25;
  }
}

/* Final Chaupar board correction: cross-first, no generic square slab */
.table {
  align-items: center;
}

.board-wrap {
  width: min(100%, 760px);
  height: auto;
  aspect-ratio: 1;
  border-color: #c28a3b3d;
  background:
    radial-gradient(circle at 50% 50%, #f6d4861f 0 13%, transparent 14%),
    radial-gradient(circle at 22% 22%, #f6d48612 0 8%, transparent 9%),
    radial-gradient(circle at 78% 22%, #f6d48612 0 8%, transparent 9%),
    radial-gradient(circle at 22% 78%, #f6d48612 0 8%, transparent 9%),
    radial-gradient(circle at 78% 78%, #f6d48612 0 8%, transparent 9%),
    repeating-linear-gradient(45deg, #ffffff05 0 2px, transparent 2px 14px),
    #22150e;
  box-shadow:
    inset 0 0 0 2px #0007,
    inset 0 0 80px #0007,
    0 24px 70px #0009;
}

.board {
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  gap: clamp(2px, .38vw, 4px);
}

.cell.inactive {
  visibility: hidden;
}

.cell.path,
.cell.home-lane,
.cell.yard {
  border-radius: 5px;
  box-shadow:
    inset 0 0 0 1px #0008,
    0 3px 8px #0005;
}

.cell-step {
  display: none;
}

.cell.path {
  background:
    linear-gradient(145deg, #996a34, #3b2415);
  border-color: #f0c46f52;
}

.cell.home-lane {
  background:
    linear-gradient(145deg, #4a2f1c, #21140d);
}

.cell.home-lane::before {
  content: "";
  width: 38%;
  height: 2px;
  border-radius: 999px;
  background: #f6d48688;
  position: absolute;
}

.cell.center {
  border-radius: 50%;
  z-index: 2;
}

.cell.center::after {
  content: "";
  position: absolute;
  inset: -8px;
  border: 2px dashed #f6d48688;
  border-radius: 50%;
  pointer-events: none;
}

.cell.safe::after {
  content: "";
  width: 28%;
  aspect-ratio: 1;
  border: 2px solid #f6d486;
  border-radius: 2px;
  position: absolute;
  right: 3px;
  top: 3px;
  transform: rotate(45deg);
  background: #271a12;
}

.token {
  border-radius: 50% 44% 52% 46%;
  font-size: clamp(.46rem, .86vw, .7rem);
}

.token::after {
  width: 28%;
}

.action-bar .turn-panel {
  border-radius: 8px;
}

@media (min-width: 801px) {
  .board-wrap {
    width: min(100%, 680px, calc(100svh - 190px));
    max-height: calc(100svh - 190px);
  }
}

@media (max-width: 800px) {
  .table {
    align-items: start;
  }

  .board-wrap {
    width: min(100%, calc(100vw - 14px), calc(100svh - 210px));
    max-height: calc(100svh - 210px);
  }

  .board,
  .kaudi-board {
    width: 100%;
  }

  .action-bar .turn-panel {
    display: grid;
    grid-column: 1 / -1;
    order: -1;
    grid-template-columns: 1fr auto;
    padding: 5px 8px;
  }

  .action-bar .turn-panel span,
  .action-bar .turn-panel b {
    font-size: .7rem;
  }

  .ad-preview {
    top: calc(max(6px, env(safe-area-inset-top)) + 142px);
    bottom: auto;
    max-width: 76px;
    min-height: 0;
    padding: 4px 6px;
    opacity: .58;
  }

  .ad-preview strong {
    display: block;
    font-size: .58rem;
    line-height: 1.05;
  }

  .ad-preview span {
    display: none;
  }
}

/* Beta-wide UI polish: make the traditional board feel like the main stage */
.app-shell {
  background:
    radial-gradient(circle at 18% 8%, rgba(246, 212, 134, .14), transparent 32%),
    radial-gradient(circle at 88% 12%, rgba(130, 184, 119, .10), transparent 30%),
    linear-gradient(180deg, #170d08 0%, #24130b 48%, #0d0806 100%);
}

/* Stage 4 viewport guard: keep the dense play HUD inside 320px phones. */
html,
body {
  max-width: 100%;
}

.shell,
.topbar,
.top-actions,
.stats,
.table,
.board-wrap,
.action-bar,
.turn-panel,
.shells,
.piece-actions,
#message {
  min-width: 0;
  max-width: 100%;
}

@media (max-width: 360px) {
  .shell {
    padding-inline: max(4px, env(safe-area-inset-left)) max(4px, env(safe-area-inset-right));
  }

  .top-actions {
    gap: 3px;
  }

  .top-actions button {
    font-size: .62rem;
    min-width: 0;
    overflow: hidden;
    padding-inline: 2px;
    text-overflow: ellipsis;
    white-space: nowrap;
    width: 100%;
  }

  .stats span {
    font-size: .52rem;
  }

  .board-wrap {
    /* Reserve a complete action row so compact phones can begin a turn without scrolling. */
    width: min(100%, calc(100vw - 8px), calc(100svh - 340px));
  }

  .action-bar {
    grid-template-columns: minmax(0, 1fr) minmax(96px, auto);
    gap: 4px;
    padding: 5px;
  }

  .action-bar .shells {
    grid-template-columns: repeat(6, minmax(16px, 1fr));
  }

  #throw,
  #open-history {
    min-width: 96px;
    font-size: .7rem;
    padding-inline: 6px;
  }

  .piece-actions button {
    font-size: .7rem;
    padding-inline: 6px;
  }
}

.table {
  gap: clamp(10px, 2vw, 20px);
}

.board-wrap {
  border: 1px solid rgba(246, 212, 134, .24);
  background:
    radial-gradient(circle at center, rgba(246, 212, 134, .10), transparent 58%),
    linear-gradient(145deg, rgba(89, 51, 27, .94), rgba(31, 18, 12, .98));
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, .045),
    0 22px 58px rgba(0, 0, 0, .38);
}

.action-bar,
.rules-card,
.side-panel,
.setup-panel,
.history-panel {
  border-color: rgba(246, 212, 134, .16);
  box-shadow: 0 14px 36px rgba(0, 0, 0, .26);
}

.action-bar {
  background: linear-gradient(180deg, rgba(54, 32, 20, .94), rgba(25, 15, 11, .96));
}

.action-bar button,
.setup-panel button,
.history-panel button,
dialog button {
  min-height: 44px;
}

.turn-panel {
  border: 1px solid rgba(246, 212, 134, .18);
  background: rgba(0, 0, 0, .18);
}

.cell.valid-move {
  box-shadow:
    inset 0 0 0 2px rgba(130, 184, 119, .9),
    0 0 18px rgba(130, 184, 119, .46);
}

.cell.move-target {
  border-color: #82b877;
  background:
    radial-gradient(circle, rgba(130, 184, 119, .42), transparent 54%),
    linear-gradient(145deg, #5d6f39, #2a2414);
}

.cell.move-target::before {
  content: "";
  width: 36%;
  aspect-ratio: 1;
  border: 2px solid #dff7b8;
  border-radius: 50%;
  position: absolute;
  opacity: .9;
}

.token {
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, .35),
    0 5px 12px rgba(0, 0, 0, .45);
}

@media (max-width: 800px) {
  .app-shell {
    padding-inline: 8px;
  }

  .board-wrap {
    box-shadow: 0 12px 30px rgba(0, 0, 0, .32);
  }

  .action-bar {
    border-radius: 12px;
  }

  .kaudi-shells {
    gap: 5px;
  }
}

@media (max-width: 360px) {
  .top-actions .quiet {
    min-width: 0;
    overflow: hidden;
    padding-inline: 2px;
    text-overflow: ellipsis;
    white-space: nowrap;
    width: 100%;
  }
}

/* Responsive layout consolidation: every play surface has a dedicated region. */
.shell {
  grid-template-areas:
    "topbar"
    "stats"
    "ad"
    "setup"
    "table"
    "actions";
  grid-template-rows: auto auto auto auto minmax(0, 1fr) auto;
  height: 100svh;
  min-height: 0;
}

.topbar { grid-area: topbar; }
.stats { grid-area: stats; }
.ad-preview {
  grid-area: ad;
  position: static !important;
  width: min(100%, 720px);
  max-width: none;
  min-height: 44px;
  margin: 0;
  opacity: 1;
  pointer-events: auto;
}
.setup-summary { grid-area: setup; }
.table { grid-area: table; }
.action-bar { grid-area: actions; }

@media (min-width: 801px) {
  .shell {
    grid-template-areas:
      "topbar topbar"
      "stats ad"
      "setup setup"
      "table table"
      "actions actions";
    grid-template-columns: minmax(0, 1fr) minmax(280px, 0.72fr);
    grid-template-rows: auto auto auto minmax(0, 1fr) auto;
  }

  .stats {
    position: static;
    transform: none;
    width: 100%;
  }

  .ad-preview {
    align-self: stretch;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 4px 12px;
    padding: 8px 10px;
  }

  .ad-preview small {
    display: block;
    grid-column: 1 / -1;
    justify-self: start;
  }

  .table {
    grid-template-columns: minmax(0, 1fr) minmax(248px, 304px);
    min-height: 0;
  }

  .board-wrap {
    width: 100%;
    height: 100%;
    min-height: 0;
    max-height: none;
  }

  .board,
  .kaudi-board {
    width: min(100%, 660px, calc(100svh - 350px));
  }

  .panel {
    display: block !important;
    max-height: none;
    min-height: 0;
    overflow: auto;
    position: static;
  }

  .action-bar {
    box-shadow: 0 -8px 26px rgba(0, 0, 0, .28);
  }
}

@media (max-width: 800px) {
  body { overflow: hidden; }

  .shell {
    gap: 5px;
    grid-template-areas:
      "topbar"
      "stats"
      "ad"
      "setup"
      "table"
      "actions";
    grid-template-rows: auto auto auto auto minmax(0, 1fr) auto;
  }

  .setup-summary {
    display: flex;
    flex-wrap: nowrap;
    gap: 4px;
    min-height: 36px;
    overflow-x: auto;
    padding: 4px;
  }

  .setup-summary span,
  .setup-summary strong {
    flex: 0 0 auto;
    min-height: 28px;
    padding: 4px 7px;
    font-size: .58rem;
  }

  .ad-preview {
    align-items: center;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 4px 8px;
    padding: 5px 8px;
    width: 100%;
  }

  .ad-preview strong { font-size: .64rem; }
  .ad-preview span { font-size: .58rem; }
  .ad-preview small { display: none; }

  .table,
  .board-wrap {
    height: 100%;
    min-height: 0;
  }

  .board-wrap { width: 100%; }

  .board,
  .kaudi-board {
    width: min(100%, calc(100svh - 400px), calc(100vw - 18px));
  }

  .action-bar {
    box-shadow: 0 -6px 18px rgba(0, 0, 0, .24);
  }
}

@media (max-width: 360px) {
  .board,
  .kaudi-board {
    width: min(100%, calc(100svh - 382px), calc(100vw - 14px));
  }

  .ad-preview { min-height: 38px; }
}
