/* =========================================================
   Rebuttal — AI Debate Coach
   Design tokens
   ========================================================= */

:root {
  --grad-start: #667eea;
  --grad-end: #764ba2;

  --mild: #f5b754;
  --moderate: #f2994a;
  --severe: #eb5757;
  --logic: #2dd4bf;

  --font-display: 'Poppins', sans-serif;
  --font-body: 'Inter', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  --radius-lg: 22px;
  --radius-md: 14px;
  --radius-sm: 9px;

  --shadow-soft: 0 8px 30px rgba(20, 10, 50, 0.25);
}

body[data-theme="dark"] {
  --bg-0: #0e0c1a;
  --bg-1: #14112450;
  --glass-bg: rgba(255, 255, 255, 0.06);
  --glass-border: rgba(255, 255, 255, 0.12);
  --text-0: #f5f3fb;
  --text-1: #c9c4de;
  --text-2: #8d87a8;
  --input-bg: rgba(255, 255, 255, 0.06);
  --input-border: rgba(255, 255, 255, 0.14);
  --track-bg: rgba(255, 255, 255, 0.08);
}

body[data-theme="light"] {
  --bg-0: #f3f1fb;
  --bg-1: #ffffff80;
  --glass-bg: rgba(255, 255, 255, 0.62);
  --glass-border: rgba(120, 100, 180, 0.18);
  --text-0: #241f3d;
  --text-1: #4c4670;
  --text-2: #786fa0;
  --input-bg: rgba(255, 255, 255, 0.75);
  --input-border: rgba(120, 100, 180, 0.25);
  --track-bg: rgba(120, 100, 180, 0.12);
}

body[data-contrast="high"] {
  --glass-border: rgba(255, 255, 255, 0.55);
  --text-1: var(--text-0);
  --text-2: var(--text-0);
}
body[data-contrast="high"][data-theme="light"] {
  --glass-border: rgba(40, 30, 70, 0.55);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg-0);
  color: var(--text-0);
  font-family: var(--font-body);
  font-size: calc(16px * var(--fontscale, 1));
  transition: background 0.4s ease, color 0.4s ease;
  overflow-x: hidden;
}

h1, h2, h3, h4, button, .brand-name, .btn { font-family: var(--font-display); }

a { color: inherit; }

:focus-visible {
  outline: 2px solid var(--grad-start);
  outline-offset: 2px;
  border-radius: 6px;
}

/* =========================================================
   Background aurora
   ========================================================= */

