:root {
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --page-pad-top: max(12px, var(--safe-top));
  --page-pad-right: max(12px, var(--safe-right));
  --page-pad-bottom: max(12px, var(--safe-bottom));
  --page-pad-left: max(12px, var(--safe-left));
  --page: #efe5d3;
  --page-shadow: rgba(42, 24, 11, 0.18);
  --ink: #21160f;
  --muted: #6d5a49;
  --panel: rgba(254, 248, 238, 0.92);
  --panel-strong: rgba(255, 250, 242, 0.97);
  --panel-line: rgba(88, 56, 29, 0.14);
  --board-wood: #7a4c31;
  --board-wood-dark: #5a331e;
  --felt: #1f4b3d;
  --felt-dark: #143227;
  --triangle-light: #efc789;
  --triangle-dark: #823c2b;
  --highlight: #ffb000;
  --highlight-soft: rgba(255, 176, 0, 0.18);
  --danger: #b53b24;
  --white-checker: linear-gradient(180deg, #fffaf0, #dbcdb3);
  --black-checker: linear-gradient(180deg, #364445, #151d1e);
  --font-display: "Avenir Next", "Gill Sans", sans-serif;
  --font-ui: "Trebuchet MS", "Avenir Next", sans-serif;
  --board-ratio: 1.7357859532;
  --board-max-width: 1020px;
  --off-rail-width: clamp(72px, 10vw, 114px);
  --board-stage-gap: clamp(8px, 1vw, 14px);
  --board-padding: clamp(8px, 1.2vw, 14px);
  --board-gap-x: clamp(3px, 0.7vw, 8px);
  --board-gap-y: clamp(4px, 0.9vw, 10px);
  --board-radius: clamp(20px, 2.3vw, 28px);
  --board-inner-radius: clamp(12px, 1.6vw, 18px);
  --board-bar-width: clamp(28px, 6vw, 70px);
  --point-inset: clamp(2px, 0.55vw, 7px);
  --point-edge-offset: clamp(8px, 1.6vw, 18px);
  --point-target-inset: clamp(4px, 0.8vw, 8px);
  --point-label-font-size: clamp(0.48rem, 1.3vw, 0.78rem);
  --point-label-padding-y: clamp(2px, 0.35vw, 3px);
  --point-label-padding-x: clamp(4px, 0.75vw, 8px);
  --stack-offset: clamp(6px, 1.35vw, 14px);
  --checker-size: clamp(18px, 4.8vw, 56px);
  --checker-overlap: calc(var(--checker-size) * -0.38);
  --tray-min-height: clamp(112px, 18vw, 188px);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--page);
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  padding: var(--page-pad-top) var(--page-pad-right) var(--page-pad-bottom) var(--page-pad-left);
  background:
    radial-gradient(circle at top left, rgba(255, 176, 0, 0.22), transparent 18%),
    radial-gradient(circle at bottom right, rgba(31, 75, 61, 0.24), transparent 18%),
    linear-gradient(180deg, #f6ecdd, var(--page));
  color: var(--ink);
  font-family: var(--font-ui);
  overflow-x: hidden;
  overscroll-behavior: none;
}

body,
button,
select,
input {
  touch-action: manipulation;
}

button,
select,
input {
  font: inherit;
}

.app-shell {
  width: 100%;
  min-height: calc(100dvh - var(--page-pad-top) - var(--page-pad-bottom));
  margin: 0 auto;
}

.table-shell {
  display: grid;
  gap: 14px;
  position: relative;
  min-height: calc(100dvh - var(--page-pad-top) - var(--page-pad-bottom));
  align-content: center;
  justify-items: center;
}

.board-stage {
  --board-width: calc(var(--stage-height) * var(--board-ratio));
  --point-base-width: calc(
    (var(--board-width) - (2 * var(--board-padding)) - var(--board-bar-width) - (11 * var(--board-gap-x))) / 12
  );
  --checker-size-board: clamp(18px, calc(var(--point-base-width) - (2 * var(--point-inset))), 64px);
  --stage-height-fit-width: calc(
    (100vw - var(--page-pad-left) - var(--page-pad-right) - var(--off-rail-width) - var(--board-stage-gap))
    / var(--board-ratio)
  );
  --stage-height: min(
    calc(100dvh - var(--page-pad-top) - var(--page-pad-bottom)),
    var(--stage-height-fit-width)
  );
  display: grid;
  grid-template-columns: auto minmax(0, var(--off-rail-width));
  gap: var(--board-stage-gap);
  width: calc(var(--stage-height) * var(--board-ratio) + var(--off-rail-width) + var(--board-stage-gap));
  max-width: 100%;
  height: var(--stage-height);
  max-height: calc(100dvh - var(--page-pad-top) - var(--page-pad-bottom));
  margin: 0 auto;
  align-items: stretch;
  justify-content: center;
}

.board-stage__center {
  position: relative;
  width: fit-content;
  height: 100%;
  min-width: 0;
  min-height: 0;
  justify-self: center;
}

.hud-button,
.popup-action,
.primary-action,
.popup-close,
.mode-choice,
.field select {
  appearance: none;
  border: 1px solid rgba(88, 56, 29, 0.14);
  border-radius: 16px;
  min-height: 48px;
  color: var(--ink);
}

.hud-button,
.popup-action,
.primary-action,
.popup-close,
.mode-choice {
  cursor: pointer;
}

.hud-button {
  min-width: 80px;
  padding: 0 16px;
  background: rgba(255, 251, 244, 0.86);
  box-shadow: 0 14px 24px rgba(47, 27, 12, 0.12);
  backdrop-filter: blur(14px);
  font-weight: 700;
}

.hud-button--alert {
  border-color: rgba(181, 59, 36, 0.34);
  box-shadow:
    0 14px 24px rgba(47, 27, 12, 0.12),
    0 0 0 4px rgba(181, 59, 36, 0.1);
}

.board-grid {
  position: relative;
  display: grid;
  width: auto;
  height: 100%;
  max-width: none;
  aspect-ratio: var(--board-ratio);
  grid-template-columns: repeat(6, minmax(0, 1fr)) var(--board-bar-width) repeat(6, minmax(0, 1fr));
  grid-template-rows: repeat(2, minmax(0, 1fr));
  gap: var(--board-gap-y) var(--board-gap-x);
  padding: var(--board-padding);
  border-radius: var(--board-radius);
  overflow: hidden;
  isolation: isolate;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.06), rgba(0, 0, 0, 0.12)),
    linear-gradient(135deg, var(--board-wood), var(--board-wood-dark));
  box-shadow:
    inset 0 0 0 1px rgba(255, 236, 214, 0.1),
    0 24px 42px rgba(49, 27, 12, 0.24);
}

