/* Стили тетриса. Вёрстка перенесена из выбранного прототипа B «Тон сайта»
   (site/_lab/001-tetris/B.html + proto.css). Цвета — только токены common.css и palette.css. */

/* ---------- Страница ---------- */
html, body { height: 100%; }
/* Страница = шапка + игра ровно на высоту экрана */
body {
  overscroll-behavior: none; display: flex; flex-direction: column; min-height: 100dvh;
  /* Вся страница — зона жестов: без прокрутки, масштабирования, выделения и меню долгого нажатия */
  touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
.topbar { width: 100%; padding: 10px 12px; }
.top-actions { display: flex; gap: 8px; }
.icon-btn { touch-action: manipulation; }

/* ---------- Раскладка игры ---------- */
.game {
  --cell: 16px;               /* до подбора — мелкий, чтобы страница не вылезала за экран */
  --gap: calc(var(--cell) * .08);
  --pad: calc(var(--cell) * .12);
  --rail: 1;

  width: fit-content;
  display: grid;
  grid-template-columns: auto auto;
  grid-template-areas: "board rail";
  column-gap: 6px; row-gap: 10px;
  align-items: start;
  margin: auto;               /* лишняя высота делится поровну сверху и снизу */
  padding: 0 max(8px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));

  /* Зона жестов: страница не прокручивается, не выделяется, нет меню долгого нажатия */
  touch-action: none;
  user-select: none; -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.side { display: none; grid-area: side; }
.lbl-wide { display: none; }

/* Телефон, высокий экран: над полем строка «Тетрис · Счёт · Рекорд», как в 2048 */
.game[data-mode="tall"] { grid-template-areas: "side side" "board rail"; }
.game[data-mode="tall"] .side { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.game[data-mode="tall"] .title { margin: 0; font-size: 40px; letter-spacing: -0.03em; line-height: 1; }
.game[data-mode="tall"] .scores { display: flex; gap: 8px; }
.game[data-mode="tall"] .score { min-width: 64px; padding: 5px 8px; border-radius: 10px; background: var(--surface-2); text-align: center; }
.game[data-mode="tall"] .score span { display: block; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.game[data-mode="tall"] .score b { display: block; font-size: 18px; font-variant-numeric: tabular-nums; line-height: 1.3; }
.game[data-mode="tall"] .score.sm { display: none; }
.game[data-mode="tall"] .rail-stats .st-score { display: none; }
.score { position: relative; }

/* ---------- Поле ---------- */
.board-wrap { grid-area: board; position: relative; }
.board {
  display: grid;
  grid-template-columns: repeat(10, var(--cell));
  grid-auto-rows: var(--cell);
  gap: var(--gap);
  padding: var(--pad);
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow);
}
.cell { position: relative; border-radius: calc(var(--cell) * .16); background: var(--slot); }
/* Кубик: подушечка — светлее сверху, чуть темнее снизу, мягкая тень */
.tile {
  border-radius: calc(var(--cell) * .18);
  background: linear-gradient(180deg,
    color-mix(in srgb, var(--c), var(--tile-hi) 28%) 0%,
    var(--c) 55%,
    color-mix(in srgb, var(--c), var(--tile-lo) 12%) 100%);
  box-shadow: 0 1px 2px color-mix(in srgb, var(--tile-lo) 22%, transparent);
}
.cell.ghost { background: color-mix(in srgb, var(--c) 28%, var(--slot)); }

/* ---------- Колонка справа ---------- */
.rail {
  grid-area: rail;
  align-self: stretch;
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  padding: 8px 5px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow);
}
.lbl { display: block; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.rail .lbl { text-transform: none; letter-spacing: 0; font-size: 11px; text-align: center; }
.slot-box { display: grid; justify-items: center; gap: 4px; }
.next-list { display: grid; justify-items: center; gap: calc(var(--cell) * .5); }
.next-list [data-next="2"] { display: none; }
.rail-stats { margin-top: auto; display: grid; gap: 6px; text-align: center; border-top: 1px solid var(--border); padding-top: 8px; width: 100%; }
.rail-stats > div { position: relative; border-radius: 8px; }
.rail-stats b { display: block; font-size: 15px; font-variant-numeric: tabular-nums; line-height: 1.15; }
.rail-stats b.long { font-size: 13px; }

/* Окошки «Запас» / «Далее»: кубик того же размера, что на поле */
.pv {
  position: relative;
  width: calc(var(--bw, 4) * var(--cell) + (var(--bw, 4) - 1) * var(--gap));
  height: calc(var(--bh, 2) * var(--cell) + (var(--bh, 2) - 1) * var(--gap));
}
.pv .tile { position: absolute; width: var(--cell); height: var(--cell); }
.pv.used { opacity: .4; }

/* ---------- Пауза поверх поля ---------- */
.pause-ov {
  position: absolute; inset: 0; z-index: 5;
  display: grid; place-content: center; justify-items: center; gap: 10px; text-align: center;
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  background: color-mix(in srgb, var(--bg) 40%, transparent);
  border-radius: 12px;
  opacity: 0; visibility: hidden;
  transition: opacity .15s ease, visibility 0s linear .15s;
}
.pause-ov.on { opacity: 1; visibility: visible; transition: opacity .15s ease; }
.pause-ov b { font-size: 26px; }
.pause-best { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.game[data-mode="tall"] .pause-best { display: none; }

/* ---------- Подсказка клавиш (только компьютер) ---------- */
.keys-hint { color: var(--muted); font-size: 13px; margin: 12px 0 0; display: none; }
@media (hover: hover) and (pointer: fine) { .keys-hint { display: block; } }

/* ---------- Кнопки и диалоги (как в 2048) ---------- */
.primary-btn {
  display: inline-flex; justify-content: center; align-items: center;
  height: 42px; padding: 0 18px; flex-shrink: 0;
  border-radius: 12px; border: 0;
  background: var(--accent); color: var(--on-accent); font-weight: 600; cursor: pointer;
  touch-action: manipulation;
}
.primary-btn:hover { filter: brightness(1.06); }
.primary-btn.wide { width: 100%; height: 46px; }
.ghost-btn {
  width: 100%; height: 42px; margin-top: 6px;
  border: 0; background: none; color: var(--muted);
  border-radius: 12px; cursor: pointer; font-weight: 500;
  touch-action: manipulation;
}
.ghost-btn:hover { background: var(--surface-2); color: var(--text); }

.dlg {
  width: min(92vw, 360px);
  padding: 22px 20px 14px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
.dlg::backdrop { background: rgba(10, 10, 12, .45); backdrop-filter: blur(2px); }
.dlg h2 { margin: 0 0 10px; font-size: 22px; text-align: center; }
.dlg .muted { color: var(--muted); text-align: center; margin: 0 0 16px; font-size: 14px; font-variant-numeric: tabular-nums; }
.dlg-help { width: min(92vw, 380px); }
.dlg-badge { margin: 0 0 6px; text-align: center; font-weight: 700; font-size: 14px; color: var(--ok); }
.dlg-badge[hidden] { display: none; }
.help-list { list-style: none; margin: 0 0 16px; padding: 0; display: grid; gap: 10px; font-size: 15px; }
.help-list li { display: flex; gap: 12px; align-items: center; }
.help-list i { flex: 0 0 40px; height: 40px; border-radius: 10px; background: var(--accent-softer); color: var(--accent); display: grid; place-items: center; font-style: normal; font-weight: 700; font-size: 20px; }
.help-list.keys i { flex-basis: 64px; font-size: 14px; }
.help-keys { display: none; }
@media (hover: hover) and (pointer: fine) {
  .help-keys { display: grid; }
  .help-touch { display: none; }
}

/* ---------- Телефон боком ---------- */
.rotate-ov {
  position: fixed; inset: 0; z-index: 40;
  display: grid; place-items: center; padding: 24px;
  background: var(--bg); color: var(--text);
  text-align: center; font-size: 18px; font-weight: 600;
}
.rotate-ov[hidden] { display: none; }

/* ---------- Анимации ---------- */
.cell.clr { animation: clr .22s ease-out forwards; animation-delay: calc(var(--d, 0) * 14ms); }
@keyframes clr { 0% { filter: brightness(1); } 40% { filter: brightness(1.6); transform: scale(1.06); } 100% { opacity: 0; transform: scale(.6); } }
.cell.lock { animation: lock .12s ease-out; }
@keyframes lock { 50% { filter: brightness(1.12); } }
.cell.drop { animation: drop .12s ease-out; }
@keyframes drop { from { transform: translateY(calc(var(--dy, 1) * -1 * (var(--cell) + var(--gap)))); } }
.cell.tile.dead { animation: dead .1s ease-out forwards; animation-delay: calc(var(--row, 0) * 20ms); }
@keyframes dead { to { opacity: .4; } }

.score-add {
  position: absolute; left: 0; right: 0; top: 4px;
  font-style: normal; font-weight: 700; color: var(--accent);
  opacity: 0; pointer-events: none; text-align: center;
}
.score-add.show { animation: float-up .6s ease-out; }
@keyframes float-up {
  from { opacity: 1; transform: translateY(0); }
  to { opacity: 0; transform: translateY(-28px); }
}
.flash { animation: flash .6s ease-out; }
@keyframes flash { 0%, 40% { background: var(--accent-soft); } }

/* ---------- Компьютер ---------- */
@media (min-width: 760px) {
  .game, .game[data-mode] { grid-template-columns: 220px auto auto; grid-template-areas: "side board rail"; column-gap: 18px; }
  .side, .game[data-mode] .side { display: block; }
  .game[data-mode] .score.sm { display: block; }
  .lbl-wide { display: inline; } .lbl-short { display: none; }
  .game { --rail: 0; padding-bottom: 24px; }
  .rail { align-self: start; padding: 14px 12px; gap: 18px; border-radius: var(--radius); }
  .next-list [data-next="2"] { display: block; }
  .rail-stats { display: none; }
  .rail .lbl { text-transform: uppercase; letter-spacing: .04em; }
  .title, .game[data-mode] .title { margin: 0 0 14px; font-size: 56px; letter-spacing: -0.03em; line-height: 1; }
  .scores, .game[data-mode] .scores { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  .score, .game[data-mode] .score { min-width: 0; padding: 6px 12px; border-radius: 10px; background: var(--surface-2); text-align: center; }
  .score span { display: block; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
  .score b, .game[data-mode] .score b { display: block; font-size: 20px; line-height: 1.45; font-variant-numeric: tabular-nums; }
  .keys-hint { line-height: 1.7; margin-top: 18px; }
  .pause-best { display: none; }
}

@media (max-width: 420px) { .brand-text { display: none; } }
/* Узкие телефоны (320px): кубик мелкий, и колонка с обычными промежутками выходила
   ниже поля (UX-1). Ужимаем только промежутки — на 375px и шире ничего не меняется. */
@media (max-width: 359px) {
  .rail { gap: 6px; }
  .next-list { gap: calc(var(--cell) * .3); }
  .rail-stats { gap: 3px; padding-top: 6px; }
}
@media (max-width: 759px) {
  .keys-hint { display: none !important; }
  .topbar { padding: 6px 10px; }
}

@media (prefers-reduced-motion: reduce) {
  .cell.clr, .cell.lock, .cell.drop, .score-add.show, .flash { animation: none; }
  .cell.clr { opacity: 0; }
  .cell.tile.dead { animation: none; opacity: .4; }
  .pause-ov, .pause-ov.on { transition: none; }
}

/* Кнопка «Пауза» ↔ «Продолжить» */
#btn-pause .ic-play { display: none; }
#btn-pause.is-paused .ic-pause { display: none; }
#btn-pause.is-paused .ic-play { display: block; }
