:root {
  --bg: #eee8dc;
  --surface: #f8f3e9;
  --ink: #252821;
  --muted: #636458;
  --line: #bcb9aa;
  --accent: #c53625;
  --accent-dark: #9b291d;
  --sand: #ceb898;
  --display: "Oswald", sans-serif;
  --body: "Golos Text", sans-serif;
  --radius: 16px;
  --radius-lg: 26px;
}

*, *::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);
  background-image:
    linear-gradient(rgba(37, 40, 33, .035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(37, 40, 33, .035) 1px, transparent 1px);
  background-size: 44px 44px;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

.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;
}

.brand {
  text-decoration: none;
  color: var(--ink);
  font-family: var(--display);
  font-weight: 600;
  font-size: clamp(20px, 1.8vw, 28px);
  letter-spacing: -0.5px;
}
.brand__sup { font-size: .5em; vertical-align: super; color: var(--accent); }

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

.pill {
  font-size: 14px;
  padding: 7px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
}
.pill--pin b { font-family: var(--display); letter-spacing: 3px; color: var(--accent); }

.conn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--muted);
  padding: 7px 14px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
}
.conn__dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--line);
  box-shadow: 0 0 0 4px rgba(188, 185, 170, .3);
}
.conn[data-state="online"] { color: var(--ink); }
.conn[data-state="online"] .conn__dot { background: #3f8f45; box-shadow: 0 0 0 4px rgba(63, 143, 69, .22); }
.conn[data-state="loading"] .conn__dot { background: var(--sand); animation: pulse 1.2s infinite; }
.conn[data-state="offline"] .conn__dot { background: var(--accent); box-shadow: 0 0 0 4px rgba(197, 54, 37, .2); }

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

/* ---------- Игроки сверху ---------- */
.players-strip {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 16px;
  min-height: 84px;
}
.players-strip__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.section-label {
  font-family: var(--display);
  text-transform: uppercase;
  letter-spacing: 2px;
  font-size: 12px;
  color: var(--muted);
}
.players-strip__count { font-size: 13px; color: var(--muted); }
.players-strip__count b { color: var(--ink); font-size: 15px; }

.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: 7px 14px 7px 8px;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--line);
  font-size: 15px;
  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: 600;
  color: var(--accent-dark);
  margin-left: 2px;
}
.chip--answered { border-color: var(--accent); background: rgba(197, 54, 37, .07); }
.chip--ready .chip__avatar { background: #3f8f45; }
.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 { display: none; }
.chip__ready {
  width: 8px; height: 8px; border-radius: 50%;
  background: #3f8f45; margin-left: 2px;
}

/* ---------- Сцена ---------- */
.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="finished"] .view--finished { display: block; }

.eyebrow {
  font-family: var(--display);
  text-transform: uppercase;
  letter-spacing: 3px;
  font-size: 13px;
  color: var(--accent);
}

/* Лобби */
.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(--line);
  border-radius: var(--radius-lg);
  padding: clamp(24px, 4vw, 64px);
}
.quiz-title {
  font-family: var(--display);
  font-weight: 500;
  font-size: clamp(34px, 5vw, 76px);
  line-height: .98;
  letter-spacing: -1.5px;
  margin: 10px 0 8px;
}
.quiz-sub { color: var(--muted); font-size: clamp(15px, 1.4vw, 20px); }

.quiz-picker {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 14px;
  max-width: 420px;
}
.quiz-picker__label {
  font-family: var(--display);
  text-transform: uppercase;
  letter-spacing: 2px;
  font-size: 12px;
  color: var(--muted);
}
.quiz-picker select {
  font: inherit;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
}

.pin-block { margin-top: clamp(20px, 3vw, 40px); }
.pin-block__label {
  display: block;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: var(--muted);
  margin-bottom: 10px;
}
.pin {
  display: flex;
  gap: clamp(8px, 1vw, 16px);
}
.pin__digit {
  font-family: var(--display);
  font-weight: 600;
  font-size: clamp(38px, 6vw, 88px);
  line-height: 1;
  color: var(--ink);
  background: var(--bg);
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  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: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: clamp(14px, 1.6vw, 24px);
  text-align: center;
  box-shadow: 0 24px 50px -30px rgba(37, 40, 33, .55);
}
.qr { display: grid; place-items: center; }
.qr canvas, .qr img, .qr svg { display: block; width: clamp(180px, 20vw, 300px) !important; height: auto !important; }
.qr-card__caption { margin-top: 14px; font-family: var(--display); text-transform: uppercase; letter-spacing: 2px; font-size: 13px; color: var(--muted); }
.qr-card__caption b { color: var(--accent); letter-spacing: 3px; }

