/* Полностью локальные стили интерфейса участника и просмотрщика фотографий.
   Строгая нейтральная темная тема без кислотных акцентов для работы в темном зале. */

:root {
  --bg-photo: #000000;
  --bg-main: #0f0f0f;
  --bg-card: #181818;
  --bg-elevated: #222222;
  --bg-hover: #2b2b2b;
  --border: #2c2c2c;
  --border-strong: #444444;
  --text-main: #e5e5e5;
  --text-muted: #9a9a9a;
  --text-dim: #6e6e6e;
  --btn-light-bg: #e5e5e5;
  --btn-light-fg: #0f0f0f;
  --danger-bg: #2d1919;
  --danger-border: #5c2b2b;
  --danger-text: #f0b8b8;
  --warn-bg: #292315;
  --warn-border: #594a24;
  --warn-text: #e6d3a3;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

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

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  padding: 0;
  background-color: var(--bg-main);
  color: var(--text-main);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

button,
input,
select,
textarea {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  opacity: 0.42;
  cursor: not-allowed;
}

/* ==================== ОБЩИЙ КАРКАС ==================== */

.app-shell {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 1120px;
  margin: 0 auto;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
}

.brand-title {
  font-size: 0.95rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stage-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  color: var(--text-muted);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  padding: 4px 10px;
  border-radius: 999px;
  white-space: nowrap;
}

.voter-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 14px;
  background: #141414;
  border-bottom: 1px solid var(--border);
  font-size: 0.82rem;
  color: var(--text-muted);
}

.link-btn {
  background: none;
  border: none;
  padding: 2px 4px;
  color: var(--text-muted);
  text-decoration: underline;
  font-size: 0.82rem;
}

.link-btn:hover {
  color: var(--text-main);
}

.center-card-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px 14px;
}

.card {
  width: 100%;
  max-width: 480px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px;
}

.card h1,
.card h2 {
  margin: 0 0 8px 0;
  font-size: 1.25rem;
  font-weight: 600;
}

.muted {
  color: var(--text-muted);
  font-size: 0.92rem;
  margin: 0 0 16px 0;
}

/* ==================== КНОПКИ И ПОЛЯ ==================== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 16px;
  border-radius: 10px;
  border: 1px solid var(--border-strong);
  background: var(--bg-elevated);
  color: var(--text-main);
  font-weight: 500;
  transition: background-color 0.12s ease, border-color 0.12s ease, transform 0.06s ease;
  user-select: none;
}

.btn:hover:not(:disabled) {
  background: var(--bg-hover);
}

.btn:active:not(:disabled) {
  transform: scale(0.985);
}

.btn-primary {
  background: var(--btn-light-bg);
  color: var(--btn-light-fg);
  border-color: var(--btn-light-bg);
  font-weight: 600;
}

.btn-primary:hover:not(:disabled) {
  background: #ffffff;
  border-color: #ffffff;
}

.btn-block {
  width: 100%;
}

.btn-sm {
  padding: 7px 11px;
  font-size: 0.84rem;
  border-radius: 8px;
}

.input {
  width: 100%;
  padding: 11px 13px;
  border-radius: 10px;
  border: 1px solid var(--border-strong);
  background: var(--bg-main);
  color: var(--text-main);
  outline: none;
}

.input:focus {
  border-color: #888888;
}

.pin-input {
  font-size: 1.45rem;
  letter-spacing: 0.45em;
  text-align: center;
  font-weight: 600;
  padding: 12px;
}

.error-box {
  background: var(--danger-bg);
  border: 1px solid var(--danger-border);
  color: var(--danger-text);
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 0.88rem;
  margin-bottom: 14px;
}

.warn-box {
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
  color: var(--warn-text);
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 0.88rem;
  margin-bottom: 14px;
}

/* ==================== ВХОД УЧАСТНИКА ==================== */

.tabs-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  background: var(--bg-main);
  padding: 4px;
  border-radius: 10px;
  border: 1px solid var(--border);
  margin-bottom: 16px;
}

