:root {
  --ink: #ffffff;
  --muted: rgba(255, 255, 255, .78);
  --gold: #ffd43b;
  --board-bg: #10205a;
  --cell-bg: rgba(4, 12, 48, .55);

  /* Размеры задаёт game.js (функция layout). Здесь — запасные значения. */
  --board: 320px;
  --gap: 3px;
  --cell: 36px;
  --tcell: 20px;
  --tscale: .55;
  --hud-h: 110px;
  --tray-h: 115px;
  --side: 200px;
  --g: 12px;
  /* Масштаб интерфейса (задаёт game.js): --hu для игры, --u для меню и окон. */
  --hu: 1;
  --u: 1;
  --k: 1;

  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #1d47c9;
  overscroll-behavior: none;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: ui-rounded, "SF Pro Rounded", "Nunito", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
}

/* ---------- Фон ---------- */

.bg {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  background:
    radial-gradient(120% 60% at 50% -10%, #5aa8ff 0%, rgba(90, 168, 255, 0) 60%),
    linear-gradient(180deg, #2b6ef2 0%, #2156da 45%, #1a3cae 100%);
}

/* Узор из плиток медленно плывёт по диагонали. */
.bg-tiles {
  position: absolute;
  inset: -72px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='72' height='72'%3E%3Crect x='6' y='6' width='60' height='60' rx='14' fill='white' fill-opacity='.045'/%3E%3Crect x='6' y='6' width='60' height='9' rx='4.5' fill='white' fill-opacity='.03'/%3E%3C/svg%3E");
  background-size: 72px 72px;
  animation: tiles-drift 18s linear infinite;
  will-change: transform;
}
@keyframes tiles-drift { to { transform: translate3d(72px, 72px, 0); } }

.orb {
  position: absolute;
  border-radius: 50%;
  will-change: transform;
}
.o1 {
  width: 70vmax; height: 70vmax; left: -30vmax; top: -25vmax;
  background: radial-gradient(circle, rgba(120, 220, 255, .35), rgba(120, 220, 255, 0) 65%);
  animation: orb 22s ease-in-out infinite alternate;
}
.o2 {
  width: 80vmax; height: 80vmax; right: -40vmax; bottom: -35vmax;
  background: radial-gradient(circle, rgba(170, 100, 255, .38), rgba(170, 100, 255, 0) 65%);
  animation: orb 26s ease-in-out infinite alternate-reverse;
}
.o3 {
  width: 45vmax; height: 45vmax; right: -10vmax; top: 20vh;
  background: radial-gradient(circle, rgba(255, 110, 200, .18), rgba(255, 110, 200, 0) 65%);
  animation: orb 30s ease-in-out infinite alternate;
}
@keyframes orb { to { transform: translate3d(8vmax, 6vmax, 0) scale(1.1); } }

/* Мерцающие искры */
.tw {
  position: absolute;
  width: var(--s);
  height: var(--s);
  background: #fff;
  clip-path: polygon(50% 0, 60% 40%, 100% 50%, 60% 60%, 50% 100%, 40% 60%, 0 50%, 40% 40%);
  opacity: 0;
  animation: twinkle 4s ease-in-out infinite;
}
@keyframes twinkle {
  0%, 100% { opacity: 0; transform: scale(.3) rotate(0deg); }
  50% { opacity: .85; transform: scale(1) rotate(45deg); }
}

/* ---------- Каркас ---------- */

#app {
  position: fixed;
  inset: 0;
  padding:
    max(8px, env(safe-area-inset-top))
    max(8px, env(safe-area-inset-right))
    max(8px, env(safe-area-inset-bottom))
    max(8px, env(safe-area-inset-left));
  display: grid;
  place-content: center;
  justify-items: center;
  gap: var(--g);
  grid-template-columns: var(--board);
  grid-template-areas: "hud" "board" "tray";
  --k: var(--hu);
}

/* ---------- Рекламный баннер (настройки в ads.js) ---------- */

:root { --ad-w: 320px; --ad-h: 50px; --ad-gap: 14px; }
/* Место под баннер: поле и лоток кончаются выше него на --ad-gap. */
body.has-ad #app {
  padding-bottom: calc(max(8px, env(safe-area-inset-bottom)) + var(--ad-h) + var(--ad-gap));
}
body.has-ad .screen {
  padding-bottom: calc(max(16px, env(safe-area-inset-bottom)) + var(--ad-h) + var(--ad-gap));
}
#ad-slot {
  position: fixed;
  left: 50%;
  bottom: max(8px, env(safe-area-inset-bottom));
  z-index: 90; /* над экранами меню (80), под окнами (100) */
  width: var(--ad-w);
  height: var(--ad-h);
  transform: translateX(-50%);
  overflow: hidden;
  display: grid;
  place-items: center;
}
#ad-slot[hidden] { display: none; }
#ad-slot .ad-preview {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  border: 2px dashed rgba(255, 255, 255, .55);
  border-radius: 8px;
  font-size: 13px;
  font-weight: 800;
  color: rgba(255, 255, 255, .8);
  background: rgba(0, 10, 60, .25);
}

#app[data-layout="side"] {
  grid-template-columns: var(--board) var(--side);
  grid-template-rows: var(--hud-h) var(--tray-h);
  grid-template-areas: "board hud" "board tray";
}

