/* ==========================================================================
   МИНИМАЛИСТИЧНАЯ ТЁМНАЯ ТЕМА + ГЕОМЕТРИЯ + КОМАНДНЫЙ ЦВЕТ (/play)
   Изменяйте оформление здесь, не затрагивая логику функциональных скриптов.
   ========================================================================== */

:root {
  --bg: #0b0e14;
  --bg-elevated: #111622;
  --card: #151b29;
  --surface-alt: #1a2234;
  --text: #eef2f7;
  --muted: #94a3b8;
  --border: rgba(148, 163, 184, 0.22);
  --border-strong: rgba(148, 163, 184, 0.42);
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --accent-soft: rgba(59, 130, 246, 0.16);
  --team-color: var(--accent);
  --team-on-color: #ffffff;
  --team-soft: rgba(59, 130, 246, 0.18);
  --team-glow: rgba(59, 130, 246, 0.28);
  --ok: #22c55e;
  --warn: #eab308;
  --danger: #ef4444;
  --danger-bg: rgba(239, 68, 68, 0.16);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --geo-line: rgba(148, 163, 184, 0.06);
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --font-sans: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  font-size: clamp(14px, 0.95vw, 17px);
  line-height: 1.5;
  overflow-x: hidden;
  min-height: 100vh;
}

a {
  color: #60a5fa;
}

/* Геометрический фон с мягкой анимацией */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background-image:
    linear-gradient(to right, var(--geo-line) 1px, transparent 1px),
    linear-gradient(to bottom, var(--geo-line) 1px, transparent 1px);
  background-size: 48px 48px;
  opacity: 0.85;
}

.geo-bg-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}

.geo-shape {
  position: absolute;
  border: 1px solid rgba(148, 163, 184, 0.16);
  will-change: transform;
}

.geo-shape--diamond {
  width: 240px;
  height: 240px;
  top: 7%;
  right: -55px;
  border-color: var(--team-soft);
  animation: geoSpinDiamond 26s linear infinite;
}

.geo-shape--ring {
  width: 185px;
  height: 185px;
  bottom: 9%;
  left: -45px;
  border-radius: 32px;
  animation: geoSpinRing 32s linear infinite reverse;
}

.geo-shape--tri {
  width: 140px;
  height: 140px;
  top: 48%;
  right: 6%;
  clip-path: polygon(50% 0%, 0% 100%, 100% 100%);
  background: rgba(148, 163, 184, 0.05);
  animation: geoDriftTri 18s ease-in-out infinite alternate;
}

@keyframes geoSpinDiamond {
  0% {
    transform: translate3d(0, 0, 0) rotate(45deg);
  }
  50% {
    transform: translate3d(-22px, 18px, 0) rotate(225deg);
  }
  100% {
    transform: translate3d(0, 0, 0) rotate(405deg);
  }
}

@keyframes geoSpinRing {
  0% {
    transform: translate3d(0, 0, 0) rotate(0deg);
  }
  50% {
    transform: translate3d(20px, -16px, 0) rotate(180deg);
  }
  100% {
    transform: translate3d(0, 0, 0) rotate(360deg);
  }
}

@keyframes geoDriftTri {
  0% {
    transform: translate3d(0, 0, 0) rotate(-12deg) scale(0.96);
  }
  100% {
    transform: translate3d(-18px, -24px, 0) rotate(16deg) scale(1.05);
  }
}

/* Поверх фоновой геометрии */
.container,
.wide-16x9 {
  position: relative;
  z-index: 1;
  width: 100%;
  margin: 0 auto;
  animation: pageEnter 0.36s var(--ease-out) both;
}

.container {
  max-width: 920px;
  padding: 16px;
}

.wide-16x9 {
  max-width: 1440px;
  min-height: 100vh;
  padding: 14px 18px;
  display: flex;
  flex-direction: column;
}

/* M7: динамическая высота мобильных браузеров.
   100vh оставлен фолбэком; 100dvh подключается только там, где поддержан. */
@supports (height: 100dvh) {
  html,
  body,
  .wide-16x9 {
    min-height: 100dvh;
  }
}

@keyframes pageEnter {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Карточки и панели */
.card,
.org-card-box {
  /* Плотный фон: полупрозрачность + blur давали мёртвый эффект и лишний GPU-
     слой, потому что поверх всё равно стоял непрозрачный --card. */
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px 18px;
  margin-bottom: 14px;
  color: var(--text);
  overflow-wrap: anywhere;
  word-break: break-word;
  transition: border-color 0.2s var(--ease-out), transform 0.2s var(--ease-out), box-shadow 0.2s var(--ease-out);
}

.card:hover,
.org-card-box:hover {
  border-color: var(--border-strong);
}

.muted {
  color: var(--muted);
}

/* Навигация и шапка */
.nav-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.nav-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.top-header {
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

/* Кнопки и состояния */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  padding: 9px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface-alt);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.25;
  text-decoration: none;
  cursor: pointer;
  max-width: 100%;
  overflow-wrap: anywhere;
  transition: transform 0.14s var(--ease-out), background-color 0.18s var(--ease-out), border-color 0.18s var(--ease-out), box-shadow 0.18s var(--ease-out);
}

