:root {
  --bg: #102e2a;
  --bg-deep: #081d1a;
  --paper: #f5edde;
  --paper-soft: #fbf6ec;
  --ink: #1c2926;
  --muted: #66716c;
  --line: rgba(28, 41, 38, 0.13);
  --rust: #b65332;
  --rust-deep: #873a26;
  --gold: #d8a75b;
  --green: #2e6c5e;
  --wood: #71432c;
  --wood-deep: #3f241a;
  --shadow: 0 24px 64px rgba(4, 14, 13, 0.32);
}

* {
  box-sizing: border-box;
}

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

body {
  color: var(--ink);
  font-family: "Avenir Next", "Trebuchet MS", "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 12% 8%, rgba(216, 167, 91, 0.16), transparent 24%),
    radial-gradient(circle at 88% 18%, rgba(85, 146, 126, 0.22), transparent 28%),
    linear-gradient(150deg, var(--bg-deep), var(--bg));
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    repeating-linear-gradient(112deg, rgba(255, 255, 255, 0.018) 0 1px, transparent 1px 7px);
  opacity: 0.48;
}

button,
select,
input {
  font: inherit;
}

.backgammon-app {
  width: min(1220px, calc(100% - 28px));
  margin: 0 auto;
  padding: 24px 0 44px;
}

.backgammon-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 13px 17px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 22px;
  background: rgba(247, 239, 222, 0.94);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

.backgammon-brand {
  display: inline-flex;
  align-items: center;
  gap: 13px;
  color: var(--ink);
  text-decoration: none;
}

.backgammon-brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 14px;
  background: linear-gradient(145deg, var(--gold), var(--rust));
  color: #fff9ed;
  font-weight: 950;
}

.backgammon-brand-copy {
  display: grid;
  gap: 2px;
}

.backgammon-brand-copy strong {
  color: var(--ink) !important;
  font-size: 1.04rem;
}

.backgammon-brand-copy span {
  color: var(--muted) !important;
  font-size: 0.86rem;
}

.backgammon-return,
.action-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.58);
  color: var(--ink);
  font-weight: 850;
  text-decoration: none;
  cursor: pointer;
}

.action-button.primary {
  border-color: transparent;
  background: linear-gradient(135deg, #dd985b, var(--rust));
  color: #fffaf1;
  box-shadow: 0 10px 24px rgba(135, 58, 38, 0.24);
}

.action-button:disabled {
  opacity: 0.42;
  cursor: not-allowed;
  box-shadow: none;
}

.backgammon-hero {
  display: grid;
  grid-template-columns: minmax(0, 0.88fr) minmax(390px, 1.12fr);
  gap: clamp(20px, 4vw, 54px);
  align-items: center;
  padding: clamp(24px, 3.7vw, 44px) 4px 14px;
}

.new-game-kicker,
.eyebrow {
  margin: 0 0 10px;
  color: rgba(255, 248, 235, 0.72);
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

.new-game-kicker span {
  display: inline-flex;
  align-items: center;
  min-height: 25px;
  margin-right: 6px;
  padding: 0 9px;
  border-radius: 999px;
  background: var(--gold);
  color: #312114;
}

.eyebrow.dark {
  color: var(--rust-deep);
}

.backgammon-copy h1,
.status-copy h2,
.turn-guide h2,
.backgammon-seo h2,
.result-overlay h2 {
  margin: 0;
  font-family: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", serif;
  line-height: 1.02;
}

.backgammon-copy h1 {
  max-width: 680px;
  color: #fff8eb;
  font-size: clamp(2.35rem, 5vw, 4.45rem);
  letter-spacing: -0.045em;
}

.backgammon-copy > p:not(.new-game-kicker) {
  max-width: 650px;
  margin: 19px 0 0;
  color: rgba(255, 248, 235, 0.72);
  font-size: clamp(1rem, 1.7vw, 1.16rem);
  line-height: 1.66;
}

.game-hero-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  margin-top: 20px;
}

.game-hero-links a {
  color: #f0ca89;
  font-size: 0.84rem;
  font-weight: 800;
  text-underline-offset: 4px;
}

.backgammon-controls-panel,
.backgammon-board-panel,
.player-card,
.turn-guide,
.backgammon-seo article {
  border: 1px solid rgba(255, 255, 255, 0.13);
  background: var(--paper);
  box-shadow: var(--shadow);
}

.backgammon-controls-panel {
  padding: 22px;
  border-radius: 28px;
}

.status-copy h2 {
  font-size: clamp(1.45rem, 2.4vw, 2rem);
}

.notice-text,
.mode-hint {
  margin: 7px 0 0;
  color: var(--muted);
  line-height: 1.5;
}

.setup-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(130px, 0.52fr);
  gap: 14px;
  align-items: end;
  margin-top: 17px;
}

