/* Оформление повторяет лендинг ezquizzy.ru: бумажный фон, прямые углы, тёмные рамки, заголовки Oswald */
:root {
  --bg: #eee8dc;
  --surface: #f8f3e9;
  --ink: #252821;
  --muted: #636458;
  --line: #bcb9aa;
  --accent: #c53625;
  --accent-dark: #9b291d;
  --sand: #ceb898;
  --ok: #3f8f45;
  --display: "Oswald", sans-serif;
  --body: "Golos Text", sans-serif;
  /* размер мелких подписей заглавными: растёт вместе с экраном */
  --label: clamp(12px, .95vw, 18px);
  /* итоговый размер QR при нехватке высоты уменьшает fitQr() в script.js */
  --qr-size: clamp(180px, 20vw, 300px);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  font-family: var(--body);
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

::selection { background: var(--accent); color: var(--surface); }

/* Фокус виден всегда: с пульта по нему ориентируются. Там, где браузер умеет, после клика мышью рамка не показывается */
a:focus, button:focus { outline: 4px solid var(--accent); outline-offset: 3px; }
a:focus:not(:focus-visible), button:focus:not(:focus-visible) { outline: none; }

.screen {
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  height: 100vh;
  padding: clamp(16px, 2.2vw, 34px);
  gap: clamp(12px, 1.6vw, 22px);
}

/* ---------- Верхняя панель ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: clamp(10px, 1.2vw, 18px);
  border-bottom: 1px solid var(--ink);
}

.brand {
  text-decoration: none;
  color: var(--ink);
  font-family: var(--display);
  font-weight: 600;
  font-size: clamp(24px, 2.2vw, 40px);
  line-height: 1;
  letter-spacing: -.04em;
  white-space: nowrap;
}
.brand__accent { color: var(--accent); }
.brand__sup {
  display: inline-block;
  margin: .1em 0 0 .12em;
  font: .28em var(--body);
  letter-spacing: 0;
  vertical-align: top;
}

.topbar__meta { display: flex; align-items: center; gap: 16px; }

.pill {
  font-size: var(--label);
  font-weight: 600;
  letter-spacing: .12em;
  text-transform: uppercase;
  padding: 5px 12px;
  border: 1px solid var(--ink);
  background: var(--surface);
}
.pill--pin b {
  margin-left: 4px;
  font-family: var(--display);
  font-weight: 500;
  font-size: 1.25em;
  color: var(--accent);
}
.pill--sound {
  font-family: inherit;
  color: var(--accent);
  border-color: var(--accent);
  cursor: pointer;
  transition: background .15s, color .15s;
}
.pill--sound:hover, .pill--sound:focus { background: var(--accent); color: var(--surface); }

.conn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: var(--label);
  font-weight: 600;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--muted);
}
.conn__dot {
  width: .75em; height: .75em; border-radius: 50%;
  background: var(--line);
}
.conn[data-state="online"] { color: var(--ink); }
.conn[data-state="online"] .conn__dot { background: var(--ok); }
.conn[data-state="loading"] .conn__dot { background: var(--sand); animation: pulse 1.2s infinite; }
.conn[data-state="offline"] .conn__dot { background: var(--accent); }

@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .35; } }

/* ---------- Игроки сверху ---------- */
.players-strip {
  padding-bottom: clamp(10px, 1.2vw, 18px);
  border-bottom: 1px solid var(--ink);
  min-height: 84px;
}
.players-strip__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.section-label {
  font-size: var(--label);
  font-weight: 600;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--muted);
}
.players-strip__count {
  font: 400 clamp(16px, 1.3vw, 24px)/1 var(--display);
  color: var(--muted);
}
.players-strip__count b { font-weight: 500; color: var(--accent); }

.players-strip__list {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.players-strip__empty { color: var(--muted); font-size: 14px; padding: 4px 0; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 5px 14px 5px 6px;
  background: var(--surface);
  border: 2px solid var(--line);
  font-size: 15px;
  font-weight: 500;
  max-width: 240px;
  animation: chip-in .28s ease both;
}
@keyframes chip-in { from { transform: translateY(-6px); opacity: 0; } to { transform: none; opacity: 1; } }

.chip__avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  display: grid; place-items: center;
  font-family: var(--display);
  font-weight: 600;
  font-size: 15px;
  color: #fff;
  background: var(--accent);
  flex: 0 0 auto;
  overflow: hidden;
}
.chip__avatar img {
  width: 100%; height: 100%;
  object-fit: cover;
  border-radius: 50%;
  display: block;
}
.chip__name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chip__score {
  font-family: var(--display);
  font-weight: 500;
  font-size: 1.1em;
  color: var(--accent);
  margin-left: 2px;
}
/* Ответивший игрок — как выбранная метка на лендинге */
.chip--answered { background: var(--ink); border-color: var(--ink); color: var(--surface); }
.chip--answered .chip__score { color: inherit; }
.chip--ready .chip__avatar { background: var(--ok); }
.chip--disconnected {
  opacity: .55;
  border-style: dashed;
}
.chip--disconnected .chip__name { text-decoration: line-through; }
.chip--disconnected .chip__avatar { filter: grayscale(1); }
.chip--disconnected .chip__ready { visibility: hidden; }
.chip__ready {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--ok); margin-left: 2px;
  visibility: hidden;
}
.chip--ready .chip__ready { visibility: visible; }