.board-grid::after {
  content: "";
  position: absolute;
  inset: var(--board-padding);
  z-index: 0;
  border-radius: var(--board-inner-radius);
  background:
    linear-gradient(180deg, rgba(31, 75, 61, 0.96), rgba(20, 50, 39, 0.98));
  box-shadow: inset 0 0 0 2px rgba(255, 236, 214, 0.08);
}

.board-grid > * {
  position: relative;
  z-index: 2;
}

.board-mark {
  position: absolute;
  top: 50%;
  z-index: 1;
  width: clamp(112px, 15vw, 188px);
  aspect-ratio: 1;
  pointer-events: none;
  background: url("/bg_logo.png") center / contain no-repeat;
  opacity: 1;
  transform: translate(-50%, -50%);
}

.board-mark--left {
  left: calc(var(--board-padding) + (((6 * var(--point-base-width)) + (5 * var(--board-gap-x))) / 2));
}

.board-mark--right {
  left: calc(
    var(--board-padding) +
    (6 * var(--point-base-width)) +
    (5 * var(--board-gap-x)) +
    var(--board-gap-x) +
    var(--board-bar-width) +
    var(--board-gap-x) +
    (((6 * var(--point-base-width)) + (5 * var(--board-gap-x))) / 2)
  );
  transform: translate(-50%, -50%) rotate(180deg);
}

.board-overlay {
  position: absolute;
  inset: var(--board-padding);
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr)) var(--board-bar-width) repeat(6, minmax(0, 1fr));
  grid-template-rows: repeat(2, minmax(0, 1fr));
  gap: var(--board-gap-y) var(--board-gap-x);
  pointer-events: none;
  z-index: 3;
}

.board-dice-pocket {
  grid-row: 1 / span 2;
  align-self: stretch;
  justify-self: stretch;
  position: relative;
  z-index: 1;
  overflow: hidden;
}

.board-dice-pocket--engine {
  grid-column: 1 / span 6;
}

.board-dice-pocket--human {
  grid-column: 8 / span 6;
}

.board-dice-pocket--active {
  filter: drop-shadow(0 10px 18px rgba(20, 9, 6, 0.28));
}

.board-action-stack {
  grid-column: 6 / span 3;
  grid-row: 1 / span 2;
  align-self: center;
  justify-self: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  pointer-events: none;
}

.board-action-button {
  pointer-events: auto;
  appearance: none;
  border: 1px solid rgba(96, 56, 19, 0.22);
  border-radius: 999px;
  min-height: clamp(56px, 8vw, 72px);
  padding: 0 clamp(22px, 4vw, 34px);
  background:
    linear-gradient(180deg, rgba(255, 250, 240, 0.98), rgba(245, 216, 166, 0.96));
  box-shadow:
    0 18px 34px rgba(53, 29, 12, 0.24),
    inset 0 2px 0 rgba(255, 255, 255, 0.72);
  color: #50341f;
  font-weight: 800;
  font-size: clamp(0.95rem, 2vw, 1.15rem);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  cursor: pointer;
}

.board-action-button--primary {
  animation: rollPulse 1.2s ease-in-out infinite alternate;
}

