/* ============================================================
   YAMADA_AI — мини-игра Tetoris
   Поле и фигуры рисуются на canvas, остальное — обычная вёрстка.
   Фон — ролик YouTube под затемнением.
   ============================================================ */

:root {
  --ink: #eef0ff;
  --muted: #9aa0c0;
  --panel: rgba(12, 12, 20, 0.78);
  --line: rgba(255, 255, 255, 0.12);
  --accent: #ff3d9a;
  --display: "Russo One", "Trebuchet MS", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
}

*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; }
html, body { height: 100%; }
body {
  background: #07060a; color: var(--ink);
  font-family: var(--display);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Фоновое видео ----------
   iframe растянут «cover»: 16:9 шире или выше экрана, лишнее за краями */
.tv { position: fixed; inset: 0; overflow: hidden; pointer-events: none; }
.tv iframe {
  position: absolute; left: 50%; top: 50%;
  width: max(100vw, 177.78vh); height: max(100vh, 56.25vw);
  translate: -50% -50%;
  border: 0;
}
.tv::after { content: ""; position: absolute; inset: 0; background: rgba(4, 4, 8, 0.6); }

/* ---------- Верх ---------- */
.bar {
  position: fixed; z-index: 5; top: 0; left: 0; right: 0;
  display: flex; align-items: center; gap: 1rem;
  padding: 0.9rem clamp(1rem, 3vw, 2rem);
}
.back, .vol {
  display: inline-flex; align-items: center; gap: 0.55em;
  height: 2.5rem; padding: 0 1rem; border-radius: 99px;
  background: var(--panel); backdrop-filter: blur(6px);
  color: var(--ink); text-decoration: none; font-size: 0.95rem;
}
.back:hover, .back:focus-visible { background: rgba(40, 36, 60, 0.9); }
.logo {
  margin: 0 auto; font-size: clamp(1.2rem, 2.4vw, 1.8rem); letter-spacing: 0.12em; font-weight: 400;
  color: #fff; text-shadow: 0 0 18px rgba(255, 61, 154, 0.6);
}
.vol { gap: 1em; }
.vol__one { display: inline-flex; align-items: center; gap: 0.45em; }
.vol__icon { color: var(--accent); }
.vol__range { width: clamp(80px, 12vw, 150px); accent-color: var(--accent); }

.beat {
  display: inline-flex; align-items: center; gap: 0.5em;
  height: 2.5rem; padding: 0 0.9rem; border-radius: 99px;
  background: var(--panel); backdrop-filter: blur(6px);
  font-size: 0.85rem; cursor: pointer; user-select: none;
}
.beat input { accent-color: var(--accent); width: 1.05rem; height: 1.05rem; }
.beat.is-wait span::after { content: " …"; }
.deck { display: inline-flex; gap: 0.35rem; }
.skip {
  height: 2.5rem; width: 2.5rem; border: 0; border-radius: 50%;
  background: var(--panel); backdrop-filter: blur(6px);
  color: var(--ink); font-size: 1rem; cursor: pointer;
}
.skip:hover, .skip:focus-visible { background: rgba(40, 36, 60, 0.9); color: var(--accent); }


/* ---------- Раскладка ----------
   Соло: одно поле и подсказка по клавишам. Против бота: два поля рядом,
   как сплит-скрин в tetr.io; высота поля ужимается, чтобы оба влезли */
.game {
  position: relative; z-index: 2;
  height: 100%;
  display: flex; justify-content: center; align-items: center;
  gap: clamp(0.8rem, 2vw, 1.6rem);
  padding: 4.2rem 1rem 1rem;
  --bh: min(calc(100vh - 7.5rem), 160vw);
}
.game[data-mode="bot"] { --bh: min(calc(100vh - 8.5rem), calc(100vw - 36rem)); }
.game[data-mode="bot"] .side--keys { display: none; }
.seats { display: flex; gap: clamp(1rem, 3vw, 3rem); align-items: flex-start; }
.seat[hidden] { display: none; }
.seat__name { text-align: center; font-size: 0.9rem; letter-spacing: 0.12em; color: var(--muted); margin-bottom: 0.4rem; min-height: 1.2em; }
.game[data-mode="solo"] .seat__name { display: none; }
.seat__row { display: flex; gap: 0.7rem; align-items: flex-start; }

.side { display: grid; gap: 0.8rem; align-content: start; }
.side--keys { align-self: flex-start; margin-top: 1.6rem; }
.box {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 0.6rem 0.75rem; backdrop-filter: blur(6px);
}
.box h2 { font-size: 0.8rem; letter-spacing: 0.14em; color: var(--muted); margin-bottom: 0.4rem; font-weight: 400; }
.box canvas { display: block; }
.hold { width: 110px; height: 72px; }
.next { width: 110px; height: calc(var(--bh) * 0.5); max-height: 330px; }

.stats { display: grid; gap: 0.35rem; min-width: 124px; }
.stats div { display: flex; justify-content: space-between; gap: 0.8rem; font-size: 0.75rem; color: var(--muted); }
.stats b { font-family: var(--mono); font-size: 0.95rem; color: var(--ink); font-variant-numeric: tabular-nums; }
.game[data-mode="solo"] .stats [data-in="bot"],
.game[data-mode="bot"] .stats [data-in="solo"] { display: none; }

.keys dl { display: grid; grid-template-columns: auto 1fr; gap: 0.3rem 0.6rem; align-items: center; font-family: system-ui, sans-serif; font-size: 0.78rem; }
.keys dd { color: var(--muted); }
kbd {
  display: inline-block; min-width: 1.6em; padding: 0.05em 0.35em; margin-right: 0.2em;
  border-radius: 4px; border: 1px solid rgba(255, 255, 255, 0.25); border-bottom-width: 2px;
  background: rgba(255, 255, 255, 0.06);
  font-family: var(--mono); font-size: 0.72rem; text-align: center; color: var(--ink);
}

/* ---------- Поле ---------- */
.well { position: relative; }
.board {
  display: block;
  height: var(--bh); width: calc(var(--bh) / 2);
  background: rgba(6, 6, 12, 0.82);
  border: 2px solid rgba(255, 255, 255, 0.18); border-top-color: transparent;
  box-shadow: 0 0 40px rgba(0, 0, 0, 0.6);
}
/* Шкала входящего мусора слева от поля, как в tetr.io: красная — уже
   поднимется со следующей фигурой, оранжевая — ещё летит */
.meter {
  position: absolute; left: -10px; bottom: 2px; width: 7px; height: calc(100% - 4px);
  background: rgba(255, 255, 255, 0.06); border-radius: 3px; overflow: hidden;
}
.meter i {
  position: absolute; left: 0; right: 0; bottom: 0; height: 0;
  background: linear-gradient(to top, #ff2d46 var(--ready, 0%), #ffa23d var(--ready, 0%));
  transition: height 0.15s;
}

/* Толчки поля: жёсткий сброс — короткий удар вниз, тетрис, T-спин и
   пришедший мусор — тряска */
.well.bump .board { animation: bump 0.16s ease-out; }
.well.shake .board { animation: shake 0.32s ease-out; }
@keyframes bump { 0% { transform: translateY(0); } 35% { transform: translateY(1.2%); } 100% { transform: translateY(0); } }
@keyframes shake {
  0%, 100% { transform: translate(0, 0); }
  20% { transform: translate(-2%, 0.6%); } 40% { transform: translate(1.6%, -0.4%); }
  60% { transform: translate(-1%, 0.3%); } 80% { transform: translate(0.5%, 0); }
}
/* Проигрыш как в tetr.io: поле коротко трясёт, стакан сереет, потом поле
   вместе с HOLD и NEXT обваливается вниз, чуть заваливаясь, и гаснет */
.seat.dead .board { animation: die-shake 0.22s linear, die-fall 1.1s cubic-bezier(0.55, 0, 0.9, 0.4) 0.22s forwards; }
.seat.dead .meter { opacity: 0; }
.seat.dead .side:first-child { animation: die-fall-l 1.1s cubic-bezier(0.55, 0, 0.9, 0.4) 0.3s forwards; }
.seat.dead .side:last-child { animation: die-fall-r 1.1s cubic-bezier(0.55, 0, 0.9, 0.4) 0.34s forwards; }
@keyframes die-shake {
  0%, 100% { transform: translate(0, 0); }
  20% { transform: translate(-3%, 0.5%); } 40% { transform: translate(3%, -0.5%); }
  60% { transform: translate(-2%, 0.3%); } 80% { transform: translate(2%, 0); }
}
@keyframes die-fall { to { transform: translateY(110vh) rotate(9deg); opacity: 0; } }
@keyframes die-fall-l { to { transform: translateY(110vh) rotate(-12deg); opacity: 0; } }
@keyframes die-fall-r { to { transform: translateY(110vh) rotate(14deg); opacity: 0; } }

/* Тряска в бит: толчок всего экрана, сила — от громкости удара */
.game { --kick: 0; }
.game.is-kick { animation: kick 0.14s ease-out; }
@keyframes kick {
  0% { transform: translate(calc(var(--kick) * -0.6%), calc(var(--kick) * 0.9%)) scale(calc(1 + var(--kick) * 0.012)); }
  100% { transform: none; }
}

.flash {
  position: absolute; left: 50%; top: 38%; translate: -50% 0;
  font-size: clamp(0.9rem, 2.2vh, 1.5rem); white-space: nowrap; text-align: center;
  color: #fff; text-shadow: 0 0 12px rgba(255, 61, 154, 0.9);
  opacity: 0; pointer-events: none;
}
.flash.is-on { animation: flash 1.1s ease-out forwards; }
@keyframes flash {
  0% { opacity: 0; transform: scale(0.7); }
  15% { opacity: 1; transform: scale(1.12); }
  30% { transform: scale(1); }
  75% { opacity: 1; }
  100% { opacity: 0; transform: translateY(-40%); }
}

/* ---------- Меню ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 4;
  display: grid; place-items: center;
  background: rgba(4, 4, 8, 0.55);
}
.overlay[hidden] { display: none; }
.overlay.is-late { animation: overlay-in 0.4s ease-out; }
@keyframes overlay-in { from { opacity: 0; } }
.menu {
  display: grid; gap: 0.9rem; justify-items: center; text-align: center;
  padding: 1.6rem 2rem; min-width: min(90vw, 420px);
  background: rgba(12, 12, 20, 0.9); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
}
.menu[hidden] { display: none; }
.menu__title { font-size: clamp(1.6rem, 4vh, 2.4rem); letter-spacing: 0.1em; font-weight: 400; }
.menu__text { font-family: system-ui, sans-serif; color: var(--muted); }
.menu__text:empty { display: none; }
.menu__pick { display: flex; gap: 0.4rem; flex-wrap: wrap; justify-content: center; }
.menu__pick[hidden] { display: none; }
.menu__pick button, .menu__go {
  font: inherit; font-size: 0.9rem; color: var(--ink); cursor: pointer;
  padding: 0.5rem 1rem; border-radius: 99px;
  background: rgba(255, 255, 255, 0.06); border: 1px solid var(--line);
}
.menu__pick button[aria-checked="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
.menu__go { background: #fff; color: #111; border: 0; padding: 0.6rem 1.4rem; font-size: 1rem; }
.menu__go kbd { color: #111; border-color: rgba(0, 0, 0, 0.3); background: rgba(0, 0, 0, 0.06); }
.menu__nick { display: flex; align-items: center; gap: 0.6rem; font-size: 0.85rem; color: var(--muted); }
.menu__nick[hidden] { display: none; }
.menu__nickin {
  width: 12rem; padding: 0.45rem 0.7rem; border-radius: 8px;
  background: rgba(255, 255, 255, 0.06); border: 1px solid var(--line); color: var(--ink);
  font: inherit; font-size: 0.95rem;
}
.menu__room { display: flex; gap: 0.4rem; width: 100%; }
.menu__room[hidden] { display: none; }
.menu__link {
  flex: 1; min-width: 0; padding: 0.45rem 0.7rem; border-radius: 8px;
  background: rgba(255, 255, 255, 0.06); border: 1px solid var(--line); color: var(--ink);
  font: 0.8rem var(--mono);
}
.menu__copy {
  font: inherit; font-size: 0.85rem; color: var(--ink); cursor: pointer;
  padding: 0.45rem 0.8rem; border-radius: 8px; background: rgba(255, 255, 255, 0.1); border: 1px solid var(--line);
}
.menu__go[hidden] { display: none; }
.countdown {
  position: fixed; left: 50%; top: 45%; translate: -50% -50%;
  font-size: clamp(3rem, 12vh, 7rem); color: #fff; pointer-events: none;
  text-shadow: 0 0 30px rgba(255, 61, 154, 0.8);
}
.countdown.is-on { animation: count 0.6s ease-out; }
@keyframes count { 0% { opacity: 0; transform: scale(1.6); } 30% { opacity: 1; transform: scale(1); } 100% { opacity: 0.2; } }

@media (prefers-reduced-motion: reduce) {
  .well.bump .board, .well.shake .board, .game.is-kick { animation: none; }
  .seat.dead .board, .seat.dead .side { animation: none; opacity: 0.35; }
}
@media (max-width: 760px) {
  .side--keys { display: none; }
}