.btn:hover {
  background: #243049;
  border-color: rgba(226, 232, 240, 0.45);
  transform: translateY(-1px);
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary,
.btn.active,
.btn.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

.btn-primary:hover,
.btn.active:hover,
.btn.is-active:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  color: #ffffff;
}

.btn-sm {
  min-height: 34px;
  padding: 6px 10px;
  font-size: 13px;
}

/* Квадратные кнопки действий с иконками карандаша и корзины */
.btn.btn-sm.icon-action-btn,
button.btn.btn-sm[data-action-icon] {
  width: 32px;
  height: 32px;
  min-width: 32px;
  min-height: 32px;
  max-width: 32px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  flex: 0 0 32px;
}

.btn.btn-sm.icon-action-btn svg,
button.btn.btn-sm[data-action-icon] svg {
  width: 15px;
  height: 15px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
}

.btn.btn-sm.icon-action-btn--delete:hover,
button.btn.btn-sm[data-action-icon="delete"]:hover {
  background: var(--danger-bg);
  background-color: var(--danger-bg);
  border-color: var(--danger);
  color: #fca5a5;
}

.btn.btn-sm.icon-action-btn--edit:hover,
button.btn.btn-sm[data-action-icon="edit"]:hover {
  background: var(--accent-soft);
  background-color: var(--accent-soft);
  border-color: var(--accent);
  color: #93c5fd;
}

input[type="file"] {
  display: inline-block;
  width: auto;
  max-width: 260px;
  max-width: min(260px, 100%);
  padding: 4px 8px;
  font-size: 12.5px;
  line-height: 1.25;
  color: var(--muted);
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  cursor: pointer;
}

input[type="file"]::file-selector-button {
  margin-right: 8px;
  padding: 4px 10px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.2;
  color: var(--text);
  background: var(--surface-alt);
  border: 1px solid var(--border-strong);
  border-radius: 5px;
  cursor: pointer;
  transition: background-color 0.16s var(--ease-out), border-color 0.16s var(--ease-out), color 0.16s var(--ease-out);
}

input[type="file"]::file-selector-button:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

/* Поля ввода */
input[type="text"],
input[type="password"],
input[type="number"],
input[type="email"],
input[type="url"],
select,
textarea {
  width: 100%;
  max-width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  color: var(--text);
  font-family: inherit;
  font-size: 15px;
  margin-top: 4px;
  transition: border-color 0.18s var(--ease-out), box-shadow 0.18s var(--ease-out);
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

label {
  display: block;
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 4px;
}

/* Сетки и таблицы */
.grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 12px;
}

.grid-2 > *,
.grid-16x9 > * {
  min-width: 0;
}

.grid-16x9 {
  display: grid;
  grid-template-columns: 1.15fr 0.85fr;
  gap: 16px;
  align-items: start;
}

@media (max-width: 960px) {
  .grid-16x9 {
    grid-template-columns: 1fr;
  }
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th, td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
  overflow-wrap: anywhere;
}

.schedule-row {
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.schedule-row:last-child {
  border-bottom: 0;
}

.q-media {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

/* Оверлей готовности к квизу оформляется в hub.html: у него своя палитра,
   safe-area-отступы и прокрутка. Дублировать его здесь нельзя — ID-селектор
   перебивал класс и центрировал карточку выше вьюпорта. */

/* Элементы команд и вариантов без белых фонов */
.team-line-item {
  background: var(--surface-alt);
  color: var(--text);
  border: 1px solid var(--border);
  border-left: 4px solid var(--team-color, var(--accent));
  border-radius: var(--radius-sm);
}

.option-tile {
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  transition: transform 0.16s var(--ease-out), border-color 0.18s var(--ease-out), background-color 0.18s var(--ease-out), box-shadow 0.18s var(--ease-out);
}

.option-tile:hover {
  border-color: var(--team-color, var(--accent));
  background: var(--surface-alt);
  transform: translateY(-1px);
}

.option-tile.selected,
.option-tile.active {
  border-color: var(--team-color, var(--accent));
  background: color-mix(in srgb, var(--team-color, var(--accent)) 22%, var(--surface-alt));
  box-shadow: 0 0 0 1px var(--team-color, var(--accent)), 0 8px 20px rgba(0, 0, 0, 0.35);
}

/* Цвет команды из палитры админа на /play.
   Флаг важности перекрывает инлайн-фон, который выставляет JS при выборе команды. */
body.play-team-theme,
body.play-team-theme[style] {
  background:
    radial-gradient(circle at 85% 12%, color-mix(in srgb, var(--team-color, var(--accent)) 28%, transparent), transparent 48%),
    radial-gradient(circle at 12% 88%, color-mix(in srgb, var(--team-color, var(--accent)) 20%, transparent), transparent 52%),
    var(--bg) !important;
  background-color: var(--bg) !important;
  transition: background 0.28s var(--ease-out);
}

body.play-team-theme .card,
body.play-team-theme .org-card-box {
  border-color: color-mix(in srgb, var(--team-color) 42%, transparent);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--team-color) 14%, transparent), 0 10px 28px rgba(0, 0, 0, 0.35);
}