.board-action-button--secondary {
  min-height: clamp(42px, 6.2vw, 54px);
  padding: 0 clamp(18px, 3vw, 26px);
  background: linear-gradient(180deg, rgba(245, 232, 207, 0.96), rgba(220, 189, 138, 0.94));
  font-size: clamp(0.8rem, 1.6vw, 0.95rem);
  letter-spacing: 0.05em;
}

.board-action-button:hover {
  transform: translateY(-1px);
}

.board-dice {
  position: relative;
  width: 100%;
  height: 100%;
  opacity: 0;
  transition: opacity 180ms ease;
}

.board-dice--visible {
  opacity: 1;
}

.die {
  position: absolute;
  top: 0;
  left: 0;
  display: grid;
  place-items: center;
  width: clamp(38px, 5vw, 52px);
  height: clamp(38px, 5vw, 52px);
  border-radius: 14px;
  background: linear-gradient(180deg, #ff8d7f, #b51a20);
  border: 1px solid rgba(101, 8, 12, 0.3);
  box-shadow:
    inset 0 2px 0 rgba(255, 232, 232, 0.42),
    0 14px 24px rgba(80, 9, 12, 0.28);
  font-weight: 800;
  color: #fff8f6;
  will-change: transform;
}

.die__value {
  display: block;
  min-width: 1ch;
  text-align: center;
}

.die--rolling {
  filter: saturate(1.08) brightness(1.02);
}

.die--ghost {
  color: var(--muted);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.6), rgba(232, 214, 188, 0.6));
}

.off-rail {
  display: grid;
  grid-template-rows: 1fr auto 1fr;
  height: 100%;
  gap: calc(var(--board-gap-y) + 4px);
  padding: var(--board-padding);
  border-radius: var(--board-radius);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.06), rgba(0, 0, 0, 0.12)),
    linear-gradient(135deg, var(--board-wood), var(--board-wood-dark));
  box-shadow:
    inset 0 0 0 1px rgba(255, 236, 214, 0.1),
    0 24px 42px rgba(49, 27, 12, 0.24);
}

.off-slot {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
  padding: clamp(10px, 1vw, 14px) clamp(8px, 0.8vw, 12px);
  border-radius: calc(var(--board-inner-radius) * 1.05);
  background: linear-gradient(180deg, rgba(31, 75, 61, 0.94), rgba(20, 50, 39, 0.98));
  box-shadow: inset 0 0 0 2px rgba(255, 236, 214, 0.08);
}

.off-slot--engine {
  justify-content: flex-start;
}

.off-slot--human {
  justify-content: flex-start;
}

.off-rail__menu {
  display: flex;
  align-items: center;
  justify-content: center;
}

.off-rail__menu .hud-button {
  min-width: 0;
  width: 100%;
  padding: 0 10px;
}

.off-slot__label {
  margin: 0;
  color: rgba(255, 246, 232, 0.84);
  font-size: clamp(0.6rem, 0.75vw, 0.78rem);
  font-weight: 800;
  letter-spacing: 0.08em;
  text-align: center;
  text-transform: uppercase;
}

.status-popup {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 7;
  width: min(84%, 420px);
  padding: 14px 16px;
  border-radius: 20px;
  background: rgba(255, 250, 242, 0.9);
  border: 1px solid rgba(88, 56, 29, 0.14);
  box-shadow:
    0 20px 42px rgba(40, 22, 9, 0.22),
    inset 0 1px 0 rgba(255, 255, 255, 0.54);
  backdrop-filter: blur(18px);
  pointer-events: none;
  text-align: center;
  transform: translate(-50%, -50%);
}

.status-popup[hidden] {
  display: none !important;
}

.status-popup__title,
.status-popup__copy {
  margin: 0;
}

.status-popup__title {
  font-family: var(--font-display);
  font-size: clamp(1rem, 1.9vw, 1.3rem);
  font-weight: 700;
}

.status-popup__copy {
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.4;
}

.status-popup.status-popup--compact {
  top: clamp(16px, 2.4vw, 24px);
  width: auto;
  max-width: calc(100% - 24px);
  padding: 8px 12px;
  border-radius: 999px;
  transform: translateX(-50%);
  background: rgba(255, 250, 242, 0.82);
  box-shadow:
    0 14px 28px rgba(40, 22, 9, 0.16),
    inset 0 1px 0 rgba(255, 255, 255, 0.5);
}

.status-popup.status-popup--compact .status-popup__title {
  font-size: clamp(0.78rem, 1.15vw, 0.92rem);
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.status-popup.status-popup--compact .status-popup__copy {
  display: none;
}

.board-popup {
  position: absolute;
  z-index: 8;
  padding: 16px;
  border-radius: 22px;
  background: rgba(255, 250, 242, 0.94);
  border: 1px solid rgba(88, 56, 29, 0.14);
  box-shadow:
    0 26px 60px rgba(40, 22, 9, 0.28),
    inset 0 1px 0 rgba(255, 255, 255, 0.52);
  backdrop-filter: blur(18px);
}

.board-popup[hidden],
.debug-panel[hidden] {
  display: none !important;
}

.board-popup--setup {
  top: 50%;
  left: 50%;
  width: min(92%, 470px);
  transform: translate(-50%, -50%);
}

.board-popup--tools {
  top: 50%;
  left: 50%;
  width: min(92%, 460px);
  max-height: calc(100% - 20px);
  overflow: auto;
  transform: translate(-50%, -50%);
}

.board-popup__header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
}