/* ---------- Сцена ---------- */
.stage {
  position: relative;
  min-height: 0;
  overflow: auto;
}
.view { display: none; height: 100%; }
.screen[data-status="waiting_players"] .view--lobby,
.screen[data-status="question"] .view--question,
.screen[data-status="waiting_answer"] .view--question,
.screen[data-status="results"] .view--results,
.screen[data-status="level_intro"] .view--level,
.screen[data-status="finished"] .view--finished { display: block; }

.eyebrow {
  font-size: var(--label);
  font-weight: 600;
  letter-spacing: .12em;
  text-transform: uppercase;
}

/* Лобби */
.lobby {
  display: grid;
  grid-template-columns: 1.2fr .8fr;
  gap: clamp(20px, 4vw, 60px);
  align-items: center;
  height: 100%;
  background: var(--surface);
  border: 1px solid var(--ink);
  padding: clamp(24px, 4vw, 64px);
}
.lobby__info { min-width: 0; }
.quiz-title {
  font-family: var(--display);
  font-weight: 500;
  font-size: clamp(34px, 5vw, 76px);
  line-height: 1;
  letter-spacing: -.03em;
  text-transform: uppercase;
  overflow-wrap: anywhere;
  margin: 10px 0 8px;
}
.quiz-sub { color: var(--muted); font-size: clamp(15px, 1.4vw, 20px); }

.pin-block { margin-top: clamp(20px, 3vw, 40px); }
.pin-block__label {
  display: block;
  font-size: var(--label);
  font-weight: 600;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 10px;
}
.pin {
  display: flex;
  gap: clamp(6px, .8vw, 12px);
}
.pin__digit {
  font-family: var(--display);
  font-weight: 500;
  font-size: clamp(38px, 6vw, 88px);
  line-height: 1;
  color: var(--surface);
  background: var(--ink);
  min-width: clamp(48px, 6vw, 96px);
  padding: clamp(10px, 1.2vw, 20px) 0;
  text-align: center;
}
.join-hint { margin-top: clamp(16px, 2vw, 28px); color: var(--muted); font-size: clamp(14px, 1.2vw, 18px); max-width: 34ch; }

.lobby__qr { display: flex; flex-direction: column; align-items: center; gap: 16px; }
.qr-card {
  background: #fff;
  border: 2px solid var(--ink);
  padding: clamp(14px, 1.6vw, 24px);
  text-align: center;
}
.qr { display: grid; place-items: center; }
.qr canvas, .qr img, .qr svg { display: block; width: var(--qr-size) !important; height: auto !important; }
.qr-card__caption {
  margin-top: 14px;
  font-size: var(--label);
  font-weight: 600;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--muted);
}
.qr-card__caption b { font: 500 1.25em var(--display); color: var(--accent); }