.bg-aurora {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  pointer-events: none;
}
.blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(90px);
  opacity: 0.45;
  animation: drift 22s ease-in-out infinite alternate;
}
body[data-theme="light"] .blob { opacity: 0.3; }
.blob-a { width: 480px; height: 480px; background: var(--grad-start); top: -120px; left: -100px; }
.blob-b { width: 420px; height: 420px; background: var(--grad-end); bottom: -140px; right: -80px; animation-delay: -6s; }
.blob-c { width: 320px; height: 320px; background: #8f6fe0; top: 40%; left: 60%; animation-delay: -12s; }

@keyframes drift {
  from { transform: translate(0, 0) scale(1); }
  to { transform: translate(40px, 30px) scale(1.08); }
}

@media (prefers-reduced-motion: reduce) {
  .blob { animation: none; }
  * { scroll-behavior: auto !important; }
}

/* =========================================================
   Glass utility
   ========================================================= */

.glass {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  box-shadow: var(--shadow-soft);
}

/* =========================================================
   Layout shell
   ========================================================= */

.app { max-width: 1240px; margin: 0 auto; padding: 20px 24px 60px; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 20px;
  margin-bottom: 28px;
  position: sticky;
  top: 16px;
  z-index: 40;
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; }
.brand-mark {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: 10px;
  background: linear-gradient(135deg, var(--grad-start), var(--grad-end));
  color: white; font-weight: 800;
}
.brand-name { font-size: 1.1rem; letter-spacing: 0.2px; }

.tabs { display: flex; gap: 4px; background: var(--track-bg); padding: 4px; border-radius: 999px; }
.tab {
  border: none; background: transparent; color: var(--text-1);
  padding: 8px 18px; border-radius: 999px; cursor: pointer; font-weight: 600; font-size: 0.92rem;
  transition: all 0.2s ease;
}
.tab.is-active { background: linear-gradient(135deg, var(--grad-start), var(--grad-end)); color: white; }

.topbar-actions { display: flex; gap: 6px; }
.icon-btn {
  width: 36px; height: 36px; border-radius: 10px; border: 1px solid var(--glass-border);
  background: var(--input-bg); color: var(--text-0); cursor: pointer; font-size: 0.95rem;
  display: inline-flex; align-items: center; justify-content: center;
  transition: transform 0.15s ease, background 0.2s ease;
}
.icon-btn:hover { transform: translateY(-1px); background: var(--glass-bg); }
.icon-btn[aria-pressed="true"] { color: var(--grad-start); border-color: var(--grad-start); }

.main { position: relative; }

.view { display: none; animation: fade-in 0.35s ease; }
.view.is-active { display: block; }

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

/* =========================================================
   Buttons & inputs
   ========================================================= */

.btn {
  border: none; border-radius: 999px; padding: 12px 22px; font-weight: 600; font-size: 0.95rem;
  cursor: pointer; transition: transform 0.15s ease, box-shadow 0.2s ease, opacity 0.2s ease;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn-primary {
  background: linear-gradient(135deg, var(--grad-start), var(--grad-end));
  color: white;
  box-shadow: 0 10px 24px rgba(102, 126, 234, 0.35);
}
.btn-ghost {
  background: var(--input-bg); color: var(--text-0); border: 1px solid var(--input-border);
}
.btn-sm { padding: 8px 14px; font-size: 0.82rem; }
.btn-block { width: 100%; margin-top: 6px; }

.text-input, .select-input {
  width: 100%; padding: 12px 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--input-border); background: var(--input-bg); color: var(--text-0);
  font-family: var(--font-body); font-size: 0.95rem;
}
.text-input::placeholder { color: var(--text-2); }

.field-label { display: block; font-size: 0.82rem; font-weight: 600; color: var(--text-1); margin: 16px 0 6px; }
.field-group { margin-bottom: 4px; }
.field-hint { font-size: 0.78rem; color: var(--text-2); margin: 6px 2px 0; min-height: 1.1em; }

.topic-row { display: flex; gap: 8px; }
.topic-row .text-input { flex: 1; }

.segmented { display: flex; background: var(--track-bg); border-radius: 999px; padding: 4px; gap: 4px; }
.segment {
  flex: 1; border: none; background: transparent; padding: 9px 10px; border-radius: 999px;
  color: var(--text-1); font-weight: 600; font-size: 0.85rem; cursor: pointer; transition: all 0.2s ease;
}
.segment.is-active { background: linear-gradient(135deg, var(--grad-start), var(--grad-end)); color: white; }

/* =========================================================
   Setup view
   ========================================================= */

.setup-grid { display: grid; grid-template-columns: 1.15fr 0.85fr; gap: 28px; align-items: start; }

.eyebrow {
  text-transform: uppercase; letter-spacing: 1.6px; font-size: 0.74rem; font-weight: 700;
  color: var(--grad-start); margin: 0 0 10px;
}
.hero-title { font-size: 2.5rem; line-height: 1.15; margin: 0 0 16px; font-weight: 700; }
.hero-sub { color: var(--text-1); font-size: 1.02rem; line-height: 1.6; max-width: 46ch; margin-bottom: 26px; }

.hero-scanner-demo { padding: 22px 24px; }
.scanner-demo-text { font-size: 1.02rem; line-height: 1.7; color: var(--text-0); margin: 0 0 14px; }
.scanner-demo-tags { display: flex; gap: 8px; flex-wrap: wrap; }

.fx-underline { text-decoration: underline wavy; text-underline-offset: 4px; text-decoration-thickness: 2px; }
.fx-mild { text-decoration-color: var(--mild); }
.fx-moderate { text-decoration-color: var(--moderate); }
.fx-severe { text-decoration-color: var(--severe); }

.setup-card { padding: 26px 28px 28px; }
.card-title { font-size: 1.25rem; margin: 0 0 6px; font-weight: 700; }
.setup-note { font-size: 0.8rem; color: var(--moderate); margin-top: 14px; line-height: 1.5; }
.setup-note code { background: var(--track-bg); padding: 1px 6px; border-radius: 6px; }

.fallacy-chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 12px; border-radius: 999px;
  font-size: 0.76rem; font-weight: 700; color: white; white-space: nowrap;
}
.fallacy-chip.mild, .fallacy-chip::before { }
.fallacy-chip.mild { background: var(--mild); color: #402c00; }
.fallacy-chip.moderate { background: var(--moderate); color: #3a1900; }
.fallacy-chip.severe { background: var(--severe); color: #3a0000; }

/* =========================================================
   Debate view
   ========================================================= */

.debate-grid { display: grid; grid-template-columns: 1fr 300px; gap: 24px; align-items: start; }

.debate-main { padding: 20px 22px; display: flex; flex-direction: column; height: calc(100vh - 190px); min-height: 520px; }

.debate-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 10px; }
.debate-topic { font-weight: 700; font-size: 1.05rem; margin: 0 0 2px; }
.debate-meta { color: var(--text-2); font-size: 0.82rem; margin: 0; }
.timer-wrap { display: flex; align-items: center; gap: 10px; }
.timer { font-family: var(--font-mono); font-size: 1.3rem; font-weight: 600; color: var(--grad-start); min-width: 3.6ch; text-align: right; }
.timer.is-low { color: var(--severe); animation: pulse-timer 1s ease-in-out infinite; }
@keyframes pulse-timer { 0%,100% { opacity: 1; } 50% { opacity: 0.45; } }

.transcript { flex: 1; overflow-y: auto; padding: 10px 4px; display: flex; flex-direction: column; gap: 14px; }
.transcript::-webkit-scrollbar { width: 8px; }
.transcript::-webkit-scrollbar-thumb { background: var(--track-bg); border-radius: 8px; }

.bubble { max-width: 82%; padding: 12px 16px; border-radius: var(--radius-md); line-height: 1.55; font-size: 0.94rem; animation: bubble-in 0.25s ease; }
@keyframes bubble-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
.bubble-text { margin: 0; white-space: pre-wrap; }
.bubble.user { align-self: flex-end; background: linear-gradient(135deg, var(--grad-start), var(--grad-end)); color: white; }
.bubble.ai { align-self: flex-start; background: var(--input-bg); border: 1px solid var(--input-border); }
.bubble-flags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }

.typing-indicator { display: flex; align-items: center; gap: 8px; color: var(--text-2); font-size: 0.82rem; padding: 6px 4px; }
.typing-indicator span { width: 6px; height: 6px; border-radius: 50%; background: var(--text-2); animation: bounce-dot 1.2s infinite ease-in-out; }
.typing-indicator span:nth-child(2) { animation-delay: 0.15s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.3s; }
@keyframes bounce-dot { 0%, 80%, 100% { transform: translateY(0); opacity: 0.4; } 40% { transform: translateY(-4px); opacity: 1; } }

.composer { margin-top: 12px; }
.composer-scan-wrap { position: relative; }
.composer-highlight {
  position: absolute; inset: 0; padding: 12px 14px; margin: 0; overflow: hidden;
  font-family: var(--font-body); font-size: 0.95rem; line-height: 1.5; white-space: pre-wrap; word-wrap: break-word;
  color: transparent; pointer-events: none; border-radius: var(--radius-sm);
}
.composer-highlight mark { background: transparent; text-decoration: underline wavy; text-underline-offset: 4px; text-decoration-thickness: 2px; border-radius: 3px; }
.composer-input {
  position: relative; width: 100%; resize: vertical; padding: 12px 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--input-border); background: transparent; color: var(--text-0);
  font-family: var(--font-body); font-size: 0.95rem; line-height: 1.5; caret-color: var(--grad-start);
}
body[data-theme="dark"] .composer-input { background: rgba(255,255,255,0.04); }
body[data-theme="light"] .composer-input { background: rgba(255,255,255,0.5); }