.board-popup__eyebrow {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.board-popup__title {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(1.35rem, 3vw, 2rem);
  line-height: 1;
}

.board-popup__text {
  margin: 12px 0 0;
  color: var(--muted);
  line-height: 1.45;
}

.popup-close {
  min-width: 78px;
  padding: 0 14px;
  background: rgba(255, 255, 255, 0.6);
  font-weight: 700;
}

.popup-copy {
  display: grid;
  gap: 8px;
  margin-top: 14px;
}

.popup-copy__line {
  margin: 0;
  color: var(--muted);
  line-height: 1.4;
}

.popup-copy__line--error {
  color: var(--danger);
  font-weight: 700;
}

.popup-copy__line--error:empty {
  display: none;
}

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

.popup-actions--single {
  grid-template-columns: 1fr;
  margin-top: 10px;
}

.popup-action,
.primary-action {
  padding: 0 16px;
  background: linear-gradient(180deg, #fffaf0, #ead5b2);
  font-weight: 700;
}

.popup-action--primary,
.primary-action {
  background: linear-gradient(180deg, #2d7e5c, #1a5640);
  color: #f8ecd6;
  border-color: rgba(26, 86, 64, 0.26);
}

.popup-action[aria-pressed="true"] {
  background: linear-gradient(180deg, #4d5d61, #2f393b);
  color: #f8ecd6;
  border-color: rgba(47, 57, 59, 0.28);
}

.setup-form {
  display: grid;
  gap: 14px;
}

.setup-choice-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.mode-choice {
  display: grid;
  gap: 4px;
  place-items: center;
  padding: 14px 12px;
  background: rgba(255, 255, 255, 0.6);
  text-align: center;
  font-weight: 700;
}

.mode-choice--selected {
  background: linear-gradient(180deg, rgba(31, 75, 61, 0.94), rgba(20, 50, 39, 0.98));
  color: #f9ecd8;
  border-color: rgba(20, 50, 39, 0.34);
}

.setup-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.field {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.88rem;
}

.field span {
  color: var(--ink);
  font-weight: 700;
}

.field select {
  width: 100%;
  padding: 0 14px;
  background: rgba(255, 255, 255, 0.76);
}

.invite-card {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid rgba(88, 56, 29, 0.1);
}

.invite-card__row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
}

.invite-card__input {
  width: 100%;
  min-height: 48px;
  padding: 0 14px;
  border: 1px solid rgba(88, 56, 29, 0.14);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.76);
  color: var(--ink);
}

.invite-card__button {
  min-width: 84px;
}

.point {
  position: relative;
  display: flex;
  align-items: stretch;
  justify-content: center;
  border: 0;
  padding: 0;
  background: transparent;
}

.point::before {
  content: "";
  position: absolute;
  left: var(--point-inset);
  right: var(--point-inset);
  filter: drop-shadow(0 8px 12px rgba(0, 0, 0, 0.18));
}

.point--top::before {
  top: 0;
  bottom: var(--point-edge-offset);
  clip-path: polygon(50% 100%, 0 0, 100% 0);
}

.point--bottom::before {
  top: var(--point-edge-offset);
  bottom: 0;
  clip-path: polygon(50% 0, 0 100%, 100% 100%);
}

.point--light::before {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.16), rgba(0, 0, 0, 0.1)), var(--triangle-light);
}

.point--dark::before {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.08), rgba(0, 0, 0, 0.16)), var(--triangle-dark);
}

.point--target::after {
  content: "";
  position: absolute;
  inset: var(--point-target-inset);
  border-radius: calc(var(--board-inner-radius) * 1.25);
  pointer-events: none;
  background: var(--highlight-soft);
  box-shadow: inset 0 0 0 2px rgba(255, 176, 0, 0.45);
}

.point.surface--hint-source::after,
.point.surface--hint-target::after,
.point.surface--hint-both::after {
  content: "";
  position: absolute;
  inset: var(--point-target-inset);
  border-radius: calc(var(--board-inner-radius) * 1.25);
  pointer-events: none;
  animation: surfaceHintPulse 1.1s ease-in-out infinite alternate;
}

.point.surface--hint-source::after {
  background: rgba(255, 248, 232, 0.08);
  box-shadow: inset 0 0 0 2px rgba(255, 248, 232, 0.42);
}

.point.surface--hint-target::after {
  background: rgba(255, 176, 0, 0.18);
  box-shadow: inset 0 0 0 2px rgba(255, 176, 0, 0.62);
}

.point.surface--hint-both::after {
  background: linear-gradient(180deg, rgba(255, 248, 232, 0.12), rgba(255, 176, 0, 0.18));
  box-shadow:
    inset 0 0 0 2px rgba(255, 248, 232, 0.36),
    inset 0 0 0 5px rgba(255, 176, 0, 0.26);
}

