:root {
  color-scheme: dark;
  --bg: #181818;
  --ink: #fff;
  --muted: #9a9a9a;
  --line: #222224;
  --slot: #101011;
  --gap: 12px;
  --move: 120ms;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body {
  height: 100dvh;
  max-height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font-family: "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", system-ui, sans-serif;
  font-weight: 500;
  overscroll-behavior: none;
}

button,
p {
  margin: 0;
}

::selection {
  background: #fff;
  color: #000;
}

.sr {
  position: fixed;
  top: 0;
  left: 0;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.stage {
  --board: min(100cqw, 100cqh);
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 16px;
  height: 100%;
  max-height: 100%;
  overflow: hidden;
  container-type: size;
  padding:
    max(16px, env(safe-area-inset-top))
    max(16px, env(safe-area-inset-right))
    max(16px, env(safe-area-inset-bottom))
    max(16px, env(safe-area-inset-left));
}

.stage.show-side {
  --board: min(100cqh, calc(100cqw - 136px));
  justify-content: flex-start;
}

.side {
  display: none;
  flex: none;
  flex-direction: column;
  gap: 18px;
  width: 104px;
  min-height: 0;
}

.stage.show-side .side {
  display: flex;
}

.stats {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.stat {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.stat-name {
  color: #3a3a3c;
  font-size: 12px;
}

.stat-num {
  color: #454548;
  font-size: 18px;
  font-variant-numeric: tabular-nums;
  font-weight: 500;
  line-height: 1;
}

.board {
  position: relative;
  flex: none;
  width: var(--board);
  height: var(--board);
  padding: var(--gap);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 18px;
  container-type: inline-size;
  touch-action: none;
  user-select: none;
}

.grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--gap);
  height: 100%;
}

.grid span {
  border-radius: 10px;
  background: var(--slot);
}

.tiles,
.veil {
  position: absolute;
  inset: var(--gap);
}

.tiles {
  z-index: 1;
}

.tile {
  position: absolute;
  top: calc(var(--y) * ((100% - 3 * var(--gap)) / 4 + var(--gap)));
  left: calc(var(--x) * ((100% - 3 * var(--gap)) / 4 + var(--gap)));
  display: flex;
  align-items: center;
  justify-content: center;
  width: calc((100% - 3 * var(--gap)) / 4);
  height: calc((100% - 3 * var(--gap)) / 4);
  border-radius: 10px;
  background: var(--bg-tile);
  color: var(--fg);
  pointer-events: none;
  transition:
    left var(--move) ease-in-out,
    top var(--move) ease-in-out;
}

.face {
  font-weight: 500;
  font-size: 16cqw;
  line-height: 1;
  letter-spacing: -0.05em;
}

.tile[data-digits="3"] .face {
  font-size: 11.5cqw;
}

.tile[data-digits="4"] .face {
  font-size: 7.6cqw;
}

.tile.pop .face {
  animation: pop 160ms ease;
}

@keyframes pop {
  0% {
    transform: scale(0.64);
  }
  70% {
    transform: scale(1.08);
  }
  100% {
    transform: scale(1);
  }
}

.veil {
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 16px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.86);
  text-align: center;
}

.veil[hidden] {
  display: none;
}

.veil p {
  max-width: 100%;
  font-size: clamp(22px, 6cqw, 36px);
  font-weight: 700;
  line-height: 1.3;
  text-wrap: balance;
}

.veil-actions,
.actions {
  display: flex;
  gap: 8px;
}

.actions {
  flex: none;
  flex-direction: column;
}

.actions button {
  width: 100%;
}

button {
  white-space: nowrap;
}

button {
  min-height: 42px;
  padding: 0 14px;
  border: 0;
  border-radius: 8px;
  background: #fff;
  color: #000;
  font: 600 15px/1 "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", system-ui, sans-serif;
  cursor: pointer;
}

button:hover {
  background: #e8e8e8;
}

button:active:not(:disabled) {
  transform: translateY(1px);
}

button:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 3px;
}

button:disabled {
  opacity: 0.35;
  cursor: default;
}

button.ghost {
  background: transparent;
  color: #fff;
  box-shadow: inset 0 0 0 1px #fff;
}

button.ghost:hover {
  background: #1a1a1a;
}

.veil button.ghost:hover {
  background: rgba(255, 255, 255, 0.08);
}

.side button {
  min-height: 30px;
  padding: 0 8px;
  border-radius: 6px;
  background: #1e1e20;
  color: #3f3f42;
  font-size: 12px;
  font-weight: 500;
}

.side button:hover {
  background: #242426;
}

.side button.ghost {
  background: transparent;
  color: #3a3a3c;
  box-shadow: inset 0 0 0 1px #2a2a2c;
}

.side button.ghost:hover {
  background: #1c1c1e;
}

.side button:focus-visible {
  outline-color: #444;
}

.side button:disabled {
  opacity: 0.7;
}

.back {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 30px;
  border-radius: 6px;
  color: #3a3a3c;
  box-shadow: inset 0 0 0 1px #2a2a2c;
  font-size: 12px;
  text-decoration: none;
}

.back:hover {
  background: #1c1c1e;
}

.back:focus-visible {
  outline: 2px solid #444;
  outline-offset: 3px;
}

@media (prefers-reduced-motion: reduce) {
  .tile,
  .tile.pop .face {
    transition: none;
    animation: none;
  }
}