body.play-team-theme .btn-primary {
  background: var(--team-color);
  border-color: var(--team-color);
  /* Цвет текста вычисляет JS (pickContrastText): на жёлтом/зелёном
     #ca8a04/#16a34a белый не проходит 4.5:1. */
  color: var(--team-on-color, #ffffff);
  box-shadow: 0 4px 16px var(--team-glow);
}

body.play-team-theme .btn-primary:hover {
  filter: brightness(1.08);
  background: var(--team-color);
  border-color: var(--team-color);
}

/* Базовые стили /play */
/* M7 + safe-area: body страницы участника и отступы контейнера.
   На /play viewport-fit=cover нет, поэтому env(...) там обычно равен 0;
   правила безопасны и не меняют вид на устройствах без вырезов. */
body.play-page {
  min-height: 100vh;
}

@supports (height: 100dvh) {
  body.play-page {
    min-height: 100dvh;
  }
}

body.play-page .container {
  --play-safe-pad: 16px;
  padding:
    calc(var(--play-safe-pad) + env(safe-area-inset-top))
    calc(var(--play-safe-pad) + env(safe-area-inset-right))
    calc(var(--play-safe-pad) + env(safe-area-inset-bottom))
    calc(var(--play-safe-pad) + env(safe-area-inset-left));
}

@media (max-width: 640px) {
  body.play-page .container {
    --play-safe-pad: 12px;
  }
}

.play-field {
  width: 100%;
  max-width: 360px;
  padding: 8px 10px;
  margin-top: 4px;
  border-radius: 8px;
}

#open-answer-input {
  max-width: 440px;
  margin-top: 6px;
}

.join-role-btns {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 12px;
}

/* Сводка комнаты на /play: не один длинный <p> с разделителями */
.room-summary {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 14px;
  margin: 0 0 10px;
}

.room-summary > span {
  min-width: 0;
  overflow-wrap: anywhere;
}

@media (max-width: 560px) {
  .room-summary {
    flex-direction: column;
    gap: 3px;
  }
}

/* Строки форм «Я организатор»: перенос на узких экранах */
.org-inline-form {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: flex-start;
}

.org-inline-form > input[type="text"],
.org-inline-form > input[type="file"] {
  flex: 1 1 220px;
  min-width: 0;
  margin-top: 0;
}

.org-inline-form > .btn {
  flex: 0 0 auto;
}

.org-link-row {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
}

.org-link-row a {
  min-width: 0;
  max-width: 100%;
  overflow-wrap: anywhere;
  word-break: break-word;
}

/* Таймер */
.quiz-timer-box {
  display: none;
  flex-direction: column;
  gap: 6px;
  margin: 8px 0 14px;
  width: 100%;
}

.quiz-timer-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  font-size: clamp(18px, 2.2vw, 28px);
  font-weight: 800;
  line-height: 1.2;
}

.quiz-timer-track {
  position: relative;
  width: 100%;
  height: 26px;
  border-radius: var(--radius-sm);
  background: rgba(148, 163, 184, 0.16);
  border: 1px solid var(--border);
  overflow: hidden;
  display: flex;
  align-items: center;
}

.quiz-timer-fill {
  height: 100%;
  width: 100%;
  background: var(--ok);
  transition: width 0.25s linear, background-color 0.25s linear;
}

.quiz-timer-expired-label {
  display: none;
  position: relative;
  z-index: 2;
  width: 100%;
  text-align: center;
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0.03em;
  color: #fca5a5;
  text-transform: uppercase;
}

.quiz-timer-track.is-expired {
  background: var(--danger-bg);
  border-color: var(--danger);
}

.quiz-timer-track.is-expired .quiz-timer-fill {
  display: none;
  /* ширину задаёт JS инлайн-стилем — флаг важности сбрасывает её при истечении */
  width: 0% !important;
}

.quiz-timer-track.is-expired .quiz-timer-expired-label {
  display: block;
}

.podium-col {
  flex: 1 1 140px;
  min-width: 130px;
  max-width: 260px;
  overflow-wrap: anywhere;
}

/* Трансляция и объявление без белых полей */
body[class*="broadcast"],
body[data-page*="broadcast"] {
  background-color: var(--bg) !important;
  color: var(--text) !important;
}

