/* ── Reset & base ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f0f2f5;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #2d3748;
  --muted: #718096;
  --primary: #6c63ff;
  --primary-dark: #574fd6;
  --side-a: #4299e1;
  --side-a-dark: #3182ce;
  --side-b: #f56565;
  --side-b-dark: #e53e3e;
  --success: #48bb78;
  --radius: 12px;
  --shadow: 0 2px 12px rgba(0,0,0,.08);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding: 24px 16px;
}

/* ── Layout ───────────────────────────────────────────────── */
.page-wrap {
  max-width: 680px;
  margin: 0 auto;
}

.page-wrap--wide {
  max-width: 960px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 1fr 260px;
  gap: 24px;
  align-items: start;
}

.page-wrap--wide > * {
  min-width: 0;
}

@media (max-width: 700px) {
  .page-wrap--wide {
    grid-template-columns: 1fr;
  }
}

/* ── Card ─────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px;
}

.card--compact {
  padding: 20px 24px;
}

/* ── Typography ───────────────────────────────────────────── */
h1 {
  font-size: 1.75rem;
  font-weight: 700;
  margin-bottom: 6px;
}

h2 {
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: 16px;
}

h3 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .05em;
}

.subtitle {
  color: var(--muted);
  margin-bottom: 28px;
  font-size: .95rem;
}

/* ── Form ─────────────────────────────────────────────────── */
.field {
  margin-bottom: 20px;
}

label {
  display: block;
  font-weight: 500;
  font-size: .9rem;
  margin-bottom: 6px;
}

input[type="text"], textarea {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  font-family: inherit;
  color: var(--text);
  background: var(--bg);
  transition: border-color .15s;
  outline: none;
}

input[type="text"]:focus, textarea:focus {
  border-color: var(--primary);
  background: #fff;
}

textarea {
  resize: vertical;
  min-height: 120px;
}

.field-hint {
  font-size: .8rem;
  color: var(--muted);
  margin-top: 4px;
}

/* ── Buttons ──────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 11px 24px;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, transform .1s, opacity .15s;
  text-decoration: none;
  white-space: nowrap;
}

.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }

.btn--primary { background: var(--primary); color: #fff; }
.btn--primary:hover:not(:disabled) { background: var(--primary-dark); }

.btn--side-a { background: var(--side-a); color: #fff; font-size: 1.1rem; padding: 14px 28px; white-space: normal; word-break: break-word; }
.btn--side-a:hover:not(:disabled) { background: var(--side-a-dark); }

.btn--side-b { background: var(--side-b); color: #fff; font-size: 1.1rem; padding: 14px 28px; white-space: normal; word-break: break-word; }
.btn--side-b:hover:not(:disabled) { background: var(--side-b-dark); }

.btn--ghost {
  background: transparent;
  color: var(--muted);
  border: 1.5px solid var(--border);
}
.btn--ghost:hover:not(:disabled) {
  background: var(--bg);
  color: var(--text);
}

.btn--danger { background: var(--side-b); color: #fff; }
.btn--danger:hover:not(:disabled) { background: var(--side-b-dark); }

.btn--full { width: 100%; }

/* ── Error message ────────────────────────────────────────── */
.error-msg {
  background: #fff5f5;
  border: 1px solid #fed7d7;
  border-radius: 8px;
  color: #c53030;
  padding: 10px 14px;
  font-size: .9rem;
  margin-top: 12px;
  display: none;
}

.error-msg.visible { display: block; }

/* ── Header bar ───────────────────────────────────────────── */
.session-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 20px;
}

.session-header__id {
  font-size: .8rem;
  color: var(--muted);
  font-family: monospace;
  background: var(--bg);
  padding: 3px 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
}

.session-header__name {
  font-size: .9rem;
  color: var(--muted);
}

/* ── Round badge ──────────────────────────────────────────── */
.round-badge {
  display: inline-block;
  background: var(--primary);
  color: #fff;
  font-size: .75rem;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 20px;
  letter-spacing: .04em;
  text-transform: uppercase;
  margin-bottom: 20px;
}

/* ── Matchup ──────────────────────────────────────────────── */
.matchup {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 16px;
  align-items: center;
  margin-bottom: 24px;
}

.matchup__side {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  text-align: center;
  min-width: 0;
}

