/* =================================================================
   Web Guitar Hero — client styles
   ================================================================= */

:root {
  --bg-0: #05060e;
  --bg-1: #0a0a1a;
  --panel: rgba(20, 22, 48, 0.72);
  --line: rgba(120, 130, 200, 0.18);
  --line-strong: rgba(120, 130, 200, 0.35);
  --fg: #eef0fa;
  --fg-muted: #9098c4;
  --fg-dim: #5d6493;

  --accent: #ffcc33;
  --accent-2: #ff7a59;
  --accent-soft: #ffe27a;
  --neon-pink: #ff3aa8;
  --neon-cyan: #2ee0ff;
  --neon-violet: #8a5cff;
  --green: #3ce074;
  --red: #ff5566;
  --blue: #3aa8ff;
  --orange: #ff8a2b;
  --yellow: #ffd23b;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; height: 100%;
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", Roboto, sans-serif;
  overflow: hidden;
  touch-action: manipulation;
  -webkit-font-smoothing: antialiased;
  user-select: text;
}
/* gradient lives on <html> so canvas#bg (z-index:-1) renders ABOVE it
   but below body content — body itself stays transparent. */
html {
  background:
    radial-gradient(1200px 800px at 20% 10%, rgba(138,92,255,0.18), transparent 60%),
    radial-gradient(900px 700px at 85% 90%, rgba(46,224,255,0.14), transparent 65%),
    radial-gradient(800px 600px at 50% 60%, rgba(255,122,89,0.08), transparent 70%),
    linear-gradient(180deg, #05060e 0%, #0a0a1a 100%);
}
body { background: transparent; }
button, input, select { font: inherit; color: inherit; }

/* selection: enabled by default, blocked only on chrome that shouldn't be copied */
button, canvas, .guitar-logo, .pulse-ring, .progress, .pill, .tag,
.game-title, .title-subline {
  user-select: none;
}
input, textarea, select, .lobby-row .code, .lobby-row .meta,
.code, .meta, .name, h1, h2, h3, p, table, td, th,
#trackInfo, #trackHostHint, #toast, #hudTrack {
  user-select: text;
}

/* =================================================================
   Buttons
   ================================================================= */
