/* Тетрис — мобильный вёрстка: HUD сверху, поле по центру, тач-пад снизу. */
:root {
  --bg: #0b0f1a;
  --panel: #131a2c;
  --panel-2: #0e1524;
  --line: #24304d;
  --text: #e8edf8;
  --dim: #8d99b5;
  --accent: #4dd2ff;
  --accent-2: #ff5c8a;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%;
  overscroll-behavior: none;
  background: var(--bg);
  color: var(--text);
  font-family: "Avenir Next", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

#app {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: calc(6px + var(--safe-t)) 10px calc(6px + var(--safe-b));
  gap: 6px;
}

/* ---------- HUD ---------- */
#hud {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  flex: 0 0 auto;
}
.stat {
  background: linear-gradient(180deg, var(--panel), var(--panel-2));
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 5px 8px 6px;
  text-align: center;
  min-width: 0;
}
.stat .k { display: block; font-size: 9px; letter-spacing: .12em; color: var(--dim); }
.stat .v { display: block; font-size: 16px; font-weight: 700; font-variant-numeric: tabular-nums; }

/* ---------- Игровая сцена ---------- */
#stage {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 0;
}

.mini {
  background: linear-gradient(180deg, var(--panel), var(--panel-2));
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 6px;
  text-align: center;
  width: 84px;
}
.mini .k { display: block; font-size: 9px; letter-spacing: .12em; color: var(--dim); margin-bottom: 4px; }
.mini canvas { display: block; }
#sideLeft, #sideRight { flex: 0 0 auto; }

#boardWrap {
  position: relative;
  height: 100%;
  aspect-ratio: 10 / 20;
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  background:
    radial-gradient(120% 60% at 50% 0%, #16203a 0%, transparent 60%),
    var(--panel-2);
  touch-action: none;
}
#c { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

#flash {
  position: absolute; inset: 0; pointer-events: none;
  background: #fff; opacity: 0; transition: opacity 250ms ease-out;
  mix-blend-mode: overlay;
}
#flash.on { opacity: .35; transition: none; }

/* ---------- Оверлеи ---------- */
#overlay, #pause, #over {
  position: absolute; inset: 0; z-index: 5;
  display: flex; align-items: center; justify-content: center;
  background: rgba(7, 10, 20, .82);
  backdrop-filter: blur(3px);
}
.panel { text-align: center; padding: 18px 14px; max-width: 92%; }
.panel h1 {
  font-size: clamp(28px, 9vw, 44px); letter-spacing: .28em; text-indent: .28em;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.panel h2 { font-size: 20px; letter-spacing: .18em; color: var(--accent); }
.panel .sub { color: var(--dim); font-size: 12px; line-height: 1.6; margin: 12px 0 16px; }
.panel .final { margin: 10px 0 4px; color: var(--dim); font-size: 14px; }
.panel .final b { color: var(--text); font-variant-numeric: tabular-nums; }
.panel .best-line { margin-top: 12px; color: var(--dim); font-size: 12px; }
.panel .best-line b { color: var(--accent); }
[hidden] { display: none !important; }

button.play {
  appearance: none; border: 0; border-radius: 12px; cursor: pointer;
  padding: 14px 34px; font-size: 16px; font-weight: 800; letter-spacing: .12em;
  color: #04121c;
  background: linear-gradient(180deg, #7de3ff, var(--accent));
  box-shadow: 0 6px 24px rgba(77, 210, 255, .35);
}
button.play:active { transform: translateY(1px) scale(.98); }

/* ---------- Верхние кнопки ---------- */
#tools {
  position: fixed;
  top: calc(8px + var(--safe-t));
  right: 12px;
  display: flex; gap: 6px; z-index: 8;
}
#tools button {
  appearance: none; cursor: pointer;
  width: 34px; height: 34px; border-radius: 9px;
  border: 1px solid var(--line);
  background: rgba(19, 26, 44, .85);
  color: var(--text); font-size: 15px; line-height: 1;
}
#tools button.off { color: var(--dim); }
#tools button:active { transform: scale(.94); }

/* ---------- Тач-пад ---------- */
#pad {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 6px;
  padding-bottom: 2px;
}
#pad button {
  appearance: none; cursor: pointer;
  height: max(52px, calc(9dvh - 6px));
  border-radius: 14px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, var(--panel), var(--panel-2));
  color: var(--text);
  font-size: 22px;
  touch-action: none;
}
#pad button:active, #pad button.held {
  background: linear-gradient(180deg, #1d2c4f, #16223c);
  border-color: var(--accent);
  transform: scale(.97);
}

.noscript { color: #fff; padding: 2rem; }

/* ---------- Планшет / десктоп: боковые панели крупнее ---------- */
@media (min-width: 700px) {
  #app { max-width: 760px; margin: 0 auto; }
  .mini canvas { width: 96px; }
  #cNext { height: 240px; }
  #pad { max-width: 520px; margin: 0 auto; width: 100%; }
  #pad button { font-size: 24px; }
}

/* альбомная ориентация телефона: падаем панели, прячем мини,_pad крупнее */
@media (orientation: landscape) and (max-height: 520px) {
  #sideLeft, #sideRight { display: none; }
  #hud { grid-template-columns: repeat(4, minmax(70px, 160px)); justify-content: center; }
  #boardWrap { aspect-ratio: 10 / 20; max-height: 100%; }
  #pad button { height: 44px; font-size: 18px; }
}