button,
.btn {
  color: var(--text);
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

@media (max-width: 640px) {
  .container,
  .wide-16x9 {
    padding: 12px;
  }
  .card,
  .org-card-box {
    padding: 14px;
  }
  .join-role-btns .btn {
    flex: 1 1 140px;
  }
}

/* ==========================================================================
   КОМПАКТНЫЙ INPUT[TYPE="FILE"] ВНУТРИ .ORG-CARD-BOX БЕЗ ВЫХОДА ЗА РАМКУ
   ========================================================================== */

.org-card-box,
.org-card-box > div,
.org-card-box form {
  min-width: 0 !important;
  max-width: 100% !important;
  overflow: visible;
}

.org-card-box input[type="file"],
.org-card-box input[type="file"][name="photo_file"] {
  flex: 1 1 auto !important;
  min-width: 0 !important;
  max-width: 100% !important;
  width: auto !important;
  font-size: 11px !important;
  line-height: 1.25 !important;
  color: var(--muted) !important;
  overflow: visible;
  text-overflow: ellipsis !important;
}

.org-card-box input[type="file"]::file-selector-button {
  font-size: 12px !important;
  line-height: 1.2 !important;
  padding: 4px 9px !important;
  margin-right: 6px !important;
  flex-shrink: 0 !important;
}

/* ==========================================================================
   МГНОВЕННЫЙ ЦВЕТ ВЫБРАННОЙ КОМАНДЫ НА /PLAY ДО ВЫБОРА РОЛИ И ВХОДА
   Флаг важности нужен: инлайн-стиль команды/переключателя перекрывает базовый фон.
   ========================================================================== */

body.play-team-theme,
body.play-team-theme[style] {
  background:
    radial-gradient(circle at 82% 14%, color-mix(in srgb, var(--team-color, var(--accent)) 34%, transparent), transparent 52%),
    radial-gradient(circle at 15% 86%, color-mix(in srgb, var(--team-color, var(--accent)) 26%, transparent), transparent 56%),
    var(--bg, #0b0e14);
  background-color: var(--bg, #0b0e14);
  transition: background 0.25s var(--ease-out, ease), border-color 0.25s var(--ease-out, ease);
}

body.play-team-theme #join-section,
body.play-team-theme #join-section.card {
  border-color: color-mix(in srgb, var(--team-color, var(--accent)) 60%, transparent);
  background:
    linear-gradient(145deg, color-mix(in srgb, var(--team-color, var(--accent)) 16%, var(--card, #151b29)), var(--card, #151b29) 75%);
  box-shadow:
    0 14px 34px rgba(0, 0, 0, 0.45),
    0 0 0 1px color-mix(in srgb, var(--team-color, var(--accent)) 28%, transparent);
}

body.play-team-theme #join-section select,
body.play-team-theme #join-section input[type="text"] {
  border-color: color-mix(in srgb, var(--team-color, var(--accent)) 55%, var(--border-strong, rgba(148, 163, 184, 0.42)));
}

body.play-team-theme #join-section .btn-primary,
body.play-team-theme #join-btn.btn-primary {
  background: var(--team-color, var(--accent));
  border-color: var(--team-color, var(--accent));
  color: var(--team-on-color, #ffffff);
}

/* ==========================================================================
   ОКАНТОВКА ШКАЛЫ .team-progress-track
   ========================================================================== */
.team-progress-track {
  border: 1.5px solid var(--border-strong, rgba(148, 163, 184, 0.45));
  box-sizing: border-box;
}
.team-progress-fill {
  border-right: 1px solid rgba(255, 255, 255, 0.22);
}

/* FIX-OVERFLOW-GUARD / FULL-AUDIT-FIX */
.org-card-box,
.org-photo-row,
.table-wrap,
.card,
.join-role-btns,
.nav-bar,
.nav-links {
  min-width: 0;
}

input[type="file"] {
  min-width: 0;
}

.team-line-name,
.option-tile {
  min-width: 0;
  overflow-wrap: anywhere;
}

/* Выравнивание полей в блоке корректировки (#p-edit) */
#p-edit .edit-fields-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(220px, 1fr));
  gap: 12px 14px;
  align-items: stretch;
}
#p-edit .edit-fields-grid > label {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 6px;
  min-width: 0;
}
#p-edit .edit-fields-grid > label > input,
#p-edit .edit-fields-grid > label > select {
  margin-top: 0;
}
@media (max-width: 900px) {
  #p-edit .edit-fields-grid {
    grid-template-columns: repeat(2, minmax(200px, 1fr));
  }
}
@media (max-width: 600px) {
  #p-edit .edit-fields-grid {
    grid-template-columns: 1fr;
  }
}
/* === Анти-мерцание на странице куратора и экранах квиза === */
#room-section,
#question-box,
#join-section,
.container,
.card {
  animation: none !important;
  opacity: 1 !important;
  transform: none !important;
}
#curator-change-banner {
  display: none;
  margin: 10px 0 12px;
  padding: 11px 14px;
  border-radius: 10px;
  border: 1px solid #22c55e !important;
  background: rgba(22, 163, 74, 0.22) !important;
  color: #dcfce7 !important;
  font-weight: 700;
}
/* === Новая страница куратора (#play) === */
.curator-choice-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 12px 0;
}

.curator-opt-card {
  position: relative;
  overflow: hidden;
  border-radius: 12px;
  border: 2px solid rgba(148, 163, 184, 0.28);
  background: #131b2e;
  transition: border-color 0.22s ease, box-shadow 0.22s ease, transform 0.16s ease, background-color 0.22s ease;
}

.curator-opt-bar {
  position: absolute;
  inset: 0 auto 0 0;
  width: var(--vote-pct, 0%);
  background: linear-gradient(90deg, rgba(59, 130, 246, 0.22), rgba(59, 130, 246, 0.10));
  pointer-events: none;
  transition: width 0.25s ease;
  z-index: 0;
}

.curator-opt-btn {
  position: relative;
  z-index: 1;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 13px 16px;
  background: transparent;
  border: 0;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  font-size: 15px;
}

.curator-opt-btn > span:first-child {
  flex: 1 1 auto;
  min-width: 0;
  overflow-wrap: break-word;
}