button {
  position: relative;
  background: linear-gradient(180deg, #1f213d 0%, #161830 100%);
  border: 1px solid var(--line-strong);
  color: var(--fg);
  padding: 10px 18px;
  border-radius: 12px;
  cursor: pointer;
  font-size: 14px;
  letter-spacing: 0.3px;
  transition: transform 0.12s ease, background 0.15s, border-color 0.15s, box-shadow 0.18s;
  overflow: hidden;
}
button::before {
  content: ''; position: absolute; inset: 0;
  background: radial-gradient(circle at var(--mx,50%) var(--my,50%), rgba(255,255,255,0.12), transparent 60%);
  opacity: 0; transition: opacity 0.2s;
  pointer-events: none;
}
button:hover:not(:disabled) {
  transform: translateY(-1px);
  border-color: rgba(255,204,51,0.55);
  box-shadow: 0 6px 22px rgba(255,204,51,0.12), inset 0 0 0 1px rgba(255,255,255,0.04);
}
button:hover:not(:disabled)::before { opacity: 1; }
button:active:not(:disabled) { transform: translateY(0); }
button:disabled { opacity: 0.4; cursor: not-allowed; }
button.primary {
  background: linear-gradient(180deg, #ffd84e 0%, #ffb028 100%);
  color: #181808;
  border-color: rgba(255,204,51,0.85);
  font-weight: 700;
  box-shadow: 0 4px 18px rgba(255,180,60,0.35), inset 0 1px 0 rgba(255,255,255,0.4);
}
button.primary:hover:not(:disabled) { box-shadow: 0 8px 28px rgba(255,180,60,0.5); }
button.ghost {
  background: transparent;
  border-color: var(--line);
  color: var(--fg-muted);
}
button.danger {
  background: linear-gradient(180deg, #4a1f24 0%, #2a1014 100%);
  border-color: rgba(255,85,102,0.4);
  color: var(--red);
}
button.on {
  background: linear-gradient(180deg, #ffd84e 0%, #ffb028 100%);
  color: #181808;
  border-color: rgba(255,204,51,0.85);
  box-shadow: 0 0 0 1px rgba(255,204,51,0.4), 0 0 18px rgba(255,204,51,0.25);
}

/* =================================================================
   Inputs
   ================================================================= */
input[type=text], input[type=password], select {
  background: rgba(8, 10, 26, 0.7);
  border: 1px solid var(--line);
  color: var(--fg);
  padding: 11px 14px;
  border-radius: 10px;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
  outline: none;
}
input::placeholder { color: var(--fg-dim); }
input[type=text]:focus, input[type=password]:focus, select:focus {
  border-color: var(--accent);
  background: rgba(15, 17, 38, 0.85);
  box-shadow: 0 0 0 3px rgba(255,204,51,0.18);
}
select {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--fg-muted) 50%),
                    linear-gradient(135deg, var(--fg-muted) 50%, transparent 50%);
  background-position: calc(100% - 16px) 50%, calc(100% - 11px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 32px;
}

/* =================================================================
   Background canvas
   ================================================================= */
#bg {
  position: fixed; inset: 0; z-index: -1;
  width: 100vw; height: 100vh;
  pointer-events: none;
}
/* during gameplay the rich animated bg is hidden + paused */
body.in-game #bg { display: none; }

/* =================================================================
   Screens
   ================================================================= */
.screen {
  position: absolute; inset: 0;
  display: none; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 24px;
}
.screen.on { display: flex; animation: fadeIn 0.35s ease-out; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* =================================================================
   Animated game title (preloader + menu + end)
   ================================================================= */
.title-wrap {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  margin-bottom: 22px;
  max-width: 100%;
}
.game-title {
  font-family: 'Impact', 'Arial Black', 'Segoe UI', sans-serif;
  font-size: clamp(26px, 7vw, 78px);
  font-weight: 900;
  letter-spacing: 6px;
  line-height: 1;
  display: flex; gap: 0;
  text-transform: uppercase;
  flex-wrap: wrap; justify-content: center;
  max-width: 100%;
}
@media (max-width: 380px) {
  .game-title { letter-spacing: 2px; }
}
.title-wrap .title-subline { text-align: center; max-width: 100%; }
.game-title span {
  background: linear-gradient(180deg, #ffe27a 0%, #ffaf2a 50%, #ff5566 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  -webkit-text-stroke: 1px rgba(255,255,255,0.05);
  filter: drop-shadow(0 0 16px rgba(255,150,60,0.45));
  animation: letter-float 3s ease-in-out infinite;
  animation-delay: calc(var(--i, 0) * 80ms);
  transform-origin: bottom center;
}
@keyframes letter-float {
  0%, 100% { transform: translateY(0) rotate(0); }
  50%      { transform: translateY(-6px) rotate(-1deg); }
}
.game-title .gap { display: inline-block; width: 0.5em; }
.title-subline {
  font-family: monospace;
  color: var(--fg-muted);
  font-size: 13px;
  letter-spacing: 6px;
  text-transform: uppercase;
  opacity: 0.7;
  display: inline-flex; align-items: center; justify-content: center;
  gap: 12px;
  max-width: 100%;
  white-space: nowrap;
}
.title-subline::before, .title-subline::after {
  content: ''; height: 1px; flex: 0 0 40px;
  background: linear-gradient(90deg, transparent, var(--fg-muted), transparent);
}
@media (max-width: 480px) {
  .title-subline { font-size: 11px; letter-spacing: 3px; gap: 8px; }
  .title-subline::before, .title-subline::after { flex-basis: 24px; }
}
@media (max-width: 360px) {
  .title-subline { font-size: 10px; letter-spacing: 2px; gap: 6px; }
  .title-subline::before, .title-subline::after { flex-basis: 16px; }
}

/* inline guitar logo */
.guitar-logo { width: 84px; height: 84px; margin-bottom: 8px; }
.guitar-logo .body { animation: logo-rock 4s ease-in-out infinite; transform-origin: 50% 65%; }
@keyframes logo-rock {
  0%, 100% { transform: rotate(-4deg); }
  50%      { transform: rotate(4deg); }
}
.guitar-logo .string {
  stroke-dasharray: 4 4;
  animation: string-strum 0.9s linear infinite;
}
.guitar-logo .string:nth-child(2) { animation-delay: 0.1s; }
.guitar-logo .string:nth-child(3) { animation-delay: 0.2s; }
.guitar-logo .string:nth-child(4) { animation-delay: 0.3s; }
@keyframes string-strum { to { stroke-dashoffset: 16; } }

/* =================================================================
   Preloader
   ================================================================= */
#pre .pulse-ring {
  width: 96px; height: 96px; position: relative; margin-bottom: 8px;
}
#pre .pulse-ring::before, #pre .pulse-ring::after {
  content: ''; position: absolute; inset: 0;
  border-radius: 50%;
  border: 3px solid var(--accent);
  animation: pulse-out 2s ease-out infinite;
}
#pre .pulse-ring::after { animation-delay: 1s; }
@keyframes pulse-out {
  0%   { transform: scale(0.4); opacity: 1; }
  100% { transform: scale(1.6); opacity: 0; }
}
#pre .status { margin-top: 18px; color: var(--fg-muted); font-size: 14px; letter-spacing: 1px; }
#pre .status.err { color: var(--red); }
#pre .retry { margin-top: 14px; display: none; }
#pre .progress { width: 280px; height: 4px; background: var(--line); border-radius: 2px; overflow: hidden;
  margin-top: 18px; }
#pre .progress .bar { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2));
  width: 0%; transition: width 0.3s; box-shadow: 0 0 10px var(--accent); }

