/* ============================================================
   Loop — Tomasetti
   A live transcript of two models talking forever.
   Quiet, type-driven, editorial. No neon, no gradients.
   ============================================================ */

/* ---------- Fonts (self-hosted, no CDN) ---------- */
@font-face {
  font-family: 'Space Grotesk';
  src: url('../fonts/space-grotesk-latin-400-normal.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Space Grotesk';
  src: url('../fonts/space-grotesk-latin-500-normal.woff2') format('woff2');
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Space Grotesk';
  src: url('../fonts/space-grotesk-latin-700-normal.woff2') format('woff2');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'JetBrains Mono';
  src: url('../fonts/jetbrains-mono-latin-400-normal.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'JetBrains Mono';
  src: url('../fonts/jetbrains-mono-latin-500-normal.woff2') format('woff2');
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}

/* ---------- Tokens ---------- */
:root {
  --bg: #0b0d11;
  --surface: #10131a;
  --surface-2: #141824;
  --line: rgba(255, 255, 255, 0.07);
  --line-strong: rgba(255, 255, 255, 0.14);
  --text: #e9ebee;
  --muted: #97a0ac;
  --faint: #5b6370;
  --for: #7cc7b8;
  --for-soft: rgba(124, 199, 184, 0.09);
  --against: #d99b7c;
  --against-soft: rgba(217, 155, 124, 0.09);
  --radius: 14px;
  --font-display: 'Space Grotesk', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* ---------- Reset ---------- */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  scrollbar-color: var(--line-strong) transparent;
}

body {
  font-family: var(--font-display);
  background: var(--bg);
  color: var(--text);
  height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.container {
  max-width: 760px;
  margin: 0 auto;
  padding: 0 1.5rem;
  width: 100%;
}

/* ---------- Header ---------- */
header {
  background: rgba(11, 13, 17, 0.85);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
  padding: 0.85rem 0;
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-container {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.btn-mute {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  background: transparent;
  border: 1px solid var(--line-strong);
  color: var(--muted);
  padding: 0.45rem 0.9rem;
  border-radius: 999px;
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 500;
  letter-spacing: 0.06em;
  transition: color 0.18s ease, border-color 0.18s ease, background 0.18s ease;
}

.btn-mute:hover {
  color: var(--text);
  border-color: rgba(255, 255, 255, 0.3);
  background: var(--surface-2);
}

.btn-mute:focus-visible {
  outline: 2px solid var(--for);
  outline-offset: 2px;
}

.btn-mute .icon-mute-off {
  display: none;
}

.btn-mute.muted {
  color: var(--faint);
  border-color: var(--line);
}

.btn-mute.muted .icon-mute-on {
  display: none;
}

.btn-mute.muted .icon-mute-off {
  display: inline;
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 0.9rem;
}

.wordmark {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
  text-decoration: none;
}

.live-indicator {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-family: var(--font-mono);
  font-size: 0.62rem;
  font-weight: 500;
  letter-spacing: 0.14em;
  color: var(--muted);
  text-transform: uppercase;
}

.live-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--for);
  animation: breathe 2.4s ease-in-out infinite;
}

@keyframes breathe {
  0%, 100% { opacity: 0.35; }
  50% { opacity: 1; }
}

.btn-new-topic {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  background: transparent;
  border: 1px solid var(--line-strong);
  color: var(--muted);
  padding: 0.45rem 0.9rem;
  border-radius: 999px;
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 500;
  letter-spacing: 0.06em;
  transition: color 0.18s ease, border-color 0.18s ease, background 0.18s ease;
}

.btn-new-topic:hover {
  color: var(--text);
  border-color: rgba(255, 255, 255, 0.3);
  background: var(--surface-2);
}

.btn-new-topic:focus-visible {
  outline: 2px solid var(--for);
  outline-offset: 2px;
}

.btn-new-topic .icon {
  font-size: 0.9rem;
  line-height: 1;
}

/* ---------- Motion (the topic) ---------- */
.motion-section {
  padding: 3rem 0 1.75rem;
  border-bottom: 1px solid var(--line);
}

.motion-label {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-family: var(--font-mono);
  font-size: 0.62rem;
  font-weight: 500;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--faint);
  margin-bottom: 0.9rem;
}

.motion-label::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--line);
}