.tab-btn {
  padding: 9px 10px;
  border: none;
  border-radius: 7px;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.9rem;
  font-weight: 500;
}

.tab-btn.active {
  background: var(--bg-elevated);
  color: var(--text-main);
}

.member-list {
  max-height: 220px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-main);
  margin-top: 8px;
  margin-bottom: 14px;
}

.member-item {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 11px 13px;
  border: none;
  border-bottom: 1px solid #1d1d1d;
  background: transparent;
  text-align: left;
  font-size: 0.95rem;
}

.member-item:last-child {
  border-bottom: none;
}

.member-item:hover:not(:disabled) {
  background: #1b1b1b;
}

.member-item.selected {
  background: #292929;
  font-weight: 600;
}

.voted-tag {
  font-size: 0.75rem;
  padding: 2px 8px;
  border-radius: 999px;
  background: #202020;
  border: 1px solid #333333;
  color: var(--text-muted);
  white-space: nowrap;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 12px 0 16px 0;
  font-size: 0.9rem;
  color: var(--text-muted);
  cursor: pointer;
}

.checkbox-row input {
  width: 18px;
  height: 18px;
  accent-color: #d4d4d4;
}

/* ==================== ШАГ 1: ПЕРВИЧНАЯ РАСКЛАДКА ==================== */

.step1-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: calc(100dvh - 78px);
  min-height: 480px;
  padding: 8px 12px 12px 12px;
  gap: 8px;
}

.step1-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.frame-counter {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.frame-number {
  font-size: 1.2rem;
  font-weight: 700;
}

.frame-progress {
  font-size: 0.86rem;
  color: var(--text-muted);
}

.own-btn {
  padding: 7px 11px;
  font-size: 0.82rem;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--bg-card);
  color: var(--text-muted);
}

.own-btn.active {
  background: var(--btn-light-bg);
  color: var(--btn-light-fg);
  border-color: var(--btn-light-bg);
  font-weight: 600;
}

.photo-stage-box {
  flex: 1;
  min-height: 180px;
  background: var(--bg-photo);
  border: 1px solid #1f1f1f;
  border-radius: 12px;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.photo-stage-box img {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  cursor: zoom-in;
  display: block;
}

.zoom-corner-hint {
  position: absolute;
  bottom: 8px;
  right: 8px;
  background: rgba(15, 15, 15, 0.76);
  border: 1px solid rgba(255, 255, 255, 0.14);
  color: #cfcfcf;
  font-size: 0.74rem;
  padding: 4px 8px;
  border-radius: 6px;
  pointer-events: none;
}

.current-tier-pill {
  position: absolute;
  top: 8px;
  left: 8px;
  background: rgba(20, 20, 20, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.22);
  color: var(--text-main);
  font-size: 0.76rem;
  padding: 4px 9px;
  border-radius: 6px;
  pointer-events: none;
}

.tier-buttons-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

@media (min-width: 640px) {
  .tier-buttons-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

.tier-btn {
  padding: 13px 10px;
  border-radius: 11px;
  border: 1px solid var(--border-strong);
  background: var(--bg-card);
  color: var(--text-main);
  font-size: 0.98rem;
  font-weight: 600;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.tier-btn small {
  font-size: 0.73rem;
  font-weight: 400;
  color: var(--text-muted);
}

.tier-btn.selected {
  background: #303030;
  border-color: #bcbcbc;
}

.step1-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

/* ==================== ШАГ 2: ПОЛКА САМОПРОВЕРКИ ==================== */

.shelf-screen {
  padding: 16px 14px 96px 14px;
}

.section-head {
  margin-bottom: 14px;
}

.section-head h2 {
  margin: 0 0 4px 0;
  font-size: 1.2rem;
}

.section-head p {
  margin: 0;
  font-size: 0.88rem;
  color: var(--text-muted);
}

.shelf-block {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 14px;
}

.shelf-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  font-weight: 600;
  font-size: 0.98rem;
}

.shelf-count {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 400;
}

.shelf-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(112px, 1fr));
  gap: 10px;
}

