*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  --bg: #0f1117;
  --panel: #1a1d27;
  --border: #2e3348;
  --text: #e8eaef;
  --muted: #8b92a8;
  --accent: #6c8cff;
  --s1: #3ecf8e;
  --s2: #f0c040;
  --s3: #f07050;
  --s4: #1a1a1a;
  --empty: #252836;
  --cell-size: clamp(48px, 10vw, 72px);
  --rule-cell: 52px;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.app {
  max-width: 720px;
  margin: 0 auto;
  padding: 1.5rem 1rem 3rem;
}

header h1 {
  margin: 0 0 0.25rem;
  font-size: 1.75rem;
  font-weight: 700;
}

.setup {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.rules-panel {
  width: 100%;
}

.rules-title {
  margin: 0 0 0.65rem;
  font-size: 1.05rem;
  font-weight: 700;
}

.rules-list {
  margin: 0;
  padding-left: 1.15rem;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.55;
}

.rules-list li {
  margin-bottom: 0.35rem;
}

.rules-list li:last-child {
  margin-bottom: 0;
}

.rules-list strong {
  color: var(--text);
}

.rules-intro {
  margin: 0 0 1rem;
  color: var(--muted);
  font-size: 0.88rem;
}

.rules-visual {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 0.75rem;
}

.rule-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.rule-card--wide {
  grid-column: 1 / -1;
}

.rule-card__text {
  margin: 0;
  font-size: 0.82rem;
  line-height: 1.45;
  color: var(--muted);
}

.rule-card__text strong {
  color: var(--text);
}

.rule-demo {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 88px;
  gap: 0.35rem;
}

.rule-cell {
  width: var(--rule-cell);
  height: var(--rule-cell);
  border-radius: 8px;
  position: relative;
  flex-shrink: 0;
  overflow: visible;
}

.rule-cell.pancake {
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.15);
  perspective: 320px;
}

.rule-cell .cell-face,
.rule-cell .cell-side {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  border-radius: 8px;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.15);
}

.rule-cell .cell-value-face {
  font-size: 1rem;
}

.rule-cell .cell-value-back {
  font-size: 0.55rem;
}

.rule-cell.empty,
.rule-demo-slot {
  background: var(--empty);
}

