/* Тёмный неоновый боулинг-клуб. Вся типографика — системная, ничего не грузится
   по сети: игра должна открываться мгновенно и работать в оффлайне после кэша. */

:root {
  --bg: #05060c;
  --panel: rgba(16, 19, 30, 0.82);
  --panel-solid: #10131e;
  --line: rgba(255, 255, 255, 0.09);
  --text: #eef1f8;
  --muted: #9aa3b8;
  --accent: #57e6ff;
  --accent-2: #ff2fb9;
  --good: #55e08a;
  --warn: #ffbe45;
  --bad: #ff5c6c;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.55);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  overscroll-behavior: none;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
}

h1, h2, h3 { margin: 0; letter-spacing: -0.02em; font-weight: 650; }
p { margin: 0; }

#stage {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

#vignette {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(ellipse at 50% 42%, transparent 42%, rgba(0, 0, 0, 0.62) 100%);
}

/* ------------------------------------------------------------- примитивы */

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  padding: 11px 18px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: transform 0.12s ease, background 0.18s ease, border-color 0.18s ease, opacity 0.18s ease;
  touch-action: manipulation;
}
.btn:hover { background: rgba(255, 255, 255, 0.11); }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.42; cursor: not-allowed; }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.btn--primary {
  background: linear-gradient(135deg, var(--accent), #3aa9ff);
  border-color: transparent;
  color: #04131a;
  box-shadow: 0 8px 24px rgba(87, 230, 255, 0.24);
}
.btn--primary:hover { background: linear-gradient(135deg, #7ff0ff, #55b8ff); }

.btn--lg { padding: 15px 26px; font-size: 17px; width: 100%; }
.btn--ghost { background: transparent; }
.btn--icon {
  width: 42px; height: 42px; padding: 0;
  display: grid; place-items: center; font-size: 18px;
  border-radius: 12px;
}

.input {
  width: 100%;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.35);
  color: var(--text);
  font: inherit;
}
.input:focus { outline: none; border-color: var(--accent); }
.input::placeholder { color: #6b7488; }

.row { display: flex; gap: 10px; }
.row > * { flex: 1; }
.stack { display: grid; gap: 10px; }
.muted { color: var(--muted); font-size: 13px; }
.error { color: var(--bad); font-size: 13px; }
.hint { color: var(--muted); font-size: 13px; text-align: center; padding: 12px 20px 24px; }

.panel {
  background: var(--panel);
  backdrop-filter: blur(22px) saturate(1.3);
  -webkit-backdrop-filter: blur(22px) saturate(1.3);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 26px;
}

/* ---------------------------------------------------------------- экраны */

.screen {
  position: fixed;
  inset: 0;
  z-index: 10;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.screen[hidden] { display: none; }
.screen--center { display: grid; place-items: center; padding: 20px; }

.panel--hero { width: min(430px, 100%); display: grid; gap: 22px; }

.brand { text-align: center; display: grid; gap: 6px; }
.brand__logo { width: 56px; height: 56px; margin: 0 auto 2px; display: block; }
.icon { width: 20px; height: 20px; display: block; }
.brand__title {
  font-size: 40px;
  background: linear-gradient(120deg, #fff, var(--accent) 60%, var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.brand__sub { color: var(--muted); font-size: 14px; }

.identity { display: flex; gap: 10px; align-items: center; }
.avatar-btn {
  width: 52px; height: 52px; flex: none;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.06);
  font-size: 26px;
  cursor: pointer;
}
.input--name { height: 52px; }

.account-line { text-align: center; color: var(--muted); font-size: 13px; min-height: 18px; }

/* ---------------------------------------------------------------- topbar */

.topbar {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  padding-top: calc(14px + env(safe-area-inset-top, 0px));
  background: rgba(6, 8, 14, 0.9);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border-bottom: 1px solid var(--line);
}
.topbar h2 { flex: 1; font-size: 19px; }
.topbar .btn--primary { flex: none; }

/* ----------------------------------------------------------------- лобби */

.lobby-list {
  display: grid;
  gap: 12px;
  padding: 16px;
  max-width: 760px;
  margin: 0 auto;
  width: 100%;
}

.table-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--panel);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}
.table-card__main { flex: 1; min-width: 0; display: grid; gap: 6px; }
.table-card__name { font-weight: 650; display: flex; align-items: center; gap: 8px; }
.table-card__seats { display: flex; gap: 5px; flex-wrap: wrap; }

.seat {
  width: 30px; height: 30px;
  border-radius: 9px;
  display: grid; place-items: center;
  font-size: 15px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.3);
}
.seat--empty { opacity: 0.32; font-size: 11px; color: var(--muted); }
.seat--ready { border-color: var(--good); box-shadow: 0 0 0 1px rgba(85, 224, 138, 0.35) inset; }
.seat--off { opacity: 0.4; }

.badge {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
}
.badge--live { color: var(--warn); border-color: rgba(255, 190, 69, 0.4); }
.badge--open { color: var(--good); border-color: rgba(85, 224, 138, 0.4); }

/* --------------------------------------------------------- кастомизация */

.customize {
  display: grid;
  grid-template-columns: minmax(0, 300px) minmax(0, 1fr);
  gap: 20px;
  padding: 18px;
  max-width: 980px;
  margin: 0 auto;
  align-items: start;
}
@media (max-width: 720px) {
  .customize { grid-template-columns: 1fr; }
}

.preview {
  position: sticky;
  top: 86px;
  background: radial-gradient(circle at 50% 40%, rgba(87, 230, 255, 0.14), transparent 65%), var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  display: grid;
  gap: 8px;
  justify-items: center;
}
#ball-preview { width: 100%; aspect-ratio: 1; max-height: 260px; }
.preview__name { font-weight: 650; }

/* Подложка: без неё текст настроек читается поверх освещённой дорожки */
#screen-customize,
#screen-lobby {
  background: rgba(5, 6, 12, 0.74);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.options {
  display: grid;
  gap: 18px;
  padding: 18px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--panel);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}
.opt-group { display: grid; gap: 10px; }
.opt-group h3 { font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 9px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.05);
  cursor: pointer;
  font: inherit;
  color: var(--text);
  font-size: 14px;
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.12s ease;
}
.chip:active { transform: scale(0.96); }
.chip[aria-pressed='true'] {
  border-color: var(--accent);
  background: rgba(87, 230, 255, 0.16);
  box-shadow: 0 0 0 1px var(--accent) inset;
}