.thumb-card {
  background: var(--bg-main);
  border: 1px solid var(--border);
  border-radius: 9px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.thumb-photo-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  background: var(--bg-photo);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: zoom-in;
}

.thumb-photo-wrap img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  display: block;
}

.thumb-num {
  position: absolute;
  top: 5px;
  left: 5px;
  background: rgba(0, 0, 0, 0.78);
  border: 1px solid rgba(255, 255, 255, 0.18);
  color: var(--text-main);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 5px;
  pointer-events: none;
}

.thumb-move-btn {
  width: 100%;
  padding: 7px 6px;
  border: none;
  border-top: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text-muted);
  font-size: 0.78rem;
}

.thumb-move-btn:hover {
  color: var(--text-main);
  background: var(--bg-hover);
}

.sticky-bottom-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(24, 24, 24, 0.96);
  border-top: 1px solid var(--border-strong);
  padding: 10px 14px;
  z-index: 50;
}

.sticky-bottom-inner {
  max-width: 1120px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

/* ==================== ШАГ 3: УМНЫЕ ПОПАРНЫЕ ДУЭЛИ ==================== */

.duel-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: calc(100dvh - 78px);
  min-height: 520px;
  padding: 8px 12px 12px 12px;
  gap: 8px;
}

.duel-topbar {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.duel-meta-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.85rem;
}

.progress-track {
  width: 100%;
  height: 7px;
  background: var(--bg-elevated);
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: #d4d4d4;
  border-radius: 999px;
  transition: width 0.2s ease;
}

.duel-arena {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-rows: 1fr 1fr;
  grid-template-columns: 1fr;
  gap: 8px;
}

@media (min-width: 768px) {
  .duel-arena {
    grid-template-rows: 1fr;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
  }
}

.duel-card {
  min-height: 0;
  background: var(--bg-photo);
  border: 1px solid #242424;
  border-radius: 12px;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.duel-card img {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  cursor: zoom-in;
  display: block;
}

.duel-badge {
  position: absolute;
  top: 8px;
  left: 8px;
  background: rgba(15, 15, 15, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.2);
  padding: 4px 9px;
  border-radius: 6px;
  font-size: 0.82rem;
  font-weight: 600;
  pointer-events: none;
}

.duel-choice-bar {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.duel-choice-btn {
  padding: 13px 10px;
  border-radius: 11px;
  border: 1px solid #666666;
  background: var(--bg-elevated);
  color: var(--text-main);
  font-weight: 600;
  font-size: 0.94rem;
  text-align: center;
}

.duel-choice-btn:hover {
  background: #303030;
  border-color: #a8a8a8;
}

/* ==================== ШАГ 4: РУЧНАЯ ПОДСТРОЙКА РЕЙТИНГА ==================== */

.manual-rank-screen {
  padding: 16px 14px 96px 14px;
  max-width: 780px;
  margin: 0 auto;
  width: 100%;
}

.rank-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 18px;
}

.rank-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 8px 10px;
  transition: border-color 0.2s ease, background-color 0.2s ease;
}

.rank-row.rank-dragging {
  border-color: #d4d4d4;
  background: #252525;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.55);
  z-index: 10;
}

.rank-row.rank-flash {
  border-color: #b8b8b8;
  background: #242424;
}

.rank-drag-handle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 44px;
  color: var(--text-dim);
  cursor: grab;
  touch-action: none;
  user-select: none;
  flex-shrink: 0;
  border-radius: 6px;
}

.rank-drag-handle:hover {
  color: var(--text-main);
  background: var(--bg-elevated);
}

.rank-drag-handle:active {
  cursor: grabbing;
}

.rank-place-btn {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 48px;
  height: 44px;
  padding: 2px 6px;
  border-radius: 9px;
  border: 1px solid var(--border-strong);
  background: var(--bg-elevated);
  color: var(--text-main);
  font-weight: 700;
  font-size: 0.95rem;
  flex-shrink: 0;
}