/* =================================================================
   Glass cards
   ================================================================= */
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 20px 22px;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 6px 36px rgba(0,0,0,0.35), inset 0 1px 0 rgba(255,255,255,0.04);
}
.card h2 { margin: 0 0 14px; font-size: 17px; }
.card h3 { margin: 0 0 12px; font-size: 13px; text-transform: uppercase; letter-spacing: 2px; color: var(--fg-muted); }

/* row that wraps server status + a small settings button */
.status-row {
  display: flex; align-items: center; gap: 10px;
  width: min(440px, 95vw);
  justify-content: space-between;
  margin-bottom: 6px;
}
.status-row #serverStatus { margin-bottom: 0; flex: 1 1 auto; min-width: 0; }
button.icon { padding: 8px 12px; font-size: 16px; line-height: 1; }

/* always-on fullscreen toggle (top-right). Visible на всех экранах, особенно
   полезно на мобиле — спрятать браузерный UI / нативные жесты. */
#fsBtn {
  position: fixed;
  top: max(8px, env(safe-area-inset-top));
  right: max(8px, env(safe-area-inset-right));
  z-index: 1000;
  width: 36px; height: 36px; padding: 0;
  font-size: 18px; line-height: 1;
  border-radius: 8px;
  background: rgba(20, 20, 32, 0.65);
  border: 1px solid var(--line);
  color: var(--fg);
  backdrop-filter: blur(6px);
  cursor: pointer;
  opacity: 0.72;
  transition: opacity 0.15s, background 0.15s;
}
#fsBtn:hover { opacity: 1; }
body.is-fullscreen #fsBtn { background: rgba(60, 60, 80, 0.65); }

/* =================================================================
   Server status pill (above 'Create lobby')
   ================================================================= */
#serverStatus {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 14px; border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--line-strong);
  backdrop-filter: blur(8px);
  font-size: 13px;
  margin-bottom: 6px;
  transition: background 0.2s, border-color 0.2s;
}
#serverStatus .dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--fg-dim);
  box-shadow: 0 0 0 0 currentColor;
  flex: 0 0 auto;
}
#serverStatus.online {
  background: rgba(60,224,116,0.12);
  border-color: rgba(60,224,116,0.55);
}
#serverStatus.online .dot {
  background: var(--green); color: var(--green);
  animation: pulse-dot 1.6s ease-in-out infinite;
}
#serverStatus.offline {
  background: rgba(255,85,102,0.12);
  border-color: rgba(255,85,102,0.55);
}
#serverStatus.offline .dot {
  background: var(--red); color: var(--red);
}
#serverStatus .label { color: var(--fg); }
#serverStatus.online .label { color: var(--green); }
#serverStatus.offline .label { color: var(--red); }
#serverStatus .ping {
  color: var(--fg-muted); font-family: monospace; font-size: 12px;
  padding-left: 10px; border-left: 1px solid var(--line);
  margin-left: auto;    /* push ping to the right edge of the pill */
}
@keyframes pulse-dot {
  0%, 100% { box-shadow: 0 0 0 0 rgba(60,224,116,0.5); }
  50%      { box-shadow: 0 0 0 6px rgba(60,224,116,0); }
}

/* =================================================================
   Menu
   ================================================================= */