.curator-opt-btn > span:last-child {
  flex: 0 0 auto;
  white-space: nowrap;
}

.curator-opt-btn:disabled {
  cursor: default;
}

/* Флаг важности: класс-состояние ставит JS поверх базовых border/background. */
.curator-opt-card.is-submitted {
  border-color: #22c55e !important;
  background: rgba(22, 163, 74, 0.22) !important;
  box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.55), 0 10px 26px rgba(22, 163, 74, 0.28) !important;
}

.curator-submitted-badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  background: #22c55e;
  color: #052e16;
  margin-left: 8px;
  white-space: nowrap;
}

#curator-top-toast {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translate(-50%, -16px);
  z-index: 99999;
  max-width: min(92vw, 540px);
  padding: 14px 20px;
  border-radius: 14px;
  background: #16a34a;
  color: #ffffff;
  font-weight: 800;
  font-size: 15px;
  line-height: 1.35;
  box-shadow: 0 18px 42px rgba(0, 0, 0, 0.55);
  border: 2px solid #bbf7d0;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s ease, transform 0.22s ease;
}

#curator-top-toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}
/* Лёгкая обводка выбранного варианта участника (восстанавливается из sessionStorage).
   Флаг важности: класс восстанавливает JS поверх базового border. */
.quiz-my-vote-selected {
  outline: 2px solid color-mix(in srgb, var(--team-color, var(--accent)) 72%, transparent);
  outline-offset: 2px;
  border-color: color-mix(in srgb, var(--team-color, var(--accent)) 78%, transparent) !important;
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--team-color, var(--accent)) 16%, transparent);
}

/* === VERDICT FLASH & CORRECT ANSWER HIGHLIGHT === */
.screen-verdict-flash {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9990;
  opacity: 0;
  will-change: opacity, box-shadow;
}

.screen-verdict-flash.is-correct {
  background: radial-gradient(
    circle at 50% 45%,
    rgba(34, 197, 94, 0.14) 0%,
    rgba(34, 197, 94, 0.28) 68%,
    rgba(22, 163, 74, 0.44) 100%
  );
  box-shadow: inset 0 0 110px rgba(34, 197, 94, 0.58);
  animation: verdictPulseFlash 2.6s ease-in-out 2 forwards;
}

.screen-verdict-flash.is-wrong {
  background: radial-gradient(
    circle at 50% 45%,
    rgba(239, 68, 68, 0.14) 0%,
    rgba(239, 68, 68, 0.28) 68%,
    rgba(220, 38, 38, 0.46) 100%
  );
  box-shadow: inset 0 0 110px rgba(239, 68, 68, 0.62);
  animation: verdictPulseFlash 2.6s ease-in-out 2 forwards;
}

@keyframes verdictPulseFlash {
  0%   { opacity: 0; }
  25%  { opacity: 0.95; }
  50%  { opacity: 0.35; }
  75%  { opacity: 0.9; }
  100% { opacity: 0; }
}

/* Подсветка правильного варианта ответа.
   Флаг важности: класс-состояние ставит JS поверх базовых border/background. */
.option-tile.option-correct,
.curator-opt-card.is-correct-answer {
  border-color: #22c55e !important;
  background: rgba(34, 197, 94, 0.22) !important;
  box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.65), 0 10px 24px rgba(34, 197, 94, 0.25) !important;
  color: var(--text);
  font-weight: 700;
}

.curator-correct-badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  background: #22c55e;
  color: #052e16;
  margin-left: 8px;
  white-space: nowrap;
}

/* === OPEN QUESTION PARTICIPANT MINIMAL & REVEAL PULSE === */
.open-curator-only-note {
  margin: 14px 0;
  padding: 14px 16px;
  border-radius: 12px;
  border: 1px solid rgba(96, 165, 250, 0.45);
  background: rgba(59, 130, 246, 0.12);
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}

.reveal-answer-callout {
  display: none;
  width: 100%;
  max-width: 100%;
  margin: 16px 0;
  padding: 18px 22px;
  border-radius: 14px;
  border: 2px solid var(--ok);
  background: linear-gradient(
    135deg,
    color-mix(in srgb, var(--ok) 26%, var(--surface-alt)),
    color-mix(in srgb, var(--ok) 14%, var(--surface-alt))
  );
  color: var(--text);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--ok) 35%, transparent), 0 14px 34px rgba(22, 163, 74, 0.28);
  overflow: hidden;
  white-space: nowrap;
}

.reveal-answer-callout.is-active {
  display: block;
  animation: revealAnswerPulse 1.55s ease-in-out infinite;
}

/* Строка «Правильный ответ» на экране игрока: раньше JS красил её жёстким
   светло-зелёным, и на светлых темах текст почти исчезал. */
#correct-opt-row.is-revealed {
  color: var(--text);
  background: color-mix(in srgb, var(--ok) 14%, var(--surface-alt));
  border-left: 3px solid var(--ok);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
}

.reveal-answer-callout__inner {
  display: inline-block;
  white-space: nowrap;
  font-size: clamp(24px, 5.2vw, 44px);
  font-weight: 900;
  line-height: 1.15;
  letter-spacing: -0.01em;
  transform-origin: left center;
}

