:root {
  color-scheme: light;
  font-family: "Segoe UI", system-ui, sans-serif;
  background: #f6efe4;
  color: #1e1a16;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
}

button {
  font: inherit;
}

.app {
  width: min(100%, 980px);
  margin: 0 auto;
  padding: 12px;
}

.topbar,
.controls,
.scorebar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.topbar h1 {
  margin: 0;
  font-size: 1.35rem;
}

.topbar p,
.message {
  margin: 4px 0 0;
}

.topbar button,
.controls button,
.modal-actions button {
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  padding: 0 14px;
  color: white;
  background: #236c5f;
  font-weight: 700;
}

.icon-button {
  width: 44px;
  padding: 0;
  font-size: 1.45rem;
  line-height: 1;
}

.topbar button.icon-button {
  padding: 0;
}

.controls button:disabled {
  opacity: 0.45;
}

.controls {
  margin: 10px 0;
  flex-wrap: wrap;
}

.dice {
  display: flex;
  gap: 6px;
  align-items: center;
  justify-content: center;
}

.die {
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  border-radius: 12px;
  background-color: rgb(255 255 255 / 76%);
  background-image: url("../assets/dice-glass-v2.png");
  background-position: center;
  background-repeat: no-repeat;
  background-size: 118%;
  border: 0;
  color: #2b1009;
  font-family: Georgia, "Palatino Linotype", "Times New Roman", serif;
  font-size: 1.88rem;
  font-weight: 900;
  line-height: 1;
  text-shadow: 0 1px 0 rgb(255 255 255 / 92%), 0 0 7px rgb(255 255 255 / 90%);
  box-shadow: 0 6px 15px rgb(0 0 0 / 24%);
}

.die.used {
  opacity: 0.28;
}

.message {
  flex-basis: 100%;
  min-height: 1.5em;
  color: #5f3218;
  font-weight: 700;
}

.scorebar {
  font-size: 0.92rem;
  margin-bottom: 8px;
  color: #1e1a16;
}

.board-wrap {
  position: relative;
  width: 100%;
}

.board-dice {
  justify-self: center;
  align-self: center;
  z-index: 20;
  padding: 5px 9px;
  min-width: 250px;
  min-height: 66px;
  border-radius: 12px;
  background: rgb(255 248 237 / 92%);
  border: 3px solid #d83b31;
  box-shadow: 0 8px 22px rgb(0 0 0 / 24%), 0 0 0 3px rgb(255 255 255 / 62%);
  pointer-events: none;
}

.board-dice.empty::after {
  content: "";
  width: 52px;
  height: 52px;
  border-radius: 12px;
  background-image: url("../assets/dice-glass-v2.png");
  background-position: center;
  background-repeat: no-repeat;
  background-size: 118%;
  opacity: 0.26;
}

.flow-guide {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 8px;
  margin: 7px 0;
  color: #1e1a16;
  font-size: 0.9rem;
  font-weight: 900;
}

.flow-guide span {
  white-space: nowrap;
}

.flow-guide strong {
  position: relative;
  display: block;
  min-height: 34px;
  padding: 7px 34px 7px 14px;
  color: white;
  text-align: center;
  background: #9a3f20;
  clip-path: polygon(0 50%, 28px 0, 100% 0, calc(100% - 12px) 50%, 100% 100%, 28px 100%);
  text-shadow: 0 1px 2px rgb(0 0 0 / 45%);
}

.black-guide strong {
  background: #252525;
}

.white-guide strong {
  background: #c5662d;
}