#menu { gap: 14px; padding-top: 36px; padding-bottom: 36px; overflow-y: auto; overflow-x: hidden; justify-content: flex-start; }
#menu .card { width: min(440px, 95vw); }
#menu .card .row {
  display: flex; gap: 8px;
  flex-wrap: wrap;             /* allow buttons to wrap on narrow widths */
  align-items: center;
}
#menu .card .row input {
  flex: 1 1 120px;             /* let inputs shrink and grow */
  min-width: 0;                /* fix overflow when forced narrow */
}
#menu .card .row button {
  flex: 0 0 auto;
}
#menu .name-row { display: flex; gap: 10px; align-items: center; width: min(440px, 95vw); }
#menu .name-row label {
  color: var(--fg-muted); font-size: 11px; text-transform: uppercase; letter-spacing: 2px;
  min-width: 50px;
}
#menu .name-row input { flex: 1; min-width: 0; }
#menu .lobby-list { max-height: 220px; overflow: auto; margin: 0 -8px; padding: 0 8px; }
#menu .lobby-row {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 10px;
  background: rgba(255,255,255,0.02);
  border: 1px solid transparent;
  margin-bottom: 6px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.12s;
}
#menu .lobby-row:hover { background: rgba(255,204,51,0.05); border-color: rgba(255,204,51,0.3); transform: translateX(2px); }
#menu .lobby-row .code { font-family: monospace; color: var(--accent); font-weight: 700; font-size: 15px; letter-spacing: 2px; }
#menu .lobby-row .meta { color: var(--fg-muted); flex: 1; font-size: 13px; }
#menu .lobby-row .lock { color: var(--fg-dim); font-size: 13px; }
#menu .empty { color: var(--fg-muted); padding: 12px; text-align: center; font-size: 13px; }

/* =================================================================
   Lobby
   ================================================================= */
#lobby {
  /* sized like a centred container — not full-bleed */
  padding: 24px 16px 36px;
  align-items: stretch; justify-content: flex-start;
  overflow-y: auto;
  overflow-x: hidden;   /* guarantee no horizontal scroll on any width */
}
#lobby > * {
  width: 100%;
  max-width: 960px;
  margin-left: auto;
  margin-right: auto;
  min-width: 0;            /* allow children to actually shrink — kills horiz overflow */
}
#lobby, #lobby .columns, #lobby .card { min-width: 0; }
@media (max-width: 480px) {
  #lobby { padding: 12px 10px 36px; }
  #lobby .header h1 { font-size: 20px; }
  #lobby .header .code { font-size: 18px; letter-spacing: 2px; }
  #lobby .header .meta { font-size: 11px; width: 100%; margin-left: 0; }
  #lobby .card { padding: 14px 14px; }
  #lobby .row label { min-width: 64px; font-size: 10px; }
  #lobby .actions button { flex: 1 1 auto; }
  #lobby .actions #startBtn { margin-left: 0; width: 100%; order: 3; }
}
#lobby .header { display: flex; align-items: baseline; gap: 14px; margin-bottom: 18px; flex-wrap: wrap; }
#lobby .header h1 {
  margin: 0; font-size: 26px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
#lobby .header .code {
  font-family: monospace; font-size: 24px;
  color: var(--accent); letter-spacing: 4px;
  text-shadow: 0 0 12px rgba(255,204,51,0.4);
}
#lobby .header .meta { color: var(--fg-muted); font-size: 13px; margin-left: auto; }
#lobby .columns { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 720px) { #lobby .columns { grid-template-columns: 1fr; } }
#lobby .row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; align-items: center; }
#lobby .row label {
  color: var(--fg-dim); font-size: 11px; text-transform: uppercase; letter-spacing: 1.5px;
  min-width: 90px;
}
#lobby .player-list {
  display: flex; flex-direction: column; gap: 8px;
  max-height: calc(100dvh - 305px);
  overflow-y: auto;
  padding-right: 4px;
}
#lobby .player-row {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px;
  background: linear-gradient(180deg, rgba(255,255,255,0.03), rgba(255,255,255,0.01));
  border: 1px solid var(--line);
  border-radius: 10px;
  transition: border-color 0.15s, transform 0.15s;
  animation: slideIn 0.3s ease-out;
}
@keyframes slideIn { from { opacity: 0; transform: translateX(-8px); } to { opacity: 1; transform: translateX(0); } }
#lobby .player-row.you {
  border-color: rgba(255,204,51,0.55);
  box-shadow: 0 0 0 1px rgba(255,204,51,0.2), 0 0 16px rgba(255,204,51,0.1);
}
#lobby .player-row .name { flex: 1; font-weight: 500; }
#lobby .player-row .tag {
  font-size: 10px; padding: 3px 8px; border-radius: 999px;
  background: rgba(0,0,0,0.3); color: var(--fg-muted);
  text-transform: uppercase; letter-spacing: 1px;
}
#lobby .player-row .tag.host { color: var(--accent); background: rgba(255,204,51,0.12); }
#lobby .player-row .tag.ready { color: var(--green); background: rgba(60,224,116,0.12); }
#lobby .player-row .tag.notready { color: var(--orange); background: rgba(255,138,43,0.12); }
#lobby .actions { display: flex; gap: 10px; margin-top: 18px; flex-wrap: wrap; }
#lobby #trackInfo { color: var(--fg-muted); font-size: 13px; margin-top: 4px; }
#lobby #trackHostHint { color: var(--fg-dim); font-size: 12px; margin-top: 6px; display: none; }

