:root {
  color-scheme: light;
  --ink: #17211b;
  --muted: #5d695f;
  --line: #d7ded5;
  --field: #eef6ec;
  --water: #dceefa;
  --sun: #f7c948;
  --soil: #8a5a32;
  --leaf: #1f6f4a;
  --leaf-dark: #174f37;
  --surface: #ffffff;
  --danger: #b54334;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

html {
  min-height: 100%;
  scroll-behavior: auto;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: linear-gradient(180deg, var(--field), #f8fbf7 45%, var(--water));
  color: var(--ink);
  overflow-x: hidden;
}

button,
select {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: clamp(460px, 28vw, 560px) minmax(0, 1fr);
  align-items: start;
  gap: clamp(18px, 2vw, 34px);
  width: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  padding: clamp(14px, 1.8vw, 28px);
}

.control-panel {
  display: flex;
  flex-direction: column;
  gap: 22px;
  align-self: start;
  min-height: min(820px, calc(100vh - 56px));
  padding: clamp(30px, 2.35vw, 46px);
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 16px 40px rgba(31, 79, 55, 0.12);
}

.brand-block {
  display: grid;
  gap: 4px;
  position: relative;
}

.eyebrow {
  margin: 0;
  color: var(--leaf-dark);
  font-size: clamp(0.9rem, 0.9vw, 1.05rem);
  font-weight: 800;
  text-transform: uppercase;
}

.version-badge {
  position: absolute;
  top: 0;
  right: 0;
  margin: 0;
  color: var(--leaf-dark);
  font-size: 0.78rem;
  font-weight: 900;
  opacity: 0.72;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(3.9rem, 4.35vw, 5.8rem);
  line-height: 1;
  letter-spacing: 0;
}

.selector-grid {
  display: grid;
  gap: 16px;
}

label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 1.16rem;
  font-weight: 800;
}

select {
  min-height: 70px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 64px 0 18px;
  appearance: none;
  background-color: var(--surface);
  background-image: url("data:image/svg+xml,%3Csvg width='42' height='42' viewBox='0 0 42 42' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M10 16L21 27L32 16' stroke='%2317211B' stroke-width='5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 20px center;
  background-size: 28px 28px;
  color: var(--ink);
  font-size: 1.28rem;
  font-weight: 800;
}

.status-strip {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.status-strip > div {
  min-height: 128px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  display: grid;
  place-items: center;
  align-content: center;
}

.status-label {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 800;
  text-transform: uppercase;
}

.status-strip strong {
  font-size: 3.6rem;
  line-height: 1;
}

.dice-readout {
  display: inline-flex;
  align-items: center;
  gap: 14px;
}

.physical-dice {
  position: relative;
  width: 78px;
  height: 78px;
  border-radius: 16px;
  border: 3px solid #17211b;
  background: linear-gradient(145deg, #ffffff, #f4f1e9);
  box-shadow: inset -5px -5px 10px rgba(23, 33, 27, 0.12), 0 8px 16px rgba(23, 33, 27, 0.18);
}

.physical-dice.rolling {
  animation: dice-roll 720ms ease-in-out;
}

.pip {
  position: absolute;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: #17211b;
  opacity: 0;
}

.pip-1 {
  left: 16px;
  top: 16px;
}

.pip-2 {
  right: 16px;
  top: 16px;
}

.pip-3 {
  left: 16px;
  top: 32px;
}

.pip-4 {
  left: 32px;
  top: 32px;
}

.pip-5 {
  right: 16px;
  top: 32px;
}

.pip-6 {
  left: 16px;
  bottom: 16px;
}

.pip-7 {
  right: 16px;
  bottom: 16px;
}

.value-1 .pip-4,
.value-2 .pip-1,
.value-2 .pip-7,
.value-3 .pip-1,
.value-3 .pip-4,
.value-3 .pip-7,
.value-4 .pip-1,
.value-4 .pip-2,
.value-4 .pip-6,
.value-4 .pip-7,
.value-5 .pip-1,
.value-5 .pip-2,
.value-5 .pip-4,
.value-5 .pip-6,
.value-5 .pip-7,
.value-6 .pip-1,
.value-6 .pip-2,
.value-6 .pip-3,
.value-6 .pip-5,
.value-6 .pip-6,
.value-6 .pip-7 {
  opacity: 1;
}

@keyframes dice-roll {
  0% {
    transform: rotate(0deg) scale(1);
  }

  28% {
    transform: rotate(126deg) scale(1.18);
  }

  58% {
    transform: rotate(286deg) scale(0.94);
  }

  100% {
    transform: rotate(360deg) scale(1);
  }
}

.action-row {
  display: grid;
  grid-template-columns: 1fr 128px;
  gap: 14px;
}

button {
  min-height: 70px;
  border: 0;
  border-radius: 10px;
  cursor: pointer;
  font-size: 1.06rem;
  font-weight: 900;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.62;
}

.primary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: var(--leaf);
  color: white;
  padding: 0 18px;
}

.secondary-button {
  background: #f2efe8;
  color: var(--soil);
  border: 1px solid #d9c9b6;
  padding: 0 18px;
}

.dice-icon {
  width: 34px;
  height: 34px;
  border: 3px solid currentColor;
  border-radius: 7px;
  position: relative;
}

.dice-icon::before,
.dice-icon::after {
  content: "";
  position: absolute;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  top: 6px;
}

.dice-icon::before {
  left: 6px;
  box-shadow: 16px 16px 0 currentColor;
}

.dice-icon::after {
  right: 6px;
  box-shadow: -9px 9px 0 currentColor;
}

.board-note {
  min-height: 44px;
  margin: 0;
  color: var(--muted);
  line-height: 1.4;
  font-size: 1.2rem;
}

.game-panel {
  display: grid;
  justify-items: center;
  align-items: start;
  min-width: 0;
}

.board-wrap {
  position: relative;
  width: min(100%, calc(100vh - 32px), calc(100dvh - 32px));
  aspect-ratio: 1 / 1;
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface);
  box-shadow: 0 20px 50px rgba(24, 39, 29, 0.18);
}

.board-image {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.square-highlight {
  position: absolute;
  width: 10%;
  height: 10%;
  transform: translate(-50%, -50%) scale(0.84);
  border: clamp(4px, 0.55vw, 10px) solid #ffffff;
  border-radius: 12px;
  background: rgba(247, 201, 72, 0.22);
  box-shadow: 0 0 0 clamp(4px, 0.5vw, 9px) rgba(31, 111, 74, 0.85), 0 0 36px rgba(247, 201, 72, 0.8);
  opacity: 0;
  pointer-events: none;
  z-index: 1;
}

.square-highlight.is-active {
  animation: square-flash 650ms ease-out;
}

@keyframes square-flash {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.7);
  }

  18%,
  72% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }

  100% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(1.12);
  }
}

