/* ── Reset & base ─────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

:root {
  --bg: #f5f4f0;
  --surface: #ffffff;
  --border: #e2e0d9;
  --text: #1a1917;
  --muted: #706e67;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-light: #eef2ff;
  --accent-border: #c7d2fe;
  --green: #16a34a;
  --green-light: #dcfce7;
  --error-bg: #fff5f5;
  --error-border: #fca5a5;
  --error-text: #b91c1c;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-xs: 6px;
  --shadow: 0 1px 4px rgba(0,0,0,.06), 0 4px 24px rgba(0,0,0,.06);
  --shadow-sm: 0 1px 3px rgba(0,0,0,.08);
  --font: 'Inter', system-ui, -apple-system, sans-serif;
  --mono: 'SFMono-Regular', 'Consolas', monospace;
}

html { font-size: 16px; }
body { font-family: var(--font); background: var(--bg); color: var(--text); min-height: 100vh; line-height: 1.6; }

/* ── Page wrapper ─────────────────────────────────────── */
.page-wrapper { min-height: 100vh; display: flex; flex-direction: column; align-items: center; padding: 0 1rem; }
.results-page { padding: 0; }

/* ── Hero ─────────────────────────────────────────────── */
.hero { text-align: center; padding: 5rem 1rem 2.5rem; }
.logo-mark { font-size: 2rem; color: var(--accent); line-height: 1; margin-bottom: 0.75rem; display: block; }
.logo-mark.small { font-size: 1.1rem; }
.site-title { font-size: clamp(2rem, 5vw, 3rem); font-weight: 800; letter-spacing: -0.03em; }
.tagline { margin-top: 0.5rem; font-size: 1.1rem; color: var(--muted); }

/* ── Homepage card ────────────────────────────────────── */
.card-home { width: 100%; max-width: 660px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 2.25rem 2rem; margin-bottom: 2rem; }

/* ── Error banner ─────────────────────────────────────── */
.error-banner { display: flex; align-items: flex-start; gap: 0.6rem; background: var(--error-bg); border: 1px solid var(--error-border); border-radius: var(--radius-sm); color: var(--error-text); padding: 0.85rem 1rem; margin-bottom: 1.5rem; font-size: 0.92rem; }
.error-icon { flex-shrink: 0; padding-top: 1px; }

/* ── Form ─────────────────────────────────────────────── */
.url-form { display: flex; flex-direction: column; gap: 0.6rem; }
.form-label { font-size: 0.9rem; font-weight: 600; }
.input-row { display: flex; gap: 0.6rem; flex-wrap: wrap; }
.url-input { flex: 1; min-width: 0; padding: 0.7rem 1rem; border: 1.5px solid var(--border); border-radius: var(--radius-sm); font-size: 0.95rem; font-family: var(--font); background: var(--bg); color: var(--text); outline: none; transition: border-color .15s, box-shadow .15s; }
.url-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(79,70,229,.12); }
.submit-btn { padding: 0.7rem 1.35rem; background: var(--accent); color: #fff; border: none; border-radius: var(--radius-sm); font-size: 0.95rem; font-weight: 600; font-family: var(--font); cursor: pointer; white-space: nowrap; transition: background .15s, transform .1s; }
.submit-btn:hover { background: var(--accent-hover); }
.submit-btn:active { transform: scale(.98); }
.hint { font-size: 0.8rem; color: var(--muted); }

/* ── Or divider ───────────────────────────────────────── */
.or-divider { display: flex; align-items: center; gap: 0.75rem; margin: 1.5rem 0 0; color: var(--muted); font-size: 0.8rem; }
.or-divider::before, .or-divider::after { content: ''; flex: 1; height: 1px; background: var(--border); }

/* ── Manual paste section ─────────────────────────────── */
.manual-section { margin-top: 0; }
.manual-toggle { width: 100%; display: flex; align-items: center; justify-content: space-between; background: none; border: none; padding: 0.65rem 0; font-family: var(--font); font-size: 0.88rem; font-weight: 600; color: var(--muted); cursor: pointer; transition: color .15s; }
.manual-toggle:hover { color: var(--text); }
.manual-toggle-icon { font-size: 0.65rem; }
.manual-body { padding-top: 0.5rem; display: flex; flex-direction: column; gap: 0.5rem; }
.manual-form { display: flex; flex-direction: column; gap: 0.5rem; }
.optional { font-weight: 400; color: var(--muted); }
.transcript-input { width: 100%; padding: 0.7rem 1rem; border: 1.5px solid var(--border); border-radius: var(--radius-sm); font-size: 0.88rem; font-family: var(--font); background: var(--bg); color: var(--text); outline: none; resize: vertical; line-height: 1.6; transition: border-color .15s, box-shadow .15s; }
.transcript-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(79,70,229,.12); }
.manual-submit-btn { width: 100%; margin-top: 0.25rem; }