/* Вопрос */
.question {
  height: 100%;
  display: flex;
  flex-direction: column;
  gap: clamp(12px, 1.6vw, 24px);
  background: var(--surface);
  border: 1px solid var(--ink);
  padding: clamp(20px, 3vw, 48px);
}
.question__head { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.question__meta { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.question__level {
  font-family: var(--display);
  font-weight: 500;
  font-size: clamp(16px, 1.3vw, 24px);
  line-height: 1.15;
  text-transform: uppercase;
  color: var(--accent);
}
.timer {
  display: inline-flex;
  align-items: baseline;
  flex: none;
  gap: 4px;
  font-family: var(--display);
  font-weight: 500;
  font-size: clamp(24px, 2.4vw, 40px);
  line-height: 1.2;
  color: var(--surface);
  background: var(--ink);
  padding: 4px 18px;
}
.timer--low { background: var(--accent); animation: pulse 1s infinite; }
.timer__unit { font-size: .5em; opacity: .7; }
.question__text {
  font-family: var(--display);
  font-weight: 500;
  font-size: clamp(28px, 3.4vw, 58px);
  line-height: 1.08;
  letter-spacing: -.02em;
  overflow-wrap: anywhere;
}
.question__body {
  flex: 1;
  min-height: 0;
  display: flex;
  gap: clamp(16px, 2vw, 32px);
  align-items: stretch;
}
.question__content {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: clamp(12px, 1.6vw, 24px);
}
.question__media {
  flex: 0 1 clamp(220px, 32vw, 480px);
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: clamp(10px, 1.2vw, 18px);
}
.question__image { max-height: 40vh; max-width: 100%; border: 1px solid var(--ink); object-fit: contain; align-self: flex-start; }
.answers {
  list-style: none;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: clamp(8px, 1vw, 14px);
}
.answers li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: clamp(12px, 1.4vw, 20px) clamp(14px, 1.4vw, 22px);
  border: 2px solid var(--line);
  font-size: clamp(16px, 1.5vw, 22px);
  font-weight: 500;
}
.answers li .answers__key {
  font-family: var(--display);
  font-weight: 500;
  font-size: 1.15em;
  color: var(--accent);
  min-width: 1.2em;
}
.answers li.correct { border-color: var(--ok); background: var(--ok); color: #fff; }
.answers li.correct .answers__key { color: inherit; }
.answered {
  font-size: var(--label);
  font-weight: 600;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--muted);
}
.answered b { font: 500 1.35em var(--display); letter-spacing: 0; color: var(--accent); }

/* Результаты */
.results {
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: clamp(16px, 2vw, 32px);
  background: var(--surface);
  border: 1px solid var(--ink);
  padding: clamp(24px, 4vw, 64px);
  text-align: center;
}
.results__answer {
  font-family: var(--display);
  font-weight: 500;
  font-size: clamp(34px, 5vw, 72px);
  line-height: 1.05;
  color: var(--ok);
  letter-spacing: -.02em;
  overflow-wrap: anywhere;
}
.stats { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; }
.stat {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 20px;
  border: 2px solid var(--line);
  font-size: clamp(15px, 1.4vw, 20px);
}
.stat b { font-family: var(--display); font-weight: 500; }
.stat--correct { border-color: var(--ok); color: #2f6f34; }

/* Следующий уровень — тёмный блок, как призыв на лендинге */
.level-intro {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(12px, 2vw, 28px);
  padding: clamp(24px, 5vw, 80px);
  text-align: center;
  background: var(--ink);
  color: var(--bg);
}
.level-intro__label {
  font-size: clamp(14px, 1.6vw, 26px);
  font-weight: 600;
  letter-spacing: .12em;
  text-transform: uppercase;
  opacity: .7;
}
.level-intro__title {
  font-family: var(--display);
  font-weight: 500;
  font-size: clamp(40px, 7vw, 110px);
  line-height: 1;
  letter-spacing: -.03em;
  text-transform: uppercase;
  overflow-wrap: anywhere;
}
.level-intro__sub { opacity: .8; font-size: clamp(15px, 1.5vw, 22px); }

/* Финал */
.finished {
  height: 100%;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--ink);
  padding: clamp(24px, 4vw, 60px);
}
.finished__title {
  font-family: var(--display);
  font-weight: 500;
  font-size: clamp(30px, 4vw, 60px);
  line-height: 1.05;
  letter-spacing: -.02em;
  text-transform: uppercase;
  margin: 8px 0 clamp(20px, 3vw, 40px);
}
.ranking { list-style: none; border-top: 1px solid var(--ink); }
.ranking li {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: clamp(10px, 1.2vw, 18px) clamp(12px, 1.6vw, 24px);
  border-bottom: 1px solid var(--line);
  font-size: clamp(17px, 1.6vw, 24px);
  font-weight: 500;
}
.ranking li.winner { background: var(--accent); border-bottom-color: var(--accent); color: var(--surface); }
.ranking__place { font-family: var(--display); font-weight: 500; font-size: 1.3em; opacity: .55; min-width: 1.6em; }
.ranking li.winner .ranking__place { opacity: 1; }
.ranking__score { margin-left: auto; font-family: var(--display); font-weight: 500; font-size: 1.15em; color: var(--accent); white-space: nowrap; }
.ranking li.winner .ranking__score { color: inherit; }
.ranking .chip__avatar { width: 60px; height: 60px; font-size: 28px; }
/* Обводка, чтобы красный аватар без картинки не сливался с красной строкой */
.ranking li.winner .chip__avatar { box-shadow: 0 0 0 2px var(--surface); }

/* ---------- Управление ---------- */
.controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  flex-wrap: wrap;
}
.controls__hint { color: var(--muted); font-size: clamp(15px, 1.05vw, 20px); }
.controls__btns { display: flex; gap: 12px; flex-wrap: wrap; }

