:root {
  --bg-0: #0a0820;
  --bg-1: #140a35;
  --bg-2: #1d0f4d;
  --panel: rgba(255, 255, 255, 0.06);
  --panel-strong: rgba(255, 255, 255, 0.12);
  --panel-border: rgba(255, 255, 255, 0.12);
  --text: #f3eeff;
  --muted: #b3a8d8;
  --accent: #8a5bff;
  --accent-2: #ff5bd1;
  --accent-3: #5be0ff;
  --good: #4ee08a;
  --bad: #ff6680;
  --gold: #ffce5b;
  --cell-bg: rgba(255, 255, 255, 0.04);
  --cell-border: rgba(255, 255, 255, 0.07);
  --tile-grad: linear-gradient(160deg, #ffffff 0%, #e9defe 100%);
  --tile-letter: #2a134d;
  --shadow-lg: 0 22px 60px -20px rgba(138, 91, 255, 0.55), 0 8px 24px -12px rgba(0, 0, 0, 0.5);
  --shadow-md: 0 10px 30px -12px rgba(0, 0, 0, 0.55);
  --radius-xl: 24px;
  --radius-lg: 18px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --board-gap: 5px;
  --nav-h: 76px;
  --topbar-h: 52px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  font-family: 'Manrope', system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(1200px 700px at 10% -10%, rgba(138, 91, 255, 0.35), transparent 60%),
    radial-gradient(900px 600px at 110% 20%, rgba(255, 91, 209, 0.25), transparent 60%),
    radial-gradient(700px 600px at 50% 110%, rgba(91, 224, 255, 0.18), transparent 60%),
    linear-gradient(180deg, var(--bg-0), var(--bg-1) 60%, var(--bg-2));
  overscroll-behavior: none;
  touch-action: manipulation;
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

button { font: inherit; }

.bg-orbs { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 0; }
.orb { position: absolute; border-radius: 50%; filter: blur(80px); opacity: 0.5; animation: float 18s ease-in-out infinite; }
.orb-1 { width: 380px; height: 380px; background: #8a5bff; top: -120px; left: -100px; }
.orb-2 { width: 420px; height: 420px; background: #ff5bd1; top: 30%; right: -160px; animation-delay: -6s; }
.orb-3 { width: 320px; height: 320px; background: #5be0ff; bottom: -120px; left: 30%; animation-delay: -12s; }
@keyframes float { 0%,100% { transform: translateY(0) translateX(0); } 50% { transform: translateY(-30px) translateX(20px); } }

/* ====== APP SHELL ====== */
.app-shell {
  position: relative;
  z-index: 1;
  width: min(560px, 100%);
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: 0 12px calc(var(--nav-h) + env(safe-area-inset-bottom));
}

/* ====== TOPBAR ====== */
.topbar {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 0;
}
.topbar-spacer { flex: 1; }
.topbar-btn { width: 40px; height: 40px; }
.coin-button {
  min-height: 48px;
  padding: 0 14px;
  border: 1px solid rgba(255,255,255,0.16);
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  color: #27143d;
  background: linear-gradient(135deg, #ffe28a, #ffb84d);
  box-shadow: 0 12px 28px -14px rgba(255,206,91,0.9), inset 0 1px 0 rgba(255,255,255,0.55);
  font-weight: 900;
  cursor: pointer;
}
.coin-button:active { transform: scale(0.97); }
.coin-plus {
  width: 20px;
  height: 20px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(255,255,255,0.46);
  font-size: 15px;
  line-height: 1;
}

/* ====== GAME LAYOUT ====== */
.game-layout {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: stretch;
  padding-top: 4px;
}

/* score */
.score-strip {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.score-card {
  padding: 8px 10px;
  border-radius: var(--radius-md);
  background: var(--panel);
  backdrop-filter: blur(10px);
  border: 1px solid var(--panel-border);
  box-shadow: var(--shadow-md);
  text-align: center;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}
.score-card.bump { transform: translateY(-3px) scale(1.04); box-shadow: 0 18px 40px -16px rgba(138,91,255,0.7); }
.score-card .label {
  display: block; font-size: 10px; text-transform: uppercase;
  letter-spacing: 0.1em; color: var(--muted); font-weight: 700;
}
.score-card .value {
  display: block; margin-top: 2px;
  font-size: 20px; font-weight: 900; font-family: 'Unbounded', sans-serif;
  line-height: 1.1;
}
.score-card.best .value { color: var(--gold); }
.score-card.combo-card .value { color: var(--accent-3); }
.score-card.combo-card.hot .value { color: var(--accent-2); text-shadow: 0 0 12px rgba(255,91,209,0.6); }

/* status */
.status-card {
  background: var(--panel);
  backdrop-filter: blur(12px);
  border-radius: var(--radius-lg);
  border: 1px solid var(--panel-border);
  box-shadow: var(--shadow-md);
  padding: 10px 12px;
}
.status-card.word-phase-active {
  border-color: rgba(255, 206, 91, 0.72);
  box-shadow: var(--shadow-md), 0 0 22px rgba(255,206,91,0.18);
  animation: wordPhaseStatusPulse 1.05s ease-in-out infinite alternate;
}
.status-card.word-phase-active .status-text { color: var(--text); }
.status-card.word-phase-exiting { transition: opacity 0.18s ease; opacity: 0.78; }
.status-row { display: flex; align-items: center; gap: 10px; }
.status-text {
  flex: 1;
  color: var(--muted);
  line-height: 1.4;
  font-size: 13px;
  min-height: 0;
}
.status-text b { color: var(--text); }
.status-undo { width: 36px; height: 36px; flex-shrink: 0; }
.skip-word-button {
  min-width: 48px;
  min-height: 48px;
  border: 1px solid rgba(255,255,255,0.22);
  border-radius: 12px;
  padding: 0 12px;
  background: rgba(255,255,255,0.1);
  color: var(--text);
  font-weight: 900;
  font-size: 12px;
  cursor: pointer;
  flex-shrink: 0;
  transition: transform 0.15s ease, opacity 0.18s ease, background 0.15s ease;
}
.skip-word-button[hidden] { display: none; }
.skip-word-button:hover { background: rgba(255,255,255,0.16); transform: translateY(-1px); }
.skip-word-button:active { transform: translateY(0) scale(0.98); }
.skip-word-button:disabled { opacity: 0.55; cursor: wait; }
.skip-word-button.word-phase-exiting { opacity: 0; transform: translateY(4px); }
@keyframes wordPhaseStatusPulse {
  from { filter: brightness(1); }
  to { filter: brightness(1.12); }
}

/* board */
.board-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
}
.board {
  width: 100%;
  aspect-ratio: 1 / 1;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  gap: var(--board-gap);
  padding: 10px;
  border-radius: var(--radius-xl);
  background:
    linear-gradient(160deg, rgba(255,255,255,0.08), rgba(255,255,255,0.02)),
    rgba(20, 10, 50, 0.5);
  border: 1px solid rgba(255,255,255,0.08);
  box-shadow: var(--shadow-lg);
  position: relative;
  user-select: none;
  touch-action: none;
}

.board-cell {
  position: relative;
  border-radius: 10px;
  background: var(--cell-bg);
  border: 1px solid var(--cell-border);
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
  transition: background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}
.board-cell.preview-valid {
  background: rgba(78, 224, 138, 0.22);
  border-color: rgba(78, 224, 138, 0.7);
  box-shadow: inset 0 0 0 1px rgba(78,224,138,0.4);
}
.board-cell.preview-invalid {
  background: rgba(255, 102, 128, 0.22);
  border-color: rgba(255, 102, 128, 0.65);
}
.board-cell.preview-word {
  box-shadow: inset 0 0 0 2px rgba(255, 206, 91, 0.85), 0 0 18px rgba(255,206,91,0.3);
  background: rgba(255, 206, 91, 0.18);
}
.board-cell.preview-bonus {
  background: rgba(255, 206, 91, 0.3);
  border-color: rgba(255, 206, 91, 0.95);
  box-shadow: inset 0 0 0 2px rgba(255, 206, 91, 1), 0 0 24px rgba(255,206,91,0.55);
  animation: bonusPreviewPulse 0.75s ease-in-out infinite alternate;
}
@keyframes bonusPreviewPulse {
  from { filter: brightness(1); }
  to { filter: brightness(1.28); }
}
.board-cell.pending-line {
  background: rgba(91, 224, 255, 0.13);
  border-color: rgba(91, 224, 255, 0.58);
  box-shadow: inset 0 0 0 1px rgba(91,224,255,0.55), 0 0 12px rgba(91,224,255,0.18);
  animation: pendingLinePulse 1.05s ease-in-out infinite alternate;
}
.board-cell.pending-line-bonus {
  background: rgba(255, 206, 91, 0.17);
  border-color: rgba(255, 206, 91, 0.72);
  box-shadow: inset 0 0 0 1px rgba(255,206,91,0.7), 0 0 15px rgba(255,206,91,0.24);
}
.board-cell.pending-line .tile {
  box-shadow: inset 0 2px 0 rgba(255,255,255,0.82), 0 0 12px rgba(91,224,255,0.24);
}
@keyframes pendingLinePulse {
  from { filter: brightness(1); }
  to { filter: brightness(1.12); }
}
.board-cell.selected-word {
  background: rgba(138, 91, 255, 0.28);
  border-color: rgba(138, 91, 255, 0.8);
  box-shadow: inset 0 0 0 2px rgba(138,91,255,0.7), 0 0 16px rgba(138,91,255,0.35);
}
.board-cell.word-candidate-best {
  background: rgba(255, 206, 91, 0.24);
  border-color: rgba(255, 206, 91, 0.95);
  box-shadow: inset 0 0 0 2px rgba(255,206,91,0.95), 0 0 18px rgba(255,206,91,0.45);
  animation: wordCandidateGlow 0.9s ease-in-out infinite alternate;
}
.board-cell.word-candidate-best .tile {
  transform: scale(1.06);
  filter: brightness(1.18) saturate(1.08);
}
.board-cell.word-candidate-alt {
  background: rgba(91, 224, 255, 0.14);
  border-color: rgba(91, 224, 255, 0.55);
  box-shadow: inset 0 0 0 1px rgba(91,224,255,0.55);
}
.board.word-phase-exiting .board-cell.word-candidate-best,
.board.word-phase-exiting .board-cell.word-candidate-alt {
  opacity: 0;
  transform: scale(0.96);
  transition: opacity 0.18s ease, transform 0.18s ease;
}
.board-cell.word-new-letter .tile {
  box-shadow: inset 0 2px 0 rgba(255,255,255,0.95), inset 0 -3px 0 rgba(98, 56, 173, 0.18), 0 0 0 2px rgba(255,255,255,0.72), 0 0 18px rgba(255,255,255,0.3);
}
.board-cell.word-hint {
  background: rgba(78, 224, 138, 0.22);
  border-color: rgba(78, 224, 138, 0.88);
  box-shadow: inset 0 0 0 2px rgba(78,224,138,0.8), 0 0 22px rgba(78,224,138,0.36);
  animation: hintPathPulse 1s ease-in-out infinite alternate;
}
.board-cell.word-hint .tile {
  transform: scale(1.04);
  filter: brightness(1.16) saturate(1.08);
}
.board-cell.remove-tile-target {
  cursor: crosshair;
  border-color: rgba(255, 206, 91, 0.85);
  box-shadow: inset 0 0 0 2px rgba(255,206,91,0.5);
}
.board-cell.remove-tile-target .tile {
  animation: removeTilePulse 0.8s ease-in-out infinite alternate;
}
@keyframes wordCandidateGlow {
  from { filter: brightness(1); }
  to { filter: brightness(1.2); }
}
@keyframes hintPathPulse {
  from { filter: brightness(1); }
  to { filter: brightness(1.18); }
}
@keyframes removeTilePulse {
  from { transform: scale(1); }
  to { transform: scale(0.92); }
}
.board-cell.hint-pulse { animation: hintPulse 0.9s ease-in-out 2; }
@keyframes hintPulse { 0%,100% { box-shadow: inset 0 0 0 2px rgba(91,224,255,0.6); } 50% { box-shadow: inset 0 0 0 3px rgba(91,224,255,1), 0 0 22px rgba(91,224,255,0.55); } }

.tile {
  width: 100%; height: 100%;
  border-radius: 9px;
  background: var(--tile-grad);
  box-shadow: inset 0 2px 0 rgba(255,255,255,0.95), inset 0 -3px 0 rgba(98, 56, 173, 0.18), 0 4px 10px rgba(20,8,55,0.4);
  border: 1px solid rgba(255,255,255,0.55);
  color: var(--tile-letter);
  font-weight: 900;
  font-size: clamp(14px, 4.2vw, 24px);
  display: flex; align-items: center; justify-content: center;
  text-transform: uppercase;
  font-family: 'Unbounded', sans-serif;
  animation: tilePop 0.28s cubic-bezier(.34,1.56,.64,1);
}
@keyframes tilePop { 0% { transform: scale(0.4); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }
.tile.warm { background: linear-gradient(160deg, #fff7d6 0%, #ffd58a 100%); color: #5a3a06; border-color: rgba(255,196,93,0.85); }
.tile.cool { background: linear-gradient(160deg, #e1f5ff 0%, #b6d8ff 100%); color: #143a66; border-color: rgba(154,200,255,0.9); }
.tile.rare { background: linear-gradient(160deg, #f1dfff 0%, #c79bff 100%); color: #2c0a55; border-color: rgba(183,135,255,0.95); }

/* Цвета фигур (block-puzzle): c1 розовый, c2 фиолет, c3 голубой, c4 зелёный, c5 жёлтый */
.tile.tile-c1, .piece-cell.tile-c1 { background: linear-gradient(160deg, #ffd1e8 0%, #ff5bd1 100%); color: #4a0a35; border-color: rgba(255,91,209,0.9); }
.tile.tile-c2, .piece-cell.tile-c2 { background: linear-gradient(160deg, #d9c4ff 0%, #8a5bff 100%); color: #210a4a; border-color: rgba(138,91,255,0.9); }
.tile.tile-c3, .piece-cell.tile-c3 { background: linear-gradient(160deg, #c4ecff 0%, #5be0ff 100%); color: #06384a; border-color: rgba(91,224,255,0.9); }
.tile.tile-c4, .piece-cell.tile-c4 { background: linear-gradient(160deg, #c9f7d8 0%, #4ee08a 100%); color: #073a1c; border-color: rgba(78,224,138,0.9); }
.tile.tile-c5, .piece-cell.tile-c5 { background: linear-gradient(160deg, #fff0b8 0%, #ffce5b 100%); color: #4a2e04; border-color: rgba(255,206,91,0.95); }

.tile.tile-selected {
  background: linear-gradient(160deg, #fff5b6 0%, #ffb14f 100%);
  border-color: rgba(255, 175, 67, 1);
  color: #4a2a04;
  transform: scale(0.96);
  box-shadow: inset 0 2px 0 rgba(255,255,255,0.9), 0 0 14px rgba(255, 175, 67, 0.6);
}
.tile.word-flash { animation: wordFlash 0.45s ease; }
@keyframes wordFlash { 0% { transform: scale(1); } 50% { transform: scale(1.12) rotate(-2deg); filter: brightness(1.3); } 100% { transform: scale(1); } }
.tile.clearing { animation: clearOut 0.4s ease forwards; }
@keyframes clearOut { 0% { transform: scale(1); opacity: 1; } 100% { transform: scale(0.2) rotate(20deg); opacity: 0; } }

.floating-scores { position: absolute; inset: 0; pointer-events: none; }
.float-score {
  position: absolute;
  font-family: 'Unbounded', sans-serif;
  font-weight: 900;
  font-size: 22px;
  color: var(--gold);
  text-shadow: 0 4px 20px rgba(255,206,91,0.7);
  animation: floatUp 1.2s ease-out forwards;
  white-space: nowrap;
}
.float-score.combo { color: var(--accent-2); text-shadow: 0 4px 20px rgba(255,91,209,0.8); }
.float-score.line { color: var(--accent-3); text-shadow: 0 4px 20px rgba(91,224,255,0.8); }
.float-score.coin { color: var(--gold); font-size: 18px; text-shadow: 0 4px 20px rgba(255,206,91,0.8); }
.float-score.bonus {
  color: var(--gold);
  font-size: 24px;
  text-shadow: 0 0 10px rgba(255,255,255,0.65), 0 4px 24px rgba(255,206,91,0.95);
  animation: floatBonus 1.45s ease-out forwards;
}
.word-chip {
  position: absolute;
  z-index: 6;
  transform: translate(-50%, -120%);
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 999px;
  padding: 8px 12px;
  background: linear-gradient(135deg, rgba(255,206,91,0.98), rgba(255,91,209,0.94));
  color: #241036;
  font-family: 'Unbounded', sans-serif;
  font-size: 13px;
  font-weight: 900;
  white-space: nowrap;
  box-shadow: 0 14px 34px -12px rgba(255,206,91,0.95), 0 6px 18px rgba(20,8,55,0.45);
  pointer-events: auto;
  cursor: pointer;
  animation: wordChipIn 0.18s ease-out, wordChipPulse 0.85s ease-in-out 0.2s infinite alternate;
}
.word-chip.word-phase-exiting {
  opacity: 0;
  transform: translate(-50%, -105%) scale(0.9);
  transition: opacity 0.18s ease, transform 0.18s ease;
  pointer-events: none;
}
@keyframes wordChipIn {
  from { transform: translate(-50%, -95%) scale(0.82); opacity: 0; }
  to { transform: translate(-50%, -120%) scale(1); opacity: 1; }
}
@keyframes wordChipPulse {
  from { filter: brightness(1); }
  to { filter: brightness(1.12); }
}
@keyframes floatUp {
  0% { transform: translate(-50%, 0) scale(0.6); opacity: 0; }
  20% { transform: translate(-50%, -20px) scale(1.1); opacity: 1; }
  100% { transform: translate(-50%, -120px) scale(1); opacity: 0; }
}
@keyframes floatBonus {
  0% { transform: translate(-50%, 4px) scale(0.55) rotate(-4deg); opacity: 0; }
  18% { transform: translate(-50%, -26px) scale(1.18) rotate(2deg); opacity: 1; }
  48% { transform: translate(-50%, -54px) scale(1.04) rotate(-1deg); opacity: 1; }
  100% { transform: translate(-50%, -135px) scale(1) rotate(0); opacity: 0; }
}

/* boosters */
.booster-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  width: 100%;
  margin: 0;
}
.booster-button {
  min-height: 48px;
  border: 1px solid rgba(255,255,255,0.14);
  border-radius: 14px;
  color: var(--text);
  background: linear-gradient(160deg, rgba(255,255,255,0.13), rgba(255,255,255,0.06));
  box-shadow: var(--shadow-md);
  font-weight: 900;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}
.booster-button:hover { background: rgba(255,255,255,0.16); transform: translateY(-1px); }
.booster-button:active { transform: scale(0.97); }
.booster-button.active {
  color: #25133d;
  background: linear-gradient(135deg, #ffdf80, #ff9d5b);
  border-color: rgba(255,255,255,0.4);
}
.booster-button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  pointer-events: none;
}
.booster-icon { font-size: 20px; line-height: 1; }
.booster-label { font-size: 14px; }

/* hand */
.hand-card {
  background: var(--panel);
  backdrop-filter: blur(12px);
  border-radius: var(--radius-lg);
  border: 1px solid var(--panel-border);
  box-shadow: var(--shadow-md);
  padding: 10px 12px 12px;
}
.hand-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 8px; font-weight: 800; font-size: 13px;
  color: var(--text);
}
.hand-counter { color: var(--muted); font-weight: 700; font-size: 12px; }
.hand {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}
.hand.word-phase-locked .piece {
  opacity: 0.55;
  cursor: not-allowed;
}
.hand.word-phase-locked .piece-slot {
  border-color: rgba(255,206,91,0.22);
}
.piece-slot {
  min-height: 96px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 14px;
  background: rgba(255,255,255,0.04);
  border: 1px dashed rgba(255,255,255,0.14);
  position: relative;
  overflow: hidden;
  padding: 6px;
  transition: all 0.2s ease;
}
.piece-slot.used { opacity: 0.3; }
.piece-slot .used-label { color: var(--muted); font-weight: 700; font-size: 11px; letter-spacing: 0.05em; }

.piece {
  position: relative;
  display: grid;
  gap: 4px;
  padding: 4px;
  cursor: grab;
  touch-action: none;
  user-select: none;
  transform-origin: center center;
}
.piece.compact { will-change: transform; }
.piece:active { cursor: grabbing; }
.piece.drag-source { opacity: 0.18; }

.piece-cell {
  border-radius: 8px;
  background: var(--tile-grad);
  border: 1px solid rgba(255,255,255,0.6);
  box-shadow: inset 0 2px 0 rgba(255,255,255,0.9), inset 0 -2px 0 rgba(98, 56, 173, 0.2), 0 4px 10px rgba(20,8,55,0.35);
  color: var(--tile-letter);
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
  font-weight: 900;
  font-family: 'Unbounded', sans-serif;
}
/* legacy letter-class styles (для совместимости, не используются) */
.piece-cell.warm { background: linear-gradient(160deg, #fff7d6, #ffd58a); color: #5a3a06; }
.piece-cell.cool { background: linear-gradient(160deg, #e1f5ff, #b6d8ff); color: #143a66; }
.piece-cell.rare { background: linear-gradient(160deg, #f1dfff, #c79bff); color: #2c0a55; }

.drag-ghost {
  position: fixed; z-index: 50;
  pointer-events: none;
  transform: scale(1.1);
  filter: drop-shadow(0 18px 28px rgba(20, 8, 55, 0.55));
}

/* ====== ICON / ACTION BUTTONS ====== */
.icon-btn {
  width: 48px; height: 48px;
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  background: var(--panel-strong);
  color: var(--text);
  font-size: 18px;
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  transition: transform 0.15s ease, background 0.15s ease;
}
.icon-btn:hover { background: rgba(255,255,255,0.18); transform: translateY(-1px); }
.icon-btn:active { transform: translateY(0) scale(0.96); }
.icon-btn:disabled { opacity: 0.35; cursor: not-allowed; }

.action-btn {
  min-height: 48px;
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 0 16px;
  font-weight: 800;
  color: var(--text);
  background: var(--panel-strong);
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}
.action-btn:hover { transform: translateY(-1px); background: rgba(255,255,255,0.18); }
.action-btn:active { transform: translateY(0) scale(0.98); }
.action-btn.primary {
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-color: transparent;
  box-shadow: 0 14px 30px -10px rgba(138, 91, 255, 0.7), inset 0 1px 0 rgba(255,255,255,0.25);
}

/* ====== BOTTOM NAV ====== */
.bottom-nav {
  position: fixed;
  left: 0; right: 0;
  bottom: 0;
  z-index: 40;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0;
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  background: linear-gradient(180deg, rgba(15, 8, 40, 0.85), rgba(10, 8, 32, 0.95));
  backdrop-filter: blur(18px);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 -10px 30px -10px rgba(0,0,0,0.6);
}
.nav-btn {
  background: transparent;
  border: 0;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 4px;
  border-radius: 12px;
  cursor: pointer;
  transition: color 0.15s ease, transform 0.15s ease, background 0.15s ease;
  font-weight: 700;
  font-size: 11px;
}
.nav-btn .nav-ico { font-size: 20px; line-height: 1; }
.nav-btn:hover { color: var(--text); background: rgba(255,255,255,0.05); }
.nav-btn:active { transform: scale(0.95); }
.nav-btn.nav-primary {
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 10px 24px -10px rgba(255,91,209,0.7), inset 0 1px 0 rgba(255,255,255,0.25);
  margin: -14px 4px 0;
  padding-top: 12px;
  border-radius: 18px;
}
.nav-btn.nav-primary .nav-ico { font-size: 22px; }

/* ====== MODAL ====== */
.modal {
  position: fixed; inset: 0;
  background: rgba(10, 8, 32, 0.7);
  backdrop-filter: blur(8px);
  display: flex; align-items: center; justify-content: center;
  padding: 16px; z-index: 90;
  animation: fadeIn 0.2s ease;
}
.modal.hidden { display: none; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal-card {
  width: min(420px, 100%);
  max-height: 85vh;
  overflow-y: auto;
  background: linear-gradient(160deg, rgba(40, 20, 90, 0.95), rgba(20, 10, 50, 0.95));
  border: 1px solid var(--panel-border);
  border-radius: 22px;
  padding: 20px;
  box-shadow: 0 30px 70px -20px rgba(138, 91, 255, 0.6);
  animation: popIn 0.3s cubic-bezier(.34,1.56,.64,1);
}
@keyframes popIn { from { transform: scale(0.9); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 14px;
}
.modal-head h2 { margin: 0; font-size: 18px; font-family: 'Unbounded', sans-serif; }
.modal-text { color: var(--muted); line-height: 1.55; font-size: 14px; margin: 0 0 14px; }
.rules-list { margin: 0; padding-left: 18px; color: var(--muted); line-height: 1.65; font-size: 14px; }
.rules-list b { color: var(--text); }
.settings-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 0; border-top: 1px solid rgba(255,255,255,0.08);
  font-weight: 700;
  gap: 12px;
}
.settings-row:first-of-type { border-top: 0; }
.language-select {
  min-height: 48px;
  min-width: 132px;
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 0 12px;
  color: var(--text);
  background: rgba(255,255,255,0.1);
  font: inherit;
  font-weight: 800;
}
.language-select option {
  color: #1d1234;
}
.profile-stats {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px;
}
.profile-stats > div {
  background: var(--panel-strong);
  border-radius: 14px;
  padding: 12px;
  text-align: center;
}
.profile-stats .label { display: block; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.1em; font-weight: 700; }
.profile-stats .value { display: block; margin-top: 4px; font-size: 22px; font-weight: 900; font-family: 'Unbounded', sans-serif; color: var(--gold); }

.shop-panel {
  width: min(420px, calc(100vw - 24px));
  max-height: min(720px, calc(100dvh - 24px));
  overflow-y: auto;
  background: linear-gradient(160deg, rgba(40, 20, 90, 0.96), rgba(20, 10, 50, 0.96));
  border: 1px solid var(--panel-border);
  border-radius: 24px;
  padding: 18px;
  box-shadow: 0 30px 70px -20px rgba(138, 91, 255, 0.6);
  animation: popIn 0.3s cubic-bezier(.34,1.56,.64,1);
}
.shop-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}
.shop-header h2 {
  margin: 0;
  font-size: 20px;
  font-family: 'Unbounded', sans-serif;
}
.shop-balance {
  margin-top: 6px;
  color: var(--gold);
  font-weight: 900;
  font-family: 'Unbounded', sans-serif;
}
.shop-section {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid rgba(255,255,255,0.09);
}
.shop-section h3 {
  margin: 0 0 10px;
  font-size: 13px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.shop-wide-button {
  width: 100%;
  min-height: 48px;
  border: 1px solid rgba(255,255,255,0.14);
  border-radius: 16px;
  color: #291641;
  background: linear-gradient(135deg, #ffe28a, #ffb84d);
  font-weight: 900;
  cursor: pointer;
}
.shop-wide-button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.shop-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}
.shop-card {
  min-height: 132px;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 18px;
  padding: 12px;
  background: rgba(255,255,255,0.07);
}
.shop-card-icon { font-size: 28px; line-height: 1; }
.shop-card-title {
  font-weight: 900;
  margin-top: 8px;
}
.shop-card-desc {
  font-size: 12px;
  color: var(--muted);
  margin-top: 3px;
  min-height: 34px;
}
.shop-card-price {
  color: var(--gold);
  font-weight: 900;
  margin-top: 8px;
}

/* ====== OVERLAY (game over) ====== */
.overlay {
  position: fixed; inset: 0;
  background: rgba(10, 8, 32, 0.7);
  backdrop-filter: blur(8px);
  display: flex; align-items: center; justify-content: center;
  padding: 20px; z-index: 95;
  animation: fadeIn 0.25s ease;
}
.overlay.hidden { display: none; }
.overlay-card {
  width: min(420px, 100%);
  background: linear-gradient(160deg, rgba(40, 20, 90, 0.95), rgba(20, 10, 50, 0.95));
  border: 1px solid var(--panel-border);
  border-radius: 24px;
  padding: 28px 24px;
  text-align: center;
  box-shadow: 0 30px 70px -20px rgba(138, 91, 255, 0.6);
  animation: popIn 0.35s cubic-bezier(.34,1.56,.64,1);
}
.overlay-emoji { font-size: 52px; margin-bottom: 6px; }
.overlay-title { font-size: 26px; font-weight: 900; font-family: 'Unbounded', sans-serif; }
.overlay-score { margin-top: 10px; font-size: 24px; font-weight: 800; color: var(--gold); font-family: 'Unbounded', sans-serif; }
.overlay-best { margin-top: 6px; font-size: 13px; color: var(--accent-3); font-weight: 700; min-height: 18px; }
.overlay-text { margin: 12px 0 20px; color: var(--muted); font-size: 14px; }
.overlay-continue {
  width: 100%;
  margin-bottom: 8px;
}
.overlay-continue-note {
  min-height: 18px;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}
.overlay-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}
.overlay-actions .action-btn { flex: 1; }

/* ====== TOAST ====== */
.toast {
  position: fixed;
  left: 50%; bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: rgba(20, 10, 50, 0.95);
  border: 1px solid var(--panel-border);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 14px;
  font-weight: 700;
  font-size: 13px;
  z-index: 80;
  box-shadow: var(--shadow-md);
  animation: toastIn 0.25s ease;
  max-width: calc(100% - 32px);
  text-align: center;
}
.toast.hidden { display: none; }
@keyframes toastIn { from { transform: translate(-50%, 20px); opacity: 0; } to { transform: translate(-50%, 0); opacity: 1; } }

/* ====== DESKTOP ====== */
@media (min-width: 720px) {
  .app-shell { width: min(520px, 100%); padding: 0 16px calc(var(--nav-h) + env(safe-area-inset-bottom)); }
  .piece-cell { width: 34px; height: 34px; font-size: 18px; }
  .piece-slot { min-height: 110px; }
  .score-card .value { font-size: 22px; }
  .nav-btn { font-size: 12px; }
}

@media (max-width: 360px) {
  :root { --board-gap: 4px; }
  .piece-cell { width: 26px; height: 26px; font-size: 14px; }
  .piece-slot { min-height: 84px; }
  .score-card .value { font-size: 18px; }
  .score-card .label { font-size: 9px; }
  .nav-btn .nav-ico { font-size: 18px; }
  .nav-btn { font-size: 10px; }
}

/* ===== Статистика генерации ===== */
.gen-stats-body { font-size: 13px; line-height: 1.45; color: #e6e3ff; }
.gen-stats-body h3 { margin: 12px 0 6px; font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: #a99dff; }
.gen-stats-body .summary { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 8px; }
.gen-stats-body .summary div { background: rgba(255,255,255,.05); border: 1px solid rgba(255,255,255,.08); border-radius: 10px; padding: 8px 10px; }
.gen-stats-body .summary .label { display:block; font-size: 11px; color: #a99dff; text-transform: uppercase; letter-spacing: .06em; }
.gen-stats-body .summary .value { display:block; font-weight: 800; font-size: 16px; }
.gen-stats-body .freq-table { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px 8px; max-height: 240px; overflow: auto; padding-right: 4px; }
.gen-stats-body .freq-table .row { display: flex; justify-content: space-between; background: rgba(255,255,255,.04); border-radius: 6px; padding: 3px 6px; font-variant-numeric: tabular-nums; }
.gen-stats-body .freq-table .row b { color: #fff; }
.gen-stats-body .freq-table .row span { color: #a99dff; font-size: 12px; }