.composer-row { display: flex; justify-content: space-between; align-items: center; margin-top: 10px; gap: 10px; flex-wrap: wrap; }
.composer-live-flags { display: flex; gap: 6px; flex-wrap: wrap; }
.composer-buttons { display: flex; gap: 8px; align-items: center; margin-left: auto; }
.icon-btn.is-recording { color: var(--severe); border-color: var(--severe); animation: pulse-timer 1s infinite; }

.debate-sidebar { display: flex; flex-direction: column; gap: 18px; }
.sidebar-card { padding: 18px 18px 20px; }
.sidebar-title { font-size: 0.9rem; font-weight: 700; margin: 0 0 12px; }
.fallacy-feed { display: flex; flex-direction: column; gap: 10px; max-height: 260px; overflow-y: auto; }
.fallacy-feed-item { padding: 10px 12px; border-radius: var(--radius-sm); background: var(--track-bg); font-size: 0.8rem; }
.fallacy-feed-item .ff-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; font-weight: 700; }
.fallacy-feed-item .ff-quote { color: var(--text-2); font-style: italic; }
.empty-note { color: var(--text-2); font-size: 0.82rem; }

.tone-bar-track { height: 10px; border-radius: 999px; background: linear-gradient(90deg, var(--logic), var(--moderate)); overflow: hidden; position: relative; }
.tone-bar-fill { position: absolute; top:0; right:0; bottom:0; background: var(--track-bg); }
.tone-bar-labels { display: flex; justify-content: space-between; font-size: 0.72rem; color: var(--text-2); margin-top: 6px; }