.rank-place-btn.top-three {
  background: var(--btn-light-bg);
  color: var(--btn-light-fg);
  border-color: var(--btn-light-bg);
}

.rank-place-btn small {
  font-size: 0.64rem;
  font-weight: 500;
  opacity: 0.78;
}

.rank-thumb-box {
  width: 76px;
  height: 54px;
  background: var(--bg-photo);
  border: 1px solid var(--border);
  border-radius: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  cursor: zoom-in;
  flex-shrink: 0;
}

.rank-thumb-box img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  display: block;
}

.rank-info {
  flex: 1;
  min-width: 0;
}

.rank-info-title {
  font-weight: 600;
  font-size: 0.95rem;
}

.rank-info-sub {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.rank-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.rank-arrow-btn {
  width: 38px;
  height: 38px;
  border-radius: 9px;
  border: 1px solid var(--border-strong);
  background: var(--bg-elevated);
  color: var(--text-main);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.05rem;
  font-weight: 600;
}

.rank-arrow-btn:hover:not(:disabled) {
  background: var(--bg-hover);
}

.place-picker-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(52px, 1fr));
  gap: 8px;
  max-height: 240px;
  overflow-y: auto;
  margin-top: 12px;
}

/* ==================== ШАГ 5 И ИТОГОВАЯ ТАБЛИЦА ==================== */

.page-wrap {
  padding: 18px 14px 48px 14px;
}

.top5-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(145px, 1fr));
  gap: 12px;
  margin-top: 12px;
}

.top5-card {
  background: var(--bg-main);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}

.top5-card .thumb-photo-wrap {
  aspect-ratio: 4 / 3;
}

.top5-caption {
  padding: 8px 10px;
  font-size: 0.85rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.results-table-wrap {
  overflow-x: auto;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.results-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.results-table th,
.results-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
}

.results-table th {
  background: #141414;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.8rem;
  white-space: nowrap;
}

.results-table tr:last-child td {
  border-bottom: none;
}

.res-thumb {
  width: 72px;
  height: 54px;
  background: var(--bg-photo);
  border: 1px solid var(--border);
  border-radius: 6px;
  object-fit: contain;
  cursor: zoom-in;
  display: block;
}

.place-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 30px;
  height: 30px;
  border-radius: 8px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  font-weight: 700;
}

.place-badge.top {
  background: var(--btn-light-bg);
  color: var(--btn-light-fg);
  border-color: var(--btn-light-bg);
}

/* ==================== МОДАЛЬНЫЕ ОКНА ==================== */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.78);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 200;
}

.modal-card {
  width: 100%;
  max-width: 400px;
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  padding: 18px;
}

.modal-card h3 {
  margin: 0 0 8px 0;
  font-size: 1.08rem;
}

.modal-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 14px;
}

/* ==================== ПОЛНОЭКРАННЫЙ ЗУМ (PhotoZoom) ==================== */

.pz-overlay {
  position: fixed;
  inset: 0;
  background: #000000;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  touch-action: none;
  user-select: none;
}

.pz-topbar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  background: linear-gradient(to bottom, rgba(0, 0, 0, 0.78), rgba(0, 0, 0, 0));
  z-index: 2;
  pointer-events: none;
}

.pz-title {
  font-weight: 600;
  font-size: 0.98rem;
  color: #e5e5e5;
}

.pz-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  pointer-events: auto;
}

.pz-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(24, 24, 24, 0.88);
  color: #e5e5e5;
  font-size: 0.85rem;
  font-weight: 500;
}

.pz-stage {
  flex: 1;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  cursor: grab;
}

.pz-stage.pz-grabbing {
  cursor: grabbing;
}

.pz-img {
  max-width: 100vw;
  max-height: 100vh;
  max-height: 100dvh;
  object-fit: contain;
  transform-origin: center center;
  will-change: transform;
}

.pz-hint {
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(20, 20, 20, 0.72);
  color: #b5b5b5;
  font-size: 0.76rem;
  padding: 5px 12px;
  border-radius: 999px;
  pointer-events: none;
  white-space: nowrap;
}