/* ── Results header ───────────────────────────────────── */
.results-header { width: 100%; background: var(--surface); border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; padding: 0.9rem 1.5rem; position: sticky; top: 0; z-index: 10; box-shadow: var(--shadow-sm); }
.back-link { font-size: 0.85rem; color: var(--accent); text-decoration: none; font-weight: 600; }
.back-link:hover { opacity: .75; }
.header-center { display: flex; align-items: center; gap: 0.35rem; }
.site-title-small { font-size: 1rem; font-weight: 800; letter-spacing: -0.02em; }
.watch-link { font-size: 0.85rem; color: var(--accent); text-decoration: none; font-weight: 600; }
.watch-link:hover { opacity: .75; }

/* ── Study main ───────────────────────────────────────── */
.study-main { width: 100%; max-width: 900px; padding: 1.5rem 1.5rem 3rem; flex: 1; }

/* ── Stats bar ────────────────────────────────────────── */
.stats-bar { display: flex; gap: 1.25rem; flex-wrap: wrap; align-items: center; margin-bottom: 1.25rem; font-size: 0.85rem; color: var(--muted); }
.stat strong { color: var(--text); }
.ai-badge { display: inline-flex; align-items: center; gap: 0.3rem; background: var(--green-light); color: var(--green); border: 1px solid #bbf7d0; border-radius: 20px; padding: 0.2rem 0.65rem; font-size: 0.75rem; font-weight: 700; letter-spacing: 0.01em; }
.ai-badge.fallback { background: var(--bg); color: var(--muted); border-color: var(--border); }
.cache-badge { display: inline-flex; align-items: center; gap: 0.3rem; background: #fefce8; color: #a16207; border: 1px solid #fde68a; border-radius: 20px; padding: 0.2rem 0.65rem; font-size: 0.75rem; font-weight: 700; letter-spacing: 0.01em; }

/* ── Tab bar ──────────────────────────────────────────── */
.tab-bar { display: flex; gap: 0.3rem; flex-wrap: wrap; margin-bottom: 1.25rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 0.3rem; }
.tab-btn { flex: 1; min-width: max-content; padding: 0.5rem 0.85rem; border: none; border-radius: var(--radius-xs); background: transparent; font-size: 0.84rem; font-weight: 600; font-family: var(--font); color: var(--muted); cursor: pointer; transition: background .12s, color .12s; white-space: nowrap; }
.tab-btn:hover { background: var(--bg); color: var(--text); }
.tab-btn.active { background: var(--accent); color: #fff; }

/* ── Tab panels ───────────────────────────────────────── */
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ── Card ─────────────────────────────────────────────── */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 2rem 2rem 2.25rem; }
.card-title { font-size: 1.25rem; font-weight: 700; letter-spacing: -0.02em; margin-bottom: 0.35rem; }
.card-subtitle { font-size: 0.83rem; color: var(--muted); margin-bottom: 1.75rem; line-height: 1.5; }

/* ── Timestamp badge ──────────────────────────────────── */
.ts-badge { display: inline-flex; align-items: center; font-size: 0.72rem; font-weight: 700; font-family: var(--mono); color: var(--accent); background: var(--accent-light); border: 1px solid var(--accent-border); border-radius: var(--radius-xs); padding: 0.18rem 0.45rem; text-decoration: none; white-space: nowrap; flex-shrink: 0; transition: background .1s; }
.ts-badge:hover { background: #e0e7ff; }
.ts-badge.small { font-size: 0.68rem; padding: 0.15rem 0.4rem; }

/* ── Outline ──────────────────────────────────────────── */
.outline-list { display: flex; flex-direction: column; }
.outline-item { display: flex; align-items: flex-start; gap: 1rem; padding: 1.1rem 0; border-bottom: 1px solid var(--border); }
.outline-item:last-child { border-bottom: none; padding-bottom: 0; }
.outline-num { flex-shrink: 0; width: 1.8rem; height: 1.8rem; display: flex; align-items: center; justify-content: center; background: var(--accent); color: #fff; border-radius: 50%; font-size: 0.72rem; font-weight: 700; margin-top: 0.15rem; }
.outline-body { display: flex; align-items: flex-start; gap: 0.75rem; flex: 1; flex-wrap: wrap; }
.outline-text { flex: 1; min-width: 180px; display: flex; flex-direction: column; gap: 0.3rem; }
.outline-title { font-size: 0.97rem; font-weight: 600; color: var(--text); line-height: 1.45; }
.outline-desc { font-size: 0.84rem; color: var(--muted); line-height: 1.6; max-width: 65ch; }
.outline-ts-link { font-size: 0.78rem; font-weight: 500; color: var(--accent); text-decoration: none; white-space: nowrap; flex-shrink: 0; opacity: 0.75; margin-top: 0.18rem; transition: opacity .15s; }
.outline-ts-link:hover { opacity: 1; text-decoration: underline; }

/* ── Outline collapsible section notes ────────────────── */
.outline-details { margin-top: 0.1rem; }
.outline-details .outline-desc { display: block; margin-top: 0.4rem; }
.outline-show-more { list-style: none; display: inline-flex; align-items: center; gap: 0.3rem; font-size: 0.76rem; font-weight: 500; color: var(--accent); opacity: 0.7; cursor: pointer; user-select: none; transition: opacity .15s; }
.outline-show-more::-webkit-details-marker { display: none; }
.outline-show-more::before { content: '▸'; font-size: 0.6rem; display: inline-block; transition: transform .15s; }
.outline-show-more:hover { opacity: 1; }
.outline-details[open] .outline-show-more { opacity: 0.85; }
.outline-details[open] .outline-show-more::before { transform: rotate(90deg); }

/* ── Summary ──────────────────────────────────────────── */
.summary-prose { display: flex; flex-direction: column; gap: 1.25rem; }
.summary-prose p { font-size: 0.96rem; line-height: 1.85; color: var(--text); max-width: 72ch; }

/* ── Key concepts ─────────────────────────────────────── */
.concepts-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 1rem; }
.concept-card { background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 1.1rem 1.15rem; display: flex; flex-direction: column; gap: 0.45rem; }
.concept-term { font-size: 0.95rem; font-weight: 700; color: var(--text); line-height: 1.3; }
.concept-desc { font-size: 0.82rem; color: var(--muted); line-height: 1.6; }
.concept-desc.muted { font-style: italic; }

/* ── Flashcards ───────────────────────────────────────── */
.flashcard-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 1.1rem; }
.flashcard { cursor: pointer; height: 220px; perspective: 1000px; }
.flashcard-inner { position: relative; width: 100%; height: 100%; transition: transform 0.4s ease; transform-style: preserve-3d; }
.flashcard.flipped .flashcard-inner { transform: rotateY(180deg); }
.flashcard-front, .flashcard-back { position: absolute; inset: 0; border-radius: var(--radius-sm); border: 1px solid var(--border); backface-visibility: hidden; -webkit-backface-visibility: hidden; display: flex; flex-direction: column; padding: 1.25rem; }
.flashcard-front { background: var(--surface); }
.flashcard-back { background: var(--accent); color: #fff; transform: rotateY(180deg); border-color: var(--accent); }
.fc-num { font-size: 0.68rem; font-weight: 700; color: var(--muted); margin-bottom: 0.5rem; }
.flashcard-back .fc-num { color: rgba(255,255,255,.55); }
.fc-question { font-size: 0.92rem; font-weight: 600; line-height: 1.55; flex: 1; color: var(--text); }
.fc-answer { font-size: 0.85rem; line-height: 1.65; flex: 1; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 5; -webkit-box-orient: vertical; }
.fc-hint { font-size: 0.7rem; color: var(--muted); margin-top: auto; padding-top: 0.5rem; }
.flashcard-back .fc-hint { color: rgba(255,255,255,.55); }

/* ── Full transcript ──────────────────────────────────── */
.transcript-list { display: flex; flex-direction: column; border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; margin-top: 0.25rem; max-height: 600px; overflow-y: auto; }
.transcript-entry { display: flex; align-items: flex-start; gap: 0.9rem; padding: 0.75rem 1rem; border-bottom: 1px solid var(--border); transition: background .1s; }
.transcript-entry:last-child { border-bottom: none; }
.transcript-entry:hover { background: var(--accent-light); }
.entry-text { font-size: 0.88rem; line-height: 1.6; }

/* ── Footer ───────────────────────────────────────────── */
.footer { padding: 1.5rem 1rem; font-size: 0.8rem; color: var(--muted); text-align: center; }

/* ── Loading overlay ──────────────────────────────────── */
.loading-overlay { position: fixed; inset: 0; background: rgba(245,244,240,.92); backdrop-filter: blur(4px); display: flex; align-items: center; justify-content: center; z-index: 100; }
.loading-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 2.5rem 2rem; text-align: center; max-width: 340px; width: 90%; display: flex; flex-direction: column; align-items: center; gap: 1.1rem; }
.loading-card-agents { max-width: 490px; text-align: left; align-items: stretch; padding: 1.75rem 1.75rem 2rem; gap: 0; }
.loading-header { display: flex; align-items: center; gap: 0.9rem; margin-bottom: 1.25rem; }
.loading-header .spinner { flex-shrink: 0; }
.loading-header .loading-title { margin: 0; }
.spinner { width: 40px; height: 40px; border: 3px solid var(--accent-border); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading-title { font-size: 1rem; font-weight: 700; color: var(--text); }

/* ── Agent pipeline (loading panel) ───────────────────── */
.agent-pipeline { display: flex; flex-direction: column; gap: 0.65rem; }
.agent-row { background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 0.65rem 0.9rem; }
.agent-row-label { display: flex; align-items: center; gap: 0.45rem; margin-bottom: 0.4rem; }
.agent-num { width: 17px; height: 17px; background: var(--accent); color: #fff; font-size: 0.62rem; font-weight: 700; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; }
.agent-name { font-size: 0.72rem; font-weight: 700; color: var(--text); letter-spacing: 0.02em; text-transform: uppercase; }
.agent-tasks { list-style: none; display: flex; flex-direction: column; gap: 0.22rem; }
.agent-task { display: flex; align-items: center; gap: 0.5rem; font-size: 0.79rem; color: var(--muted); padding: 0.1rem 0; transition: color .25s; }
.agent-task::before { content: ''; flex-shrink: 0; width: 10px; height: 10px; border-radius: 50%; background: var(--border); transition: background .25s; }
.agent-task[data-state="active"] { color: var(--accent); font-weight: 500; }
.agent-task[data-state="active"]::before { background: transparent; border: 2px solid var(--accent-border); border-top-color: var(--accent); animation: spin .65s linear infinite; }
.agent-task[data-state="done"] { color: var(--green); }
.agent-task[data-state="done"]::before { content: '✓'; background: var(--green-light); font-size: 0.55rem; font-weight: 700; color: var(--green); display: flex; align-items: center; justify-content: center; }

/* ── Agent Activity Summary (results page) ────────────── */
.agent-summary { margin-bottom: 1rem; }
.agent-summary-toggle { cursor: pointer; list-style: none; font-size: 0.79rem; color: var(--muted); font-weight: 600; display: flex; align-items: center; gap: 0.4rem; user-select: none; padding: 0.25rem 0; transition: color .15s; }
.agent-summary-toggle::-webkit-details-marker { display: none; }
.agent-summary-toggle:hover { color: var(--text); }
.agent-summary-arrow { font-size: 0.5rem; display: inline-block; transition: transform .15s; line-height: 1; }
details[open] .agent-summary-arrow { transform: rotate(90deg); }
.agent-summary-body { display: flex; flex-direction: column; gap: 0.6rem; padding: 0.85rem 1rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); margin-top: 0.35rem; }
.agent-summary-row { display: flex; align-items: flex-start; gap: 0.6rem; }
.agent-summary-check { color: var(--green); font-weight: 700; font-size: 0.78rem; flex-shrink: 0; margin-top: 1px; width: 1em; text-align: center; }
.agent-summary-info { display: flex; flex-direction: column; gap: 0.1rem; }
.agent-summary-name { font-size: 0.79rem; font-weight: 700; color: var(--text); }
.agent-summary-desc { font-size: 0.75rem; color: var(--muted); line-height: 1.5; }
.ai-inline-badge { display: inline-flex; align-items: center; background: var(--accent-light); color: var(--accent); font-size: 0.6rem; font-weight: 700; padding: 0.1em 0.45em; border-radius: 3px; vertical-align: middle; margin-left: 0.25em; letter-spacing: 0.03em; }

/* ── Ask tab ──────────────────────────────────────────── */
.ask-tab-btn { font-weight: 700; }
.ask-form { margin-bottom: 1.5rem; }
.ask-input-row { display: flex; gap: 0.6rem; }
.ask-input { flex: 1; padding: 0.7rem 1rem; border: 1.5px solid var(--border); border-radius: var(--radius-sm); font-size: 0.95rem; font-family: var(--font); background: var(--bg); color: var(--text); outline: none; transition: border-color .15s, box-shadow .15s; }
.ask-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(79,70,229,.12); }
.ask-btn { padding: 0.7rem 1.35rem; background: var(--accent); color: #fff; border: none; border-radius: var(--radius-sm); font-size: 0.95rem; font-weight: 600; font-family: var(--font); cursor: pointer; white-space: nowrap; transition: background .15s; }
.ask-btn:hover { background: var(--accent-hover); }
.ask-btn:disabled { opacity: .55; cursor: not-allowed; }
.ask-loading { display: flex; align-items: center; gap: 0.75rem; color: var(--muted); font-size: 0.86rem; padding: 0.75rem 0 1rem; }
.spinner-sm { width: 18px; height: 18px; border: 2.5px solid var(--accent-border); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; flex-shrink: 0; }
.ask-result { display: flex; flex-direction: column; gap: 1rem; border-top: 1px solid var(--border); padding-top: 1.25rem; }
.ask-answer { font-size: 0.97rem; line-height: 1.8; color: var(--text); max-width: 72ch; }
.ask-source { display: flex; flex-direction: column; gap: 0.5rem; }
.ask-source-link { font-size: 0.84rem; font-weight: 600; color: var(--accent); text-decoration: none; }
.ask-source-link:hover { opacity: .8; }
.ask-source-label { font-size: 0.8rem; color: var(--muted); font-style: italic; }
.ask-quote { border-left: 3px solid var(--accent-border); padding: 0.5rem 0.85rem; font-size: 0.83rem; color: var(--muted); line-height: 1.6; background: var(--accent-light); border-radius: 0 var(--radius-xs) var(--radius-xs) 0; margin: 0; }
.ask-error { background: var(--error-bg); border: 1px solid var(--error-border); color: var(--error-text); border-radius: var(--radius-sm); padding: 0.75rem 1rem; font-size: 0.88rem; margin-top: 0.5rem; }

/* ── Mode selector ───────────────────────────────────── */
.mode-selector { display: flex; align-items: center; gap: 1rem; margin-bottom: 1.25rem; flex-wrap: wrap; }
.mode-pills { display: inline-flex; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 3px; gap: 2px; box-shadow: var(--shadow-sm); flex-shrink: 0; }
.mode-btn { padding: 0.42rem 1.05rem; border: none; border-radius: 7px; font-size: 0.82rem; font-weight: 600; font-family: var(--font); color: var(--muted); background: transparent; cursor: pointer; transition: background .15s, color .15s, box-shadow .15s, opacity .15s; white-space: nowrap; display: inline-flex; align-items: center; gap: 0; }
.mode-btn:hover:not(.active) { background: var(--bg); color: var(--text); }
.mode-btn.active { background: var(--text); color: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.18); }
/* Preparing state: subtle pulsing dot after label — signals background work without locking anything */
.mode-btn[data-preparing] { gap: 0.4rem; }
.mode-btn[data-preparing]::after { content: ''; width: 5px; height: 5px; border-radius: 50%; background: var(--accent); flex-shrink: 0; animation: preparePulse 1.3s ease-in-out infinite; }
@keyframes preparePulse { 0%, 100% { opacity: .3; transform: scale(.75); } 55% { opacity: 1; transform: scale(1); } }
.mode-meta { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; }
.mode-desc { font-size: 0.78rem; color: var(--muted); font-style: italic; }
.mode-loading { display: flex; align-items: center; gap: 0.45rem; font-size: 0.78rem; color: var(--accent); font-weight: 500; }
/* Smooth content fade-in after mode switch */
@keyframes modeContentIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }
.mode-fade-in { animation: modeContentIn 0.28s ease; }

/* ── Responsive ───────────────────────────────────────── */
@media (max-width: 600px) {
  .card-home { padding: 1.5rem 1.1rem; }
  .input-row { flex-direction: column; }
  .submit-btn { width: 100%; }
  .results-header { flex-wrap: wrap; gap: 0.5rem; padding: 0.75rem 1rem; }
  .study-main { padding: 1rem 1rem 2rem; }
  .tab-bar { gap: 0.2rem; padding: 0.25rem; }
  .tab-btn { padding: 0.45rem 0.55rem; font-size: 0.77rem; }
  .flashcard-grid { grid-template-columns: 1fr; }
  .concepts-grid { grid-template-columns: 1fr 1fr; }
}