.btn {
  font: inherit;
  font-size: clamp(16px, 1.15vw, 22px);
  font-weight: 600;
  color: var(--surface);
  background: var(--accent);
  border: 2px solid var(--accent);
  border-radius: 0;
  padding: 13px 30px;
  cursor: pointer;
  transition: background .15s, border-color .15s, color .15s, opacity .15s;
}
.btn:hover:not(:disabled), .btn:focus:not(:disabled) { background: var(--accent-dark); border-color: var(--accent-dark); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn--ghost { background: none; color: var(--ink); border-color: var(--ink); }
.btn--ghost:hover:not(:disabled), .btn--ghost:focus:not(:disabled) { background: none; color: var(--accent); border-color: var(--accent); }
.btn--copy { padding: 9px 22px; font-size: clamp(14px, 1vw, 18px); }

/* ---------- Реакции игроков ---------- */
.reactions-layer {
  position: fixed; inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 40;
}
.reaction {
  position: absolute;
  bottom: 0;
  left: var(--x, 50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  animation: reaction-float 4.2s ease-out forwards;
}
.reaction__emoji { font-size: clamp(44px, 5vw, 80px); line-height: 1; }
.reaction__who {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 200px;
  padding: 3px 12px 3px 3px;
  border: 1px solid var(--ink);
  background: var(--surface);
  font-size: clamp(12px, 1.1vw, 16px);
  font-weight: 500;
}
.reaction__who .chip__avatar { width: 24px; height: 24px; font-size: 12px; }
.reaction__name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@keyframes reaction-float {
  0% { transform: translate(-50%, 0) scale(.6); opacity: 0; }
  10% { transform: translate(-50%, -8vh) scale(1); opacity: 1; }
  80% { opacity: 1; }
  100% { transform: translate(calc(-50% + var(--drift, 0px)), -75vh) scale(1); opacity: 0; }
}

/* ---------- Оверлей / тост ---------- */
.overlay {
  position: fixed; inset: 0;
  background: rgba(37, 40, 33, .6);
  display: grid; place-items: center;
  z-index: 50;
}
.overlay__card {
  background: var(--surface);
  border: 1px solid var(--ink);
  padding: clamp(28px, 4vw, 56px);
  text-align: center;
  max-width: 460px;
}
.overlay__title {
  font-family: var(--display);
  font-weight: 500;
  font-size: clamp(24px, 3vw, 40px);
  line-height: 1.1;
  text-transform: uppercase;
  margin-bottom: 10px;
}
.overlay__text { color: var(--muted); margin-bottom: 24px; }

.toast {
  position: fixed;
  bottom: 26px; left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--ink);
  color: var(--bg);
  padding: 14px 26px;
  font-size: 15px;
  font-weight: 500;
  opacity: 0;
  transition: opacity .2s ease, transform .2s ease;
  z-index: 60;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Низкий экран (например, ТВ 1920x1080 при масштабе 2.0 = 960x540 CSS-пикселей):
   сжимаем рамку, чтобы лобби с QR помещалось без прокрутки */
@media (min-width: 901px) and (max-height: 800px) {
  :root { --qr-size: clamp(140px, 100vh - 290px, 300px); }
  .screen { padding: 12px 16px; gap: 8px; }
  .topbar { padding-bottom: 8px; }
  .pill { padding: 3px 10px; }
  .players-strip { min-height: 0; padding-bottom: 8px; }
  .players-strip__head { margin-bottom: 6px; }
  .chip { padding: 3px 12px 3px 4px; }
  .chip__avatar { width: 26px; height: 26px; font-size: 13px; }
  .controls .btn { padding: 9px 24px; }
  .lobby { gap: 24px; padding: 16px 28px; }
  .quiz-title { font-size: clamp(28px, 8vh, 64px); }
  .pin-block { margin-top: 12px; }
  .pin-block__label { margin-bottom: 6px; }
  .pin__digit { font-size: clamp(30px, 9vh, 72px); min-width: clamp(38px, 8vh, 72px); padding: 6px 0; }
  .join-hint { margin-top: 10px; }
  .lobby__qr { gap: 8px; }
  .qr-card { padding: 12px; }
  .qr-card__caption { margin-top: 8px; }
  .btn--copy { padding: 5px 18px; }
}

@media (max-width: 900px) {
  body { overflow: auto; }
  .screen { height: auto; min-height: 100vh; grid-template-columns: minmax(0, 1fr); }
  .topbar, .topbar__meta { flex-wrap: wrap; }
  /* minmax(0, 1fr): колонка не растягивается по ширине PIN, иначе появляется горизонтальный скролл */
  .lobby { grid-template-columns: minmax(0, 1fr); }
  .lobby__qr { order: -1; }
  .pin__digit { flex: 0 1 clamp(48px, 6vw, 96px); min-width: 0; }
  .answers { grid-template-columns: 1fr; }
}
