: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;
  --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-x: hidden;
}

.screen {
  min-height: 100vh;
  max-width: 720px;
  margin: 0 auto;
  padding: clamp(14px, 3vw, 28px);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ---------- Верхняя панель ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

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

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

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

.conn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
  padding: 6px 12px;
  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: var(--ok); 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; } }

/* ---------- Сцена и экраны ---------- */
.stage { flex: 1; display: flex; }
.view { display: none; flex-direction: column; width: 100%; }

.screen[data-view="boot"] .view--boot,
.screen[data-view="pin"] .view--pin,
.screen[data-view="join"] .view--join,
.screen[data-view="waiting"] .view--waiting,
.screen[data-view="question"] .view--question,
.screen[data-view="results"] .view--results,
.screen[data-view="finished"] .view--finished,
.screen[data-view="dead"] .view--dead { display: flex; }

.panel {
  margin: auto;
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: clamp(20px, 5vw, 36px);
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.panel--narrow { max-width: 440px; }
.panel--center { align-items: center; text-align: center; }

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

.title {
  font-family: var(--display);
  font-weight: 500;
  font-size: clamp(28px, 7vw, 42px);
  line-height: 1.02;
  letter-spacing: -0.5px;
}
.title--sm { font-size: clamp(24px, 6vw, 34px); }

.sub { color: var(--muted); font-size: 15px; }

/* ---------- Формы ---------- */
.field { display: flex; flex-direction: column; gap: 8px; }
.field__label {
  font-family: var(--display);
  text-transform: uppercase;
  letter-spacing: 2px;
  font-size: 12px;
  color: var(--muted);
}
.hint { color: var(--muted); font-size: 13px; }

.input {
  font: inherit;
  color: inherit;
  background: var(--bg);
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 18px;
  width: 100%;
  outline: none;
  transition: border-color .15s ease;
}
.input:focus { border-color: var(--accent); }
.input--pin {
  font-family: var(--display);
  font-weight: 600;
  font-size: 26px;
  letter-spacing: 10px;
  text-indent: 10px;
  text-align: center;
  padding: 14px;
}

.pin-form { display: flex; flex-direction: column; gap: 12px; width: 100%; }

/* ---------- Кнопки ---------- */
.btn {
  font: inherit;
  font-weight: 600;
  color: #fff;
  background: var(--accent);
  border: 1.5px solid var(--accent);
  border-radius: 999px;
  padding: 15px 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--block { width: 100%; }

/* ---------- Аватары ---------- */
.avatar-grid {
  list-style: none;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(58px, 1fr));
  gap: 10px;
}
.avatar-pick {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 50%;
  border: 2px solid var(--line);
  background: var(--bg);
  padding: 4px;
  cursor: pointer;
  overflow: hidden;
  display: grid;
  place-items: center;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.avatar-pick img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; display: block; }
.avatar-pick--selected { border-color: var(--accent); box-shadow: 0 0 0 4px rgba(197, 54, 37, .16); }
.avatar-pick--fallback {
  font-family: var(--display);
  font-weight: 600;
  font-size: 18px;
  color: #fff;
}

/* ---------- Мой профиль ---------- */
.me { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.me__avatar {
  width: 88px; height: 88px;
  border-radius: 50%;
  overflow: hidden;
  display: grid;
  place-items: center;
  background: var(--accent);
  color: #fff;
  font-family: var(--display);
  font-weight: 600;
  font-size: 36px;
  border: 1.5px solid var(--line);
}
.me__avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.me__name { font-family: var(--display); font-weight: 500; font-size: 22px; }

.ready-progress {
  padding: 10px 20px;
  border: 1.5px solid var(--line);
  border-radius: 999px;
  background: var(--bg);
  color: var(--muted);
  font-size: 15px;
}
.ready-progress b { color: var(--ink); font-family: var(--display); }

/* ---------- Вопрос ---------- */
.question__head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

.timer {
  display: inline-flex;
  align-items: baseline;
  gap: 4px;
  font-family: var(--display);
  font-weight: 600;
  font-size: 24px;
  padding: 4px 16px;
  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(22px, 6vw, 34px);
  line-height: 1.1;
  letter-spacing: -0.5px;
}
.question__media { display: flex; justify-content: center; }
.question__image { max-width: 100%; max-height: 38vh; border-radius: var(--radius); object-fit: contain; }

.answers { list-style: none; display: flex; flex-direction: column; gap: 10px; }
.answers__opt {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  padding: 15px 18px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg);
  font: inherit;
  font-size: 16px;
  color: inherit;
  cursor: pointer;
  transition: border-color .15s ease, background .15s ease;
}
.answers__opt:hover { border-color: var(--ink); }
.answers__opt--selected { border-color: var(--accent); background: rgba(197, 54, 37, .08); }
.answers__key { font-family: var(--display); font-weight: 600; color: var(--accent); min-width: 1.2em; }

.answered-note {
  align-self: center;
  padding: 10px 22px;
  border-radius: 999px;
  border: 1.5px solid var(--ok);
  color: var(--ok);
  background: rgba(63, 143, 69, .1);
  font-weight: 600;
  text-align: center;
  word-break: break-word;
}

/* ---------- Результат вопроса ---------- */
.results__answer {
  font-family: var(--display);
  font-weight: 600;
  font-size: clamp(24px, 7vw, 36px);
  color: var(--ok);
  letter-spacing: -0.5px;
}
.verdict { font-family: var(--display); font-weight: 600; font-size: 26px; }
.verdict--ok { color: var(--ok); }
.verdict--bad { color: var(--accent); }
.score-line { color: var(--muted); font-size: 15px; }
.score-line b { color: var(--accent-dark); font-family: var(--display); font-size: 18px; }

/* ---------- Итоги ---------- */
.my-place {
  align-self: flex-start;
  padding: 10px 20px;
  border: 1.5px solid var(--accent);
  border-radius: 999px;
  background: rgba(197, 54, 37, .07);
  font-size: 15px;
}
.ranking { list-style: none; display: flex; flex-direction: column; gap: 10px; }
.ranking li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg);
  font-size: 16px;
}
.ranking li.winner { border-color: var(--accent); background: rgba(197, 54, 37, .08); }
.ranking li.me { border-color: var(--ok); }
.ranking__place { font-family: var(--display); font-weight: 600; font-size: 1.15em; color: var(--muted); min-width: 1.5em; }
.ranking__name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ranking__score { margin-left: auto; font-family: var(--display); font-weight: 600; color: var(--accent-dark); }

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

/* ---------- Оверлей / тост ---------- */
.overlay {
  position: fixed; inset: 0;
  background: rgba(37, 40, 33, .6);
  display: grid;
  place-items: center;
  z-index: 50;
  padding: 20px;
}
.overlay__card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: clamp(24px, 5vw, 44px);
  text-align: center;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: center;
}
.overlay__title { font-family: var(--display); font-size: 26px; }
.overlay__text { color: var(--muted); }

.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;
  max-width: calc(100vw - 40px);
  text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