.matchup__side--a .matchup__votes { color: var(--side-a); }
.matchup__side--b .matchup__votes { color: var(--side-b); }

.matchup__name {
  font-size: 1.1rem;
  font-weight: 600;
  word-break: break-word;
}

.matchup__votes {
  font-size: 2.5rem;
  font-weight: 700;
  line-height: 1;
}

.matchup__vs {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
}

/* ── Vote bar ─────────────────────────────────────────────── */
.vote-bar {
  height: 8px;
  background: var(--side-b);
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 24px;
}

.vote-bar__fill {
  height: 100%;
  background: var(--side-a);
  border-radius: 4px;
  transition: width .4s ease;
}

/* ── Vote actions ─────────────────────────────────────────── */
.vote-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}

.vote-actions .btn {
  width: 75%;
}

.vote-status {
  text-align: center;
  color: var(--muted);
  font-size: .9rem;
  margin-bottom: 20px;
  min-height: 1.4em;
}

.vote-status--voted {
  color: var(--success);
  font-weight: 600;
}

/* ── Vote selection state ─────────────────────────────────── */
.btn--voted {
  outline: 3px solid rgba(255,255,255,0.85);
  outline-offset: 2px;
  box-shadow: 0 0 0 5px rgba(0,0,0,0.25);
}

.btn--unvoted {
  opacity: 0.5;
}

/* ── Host controls ────────────────────────────────────────── */
.host-controls {
  border-top: 1px solid var(--border);
  padding-top: 20px;
  margin-top: 4px;
}

/* ── Champion ─────────────────────────────────────────────── */
.champion-banner {
  text-align: center;
  padding: 32px 24px;
}

.champion-banner__trophy {
  font-size: 3rem;
  margin-bottom: 12px;
}

.champion-banner__label {
  font-size: .85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
  margin-bottom: 8px;
}

.champion-banner__name {
  font-size: 2rem;
  font-weight: 700;
  color: var(--primary);
}

/* ── Participants sidebar ─────────────────────────────────── */
.participants-list {
  list-style: none;
}

.participants-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 0;
  border-bottom: 1px solid var(--border);
  font-size: .9rem;
}

.participants-list li:last-child { border-bottom: none; }

.participant__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--border);
  flex-shrink: 0;
}

.participant__dot--host { background: var(--primary); }
.participant__dot--voted { background: var(--success); }

.participant__badge {
  font-size: .7rem;
  background: var(--primary);
  color: #fff;
  padding: 1px 6px;
  border-radius: 10px;
  margin-left: auto;
}

/* ── Share box ────────────────────────────────────────────── */
.share-box {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  font-family: monospace;
  font-size: .85rem;
  word-break: break-all;
  color: var(--text);
  margin: 8px 0 16px;
}

/* ── Spinner ──────────────────────────────────────────────── */
.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255,255,255,.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .6s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Connection status dot ────────────────────────────────── */
.live-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--border);
  margin-right: 4px;
  transition: background .3s;
}

.live-dot--connected { background: var(--success); }

.live-indicator {
  display: flex;
  align-items: center;
  font-size: .8rem;
  color: var(--muted);
}

/* ── Vote history panel ────────────────────────────────────── */
.vote-history__list {
  list-style: none;
  max-height: 300px;
  overflow-y: auto;
}

.vote-history__item {
  padding: 9px 0;
  border-bottom: 1px solid var(--border);
}

.vote-history__item:last-child { border-bottom: none; }

.vote-history__round {
  font-size: .7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
  margin-bottom: 3px;
}

.vote-history__row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: .85rem;
}

.vote-history__name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.vote-history__name--winner {
  font-weight: 700;
  color: var(--text);
}

.vote-history__name--loser {
  color: var(--muted);
}

.vote-history__score {
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  font-size: .8rem;
  flex-shrink: 0;
}

.vote-history__empty {
  color: var(--muted);
  font-size: .85rem;
}

@media (max-width: 700px) {
  .hide-on-mobile { display: none !important; }
}

/* ── Winner reveal (anonymous voting) ────────────────────── */
.winner-reveal {
  text-align: center;
  padding: 24px 0 8px;
  border-top: 1px solid var(--border);
  margin-top: 8px;
}

.winner-reveal__label {
  font-size: .75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
  margin-bottom: 8px;
}