.setup-label {
  display: block;
  margin: 0 0 7px;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 900;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.mode-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
}

.choice-pill {
  position: relative;
  cursor: pointer;
}

.choice-pill input {
  position: absolute;
  opacity: 0;
}

.choice-pill span,
.difficulty-select {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--paper-soft);
  color: var(--ink);
  font-weight: 800;
}

.choice-pill input:checked + span {
  border-color: rgba(46, 108, 94, 0.46);
  background: rgba(46, 108, 94, 0.13);
  box-shadow: inset 0 0 0 1px rgba(46, 108, 94, 0.12);
}

.choice-pill input:focus-visible + span,
.difficulty-select:focus-visible,
.action-button:focus-visible,
.backgammon-return:focus-visible {
  outline: 3px solid rgba(216, 167, 91, 0.4);
  outline-offset: 3px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 16px;
}

.metric-grid article {
  padding: 10px 12px;
  border-top: 1px solid var(--line);
}

.metric-grid span {
  display: block;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 800;
  text-transform: uppercase;
}

.metric-grid strong {
  display: block;
  margin-top: 3px;
  font-size: 1.22rem;
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.backgammon-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 255px;
  gap: 18px;
  align-items: start;
  margin-top: 8px;
}

.backgammon-board-panel {
  position: relative;
  min-width: 0;
  padding: clamp(10px, 1.8vw, 18px);
  border-radius: 30px;
  background:
    radial-gradient(circle at 50% 10%, rgba(255, 255, 255, 0.1), transparent 26%),
    linear-gradient(145deg, #875437, #4b2c20);
}

.backgammon-board-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(42px, 6vw, 62px);
  gap: 10px;
}