.board {
  position: relative;
  display: grid;
  grid-template-columns: repeat(6, 1fr) 0.78fr 0.78fr repeat(6, 1fr);
  grid-template-rows: minmax(178px, 34vh) minmax(178px, 34vh);
  gap: 5px;
  padding: 8px;
  border-radius: 8px;
  background: linear-gradient(90deg, #8f5d34, #c58a4d 47%, #8f5d34);
  box-shadow: 0 8px 28px rgb(38 25 16 / 22%);
}

.point,
.tray {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 0;
  border: 0;
  border-radius: 5px;
  padding: 18px 3px 5px;
  background: rgb(235 190 113 / 90%);
  overflow: hidden;
  touch-action: manipulation;
}

.point:nth-child(odd) {
  background: rgb(121 57 37 / 92%);
}

.boundary-after::after {
  content: "";
  position: absolute;
  top: -8px;
  right: -3px;
  bottom: -8px;
  z-index: 2;
  width: 7px;
  border-radius: 999px;
  background: rgb(37 25 22 / 86%);
  box-shadow: 0 0 0 1px rgb(255 248 237 / 45%);
  pointer-events: none;
}

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

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

.tray {
  justify-content: center;
  grid-row: span 2;
  background: #251916;
  color: #fff8ed;
}

.tray span:first-child,
.point-number {
  position: absolute;
  top: 3px;
  left: 4px;
  font-size: 0.72rem;
  font-weight: 700;
  opacity: 0.76;
}

.checker {
  display: block;
  width: min(34px, 8vw);
  height: min(34px, 8vw);
  min-width: 24px;
  min-height: 24px;
  margin: 2px auto;
  border-radius: 50%;
  border: 0;
  background-position: center;
  background-size: cover;
  box-shadow: 0 2px 5px rgb(0 0 0 / 30%);
}

.checker.player {
  background-image: url("../assets/white-checker.png");
}

.checker.cpu {
  background-image: url("../assets/black-checker.png");
}

.source,
.destination {
  outline: 0;
  filter: brightness(1.08);
}

.destination::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 36px;
  width: 34px;
  height: 34px;
  transform: translateX(-50%);
  border-radius: 999px;
  background: transparent;
  border: 4px solid #22c7ff;
  box-shadow: 0 0 0 2px rgb(6 37 55 / 35%), 0 4px 12px rgb(34 199 255 / 40%);
}

.destination.ring-on-checker::before {
  display: none;
}

.point.bottom.source::before,
.point.bottom.destination::before {
  top: auto;
  bottom: 36px;
}

.tray.source::before,
.tray.destination::before {
  top: 48%;
}

.ghost-destination {
  outline: 0;
}

.ghost-destination::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 36px;
  width: 56%;
  height: 18px;
  transform: translateX(-50%);
  border-radius: 999px;
  background: rgb(155 232 255 / 34%);
  box-shadow: 0 0 0 2px rgb(6 37 55 / 12%);
}

.point.bottom.ghost-destination::before {
  top: auto;
  bottom: 36px;
}

.tray.ghost-destination::before {
  top: 48%;
}

.checker {
  position: relative;
}

.checker.source-ring::after,
.checker.destination-ring::after,
.checker.moved-ring::before {
  content: "";
  position: absolute;
  inset: -3px;
  border-radius: 50%;
  pointer-events: none;
}

.checker.source-ring::after {
  border: 4px solid #ffd338;
  box-shadow: 0 0 0 2px rgb(35 25 12 / 22%), 0 3px 10px rgb(255 211 56 / 36%);
}

.checker.destination-ring::after {
  border: 4px solid #22c7ff;
  box-shadow: 0 0 0 2px rgb(6 37 55 / 22%), 0 3px 10px rgb(34 199 255 / 34%);
}

.checker.moved-ring::before {
  inset: -1px;
  border: 3px solid #e3342f;
  box-shadow: 0 1px 4px rgb(0 0 0 / 22%);
}

.selected {
  outline: 5px solid #28e06d;
  outline-offset: -6px;
}

.checker.ghost {
  position: fixed;
  z-index: 20;
  margin: 0;
  translate: -50% -50%;
  pointer-events: none;
  transition: transform 300ms cubic-bezier(.2, .75, .2, 1);
}

.rules {
  margin-top: 10px;
  border-radius: 8px;
  padding: 8px 10px;
  color: #1e1a16;
  background: #fff8ed;
  border: 1px solid #e2d3bc;
}

.rules summary {
  cursor: pointer;
  font-weight: 800;
}

.rules ul {
  margin: 8px 0 2px;
  padding-left: 1.25rem;
}

.rules li {
  margin: 5px 0;
  line-height: 1.45;
}

.seo-copy {
  margin-top: 12px;
  padding: 14px 0 4px;
  border-top: 1px solid #e2d3bc;
  color: #3a3128;
}

.seo-copy summary {
  cursor: pointer;
  font-weight: 800;
}

.seo-copy-body {
  padding-top: 8px;
}

.seo-copy h2 {
  margin: 12px 0 5px;
  font-size: 1rem;
}

.seo-copy p {
  margin: 0;
  line-height: 1.65;
  font-size: 0.92rem;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgb(0 0 0 / 46%);
}

.modal.hidden {
  display: none;
}

.modal-panel {
  width: min(100%, 380px);
  border-radius: 8px;
  padding: 18px;
  background: #fff8ed;
  box-shadow: 0 18px 48px rgb(0 0 0 / 34%);
}

.modal-panel h2 {
  margin: 0 0 8px;
  font-size: 1.15rem;
}