/* =================================================================
   Game
   ================================================================= */
#game { padding: 0; align-items: stretch; justify-content: stretch; }
#game canvas {
  display: block; touch-action: none;
  flex: 1 1 0;          /* take remaining space inside the column flex */
  min-height: 0;        /* let flex shrink past the canvas intrinsic height */
  width: 100%;
  height: 100%;
}
#game #hud {
  position: absolute; top: 0; left: 0; right: 0; z-index: 10; padding: 12px 16px;
  display: flex; gap: 8px; align-items: center; pointer-events: none; flex-wrap: wrap;
}
#game #hud .pill, #game #hud button.pill {
  background: rgba(5,6,18,0.85);
  /* backdrop-filter намеренно убран в игре — это самая дорогая операция для
     GPU на мобилках, давала просадки fps. Используем непрозрачный фон вместо
     блюра. */
  border: 1px solid var(--line);
  padding: 6px 12px; border-radius: 999px; font-size: 13px;
  letter-spacing: 0.5px;
  pointer-events: auto;    /* buttons inside the HUD need clicks */
}
#game #hud button.pill { cursor: pointer; color: var(--fg-muted); font-family: inherit; }
#game #hud button.pill:hover { color: var(--fg); border-color: var(--accent); }

/* hud toggle visible only on narrow screens — размер совпадает с остальными
   пилюлями, чтобы строка была ровной */
#hudToggle { display: none; }
@media (max-width: 720px) {
  #hudToggle { display: inline-flex; align-items: center; justify-content: center; }
  #game #hud.collapsed .pill:not(#hudMenu):not(#hudToggle):not(.score):not(.combo):not(#hudWatch) { display: none; }
  #game #hud { padding: 8px 10px; gap: 6px; }
  #game #hud .pill { font-size: 12px; padding: 5px 10px; }
}
/* Spectator watch-target pill — always shown for spectators */
#game.spectator #hudWatch { display: inline-block; cursor: pointer; }

/* На очень узких экранах прячем слово «меню» — остаётся только символ ≡ */
@media (max-width: 370px) {
  #hudMenu .lbl { display: none; }
}

/* spectator never sees player-only HUD pills */
#game.spectator #hud .pill.score,
#game.spectator #hud .pill.combo,
#game.spectator #hud .pill[data-role="hits"],
#game.spectator #hud .pill[data-role="mult"],
#game.spectator #hud .pill[data-role="acc"],
#game.spectator #hud .pill[data-role="shift"] { display: none; }
#game #hud .pill.combo { color: var(--accent); font-weight: 700; }
#game #hud .pill.score { color: var(--fg); font-weight: 700; }
#game #hud .pill[data-role="mult"] { color: var(--fg); font-weight: 700; }
#game #hud .pill.mult-hot {
  background: linear-gradient(180deg, #ffd84e, #ff8a2b); color: #1a0e02;
  border-color: var(--accent);
  box-shadow: 0 0 14px rgba(255,170,40,0.55);
}
#game #hud .pill.mult-shift {
  background: linear-gradient(180deg, #b48bff, #6d3ce0); color: #1a0a2e;
  border-color: #a26bff;
  box-shadow: 0 0 14px rgba(162,107,255,0.6);
}
#game #hud .pill[data-role="acc"] { color: var(--fg); font-weight: 700; }
#game #hud .pill.acc-hi { color: #3ce074; border-color: rgba(60,224,116,0.5); }
#game #hud .pill.acc-lo { color: #ff5566; border-color: rgba(255,85,102,0.5); }
#game #hud .pill.shift-ready {
  background: linear-gradient(180deg, #ffd84e, #ffb028); color: #181808;
  border-color: var(--accent); font-weight: 700;
  box-shadow: 0 0 18px rgba(255,204,51,0.5);
  animation: glow-ready 1.2s ease-in-out infinite alternate;
}
@keyframes glow-ready {
  from { box-shadow: 0 0 12px rgba(255,204,51,0.4); }
  to   { box-shadow: 0 0 28px rgba(255,204,51,0.8); }
}
#game #hud .pill.shift-active {
  background: linear-gradient(180deg, #b48bff, #6d3ce0); color: #1a0a2e;
  border-color: #a26bff; font-weight: 700;
  animation: glow-active 0.5s ease-in-out infinite alternate;
}
@keyframes glow-active {
  from { box-shadow: 0 0 18px rgba(162,107,255,0.7); transform: scale(1); }
  to   { box-shadow: 0 0 32px rgba(162,107,255,1); transform: scale(1.04); }
}
#game #shiftBar {
  position: absolute; right: 16px; top: calc(50% - 15px); transform: translateY(-50%);
  width: 16px; height: 50%;
  background: rgba(5,6,18,0.7); border: 1px solid var(--line); border-radius: 8px;
  overflow: hidden; z-index: 8;
  box-shadow: 0 0 20px rgba(0,0,0,0.6);
  cursor: default;
  transition: border-color 0.2s, box-shadow 0.2s;
}
/* Кружок мультипликатора — отдельным абсолютным элементом, ниже бара.
   75% (= низ бара: top 50% - half height 25% = 25%, low = 75%) + небольшой
   gap. По ширине совпадает с баром (16px), правым краем выровнен с правым
   краем бара (right: 16px). Активирует SHIFT при клике. */