.chips--colors .chip {
  width: 40px; height: 40px;
  border-radius: 12px;
  padding: 0;
  position: relative;
}
.chips--avatars .chip { width: 44px; height: 44px; padding: 0; font-size: 21px; border-radius: 12px; }

/* ------------------------------------------------------------------ HUD */

#hud[hidden] { display: none; }
#hud {
  position: fixed;
  inset: 0;
  z-index: 8;
  pointer-events: none;
  display: flex;
  flex-direction: column;
}
#hud > * { pointer-events: auto; }

.hud__top {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  padding-top: calc(12px + env(safe-area-inset-top, 0px));
  background: linear-gradient(rgba(5, 6, 12, 0.92), transparent);
}
.hud__title { flex: 1; display: grid; line-height: 1.25; min-width: 0; }
.hud__title strong { font-size: 15px; }
.hud__title span { font-size: 12px; }

.hud__players {
  display: flex;
  gap: 8px;
  padding: 0 14px 8px;
  overflow-x: auto;
  scrollbar-width: none;
}
.hud__players::-webkit-scrollbar { display: none; }
.hud__players[hidden] { display: none; } /* display:flex иначе перебивает атрибут hidden */

.pchip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px 7px 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(12, 15, 24, 0.82);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  white-space: nowrap;
  font-size: 13px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.pchip__avatar { font-size: 17px; }
.pchip__score { font-weight: 700; font-variant-numeric: tabular-nums; }
.pchip--turn {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent) inset, 0 0 24px rgba(87, 230, 255, 0.28);
}
.pchip--ready .pchip__avatar { filter: drop-shadow(0 0 6px var(--good)); }
.pchip--off { opacity: 0.45; }

