/* ── Reset & Base ─────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #0d1117;
  --surface:   #161b22;
  --border:    #30363d;
  --accent:    #3b82f6;
  --accent2:   #10b981;
  --danger:    #ef4444;
  --text:      #e6edf3;
  --muted:     #8b949e;
  --yea:       #22c55e;
  --nay:       #ef4444;
  --radius:    12px;
  --touch-min: 44px;
}

html { scroll-behavior: smooth; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 16px;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  -webkit-text-size-adjust: 100%;
}

.hidden { display: none !important; }

/* ── Search Panel ─────────────────────────────────────────────── */
#search-panel {
  width: 100%;
  max-width: 680px;
  padding: 2rem 1rem;
  padding-bottom: max(2rem, env(safe-area-inset-bottom));
  text-align: center;
}

.logo {
  font-size: clamp(2rem, 8vw, 3rem);
  font-weight: 800;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 0.5rem;
}

.tagline {
  color: var(--muted);
  font-size: clamp(0.9rem, 3vw, 1.05rem);
  line-height: 1.5;
  margin-bottom: 2rem;
}

.search-bar {
  display: flex;
  gap: 0.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.5rem;
  margin-bottom: 0.75rem;
}

#query-input {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font-size: 1rem;
  padding: 0.5rem;
  min-height: var(--touch-min);
}
#query-input::placeholder { color: var(--muted); }

#mic-btn {
  flex-shrink: 0;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--muted);
  cursor: pointer;
  min-width: var(--touch-min);
  min-height: var(--touch-min);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.2s, border-color 0.2s, background 0.2s;
  -webkit-tap-highlight-color: transparent;
}
#mic-btn svg { width: 20px; height: 20px; }
#mic-btn:hover,
#mic-btn:focus-visible  { color: var(--accent); border-color: var(--accent); }
#mic-btn[aria-pressed="true"] {
  color: var(--danger);
  border-color: var(--danger);
  background: rgba(239,68,68,0.1);
  animation: pulse 1.2s ease-in-out infinite;
}

.search-submit-btn {
  width: 100%;
  background: var(--accent);
  border: none;
  border-radius: var(--radius);
  color: white;
  cursor: pointer;
  font-size: 1rem;
  font-weight: 700;
  padding: 0.75rem 1.5rem;
  min-height: var(--touch-min);
  transition: opacity 0.2s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
}
.search-submit-btn:hover  { opacity: 0.88; }
.search-submit-btn:active { opacity: 0.75; transform: scale(0.98); }
.search-submit-btn:disabled { opacity: 0.45; cursor: not-allowed; }

.mic-interim {
  color: var(--muted);
  font-style: italic;
  font-size: 0.88rem;
  min-height: 1.4em;
  margin: 0.25rem 0;
}

.mic-status {
  color: var(--danger);
  font-size: 0.85rem;
  margin-top: 0.4rem;
  animation: pulse 1.2s ease-in-out infinite;
}

.error-msg {
  color: var(--danger);
  background: rgba(239,68,68,0.08);
  border: 1px solid rgba(239,68,68,0.35);
  border-radius: 10px;
  padding: 0.85rem 1rem;
  margin-top: 1rem;
  font-size: 0.9rem;
  text-align: left;
  line-height: 1.55;
}

/* ── Loading ──────────────────────────────────────────────────── */
#loading-panel {
  text-align: center;
  padding: 4rem 1.5rem;
}

.spinner {
  width: 52px; height: 52px;
  border: 4px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
  margin: 0 auto 1.5rem;
}

.loader-text { font-size: 1.1rem; font-weight: 600; margin-bottom: 0.5rem; transition: opacity 0.35s ease; }
.loader-sub  { color: var(--muted); font-size: 0.88rem; line-height: 1.55; max-width: 320px; margin: 0 auto; transition: opacity 0.35s ease; }

/* ── Story Panel ──────────────────────────────────────────────── */
#story-panel {
  width: 100%;
  max-width: 960px;
  padding: 0.75rem;
  padding-bottom: max(1rem, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.story-header {
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
}

#back-btn {
  flex-shrink: 0;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.85rem;
  padding: 0.4rem 0.75rem;
  min-height: var(--touch-min);
  white-space: nowrap;
  transition: color 0.2s;
  -webkit-tap-highlight-color: transparent;
}
#back-btn:hover { color: var(--text); }

.story-header-text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

#story-title {
  font-size: clamp(0.92rem, 3vw, 1.1rem);
  font-weight: 700;
  line-height: 1.3;
}

