:root {
  color-scheme: dark;
  --bg: #202225;
  --ink: #f5f7fa;
  --muted: #b4bbc3;
  --panel: rgba(44, 47, 51, 0.82);
  --grid: rgba(14, 17, 20, 0.58);
  --cell: rgba(52, 56, 61, 0.92);
  --cell-hover: rgba(70, 82, 76, 0.96);
  --accent: #f0f4f8;
  --warn: #ff8a80;
  --shadow: 0 18px 45px rgba(0, 0, 0, 0.36);
  --glow: rgba(167, 255, 235, 0.34);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

body {
  margin: 0;
  min-height: 100vh;
  width: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background:
    radial-gradient(circle at 28% 18%, rgba(167, 255, 235, 0.08), transparent 28%),
    radial-gradient(circle at 80% 72%, rgba(214, 74, 160, 0.07), transparent 30%),
    linear-gradient(135deg, rgba(255, 255, 255, 0.025), transparent 24%, rgba(128, 213, 255, 0.018) 52%, transparent 74%),
    var(--bg);
  background-size: 140% 140%;
  animation: ambient-shift 12s ease-in-out infinite alternate;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  touch-action: none;
}

html {
  min-height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
}

button {
  font: inherit;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

button {
  transform: translateZ(0);
  transition: border-color 180ms ease, box-shadow 180ms ease, transform 180ms cubic-bezier(0.22, 1, 0.36, 1), background 180ms ease;
}

button:active {
  transform: scale(0.96);
}

body:not(.game-started) .game-shell {
  display: none;
}

body.game-started .title-screen {
  display: none;
}

body:not(.paused) .pause-screen {
  display: none;
}

body:not(.game-over) .game-over-screen {
  display: none;
}

body:not(.directions-open) .directions-screen {
  display: none;
}

body:not(.settings-open) .settings-screen {
  display: none;
}

body:not(.high-score-open) .high-score-screen {
  display: none;
}

@keyframes ambient-shift {
  from {
    background-position: 0% 0%;
  }
  to {
    background-position: 100% 100%;
  }
}

.title-screen {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  padding: max(28px, env(safe-area-inset-top)) 24px max(18px, env(safe-area-inset-bottom));
  background:
    radial-gradient(circle at 28% 18%, rgba(167, 255, 235, 0.08), transparent 28%),
    radial-gradient(circle at 80% 72%, rgba(214, 74, 160, 0.07), transparent 30%),
    linear-gradient(135deg, rgba(255, 255, 255, 0.025), transparent 24%, rgba(128, 213, 255, 0.018) 52%, transparent 74%),
    linear-gradient(180deg, #252a2f 0%, #202225 52%, #1b1e22 100%);
  opacity: 1;
  transform: translateY(0);
  transition: opacity 260ms ease, transform 260ms ease;
}

.menu-topbar {
  width: min(100%, 820px);
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.menu-corner-button {
  width: 46px;
  height: 46px;
  border: 0;
  background: transparent;
  color: rgba(255, 255, 255, 0.66);
  cursor: pointer;
  display: grid;
  place-items: center;
  padding: 0;
  filter: drop-shadow(0 3px 8px rgba(0, 0, 0, 0.38));
  transition: color 180ms ease, transform 180ms ease, filter 180ms ease;
}

.menu-corner-button svg {
  width: 34px;
  height: 34px;
  fill: currentColor;
}

.menu-corner-button:hover,
.menu-corner-button:focus-visible {
  color: #ffffff;
  transform: translateY(-2px) scale(1.04);
  filter: drop-shadow(0 0 16px rgba(255, 255, 255, 0.24));
  outline: none;
}

body.title-exiting .title-screen {
  opacity: 0;
  transform: translateY(-18px);
}

.title-content {
  width: min(680px, 100%);
  display: grid;
  justify-items: center;
  align-self: stretch;
  grid-template-rows: 1fr auto;
  gap: 0;
  text-align: center;
  margin: 0 auto;
  padding: 0 0 clamp(110px, 15vh, 160px);
}

.game-title {
  margin: 0;
  line-height: 0.9;
  align-self: center;
  animation: title-drop 520ms cubic-bezier(0.22, 1, 0.36, 1) both;
}

.dominix-logo {
  display: block;
  width: min(620px, 86vw);
  height: auto;
  opacity: 1;
  filter: drop-shadow(0 28px 42px rgba(255, 255, 255, 0.16)) drop-shadow(0 24px 30px rgba(0, 0, 0, 0.28));
  transform: translateX(-10px) rotate(-1.1deg) scale(0.99);
  transform-origin: center;
  animation: logo-tilt 5.2s ease-in-out infinite alternate;
}

.version-label {
  position: fixed;
  right: 16px;
  bottom: 14px;
  margin: 0;
  color: rgba(245, 247, 250, 0.56);
  font-size: 0.95rem;
  font-weight: 800;
  letter-spacing: 0;
  z-index: 32;
}

@keyframes title-drop {
  from {
    opacity: 0;
    transform: translateY(-26px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes logo-tilt {
  from {
    transform: translateX(-10px) rotate(-1.1deg) scale(0.99);
  }
  to {
    transform: translateX(-4px) rotate(1.1deg) scale(1.012);
  }
}

.start-button {
  position: relative;
  overflow: hidden;
  width: min(540px, calc(100vw - 68px));
  min-height: 82px;
  border: 2px solid rgba(255, 255, 255, 0.58);
  border-radius: 8px;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.16), rgba(255, 255, 255, 0.035));
  color: #f5f7fa;
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: 0.42em;
  text-transform: uppercase;
  cursor: pointer;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.38), inset 0 0 18px rgba(255, 255, 255, 0.04);
  backdrop-filter: blur(6px);
}

.start-button.secondary {
  min-height: 66px;
  color: rgba(245, 247, 250, 0.72);
  font-size: 1.06rem;
}

.menu-actions {
  display: grid;
  gap: 26px;
}

.start-button:hover,
.start-button:focus-visible {
  border-color: #ffffff;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.24), rgba(255, 255, 255, 0.08));
  box-shadow: 0 20px 46px rgba(0, 0, 0, 0.44), 0 0 28px rgba(167, 255, 235, 0.12), inset 0 0 22px rgba(255, 255, 255, 0.07);
  transform: translateY(-2px);
  outline: none;
}

.corner-logo {
  position: fixed;
  left: 14px;
  bottom: 12px;
  width: min(190px, 34vw);
  opacity: 0.28;
  pointer-events: none;
  z-index: 30;
  filter: grayscale(0.1) drop-shadow(0 10px 18px rgba(0, 0, 0, 0.35));
  animation: logo-breathe 4.8s ease-in-out infinite alternate;
}

body.game-started .corner-logo {
  display: none;
}

@keyframes logo-breathe {
  from {
    opacity: 0.2;
    transform: scale(0.985);
  }
  to {
    opacity: 0.32;
    transform: scale(1);
  }
}

.pause-screen,
.game-over-screen,
.directions-screen,
.settings-screen,
.high-score-screen {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  width: 100vw;
  min-height: 100dvh;
  padding: 24px;
  background: rgba(14, 16, 18, 0.72);
  backdrop-filter: blur(7px);
  animation: overlay-fade 180ms ease both;
}

.directions-screen {
  z-index: 45;
}

.settings-screen {
  z-index: 45;
}

.high-score-screen {
  z-index: 45;
}

.pause-panel {
  position: relative;
  overflow: hidden;
  width: min(340px, 100%);
  justify-self: center;
  align-self: center;
  display: grid;
  gap: 14px;
  padding: 24px;
  border-radius: 8px;
  background: linear-gradient(155deg, rgba(54, 59, 64, 0.94), rgba(24, 27, 30, 0.96));
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255, 255, 255, 0.08);
  animation: panel-rise 220ms cubic-bezier(0.22, 1, 0.36, 1) both;
}

.pause-panel::after,
.directions-panel::after,
.settings-panel::after,
.score-panel::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.08), transparent 34%, rgba(167, 255, 235, 0.035));
  pointer-events: none;
}

.directions-panel,
.settings-panel {
  position: relative;
  overflow: hidden;
  width: min(680px, calc(100vw - 48px));
  justify-self: center;
  align-self: center;
  max-height: min(760px, calc(100vh - 48px));
  overflow-y: auto;
  overflow-x: hidden;
  display: grid;
  gap: 12px;
  padding: 24px;
  border-radius: 8px;
  background: linear-gradient(155deg, rgba(54, 59, 64, 0.94), rgba(24, 27, 30, 0.96));
  color: #f5f7fa;
  box-shadow: var(--shadow);
  border: 1px solid rgba(255, 255, 255, 0.12);
  animation: panel-rise 220ms cubic-bezier(0.22, 1, 0.36, 1) both;
}

.compact-panel {
  min-height: 180px;
  align-content: center;
  justify-items: center;
}

.score-panel {
  position: relative;
  overflow: visible;
  width: min(420px, calc(100vw - 48px));
  margin: 42px auto 0;
  justify-self: center;
  align-self: center;
  display: grid;
  gap: 12px;
  padding: 24px;
  border-radius: 8px;
  background: linear-gradient(155deg, rgba(54, 59, 64, 0.94), rgba(24, 27, 30, 0.96));
  color: #f5f7fa;
  box-shadow: var(--shadow);
  border: 1px solid rgba(255, 255, 255, 0.12);
  text-align: center;
  animation: panel-rise 220ms cubic-bezier(0.22, 1, 0.36, 1) both;
}

.score-panel h2 {
  margin: 0;
  color: #ffffff;
  font-size: clamp(3rem, 15vw, 5.5rem);
  line-height: 0.92;
}

.score-panel p {
  margin: 0;
  color: #d9dee4;
}

.score-tabs {
  position: absolute;
  left: 14px;
  top: -42px;
  z-index: 2;
  display: flex;
  align-items: end;
  gap: 3px;
}

.score-tab {
  min-width: 106px;
  min-height: 42px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-bottom: 0;
  border-radius: 11px 11px 0 0;
  background: rgba(18, 21, 24, 0.72);
  color: rgba(245, 247, 250, 0.72);
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 850;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08), 0 -6px 14px rgba(0, 0, 0, 0.16);
}

.score-tab.active {
  min-height: 46px;
  background: linear-gradient(155deg, rgba(54, 59, 64, 0.98), rgba(24, 27, 30, 0.98));
  color: #ffffff;
  border-color: rgba(255, 255, 255, 0.28);
  transform: translateY(1px);
}

.score-tab-panel {
  display: grid;
  gap: 12px;
  position: relative;
  z-index: 1;
}

.score-tab-panel[hidden] {
  display: none;
}

.directions-panel h2 {
  margin: 0;
  font-size: 2rem;
  line-height: 1;
}

.settings-panel h2 {
  margin: 0 0 18px;
  font-size: 2.4rem;
  line-height: 1;
}

.setting-row {
  min-height: 92px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 12px 0;
  color: #ffffff;
  font-size: 1.2rem;
  font-weight: 800;
}

.toggle-switch {
  width: 86px;
  height: 46px;
  border: 2px solid rgba(255, 255, 255, 0.26);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.14);
  cursor: pointer;
  padding: 4px;
  transition: background 180ms ease, border-color 180ms ease;
}

.toggle-knob {
  display: block;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 5px 16px rgba(0, 0, 0, 0.35);
  transition: transform 190ms cubic-bezier(0.22, 1, 0.36, 1);
}

.toggle-switch[aria-checked="true"] {
  background: rgba(255, 255, 255, 0.62);
  border-color: rgba(255, 255, 255, 0.78);
}

.toggle-switch[aria-checked="true"] .toggle-knob {
  transform: translateX(40px);
}

.directions-panel p {
  margin: 0;
  color: #d9dee4;
  line-height: 1.45;
}

.close-button {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 38px;
  height: 38px;
  border: 2px solid rgba(255, 255, 255, 0.22);
  border-radius: 50%;
  background: rgba(20, 23, 25, 0.4);
  color: #ffffff;
  cursor: pointer;
  font-size: 1rem;
  font-weight: 900;
}

.pause-panel h2 {
  margin: 0 0 4px;
  font-size: 2.4rem;
  line-height: 1;
}

.menu-button {
  position: relative;
  overflow: hidden;
  min-height: 52px;
  border: 2px solid rgba(167, 255, 235, 0.62);
  border-radius: 8px;
  background: #a7ffeb;
  color: #141719;
  font-weight: 850;
  cursor: pointer;
}

.menu-button.secondary {
  background: transparent;
  color: #f5f7fa;
  border-color: rgba(255, 255, 255, 0.28);
}

.restart-confirm {
  display: grid;
  gap: 10px;
  margin-top: 2px;
  padding: 14px;
  border: 2px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  background: rgba(20, 23, 25, 0.46);
  animation: panel-rise 180ms cubic-bezier(0.22, 1, 0.36, 1) both;
}

