:root {
  --color-bg: #0e2a30;
  --color-bg-elevated: #123640;
  --color-teal: #1f7a8c;
  --color-teal-light: #4fb0c6;
  --color-text: #eaf6f6;
  --color-text-muted: #9fc7cc;
  --color-gold: #d4af37;
  --color-coral: #ff6f59;
  --radius: 14px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  padding: 24px;
}

.locale-control {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  right: 12px;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.75rem;
}

.locale-control select {
  max-width: 9rem;
  min-height: 2.25rem;
  font: inherit;
}

.screen {
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  text-align: center;
}

.btn,
.btn-quiet,
.status-text,
.table-row-name,
.table-row-meta,
.modal-box {
  overflow-wrap: anywhere;
}

.btn,
.btn-quiet {
  white-space: normal;
  min-height: 44px;
}

@media (max-width: 430px) {
  body {
    padding: max(68px, calc(env(safe-area-inset-top) + 56px)) 16px 20px;
    align-items: flex-start;
  }

  .locale-control {
    max-width: calc(100vw - 24px);
  }

  .locale-control span {
    white-space: normal;
  }
}

/* Весь контент экрана "screen-dynamic" рендерится внутрь этого div одним innerHTML —
   без собственной flex-раскладки все вложенные элементы слипались без отступов. */
#dynamic-content {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.hidden {
  display: none !important;
}

.brand-mark {
  display: block;
}

.brand-mark-lg {
  width: 96px;
  height: 96px;
  margin-bottom: 4px;
}

.brand-mark-sm {
  width: 44px;
  height: 44px;
}

.logo {
  font-size: 26px;
  letter-spacing: 0.1em;
  margin: 0;
  font-weight: 700;
}

.logo-civil {
  color: var(--color-text);
}

.logo-signal {
  color: var(--color-teal-light);
}

.tagline {
  margin: 0 0 12px;
  color: var(--color-text-muted);
  font-style: italic;
}

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

.btn {
  padding: 14px 20px;
  border-radius: var(--radius);
  border: none;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s ease, transform 0.05s ease;
  display: inline-block;
  text-decoration: none;
  text-align: center;
}

.btn:active {
  transform: scale(0.98);
}

.btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--color-teal);
  color: white;
}

.btn-secondary {
  background: var(--color-bg-elevated);
  color: var(--color-text);
  border: 1px solid var(--color-teal);
}

.status-text {
  color: var(--color-text-muted);
  font-size: 14px;
  min-height: 18px;
}

.error-text {
  color: var(--color-coral);
  font-size: 14px;
  min-height: 18px;
}

input[type='text'] {
  width: 100%;
  padding: 14px;
  border-radius: var(--radius);
  border: 1px solid var(--color-teal);
  background: var(--color-bg-elevated);
  color: var(--color-text);
  font-size: 16px;
  text-align: center;
}

input[type='text']::placeholder {
  color: var(--color-text-muted);
}

.players-list {
  list-style: none;
  padding: 0;
  margin: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.players-list li {
  background: var(--color-bg-elevated);
  border-radius: var(--radius);
  padding: 12px 16px;
  font-size: 15px;
}

.vote-status-list li {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  color: var(--color-text-muted);
}

.vote-status-list li span:first-child { color: var(--color-text); }

.protocols-list li {
  padding: 0;
  overflow: hidden;
}

.protocols-list a {
  display: block;
  padding: 12px 16px;
  color: var(--color-text);
  text-decoration: none;
}

.protocols-list a:hover {
  background: var(--color-teal);
}

.invite-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 16px;
  background: var(--color-bg-elevated);
  border-radius: var(--radius);
  width: 100%;
}

#qrcode {
  background: white;
  padding: 8px;
  border-radius: 8px;
}

#link-text {
  font-size: 13px;
  text-align: center;
  padding: 10px;
}

/* --- CS-020: переходный экран раунда --- */
.round-number {
  font-size: 40px;
  letter-spacing: 0.08em;
  color: var(--color-teal-light);
}

/* --- CS-021/030: карта --- */
.card {
  width: 220px;
  height: 320px;
  position: relative;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

.card-face {
  position: absolute;
  inset: 0;
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  backface-visibility: hidden;
  transition: opacity 0.15s ease;
  overflow: hidden;
}

/* --- Рубашка: градиент в фирменной гамме, знак бренда + крупный "?" --- */
.card-back {
  background: linear-gradient(160deg, var(--color-teal) 0%, var(--color-bg-elevated) 100%);
  border: 2px solid var(--color-teal-light);
  opacity: 1;
  gap: 4px;
}

.card-question {
  font-size: 80px;
  font-weight: 700;
  color: var(--color-teal-light);
  line-height: 1;
  opacity: 0.9;
}

/* --- Лицевые стороны --- */
.card-front {
  opacity: 0;
  gap: 6px;
  padding: 16px;
}

.card-icon {
  font-size: 84px;
  line-height: 1;
  margin-bottom: 4px;
}

.card-title-en {
  font-size: 30px;
  font-weight: 800;
  letter-spacing: 0.06em;
  line-height: 1;
}

.card-front.role-civil {
  background: linear-gradient(160deg, var(--color-teal) 0%, var(--color-bg-elevated) 100%);
  border: 2px solid var(--color-teal-light);
}

.card-front.role-civil .card-title-en {
  color: var(--color-teal-light);
}

.card-front.role-actor {
  background: linear-gradient(160deg, #7a3a2e 0%, #2e1712 100%);
  border: 2px solid var(--color-coral);
}

.card-front.role-actor .card-title-en {
  color: var(--color-coral);
}

.card.revealed .card-back {
  opacity: 0;
}

.card.revealed .card-front {
  opacity: 1;
}

.card-locked {
  opacity: 0.85;
}

/* Экран вскрытия — карта чуть компактнее, чтобы влезал текст исхода сверху */
.reveal-title + .card {
  width: 180px;
  height: 260px;
}
.reveal-title + .card .card-icon {
  font-size: 68px;
}
.reveal-title + .card .card-title-en {
  font-size: 24px;
}

.opening-hint {
  color: var(--color-teal-light);
  font-style: italic;
  font-size: 14px;
  max-width: 320px;
}

/* --- CS-031: индикатор готовности --- */
.readiness-dots {
  display: flex;
  gap: 10px;
  margin: 8px auto;
  width: fit-content;
  justify-content: center;
}

.dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-teal);
}