.turn-banner {
  align-self: center;
  margin-top: 4px;
  padding: 8px 18px;
  border-radius: 999px;
  background: rgba(12, 15, 24, 0.85);
  border: 1px solid var(--line);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  font-size: 13px;
  font-weight: 600;
}
.turn-banner[hidden] { display: none; }
.turn-banner b { color: var(--accent); }
.turn-banner__frame {
  margin-left: 8px;
  padding-left: 8px;
  border-left: 1px solid var(--line);
  color: var(--muted);
  font-weight: 500;
}

.announce {
  position: fixed;
  left: 50%;
  top: 38%;
  transform: translate(-50%, -50%);
  font-size: clamp(44px, 13vw, 104px);
  font-weight: 800;
  letter-spacing: -0.04em;
  text-align: center;
  pointer-events: none;
  background: linear-gradient(120deg, #fff, var(--accent) 55%, var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 6px 30px rgba(87, 230, 255, 0.4));
  animation: pop 0.5s cubic-bezier(0.2, 1.4, 0.4, 1);
}
.announce[hidden] { display: none; }
@keyframes pop {
  from { transform: translate(-50%, -50%) scale(0.5); opacity: 0; }
  to { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}

/* ------------------------------------------------------- панель лобби -- */

.lobby-panel {
  margin: auto;
  width: min(420px, calc(100% - 32px));
  text-align: center;
  display: grid;
  gap: 12px;
  padding: 24px;
  border-radius: var(--radius);
  background: var(--panel);
  backdrop-filter: blur(22px);
  -webkit-backdrop-filter: blur(22px);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}
.lobby-panel[hidden] { display: none; }
.ready-state { font-size: 13px; color: var(--muted); }
.ready-state b { color: var(--bad); }
.ready-state.is-ready b { color: var(--good); }

.countdown { font-size: 34px; font-weight: 800; color: var(--accent); font-variant-numeric: tabular-nums; }
.countdown[hidden] { display: none; }

/* -------------------------------------------------------------- контролы */

.controls {
  margin-top: auto;
  display: grid;
  gap: 12px;
  padding: 14px 16px calc(16px + var(--safe-b));
  background: linear-gradient(transparent, rgba(5, 6, 12, 0.9) 22%);
}
.controls[hidden] { display: none; }

.controls__sliders {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
}
@media (max-width: 560px) {
  .controls__sliders { grid-template-columns: 1fr; gap: 6px; }
}

.slider { display: grid; gap: 4px; }
.slider__label { font-size: 12px; color: var(--muted); display: flex; justify-content: space-between; }
.slider__label b { color: var(--text); font-variant-numeric: tabular-nums; }

input[type='range'] {
  appearance: none;
  width: 100%;
  height: 26px;
  background: transparent;
  cursor: pointer;
}
input[type='range']::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.16);
}
input[type='range']::-webkit-slider-thumb {
  appearance: none;
  width: 22px; height: 22px;
  margin-top: -8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 2px 10px rgba(87, 230, 255, 0.5);
}
input[type='range']::-moz-range-track { height: 6px; border-radius: 999px; background: rgba(255, 255, 255, 0.16); }
input[type='range']::-moz-range-thumb {
  width: 22px; height: 22px; border: none; border-radius: 50%;
  background: var(--accent); box-shadow: 0 2px 10px rgba(87, 230, 255, 0.5);
}

.power { display: grid; gap: 8px; max-width: 720px; width: 100%; margin: 0 auto; justify-items: center; }
.power__meter {
  width: 100%;
  height: 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  overflow: hidden;
  border: 1px solid var(--line);
}
.power__fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--good), var(--warn) 62%, var(--bad));
  transition: width 0.02s linear;
}
.power__hint { font-size: 12px; color: var(--muted); text-align: center; }

.btn--throw {
  width: 100%;
  padding: 18px;
  font-size: 17px;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent-2), #ff6a3d);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 10px 30px rgba(255, 47, 185, 0.3);
  user-select: none;
}
.btn--throw.is-charging { background: linear-gradient(135deg, #ff6a3d, var(--warn)); }

/* ------------------------------------------------------------- табло -- */

/* Табло всегда на виду сверху: в боулинге это главный источник информации. */
.scorecard {
  margin: 0 12px 8px;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 8px 10px;
  background: rgba(8, 10, 17, 0.88);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  scrollbar-width: thin;
}
.scorecard[hidden] { display: none; }
.scorecard.is-collapsed { display: none; }
.scorecard::-webkit-scrollbar { height: 4px; }
.scorecard::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.18); border-radius: 4px; }