.winner-reveal__name {
  font-size: 2rem;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 6px;
  word-break: break-word;
}

.winner-reveal__votes {
  font-size: 1rem;
  color: var(--muted);
  margin-bottom: 12px;
}

.winner-reveal__countdown {
  font-size: .85rem;
  color: var(--muted);
}

/* ── Checkbox fields (create page) ───────────────────────── */
.field--checkbox {
  margin-bottom: 14px;
}

.field--checkbox label {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font-size: .95rem;
  font-weight: 400;
  margin-bottom: 0;
}

.field--checkbox input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
  cursor: pointer;
  flex-shrink: 0;
}

/* ── Poster vote buttons ──────────────────────────────────── */
.matchup--compact .matchup__name {
  display: none;
}

.vote-actions--posters {
  flex-direction: column;
  gap: 16px;
  margin-bottom: 16px;
}
.vote-actions--posters .btn--poster {
  width: 100%;
}

@media (min-width: 600px) {
  .vote-actions--posters {
    flex-direction: row;
    align-items: stretch;
  }
  .vote-actions--posters .btn--poster {
    width: 50%;
  }
}

.btn--poster {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  padding: 0;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  transition: border-color .15s, transform .1s;
}

.btn--poster:active { transform: scale(.98); }
.btn--poster:disabled { opacity: .45; cursor: not-allowed; transform: none; }

.btn--poster__img {
  width: 100%;
  aspect-ratio: 2 / 3;
  object-fit: cover;
  display: block;
  background: var(--bg);
  pointer-events: none;
}

.btn--poster__name {
  padding: 10px 12px;
  font-size: .95rem;
  font-weight: 600;
  text-align: center;
  color: var(--text);
  word-break: break-word;
  background: var(--surface);
}

/* Voted / unvoted states (override the default text-button styles) */
.btn--poster.btn--voted {
  border-color: var(--success);
  outline: none;
  box-shadow: 0 0 0 4px rgba(72, 187, 120, .25);
}
.btn--poster.btn--unvoted {
  opacity: .55;
}

/* Hold-to-vote progress ring */
.btn--poster__ring {
  position: absolute;
  inset: 0;
  border-radius: 10px;
  pointer-events: none;
  opacity: 0;
  border: 3px solid var(--primary);
  transition: opacity .15s;
}
.btn--poster--holding .btn--poster__ring {
  opacity: 1;
  animation: hold-ring .5s linear forwards;
}
@keyframes hold-ring {
  from { clip-path: polygon(50% 50%, 50% 0%, 50% 0%, 50% 0%, 50% 0%, 50% 0%); }
  to   { clip-path: polygon(50% 50%, 50% 0%, 100% 0%, 100% 100%, 0% 100%, 0% 0%); }
}

/* ── Movie modal ──────────────────────────────────────────── */
body.modal-open { overflow: hidden; }

.movie-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.movie-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 17, 23, .65);
  backdrop-filter: blur(2px);
}

.movie-modal__card {
  position: relative;
  background: var(--surface);
  border-radius: 16px;
  box-shadow: 0 12px 40px rgba(0,0,0,.35);
  width: min(560px, calc(100vw - 24px));
  max-height: calc(100vh - 24px);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0;
}

@media (min-width: 600px) {
  .movie-modal__card {
    flex-direction: row;
  }
}

.movie-modal__poster {
  width: 100%;
  aspect-ratio: 2 / 3;
  object-fit: cover;
  background: var(--bg);
}

@media (min-width: 600px) {
  .movie-modal__poster {
    width: 220px;
    flex-shrink: 0;
    aspect-ratio: auto;
    height: auto;
  }
}

.movie-modal__body {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex: 1;
}

.movie-modal__title {
  font-size: 1.3rem;
  font-weight: 700;
  margin: 0;
  word-break: break-word;
}

.movie-modal__overview {
  font-size: .95rem;
  color: var(--text);
  line-height: 1.45;
  margin: 0;
}

.movie-modal__close {
  position: absolute;
  top: 8px;
  right: 12px;
  background: rgba(255,255,255,.85);
  border: none;
  border-radius: 50%;
  width: 32px;
  height: 32px;
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
  color: var(--text);
  z-index: 1;
}
.movie-modal__close:hover { background: #fff; }