.modal-panel p {
  margin: 0 0 14px;
  line-height: 1.5;
}

.modal-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.modal-actions button:last-child {
  background: #7a2e2e;
}

.stack-count {
  display: inline-block;
  margin-top: 2px;
  padding: 1px 5px;
  border-radius: 999px;
  background: rgb(255 255 255 / 78%);
  color: #1e1a16;
  font-size: 0.78rem;
  font-weight: 800;
}

@media (max-width: 620px) {
  .app {
    width: 100%;
    padding: 5px;
  }

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

  .topbar h1 {
    font-size: 1rem;
  }

  .topbar p,
  .message,
  .scorebar {
    font-size: 0.76rem;
  }

  .topbar button {
    min-height: 34px;
    padding: 0 9px;
    font-size: 0.82rem;
  }

  .controls {
    margin: 4px 0;
  }

  #rollButton {
    display: none;
  }

  .undo-button {
    min-height: 32px;
    padding: 0 10px;
    font-size: 0.76rem;
  }

  .board {
    grid-template-columns: repeat(12, minmax(0, 1fr));
    grid-template-rows: 28px minmax(78px, 16vh) minmax(78px, 16vh) 28px;
    gap: 3px;
    padding: 4px;
  }

  .point,
  .tray {
    min-height: 0;
    padding-inline: 1px;
    padding-top: 15px;
    padding-bottom: 2px;
  }

  .tray {
    grid-row: auto;
    flex-direction: row;
    justify-content: flex-start;
    gap: 2px;
    padding: 2px 22px 2px 34px;
  }

  .tray.bar {
    grid-column: 1 / 13;
    grid-row: 1;
  }

  .tray.off {
    grid-column: 1 / 13;
    grid-row: 4;
  }

  .point.top {
    grid-row: 2;
  }

  .point.bottom {
    grid-row: 3;
  }

  .tray span:first-child,
  .point-number {
    font-size: 0.64rem;
  }

  .checker {
    width: clamp(18px, 5.7vw, 24px);
    height: clamp(18px, 5.7vw, 24px);
    min-width: 18px;
    min-height: 18px;
    margin: 1px auto;
  }

  .point .checker + .checker {
    margin-top: -10px;
  }

  .tray .checker {
    margin: 0 -3px 0 0;
  }

  .stack-count {
    margin-top: 0;
    font-size: 0.66rem;
  }

  .scorebar {
    display: grid;
    grid-template-columns: 1fr;
    gap: 2px;
  }

  .die {
    width: 40px;
    height: 40px;
    font-size: 1.55rem;
  }

  .board-dice {
    padding: 3px 6px;
    min-width: 194px;
    min-height: 52px;
    border-radius: 10px;
    border-width: 2px;
  }

  .board-dice.empty::after {
    width: 40px;
    height: 40px;
  }

  .flow-guide {
    grid-template-columns: auto 1fr auto;
    gap: 4px;
    margin: 3px 0;
    font-size: 0.74rem;
  }

  .flow-guide span {
    font-size: 0.7rem;
  }

  .flow-guide strong {
    min-height: 24px;
    padding-block: 4px;
  }

  .destination::before {
    top: 25px;
    width: 24px;
    height: 24px;
    border-width: 3px;
  }

  .point.bottom.source::before,
  .point.bottom.destination::before {
    bottom: 30px;
  }

  .tray.source::before,
  .tray.destination::before,
  .tray.ghost-destination::before {
    left: auto;
    right: 5px;
    top: 50%;
    width: 18px;
    height: 18px;
    transform: translateY(-50%);
  }

  .ghost-destination::before {
    top: 30px;
    width: 64%;
    height: 12px;
  }

  .point.bottom.ghost-destination::before {
    bottom: 30px;
  }

  .checker.source-ring::after,
  .checker.destination-ring::after {
    inset: -2px;
    border-width: 3px;
  }

  .checker.moved-ring::before {
    inset: -1px;
    border-width: 2px;
  }

  .boundary-after::after {
    top: -4px;
    right: -3px;
    bottom: -4px;
    width: 5px;
  }

  .rules {
    margin-top: 5px;
    padding: 5px 8px;
    font-size: 0.78rem;
  }

  .seo-copy {
    margin-top: 7px;
    padding-top: 8px;
  }

  .seo-copy h2 {
    margin: 8px 0 3px;
    font-size: 0.86rem;
  }

  .seo-copy p {
    font-size: 0.76rem;
    line-height: 1.55;
  }

  .modal-actions {
    grid-template-columns: 1fr;
  }
}