#app.shake1 { animation: shake1 .35s ease-out; }
#app.shake2 { animation: shake2 .5s ease-out; }
@keyframes shake1 {
  20% { transform: translate3d(-3px, 2px, 0); }
  45% { transform: translate3d(3px, -2px, 0); }
  70% { transform: translate3d(-2px, 1px, 0); }
}
@keyframes shake2 {
  10% { transform: translate3d(-7px, 4px, 0) rotate(-.4deg); }
  25% { transform: translate3d(6px, -5px, 0) rotate(.4deg); }
  40% { transform: translate3d(-5px, 3px, 0); }
  60% { transform: translate3d(4px, -2px, 0); }
  80% { transform: translate3d(-2px, 1px, 0); }
}

/* ---------- Верхняя панель ---------- */

.hud {
  grid-area: hud;
  width: 100%;
  height: var(--hud-h);
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  grid-template-rows: calc(44px * var(--k)) 1fr;
  grid-template-areas: "best badge actions" "score score score";
  column-gap: calc(6px * var(--k));
  align-items: center;
}

.left {
  grid-area: best;
  justify-self: start;
  display: flex;
  align-items: center;
  gap: calc(10px * var(--k));
  min-width: 0;
}
#app[data-narrow="1"] .left { gap: 5px; }

.best {
  display: flex;
  align-items: center;
  gap: calc(6px * var(--k));
  padding-left: 2px;
  font-size: calc(22px * var(--k));
  font-weight: 900;
  color: var(--gold);
  font-variant-numeric: tabular-nums;
  text-shadow: 0 2px 0 #b5650c, 0 3px 8px rgba(0, 0, 40, .35);
}
.best svg { width: calc(30px * var(--k)); height: calc(30px * var(--k)); filter: drop-shadow(0 2px 2px rgba(0, 0, 40, .35)); }

.score {
  grid-area: score;
  justify-self: center;
  font-size: calc((var(--hud-h) - 44px * var(--k)) * .82);
  font-weight: 900;
  line-height: 1;
  letter-spacing: -.01em;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 .06em 0 #1a3caa, 0 .1em .25em rgba(0, 0, 40, .4);
}
.score.bump { animation: bump .3s ease-out; }
@keyframes bump { 40% { transform: scale(1.12); } }

.badge {
  grid-area: badge;
  justify-self: center;
  display: flex;
  align-items: center;
  gap: calc(5px * var(--k));
  padding: calc(5px * var(--k)) calc(12px * var(--k));
  border-radius: 999px;
  background: linear-gradient(180deg, #ff8fd0, #e2399a);
  box-shadow: inset 0 -3px 0 rgba(120, 0, 70, .35), inset 0 2px 0 rgba(255, 255, 255, .45), 0 4px 10px rgba(0, 0, 40, .3);
  font-size: calc(15px * var(--k));
  font-weight: 900;
  white-space: nowrap;
  text-shadow: 0 1px 0 rgba(120, 0, 70, .5);
}
.badge[hidden] { display: none; }
.badge span { margin-right: 3px; }
.badge b { font-weight: inherit; }
/* В панели справа две кнопки (звук и пауза): на узких экранах ужимаю центр. */
@media (max-width: 440px) {
  .badge .bl { display: none; }
}
@media (max-width: 400px) {
  .best { font-size: 19px; gap: 4px; }
  .best svg { width: 24px; height: 24px; }
  .left { gap: 6px; }
  .actions { gap: 6px; }
  .badge { padding: 5px 9px; gap: 4px; }
}
@media (max-width: 360px) {
  .badge i { display: none; }
}
.badge i {
  width: calc(7px * var(--k));
  height: calc(7px * var(--k));
  border-radius: 50%;
  background: rgba(255, 255, 255, .3);
  transition: background .2s;
}
.badge i.on { background: #fff; box-shadow: 0 0 6px #fff; }
.badge.pop-in { animation: badge-in .35s cubic-bezier(.2, 1.6, .4, 1); }
@keyframes badge-in { from { transform: scale(.4); } }

.actions { grid-area: actions; justify-self: end; display: flex; gap: calc(8px * var(--k)); }

.icon-btn {
  width: calc(44px * var(--k));
  height: calc(44px * var(--k));
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: calc(14px * var(--k));
  background: linear-gradient(180deg, rgba(255, 255, 255, .28), rgba(255, 255, 255, .12));
  box-shadow: inset 0 -3px 0 rgba(0, 20, 80, .25), inset 0 1.5px 0 rgba(255, 255, 255, .45), 0 3px 8px rgba(0, 0, 40, .2);
  color: #fff;
  cursor: pointer;
  touch-action: manipulation;
}
.icon-btn:active { transform: translateY(2px); box-shadow: inset 0 -1px 0 rgba(0, 20, 80, .25); }
.icon-btn svg { width: calc(24px * var(--k)); height: calc(24px * var(--k)); filter: drop-shadow(0 1.5px 0 rgba(0, 20, 80, .35)); }
.icon-btn .snd-off { display: none; }
.icon-btn.muted .snd-on { display: none; }
.icon-btn.muted .snd-off { display: inline; }
@media (max-width: 400px) {
  .icon-btn { width: 40px; height: 40px; border-radius: 13px; }
  .icon-btn svg { width: 22px; height: 22px; }
}

/* Боковая колонка узкая: панель в столбик. Сверху кнопки, ниже счёт, рекорд и комбо.
   В режиме уровней: номер уровня на месте счёта, цели на месте рекорда. */
#app[data-layout="side"] .hud, #app[data-layout="wide"] .hud {
  grid-template-columns: auto minmax(0, 1fr) auto;
  grid-template-rows: calc(44px * var(--k)) auto auto calc(32px * var(--k));
  grid-template-areas: "home . actions" "score score score" "best best best" "badge badge badge";
  align-content: space-between;
  row-gap: calc(8px * var(--k));
}
#app[data-layout="side"] .left, #app[data-layout="wide"] .left { display: contents; }
#app[data-layout="side"] #btn-home, #app[data-layout="wide"] #btn-home { grid-area: home; }
#app[data-layout="side"] .best, #app[data-layout="wide"] .best { grid-area: best; justify-self: center; }
#app[data-layout="side"] .lvl, #app[data-layout="wide"] .lvl { grid-area: score; justify-self: center; }
#app[data-layout="side"] .goals, #app[data-layout="wide"] .goals { grid-area: best; }
#app[data-layout="wide"] .hud { height: auto; min-height: var(--hud-h); align-content: start; row-gap: calc(14px * var(--k)); }
#app[data-layout="side"] .score, #app[data-layout="wide"] .score { font-size: calc(50px * var(--k)); }
/* Широкий экран (планшет и ПК горизонтально): панель слева, поле по центру, лоток справа. */
#app[data-layout="wide"] {
  grid-template-columns: var(--side) var(--board) var(--side);
  grid-template-rows: var(--board);
  grid-template-areas: "hud board tray";
}
#app[data-layout="wide"] .hud { align-self: start; }