.backgammon-board {
  position: relative;
  min-width: 0;
  aspect-ratio: 1.55 / 1;
  overflow: hidden;
  border: clamp(7px, 1.2vw, 13px) solid var(--wood-deep);
  border-radius: 15px;
  background:
    linear-gradient(90deg, transparent 49.7%, rgba(61, 34, 24, 0.34) 49.7% 50.3%, transparent 50.3%),
    linear-gradient(#d5b879 49.7%, #7d4a31 49.7% 50.3%, #d5b879 50.3%);
  box-shadow:
    inset 0 0 0 2px rgba(255, 244, 214, 0.18),
    inset 0 0 28px rgba(75, 40, 27, 0.28);
}

.board-fold {
  position: absolute;
  z-index: 1;
  inset: 0 auto 0 calc(6 * (100% / 13));
  width: calc(100% / 13);
  border-inline: 2px solid rgba(63, 36, 26, 0.34);
  background:
    linear-gradient(90deg, rgba(63, 36, 26, 0.1), rgba(255, 238, 195, 0.12), rgba(63, 36, 26, 0.1));
  pointer-events: none;
}

.backgammon-point {
  position: absolute;
  z-index: 4;
  left: calc(var(--column) * (100% / 13));
  width: calc(100% / 13);
  height: 47%;
  padding: clamp(4px, 0.7vw, 8px) 2px;
  overflow: visible;
  border: 0;
  background: transparent;
  display: flex;
  align-items: center;
  flex-direction: column;
  cursor: default;
}

.backgammon-point.top {
  top: 0;
  justify-content: flex-start;
}

.backgammon-point.bottom {
  bottom: 0;
  justify-content: flex-end;
}

.backgammon-point::before {
  content: "";
  position: absolute;
  z-index: -1;
  inset: 0 5%;
  filter: drop-shadow(0 2px 1px rgba(55, 30, 21, 0.18));
}

.backgammon-point.top::before {
  clip-path: polygon(0 0, 100% 0, 50% 100%);
}

.backgammon-point.bottom::before {
  clip-path: polygon(50% 0, 100% 100%, 0 100%);
}

.backgammon-point.tone-light::before {
  background: linear-gradient(165deg, #eed39a, #cfaa68);
}

.backgammon-point.tone-dark::before {
  background: linear-gradient(165deg, #ae4f32, #7e3426);
}

.backgammon-point.is-source {
  cursor: pointer;
}

.backgammon-point.is-source::after,
.bar-slot.is-source::after {
  content: "";
  position: absolute;
  z-index: 8;
  width: clamp(8px, 1vw, 12px);
  height: clamp(8px, 1vw, 12px);
  border-radius: 50%;
  background: #f5d276;
  box-shadow: 0 0 0 4px rgba(245, 210, 118, 0.23);
}

.backgammon-point.top.is-source::after {
  top: 8px;
}

.backgammon-point.bottom.is-source::after {
  bottom: 8px;
}

.backgammon-point.is-selected .backgammon-checker,
.bar-slot.is-selected .backgammon-checker {
  box-shadow: 0 0 0 4px #f5d276, 0 7px 12px rgba(38, 20, 15, 0.32);
}

.backgammon-point.is-target::before {
  filter: brightness(1.22) drop-shadow(0 0 8px rgba(245, 210, 118, 0.7));
}

.backgammon-checker,
.player-checker {
  display: block;
  flex: 0 0 auto;
  width: clamp(22px, 4.7vw, 43px);
  aspect-ratio: 1;
  border-radius: 50%;
  box-shadow: 0 6px 11px rgba(38, 20, 15, 0.31);
}

.backgammon-checker + .backgammon-checker {
  margin-top: clamp(-11px, -1vw, -6px);
}

.backgammon-checker.white,
.player-checker.white {
  border: 2px solid #c6bca8;
  background:
    radial-gradient(circle at 34% 27%, #fffefa, #e8dfce 58%, #b9aa91);
}

.backgammon-checker.black,
.player-checker.black {
  border: 2px solid #182723;
  background:
    radial-gradient(circle at 34% 27%, #52675f, #1f332d 58%, #0b1714);
}

.backgammon-stack-count {
  position: relative;
  z-index: 9;
  display: grid;
  place-items: center;
  min-width: 22px;
  min-height: 22px;
  margin-top: -23px;
  border-radius: 999px;
  background: #dca65c;
  color: #211810;
  font-size: 0.7rem;
  font-weight: 950;
}

.backgammon-bar {
  position: absolute;
  z-index: 6;
  inset: 0 auto 0 calc(6 * (100% / 13));
  display: grid;
  grid-template-rows: 1fr auto 1fr;
  width: calc(100% / 13);
  padding: 8px 3px;
}

.bar-slot {
  position: relative;
  display: flex;
  align-items: center;
  flex-direction: column;
  min-width: 0;
  padding: 1px;
  border: 0;
  background: transparent;
}

.black-slot {
  justify-content: flex-start;
}

.white-slot {
  justify-content: flex-end;
}

.bar-slot.is-source {
  cursor: pointer;
}

.bar-slot.is-source::after {
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.bar-label {
  color: rgba(55, 31, 22, 0.66);
  font-size: clamp(0.48rem, 0.8vw, 0.64rem);
  font-weight: 950;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.dice-display {
  position: absolute;
  z-index: 12;
  top: 50%;
  left: 50%;
  display: flex;
  align-items: center;
  gap: 6px;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.backgammon-die {
  display: grid;
  place-items: center;
  width: clamp(28px, 4.4vw, 44px);
  aspect-ratio: 1;
  border: 1px solid rgba(64, 36, 24, 0.25);
  border-radius: 10px;
  background: #fff9eb;
  box-shadow: 0 6px 16px rgba(54, 30, 21, 0.25);
  color: #26322e;
  font-size: clamp(1.2rem, 2.8vw, 2rem);
  line-height: 1;
}

.backgammon-die.is-used {
  opacity: 0.34;
}

.double-badge {
  padding: 5px 8px;
  border-radius: 999px;
  background: #263f38;
  color: #fff8eb;
  font-size: 0.62rem;
  font-weight: 900;
}

.off-rail {
  display: grid;
  grid-template-rows: 1fr 1fr;
  gap: 8px;
  min-width: 0;
}

.off-slot {
  position: relative;
  display: flex;
  align-items: center;
  flex-direction: column;
  min-width: 0;
  padding: 6px 3px;
  overflow: hidden;
  border: 1px solid rgba(255, 233, 187, 0.15);
  border-radius: 12px;
  background: rgba(34, 19, 14, 0.32);
  color: #fff4df;
}

.black-off {
  justify-content: flex-start;
}

.white-off {
  justify-content: flex-end;
}

.off-slot.is-target {
  border-color: #f5d276;
  box-shadow: 0 0 0 3px rgba(245, 210, 118, 0.18);
  cursor: pointer;
}

.off-slot .backgammon-checker {
  width: min(80%, 38px);
}

.off-slot .off-label {
  color: rgba(255, 244, 223, 0.64);
  font-size: 0.58rem;
  font-weight: 900;
  text-transform: uppercase;
}

.off-slot strong {
  position: absolute;
  inset: 50% auto auto 50%;
  transform: translate(-50%, -50%);
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--gold);
  color: #26180f;
}

.backgammon-sidebar {
  display: grid;
  gap: 10px;
}

.player-card {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 11px;
  align-items: center;
  padding: 14px;
  border-radius: 19px;
  box-shadow: 0 16px 38px rgba(4, 14, 13, 0.2);
}

.player-card.active {
  border-color: rgba(216, 167, 91, 0.68);
  box-shadow: 0 0 0 3px rgba(216, 167, 91, 0.13), 0 16px 38px rgba(4, 14, 13, 0.2);
}

.player-checker {
  width: 36px;
}

.player-name,
.player-role {
  margin: 0;
}

.player-name {
  font-weight: 900;
}

.player-role,
.direction {
  color: var(--muted);
  font-size: 0.76rem;
}

.direction {
  font-weight: 800;
}

.turn-guide {
  margin-top: 3px;
  padding: 18px;
  border-radius: 22px;
  background: rgba(245, 237, 222, 0.94);
}

.turn-guide h2 {
  font-size: 1.5rem;
}

.turn-guide ol {
  margin: 13px 0 0;
  padding-left: 20px;
  line-height: 1.7;
}

.turn-guide > p:last-child {
  margin: 13px 0 0;
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.5;
}

.result-overlay {
  position: fixed;
  z-index: 120;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(4, 16, 14, 0.68);
  backdrop-filter: blur(6px);
}

.result-overlay[hidden] {
  display: none !important;
}

.result-overlay-card {
  width: min(440px, 100%);
  padding: 28px;
  border-radius: 28px;
  background: var(--paper);
  text-align: center;
  box-shadow: var(--shadow);
}

.overlay-kicker {
  margin: 0 0 8px;
  color: var(--rust);
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.11em;
  text-transform: uppercase;
}

.result-overlay h2 {
  font-size: 2.2rem;
}

.overlay-message {
  margin: 11px 0 20px;
  color: var(--muted);
  line-height: 1.55;
}

.backgammon-seo {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-top: 24px;
}

.backgammon-seo article {
  padding: clamp(20px, 3vw, 30px);
  border-radius: 26px;
  background: rgba(245, 237, 222, 0.95);
}

.backgammon-seo h2 {
  font-size: clamp(1.55rem, 3vw, 2.25rem);
}

.backgammon-seo p:not(.eyebrow),
.backgammon-seo li,
.backgammon-seo dd {
  color: var(--muted);
  line-height: 1.66;
}

.backgammon-seo ol {
  padding-left: 20px;
}

.backgammon-seo dt {
  margin-top: 12px;
  font-weight: 900;
}

.backgammon-seo dd {
  margin: 4px 0 0;
}

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

  .backgammon-copy {
    max-width: 800px;
  }

  .backgammon-layout {
    grid-template-columns: 1fr;
  }

  .backgammon-sidebar {
    grid-template-columns: 1fr 1fr;
  }

  .turn-guide {
    grid-column: 1 / -1;
  }
}

@media (max-width: 640px) {
  .backgammon-app {
    width: min(100% - 16px, 760px);
    padding-top: 8px;
  }

  .backgammon-topbar {
    padding: 9px 11px;
    border-radius: 17px;
  }

  .backgammon-brand-mark {
    width: 38px;
    height: 38px;
  }

  .backgammon-brand-copy span {
    display: none;
  }

  .backgammon-return {
    min-height: 38px;
    padding-inline: 12px;
    font-size: 0.78rem;
  }

  .backgammon-hero {
    gap: 16px;
    padding: 22px 2px 10px;
  }

  .backgammon-copy h1 {
    font-size: clamp(2.15rem, 12vw, 3.4rem);
  }

  .backgammon-copy > p:not(.new-game-kicker) {
    margin-top: 12px;
    font-size: 0.93rem;
    line-height: 1.5;
  }

  .game-hero-links {
    margin-top: 13px;
  }

  .backgammon-controls-panel {
    padding: 16px;
    border-radius: 21px;
  }

  .setup-panel {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .metric-grid {
    margin-top: 11px;
  }

  .metric-grid article {
    padding-inline: 5px;
  }

  .metric-grid span {
    font-size: 0.58rem;
  }

  .action-row {
    display: grid;
    grid-template-columns: 1.25fr 1fr 1fr;
  }

  .action-button {
    min-height: 41px;
    padding-inline: 9px;
    font-size: 0.75rem;
  }

  .backgammon-layout {
    margin-top: 2px;
  }

  .backgammon-board-panel {
    padding: 7px;
    border-radius: 20px;
  }

  .backgammon-board-shell {
    grid-template-columns: minmax(0, 1fr) 32px;
    gap: 5px;
  }

  .backgammon-board {
    border-width: 6px;
    border-radius: 10px;
  }

  .backgammon-checker {
    width: min(74%, 28px);
    border-width: 1px;
  }

  .backgammon-checker + .backgammon-checker {
    margin-top: -8px;
  }

  .backgammon-stack-count {
    min-width: 18px;
    min-height: 18px;
    margin-top: -18px;
    font-size: 0.58rem;
  }

  .dice-display {
    gap: 3px;
  }

  .backgammon-die {
    width: 27px;
    border-radius: 7px;
    font-size: 1.22rem;
  }

  .double-badge {
    display: none;
  }

  .off-slot {
    padding-inline: 1px;
  }

  .off-slot .off-label {
    font-size: 0.45rem;
  }

  .backgammon-sidebar {
    grid-template-columns: 1fr 1fr;
    gap: 7px;
  }

  .player-card {
    grid-template-columns: auto 1fr;
    padding: 10px;
  }

  .player-checker {
    width: 29px;
  }

  .direction {
    display: none;
  }

  .turn-guide {
    display: none;
  }

  .backgammon-seo {
    grid-template-columns: 1fr;
    margin-top: 16px;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    scroll-behavior: auto !important;
  }
}