#game #shiftMultBubble {
  position: absolute; right: 16px; top: calc(75% - 15px); margin-top: 10px;
  width: 16px; height: 16px; border-radius: 50%;
  background: rgba(5,6,18,0.85); border: 1px solid var(--line);
  display: flex; align-items: center; justify-content: center;
  font-size: 8px; font-weight: 800; color: var(--fg);
  letter-spacing: -0.5px; line-height: 1;
  z-index: 8; cursor: pointer;
  box-shadow: 0 0 10px rgba(0,0,0,0.55);
  transition: background 0.2s, border-color 0.2s, box-shadow 0.25s, transform 0.2s;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
#game #shiftMultBubble[data-tier="2"] {
  background: linear-gradient(180deg, #ffe27a, #ffcc33);
  color: #181808; border-color: var(--accent);
  box-shadow: 0 0 14px rgba(255,204,51,0.55);
}
#game #shiftMultBubble[data-tier="4"] {
  background: linear-gradient(180deg, #ffd84e, #ff8a2b);
  color: #2a1300; border-color: var(--accent);
  box-shadow: 0 0 18px rgba(255,170,40,0.75);
}
#game #shiftMultBubble.shift-active {
  background: linear-gradient(180deg, #b48bff, #6d3ce0);
  color: #1a0a2e; border-color: #a26bff;
  box-shadow: 0 0 22px rgba(162,107,255,0.85);
  transform: scale(1.08);
}
#game #shiftBar.ready {
  cursor: pointer;
  border-color: var(--accent);
  box-shadow: 0 0 20px rgba(255,204,51,0.5);
}
#game #shiftBar.active {
  cursor: default;
  border-color: #a26bff;
  box-shadow: 0 0 24px rgba(162,107,255,0.6);
}
#game #shiftBar .fill {
  position: absolute; bottom: 0; left: 0; right: 0;
  background: linear-gradient(180deg, var(--accent-2), var(--accent));
  transition: height 0.15s ease-out, background 0.2s;
}
#game #shiftBar .label {
  position: absolute; left: 50%; bottom: -22px; transform: translateX(-50%);
  font-size: 11px; color: var(--fg-muted); letter-spacing: 1.5px;
}
#game #scoreboard {
  position: absolute; top: 0; bottom: 0; right: 0; width: 280px;
  background: rgba(5,6,18,0.95);
  /* blur убран — GPU съедал кадры на мобилках */
  border-left: 1px solid var(--line);
  padding: 16px 14px; z-index: 9;
  display: none; flex-direction: column; overflow-y: auto;
}
#game.spectator #scoreboard { display: flex; }

/* on narrow screens HUD and scoreboard go into the flex flow so the canvas
   can take the rest of the height. No empty strip above. */