.score-table { width: 100%; min-width: 560px; border-collapse: collapse; font-size: 12px; }
.score-table th, .score-table td {
  border: 1px solid var(--line);
  padding: 4px 3px;
  text-align: center;
}
.score-table th { color: var(--muted); font-weight: 600; }
.score-table .player-cell { text-align: left; white-space: nowrap; padding-left: 8px; font-weight: 600; }
.score-table .total-cell { font-weight: 800; font-size: 14px; }
.frame-rolls { display: flex; justify-content: center; gap: 2px; min-height: 15px; }
.frame-rolls span {
  width: 15px; height: 15px;
  display: grid; place-items: center;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.08);
  font-size: 11px; font-weight: 700;
}
.frame-rolls span.is-strike { background: rgba(87, 230, 255, 0.28); color: var(--accent); }
.frame-rolls span.is-spare { background: rgba(255, 190, 69, 0.25); color: var(--warn); }
.frame-score { font-variant-numeric: tabular-nums; font-weight: 600; }
.row--current { background: rgba(87, 230, 255, 0.08); }

/* --------------------------------------------------------------- чат -- */

/* Чат держим в верхней половине справа: снизу живут ползунки и кнопка броска,
   и любая привязка к низу рано или поздно налезает на них на узком экране. */
.chat {
  position: fixed;
  right: 12px;
  top: 30vh;
  width: min(280px, 60vw);
  display: grid;
  gap: 6px;
  z-index: 9;
}
@media (max-width: 560px) {
  .chat { top: 26vh; width: 54vw; }
  .chat__log { max-height: 18vh; }
}

.chat__log { display: grid; gap: 4px; max-height: 26vh; overflow-y: auto; scrollbar-width: none; }
.chat__log::-webkit-scrollbar { display: none; }
.chat__msg {
  font-size: 12px;
  background: rgba(10, 12, 20, 0.78);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 5px 9px;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  animation: fade 0.3s ease;
}
.chat__msg b { color: var(--accent); }
.chat__msg--sys { color: var(--muted); font-style: italic; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } }

.chat__form { display: flex; gap: 6px; }
.chat__form .input { font-size: 13px; padding: 8px 10px; }
.chat__form .btn { flex: none; width: 38px; height: 36px; }

/* ------------------------------------------------------------ оверлеи -- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(3, 4, 9, 0.72);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  overflow-y: auto;
}
.overlay[hidden] { display: none; }
.overlay .panel { width: min(440px, 100%); display: grid; gap: 16px; }

.standings { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.standings li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--line);
}
.standings li:first-child { border-color: rgba(255, 190, 69, 0.5); background: rgba(255, 190, 69, 0.1); }
.standings .place { width: 24px; color: var(--muted); font-weight: 700; }
.standings .who { flex: 1; font-weight: 600; }
.standings .pts { font-weight: 800; font-variant-numeric: tabular-nums; }
.standings .sub { color: var(--muted); font-size: 12px; font-weight: 400; }

#auth-form { display: grid; gap: 10px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + var(--safe-b));
  transform: translateX(-50%);
  z-index: 40;
  padding: 12px 20px;
  border-radius: 999px;
  background: rgba(14, 17, 27, 0.95);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  font-size: 14px;
  animation: fade 0.25s ease;
  max-width: calc(100% - 32px);
  text-align: center;
}
.toast[hidden] { display: none; }

.conn {
  position: fixed;
  top: calc(8px + env(safe-area-inset-top, 0px));
  left: 50%;
  transform: translateX(-50%);
  z-index: 41;
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: rgba(255, 92, 108, 0.16);
  border: 1px solid rgba(255, 92, 108, 0.4);
  color: var(--bad);
}
.conn[hidden] { display: none; }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