/* Вопрос */
.question {
  height: 100%;
  display: flex;
  flex-direction: column;
  gap: clamp(12px, 1.6vw, 24px);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: clamp(20px, 3vw, 48px);
}
.question__head { display: flex; align-items: center; justify-content: space-between; }
.timer {
  display: inline-flex;
  align-items: baseline;
  gap: 4px;
  font-family: var(--display);
  font-weight: 600;
  font-size: clamp(24px, 2.4vw, 40px);
  color: var(--ink);
  padding: 6px 18px;
  border-radius: 999px;
  border: 1.5px solid var(--line);
}
.timer--low { color: var(--accent); border-color: var(--accent); animation: pulse 1s infinite; }
.timer__unit { font-size: .5em; color: var(--muted); }
.question__text {
  font-family: var(--display);
  font-weight: 500;
  font-size: clamp(28px, 3.4vw, 58px);
  line-height: 1.05;
  letter-spacing: -1px;
}
.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-radius: var(--radius); 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: 1.5px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg);
  font-size: clamp(16px, 1.5vw, 22px);
}
.answers li .answers__key {
  font-family: var(--display);
  font-weight: 600;
  color: var(--accent);
  min-width: 1.2em;
}
.answers li.correct { border-color: #3f8f45; background: rgba(63, 143, 69, .12); }
.answered { color: var(--muted); font-size: clamp(14px, 1.2vw, 18px); }
.answered b { color: var(--ink); }

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

/* Финал */
.finished {
  height: 100%;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: clamp(24px, 4vw, 60px);
}
.finished__title { font-family: var(--display); font-weight: 500; font-size: clamp(30px, 4vw, 60px); margin: 8px 0 clamp(20px, 3vw, 40px); letter-spacing: -1px; }
.ranking { list-style: none; display: flex; flex-direction: column; gap: 10px; }
.ranking li {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: clamp(12px, 1.4vw, 20px) clamp(16px, 2vw, 28px);
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg);
  font-size: clamp(17px, 1.6vw, 24px);
}
.ranking li.winner { border-color: var(--accent); background: rgba(197, 54, 37, .08); }
.ranking__place { font-family: var(--display); font-weight: 600; font-size: 1.3em; color: var(--muted); min-width: 1.6em; }
.ranking li.winner .ranking__place { color: var(--accent); }
.ranking__score { margin-left: auto; font-family: var(--display); font-weight: 600; color: var(--accent-dark); }

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

.btn {
  font: inherit;
  font-weight: 600;
  color: #fff;
  background: var(--accent);
  border: 1.5px solid var(--accent);
  border-radius: 999px;
  padding: 14px 30px;
  cursor: pointer;
  transition: transform .12s ease, background .15s ease, opacity .15s ease;
}
.btn:hover:not(:disabled) { background: var(--accent-dark); border-color: var(--accent-dark); transform: translateY(-1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn--ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn--ghost:hover:not(:disabled) { background: var(--surface); border-color: var(--ink); }
.btn--copy { padding: 10px 22px; font-size: 14px; }

/* ---------- Оверлей / тост ---------- */
.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-radius: var(--radius-lg);
  padding: clamp(28px, 4vw, 56px);
  text-align: center;
  max-width: 460px;
}
.overlay__title { font-family: var(--display); font-size: clamp(24px, 3vw, 40px); 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;
  border-radius: 999px;
  font-size: 15px;
  opacity: 0;
  transition: opacity .2s ease, transform .2s ease;
  z-index: 60;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 900px) {
  body { overflow: auto; }
  .screen { height: auto; min-height: 100vh; }
  .lobby { grid-template-columns: 1fr; }
  .lobby__qr { order: -1; }
  .answers { grid-template-columns: 1fr; }
}