@keyframes revealAnswerPulse {
  0%, 100% {
    transform: scale(1);
    box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.35), 0 12px 28px rgba(22, 163, 74, 0.25);
  }
  50% {
    transform: scale(1.025);
    box-shadow: 0 0 0 5px rgba(34, 197, 94, 0.55), 0 18px 42px rgba(34, 197, 94, 0.48);
  }
}

/* ==========================================================================
   ИСПРАВЛЕНИЯ ВЁРСТКИ (блок C)
   1) Светлые плашки светлой темы на тёмном фоне: текст читался с контрастом
      1.05:1 (чипы команд, «Правильный ответ», пьедестал, бейдж баллов).
   2) Карточки команд в лобби табло сжимались до 44px: встроенный
      min-width: 0 перебивал min-width: 150px, и полоса не прокручивалась.
   3) Имя команды в пульте красилось цветом из конфига (#4b5563 — 2.25:1).
   ========================================================================== */

/* --- 1. Контраст: элементы, которые раньше оставались от светлой темы --- */
.option-correct {
  border-color: var(--ok);
  background: color-mix(in srgb, var(--ok) 16%, var(--surface-alt));
  color: var(--text);
}

.team-chip {
  background: var(--surface-alt);
  color: var(--text);
}

.team-chip-voted {
  background: color-mix(in srgb, var(--accent) 24%, var(--surface-alt));
  color: var(--text);
}

.team-chip-win {
  border-color: var(--ok);
  background: color-mix(in srgb, var(--ok) 20%, var(--surface-alt));
  color: var(--text);
  font-weight: 700;
}

.podium-col,
.step-hero {
  background: var(--surface-alt);
}

.qr-action-link {
  background: var(--card);
  color: var(--text);
}

/* --- 2. Полоса команд в лобби табло: карточки не сжимаются до нуля --- */
.teams-bottom-line .team-line-item {
  min-width: 150px;
}

.team-line-name {
  min-width: 0;
  white-space: nowrap;
}

/* --- 3. Имя команды в пульте: цвет команды точкой, текст контрастный --- */
.ctrl-team-name-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.ctrl-team-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex: 0 0 auto;
}

.ctrl-team-name {
  color: var(--text);
  overflow-wrap: anywhere;
}

/* --- 4. Шапка вопроса на табло: таймер шириной 100% сжимал счётчик --- */
.q-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.q-head-counter {
  font-size: 19px;
  font-weight: 700;
  white-space: nowrap;
}

#qt-box-bcast {
  flex: 1 1 320px;
  width: auto;
  max-width: 520px;
  min-width: 200px;
  margin: 0;
}

/* --- 5. Подпись таймера: число и «сек.» разъезжались по краям полосы --- */
.quiz-timer-header {
  justify-content: flex-start;
  gap: 6px;
}

/* --- 6. Цветовые поля в админке: были узкие и не в стиле остальных полей --- */
input[type="color"] {
  width: 100%;
  max-width: 100%;
  height: 42px;
  padding: 4px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  cursor: pointer;
}

/* M-стабильные рамки: 0.5px на DPR 3–4 браузеры квантуют по-разному
   (где-то линия исчезает, где-то двоится). Держим честный 1px CSS на всех
   плотностях — толщина предсказуема, а не «плавает» между устройствами. */
@media (min-resolution: 3dppx) {
  .card,
  .org-card-box,
  .top-header,
  .btn,
  .q-media,
  .option-tile,
  .quiz-timer-track,
  .open-curator-only-note {
    border-width: 1px;
  }

  .team-line-item {
    border-width: 1px 1px 1px 4px;
  }
}

input[type="color"]::-webkit-color-swatch-wrapper {
  padding: 0;
}

input[type="color"]::-webkit-color-swatch {
  border: 0;
  border-radius: 4px;
}

/* ==========================================================================
   /play: медиа вопроса, локальный таймер, компактный портрет и ландшафт
   ========================================================================== */
#question-box {
  display: none;
  grid-template-columns: minmax(0, 1fr);
}

.play-q-head,
.play-q-body {
  min-width: 0;
}

.play-media {
  margin: 8px 0 12px;
}

.play-media-figure {
  margin: 0;
}

.play-question-image {
  display: block;
  width: auto;
  max-width: 100%;
  max-height: clamp(150px, 28vh, 280px);
  height: auto;
  object-fit: contain;
  margin: 0 auto;
  border-radius: 10px;
  background: var(--surface-alt);
}

.play-media-figure figcaption {
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.3;
  text-align: center;
}

.play-audio-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.play-audio-row audio {
  flex: 1 1 220px;
  min-width: 0;
  max-width: 100%;
  height: 40px;
}

.play-audio-btn {
  min-height: 40px;
  white-space: nowrap;
}

.play-media-note {
  flex: 1 1 100%;
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.3;
}

/* Индикатор обрыва связи: таймер продолжает идти локально, но честно
   предупреждаем, что ответ может не дойти до сервера. */