.restart-confirm[hidden] {
  display: none;
}

.restart-confirm p {
  margin: 0;
  color: #ffffff;
  font-weight: 850;
  text-align: center;
}

.confirm-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.confirm-button {
  min-height: 44px;
  border: 2px solid rgba(255, 255, 255, 0.5);
  border-radius: 8px;
  background: #ffffff;
  color: #141719;
  cursor: pointer;
  font-weight: 850;
}

.confirm-button.secondary {
  background: transparent;
  color: #ffffff;
  border-color: rgba(255, 255, 255, 0.28);
}

.final-score {
  margin: 0 0 6px;
  color: var(--muted);
}

.final-score strong {
  display: block;
  margin-top: 6px;
  color: #ffffff;
  font-size: 2rem;
}

@keyframes overlay-fade {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes panel-rise {
  from {
    opacity: 0;
    transform: translateY(14px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.game-shell {
  width: min(680px, calc(100vw - 28px));
  margin: 0 auto;
  padding: 18px 0 24px;
}

body.clear-burst .game-shell {
  animation: game-jolt 520ms cubic-bezier(0.2, 1, 0.32, 1) both;
}

body.game-entering .game-shell {
  animation: board-enter 340ms cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes board-enter {
  from {
    opacity: 0;
    transform: translateY(18px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes game-jolt {
  0% {
    transform: translateX(0);
  }
  18% {
    transform: translateX(-4px) rotate(-0.25deg);
  }
  38% {
    transform: translateX(4px) rotate(0.25deg);
  }
  62% {
    transform: translateX(-2px) rotate(-0.12deg);
  }
  100% {
    transform: translateX(0) rotate(0);
  }
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}

.top-actions {
  display: flex;
  gap: 10px;
}

.label {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(2rem, 8vw, 4.25rem);
  line-height: 0.95;
}

.icon-button {
  width: 54px;
  height: 54px;
  border: 2px solid rgba(255, 255, 255, 0.5);
  border-radius: 8px;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.18), rgba(44, 47, 51, 0.9));
  color: var(--accent);
  cursor: pointer;
  display: grid;
  place-items: center;
  font-size: 1.65rem;
  font-weight: 900;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.3), 0 0 18px rgba(255, 255, 255, 0.08);
}

.icon-button:hover,
.icon-button:focus-visible {
  border-color: #ffffff;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.34), 0 0 24px rgba(255, 255, 255, 0.16);
  transform: translateY(-2px);
  outline: none;
}

.play-area {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
  align-items: center;
  justify-items: center;
}

.board {
  width: min(100%, 620px, calc(100vh - 250px));
  min-width: 300px;
  aspect-ratio: 1;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  grid-template-rows: repeat(6, 1fr);
  gap: 6px;
  padding: 8px;
  border-radius: 8px;
  background: var(--grid);
  box-shadow: var(--shadow), inset 0 0 0 1px rgba(255, 255, 255, 0.08), 0 0 36px rgba(128, 213, 255, 0.05);
  touch-action: none;
  position: relative;
  overflow: hidden;
}

.board::before {
  content: "";
  position: absolute;
  inset: -25%;
  z-index: 0;
  background:
    radial-gradient(circle at 22% 22%, rgba(167, 255, 235, 0.1), transparent 18%),
    conic-gradient(from 0deg, transparent, rgba(255, 255, 255, 0.06), transparent, rgba(128, 213, 255, 0.05), transparent);
  opacity: 0.36;
  animation: board-current 8s linear infinite;
  pointer-events: none;
}

.board.combo-burst::before {
  animation: board-current 8s linear infinite, board-flare 860ms ease-out both;
}

.board.combo-burst {
  animation: board-pulse 860ms cubic-bezier(0.2, 1, 0.32, 1) both;
}

.board.game-over-collapse {
  animation: collapse-glow 1500ms ease-out both;
}

@keyframes board-current {
  to {
    transform: rotate(1turn);
  }
}

@keyframes board-pulse {
  0% {
    box-shadow: var(--shadow), inset 0 0 0 1px rgba(255, 255, 255, 0.08), 0 0 36px rgba(128, 213, 255, 0.05);
  }
  35% {
    box-shadow: 0 24px 56px rgba(0, 0, 0, 0.46), inset 0 0 0 2px rgba(255, 255, 255, 0.22), 0 0 48px rgba(167, 255, 235, 0.26);
  }
  100% {
    box-shadow: var(--shadow), inset 0 0 0 1px rgba(255, 255, 255, 0.08), 0 0 36px rgba(128, 213, 255, 0.05);
  }
}

@keyframes board-flare {
  0% {
    opacity: 0.24;
    transform: scale(0.96) rotate(0turn);
  }
  42% {
    opacity: 0.88;
  }
  100% {
    opacity: 0.36;
    transform: scale(1.12) rotate(0.12turn);
  }
}

@keyframes collapse-glow {
  0% {
    box-shadow: var(--shadow), inset 0 0 0 1px rgba(255, 255, 255, 0.08), 0 0 36px rgba(128, 213, 255, 0.05);
  }
  42% {
    box-shadow: 0 24px 58px rgba(0, 0, 0, 0.48), inset 0 0 0 2px rgba(255, 255, 255, 0.18), 0 0 54px rgba(255, 128, 153, 0.2);
  }
  100% {
    box-shadow: var(--shadow), inset 0 0 0 1px rgba(255, 255, 255, 0.08), 0 0 36px rgba(128, 213, 255, 0.05);
  }
}

.cell {
  min-width: 0;
  min-height: 0;
  border: 0;
  border-radius: 5px;
  background: var(--cell);
  color: #ffffff;
  position: relative;
  display: grid;
  place-items: center;
  font-size: clamp(1.25rem, 6vw, 2.8rem);
  font-weight: 850;
  transition: background 120ms ease, transform 120ms ease;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04), inset 0 -10px 20px rgba(0, 0, 0, 0.08);
  z-index: 1;
}

.cell.valid-target {
  background: var(--cell-hover);
  box-shadow: inset 0 0 0 3px rgba(167, 255, 235, 0.62), 0 0 18px rgba(167, 255, 235, 0.18);
  animation: target-glow 720ms ease-in-out infinite alternate;
}

.cell.invalid-target {
  background: #6b3434;
  animation: invalid-shake 150ms linear both;
}

.cell.blocked {
  background: var(--cell);
}

.cell.clearing {
  animation: clear-pop 240ms ease forwards;
}

@keyframes target-glow {
  to {
    box-shadow: inset 0 0 0 3px rgba(255, 255, 255, 0.76), 0 0 22px rgba(167, 255, 235, 0.26);
  }
}

@keyframes invalid-shake {
  25% {
    transform: translateX(-3px);
  }
  75% {
    transform: translateX(3px);
  }
}

@keyframes clear-pop {
  to {
    transform: scale(0.78);
    opacity: 0;
  }
}

.pip {
  position: relative;
  z-index: 2;
  line-height: 1;
  color: #ffffff;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
}

.placed-domino {
  display: grid;
  gap: 0;
  z-index: 3;
  pointer-events: none;
  border-radius: 8px;
  overflow: hidden;
  position: relative;
  box-shadow:
    inset 0 0 0 2px rgba(255, 255, 255, 0.22),
    0 9px 18px rgba(0, 0, 0, 0.3);
}

.placed-domino::before {
  content: "";
  position: absolute;
  inset: -18%;
  z-index: 4;
  background: linear-gradient(105deg, transparent 18%, rgba(255, 255, 255, 0.72) 46%, rgba(167, 255, 235, 0.52) 52%, transparent 78%);
  opacity: 0;
  transform: translateX(-130%) rotate(0.001deg);
  pointer-events: none;
  mix-blend-mode: screen;
}

.placed-domino.placed-new {
  animation: domino-land 280ms cubic-bezier(0.2, 1.35, 0.32, 1) both;
}

.placed-domino.clearing {
  animation: match-clear 920ms cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.placed-domino.clearing::before {
  animation: match-shine 920ms cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.placed-domino.clearing .placed-half {
  animation: match-pulse 920ms cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.placed-domino.game-over-clearing {
  animation: game-over-domino-vanish 820ms cubic-bezier(0.16, 1, 0.3, 1) var(--collapse-delay, 0ms) forwards;
}

.placed-domino.game-over-clearing::before {
  animation: match-shine 760ms cubic-bezier(0.16, 1, 0.3, 1) var(--collapse-delay, 0ms) forwards;
}

.placed-domino.game-over-clearing .placed-half {
  animation: game-over-half-glow 820ms cubic-bezier(0.16, 1, 0.3, 1) var(--collapse-delay, 0ms) forwards;
}

@keyframes domino-land {
  0% {
    opacity: 0;
    transform: translateY(-10px) scale(0.92);
  }
  72% {
    opacity: 1;
    transform: translateY(2px) scale(1.035);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes match-clear {
  0% {
    opacity: 1;
    filter: brightness(1) saturate(1);
    transform: scale(1) rotate(0);
  }
  24% {
    opacity: 1;
    filter: brightness(1.65) saturate(1.25);
    transform: scale(1.06) rotate(-1deg);
  }
  48% {
    opacity: 1;
    filter: brightness(1.95) saturate(1.42);
    transform: scale(1.02) rotate(1.4deg);
  }
  70% {
    opacity: 0.72;
    filter: brightness(1.35) saturate(0.9) blur(0.2px);
    transform: scale(0.9) rotate(-2deg);
  }
  100% {
    opacity: 0;
    filter: brightness(1.25) saturate(0.7) blur(2px);
    transform: scale(0.32) rotate(8deg);
  }
}

@keyframes match-shine {
  0% {
    opacity: 0;
    transform: translateX(-130%);
  }
  18% {
    opacity: 0.92;
  }
  54% {
    opacity: 0.8;
    transform: translateX(130%);
  }
  100% {
    opacity: 0;
    transform: translateX(160%);
  }
}

@keyframes match-pulse {
  18% {
    box-shadow: inset 0 0 0 5px rgba(255, 255, 255, 0.52), inset 0 0 26px rgba(255, 255, 255, 0.24);
  }
  46% {
    transform: scale(1.035);
    box-shadow: inset 0 0 0 7px rgba(167, 255, 235, 0.38), inset 0 0 34px rgba(255, 255, 255, 0.22);
  }
  100% {
    transform: scale(0.92);
  }
}

@keyframes game-over-domino-vanish {
  0% {
    opacity: 1;
    filter: brightness(1) saturate(1);
    transform: scale(1) rotate(0);
  }
  25% {
    opacity: 1;
    filter: brightness(1.8) saturate(1.25);
    transform: scale(1.05) rotate(-1deg);
  }
  58% {
    opacity: 0.7;
    filter: brightness(1.35) saturate(0.8) blur(0.4px);
    transform: scale(0.82) rotate(2deg);
  }
  100% {
    opacity: 0;
    filter: brightness(1.1) saturate(0.45) blur(2.4px);
    transform: scale(0.18) rotate(-10deg);
  }
}

@keyframes game-over-half-glow {
  22% {
    box-shadow: inset 0 0 0 6px rgba(255, 255, 255, 0.48), inset 0 0 30px rgba(255, 255, 255, 0.22);
  }
  54% {
    transform: scale(0.96);
    box-shadow: inset 0 0 0 7px rgba(255, 128, 153, 0.32), inset 0 0 34px rgba(255, 255, 255, 0.18);
  }
  100% {
    transform: scale(0.78);
  }
}

.placed-domino.horizontal {
  grid-template-columns: repeat(2, 1fr);
}

.placed-domino.vertical {
  grid-template-rows: repeat(2, 1fr);
}

.placed-half {
  min-width: 0;
  min-height: 0;
  display: grid;
  place-items: center;
  background: var(--tile-color, #5a6068);
  color: #ffffff;
  font-size: clamp(1.05rem, 5vw, 2.55rem);
  font-weight: 850;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.16), inset 0 -16px 26px rgba(0, 0, 0, 0.14);
}

.placed-half.blank::after {
  content: "";
  width: 22%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.42);
}

.hand-panel {
  --tray-tile: clamp(52px, 14vw, 74px);
  width: min(100%, 620px);
  min-height: calc(var(--tray-tile) * 2 + 36px);
  border-radius: 8px;
  background: var(--panel);
  padding: 14px;
  box-shadow: var(--shadow);
  display: grid;
  place-items: center;
}

.hand-domino {
  --tile: var(--tray-tile);
  display: grid;
  width: calc(var(--tile) * 2 + 8px);
  height: var(--tile);
  grid-template-columns: repeat(2, var(--tile));
  grid-template-rows: var(--tile);
  gap: 8px;
  padding: 0;
  border-radius: 8px;
  cursor: grab;
  user-select: none;
  touch-action: none;
  margin: 0;
}

.hand-domino:active {
  cursor: grabbing;
}

.hand-domino.rotating {
  animation: hand-rotate-pop 190ms ease both;
}

@keyframes hand-rotate-pop {
  0% {
    transform: scale(1) rotate(0deg);
  }
  48% {
    transform: scale(0.94) rotate(8deg);
  }
  100% {
    transform: scale(1) rotate(0deg);
  }
}

.drag-ghost {
  position: fixed;
  z-index: 20;
  pointer-events: none;
  opacity: 0.92;
  transform: translate(-50%, -50%) rotate(2deg) scale(1.04);
  filter: drop-shadow(0 22px 24px rgba(0, 0, 0, 0.35));
}

.hand-domino.vertical {
  width: var(--tile);
  height: calc(var(--tile) * 2 + 8px);
  grid-template-columns: var(--tile);
  grid-template-rows: repeat(2, var(--tile));
}

.half {
  border-radius: 7px;
  background: var(--tile-color, #5a6068);
  color: #ffffff;
  display: grid;
  place-items: center;
  font-size: clamp(1.55rem, 6vw, 2.1rem);
  font-weight: 850;
  box-shadow: inset 0 0 0 3px rgba(255, 255, 255, 0.22), 0 7px 14px rgba(0, 0, 0, 0.24);
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
}

.half.blank::after {
  content: "";
  width: 18px;
  aspect-ratio: 1;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.42);
}

.status {
  display: none;
}

.status.danger {
  color: var(--warn);
  font-weight: 750;
}

.status.success {
  color: var(--accent);
  font-weight: 750;
}

.score-pop {
  animation: score-pop 520ms cubic-bezier(0.16, 1, 0.3, 1) both;
}

@keyframes score-pop {
  0% {
    transform: scale(1);
  }
  32% {
    transform: scale(1.18) skewX(-3deg);
    color: #ffffff;
    text-shadow: 0 0 22px rgba(167, 255, 235, 0.55);
  }
  68% {
    transform: scale(0.98) skewX(1deg);
    color: #a7ffeb;
  }
  100% {
    transform: scale(1);
  }
}

.floating-score {
  position: fixed;
  z-index: 60;
  pointer-events: none;
  color: #ffffff;
  font-size: clamp(1.5rem, 8vw, 3rem);
  font-weight: 900;
  letter-spacing: 0.04em;
  text-shadow: 0 3px 10px rgba(0, 0, 0, 0.55), 0 0 24px rgba(167, 255, 235, 0.42);
  animation: float-score 1050ms cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes float-score {
  from {
    opacity: 0;
    transform: translate(-50%, 6px) scale(0.9);
  }
  18% {
    opacity: 1;
  }
  to {
    opacity: 0;
    transform: translate(-50%, -42px) scale(1.05);
  }
}

.particle {
  position: fixed;
  z-index: 35;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  background: var(--particle-color, #a7ffeb);
  pointer-events: none;
  box-shadow: 0 0 14px var(--particle-color, #a7ffeb);
  animation: particle-burst 860ms cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.shockwave {
  position: fixed;
  z-index: 34;
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255, 255, 255, 0.72);
  border-radius: 999px;
  pointer-events: none;
  transform: translate(-50%, -50%) scale(0.2);
  box-shadow: 0 0 22px rgba(167, 255, 235, 0.46), inset 0 0 18px rgba(255, 255, 255, 0.18);
  animation: shockwave 840ms cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes particle-burst {
  42% {
    opacity: 1;
    transform: translate(calc(var(--dx) * 0.62), calc(var(--dy) * 0.62)) rotate(160deg) scale(1.1);
  }
  to {
    opacity: 0;
    transform: translate(var(--dx), var(--dy)) rotate(360deg) scale(0.18);
  }
}

@keyframes shockwave {
  0% {
    opacity: 0.95;
    transform: translate(-50%, -50%) scale(0.2);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(6.8);
  }
}

@media (max-width: 760px) {
  .game-shell {
    width: min(100vw - 18px, 560px);
    padding: 14px 0;
  }

  .board {
    width: min(100%, calc(100vh - 230px));
    min-width: 0;
  }

  .hand-panel {
    --tray-tile: clamp(50px, 15vw, 62px);
  }

  .corner-logo {
    width: min(138px, 40vw);
    opacity: 0.24;
  }
}