.motion-text {
  font-size: clamp(1.6rem, 4.2vw, 2.3rem);
  font-weight: 500;
  letter-spacing: -0.025em;
  line-height: 1.12;
  color: var(--text);
}

/* ---------- Matchup ---------- */
.matchup {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border-bottom: 1px solid var(--line);
}

.debater {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  padding: 1.4rem 1.5rem;
}

.debater.for {
  border-right: 1px solid var(--line);
  border-top: 2px solid var(--for);
}

.debater.against {
  text-align: right;
  align-items: flex-end;
  border-top: 2px solid var(--against);
}

.debater .stance {
  font-family: var(--font-mono);
  font-size: 0.6rem;
  font-weight: 500;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.debater.for .stance { color: var(--for); }
.debater.against .stance { color: var(--against); }

.debater .name {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
}

.debater .role {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  color: var(--faint);
  letter-spacing: 0.04em;
}

/* ---------- Feed ---------- */
/* The chat is a bounded window: header, motion, and matchup stay put
   while the transcript scrolls inside the feed. The page itself never
   scrolls, so the conversation can't run away from you. */
.main-content {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding-top: 1.25rem;
}

.feed-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 0.6rem;
  flex-shrink: 0;
}

.feed-controls {
  display: flex;
  align-items: center;
  gap: 0.7rem;
}

.btn-follow {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: transparent;
  border: 1px solid var(--line-strong);
  color: var(--muted);
  padding: 0.28rem 0.7rem;
  border-radius: 999px;
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 0.62rem;
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  transition: color 0.18s ease, border-color 0.18s ease, background 0.18s ease;
}

.btn-follow:hover {
  color: var(--text);
  border-color: rgba(255, 255, 255, 0.3);
}

.btn-follow:focus-visible {
  outline: 2px solid var(--for);
  outline-offset: 2px;
}

.btn-follow[aria-pressed="true"] {
  color: var(--for);
  border-color: var(--for);
  background: var(--for-soft);
}

.btn-follow[aria-pressed="false"] {
  color: var(--faint);
  border-color: var(--line);
}

.feed-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* Floating "back to latest" chip: appears when following and the reader
   scrolls up, so they can snap back without hunting for the bottom. */
.follow-chip {
  position: absolute;
  right: 1rem;
  bottom: 0.9rem;
  z-index: 5;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  background: var(--surface-2);
  border: 1px solid var(--line-strong);
  color: var(--muted);
  padding: 0.5rem 1rem;
  border-radius: 999px;
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 500;
  letter-spacing: 0.06em;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
  transition: color 0.18s ease, border-color 0.18s ease, background 0.18s ease;
}

.follow-chip:hover {
  color: var(--text);
  border-color: var(--for);
  background: var(--surface);
}

.follow-chip:focus-visible {
  outline: 2px solid var(--for);
  outline-offset: 2px;
}

.feed-title {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  font-weight: 500;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--faint);
}

.turn-badge {
  font-family: var(--font-mono);
  font-size: 0.66rem;
  color: var(--muted);
}

.debate-feed {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding-right: 0.5rem;
  padding-bottom: 1.5rem;
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}

.debate-feed::-webkit-scrollbar {
  width: 6px;
}

.debate-feed::-webkit-scrollbar-track {
  background: transparent;
}

.debate-feed::-webkit-scrollbar-thumb {
  background: var(--line-strong);
  border-radius: 3px;
}

/* Round divider */
.round-divider {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  margin: 2.2rem 0 1.4rem;
}

.round-divider:first-child {
  margin-top: 0;
}

.round-divider::before,
.round-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--line);
}

.round-divider span {
  font-family: var(--font-mono);
  font-size: 0.6rem;
  font-weight: 500;
  letter-spacing: 0.18em;
  color: var(--faint);
  text-transform: uppercase;
}

/* Referee ruling */
.ruling {
  margin: 0.4rem 0 0.4rem 0;
  padding: 0.7rem 1rem 0.7rem 1.1rem;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  position: relative;
  animation: turnIn 0.35s ease;
}

.ruling::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0.7rem;
  bottom: 0.7rem;
  width: 2px;
  border-radius: 1px;
  background: var(--faint);
}

.ruling-speaker {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  font-family: var(--font-mono);
  font-size: 0.62rem;
  font-weight: 500;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--faint);
  margin-bottom: 0.3rem;
}