@media (max-width: 720px) {
  #game { flex-direction: column; }
  #game #hud {
    position: relative;
    order: 0;
    background: rgba(5,6,18,0.6);
    border-bottom: 1px solid var(--line);
  }
  #game canvas { flex: 1 1 0; min-height: 0; width: 100%; order: 2; }
  #game.spectator #scoreboard {
    position: relative;
    top: auto; bottom: auto; left: auto; right: auto;
    width: auto;
    flex: 0 0 auto;
    order: 1;                     /* directly under the HUD, above the canvas */
    margin-top: 0;
    flex-direction: row; gap: 8px;
    padding: 8px 10px;
    border-left: none; border-bottom: 1px solid var(--line);
    overflow-x: auto; overflow-y: hidden;
  }
  #game.spectator #scoreboard h3 { display: none; }
  #game.spectator #scoreboard .row {
    flex: 0 0 auto; min-width: 130px; margin-bottom: 0;
    padding: 6px 10px;
  }
  #game.spectator #scoreboard .row .stats { gap: 6px; font-size: 11px; }
}
#scoreboard h3 { margin: 0 0 12px; font-size: 12px; text-transform: uppercase; letter-spacing: 2px; color: var(--fg-muted); }
#scoreboard .row {
  padding: 10px 12px;
  background: rgba(255,255,255,0.025);
  border-radius: 10px; margin-bottom: 8px;
  border: 1px solid transparent;
  transition: border-color 0.2s, background 0.2s;
}
#scoreboard .row.leader {
  border-color: rgba(255,204,51,0.6);
  background: rgba(255,204,51,0.06);
}
#scoreboard .row .name { font-weight: 700; font-size: 14px; }
#scoreboard .row .stats { color: var(--fg-muted); font-size: 12px; margin-top: 4px; display: flex; gap: 10px; }
#scoreboard .row .bar { margin-top: 6px; height: 4px; background: rgba(0,0,0,0.3); border-radius: 2px; overflow: hidden; }
#scoreboard .row .bar .fill { height: 100%; background: var(--accent); transition: width 0.2s linear; }
#scoreboard .row.shift-active {
  background: rgba(60,224,116,0.12); border-color: var(--green);
  box-shadow: 0 0 16px rgba(60,224,116,0.2);
}
/* thin song-progress bar pinned to the very bottom of the game screen */
#songProgress {
  position: absolute; left: 0; right: 0; bottom: 0;
  height: 3px;
  background: rgba(255,255,255,0.06);
  z-index: 11; pointer-events: none;
}
#songProgress .fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  width: 0%;
  transition: width 0.08s linear;
  box-shadow: 0 0 6px rgba(255,204,51,0.6);
}

#countdown {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  z-index: 20; pointer-events: none;
}
#countdown .num {
  font-family: 'Impact', 'Arial Black', sans-serif;
  font-size: 150px; font-weight: 900;
  background: linear-gradient(180deg, var(--accent-soft), var(--accent-2));
  -webkit-background-clip: text; background-clip: text; color: transparent;
  text-shadow: 0 0 60px rgba(255,204,51,0.7);
  animation: cd-pop 0.5s ease-out;
}
@keyframes cd-pop {
  0% { transform: scale(0.3); opacity: 0; }
  50% { transform: scale(1.1); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

/* =================================================================
   End-of-song stats modal (replaces the old fullscreen screen)
   ================================================================= */
#endModal .modal { width: min(620px, 100%); padding: 24px 28px; }
#endModal h2 {
  margin: 0 0 18px; font-size: clamp(22px, 4vw, 30px); text-align: center;
  /* mirrored palette so the loop is seamless — end matches the start */
  background: linear-gradient(90deg,
    var(--accent-soft),
    var(--accent-2),
    var(--neon-pink),
    var(--accent-2),
    var(--accent-soft)
  );
  -webkit-background-clip: text; background-clip: text; color: transparent;
  background-size: 200% auto;
  background-repeat: repeat-x;
  animation: shimmer 4s linear infinite;
}
@keyframes shimmer {
  from { background-position:   0% 50%; }
  to   { background-position: -200% 50%; }
}
#endModal table { width: 100%; border-collapse: separate; border-spacing: 0; }
#endModal th, #endModal td { padding: 10px 12px; text-align: left; font-size: 14px; border-bottom: 1px solid var(--line); }
#endModal th { color: var(--fg-muted); font-size: 10px; text-transform: uppercase; letter-spacing: 1.5px; }
#endModal tr.winner td {
  color: var(--accent); font-weight: 700;
  background: linear-gradient(90deg, rgba(255,204,51,0.1), transparent);
}
#endModal .actions { display: flex; gap: 10px; margin-top: 18px; justify-content: center; }
@media (max-width: 480px) {
  #endModal th, #endModal td { padding: 6px 8px; font-size: 12px; }
}

/* =================================================================
   Modal (settings)
   ================================================================= */