/* =========================================================
   Results view
   ========================================================= */

.results-grid { display: grid; grid-template-columns: 1.2fr 1fr 1fr; gap: 22px; align-items: start; }
.results-card { padding: 22px 24px; }
.results-summary-text { color: var(--text-1); line-height: 1.6; margin-bottom: 18px; }
.score-chart-wrap { display: flex; justify-content: center; margin-bottom: 12px; }
.score-bars { display: flex; flex-direction: column; gap: 10px; }
.score-bar-row { display: grid; grid-template-columns: 110px 1fr 34px; align-items: center; gap: 10px; font-size: 0.82rem; }
.score-bar-track { height: 8px; border-radius: 999px; background: var(--track-bg); overflow: hidden; }
.score-bar-fill { height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--grad-start), var(--grad-end)); }
.score-bar-num { font-family: var(--font-mono); text-align: right; color: var(--text-1); }

.bullet-list { margin: 0 0 18px; padding-left: 18px; color: var(--text-1); font-size: 0.88rem; line-height: 1.6; }
.bullet-list.numbered { list-style: decimal; }

.results-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0; }

/* =========================================================
   Library view
   ========================================================= */

.library-head { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.library-head .text-input { max-width: 320px; }
.library-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; margin-bottom: 26px; }
.fallacy-card { padding: 18px 20px; }
.fallacy-card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 8px; }
.fallacy-card-name { margin: 0; font-size: 1.02rem; }
.fallacy-card-category { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.6px; color: var(--text-2); white-space: nowrap; }
.fallacy-card-def { color: var(--text-1); font-size: 0.87rem; line-height: 1.55; margin: 0 0 10px; }
.fallacy-card-example { font-size: 0.82rem; color: var(--text-2); font-style: italic; margin: 0 0 10px; }
.fallacy-card-fix { font-size: 0.8rem; color: var(--logic); margin: 0; }
.fallacy-card-fix::before { content: "Fix: "; font-weight: 700; }

.glossary-card { padding: 22px 24px; }
.glossary-list { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 24px; margin: 0; }
.glossary-list dt { font-weight: 700; font-size: 0.88rem; }
.glossary-list dd { margin: 2px 0 0; color: var(--text-1); font-size: 0.82rem; line-height: 1.5; }

/* =========================================================
   Dashboard view
   ========================================================= */