.ruling-body {
  font-size: 0.92rem;
  line-height: 1.5;
  color: var(--muted);
  font-style: italic;
}

/* A single turn */
.turn {
  padding: 0.55rem 0 0.55rem 1.1rem;
  position: relative;
  animation: turnIn 0.35s ease;
}

@keyframes turnIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.turn::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0.7rem;
  bottom: 0.7rem;
  width: 2px;
  border-radius: 1px;
}

.turn.for::before { background: var(--for); }
.turn.against::before { background: var(--against); }

.turn-speaker {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  font-family: var(--font-mono);
  font-size: 0.66rem;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin-bottom: 0.4rem;
}

/* Waveform: 4 bars at the right of each speaker row. Static + dim when
   idle; the bars bounce while this turn's audio is playing. */
.wave {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  height: 12px;
  flex-shrink: 0;
}

.wave i {
  width: 2px;
  border-radius: 1px;
  background: currentColor;
  opacity: 0.18;
  height: 4px;
  transition: opacity 0.2s ease;
}

.turn.playing .wave i,
.ruling.playing .wave i {
  opacity: 0.9;
  animation: wave 0.9s ease-in-out infinite;
}

.turn.playing .wave i:nth-child(2),
.ruling.playing .wave i:nth-child(2) { animation-delay: 0.12s; }
.turn.playing .wave i:nth-child(3),
.ruling.playing .wave i:nth-child(3) { animation-delay: 0.24s; }
.turn.playing .wave i:nth-child(4),
.ruling.playing .wave i:nth-child(4) { animation-delay: 0.36s; }

@keyframes wave {
  0%, 100% { height: 4px; }
  50% { height: 12px; }
}

.turn.for .turn-speaker { color: var(--for); }
.turn.against .turn-speaker { color: var(--against); }

.turn-body {
  font-size: 1rem;
  line-height: 1.6;
  color: var(--text);
  max-width: 62ch;
}

.turn.against .turn-body {
  color: #d3d7dc;
}

/* Welcome / loading state */
.welcome-message {
  text-align: center;
  padding: 3.5rem 1rem;
  color: var(--faint);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
}

.loading-pulse {
  animation: pulse 1.6s infinite ease-in-out;
}

@keyframes pulse {
  0%, 100% { opacity: 0.35; }
  50% { opacity: 1; }
}

/* ---------- Footer ---------- */
footer {
  border-top: 1px solid var(--line);
  padding: 0.85rem 0;
  font-family: var(--font-mono);
  font-size: 0.62rem;
  color: var(--faint);
  letter-spacing: 0.05em;
  flex-shrink: 0;
}

.footer-container {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.connection-status {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.connection-status .dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--for);
}

.connection-status.disconnected .dot {
  background: var(--against);
}

footer .visits {
  color: var(--muted);
}

/* ---------- Audience vote ---------- */
.vote-widget {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.8rem 1.25rem;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}

.vote-head {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  min-width: 0;
}

.vote-label {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  font-weight: 500;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}

.vote-note {
  font-family: var(--font-mono);
  font-size: 0.6rem;
  letter-spacing: 0.04em;
  color: var(--faint);
}

.vote-actions {
  display: flex;
  gap: 0.5rem;
}

.vote-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: transparent;
  border: 1px solid var(--line-strong);
  color: var(--muted);
  padding: 0.4rem 0.85rem;
  border-radius: 999px;
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 500;
  letter-spacing: 0.05em;
  transition: color 0.18s ease, border-color 0.18s ease, background 0.18s ease;
}

.vote-btn:hover:not(:disabled) {
  color: var(--text);
  border-color: rgba(255, 255, 255, 0.3);
  background: var(--surface-2);
}

.vote-btn:disabled {
  opacity: 0.5;
  cursor: default;
}

.vote-btn:focus-visible {
  outline: 2px solid var(--for);
  outline-offset: 2px;
}

.vote-btn .vote-side { color: var(--faint); }
.vote-btn.vote-for .vote-side { color: var(--for); }
.vote-btn.vote-against .vote-side { color: var(--against); }

.vote-btn .vote-name {
  color: var(--faint);
  font-weight: 400;
}

.vote-btn .vote-count {
  color: var(--text);
  min-width: 1.2em;
  text-align: right;
}

.vote-btn.voted {
  cursor: default;
  background: var(--surface-2);
  border-color: var(--line-strong);
}