.modal-back {
  position: fixed; inset: 0; z-index: 90;
  background: rgba(5,6,18,0.7);
  backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
}
.modal-back.hide { display: none; }
.modal {
  width: min(480px, 100%);
  max-height: calc(100dvh - 32px);
  display: flex; flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--line-strong);
  border-radius: 16px;
  padding: 0;            /* head/body manage their own padding so body can scroll */
  backdrop-filter: blur(12px);
  box-shadow: 0 20px 60px rgba(0,0,0,0.6);
  animation: fadeIn 0.2s ease-out;
  overflow: hidden;
}
.modal-head {
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}
.modal-body {
  padding: 14px 20px 20px;
  overflow-y: auto;
  flex: 1 1 auto;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.modal-head h2 { margin: 0; font-size: 20px; }
.modal-body h3 { margin: 12px 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: 1.5px; color: var(--fg-muted); }
.modal-body .hint { margin: -2px 0 12px; color: var(--fg-dim); font-size: 12px; }
.modal-body label.check {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  background: rgba(255,255,255,0.02);
  border: 1px solid var(--line); border-radius: 10px;
  cursor: pointer;
}
.modal-body label.check input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--accent); }
.keymap-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.keymap-row label {
  display: inline-flex; flex-direction: column; align-items: center; gap: 4px;
}
.keymap-row label span {
  font-size: 10px; color: var(--fg-muted); letter-spacing: 1px;
}
.keymap-row input.keyInp,
.keymap-row input.shiftKeyInp {
  width: 44px; height: 44px; text-align: center;
  font-family: monospace; font-size: 18px; font-weight: 700;
  text-transform: uppercase;
}
.keymap-row button.bindShift {
  width: 26px; height: 26px; padding: 0; margin: 4px 0 0 0;
  font-size: 14px; line-height: 1; opacity: 0.7;
}
.keymap-row button.bindShift:hover { opacity: 1; }
.keymap-row button { margin-left: 8px; }

/* Track picker list inside the modal */
.track-list {
  max-height: calc(100dvh - 305px);
  overflow-y: auto;
  margin: 0 -4px;
  padding: 0 4px;
}
.track-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px; border-radius: 12px;
  background: rgba(255,255,255,0.02);
  border: 1px solid var(--line);
  margin-bottom: 8px; cursor: pointer;
  transition: border-color 0.15s, background 0.15s, transform 0.12s;
}
.track-item:hover {
  border-color: var(--accent);
  background: rgba(255,204,51,0.06);
  transform: translateX(2px);
}
.track-item.active {
  border-color: var(--accent);
  background: rgba(255,204,51,0.1);
  box-shadow: 0 0 0 1px rgba(255,204,51,0.3) inset;
}
.track-item .ti-main { flex: 1; min-width: 0; }
.track-item .ti-title { font-weight: 600; font-size: 15px; color: var(--fg); }
.track-item .ti-descr { color: var(--fg-muted); font-size: 12px; margin-top: 2px; }
.track-item .ti-stats {
  display: flex; gap: 14px; color: var(--fg-muted); font-size: 12px; margin-top: 6px;
  font-family: monospace; flex-wrap: wrap; align-items: center;
}
.track-item .ti-stats .stat {
  display: inline-flex; align-items: center; gap: 5px; white-space: nowrap;
  line-height: 1;
}
.track-item .ti-stats .stat b { font-weight: 600; color: var(--fg); }
.track-item .ti-stats svg {
  width: 13px; height: 13px; flex: 0 0 13px;
  color: var(--accent); display: block;
}
.track-item .ti-diff {
  flex: 0 0 auto;
  display: flex; flex-direction: column; align-items: center;
  padding: 6px 12px; border-radius: 10px;
  background: rgba(255,204,51,0.08);
  border: 1px solid rgba(255,204,51,0.25);
  min-width: 64px;
}
.track-item .ti-diff-label {
  font-size: 9px; text-transform: uppercase; letter-spacing: 1.2px;
  color: var(--fg-muted);
}
.track-item .ti-diff-num {
  font-family: monospace; font-weight: 800; font-size: 20px;
  color: var(--accent); line-height: 1.1;
}

/* Role-toggle button next to each player (host only) */
#lobby .player-row .role-toggle {
  background: rgba(0,0,0,0.25); border: 1px solid var(--line);
  color: var(--fg-muted); font-size: 10px; padding: 3px 8px; border-radius: 999px;
  cursor: pointer;
  text-transform: uppercase; letter-spacing: 1px;
  transition: border-color 0.15s, color 0.15s;
}
#lobby .player-row .role-toggle:hover { border-color: var(--accent); color: var(--accent); }

/* =================================================================
   Toast
   ================================================================= */
#toast {
  position: fixed; top: 20px; right: 20px;
  background: rgba(20,22,48,0.95);
  backdrop-filter: blur(10px);
  border: 1px solid var(--line-strong);
  padding: 12px 16px; border-radius: 12px;
  opacity: 0; transform: translateY(-8px);
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none; z-index: 100;
  font-size: 13px; max-width: 340px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.5);
}
#toast.show { opacity: 1; transform: translateY(0); }
#toast.ok { border-color: var(--green); }
#toast.err { border-color: var(--red); color: var(--red); }