.dot-ready {
  background: var(--color-teal-light);
  box-shadow: 0 0 8px var(--color-teal-light);
}

/* --- CS-042: акцент при вскрытии карты --- */
.reveal-title {
  font-size: 24px;
}

.reveal-actor {
  color: var(--color-coral);
}

.reveal-civil {
  color: var(--color-teal-light);
}

.public-reveal {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  max-height: 520px;
  overflow: hidden;
  transition: opacity 360ms ease, transform 360ms ease, max-height 420ms ease;
}

.public-reveal-name { margin: 2px 0 0; font-size: 20px; font-weight: 700; }
.public-reveal-leaving { opacity: 0; transform: scale(.88) translateY(-18px); max-height: 0; }
.round-result-table { display: grid; gap: 8px; width: min(100%, 430px); }
.round-result-row { min-height: 64px; }
.round-delta { color: var(--color-gold); font-size: 20px; }
.table-badge-actor { color: var(--color-coral); }

/* --- Постоянный статус-бар: раунд + обрыв связи --- */
.top-status-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  gap: 14px;
  padding: 6px 12px;
  background: rgba(14, 42, 48, 0.9);
  border-bottom: 1px solid var(--color-teal);
  font-size: 12px;
  color: var(--color-text-muted);
  z-index: 40;
  pointer-events: none;
}

#top-disconnect-label {
  color: var(--color-text-muted);
}

#top-disconnect-label:empty {
  display: none;
}

/* --- CS-060/061: аварийные действия --- */
.emergency-fab {
  position: fixed;
  bottom: 16px;
  right: 16px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--color-teal);
  background: var(--color-bg-elevated);
  color: var(--color-coral);
  font-size: 20px;
  cursor: pointer;
  z-index: 50;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

.modal-box {
  position: relative;
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-teal);
  border-radius: var(--radius);
  padding: 20px;
  max-width: 400px;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: 80vh;
  overflow-y: auto;
}

.modal-close {
  position: absolute;
  top: 8px;
  right: 10px;
  width: 44px;
  height: 44px;
  border: 0;
  background: transparent;
  color: var(--color-text-muted);
  font-size: 28px;
  cursor: pointer;
}

.btn-quiet {
  padding: 12px 16px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--color-text-muted);
  font-size: 15px;
  cursor: pointer;
}

.modal-section-title {
  font-size: 14px;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 8px 0 4px;
}

.emergency-target-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.emergency-action-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 4px 0 18px;
  border-bottom: 1px solid #34525a;
}

.emergency-action-section:last-of-type { border-bottom: 0; }
.emergency-action-section .modal-section-title { margin-bottom: 0; }
.emergency-section-cta { margin-top: 8px; }

.emergency-target-btn {
  padding: 10px;
  border-radius: var(--radius);
  border: 1px solid var(--color-teal);
  background: var(--color-bg);
  color: var(--color-text);
  cursor: pointer;
  text-align: left;
}

.emergency-target-btn.selected {
  border-color: var(--color-gold);
  box-shadow: 0 0 0 2px var(--color-gold);
}

/* --- CS-051: визуальная дорожка очков до 21 --- */
.score-track {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.score-track-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.score-track-label {
  display: flex;
  justify-content: space-between;
  font-size: 14px;
}

.score-track-bar-bg {
  width: 100%;
  height: 16px;
  border-radius: 999px;
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-teal);
  overflow: hidden;
}

.score-track-bar-fill {
  height: 100%;
  background: var(--color-teal-light);
  border-radius: 999px;
  transition: width 0.3s ease;
}

.score-track-bar-fill.reached {
  background: var(--color-gold);
}

/* --- Голосование: стабильные четыре места общего стола --- */
.table-map {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  max-width: 420px;
  margin: 8px auto;
}

.table-row {
  min-height: 58px;
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: var(--radius);
  border: 1px solid #34525a;
  background: var(--color-bg-elevated);
  color: var(--color-text);
  text-align: left;
}

.table-row:disabled { opacity: 0.62; }
.table-row-selectable {
  border-color: var(--color-teal);
  cursor: pointer;
  opacity: 1;
}
.table-row-selectable.selected {
  border-color: var(--color-teal-light);
  box-shadow: 0 0 0 2px var(--color-teal-light);
}
.table-row-majority { border-color: var(--color-gold); }
.table-row-name { font-size: 17px; font-weight: 600; }
.table-row-meta { display: flex; align-items: center; justify-content: flex-end; gap: 6px; flex-wrap: wrap; }
.table-badge { color: var(--color-text-muted); font-size: 11px; text-transform: uppercase; letter-spacing: .04em; }
.table-badge-revealed { color: var(--color-teal-light); }
.vote-total { color: var(--color-gold); font-size: 14px; }
.row-countdown { color: var(--color-teal-light); font-size: 13px; font-weight: 700; }
.vote-result-row { flex-wrap: wrap; }
.vote-direction-names {
  flex: 0 0 100%;
  color: var(--color-text-muted);
  font-size: 13px;
}