.rule-demo-board,
.rule-demo-move,
.rule-demo-collect,
.rule-demo-red-grid,
.rule-demo-combos {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.rule-demo-arrow {
  color: var(--accent);
  font-weight: 800;
  font-size: 1.1rem;
}

.rule-demo-caption {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.rule-demo-caption--pulse {
  animation: ruleCaptionPulse 2s ease-in-out infinite;
}

@keyframes ruleCaptionPulse {
  0%, 100% { opacity: 0.55; }
  50% { opacity: 1; color: var(--accent); }
}

/* Авто +1 и переворот */
.rule-demo-tick {
  animation: cellTick 1.4s ease-out infinite;
}

.rule-demo-flip {
  padding: 0;
  background: transparent !important;
}

.rule-demo-flipper {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  animation: ruleFlipLoop 2.8s ease-in-out infinite;
}

.rule-demo-flipper .cell-side {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
}

.rule-demo-flipper .cell-side--arrive {
  transform: rotateY(180deg);
}

@keyframes ruleFlipLoop {
  0%, 38% { transform: rotateY(0deg); }
  50%, 88% { transform: rotateY(180deg); }
  100% { transform: rotateY(360deg); }
}

/* Сбор и перемещение */
.rule-demo-drag {
  animation: ruleDragUp 2.2s ease-in-out infinite;
}

.rule-demo-drag-path {
  font-size: 1.35rem;
  color: var(--s1);
  animation: ruleDragPath 2.2s ease-in-out infinite;
}

.rule-demo-drop {
  min-width: 56px;
  min-height: 40px;
  border: 2px dashed var(--border);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.65rem;
  font-weight: 800;
  color: var(--s1);
  animation: ruleDropGlow 2.2s ease-in-out infinite;
}

@keyframes ruleDragUp {
  0%, 100% { transform: translate(0, 0); opacity: 1; }
  35%, 55% { transform: translate(12px, -14px) scale(0.92); opacity: 0.55; }
  70% { transform: translate(0, 0); opacity: 1; }
}

@keyframes ruleDragPath {
  0%, 30%, 100% { opacity: 0.35; }
  45%, 60% { opacity: 1; }
}

@keyframes ruleDropGlow {
  0%, 100% { border-color: var(--border); background: transparent; }
  45%, 60% { border-color: var(--s1); background: rgba(62, 207, 142, 0.15); }
}

.rule-demo-slot {
  animation: ruleSlotHint 2.2s ease-in-out infinite 0.4s;
}

@keyframes ruleSlotHint {
  0%, 100% { outline: none; }
  50% { outline: 2px dashed var(--accent); outline-offset: 2px; }
}

.rule-demo-move {
  margin-top: 0.25rem;
}

/* Дедлайн / счёт */
.rule-demo-hud {
  width: 100%;
  max-width: 160px;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.rule-demo-counter {
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--s1);
  text-align: center;
}

.rule-demo-counter-val {
  animation: ruleScoreTick 3s steps(6) infinite;
}

@keyframes ruleScoreTick {
  0% { opacity: 1; }
  16% { opacity: 0.4; transform: scale(1.08); }
  20% { opacity: 1; transform: scale(1); }
}

.rule-demo-timer {
  height: 8px;
  border-radius: 999px;
  background: #12151f;
  border: 1px solid var(--border);
  overflow: hidden;
}

.rule-demo-timer-fill {
  height: 100%;
  width: 35%;
  border-radius: inherit;
  background: linear-gradient(90deg, #4a6fd6, var(--accent));
  animation: ruleTimerDrain 3s linear infinite;
}

@keyframes ruleTimerDrain {
  0% { width: 92%; }
  100% { width: 8%; }
}

/* Сгорание */
.rule-demo-burn {
  animation: cellCrumble 2.4s ease-in forwards infinite;
  outline: 3px solid var(--s3);
  outline-offset: 2px;
}

/* Синяя колонка */
.rule-demo-column {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.rule-demo-col-cell {
  animation: ruleColIdle 2.5s ease-in-out infinite;
}

.rule-demo-col-blue .cell-face {
  animation: ruleColDrain 2.5s ease-in-out infinite;
}

.rule-demo-col-cell:nth-child(1) { animation-delay: 0s; }
.rule-demo-col-cell:nth-child(2) { animation-delay: 0.15s; }
.rule-demo-col-cell:nth-child(3) { animation-delay: 0.3s; }

@keyframes ruleColDrain {
  0%, 25%, 100% { filter: brightness(1); outline: none; }
  12% { filter: brightness(1.25); box-shadow: 0 0 0 2px #4a9eff; }
}

@keyframes ruleColIdle {
  0%, 25%, 100% { transform: scale(1); }
  12% { transform: scale(1.05); }
}

/* Красная */
.rule-demo-red-grid {
  display: grid;
  grid-template-columns: repeat(3, var(--rule-cell));
  gap: 4px;
}

.rule-demo-red-center .cell-red-mark {
  animation: ruleRedPulse 2s ease-in-out infinite;
}

.rule-demo-red-grid .cell--has-bonus .cell-value-face {
  animation: ruleBonusPop 2s ease-in-out infinite;
}

@keyframes ruleRedPulse {
  0%, 100% { box-shadow: 0 0 8px rgba(240, 90, 70, 0.5); }
  50% { box-shadow: 0 0 16px rgba(240, 90, 70, 0.85); transform: scale(1.1); }
}

@keyframes ruleBonusPop {
  0%, 70%, 100% { opacity: 1; }
  35% { opacity: 0.5; transform: scale(1.12); }
}

/* Комбо */
.rule-demo-combos {
  gap: 0.5rem;
}

.rule-demo-combos .rule-cell {
  animation: comboBadgePop 2.4s ease-out infinite;
}

.rule-demo-combos .rule-cell:nth-child(2) { animation-delay: 0.25s; }
.rule-demo-combos .rule-cell:nth-child(3) { animation-delay: 0.5s; }

.rule-demo-score {
  font-size: 0.72rem;
  font-weight: 800;
  color: var(--s2);
}

.rule-demo-score--pop {
  animation: ruleScoreBonus 2.4s ease-in-out infinite;
}

@keyframes ruleScoreBonus {
  0%, 100% { opacity: 0.5; transform: translateY(0); }
  50% { opacity: 1; transform: translateY(-3px); }
}

@media (max-width: 440px) {
  :root {
    --rule-cell: 46px;
  }

  .rules-visual {
    grid-template-columns: 1fr;
  }
}

.btn--play {
  width: 100%;
  padding: 0.85rem 1.25rem;
  font-size: 1.1rem;
}

.setup-settings {
  width: 100%;
  border-top: 1px solid var(--border);
  padding-top: 0.75rem;
}

.setup-settings summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 600;
  user-select: none;
}

.setup-settings-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: flex-end;
  margin-top: 0.85rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.field label {
  font-size: 0.85rem;
  color: var(--muted);
}

.field input {
  width: 5rem;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
}

.field--range .range-inputs {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.field--range .range-inputs input {
  width: 3.5rem;
}

.range-sep {
  color: var(--muted);
  font-size: 0.9rem;
}

.btn {
  padding: 0.55rem 1.1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  font-size: 0.95rem;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}

.btn:hover {
  background: #252a3a;
}

.btn:active {
  transform: scale(0.98);
}

.btn.primary {
  background: var(--accent);
  border-color: transparent;
  color: #fff;
  font-weight: 600;
}

.btn.primary:hover {
  filter: brightness(1.08);
}

.btn--sell {
  border-color: rgba(62, 207, 142, 0.45);
  color: var(--s1);
  font-weight: 600;
}

.btn--sell:hover {
  background: rgba(62, 207, 142, 0.12);
}

.hint {
  flex: 1 1 100%;
  margin: 0;
  font-size: 0.85rem;
  color: #f07050;
  min-height: 1.2em;
}

.hidden {
  display: none !important;
}

.hud {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.hud-top {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.75rem;
  align-items: stretch;
}

.timer-block {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.65rem 0.75rem 0.75rem;
}

.timer-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 0.45rem;
  gap: 0.5rem;
}

.timer-title {
  font-size: 0.78rem;
  color: var(--muted);
  font-weight: 600;
}

.timer-label {
  font-size: 1rem;
  font-weight: 800;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.timer-track {
  position: relative;
  height: 14px;
  border-radius: 999px;
  background: #12151f;
  border: 1px solid var(--border);
  overflow: hidden;
}

.timer-fill {
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: linear-gradient(90deg, #4a6fd6 0%, var(--accent) 55%, #9eb4ff 100%);
  box-shadow: 0 0 16px rgba(108, 140, 255, 0.55);
}

.timer-track--ready .timer-fill {
  background: linear-gradient(90deg, var(--s2) 0%, #fff2a8 100%);
  box-shadow: 0 0 20px rgba(240, 192, 64, 0.65);
  animation: timerPulse 0.35s ease-in-out infinite alternate;
}

.timer-track--busy .timer-fill {
  background: linear-gradient(90deg, var(--s3) 0%, #ffb199 100%);
  animation: timerBusy 0.5s ease-in-out infinite alternate;
}

.timer-track--slowmo .timer-fill {
  background: linear-gradient(90deg, #5a8fd6 0%, #9eb4ff 55%, #c8d8ff 100%);
  box-shadow: 0 0 14px rgba(158, 180, 255, 0.45);
  filter: saturate(0.85);
}

@keyframes timerPulse {
  from { filter: brightness(1); }
  to { filter: brightness(1.25); }
}

@keyframes timerBusy {
  from { opacity: 0.75; }
  to { opacity: 1; }
}

.counter,
.drop-zone {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.75rem;
}

.counter {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 0.2rem;
  position: relative;
  overflow: visible;
  transform-origin: center;
}

.counter-label {
  color: var(--muted);
  font-size: 0.78rem;
}

.counter strong {
  font-size: 1.3rem;
  line-height: 1;
}

.counter--score strong {
  color: var(--s1);
}

.counter--pop {
  animation: counterPop 0.32s cubic-bezier(0.2, 1.6, 0.35, 1);
}

.counter--good {
  box-shadow:
    0 0 0 1px rgba(62, 207, 142, 0.55),
    0 0 26px rgba(62, 207, 142, 0.22);
}

.counter--bad {
  box-shadow:
    0 0 0 1px rgba(240, 112, 80, 0.55),
    0 0 26px rgba(240, 112, 80, 0.22);
}

.counter-float {
  position: absolute;
  right: 0.7rem;
  top: 0.25rem;
  font-weight: 900;
  font-size: 1.1rem;
  pointer-events: none;
  text-shadow:
    0 2px 0 rgba(0, 0, 0, 0.6),
    0 0 14px currentColor;
  animation: counterFloat 0.85s ease-out forwards;
  z-index: 5;
}

.counter-float--good {
  color: var(--s1);
}

.counter-float--bad {
  color: var(--s3);
}

.counter-float--neutral {
  color: var(--s2);
}

.counter--neutral {
  box-shadow:
    0 0 0 1px rgba(240, 192, 64, 0.55),
    0 0 26px rgba(240, 192, 64, 0.22);
}

.counter-sub {
  font-size: 0.72rem;
  color: var(--muted);
  margin-top: 0.15rem;
}

@keyframes counterPop {
  0% { transform: scale(1) rotate(0deg); }
  35% { transform: scale(1.18) rotate(-2deg); }
  62% { transform: scale(0.94) rotate(1deg); }
  100% { transform: scale(1) rotate(0deg); }
}

@keyframes counterFloat {
  0% {
    opacity: 0;
    transform: translateY(8px) scale(0.75) rotate(-4deg);
  }
  15% {
    opacity: 1;
    transform: translateY(-2px) scale(1.2) rotate(3deg);
  }
  100% {
    opacity: 0;
    transform: translateY(-34px) scale(0.95) rotate(-2deg);
  }
}

.drop-zone {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 64px;
  color: var(--muted);
  font-weight: 700;
  text-align: center;
  border-style: dashed;
  transition: border-color 0.15s, background 0.15s, color 0.15s, transform 0.15s;
}

.drop-zone--active {
  background: rgba(108, 140, 255, 0.15);
  border-color: var(--accent);
  color: var(--text);
  transform: translateY(-1px);
}

.drop-zone--collect {
  background: rgba(62, 207, 142, 0.18);
  border-color: var(--s1);
  color: var(--s1);
  animation: dropCollect 0.4s ease-out;
}

.drop-zone--reset {
  background: rgba(240, 192, 64, 0.15);
  border-color: var(--s2);
  color: var(--s2);
  animation: dropReset 0.5s ease-out;
}

@keyframes dropCollect {
  0% { transform: scale(1); }
  40% { transform: scale(1.04); box-shadow: 0 0 24px rgba(62, 207, 142, 0.35); }
  100% { transform: scale(1); }
}

@keyframes dropReset {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(0.97); filter: brightness(1.2); }
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.toolbar-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

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

.board-wrap {
  display: flex;
  justify-content: center;
  margin-bottom: 1rem;
  overflow: visible;
  border-radius: 14px;
  transition: box-shadow 0.2s;
}

.board-wrap--tick {
  box-shadow: 0 0 0 2px rgba(108, 140, 255, 0.45), 0 0 28px rgba(108, 140, 255, 0.2);
}

.board {
  display: grid;
  gap: 4px;
  padding: 8px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: visible;
}

.cell {
  width: var(--cell-size);
  height: var(--cell-size);
  border: none;
  border-radius: 8px;
  cursor: default;
  position: relative;
  transition: transform 0.2s ease, box-shadow 0.2s, filter 0.15s;
  font-size: 1.1rem;
  font-weight: 700;
  color: rgba(0, 0, 0, 0.55);
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.25);
  overflow: visible;
  padding: 0;
  background: transparent;
  font-family: inherit;
}

.cell[role="button"]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.cell-face {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  border-radius: 8px;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.15);
  pointer-events: none;
}

.cell-values {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.12rem;
  line-height: 1;
  text-shadow: inherit;
}

.cell-value-face {
  font-size: clamp(0.65rem, 2.5vw, 1.05rem);
  font-weight: 700;
  white-space: nowrap;
}

.cell-value-back {
  font-size: clamp(0.5rem, 1.8vw, 0.62rem);
  font-weight: 600;
  opacity: 0.8;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.cell-side .cell-value-back {
  opacity: 0.85;
}

.cell.empty {
  background: var(--empty);
  cursor: default;
  pointer-events: none;
}

.board-wrap--pan-drag .cell.empty {
  pointer-events: auto;
  cursor: copy;
}

.cell.empty.cell--drop-hint {
  outline: 2px dashed var(--accent);
  outline-offset: 2px;
  background: rgba(108, 140, 255, 0.12);
  box-shadow: inset 0 0 0 1px rgba(108, 140, 255, 0.35);
}

.cell.pancake {
  cursor: pointer;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.15);
  perspective: 520px;
}

.cell.pancake[draggable="true"] {
  cursor: grab;
}

.cell.pancake[draggable="true"]:active {
  cursor: grabbing;
}

.cell--dragging {
  opacity: 0.45;
}

.cell--drag-ghost {
  opacity: 0.92;
  pointer-events: none;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}

.cell--tick {
  animation: cellTick 0.28s ease-out;
  z-index: 2;
}

.cell--drain {
  animation: cellDrain 0.35s ease-out;
  outline: 2px solid #4a9eff;
  outline-offset: 2px;
}

.cell-blue-mark,
.cell-red-mark {
  position: absolute;
  top: 4px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.85);
  pointer-events: none;
  z-index: 7;
}

.pancake.cell--combo-pair .cell-combo-badge--pair,
.pancake.cell--combo-high .cell-combo-badge--high,
.pancake.cell--combo-nine .cell-combo-badge--nine {
  z-index: 8;
}

.cell-blue-mark {
  right: 4px;
  background: linear-gradient(145deg, #6eb8ff, #2a6fd6);
  box-shadow: 0 0 10px rgba(74, 158, 255, 0.65);
}

.cell-red-mark {
  left: 4px;
  background: linear-gradient(145deg, #ff8a7a, #d63a2a);
  box-shadow: 0 0 10px rgba(240, 90, 70, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.55rem;
  font-weight: 800;
  color: #fff;
  line-height: 1;
}

.cell-combo-badges {
  position: absolute;
  left: 2px;
  right: 2px;
  bottom: 2px;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 1px;
  pointer-events: none;
  z-index: 6;
  max-height: 28%;
}

.cell-combo-badge {
  position: static;
  transform: none;
  font-size: 0.34rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  text-transform: lowercase;
  padding: 0.05rem 0.2rem;
  border-radius: 3px;
  pointer-events: none;
  white-space: nowrap;
  line-height: 1;
  opacity: 0.92;
}

.cell-combo-badge--pair {
  background: rgba(240, 192, 64, 0.9);
  color: #1a1408;
}

.cell-combo-badge--high {
  background: rgba(255, 140, 60, 0.9);
  color: #2a1208;
}

.cell-combo-badge--nine {
  background: linear-gradient(135deg, #c77dff, #7b5cff);
  color: #fff;
}

.pancake.cell--has-bonus .cell-value-face,
.pancake.cell--has-bonus .cell-value-back {
  color: inherit;
}

.pancake.cell--has-bonus {
  box-shadow:
    inset 0 -3px 0 rgba(0, 0, 0, 0.15),
    0 0 0 1px rgba(108, 140, 255, 0.4);
}

.pancake.cell--hot {
  outline: 2px solid rgba(240, 112, 80, 0.75);
  outline-offset: 2px;
}

.cell-value-back-chip {
  display: inline-block;
  padding: 0.08rem 0.28rem;
  border-radius: 4px;
  line-height: 1.1;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.2);
}

.pancake.cell--combo-pair:not(.cell--combo-high):not(.cell--combo-nine),
.pancake.cell--combo-high:not(.cell--combo-nine),
.pancake.cell--combo-nine {
  outline: none;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.15);
}

.pancake.cell--has-flipper .cell-blue-mark,
.pancake.cell--has-flipper .cell-red-mark {
  z-index: 8;
}

@keyframes cellDrain {
  0% { filter: brightness(1); }
  40% { filter: brightness(1.2) hue-rotate(-15deg); }
  100% { filter: brightness(1); }
}

.cell--crumble {
  z-index: 4;
  pointer-events: none;
  animation: cellCrumble 0.65s ease-in forwards;
  outline: 3px solid var(--s3);
  outline-offset: 2px;
  box-shadow: 0 0 22px rgba(240, 112, 80, 0.55);
}

.cell--spawn {
  z-index: 3;
  animation: cellSpawn 0.52s cubic-bezier(0.2, 1.4, 0.35, 1);
  outline: 3px solid var(--s1);
  outline-offset: 2px;
  box-shadow: 0 0 22px rgba(62, 207, 142, 0.45);
}

.cell--flip-fx {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.cell-fx-label {
  position: absolute;
  left: 50%;
  top: -0.45rem;
  transform: translateX(-50%);
  font-size: 0.58rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 0.12rem 0.35rem;
  border-radius: 4px;
  pointer-events: none;
  z-index: 6;
  white-space: nowrap;
}

.cell-fx-label--burn {
  background: var(--s3);
  color: #fff;
  animation: labelPop 0.35s ease-out;
}

.cell-fx-label--spawn {
  background: var(--s1);
  color: #0f1117;
  animation: labelPop 0.35s ease-out;
}

.crumble-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: visible;
  z-index: 5;
}

.crumble-bit {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 7px;
  height: 7px;
  margin: -3px 0 0 -3px;
  border-radius: 2px;
  background: #c45a3a;
  opacity: 0.95;
  animation: crumbleBit 0.6s ease-out forwards;
}

@keyframes cellTick {
  0% { filter: brightness(1); transform: scale(1); }
  35% { filter: brightness(1.35); transform: scale(1.06); }
  100% { filter: brightness(1); transform: scale(1); }
}

@keyframes cellCrumble {
  0% { transform: scale(1) rotate(0deg); opacity: 1; }
  35% { transform: scale(1.08) rotate(-3deg); }
  100% { transform: scale(0.2) rotate(12deg); opacity: 0; filter: grayscale(1); }
}

@keyframes cellSpawn {
  0% { transform: scale(0.2); opacity: 0; }
  55% { transform: scale(1.12); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes crumbleBit {
  0% { opacity: 1; transform: translate(0, 0) rotate(0deg); }
  100% {
    opacity: 0;
    transform: translate(var(--bx), var(--by)) rotate(var(--br));
  }
}

@keyframes labelPop {
  0% { opacity: 0; transform: translateX(-50%) scale(0.6); }
  100% { opacity: 1; transform: translateX(-50%) scale(1); }
}

.cell.pancake.cell--hint {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
  z-index: 3;
  box-shadow:
    inset 0 -3px 0 rgba(0, 0, 0, 0.15),
    0 0 0 1px rgba(108, 140, 255, 0.35);
}

.hint-mark {
  color: var(--accent);
}

.blue-mark {
  color: #6eb8ff;
}

.red-mark {
  color: #ff8a7a;
}

/* --- Анимация (визуальный поворот карточки) --- */
.cell--has-flipper {
  padding: 0;
  background: transparent !important;
}

.cell-flipper {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.42s ease;
  border-radius: 8px;
}

.cell-flipper--turned {
  transform: rotateY(180deg);
}

.cell-side {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  backface-visibility: hidden;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.15);
}

.cell-side--arrive {
  transform: rotateY(180deg);
}

.cell.pancake:hover:not(:disabled):not(.cell--has-flipper) {
  filter: brightness(1.08);
  transform: translateY(-2px);
}

.cell.pancake.cell--has-flipper:hover:not(:disabled) {
  filter: brightness(1.06);
}

.cell.pancake:active:not(:disabled):not(.cell--has-flipper) {
  transform: translateY(0) scale(0.97);
}

.lose-mark {
  color: var(--s3);
}

.cell[aria-disabled="true"] {
  cursor: not-allowed;
  opacity: 0.85;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  justify-content: center;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 0.75rem;
}

.legend strong {
  color: var(--text);
}

.message {
  text-align: center;
  min-height: 1.5em;
  font-size: 1.05rem;
  font-weight: 600;
}

.message.win { color: var(--s1); }
.message.lose { color: var(--s3); }

@media (max-width: 400px) {
  :root {
    --cell-size: 44px;
  }

  .hud-top {
    grid-template-columns: 1fr;
  }
}