.connection-status {
  position: fixed;
  top: calc(8px + env(safe-area-inset-top));
  left: 50%;
  z-index: 80;
  transform: translateX(-50%);
  max-width: calc(100vw - 24px);
  padding: 9px 14px;
  border-radius: 999px;
  border: 1px solid #f59e0b;
  background: #451a03;
  color: #fef3c7;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.25;
  text-align: center;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

@media (max-width: 430px) {
  body.play-page .container {
    --play-safe-pad: 10px;
  }
  body.play-page #room-section.card {
    padding: 12px;
  }
  body.play-page .room-summary {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 2px 8px;
    font-size: 12px;
    margin-bottom: 6px;
  }
  body.play-page #q-title {
    font-size: 18px;
    margin: 4px 0;
  }
  body.play-page #q-text {
    font-size: 15px;
    margin: 4px 0 6px;
  }
  body.play-page .play-media {
    margin: 4px 0 6px;
  }
  body.play-page .play-question-image {
    max-height: 140px;
  }
  body.play-page .play-audio-row {
    flex-wrap: nowrap;
    gap: 6px;
  }
  body.play-page .play-audio-row audio {
    flex: 1 1 auto;
    width: 0;
    height: 36px;
  }
  body.play-page .play-audio-btn {
    min-height: 36px;
    padding: 6px 9px;
    font-size: 12px;
  }
  body.play-page #member-choice-list {
    gap: 6px;
  }
  body.play-page .quiz-timer-box {
    margin: 4px 0 8px;
  }
  body.play-page .quiz-timer-header {
    font-size: 18px;
    line-height: 1.15;
  }
  body.play-page .quiz-timer-track {
    height: 20px;
  }
  body.play-page .curator-choice-list {
    gap: 6px;
    margin: 8px 0;
  }
  body.play-page .curator-opt-btn {
    padding: 8px 10px;
    font-size: 14px;
    gap: 6px;
  }
  body.play-page #question-extra-meta {
    font-size: 13px;
    line-height: 1.35;
  }
  body.play-page #question-extra-meta p {
    margin: 2px 0;
  }
  body.play-page #team-members-block h3 {
    font-size: 16px;
    margin: 6px 0;
  }
}

/* Ландшафтный телефон: вопрос и таймер слева, варианты справа. */
@media (orientation: landscape) and (max-height: 500px) {
  body.play-page .container {
    max-width: none;
    --play-safe-pad: 6px;
    padding:
      calc(var(--play-safe-pad) + env(safe-area-inset-top))
      calc(var(--play-safe-pad) + env(safe-area-inset-right))
      calc(var(--play-safe-pad) + env(safe-area-inset-bottom))
      calc(var(--play-safe-pad) + env(safe-area-inset-left));
  }
  body.play-page #room-section.card {
    padding: 8px 10px;
    margin-bottom: 0;
  }
  body.play-page .room-summary {
    gap: 2px 10px;
    margin-bottom: 4px;
    font-size: 12px;
    line-height: 1.25;
  }
  body.play-page #question-box {
    grid-template-columns: minmax(0, 0.92fr) minmax(0, 1.08fr);
    grid-template-areas: "head body";
    gap: 0 12px;
    align-items: start;
  }
  body.play-page .play-q-head {
    grid-area: head;
  }
  body.play-page .play-q-body {
    grid-area: body;
  }
  body.play-page #qt-box-play {
    position: sticky;
    top: calc(env(safe-area-inset-top) + 4px);
    z-index: 8;
    margin: 0 0 4px;
    padding: 4px 0;
    background: var(--card);
  }
  body.play-page .quiz-timer-header {
    font-size: 18px;
    line-height: 1.1;
  }
  body.play-page .quiz-timer-track {
    height: 16px;
  }
  body.play-page #q-title {
    margin: 2px 0 3px;
    font-size: 16px;
    line-height: 1.2;
  }
  body.play-page #q-text {
    margin: 0 0 4px;
    font-size: 14px;
    line-height: 1.25;
  }
  body.play-page .play-media {
    margin: 4px 0;
  }
  body.play-page .play-question-image {
    /* В альбомной ориентации фото не должно уводить аудио и варианты
       ниже экрана: 852×393 и 915×412 — самые тесные сценарии. */
    max-height: clamp(64px, calc(100vh - 315px), 140px);
    max-height: clamp(64px, calc(100dvh - 315px), 140px);
  }
  body.play-page .play-media-figure figcaption {
    font-size: 11px;
    margin-top: 2px;
  }
  body.play-page .curator-choice-list {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
    margin: 0;
  }
  body.play-page .curator-opt-btn {
    padding: 8px 9px;
    font-size: 13px;
    line-height: 1.2;
    gap: 6px;
  }
  body.play-page #become-curator-wrap,
  body.play-page #curator-hint {
    margin-bottom: 4px;
    padding: 6px 8px;
    font-size: 11px;
    line-height: 1.25;
  }
  body.play-page #open-answer-block {
    margin: 0;
  }
  body.play-page #question-extra-meta {
    margin-top: 4px;
    font-size: 12px;
    line-height: 1.3;
  }
  body.play-page #question-extra-meta p {
    margin: 1px 0;
  }
  body.play-page #member-vote-line,
  body.play-page #leading-opt-line {
    display: none !important;
  }
  body.play-page #team-members-block {
    display: none !important;
  }
  body.play-page #play-error-line {
    margin: 2px 0;
    font-size: 12px;
  }
  body.play-page .reveal-answer-callout {
    margin-top: 4px;
  }
}