#story-issue-badge {
  align-self: flex-start;
  background: rgba(59,130,246,0.12);
  border: 1px solid rgba(59,130,246,0.3);
  border-radius: 20px;
  color: var(--accent);
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.15rem 0.6rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
}

/* ── Slideshow ────────────────────────────────────────────────── */
.slideshow {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.slide-image-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 7;
  background: #0a0f18;
  overflow: hidden;
  touch-action: pan-y;
}

@media (max-width: 480px) {
  .slide-image-wrap { aspect-ratio: 4 / 3; }
}

#slide-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: opacity 0.45s ease;
}

#slide-badge {
  position: absolute;
  top: 10px; left: 10px;
  background: rgba(0,0,0,0.68);
  border-radius: 6px;
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.18rem 0.55rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  pointer-events: none;
}

.slide-tap-zone {
  position: absolute;
  top: 0; bottom: 0;
  width: 28%;
  background: transparent;
  border: none;
  cursor: pointer;
  z-index: 2;
  -webkit-tap-highlight-color: transparent;
}
.slide-tap-zone.left  { left: 0; }
.slide-tap-zone.right { right: 0; }

.slide-image-wrap.no-image::after {
  content: 'Illustration unavailable';
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  pointer-events: none;
}

/* Fixed-height info panel keeps the carousel stable regardless of slide content */
.slide-info {
  height: 220px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  border-top: 1px solid var(--border);
}

.caption-bar {
  padding: 0.85rem 1rem;
  flex-shrink: 0;
}

#slide-caption {
  font-size: clamp(0.88rem, 2.5vw, 1rem);
  line-height: 1.65;
}

/* ── Vote Breakdown ───────────────────────────────────────────── */
.vote-breakdown {
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.vote-bars { display: flex; flex-direction: column; gap: 0.55rem; margin-bottom: 0.6rem; }

.vote-bar {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  font-size: 0.88rem;
}

.bar-label { width: 34px; font-weight: 700; }

.bar-track {
  flex: 1;
  max-width: 220px;
  height: 12px;
  background: rgba(255,255,255,0.07);
  border-radius: 6px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  width: 0;
  border-radius: 6px;
  transition: width 0.9s cubic-bezier(0.16, 1, 0.3, 1);
}
.yea-bar .bar-fill { background: var(--yea); }
.nay-bar .bar-fill { background: var(--nay); }
.bar-count { font-weight: 700; min-width: 36px; }

.party-breakdown { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.party-pill {
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--muted);
  font-size: 0.75rem;
  padding: 0.15rem 0.55rem;
}

/* ── Sponsor Card ─────────────────────────────────────────────── */
.sponsor-card {
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.sponsor-card h3 { font-size: 1rem; margin-bottom: 0.25rem; }
#sponsor-meta { color: var(--muted); font-size: 0.85rem; }

/* ── Controls ─────────────────────────────────────────────────── */
.controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.65rem;
  padding: 0.55rem 0;
}

.controls button {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
  font-size: 1.6rem;
  line-height: 1;
  min-width: var(--touch-min);
  min-height: var(--touch-min);
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.controls button:hover:not(:disabled) { background: var(--border); }
.controls button:disabled { opacity: 0.3; cursor: not-allowed; }

.slide-dots { display: flex; gap: 0; flex-wrap: wrap; justify-content: center; }
.dot {
  min-width: 32px;
  min-height: var(--touch-min);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.dot::after {
  content: '';
  width: 8px; height: 8px;
  background: var(--border);
  border-radius: 50%;
  transition: background 0.2s, transform 0.2s;
}
.dot.active::after { background: var(--accent); transform: scale(1.4); }

.audio-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  padding-bottom: 0.3rem;
}

#play-pause-btn {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.85rem;
  padding: 0.4rem 0.9rem;
  min-height: var(--touch-min);
  transition: color 0.2s;
  -webkit-tap-highlight-color: transparent;
}
#play-pause-btn:hover { color: var(--text); }
#slide-counter { color: var(--muted); font-size: 0.85rem; }

/* ── Debug Panel ──────────────────────────────────────────────── */
.debug-panel {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.debug-panel summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.5rem 0.75rem;
  user-select: none;
  background: rgba(255,255,255,0.03);
  list-style: none;
}
#debug-log {
  color: var(--muted);
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 180px;
  overflow-y: auto;
  padding: 0.5rem 0.75rem;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.7rem;
  line-height: 1.6;
}
.debug-error { color: var(--danger); }
.debug-warn  { color: #f59e0b; }
.debug-ok    { color: var(--accent2); }

/* ── Animations ───────────────────────────────────────────────── */
@keyframes spin  { to { transform: rotate(360deg); } }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }
