:root {
  --ink: #251b13;
  --muted: #6c5a45;
  --paper: #f6efe3;
  --panel: #fffaf0;
  --board-light: #c88645;
  --board-mid: #9c5a2e;
  --board-dark: #603419;
  --green: #26745d;
  --blue: #244a76;
  --red: #a9432b;
  --gold: #d5a03d;
  --shadow: 0 22px 70px rgba(58, 34, 16, 0.22);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: "Microsoft YaHei", "PingFang SC", "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 12% 18%, rgba(213, 160, 61, 0.18), transparent 28rem),
    linear-gradient(135deg, #efe2cf 0%, #f8f1e8 44%, #e5d0b5 100%);
}

button,
select {
  font: inherit;
}

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

.hero-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 420px);
  gap: 24px;
  align-items: stretch;
  min-height: 220px;
  margin-bottom: 22px;
}

.hero-copy {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 30px 34px;
  border: 1px solid rgba(96, 52, 25, 0.14);
  border-radius: 8px;
  background: rgba(255, 250, 240, 0.78);
  box-shadow: var(--shadow);
}

.eyebrow {
  margin: 0 0 12px;
  color: var(--green);
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0;
}

h1 {
  margin: 0;
  font-family: Georgia, "Times New Roman", "Microsoft YaHei", serif;
  font-size: clamp(3.2rem, 8vw, 6.4rem);
  line-height: 0.95;
  letter-spacing: 0;
}

.intro {
  max-width: 52ch;
  margin: 16px 0 0;
  color: var(--muted);
  font-size: 1.04rem;
  line-height: 1.75;
}

.hero-photo {
  min-height: 220px;
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(37, 27, 19, 0.06), rgba(37, 27, 19, 0.32)),
    url("assets/bao-board-from-zanzibar.jpg") center / cover;
  border: 1px solid rgba(96, 52, 25, 0.18);
  box-shadow: var(--shadow);
}

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

.control-panel,
.board-zone {
  border: 1px solid rgba(96, 52, 25, 0.15);
  border-radius: 8px;
  background: rgba(255, 250, 240, 0.82);
  box-shadow: var(--shadow);
}

.control-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 18px;
}

.score-card {
  min-height: 112px;
  padding: 16px;
  border-radius: 8px;
  color: #fffdf7;
}

.player-two {
  background: linear-gradient(135deg, var(--blue), #182d43);
}

.player-one {
  background: linear-gradient(135deg, var(--green), #174535);
}

.player-name,
.score-card small {
  display: block;
  color: rgba(255, 253, 247, 0.76);
  font-size: 0.86rem;
}

.score-card strong {
  display: block;
  margin: 6px 0 2px;
  font-size: 3rem;
  line-height: 1;
}

.mode-group {
  display: grid;
  gap: 8px;
}

.mode-button,
.primary-button,
.pit {
  border: 0;
  cursor: pointer;
}

.mode-button,
.primary-button,
.difficulty-control select {
  min-height: 44px;
  border-radius: 8px;
}

.mode-button {
  color: var(--ink);
  background: #efe1ce;
}

.mode-button.active {
  color: #fffdf7;
  background: var(--board-dark);
}

.difficulty-control {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.9rem;
}

.difficulty-control select {
  width: 100%;
  padding: 0 12px;
  border: 1px solid rgba(96, 52, 25, 0.28);
  color: var(--ink);
  background: #fffaf0;
}

.primary-button {
  color: #fffdf7;
  background: var(--red);
  font-weight: 700;
}

.board-zone {
  padding: 18px;
}

.starter-banner {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  margin-bottom: 14px;
  padding: 14px 16px;
  border: 2px solid rgba(213, 160, 61, 0.8);
  border-radius: 8px;
  background: linear-gradient(135deg, rgba(213, 160, 61, 0.24), rgba(38, 116, 93, 0.14));
  color: var(--ink);
}

.starter-banner.is-hidden {
  display: none;
}

.starter-banner span {
  display: inline-grid;
  place-items: center;
  min-height: 34px;
  padding: 0 12px;
  border-radius: 999px;
  color: #fffdf7;
  background: var(--green);
  font-size: 0.9rem;
  font-weight: 800;
}

.starter-banner strong {
  font-size: 1.1rem;
}

.status-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 16px;
  padding: 14px 16px;
  border-bottom: 1px solid rgba(96, 52, 25, 0.14);
}

.status-label {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
}

#turn-label {
  font-size: 1.25rem;
}

#message {
  margin: 0;
  color: var(--muted);
  text-align: right;
  line-height: 1.5;
}

.status-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
}

.sound-toggle {
  flex: 0 0 auto;
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid rgba(96, 52, 25, 0.18);
  border-radius: 999px;
  color: var(--ink);
  background: #efe1ce;
  cursor: pointer;
}

.sound-toggle[aria-pressed="false"] {
  color: var(--muted);
  background: rgba(239, 225, 206, 0.55);
}

.board {
  position: relative;
  display: grid;
  grid-template-columns: 1.1fr repeat(6, 1fr) 1.1fr;
  grid-template-rows: repeat(2, minmax(106px, 1fr));
  gap: 12px;
  min-height: 300px;
  padding: 26px;
  border-radius: 8px;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.18), transparent 24%, rgba(0, 0, 0, 0.11)),
    repeating-linear-gradient(88deg, rgba(255, 255, 255, 0.07) 0 12px, rgba(70, 33, 12, 0.07) 12px 20px),
    linear-gradient(135deg, var(--board-light), var(--board-mid) 55%, var(--board-dark));
  box-shadow: inset 0 5px 20px rgba(255, 255, 255, 0.22), inset 0 -12px 30px rgba(46, 22, 8, 0.24);
}

.pit-row {
  display: contents;
}

.store,
.pit {
  position: relative;
  display: grid;
  place-items: center;
  isolation: isolate;
  border-radius: 999px;
  background:
    radial-gradient(circle at 50% 64%, rgba(45, 22, 9, 0.52), transparent 58%),
    radial-gradient(circle at 45% 35%, #8e4e27 0%, #6b371b 72%);
  box-shadow:
    inset 0 11px 20px rgba(31, 15, 5, 0.66),
    inset 0 -5px 10px rgba(255, 223, 171, 0.2),
    0 5px 13px rgba(39, 20, 8, 0.2);
}

.store {
  grid-row: 1 / 3;
  min-height: 250px;
  border-radius: 46px;
  border: 3px solid rgba(255, 250, 240, 0.28);
  overflow: hidden;
}

.store-north {
  grid-column: 1;
  background:
    linear-gradient(180deg, rgba(36, 74, 118, 0.7), rgba(24, 45, 67, 0.62)),
    radial-gradient(circle at 50% 64%, rgba(45, 22, 9, 0.52), transparent 58%),
    radial-gradient(circle at 45% 35%, #8e4e27 0%, #6b371b 72%);
  box-shadow:
    inset 0 0 0 5px rgba(36, 74, 118, 0.72),
    inset 0 11px 20px rgba(31, 15, 5, 0.66),
    0 5px 13px rgba(39, 20, 8, 0.2);
}

.store-south {
  grid-column: 8;
  background:
    linear-gradient(180deg, rgba(38, 116, 93, 0.72), rgba(23, 69, 53, 0.62)),
    radial-gradient(circle at 50% 64%, rgba(45, 22, 9, 0.52), transparent 58%),
    radial-gradient(circle at 45% 35%, #8e4e27 0%, #6b371b 72%);
  box-shadow:
    inset 0 0 0 5px rgba(38, 116, 93, 0.72),
    inset 0 11px 20px rgba(31, 15, 5, 0.66),
    0 5px 13px rgba(39, 20, 8, 0.2);
}

.store-owner {
  position: absolute;
  top: 12px;
  left: 50%;
  z-index: 4;
  min-width: 54px;
  padding: 5px 10px;
  border-radius: 999px;
  color: #fffdf7;
  font-size: 0.82rem;
  font-weight: 800;
  text-align: center;
  transform: translateX(-50%);
  box-shadow: 0 3px 10px rgba(30, 18, 8, 0.24);
}

.store-north .store-owner {
  background: var(--blue);
}

.store-south .store-owner {
  background: var(--green);
}

.pit {
  min-width: 0;
  min-height: 106px;
  padding: 8px;
  transition: transform 160ms ease, box-shadow 160ms ease, outline-color 160ms ease;
}

.pit-12 { grid-column: 2; grid-row: 1; }
.pit-11 { grid-column: 3; grid-row: 1; }
.pit-10 { grid-column: 4; grid-row: 1; }
.pit-9 { grid-column: 5; grid-row: 1; }
.pit-8 { grid-column: 6; grid-row: 1; }
.pit-7 { grid-column: 7; grid-row: 1; }
.pit-0 { grid-column: 2; grid-row: 2; }
.pit-1 { grid-column: 3; grid-row: 2; }
.pit-2 { grid-column: 4; grid-row: 2; }
.pit-3 { grid-column: 5; grid-row: 2; }
.pit-4 { grid-column: 6; grid-row: 2; }
.pit-5 { grid-column: 7; grid-row: 2; }

.pit:disabled {
  cursor: default;
  opacity: 0.74;
}

.pit.playable:not(:disabled):hover,
.pit.playable:not(:disabled):focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 3px;
  transform: translateY(-3px);
}

.active-bin {
  outline: 4px solid rgba(213, 160, 61, 0.92);
  outline-offset: 4px;
  transform: translateY(-4px) scale(1.02);
}

.source-bin {
  outline: 4px solid rgba(169, 67, 43, 0.78);
  outline-offset: 4px;
}

.ai-chosen-bin {
  outline: 5px solid rgba(36, 74, 118, 0.95);
  outline-offset: 6px;
  box-shadow:
    0 0 0 8px rgba(36, 74, 118, 0.18),
    inset 0 11px 20px rgba(31, 15, 5, 0.66),
    inset 0 -5px 10px rgba(255, 223, 171, 0.2),
    0 5px 13px rgba(39, 20, 8, 0.2);
  animation: ai-choice-pulse 760ms ease-in-out infinite alternate;
}

.active-bin .seed {
  animation: seed-drop 240ms ease both;
}

.pit-count,
.store-count {
  position: absolute;
  right: 9px;
  bottom: 7px;
  z-index: 3;
  display: grid;
  place-items: center;
  min-width: 28px;
  min-height: 28px;
  padding: 0 6px;
  border-radius: 999px;
  color: var(--ink);
  background: rgba(255, 250, 240, 0.92);
  font-weight: 800;
  box-shadow: 0 2px 8px rgba(30, 18, 8, 0.22);
}

.seed-field {
  position: relative;
  width: min(86%, 92px);
  aspect-ratio: 1;
}

.store .seed-field {
  width: min(76%, 92px);
}

.seed {
  position: absolute;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--seed-color, #ead7a9);
  box-shadow:
    inset -3px -4px 5px rgba(72, 42, 18, 0.25),
    inset 2px 2px 4px rgba(255, 255, 255, 0.58),
    0 2px 3px rgba(28, 14, 5, 0.22);
}

@keyframes seed-drop {
  0% {
    opacity: 0;
    transform: translateY(-16px) scale(1.32);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes ai-choice-pulse {
  0% {
    transform: translateY(-2px) scale(1);
  }
  100% {
    transform: translateY(-6px) scale(1.04);
  }
}

.rules-panel {
  margin-top: 16px;
  padding: 16px;
  border-radius: 8px;
  background: rgba(239, 225, 206, 0.72);
}

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

.rules-panel ul {
  display: grid;
  gap: 7px;
  margin: 0;
  padding-left: 1.2rem;
  color: var(--muted);
  line-height: 1.55;
}

.history-note {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid rgba(96, 52, 25, 0.16);
}

.history-note h2 {
  margin-bottom: 8px;
}

.history-note p {
  margin: 0;
  color: var(--muted);
  line-height: 1.65;
}

.history-note p + p {
  margin-top: 8px;
}

.celebration-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(37, 27, 19, 0.54);
  backdrop-filter: blur(6px);
}

.celebration-overlay.is-hidden {
  display: none;
}

.celebration-card {
  position: relative;
  z-index: 2;
  width: min(420px, 100%);
  padding: 30px;
  border: 2px solid rgba(213, 160, 61, 0.8);
  border-radius: 8px;
  text-align: center;
  background:
    linear-gradient(180deg, rgba(255, 250, 240, 0.96), rgba(239, 225, 206, 0.98)),
    var(--panel);
  box-shadow: 0 28px 90px rgba(0, 0, 0, 0.32);
  animation: celebration-pop 420ms cubic-bezier(0.18, 0.89, 0.32, 1.28) both;
}

.celebration-kicker {
  margin: 0 0 10px;
  color: var(--green);
  font-weight: 800;
}

.celebration-card h2 {
  margin: 0;
  font-family: Georgia, "Times New Roman", "Microsoft YaHei", serif;
  font-size: clamp(2.2rem, 8vw, 4rem);
  line-height: 1;
}

.celebration-card p:not(.celebration-kicker) {
  margin: 14px 0 22px;
  color: var(--muted);
  font-size: 1.15rem;
}

.confetti-field {
  position: absolute;
  inset: 0;
  overflow: hidden;
}

.confetti-field span {
  position: absolute;
  top: -12%;
  left: var(--x);
  width: 12px;
  height: 22px;
  border-radius: 2px;
  background: var(--c);
  transform: rotate(var(--r));
  animation: confetti-fall var(--d) linear var(--delay) infinite;
}

.confetti-field span:nth-child(1) { --x: 9%; --c: var(--gold); --r: 18deg; --d: 2.8s; --delay: 0s; }
.confetti-field span:nth-child(2) { --x: 19%; --c: var(--green); --r: -28deg; --d: 3.1s; --delay: 0.2s; }
.confetti-field span:nth-child(3) { --x: 31%; --c: var(--red); --r: 42deg; --d: 2.6s; --delay: 0.4s; }
.confetti-field span:nth-child(4) { --x: 43%; --c: var(--blue); --r: -12deg; --d: 3.3s; --delay: 0.1s; }
.confetti-field span:nth-child(5) { --x: 54%; --c: #fffaf0; --r: 58deg; --d: 2.9s; --delay: 0.5s; }
.confetti-field span:nth-child(6) { --x: 63%; --c: var(--gold); --r: -48deg; --d: 3.2s; --delay: 0.15s; }
.confetti-field span:nth-child(7) { --x: 72%; --c: var(--green); --r: 25deg; --d: 2.7s; --delay: 0.35s; }
.confetti-field span:nth-child(8) { --x: 81%; --c: var(--red); --r: -33deg; --d: 3s; --delay: 0.05s; }
.confetti-field span:nth-child(9) { --x: 88%; --c: var(--blue); --r: 15deg; --d: 2.5s; --delay: 0.45s; }
.confetti-field span:nth-child(10) { --x: 96%; --c: var(--gold); --r: -60deg; --d: 3.4s; --delay: 0.25s; }

@keyframes celebration-pop {
  0% {
    opacity: 0;
    transform: translateY(22px) scale(0.92);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes confetti-fall {
  0% {
    transform: translateY(-10vh) rotate(var(--r));
  }
  100% {
    transform: translateY(115vh) rotate(calc(var(--r) + 520deg));
  }
}

@media (max-width: 880px) {
  .hero-panel,
  .game-layout {
    grid-template-columns: 1fr;
  }

  .control-panel {
    grid-row: 2;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .mode-group,
  .difficulty-control,
  .primary-button {
    grid-column: span 2;
  }
}

@media (max-width: 640px) {
  .app-shell {
    width: min(100% - 20px, 1180px);
    padding: 14px 0;
  }

  .hero-copy {
    padding: 22px;
  }

  .hero-photo {
    min-height: 170px;
  }

  .board-zone {
    padding: 10px;
  }

  .status-strip {
    display: grid;
    padding: 12px;
  }

  .starter-banner {
    grid-template-columns: 1fr;
  }

  .status-actions {
    display: grid;
    justify-content: stretch;
  }

  #message {
    text-align: left;
  }

  .board {
    grid-template-columns: repeat(6, 1fr);
    grid-template-rows: 88px 88px 74px;
    gap: 8px;
    min-height: 284px;
    padding: 14px;
  }

  .store {
    grid-row: 3;
    min-height: 74px;
    border-radius: 34px;
  }

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

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

  .pit {
    min-height: 88px;
  }

  .pit-12 { grid-column: 1; grid-row: 1; }
  .pit-11 { grid-column: 2; grid-row: 1; }
  .pit-10 { grid-column: 3; grid-row: 1; }
  .pit-9 { grid-column: 4; grid-row: 1; }
  .pit-8 { grid-column: 5; grid-row: 1; }
  .pit-7 { grid-column: 6; grid-row: 1; }
  .pit-0 { grid-column: 1; grid-row: 2; }
  .pit-1 { grid-column: 2; grid-row: 2; }
  .pit-2 { grid-column: 3; grid-row: 2; }
  .pit-3 { grid-column: 4; grid-row: 2; }
  .pit-4 { grid-column: 5; grid-row: 2; }
  .pit-5 { grid-column: 6; grid-row: 2; }

  .seed {
    width: 14px;
    height: 14px;
  }
}