.vote-btn.voted.vote-for { color: var(--for); border-color: var(--for); background: var(--for-soft); }
.vote-btn.voted.vote-against { color: var(--against); border-color: var(--against); background: var(--against-soft); }

.vote-btn.voted .vote-count { color: inherit; }

/* ---------- Past-debate history panel ---------- */
.history-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(5, 7, 10, 0.6);
  backdrop-filter: blur(3px);
  display: flex;
  justify-content: flex-end;
}

.history-overlay[hidden] {
  display: none;
}

.history-panel {
  width: min(480px, 100%);
  height: 100%;
  background: var(--surface);
  border-left: 1px solid var(--line-strong);
  display: flex;
  flex-direction: column;
  animation: panelIn 0.28s cubic-bezier(0.32, 0.72, 0, 1);
}

@keyframes panelIn {
  from { transform: translateX(24px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

.history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}

.btn-history-close {
  background: transparent;
  border: 1px solid var(--line-strong);
  color: var(--muted);
  width: 2rem;
  height: 2rem;
  border-radius: 999px;
  cursor: pointer;
  font-size: 0.8rem;
  line-height: 1;
  transition: color 0.18s ease, border-color 0.18s ease, background 0.18s ease;
}

.btn-history-close:hover {
  color: var(--text);
  border-color: rgba(255, 255, 255, 0.3);
  background: var(--surface-2);
}

.btn-history-close:focus-visible {
  outline: 2px solid var(--for);
  outline-offset: 2px;
}

.history-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 0 1.25rem 2rem;
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}

.history-list::-webkit-scrollbar {
  width: 6px;
}

.history-list::-webkit-scrollbar-thumb {
  background: var(--line-strong);
  border-radius: 3px;
}

.history-empty {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  line-height: 1.6;
  color: var(--faint);
  padding: 1.5rem 0;
}

.history-item {
  border-bottom: 1px solid var(--line);
}

.history-item-head {
  padding: 1rem 0;
  cursor: pointer;
}

.history-item-head:hover .history-topic {
  color: var(--for);
}

.history-item-meta {
  display: flex;
  gap: 0.8rem;
  align-items: baseline;
  font-family: var(--font-mono);
  font-size: 0.6rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--faint);
  margin-bottom: 0.4rem;
}

.history-topic {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 500;
  letter-spacing: -0.01em;
  line-height: 1.35;
  color: var(--text);
  transition: color 0.18s ease;
}

.history-verdict {
  margin-top: 0.5rem;
  font-size: 0.82rem;
  line-height: 1.5;
  color: var(--muted);
  font-style: italic;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.history-detail {
  padding: 0.2rem 0 1.2rem;
}

.history-detail .turn,
.history-detail .ruling {
  animation: none;
}

.history-round-label {
  font-family: var(--font-mono);
  font-size: 0.6rem;
  font-weight: 500;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--faint);
  margin: 1.2rem 0 0.2rem;
}

.history-next {
  margin-top: 1rem;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--faint);
  line-height: 1.5;
}

.history-next em {
  font-style: normal;
  color: var(--muted);
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  .live-dot { animation: none; }
  .turn { animation: none; }
  .ruling { animation: none; }
  .loading-pulse { animation: none; }
  .turn.playing .wave i,
  .ruling.playing .wave i { animation: none; opacity: 0.9; }
  .history-panel { animation: none; }
}

/* ---------- Mobile ---------- */
@media (max-width: 640px) {
  .container { padding: 0 1rem; }

  .motion-section { padding: 1.6rem 0 1.1rem; }
  .motion-text { font-size: 1.3rem; }

  .debater { padding: 1rem 0.8rem; }
  .debater .name { font-size: 1rem; }

  .turn-body { font-size: 0.95rem; }
  .turn { padding-left: 0.9rem; }
  .main-content { padding-top: 1rem; }

  .btn-mute .mute-label { display: none; }
  .btn-mute { padding: 0.45rem 0.65rem; }
  .btn-new-topic .icon { display: none; }

  .vote-widget { flex-direction: column; align-items: stretch; gap: 0.6rem; padding: 0.8rem 1rem; }
  .vote-head { flex-direction: row; justify-content: space-between; align-items: baseline; }
  .vote-actions { justify-content: stretch; }
  .vote-btn { flex: 1; justify-content: center; }
}