/* Компактная панель для очень маленьких окон (например, iframe 300×300). */
#app[data-layout="portrait"][data-narrow="1"] .badge { display: none; }
#app[data-narrow="1"] .actions { gap: 6px; }
/* Поле узкое (~130px): панель шире поля, на всю ширину окна. */
#app[data-layout="portrait"][data-narrow="1"] .hud { width: min(calc(100vw - 16px), 300px); justify-self: center; }
#app[data-narrow="1"] .icon-btn { width: 34px; height: 34px; border-radius: 11px; }
#app[data-narrow="1"] .icon-btn svg { width: 19px; height: 19px; }
#app[data-narrow="1"] .best { font-size: 15px; gap: 4px; }
#app[data-narrow="1"] .best svg { width: 20px; height: 20px; }

/* ---------- Поле ---------- */

.board {
  grid-area: board;
  position: relative;
  width: var(--board);
  height: var(--board);
  padding: var(--gap);
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  gap: var(--gap);
  background: linear-gradient(180deg, #13276b, #0d1b4f);
  border-radius: calc(var(--cell) * .3);
  box-shadow:
    0 0 0 calc(var(--gap) * 1.2) rgba(255, 255, 255, .14),
    0 calc(var(--cell) * .25) calc(var(--cell) * .6) rgba(0, 10, 60, .5),
    inset 0 2px 10px rgba(0, 0, 0, .45);
  --pc: var(--cell);
  --gc: #fff;
}

.cell {
  position: relative;
  border-radius: 18%;
  background: var(--cell-bg);
  box-shadow: inset 0 calc(var(--cell) * .06) calc(var(--cell) * .1) rgba(0, 0, 0, .35);
}

/* Блок — «желейная кнопка»: глянец сверху, тёмная грань снизу, внутренняя плашка. */
.tile, .pt {
  position: relative;
  border-radius: 18%;
  background:
    radial-gradient(110% 70% at 30% 8%, rgba(255, 255, 255, .55), rgba(255, 255, 255, 0) 50%),
    linear-gradient(180deg, color-mix(in srgb, var(--c) 72%, #fff) 0%, var(--c) 42%, color-mix(in srgb, var(--c) 78%, #000) 100%);
  box-shadow:
    inset 0 calc(var(--pc) * -.1) 0 color-mix(in srgb, var(--c) 55%, #000),
    inset 0 calc(var(--pc) * .055) 0 rgba(255, 255, 255, .5),
    inset calc(var(--pc) * .045) 0 0 rgba(255, 255, 255, .14),
    inset calc(var(--pc) * -.045) 0 0 rgba(0, 0, 0, .1),
    0 calc(var(--pc) * .05) calc(var(--pc) * .08) rgba(0, 0, 30, .35);
}
.tile::after, .pt::after {
  content: "";
  position: absolute;
  left: 24%; right: 24%; top: 20%; bottom: 28%;
  border-radius: 28%;
  background: linear-gradient(180deg, color-mix(in srgb, var(--c) 80%, #000) 0%, color-mix(in srgb, var(--c) 85%, #fff) 100%);
  box-shadow: inset 0 calc(var(--pc) * .03) calc(var(--pc) * .04) rgba(0, 0, 0, .25), 0 calc(var(--pc) * .025) 0 rgba(255, 255, 255, .35);
  opacity: .7;
}
.tile::before, .pt::before {
  content: "";
  position: absolute;
  left: 13%; top: 9%;
  width: 18%; height: 11%;
  border-radius: 50%;
  background: rgba(255, 255, 255, .85);
  transform: rotate(-20deg);
  z-index: 1;
}

.tile { position: absolute; inset: 0; transition: filter .45s; transition-delay: calc(var(--row, 0) * 70ms); }
.tile.in { animation: tile-in .28s cubic-bezier(.3, 1.6, .5, 1); }
.tile.out {
  z-index: 2;
  animation: tile-out .3s ease-in both;
  animation-delay: var(--d, 0ms);
}
@keyframes tile-in {
  0% { transform: scale(.7); }
  60% { transform: scale(1.08); }
}
@keyframes tile-out {
  0%   { transform: scale(1); filter: brightness(1); }
  35%  { transform: scale(1.15); filter: brightness(1.9); }
  100% { transform: scale(.2); filter: brightness(2.5); opacity: 0; }
}

/* Предпросмотр: куда встанет фигура */
.cell.ghost::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 18%;
  background: var(--gc);
  opacity: .42;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, .55);
}
/* Предпросмотр: линия заполнится — её блоки окрашиваются в цвет фигуры. */
.cell.wc .tile {
  --c: var(--gc) !important;
  animation: wc-glow .5s ease-in-out infinite alternate;
}
.cell.wc.ghost::after { opacity: .8; }
@keyframes wc-glow { to { filter: brightness(1.3); } }

/* Луч при очистке линии */
.beam {
  position: absolute;
  z-index: 4;
  pointer-events: none;
  border-radius: calc(var(--cell) * .3);
  background: linear-gradient(90deg, rgba(255, 255, 255, 0), #fff 30%, #fff 70%, rgba(255, 255, 255, 0));
  box-shadow: 0 0 calc(var(--cell) * .5) var(--bc), 0 0 calc(var(--cell) * 1.1) var(--bc);
  animation: beam-x .55s ease-out forwards;
}
.beam.col {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0), #fff 30%, #fff 70%, rgba(255, 255, 255, 0));
  animation-name: beam-y;
}
@keyframes beam-x {
  0%   { transform: scaleX(0); opacity: 1; }
  35%  { transform: scaleX(1.05); opacity: 1; }
  100% { transform: scaleX(1.05) scaleY(.15); opacity: 0; }
}
@keyframes beam-y {
  0%   { transform: scaleY(0); opacity: 1; }
  35%  { transform: scaleY(1.05); opacity: 1; }
  100% { transform: scaleY(1.05) scaleX(.15); opacity: 0; }
}

.board.dead .tile { filter: grayscale(1) brightness(.55); }

.hint {
  grid-area: board;
  align-self: end;
  z-index: 5;
  margin-bottom: calc(var(--cell) * .5);
  padding: calc(9px * var(--k)) calc(16px * var(--k));
  border-radius: 999px;
  background: rgba(0, 10, 50, .6);
  box-shadow: inset 0 0 0 1.5px rgba(255, 255, 255, .25);
  color: #fff;
  font-size: calc(15px * var(--k));
  font-weight: 800;
  pointer-events: none;
  animation: hint-pulse 1.6s ease-in-out infinite;
}
.hint[hidden] { display: none; }
@keyframes hint-pulse { 50% { transform: translateY(5px); } }

/* ---------- Фигуры ---------- */

.piece {
  display: grid;
  grid-template-columns: repeat(var(--cols), var(--pc));
  grid-auto-rows: var(--pc);
  gap: var(--pg);
  pointer-events: none;
}
.piece i { display: block; }

.tray {
  grid-area: tray;
  width: 100%;
  height: var(--tray-h);
  display: flex;
}
#app[data-tray="col"] .tray { flex-direction: column; }

.slot {
  flex: 1 1 0;
  min-width: 0;
  min-height: 0;
  display: grid;
  place-items: center;
  cursor: grab;
  touch-action: none;
  --pc: var(--tcell);
  --pg: calc(var(--gap) * var(--tscale));
}
.slot .piece { transition: opacity .25s, filter .25s; filter: drop-shadow(0 3px 4px rgba(0, 0, 40, .3)); }
.slot .piece.enter { animation: piece-in .4s cubic-bezier(.2, 1.5, .4, 1) backwards; }
.slot:nth-child(2) .piece.enter { animation-delay: .07s; }
.slot:nth-child(3) .piece.enter { animation-delay: .14s; }
.slot.stuck .piece { opacity: .35; filter: grayscale(.9); }
.slot.lifted .piece { opacity: 0; transition: none; }
@keyframes piece-in { from { transform: translateY(40%) scale(0); opacity: 0; } }

/* Фигура под пальцем */
.drag {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 50;
  transform-origin: 0 0;
  pointer-events: none;
  will-change: transform;
  --pc: var(--cell);
  --pg: var(--gap);
}
.drag .piece {
  transform-origin: 50% 100%;
  animation: pickup .14s ease-out;
  filter: drop-shadow(0 10px 10px rgba(0, 0, 40, .4));
}
.drag.back { transition: transform .2s cubic-bezier(.3, .7, .4, 1); }
.drag.back .piece { filter: none; }
@keyframes pickup { from { transform: scale(.6); } }

/* ---------- Эффекты ---------- */

#fx {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 45;
  pointer-events: none;
}

.pop {
  position: fixed;
  z-index: 60;
  pointer-events: none;
  white-space: nowrap;
  transform: translate(-50%, -50%);
  font-size: calc(var(--cell) * .72);
  font-weight: 900;
  color: #fff;
  text-shadow: 0 .07em 0 var(--c), 0 0 .3em var(--c), 0 .12em .3em rgba(0, 0, 40, .5);
  -webkit-text-stroke: calc(var(--cell) * .02) var(--c);
  animation: pop-up .9s ease-out forwards;
}
@keyframes pop-up {
  0%   { opacity: 0; transform: translate(-50%, -20%) scale(.5); }
  18%  { opacity: 1; transform: translate(-50%, -50%) scale(1.15); }
  30%  { transform: translate(-50%, -50%) scale(1); }
  70%  { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -160%) scale(1); }
}

/* Баннер «Комбо N» и слово похвалы */
.banner {
  position: fixed;
  z-index: 70;
  display: flex;
  flex-direction: column;
  align-items: center;
  pointer-events: none;
  white-space: nowrap;
  transform: translate(-50%, -50%);
  animation: banner 1.35s ease-out forwards;
}
@keyframes banner {
  0%   { opacity: 0; transform: translate(-50%, -50%) scale(.3) rotate(-6deg); }
  14%  { opacity: 1; transform: translate(-50%, -50%) scale(1.12) rotate(2deg); }
  24%  { transform: translate(-50%, -50%) scale(.96) rotate(0); }
  32%  { transform: translate(-50%, -50%) scale(1); }
  78%  { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -85%) scale(1.05); }
}
.b-combo { display: flex; align-items: baseline; gap: .15em; }
.b-label {
  font-size: calc(var(--board) * .12);
  font-weight: 900;
  font-style: italic;
  color: #fff;
  -webkit-text-stroke: calc(var(--board) * .006) #1b3fae;
  text-shadow: 0 .06em 0 #1b3fae, 0 .1em .3em rgba(0, 0, 50, .6), 0 0 .5em rgba(120, 200, 255, .8);
}
.b-num, .b-word {
  font-weight: 900;
  color: transparent;
  -webkit-background-clip: text;
  background-clip: text;
  paint-order: stroke fill;
}
.b-num {
  font-size: calc(var(--board) * .2);
  line-height: 1;
  background-image: linear-gradient(180deg, #fff 0%, #ffd6f0 30%, #ff5cb5 62%, #c9227f 100%);
  -webkit-text-stroke: calc(var(--board) * .007) #fff;
  filter: drop-shadow(0 .04em 0 #8e1259) drop-shadow(0 .06em .12em rgba(0, 0, 50, .5));
}
.b-word {
  margin-top: .05em;
  /* Длинное слово уменьшается, чтобы влезть в ширину поля. */
  font-size: calc(var(--board) * min(.105, 1.1 / var(--len, 8)));
  letter-spacing: .02em;
  text-transform: uppercase;
  background-image: linear-gradient(180deg, #fffbe0 0%, #ffe066 40%, #ffab2e 75%, #f07a12 100%);
  -webkit-text-stroke: calc(var(--board) * .005) #fff;
  filter: drop-shadow(0 .05em 0 #a64b00) drop-shadow(0 .08em .15em rgba(0, 0, 50, .55));
}
.banner.cool .b-word {
  background-image: linear-gradient(180deg, #ffffff 0%, #b8f3ff 40%, #3fd0ff 75%, #1c86e8 100%);
  filter: drop-shadow(0 .05em 0 #0b3d99) drop-shadow(0 .08em .15em rgba(0, 0, 50, .55));
}

/* ---------- Окно ---------- */

.modal {
  --k: var(--u);
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(5, 15, 60, .55);
  -webkit-backdrop-filter: blur(5px);
  backdrop-filter: blur(5px);
  animation: fade .25s;
}
.modal[hidden] { display: none; }

.card {
  width: min(calc(320px * var(--k)), 100%);
  padding: calc(26px * var(--k)) calc(20px * var(--k)) calc(20px * var(--k));
  border-radius: calc(28px * var(--k));
  background: linear-gradient(180deg, #4b8dff 0%, #2a5fe0 100%);
  text-align: center;
  box-shadow:
    inset 0 0 0 3px rgba(255, 255, 255, .3),
    inset 0 -6px 0 rgba(0, 20, 100, .3),
    0 24px 60px rgba(0, 0, 40, .5);
  animation: card-in .4s cubic-bezier(.2, 1.4, .4, 1);
}
.card h2 {
  margin: 0 0 calc(6px * var(--k));
  font-size: calc(24px * var(--k));
  font-weight: 900;
  text-shadow: 0 2px 0 #1a3caa;
}
.card .big {
  font-size: calc(64px * var(--k));
  font-weight: 900;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 4px 0 #1a3caa, 0 6px 16px rgba(0, 0, 40, .4);
}
.card .big.txt { font-size: calc(40px * var(--k)); margin: calc(4px * var(--k)) 0; }
.card .big:empty, .card .sub:empty { display: none; }
.card .sub { margin-top: calc(4px * var(--k)); font-size: calc(17px * var(--k)); font-weight: 800; color: var(--muted); }
.card .sub.record { color: var(--gold); text-shadow: 0 2px 0 #b5650c; }

.btn {
  display: block;
  width: 100%;
  min-height: calc(56px * var(--k));
  margin-top: calc(18px * var(--k));
  padding: 0 calc(16px * var(--k));
  border: 0;
  border-radius: calc(18px * var(--k));
  background: linear-gradient(180deg, #7be36f, #3db84a);
  color: #fff;
  font: inherit;
  font-size: calc(20px * var(--k));
  font-weight: 900;
  text-shadow: 0 2px 0 #1f7a2b;
  box-shadow: inset 0 -5px 0 #2a8f37, inset 0 2px 0 rgba(255, 255, 255, .5), 0 6px 14px rgba(0, 0, 40, .3);
  cursor: pointer;
  touch-action: manipulation;
}
.btn:active { transform: translateY(3px); box-shadow: inset 0 -2px 0 #2a8f37, inset 0 2px 0 rgba(255, 255, 255, .5); }
.btn.ghost {
  margin-top: calc(10px * var(--k));
  background: rgba(255, 255, 255, .14);
  text-shadow: none;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, .45);
}
.btn[hidden] { display: none; }

@keyframes fade { from { opacity: 0; } }
@keyframes card-in { from { transform: scale(.7) translateY(20px); opacity: 0; } }

#m-btns .btn:not(.ghost) + .btn { margin-top: calc(10px * var(--k)); }

/* ================= Режимы ================= */

#app[data-mode="level"] .best,
#app[data-mode="level"] .score,
#app[data-mode="classic"] .lvl,
#app[data-mode="classic"] .goals { display: none; }

.lvl {
  padding-left: 2px;
  font-size: calc(20px * var(--k));
  font-weight: 900;
  white-space: nowrap;
  text-shadow: 0 2px 0 #1a3caa, 0 3px 8px rgba(0, 0, 40, .35);
}
#app[data-narrow="1"] .lvl { font-size: 15px; }

/* Цели уровня */
.goals {
  grid-area: score;
  justify-self: center;
  align-self: center;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: calc(8px * var(--k));
}
.chip {
  position: relative;
  display: flex;
  align-items: center;
  gap: calc(7px * var(--k));
  height: clamp(32px, calc((var(--hud-h) - 44px * var(--k)) * .62), calc(52px * var(--k)));
  padding: 0 calc(14px * var(--k)) 0 calc(9px * var(--k));
  border-radius: 999px;
  background: rgba(5, 20, 80, .35);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, .22), 0 3px 8px rgba(0, 0, 40, .2);
  font-size: clamp(16px, calc((var(--hud-h) - 44px * var(--k)) * .36), calc(26px * var(--k)));
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  text-shadow: 0 2px 0 rgba(0, 0, 60, .35);
  transition: background .3s;
}
.chip .gi { width: 1.3em; height: 1.3em; }
.chip.done { background: rgba(40, 170, 80, .5); }
.chip.done::after {
  content: "✓";
  position: absolute;
  right: -5px;
  top: -6px;
  width: calc(20px * var(--k));
  height: calc(20px * var(--k));
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #3db84a;
  box-shadow: 0 0 0 2px #fff;
  font-size: calc(13px * var(--k));
  text-shadow: none;
}
.chip.bump { animation: bump .3s ease-out; }
#app[data-layout="portrait"] .goals { flex-wrap: nowrap; }
#app[data-layout="portrait"] .goals[data-n="3"] .chip {
  font-size: clamp(13px, calc(var(--board) * .052), calc(22px * var(--k)));
  padding: 0 calc(10px * var(--k)) 0 calc(7px * var(--k));
  gap: calc(5px * var(--k));
}
#app[data-layout="side"] .chip, #app[data-layout="wide"] .chip { height: calc(30px * var(--k)); font-size: calc(16px * var(--k)); padding: 0 calc(10px * var(--k)) 0 calc(7px * var(--k)); }
#app[data-narrow="1"] .chip { height: 26px; font-size: 13px; padding: 0 8px 0 5px; gap: 4px; }
#app[data-narrow="1"] .goals { gap: 5px; }

/* Значки целей */
.gi { display: inline-block; flex: none; }
.gi.g1 {
  clip-path: polygon(50% 0, 100% 42%, 50% 100%, 0 42%);
  background: linear-gradient(160deg, #fff 0%, #ffc4f6 30%, #e04bff 65%, #8a1fd1 100%);
}
.gi.g2 {
  clip-path: polygon(50% 0, 63% 33%, 98% 36%, 71% 59%, 80% 95%, 50% 76%, 20% 95%, 29% 59%, 2% 36%, 37% 33%);
  background: linear-gradient(170deg, #fff8c8 0%, #ffd43b 45%, #f08a12 100%);
}
.gi.ice {
  border-radius: 26%;
  background: linear-gradient(135deg, #f2fcff 0%, #b5e6ff 45%, #7cc8f5 70%, #e8f8ff 100%);
  box-shadow: inset 0 0 0 2px #fff;
}
.gi.sc {
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff6b0, #ffd43b 42%, #e08a10);
  box-shadow: inset 0 -2px 0 rgba(150, 70, 0, .5);
}

/* Кристалл на блоке: белый контур (::before) и цветной камень (::after) */
.tile.g1::before, .pt.g1::before, .tile.g2::before, .pt.g2::before {
  left: 12%; right: 12%; top: 9%; bottom: 15%;
  width: auto; height: auto;
  border-radius: 0;
  transform: none;
  background: #fff;
  z-index: 1;
}
.tile.g1::after, .pt.g1::after, .tile.g2::after, .pt.g2::after {
  left: 21%; right: 21%; top: 19%; bottom: 24%;
  border-radius: 0;
  opacity: 1;
  box-shadow: none;
  z-index: 2;
}
.tile.g1::before, .pt.g1::before, .tile.g1::after, .pt.g1::after {
  clip-path: polygon(50% 0, 100% 42%, 50% 100%, 0 42%);
}
.tile.g1::after, .pt.g1::after { background: linear-gradient(160deg, #fff 0%, #ffc4f6 30%, #e04bff 65%, #8a1fd1 100%); }
.tile.g2::before, .pt.g2::before, .tile.g2::after, .pt.g2::after {
  clip-path: polygon(50% 0, 63% 33%, 98% 36%, 71% 59%, 80% 95%, 50% 76%, 20% 95%, 29% 59%, 2% 36%, 37% 33%);
}
.tile.g2::after, .pt.g2::after { background: linear-gradient(170deg, #fff8c8 0%, #ffd43b 45%, #f08a12 100%); }

/* Лёд на блоке */
.frost, .frost-break {
  position: absolute;
  inset: 0;
  z-index: 3;
  border-radius: 18%;
  background: linear-gradient(135deg, rgba(240, 252, 255, .92) 0%, rgba(180, 230, 255, .6) 40%, rgba(150, 215, 255, .5) 60%, rgba(235, 250, 255, .88) 100%);
  box-shadow: inset 0 0 0 calc(var(--pc) * .05) rgba(255, 255, 255, .95), inset 0 calc(var(--pc) * -.08) 0 rgba(110, 180, 235, .55);
}
.frost::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background:
    linear-gradient(55deg, transparent 46%, rgba(255, 255, 255, .95) 47%, rgba(255, 255, 255, .95) 50%, transparent 51%),
    linear-gradient(-30deg, transparent 60%, rgba(255, 255, 255, .8) 61%, rgba(255, 255, 255, .8) 63%, transparent 64%);
}
.frost-break { animation: frost-break .35s ease-out forwards; animation-delay: var(--d, 0ms); }
@keyframes frost-break { to { transform: scale(1.35); opacity: 0; } }

/* Кристалл летит в панель целей */
.fly { position: fixed; left: 0; top: 0; z-index: 75; pointer-events: none; }
.fly .gi { display: block; width: 100%; height: 100%; }

/* ================= Экраны ================= */

body.in-screen #app { visibility: hidden; }

.screen {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: calc(18px * var(--k));
  --k: var(--u);
  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));
}
.screen[hidden] { display: none; }

#menu {
  justify-content: safe center;
  overflow-y: auto;
  overscroll-behavior: contain;
  touch-action: pan-y;
}
#menu > * { flex-shrink: 0; }

.menu-legal {
  font-size: 13px;
  color: var(--muted);
}
.menu-legal a, .cookie-banner a { color: inherit; touch-action: manipulation; }

.cookie-banner {
  width: min(360px, 100%);
  padding: 12px;
  border-radius: 16px;
  background: var(--board-bg);
  text-align: center;
  font-size: 14px;
  line-height: 1.4;
}
.cookie-banner[hidden] { display: none; }
.cookie-banner p { margin: 0; }
.cookie-banner .cookie-documents, .cookie-banner #cookie-status { margin-top: 8px; }
.cookie-actions { display: flex; gap: 8px; margin-top: 8px; }
.cookie-actions button {
  flex: 1;
  min-height: 44px;
  padding: 0 8px;
  border: 1px solid var(--muted);
  border-radius: 10px;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
}

.logo { display: flex; gap: min(1.2vw, calc(6px * var(--k))); margin-bottom: min(5vh, calc(36px * var(--k))); }
.logo span {
  width: min(9.8vw, calc(54px * var(--k)));
  height: min(9.8vw, calc(54px * var(--k)));
  display: grid;
  place-items: center;
  border-radius: 22%;
  font-size: min(6.6vw, calc(36px * var(--k)));
  font-weight: 900;
  color: #fff;
  text-shadow: 0 3px 0 rgba(0, 0, 0, .25);
  background:
    radial-gradient(110% 70% at 30% 8%, rgba(255, 255, 255, .5), rgba(255, 255, 255, 0) 50%),
    linear-gradient(180deg, color-mix(in srgb, var(--c) 70%, #fff), var(--c) 45%, color-mix(in srgb, var(--c) 75%, #000));
  box-shadow: inset 0 -5px 0 color-mix(in srgb, var(--c) 55%, #000), inset 0 3px 0 rgba(255, 255, 255, .5), 0 6px 12px rgba(0, 0, 40, .35);
  animation: logo-bob 2.4s ease-in-out infinite;
  animation-delay: calc(var(--i) * .12s);
}
@keyframes logo-bob { 50% { transform: translateY(-7px); } }

.mode-btn {
  width: min(calc(320px * var(--k)), 100%);
  min-height: calc(78px * var(--k));
  display: flex;
  align-items: center;
  gap: calc(14px * var(--k));
  padding: calc(10px * var(--k)) calc(18px * var(--k));
  border: 0;
  border-radius: calc(24px * var(--k));
  color: #fff;
  font: inherit;
  text-align: left;
  cursor: pointer;
  touch-action: manipulation;
  box-shadow: inset 0 -6px 0 rgba(0, 0, 0, .2), inset 0 2px 0 rgba(255, 255, 255, .45), 0 8px 18px rgba(0, 0, 40, .3);
}
.mode-btn:active { transform: translateY(3px); }
.mode-btn.classic { background: linear-gradient(180deg, #ffb347, #ff7a1a); }
.mode-btn.levels { background: linear-gradient(180deg, #ff7ccf, #d63aa0); }
.mode-btn .ico { width: calc(46px * var(--k)); height: calc(46px * var(--k)); flex: none; filter: drop-shadow(0 2px 0 rgba(0, 0, 0, .2)); }
.mode-btn .mt { display: block; font-size: calc(25px * var(--k)); font-weight: 900; text-shadow: 0 2px 0 rgba(0, 0, 0, .2); }
.mode-btn .ms { display: block; margin-top: 2px; font-size: calc(15px * var(--k)); font-weight: 800; opacity: .92; }

.install-btn {
  display: flex;
  align-items: center;
  gap: calc(8px * var(--k));
  margin-top: calc(6px * var(--k));
  padding: calc(10px * var(--k)) calc(18px * var(--k));
  border: 0;
  border-radius: 999px;
  color: #fff;
  font: inherit;
  font-size: calc(16px * var(--k));
  font-weight: 800;
  cursor: pointer;
  touch-action: manipulation;
  background: rgba(10, 30, 110, .35);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, .28);
}
.install-btn[hidden] { display: none; }
.install-btn:active { transform: translateY(2px); }
.install-btn svg { width: calc(22px * var(--k)); height: calc(22px * var(--k)); flex: none; }

.card .m-icon {
  display: block;
  width: calc(84px * var(--k));
  height: calc(84px * var(--k));
  margin: calc(8px * var(--k)) auto calc(10px * var(--k));
  border-radius: 22%;
  box-shadow: 0 6px 16px rgba(0, 0, 40, .35), inset 0 0 0 1px rgba(255, 255, 255, .2);
}
.card .sub.steps { white-space: pre-line; text-align: left; line-height: 1.45; color: #fff; }

#levels { justify-content: flex-start; gap: calc(12px * var(--k)); }
.lv-head { width: min(calc(440px * var(--k)), 100%); display: flex; align-items: center; gap: calc(12px * var(--k)); flex: none; }
.lv-head h2 { margin: 0; font-size: calc(26px * var(--k)); font-weight: 900; text-shadow: 0 3px 0 #1a3caa; }
.lv-grid {
  width: min(calc(440px * var(--k)), 100%);
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  touch-action: pan-y;
  -webkit-overflow-scrolling: touch;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: calc(14px * var(--k)) calc(12px * var(--k));
  align-content: start;
  padding: calc(8px * var(--k)) calc(6px * var(--k)) calc(28px * var(--k));
}
.lv {
  position: relative;
  aspect-ratio: 1;
  border: 0;
  border-radius: 30%;
  color: #fff;
  font: inherit;
  font-size: clamp(17px, 5.5vw, calc(24px * var(--k)));
  font-weight: 900;
  cursor: pointer;
  touch-action: manipulation;
  background: linear-gradient(180deg, #7be36f, #3db84a);
  box-shadow: inset 0 -5px 0 #2a8f37, inset 0 2px 0 rgba(255, 255, 255, .5), 0 4px 10px rgba(0, 0, 40, .25);
  text-shadow: 0 2px 0 rgba(0, 0, 40, .3);
}
.lv:active { transform: translateY(2px); }
.lv.cur {
  background: linear-gradient(180deg, #ffe066, #ffab2e);
  box-shadow: inset 0 -5px 0 #d9781a, inset 0 2px 0 rgba(255, 255, 255, .6), 0 0 0 3px #fff, 0 6px 16px rgba(0, 0, 40, .35);
  animation: cur-pulse 1.3s ease-in-out infinite;
}
.lv.locked {
  background: rgba(5, 15, 60, .35);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, .12);
  color: rgba(255, 255, 255, .35);
  text-shadow: none;
  cursor: default;
}
.lv.done::after {
  content: "✓";
  position: absolute;
  right: -3px;
  top: -4px;
  width: calc(20px * var(--k));
  height: calc(20px * var(--k));
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #fff;
  color: #2a8f37;
  font-size: calc(13px * var(--k));
  text-shadow: none;
}
@keyframes cur-pulse { 50% { transform: scale(1.07); } }

/* ПК: отклик на наведение мыши. На сенсорных экранах не включается. */
@media (hover: hover) and (pointer: fine) {
  .icon-btn, .btn, .mode-btn, .install-btn, .lv { transition: filter .15s, transform .15s; }
  .icon-btn:hover, .btn:hover, .mode-btn:hover, .install-btn:hover, .lv:not(.locked):hover { filter: brightness(1.1); }
  .mode-btn:hover, .lv:not(.locked):not(.cur):hover { transform: translateY(-2px); }
  .mode-btn:hover:active, .lv:not(.locked):not(.cur):hover:active { transform: translateY(2px); }
  .slot:not(.stuck):not(.lifted):hover .piece { filter: drop-shadow(0 3px 4px rgba(0, 0, 40, .3)) brightness(1.12); }
  body:has(.drag) { cursor: grabbing; }
}

@media (prefers-reduced-motion: reduce) {
  .hint, .score.bump, .bg-tiles, .orb, .tw, #app.shake1, #app.shake2, .logo span, .lv.cur { animation: none; }
}