.stat-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; margin-bottom: 22px; }
.stat-card { padding: 18px; text-align: center; }
.stat-value { font-family: var(--font-mono); font-size: 1.8rem; font-weight: 700; margin: 0; background: linear-gradient(135deg, var(--grad-start), var(--grad-end)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.stat-label { font-size: 0.76rem; color: var(--text-2); margin: 4px 0 0; }

.dashboard-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 20px; }
.dashboard-card { padding: 20px 22px; margin-bottom: 20px; }

.badge-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 12px; }
.badge-item { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 14px 10px; border-radius: var(--radius-sm); background: var(--track-bg); text-align: center; }
.badge-item.is-locked { opacity: 0.35; filter: grayscale(1); }
.badge-emoji { font-size: 1.6rem; }
.badge-name { font-size: 0.72rem; color: var(--text-1); font-weight: 600; }

.history-list { display: flex; flex-direction: column; gap: 8px; }
.history-item {
  display: flex; justify-content: space-between; align-items: center; width: 100%;
  padding: 12px 14px; border-radius: var(--radius-sm); background: var(--track-bg);
  border: none; cursor: pointer; text-align: left; color: var(--text-0); font-family: var(--font-body);
}
.history-topic { margin: 0; font-weight: 600; font-size: 0.88rem; }
.history-meta { margin: 2px 0 0; font-size: 0.76rem; color: var(--text-2); }
.history-score { font-family: var(--font-mono); font-weight: 700; color: var(--grad-start); }

/* =========================================================
   Toasts, modal, confetti
   ========================================================= */

.toast-stack { position: fixed; bottom: 22px; right: 22px; z-index: 200; display: flex; flex-direction: column; gap: 10px; }
.toast {
  padding: 12px 18px; border-radius: var(--radius-sm); font-size: 0.85rem; font-weight: 600;
  background: var(--glass-bg); border: 1px solid var(--glass-border); backdrop-filter: blur(16px);
  color: var(--text-0); box-shadow: var(--shadow-soft); animation: toast-in 0.25s ease;
}
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

.modal-overlay { position: fixed; inset: 0; background: rgba(5, 3, 15, 0.55); z-index: 300; display: flex; align-items: center; justify-content: center; }
.modal-overlay[hidden] { display: none; }
.modal { padding: 26px 28px; max-width: 380px; width: 90%; }
.shortcut-list { list-style: none; padding: 0; margin: 14px 0 20px; display: flex; flex-direction: column; gap: 10px; font-size: 0.88rem; color: var(--text-1); }
kbd { background: var(--track-bg); padding: 3px 8px; border-radius: 6px; font-family: var(--font-mono); font-size: 0.78rem; margin-right: 4px; }

.confetti-canvas { position: fixed; inset: 0; z-index: 250; pointer-events: none; }

/* =========================================================
   Responsive
   ========================================================= */

@media (max-width: 980px) {
  .setup-grid { grid-template-columns: 1fr; }
  .debate-grid { grid-template-columns: 1fr; }
  .debate-main { height: auto; min-height: 460px; }
  .results-grid { grid-template-columns: 1fr; }
  .dashboard-grid { grid-template-columns: 1fr; }
  .glossary-list { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  .app { padding: 14px 12px 40px; }
  .hero-title { font-size: 1.9rem; }
  .topbar { flex-direction: column; align-items: stretch; gap: 10px; }
  .tabs { justify-content: center; }
  .topbar-actions { justify-content: center; }
  .debate-header { flex-direction: column; }
  .timer-wrap { width: 100%; justify-content: space-between; }
}

/* =========================================================
   Print (used by the "Print / save as PDF" results button)
   ========================================================= */

@media print {
  .bg-aurora, .topbar, .toast-stack, .confetti-canvas, .tabs,
  #view-setup, #view-debate, #view-library, #view-dashboard,
  .results-actions, .modal-overlay { display: none !important; }

  body, .app { background: white !important; color: black !important; }
  .glass {
    background: white !important; border: 1px solid #ccc !important;
    box-shadow: none !important; backdrop-filter: none !important;
  }
  .results-grid { display: block !important; }
  .results-card { break-inside: avoid; margin-bottom: 16px; }
}