.token {
  position: absolute;
  width: clamp(34px, 6.45%, 70px);
  height: clamp(48px, 8.35%, 92px);
  transform: translate(-50%, -76%);
  transition: left 220ms ease, top 220ms ease;
  z-index: 2;
}

.token::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 0;
  width: 54%;
  aspect-ratio: 1 / 1;
  transform: translateX(-50%);
  border-radius: 50%;
  border: 3px solid #ffffff;
  background: radial-gradient(circle at 34% 28%, #ffd8d2 0 12%, #ff3b30 13% 50%, #b81319 51% 100%);
  box-shadow: 0 7px 18px rgba(0, 0, 0, 0.4);
}

.token::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 0;
  width: 76%;
  height: 62%;
  transform: translateX(-50%);
  border-radius: 46% 46% 12% 12%;
  border: 3px solid #ffffff;
  background: linear-gradient(180deg, #ff3b30, #d91f26 68%, #8f1016);
  box-shadow: 0 10px 22px rgba(0, 0, 0, 0.48);
}

.event-dialog {
  width: min(760px, calc(100vw - 80px));
  max-height: min(82vh, 760px);
  border: 0;
  border-radius: 8px;
  padding: 34px;
  color: var(--ink);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.32);
  overflow: auto;
}

.event-dialog::backdrop {
  background: rgba(12, 18, 14, 0.54);
}

.dialog-topline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
  color: var(--muted);
  font-weight: 800;
  text-transform: uppercase;
  font-size: 0.92rem;
}

.event-type.ladder {
  color: var(--leaf);
}

.event-type.snake {
  color: var(--danger);
}

.event-dialog h2 {
  margin: 0 0 16px;
  font-size: clamp(1.7rem, 2.3vw, 2.35rem);
  line-height: 1.08;
  letter-spacing: 0;
}

.event-dialog p {
  margin: 0 0 26px;
  color: var(--muted);
  font-size: clamp(1.15rem, 1.55vw, 1.45rem);
  line-height: 1.36;
  white-space: pre-line;
}

.event-dialog .primary-button {
  min-width: min(240px, 100%);
  min-height: 64px;
  font-size: 1.08rem;
}

.confetti-layer {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 9;
}

.confetti-layer span {
  position: absolute;
  left: var(--left);
  top: -8vh;
  width: clamp(14px, 0.9vw, 28px);
  height: clamp(20px, 1.2vw, 36px);
  border-radius: 3px;
  background: var(--color);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.24);
  animation: confetti-fall var(--duration) cubic-bezier(0.2, 0.74, 0.35, 1) var(--delay) forwards;
}

@keyframes confetti-fall {
  0% {
    opacity: 0;
    transform: translate3d(0, -8vh, 0) rotate(0deg);
  }

  10% {
    opacity: 1;
  }

  100% {
    opacity: 0;
    transform: translate3d(var(--drift), 112vh, 0) rotate(780deg);
  }
}

.win-dialog {
  width: min(820px, calc(100vw - 80px));
  border: 0;
  border-radius: 8px;
  padding: 44px;
  text-align: center;
  color: var(--ink);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.32);
  z-index: 10;
}

.win-dialog::backdrop {
  background: rgba(12, 18, 14, 0.5);
}

.win-dialog p {
  margin: 0 0 18px;
  color: var(--leaf-dark);
  font-size: clamp(1.25rem, 1.7vw, 1.6rem);
  font-weight: 900;
  text-transform: uppercase;
}

.win-dialog h2 {
  margin: 0 0 34px;
  font-size: clamp(3.2rem, 4.8vw, 5.2rem);
  line-height: 1;
  letter-spacing: 0;
}

.win-dialog .primary-button {
  min-width: min(260px, 100%);
  min-height: 64px;
  font-size: 1.08rem;
}

@media (max-width: 860px) {
  .app-shell {
    grid-template-columns: 1fr;
    width: 100vw;
    max-width: 100vw;
    padding: 10px;
    gap: 10px;
    overflow-x: hidden;
  }

  .control-panel {
    order: 2;
    padding: 14px;
    justify-self: center;
    width: calc(100vw - 20px);
    max-width: calc(100vw - 20px);
    min-width: 0;
    min-height: auto;
    gap: 12px;
  }

  .brand-block {
    gap: 2px;
    min-width: 0;
  }

  .eyebrow,
  .version-badge {
    font-size: 0.68rem;
  }

  .version-badge {
    display: none;
  }

  h1 {
    font-size: clamp(1.9rem, 9vw, 3rem);
    line-height: 1;
  }

  label {
    gap: 5px;
    font-size: 0.78rem;
  }

  select {
    min-height: 42px;
    padding: 0 40px 0 12px;
    background-position: right 12px center;
    background-size: 22px 22px;
    font-size: 0.98rem;
  }

  .selector-grid,
  .status-strip {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    min-width: 0;
  }

  .selector-grid > *,
  .status-strip > *,
  .action-row > * {
    min-width: 0;
  }

  .status-strip > div {
    min-height: 58px;
  }

  .status-label {
    font-size: 0.64rem;
  }

  .status-strip strong {
    font-size: 1.58rem;
  }

  .dice-readout {
    gap: 6px;
  }

  .physical-dice {
    width: 34px;
    height: 34px;
    border-width: 2px;
    border-radius: 9px;
  }

  .pip {
    width: 5px;
    height: 5px;
  }

  .pip-1 {
    left: 7px;
    top: 7px;
  }

  .pip-2 {
    right: 7px;
    top: 7px;
  }

  .pip-3 {
    left: 7px;
    top: 14px;
  }

  .pip-4 {
    left: 14px;
    top: 14px;
  }

  .pip-5 {
    right: 7px;
    top: 14px;
  }

  .pip-6 {
    left: 7px;
    bottom: 7px;
  }

  .pip-7 {
    right: 7px;
    bottom: 7px;
  }

  .action-row {
    grid-template-columns: 1fr 88px;
    gap: 8px;
  }

  button {
    min-height: 44px;
    font-size: 0.78rem;
    border-radius: 8px;
  }

  .primary-button {
    gap: 7px;
    padding: 0 12px;
  }

  .secondary-button {
    padding: 0 10px;
  }

  .dice-icon {
    width: 18px;
    height: 18px;
    border-width: 2px;
  }

  .dice-icon::before,
  .dice-icon::after {
    width: 3px;
    height: 3px;
    top: 3px;
  }

  .dice-icon::before {
    left: 3px;
    box-shadow: 8px 8px 0 currentColor;
  }

  .dice-icon::after {
    right: 3px;
    box-shadow: -4px 4px 0 currentColor;
  }

  .board-note {
    display: none;
  }

  .game-panel {
    order: 1;
    width: 100%;
    max-width: 100%;
    align-items: start;
  }

  .board-wrap {
    width: 100%;
    box-shadow: 0 12px 24px rgba(24, 39, 29, 0.18);
  }

  .event-dialog {
    width: min(94vw, 520px);
    max-height: 82vh;
    padding: 20px;
  }

  .dialog-topline {
    gap: 12px;
    margin-bottom: 12px;
    font-size: 0.78rem;
  }

  .event-dialog h2 {
    margin-bottom: 12px;
    font-size: clamp(1.45rem, 7vw, 2.25rem);
  }

  .event-dialog p {
    margin-bottom: 18px;
    font-size: clamp(1.05rem, 5.2vw, 1.55rem);
    line-height: 1.35;
  }

  .event-dialog .primary-button,
  .win-dialog .primary-button {
    min-width: 100%;
    min-height: 54px;
    font-size: 1rem;
  }

  .win-dialog {
    width: min(94vw, 540px);
    padding: 24px;
  }

  .win-dialog p {
    margin-bottom: 12px;
    font-size: clamp(1.05rem, 5vw, 1.5rem);
  }

  .win-dialog h2 {
    margin-bottom: 22px;
    font-size: clamp(2.4rem, 12vw, 4.2rem);
  }

}

@media (max-width: 1280px) and (min-width: 861px) {
  .app-shell {
    grid-template-columns: clamp(320px, 30vw, 390px) minmax(0, 1fr);
  }

  .control-panel {
    min-height: auto;
    padding: 24px;
    gap: 16px;
  }

  h1 {
    font-size: clamp(2.9rem, 3.7vw, 4rem);
  }

  label {
    font-size: 0.96rem;
  }

  select {
    min-height: 56px;
    font-size: 1.05rem;
    background-position: right 16px center;
    background-size: 24px 24px;
    padding: 0 48px 0 14px;
  }

  .status-strip > div {
    min-height: 88px;
  }

  .status-label {
    font-size: 0.74rem;
  }

  .status-strip strong {
    font-size: 2.55rem;
  }

  .physical-dice {
    width: 56px;
    height: 56px;
    border-radius: 12px;
  }

  .pip {
    width: 9px;
    height: 9px;
  }

  .pip-1 {
    left: 11px;
    top: 11px;
  }

  .pip-2 {
    right: 11px;
    top: 11px;
  }

  .pip-3 {
    left: 11px;
    top: 23px;
  }

  .pip-4 {
    left: 23px;
    top: 23px;
  }

  .pip-5 {
    right: 11px;
    top: 23px;
  }

  .pip-6 {
    left: 11px;
    bottom: 11px;
  }

  .pip-7 {
    right: 11px;
    bottom: 11px;
  }

  .action-row {
    grid-template-columns: 1fr 96px;
    gap: 12px;
  }

  button {
    min-height: 56px;
    font-size: 0.88rem;
  }
}

@media (max-width: 520px) {
  .selector-grid,
  .status-strip {
    grid-template-columns: 1fr 1fr;
  }

  .action-row {
    grid-template-columns: 1fr 76px;
  }

  .control-panel {
    padding: 12px;
    gap: 10px;
  }

  h1 {
    font-size: clamp(1.7rem, 8vw, 2.45rem);
  }

  button {
    font-size: 0.72rem;
  }
}