/* --- Телефон: таблица команд пульта превращается в карточки, а не в
   горизонтальную прокрутку на 720px. --- */
@media (max-width: 640px) {
  #rt-teams .table-wrap,
  #rt-open .table-wrap {
    max-height: none;
    overflow: visible;
  }

  #rt-teams table,
  #rt-open table {
    display: block;
    width: 100%;
    border-collapse: separate;
  }

  /* Перебиваем min-width:720px из control.css: id + вложенность + :first-child
     дают большую специфичность, чем .control-page #rt-teams table. */
  #rt-teams .table-wrap table:first-child,
  #rt-open .table-wrap table:first-child {
    width: 100%;
    min-width: 0;
  }

  #rt-teams thead,
  #rt-open thead {
    display: none;
  }

  #rt-teams tbody,
  #rt-open tbody {
    display: grid;
    gap: 10px;
  }

  #rt-teams tr,
  #rt-open tr {
    display: grid;
    gap: 4px;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-alt);
  }

  #rt-teams td,
  #rt-open td {
    display: grid;
    grid-template-columns: 88px minmax(0, 1fr);
    align-items: center;
    gap: 8px;
    width: auto;
    padding: 3px 0;
    border: 0;
  }

  #rt-teams td::before,
  #rt-open td::before {
    color: var(--muted);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.02em;
    line-height: 1.3;
    text-transform: uppercase;
  }

  #rt-teams td:nth-child(1),
  #rt-open td:nth-child(1) {
    display: block;
    margin-bottom: 4px;
    padding: 0 0 8px;
    border-bottom: 1px solid var(--border);
  }

  #rt-teams td:nth-child(1)::before,
  #rt-open td:nth-child(1)::before {
    display: none;
  }

  #rt-teams td:nth-child(2)::before { content: "Куратор"; }
  #rt-teams td:nth-child(3)::before { content: "Ответ"; }
  #rt-teams td:nth-child(4)::before { content: "Очки"; }
  #rt-teams td:nth-child(5)::before { content: "Куратору"; }
  #rt-open td:nth-child(2)::before { content: "Ответ команды"; }
  #rt-open td:nth-child(3)::before { content: "Очки"; }
  #rt-open td:nth-child(4)::before { content: "Оценка"; }

  #rt-teams .ctrl-curator-cell {
    display: grid;
    gap: 6px;
  }

  #rt-teams .ctrl-curator-name {
    max-width: none;
    overflow: visible;
    text-overflow: clip;
    white-space: normal;
  }

  #rt-teams .ctrl-curator-select {
    width: 100%;
    max-width: none;
  }

  #rt-teams .ctrl-curator-cell .btn {
    justify-self: start;
  }

  #rt-open td:nth-child(4) {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
  }

  #rt-open td:nth-child(4)::before {
    flex: 0 0 100%;
  }
}

/* На очень низких ландшафтах прячем служебную сводку, чтобы варианты и
   таймер оставались на первом экране. */
@media (orientation: landscape) and (max-height: 380px) {
  body.play-page .room-summary {
    display: none;
  }
  body.play-page #question-extra-meta {
    display: none !important;
  }
}

/* ==========================================================================
   ПОЛНОЭКРАННЫЙ РЕЖИМ
   Кнопка общая для админки, пульта и трансляции. Иконка меняется, подпись
   остаётся доступной и на планшете; при отказе Fullscreen API включается
   резервный режим на всю доступную область.
   ========================================================================== */
.fullscreen-btn {
  flex: 0 0 auto;
  white-space: nowrap;
  touch-action: manipulation;
}

.fullscreen-btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 0;
}

.fullscreen-icon-collapse {
  display: none;
}

html[data-fullscreen-active="true"] .fullscreen-icon-expand {
  display: none;
}

html[data-fullscreen-active="true"] .fullscreen-icon-collapse {
  display: block;
}

html[data-fullscreen-active="true"] .fullscreen-btn {
  border-color: var(--accent);
  background: var(--accent-soft);
}

/* Резервный режим: если нативный Fullscreen API недоступен, страница
   занимает всю видимую область и прокручивается внутри неё. Это важно для
   iPad и встроенных браузеров, где нельзя скрыть интерфейс браузера. */
body.leto-fullscreen-fallback {
  position: fixed;
  inset: 0;
  z-index: 9990;
  width: 100%;
  height: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--bg);
  overscroll-behavior: contain;
}

body.leto-fullscreen-fallback .container {
  max-width: none;
}

/* В резервном режиме верхняя панель остаётся на виду, чтобы кнопка выхода
   была доступна и после прокрутки длинной страницы. */
body.leto-fullscreen-fallback .nav-bar,
body.leto-fullscreen-fallback .top-header {
  position: sticky;
  top: 0;
  z-index: 60;
}

body.leto-fullscreen-fallback .wide-16x9 {
  max-width: none;
}

body.leto-fullscreen-fallback #stage-question {
  max-height: none;
}

@media (max-width: 560px) {
  .fullscreen-btn-label {
    display: none;
  }

  .fullscreen-btn {
    min-width: 44px;
    width: 44px;
    padding-left: 0;
    padding-right: 0;
  }
}