.point.surface--move-source::after,
.point.surface--move-target::after {
  content: "";
  position: absolute;
  inset: var(--point-target-inset);
  border-radius: calc(var(--board-inner-radius) * 1.25);
  pointer-events: none;
  animation: surfacePulse 420ms ease-in-out infinite alternate;
}

.point.surface--move-source::after {
  background: rgba(255, 248, 232, 0.1);
  box-shadow: inset 0 0 0 2px rgba(255, 248, 232, 0.42);
}

.point.surface--move-target::after {
  background: var(--highlight-soft);
  box-shadow: inset 0 0 0 2px rgba(255, 176, 0, 0.5);
}

.point__label {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  padding: var(--point-label-padding-y) var(--point-label-padding-x);
  border-radius: 999px;
  background: rgba(22, 18, 14, 0.42);
  color: rgba(255, 248, 237, 0.86);
  font-size: var(--point-label-font-size);
  font-weight: 700;
  line-height: 1;
}

.point--top .point__label {
  top: clamp(4px, 0.8vw, 8px);
}

.point--bottom .point__label {
  bottom: clamp(4px, 0.8vw, 8px);
}

.point__stack {
  position: absolute;
  left: 50%;
  display: flex;
  align-items: center;
  gap: 0;
  transform: translateX(-50%);
}

.point--top .point__stack {
  top: var(--stack-offset);
  flex-direction: column;
}

.point--bottom .point__stack {
  bottom: var(--stack-offset);
  flex-direction: column-reverse;
}

.point__stack--draggable {
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.point__stack--selected .checker--lead,
.point__stack--source .checker--lead,
.bar-slot--source .checker--lead {
  box-shadow:
    0 0 0 3px rgba(255, 176, 0, 0.72),
    0 16px 20px rgba(0, 0, 0, 0.2);
}

.checker {
  position: relative;
  width: var(--checker-size-board, var(--checker-size));
  height: var(--checker-size-board, var(--checker-size));
  margin-top: var(--checker-overlap);
  border-radius: 50%;
  border: clamp(1px, 0.24vw, 2px) solid rgba(36, 22, 13, 0.22);
  box-shadow: 0 12px 18px rgba(0, 0, 0, 0.16);
}

.point--bottom .checker {
  margin-top: 0;
  margin-bottom: var(--checker-overlap);
}

.point__stack .checker:first-child,
.bar-slot__stack .checker:first-child,
.tray-slot__stack .checker:first-child {
  margin-top: 0;
}

.point--bottom .point__stack .checker:first-child,
.bar-slot--bottom .bar-slot__stack .checker:first-child {
  margin-bottom: 0;
}

.checker--white {
  background: var(--white-checker);
}

.checker--black {
  background: var(--black-checker);
  border-color: rgba(255, 255, 255, 0.08);
}

.checker--drag-preview {
  position: fixed;
  top: -120px;
  left: -120px;
  margin: 0;
  pointer-events: none;
  z-index: 9999;
}

.checker--pointer-drag {
  position: fixed;
  top: 0;
  left: 0;
  margin: 0;
  pointer-events: none;
  z-index: 10001;
  box-shadow: 0 22px 36px rgba(0, 0, 0, 0.28);
  will-change: transform;
}

.checker--remote-drag {
  opacity: 0.94;
  filter: saturate(0.88);
}

.checker--move-token {
  position: fixed;
  top: 0;
  left: 0;
  margin: 0;
  pointer-events: none;
  z-index: 10000;
  box-shadow: 0 18px 30px rgba(0, 0, 0, 0.26);
  will-change: transform, opacity;
}

.checker--moving-away {
  opacity: 0;
}

.checker__count {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: clamp(0.52rem, 1.4vw, 0.95rem);
  color: #fff7e9;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.42);
}

.checker--white .checker__count {
  color: #4d3322;
  text-shadow: none;
}

.bar-lane {
  grid-column: 7;
  grid-row: 1 / span 2;
  display: grid;
  grid-template-rows: 1fr 1fr;
  gap: calc(var(--board-gap-y) + 2px);
  padding: clamp(6px, 0.9vw, 10px);
  border-radius: clamp(16px, 2vw, 22px);
  background: linear-gradient(180deg, rgba(255, 252, 246, 0.16), rgba(0, 0, 0, 0.18));
  box-shadow: inset 0 0 0 1px rgba(255, 245, 226, 0.08);
}

.bar-slot {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: clamp(12px, 1.6vw, 18px);
  background: rgba(255, 248, 236, 0.08);
}

.bar-slot--source {
  box-shadow: inset 0 0 0 2px rgba(255, 176, 0, 0.4);
}

.bar-slot.surface--move-source,
.bar-slot.surface--move-target,
.tray-slot.surface--move-source,
.tray-slot.surface--move-target {
  animation: surfacePulse 420ms ease-in-out infinite alternate;
}

.bar-slot.surface--hint-source,
.bar-slot.surface--hint-target,
.bar-slot.surface--hint-both,
.tray-slot.surface--hint-source,
.tray-slot.surface--hint-target,
.tray-slot.surface--hint-both {
  animation: surfaceHintPulse 1.1s ease-in-out infinite alternate;
}

.bar-slot.surface--move-source,
.bar-slot.surface--hint-source,
.tray-slot.surface--move-source,
.tray-slot.surface--hint-source {
  box-shadow:
    inset 0 0 0 2px rgba(255, 247, 225, 0.4),
    0 0 22px rgba(255, 247, 225, 0.12);
}

.bar-slot.surface--move-target,
.bar-slot.surface--hint-target,
.tray-slot.surface--move-target,
.tray-slot.surface--hint-target {
  box-shadow:
    inset 0 0 0 2px rgba(255, 176, 0, 0.48),
    0 0 24px rgba(255, 176, 0, 0.16);
}

.bar-slot.surface--hint-both,
.tray-slot.surface--hint-both {
  box-shadow:
    inset 0 0 0 2px rgba(255, 248, 232, 0.34),
    inset 0 0 0 5px rgba(255, 176, 0, 0.22),
    0 0 24px rgba(255, 176, 0, 0.12);
}

.bar-slot__label {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  padding: var(--point-label-padding-y) var(--point-label-padding-x);
  border-radius: 999px;
  background: rgba(22, 18, 14, 0.46);
  color: rgba(255, 246, 232, 0.86);
  font-size: clamp(0.46rem, 1.2vw, 0.72rem);
  font-weight: 700;
  line-height: 1;
  white-space: nowrap;
}

.bar-slot--top .bar-slot__label {
  top: clamp(4px, 0.8vw, 8px);
}

.bar-slot--bottom .bar-slot__label {
  bottom: clamp(4px, 0.8vw, 8px);
}

.bar-slot__stack {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
}

.bar-slot--bottom .bar-slot__stack {
  flex-direction: column-reverse;
}

.tray-slot {
  min-height: var(--tray-min-height);
  padding: clamp(10px, 1.2vw, 14px) clamp(8px, 0.9vw, 10px);
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(124, 77, 46, 0.08), rgba(93, 52, 29, 0.16));
  border: 1px solid rgba(79, 49, 25, 0.1);
}

.tray-slot--board {
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  flex: 1;
  min-height: 0;
  width: 100%;
}

.tray-slot--target {
  box-shadow: inset 0 0 0 2px rgba(255, 176, 0, 0.4);
}

.tray-slot__stack {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
}

.tray-slot__stack .checker {
  margin-top: calc(var(--checker-size) * -0.1);
}

.tray-slot__stack--top {
  margin-bottom: auto;
}

.tray-slot__stack--bottom {
  margin-top: auto;
}

.debug-panel {
  padding: 16px;
  border-radius: 24px;
  background: rgba(255, 251, 244, 0.76);
  border: 1px solid rgba(88, 56, 29, 0.1);
  box-shadow: 0 18px 36px rgba(47, 27, 12, 0.12);
}

.debug-panel__header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.debug-panel__eyebrow,
.debug-panel__copy {
  margin: 0;
}

.debug-panel__eyebrow {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.debug-panel__copy {
  color: var(--muted);
  font-size: 0.9rem;
}

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

.panel {
  padding: 16px;
  border-radius: 20px;
  background: var(--panel);
  border: 1px solid rgba(88, 56, 29, 0.1);
}

.panel h3 {
  margin: 0 0 10px;
  font-family: var(--font-display);
  font-size: 1.12rem;
}

.panel-copy {
  margin: 0;
  line-height: 1.5;
  color: var(--muted);
}

.turn-list,
.log-list {
  margin: 0;
  padding-left: 18px;
  display: grid;
  gap: 10px;
}

.turn-list li,
.log-list li {
  line-height: 1.45;
}

.turn-list li {
  color: var(--muted);
}

.turn-list li.turn-list__item--active {
  color: var(--ink);
  font-weight: 700;
}

.log-list li {
  color: var(--ink);
}

.board-empty {
  display: grid;
  grid-column: 1 / -1;
  grid-row: 1 / -1;
  place-items: center;
  padding: 18px;
  color: rgba(255, 246, 232, 0.78);
  font-size: clamp(0.88rem, 2vw, 1.04rem);
  text-align: center;
}

button:disabled,
select:disabled,
input:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.rotate-overlay {
  display: none;
}

.rotate-overlay__card {
  width: min(92vw, 360px);
  padding: 24px 22px;
  border-radius: 24px;
  background: rgba(255, 250, 242, 0.96);
  border: 1px solid rgba(88, 56, 29, 0.14);
  box-shadow:
    0 26px 54px rgba(40, 22, 9, 0.24),
    inset 0 1px 0 rgba(255, 255, 255, 0.56);
  text-align: center;
}

.rotate-overlay__eyebrow,
.rotate-overlay__title,
.rotate-overlay__copy {
  margin: 0;
}

.rotate-overlay__eyebrow {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.rotate-overlay__title {
  margin-top: 10px;
  font-family: var(--font-display);
  font-size: clamp(1.7rem, 7vw, 2.35rem);
  line-height: 1;
}

.rotate-overlay__copy {
  margin-top: 12px;
  color: var(--muted);
  line-height: 1.45;
}

@keyframes surfacePulse {
  from {
    transform: scale(1);
    opacity: 0.88;
  }

  to {
    transform: scale(1.02);
    opacity: 1;
  }
}

@keyframes surfaceHintPulse {
  from {
    transform: scale(1);
    opacity: 0.78;
  }

  to {
    transform: scale(1.015);
    opacity: 1;
  }
}

@keyframes dieFloat {
  from {
    transform: translateY(-2px) rotate(-7deg);
  }

  to {
    transform: translateY(2px) rotate(7deg);
  }
}

@keyframes dieRoll {
  0% {
    transform: translateY(-3px) rotate(-12deg) scale(0.96);
  }

  50% {
    transform: translateY(2px) rotate(9deg) scale(1.04);
  }

  100% {
    transform: translateY(-1px) rotate(-6deg) scale(0.99);
  }
}

@keyframes rollPulse {
  from {
    transform: translateY(0);
    box-shadow:
      0 18px 34px rgba(53, 29, 12, 0.24),
      inset 0 2px 0 rgba(255, 255, 255, 0.72);
  }

  to {
    transform: translateY(-2px);
    box-shadow:
      0 24px 40px rgba(53, 29, 12, 0.3),
      inset 0 2px 0 rgba(255, 255, 255, 0.72);
  }
}

body.is-busy .hud-button,
body.is-transient-busy .hud-button,
body.is-busy .board-action-button,
body.is-transient-busy .board-action-button,
body.is-busy .popup-action,
body.is-transient-busy .popup-action,
body.is-busy .primary-action,
body.is-transient-busy .primary-action,
body.is-busy .popup-close,
body.is-transient-busy .popup-close,
body.is-busy .mode-choice,
body.is-transient-busy .mode-choice,
body.is-busy .field select,
body.is-transient-busy .field select {
  pointer-events: none;
}

body.is-busy #sound-toggle-button,
body.is-transient-busy #sound-toggle-button {
  pointer-events: auto;
}

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

@media (max-width: 720px) {
  :root {
    --off-rail-width: clamp(60px, 15vw, 82px);
    --board-padding: clamp(6px, 1.9vw, 9px);
    --board-gap-x: clamp(2px, 0.65vw, 4px);
    --board-gap-y: clamp(4px, 0.9vw, 6px);
    --board-bar-width: clamp(24px, 8vw, 40px);
    --point-label-font-size: clamp(0.42rem, 1.8vw, 0.58rem);
    --stack-offset: clamp(5px, 1.35vw, 10px);
    --checker-size: clamp(18px, 5.5vw, 34px);
  }

  body {
    padding: 8px;
  }

  .board-popup--setup {
    width: calc(100% - 8px);
  }

  .board-popup--tools {
    width: calc(100% - 8px);
    max-height: calc(100% - 12px);
  }

  .board-action-button {
    min-height: 48px;
    padding: 0 20px;
    font-size: 0.88rem;
  }

  .status-popup {
    width: calc(100% - 12px);
    padding: 12px 14px;
  }

  .status-popup__copy {
    font-size: 0.82rem;
  }

  .setup-choice-grid,
  .setup-fields,
  .invite-card__row {
    grid-template-columns: 1fr;
  }

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

  .off-slot {
    padding: 8px 6px;
    gap: 8px;
  }

  .off-rail__menu .hud-button {
    min-height: 42px;
    font-size: 0.8rem;
  }

  .off-slot__label {
    font-size: 0.54rem;
    letter-spacing: 0.04em;
  }
}

@media (max-width: 520px) {
  .status-popup__copy {
    display: none;
  }

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

  .hud-button,
  .popup-action,
  .primary-action,
  .popup-close,
  .mode-choice {
    min-height: 44px;
  }
}

@media (orientation: portrait) and (pointer: coarse) {
  :root {
    --page-pad-top: var(--safe-top);
    --page-pad-right: var(--safe-right);
    --page-pad-bottom: var(--safe-bottom);
    --page-pad-left: var(--safe-left);
  }

  body {
    padding: var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left);
  }

  .app-shell {
    display: none;
  }

  .rotate-overlay {
    position: fixed;
    inset: 0;
    z-index: 40;
    display: grid;
    place-items: center;
    padding:
      max(20px, var(--safe-top))
      max(20px, var(--safe-right))
      max(20px, var(--safe-bottom))
      max(20px, var(--safe-left));
    background:
      radial-gradient(circle at top left, rgba(255, 176, 0, 0.2), transparent 24%),
      radial-gradient(circle at bottom right, rgba(31, 75, 61, 0.24), transparent 26%),
      linear-gradient(180deg, #f6ecdd, var(--page));
  }
}

@media (orientation: landscape) and (pointer: coarse) {
  :root {
    --page-pad-top: var(--safe-top);
    --page-pad-right: var(--safe-right);
    --page-pad-bottom: var(--safe-bottom);
    --page-pad-left: var(--safe-left);
    --off-rail-width: clamp(56px, 10vw, 84px);
    --board-stage-gap: clamp(6px, 1vw, 10px);
    --board-padding: clamp(6px, 1.6vh, 10px);
    --board-gap-x: clamp(2px, 0.55vw, 5px);
    --board-gap-y: clamp(3px, 0.8vh, 7px);
    --board-radius: clamp(16px, 3.4vh, 24px);
    --board-inner-radius: clamp(10px, 2.2vh, 16px);
    --board-bar-width: clamp(24px, 6vw, 40px);
    --point-inset: clamp(2px, 0.35vw, 5px);
    --point-edge-offset: clamp(6px, 1.2vh, 12px);
    --point-target-inset: clamp(3px, 0.7vh, 6px);
    --point-label-font-size: clamp(0.36rem, 1.45vh, 0.55rem);
    --point-label-padding-y: clamp(1px, 0.22vh, 2px);
    --point-label-padding-x: clamp(3px, 0.55vw, 6px);
    --stack-offset: clamp(4px, 0.95vh, 8px);
    --tray-min-height: 0px;
  }

  .board-stage {
    --checker-size-board: max(18px, calc(var(--point-base-width) - (2 * var(--point-inset))));
  }

  body {
    padding: var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left);
    overflow: hidden;
  }

  .app-shell {
    width: 100%;
    max-width: none;
    height: calc(100dvh - var(--safe-top) - var(--safe-bottom));
    margin: 0;
  }

  .table-shell {
    height: 100%;
    gap: 0;
  }

  .board-stage__center,
  .board-grid,
  .off-rail {
    height: 100%;
  }

  .board-action-button {
    min-height: clamp(48px, 12vh, 66px);
    padding: 0 clamp(18px, 3vw, 28px);
    font-size: clamp(0.82rem, 2.2vh, 1rem);
  }

  .board-dice {
    gap: clamp(6px, 1vw, 10px);
    min-height: clamp(34px, 9vh, 50px);
  }

  .die {
    width: clamp(32px, 8vh, 48px);
    height: clamp(32px, 8vh, 48px);
    border-radius: 12px;
  }

  .off-slot {
    gap: 6px;
    padding: clamp(8px, 1.4vh, 12px) clamp(6px, 0.9vw, 10px);
  }

  .off-slot__label {
    font-size: clamp(0.45rem, 1.35vh, 0.68rem);
    letter-spacing: 0.05em;
  }

  .off-rail__menu .hud-button {
    min-height: clamp(40px, 10vh, 54px);
    padding: 0 8px;
    font-size: clamp(0.72rem, 2.1vh, 0.88rem);
  }

  .tray-slot {
    padding: clamp(8px, 1.2vh, 12px) clamp(4px, 0.6vw, 8px);
  }

  .status-popup {
    width: min(72%, 360px);
    padding: 12px 14px;
  }

  .status-popup__title {
    font-size: clamp(0.96rem, 2.6vh, 1.18rem);
  }

  .status-popup__copy {
    font-size: clamp(0.72rem, 1.9vh, 0.86rem);
  }

  .board-popup--setup,
  .board-popup--tools {
    width: min(78%, 420px);
    max-height: calc(100% - 12px);
  }

  .board-popup--setup {
    width: min(72%, 360px);
    padding: 12px;
    overflow: auto;
  }

  .board-popup--setup .board-popup__header {
    gap: 8px;
  }

  .board-popup--setup .board-popup__eyebrow {
    margin-bottom: 4px;
    font-size: 0.68rem;
  }

  .board-popup--setup .board-popup__title {
    font-size: clamp(1.02rem, 3.2vh, 1.34rem);
  }

  .board-popup--setup .board-popup__text {
    margin-top: 8px;
    font-size: clamp(0.72rem, 1.9vh, 0.84rem);
    line-height: 1.3;
  }

  .board-popup--setup .setup-form {
    gap: 10px;
  }

  .board-popup--setup .setup-choice-grid,
  .board-popup--setup .setup-fields {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .board-popup--setup .mode-choice,
  .board-popup--setup .field select,
  .board-popup--setup .primary-action {
    min-height: 40px;
  }

  .board-popup--setup .mode-choice {
    padding: 10px 8px;
    font-size: clamp(0.78rem, 1.9vh, 0.88rem);
  }

  .board-popup--setup .field {
    gap: 4px;
    font-size: 0.8rem;
  }

  .board-popup--setup .field select,
  .board-popup--setup .primary-action {
    padding: 0 12px;
  }

  .board-popup--setup .primary-action {
    font-size: clamp(0.82rem, 2vh, 0.92rem);
  }

  .debug-panel {
    position: absolute;
    top: 8px;
    right: 8px;
    left: 8px;
    z-index: 12;
    max-height: calc(100% - 16px);
    overflow: auto;
  }
}
