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

:root {
  --bg: #f2ede6;
  --surface: #faf6f1;
  --surface-2: #ede7de;
  --border: #ddd5c8;
  --text: #1e1b2e;
  --text-muted: #6b6580;
  --primary: #ff6b6b;
  --primary-hover: #e05555;
  --accent: #4ecdc4;
  --danger: #ff4d6a;
  --success: #00d2a0;
}

body {
  font-family: 'Nunito', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* Nav */
nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 2rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(8px);
}

.nav-brand {
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--primary);
  letter-spacing: -0.02em;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.nav-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  padding: 0.45rem 0.9rem;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 500;
  transition: all 0.15s;
}

.nav-btn:hover {
  color: var(--text);
  background: var(--surface-2);
}

.nav-btn.active {
  color: var(--text);
  background: var(--surface-2);
  font-weight: 600;
}

/* Main */
main {
  max-width: 1600px;
  margin: 0 auto;
  padding: 2rem;
}

.view { display: none; }
.view.active { display: block; }

/* Upload Area */
.upload-area {
  border: 2px dashed var(--border);
  border-radius: 20px;
  padding: 4.5rem 2rem;
  text-align: center;
  cursor: pointer;
  transition: all 0.25s;
  background: linear-gradient(160deg, rgba(255,107,107,0.04) 0%, transparent 60%);
}

.upload-area:hover, .upload-area.dragover {
  border-color: var(--primary);
  background: rgba(255, 107, 107, 0.07);
  transform: translateY(-1px);
}

.upload-icon {
  color: var(--primary);
  margin-bottom: 1rem;
}

.upload-area h2 {
  margin-bottom: 0.5rem;
}

.upload-area p {
  color: var(--text-muted);
}

/* Upload estimate card */
.upload-estimate {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 1.5rem 2rem;
  margin-top: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.estimate-file-name {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.estimate-cost {
  font-size: 0.95rem;
  color: var(--text-muted);
}

.estimate-cost strong {
  color: var(--text);
}

.estimate-balance {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.estimate-balance.warning {
  color: #d97706;
}

.estimate-balance.danger {
  color: var(--danger);
}

.estimate-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 0.25rem;
}

/* Processing */
.processing {
  padding: 1.75rem 2rem 2rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  margin-top: 1.5rem;
}

.job-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
}

.job-title {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text);
}

.job-filename {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.15rem;
  max-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.job-spinner {
  width: 22px;
  height: 22px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.job-progress-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1.75rem;
}

.progress-bar-wrap {
  flex: 1;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  border-radius: 3px;
  transition: width 0.4s ease;
  position: relative;
}

.progress-bar::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent 0%, rgba(255,255,255,0.15) 50%, transparent 100%);
  animation: shimmer 1.6s infinite;
}

@keyframes shimmer {
  from { transform: translateX(-100%); }
  to   { transform: translateX(100%); }
}

.progress-pct {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--primary);
  min-width: 2.8rem;
  text-align: right;
}

/* Timeline */
.timeline {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.timeline-step {
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  padding: 0.75rem 0;
  position: relative;
  opacity: 0.3;
  transition: opacity 0.3s;
}

.timeline-step.active { opacity: 1; }
.timeline-step.done { opacity: 0.65; }

.timeline-step:not(:last-child)::before {
  content: '';
  position: absolute;
  left: 9px;
  top: 36px;
  width: 2px;
  height: calc(100% - 12px);
  background: var(--border);
  transition: background 0.3s;
}

.timeline-step.done:not(:last-child)::before {
  background: var(--success);
}

.step-dot {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: var(--bg);
  flex-shrink: 0;
  margin-top: 2px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s;
}

.timeline-step.active .step-dot {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(255, 107, 107, 0.2);
  animation: pulse-dot 1.4s ease infinite;
}

.timeline-step.done .step-dot {
  border-color: var(--success);
  background: var(--success);
}

.timeline-step.done .step-dot::after {
  content: '';
  width: 6px;
  height: 4px;
  border-left: 2px solid #fff;
  border-bottom: 2px solid #fff;
  transform: rotate(-45deg) translateY(-1px);
}

@keyframes pulse-dot {
  0%, 100% { box-shadow: 0 0 0 3px rgba(255, 107, 107, 0.2); }
  50% { box-shadow: 0 0 0 6px rgba(255, 107, 107, 0.1); }
}

.step-body {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.step-body-wide {
  flex: 1;
  min-width: 0;
}

.step-label {
  font-size: 0.95rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.step-detail {
  font-size: 0.8rem;
  color: var(--text-muted);
  min-height: 1rem;
}

/* Model badges */
.model-badge {
  display: inline-block;
  font-size: 0.65rem;
  font-weight: 600;
  padding: 0.1rem 0.45rem;
  border-radius: 20px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  vertical-align: middle;
}

.badge-sonnet {
  background: rgba(255, 107, 107, 0.12);
  color: #c94040;
  border: 1px solid rgba(255, 107, 107, 0.25);
}

.badge-haiku {
  background: rgba(78, 205, 196, 0.15);
  color: #1a9e96;
  border: 1px solid rgba(78, 205, 196, 0.3);
}

/* Parallel tag */
.parallel-tag {
  display: inline-block;
  font-size: 0.65rem;
  font-weight: 500;
  padding: 0.1rem 0.45rem;
  border-radius: 20px;
  background: var(--surface-2);
  color: var(--text-muted);
  border: 1px solid var(--border);
  letter-spacing: 0.02em;
  vertical-align: middle;
}

/* Parallel cards grid */
.parallel-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 0.6rem;
  margin-top: 0.6rem;
}

@media (max-width: 700px) {
  .parallel-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 520px) {
  .parallel-grid { grid-template-columns: 1fr; }
}

.parallel-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.65rem 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  opacity: 0.4;
  transition: all 0.3s;
}

.parallel-card.active {
  opacity: 1;
  border-color: var(--primary);
  background: rgba(255, 107, 107, 0.07);
}

.parallel-card.done {
  opacity: 0.55;
  border-color: var(--success);
  background: rgba(0, 201, 123, 0.06);
}

.parallel-card-label {
  font-size: 0.85rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-wrap: wrap;
}

/* Buttons */
.btn {
  padding: 0.55rem 1.1rem;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 500;
  transition: all 0.15s;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.btn:hover { background: var(--border); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.btn-primary:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
}

.upgrade-btn {
  background: linear-gradient(135deg, var(--primary), #ff6b9d);
  border-color: transparent;
  color: #fff;
  font-size: 0.8rem;
  padding: 0.35rem 0.85rem;
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(255,107,107,0.3);
}
.upgrade-btn:hover {
  background: linear-gradient(135deg, var(--primary-hover), #e0558a);
  box-shadow: 0 3px 12px rgba(255,107,107,0.45);
}

.btn-danger {
  background: transparent;
  border-color: var(--danger);
  color: var(--danger);
}

.btn-danger:hover { background: rgba(255, 77, 106, 0.1); }

/* Results */
.results-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
}

/* Tabs */
.tabs {
  display: flex;
  gap: 0.1rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1.5rem;
}

.tab {
  background: none;
  border: none;
  color: var(--text-muted);
  padding: 0.7rem 1.25rem;
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 500;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: all 0.15s;
}

.tab:hover { color: var(--text); }

.tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  font-weight: 600;
}

.tab-content { display: none; }
.tab-content.active { display: block; }

/* Notes */
.notes-container {
  display: grid;
  grid-template-columns: 55% 45%;
  position: relative;
  height: 85vh;
  align-items: stretch;
  /* prevent grid children from overflowing their tracks */
  min-height: 0;
}

.notes-container > * {
  min-height: 0;
  overflow: hidden;
}

iframe.preview-pane {
  width: 100%;
  height: 100%;
  min-height: 0;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0;
}

.pdf-pane-wrapper {
  height: 100%;
  display: flex;
  flex-direction: column;
  position: relative;
  padding-right: 1rem;
}

div.preview-pane {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  min-height: 70vh;
}

.notes-pane {
  overflow-y: auto;
  height: 100%;
  scroll-behavior: smooth;
}

.notes-content {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 2rem;
  line-height: 2;
  font-family: 'Atkinson Hyperlegible', sans-serif;
  font-size: 1.05rem;
  letter-spacing: 0.02em;
  word-spacing: 0.1em;
}

/* Apply the same readable notes font to flashcards and chat for consistency */
.flashcard-front, .flashcard-back, .flashcard-text, .flashcard-label,
.anki-front, .anki-back, .anki-back-content,
.chat-bubble, .chat-input, .chat-empty {
  font-family: 'Atkinson Hyperlegible', sans-serif !important;
  font-weight: 400 !important; /* use a weight we load from Google Fonts */
}

/* Ensure all descendants also inherit the dyslexia-friendly font */
.flashcard, .flashcard *,
.chat-container, .chat-container *,
.anki-card, .anki-card * {
  font-family: 'Atkinson Hyperlegible', sans-serif !important;
  font-weight: 400 !important;
}

/* Ensure study-mode specific elements inherit the notes font */
.anki-front, .anki-back, .anki-front-content, .anki-back-content,
#anki-front, #deck-anki-front, #daily-anki-front,
#anki-back, #deck-anki-back, #daily-anki-back,
.deck-anki-card, #deck-anki-card, #daily-anki-card {
  font-family: 'Atkinson Hyperlegible', sans-serif !important;
  font-weight: 400 !important;
}

.notes-content h1, .notes-content h2, .notes-content h3 {
  margin: 1.75rem 0 0.75rem;
  color: var(--text);
  font-weight: 700;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.4rem;
  letter-spacing: 0.01em;
}

.notes-content h1:first-child, .notes-content h2:first-child {
  margin-top: 0;
}

.notes-content ul, .notes-content ol {
  padding-left: 1.75rem;
  margin: 0.5rem 0;
}

.notes-content li {
  margin: 0.5rem 0;
  padding-left: 0.25rem;
}

.notes-content p { margin: 0.9rem 0; }

.notes-content strong {
  color: var(--primary);
  font-weight: 700;
}

.notes-content code {
  background: var(--surface-2);
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  font-size: 0.9em;
}

/* PDF Pane Wrapper — height/flex set earlier; position here for indicator overlay */

.pdf-page-indicator {
  position: absolute;
  bottom: 1rem;
  right: 1rem;
  background: rgba(0,0,0,0.7);
  color: var(--text);
  padding: 0.3rem 0.75rem;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 600;
  pointer-events: none;
  z-index: 10;
  backdrop-filter: blur(4px);
}

/* Notes Pane Wrapper */
.notes-pane-wrapper {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  overflow: hidden;
  padding-left: 1rem;
}

.notes-search {
  width: 100%;
  padding: 0.6rem 1rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 0.9rem;
  margin-bottom: 0.5rem;
  outline: none;
  transition: border-color 0.2s;
}

.notes-search:focus {
  border-color: var(--primary);
}

.notes-search::placeholder {
  color: var(--text-muted);
}

/* Button that matches the notes search input height */
.notes-search-btn {
  display: inline-flex;
  align-items: center;
  padding: 0 0.9rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 0.9rem;
  cursor: pointer;
  box-sizing: border-box;
}

.notes-search-btn:active { transform: translateY(1px); }

/* Row wrapper to make search input and button equal height */
.notes-search-row {
  display: flex;
  gap: 8px;
  margin-bottom: 0.5rem;
  align-items: stretch;
  height: 40px; /* consistent height for both elements */
}

.notes-search-row .notes-search,
.notes-search-row .notes-search-btn {
  height: 100%;
}

.notes-search-row .notes-search { padding: 0 1rem; }

.notes-reading-progress {
  height: 3px;
  background: var(--surface-2);
  border-radius: 99px;
  overflow: hidden;
  margin-bottom: 0.75rem;
}

.notes-reading-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  border-radius: 99px;
  transition: width 0.15s ease;
}

/* Structured Note Sections */
.note-section {
  border-left: 3px solid transparent;
  padding: 0.75rem 1rem;
  transition: border-color 0.3s, background 0.3s;
  border-radius: 0 8px 8px 0;
  margin-bottom: 1.25rem;
}

.note-section.active {
  border-left-color: var(--primary);
  background: rgba(255, 107, 107, 0.06);
}

.note-heading-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.note-heading-row h2 {
  margin: 0;
  flex: 1;
}

.collapse-toggle {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.7rem;
  cursor: pointer;
  padding: 0.25rem;
  border-radius: 4px;
  transition: color 0.2s, background 0.2s;
  flex-shrink: 0;
  line-height: 1;
}

.collapse-toggle:hover {
  color: var(--text);
  background: var(--surface-2);
}

.note-section.collapsed .note-body {
  display: none;
}

.page-badge {
  display: inline-block;
  font-size: 0.65rem;
  padding: 0.15rem 0.5rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 99px;
  color: var(--text-muted);
  margin-left: 0.5rem;
  cursor: pointer;
  vertical-align: middle;
  transition: all 0.2s;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
}

.page-badge:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: rgba(255, 107, 107, 0.1);
}

.view-in-notes-btn {
  margin-top: 0.75rem;
  font-size: 0.75rem; 
  padding: 0.35rem 0.75rem;
  border-color: var(--primary);
  color: var(--primary);
}

.view-in-notes-btn:hover {
  background: rgba(255, 107, 107, 0.15);
}

/* Flashcards Grid */
.flashcards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
}

.flashcard {
  perspective: 1000px;
  cursor: pointer;
  min-height: 160px;
}

.flashcard:hover .flashcard-inner {
  transform: translateY(-2px);
}

.flashcard.flipped .flashcard-inner {
  transform: rotateY(180deg);
}

.flashcard.flipped:hover .flashcard-inner {
  transform: translateY(-2px) rotateY(180deg);
}

.flashcard-inner {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 220px;
  transition: transform 0.5s ease-in-out;
  transform-style: preserve-3d;
}

.flashcard-front, .flashcard-back {
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  min-height: 220px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem;
  overflow-y: auto;
  overflow-x: hidden;
  transition: border-color 0.3s;
  box-sizing: border-box;
}

.flashcard:hover .flashcard-front,
.flashcard:hover .flashcard-back {
  border-color: var(--primary);
}

.flashcard-back {
  transform: rotateY(180deg);
}

.flashcard-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.flashcard-text {
  font-size: 1.15rem;
  line-height: 1.6;
}
.flashcard-text-md ul, .flashcard-text-md ol {
  margin: 0.25rem 0 0 1.1rem;
  padding: 0;
  text-align: left;
}
.flashcard-text-md li {
  margin-bottom: 0.2rem;
}
.flashcard-text-md p {
  margin: 0;
}

/* Flashcard Images (PNG rendered from PDF pages) */
.flashcard-img {
  width: 100%;
  max-height: 200px;
  object-fit: contain;
  border-radius: 8px;
  margin-top: 0.75rem;
  background: #fff;
  display: block;
}

/* ── Anki / Study Mode ───────────────────────────────────────────────────── */

/* Daily view header */
.daily-view-header {
  max-width: 700px;
  margin: 0 auto 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}
.daily-view-header h2 {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 0.3rem;
}
.daily-view-header p {
  color: var(--text-muted);
  font-size: 0.9rem;
}
.daily-folder-select {
  flex-shrink: 0;
  padding: 0.45rem 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.85rem;
  cursor: pointer;
  outline: none;
}

.anki-container {
  max-width: 680px;
  margin: 0 auto;
  text-align: center;
}

.anki-progress-wrap {
  height: 5px;
  background: var(--surface-2);
  border-radius: 99px;
  overflow: hidden;
  margin-bottom: 0.85rem;
}

.anki-progress-bar {
  height: 100%;
  background: var(--primary);
  border-radius: 99px;
  width: 0%;
  transition: width 0.5s ease;
}

.anki-stats {
  display: flex;
  justify-content: space-between;
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-bottom: 1.25rem;
  font-weight: 500;
}

.anki-mastered-count { color: var(--success); }

/* Card flip container */
.anki-card {
  width: 100%;
  perspective: 1200px;
  cursor: pointer;
  margin-bottom: 1.25rem;
  user-select: none;
}

.anki-card-inner {
  position: relative;
  width: 100%;
  transition: transform 0.45s cubic-bezier(0.4, 0, 0.2, 1);
  transform-style: preserve-3d;
  display: grid;
}

.anki-card.flipped .anki-card-inner {
  transform: rotateY(180deg);
}

/* Front and back shared styles */
.anki-front, .anki-back {
  grid-area: 1 / 1;
  width: 100%;
  min-height: 240px;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: 18px;
  padding: 2.5rem 2rem;
  box-sizing: border-box;
  overflow-y: auto;
  overflow-x: hidden;
}

.anki-front {
  background: var(--surface);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
}

.anki-front-content {
  font-size: clamp(1rem, 0.75rem + 1.5vw, 1.5rem);
  line-height: 1.5;
  font-weight: 500;
  overflow-wrap: break-word;
  width: 100%;
}

.anki-back {
  background: var(--surface);
  border: 1px solid var(--primary);
  border-top: 3px solid var(--primary);
  transform: rotateY(180deg);
  text-align: left;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.anki-back-question {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-bottom: 0.6rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.anki-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 0.6rem 0 0.85rem;
}

.anki-back-content {
  font-size: clamp(1rem, 0.75rem + 1.5vw, 1.45rem);
  line-height: 1.6;
  overflow-wrap: break-word;
}

/* Tap hint */
.anki-hint {
  color: var(--text-muted);
  font-size: 0.78rem;
  margin-bottom: 1.25rem;
  opacity: 0.7;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
}
.anki-hint::before {
  content: '';
  display: inline-block;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--text-muted);
  opacity: 0.5;
}

/* Rating buttons */
.anki-buttons {
  display: flex;
  justify-content: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.anki-btn {
  padding: 0.6rem 1.1rem;
  border: none;
  border-radius: 10px;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  color: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
  min-width: 72px;
}

.anki-btn-label {
  font-size: 0.88rem;
  font-weight: 700;
}
.anki-btn-hint {
  font-size: 0.68rem;
  font-weight: 400;
  opacity: 0.8;
}

.anki-again  { background: #c53030; }
.anki-hard   { background: #c27803; }
.anki-good   { background: #1d4ed8; }
.anki-easy   { background: #15803d; }
.anki-again:hover  { background: #e53e3e; transform: translateY(-1px); }
.anki-hard:hover   { background: #d97706; transform: translateY(-1px); }
.anki-good:hover   { background: #2563eb; transform: translateY(-1px); }
.anki-easy:hover   { background: #16a34a; transform: translateY(-1px); }

/* Session complete */
.anki-done {
  padding: 2.5rem 2rem;
  background: var(--surface);
  border-radius: 18px;
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

.anki-done-icon {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--success), #00a86b);
  color: #fff;
  font-size: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 0.5rem;
  box-shadow: 0 4px 16px rgba(0, 201, 123, 0.3);
}

.anki-done h3 {
  font-size: 1.3rem;
  font-weight: 700;
  margin-bottom: 0;
}
.anki-done p {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-bottom: 0.75rem;
}

/* Saved Decks */
.decks-list {
  display: grid;
  gap: 1rem;
}

.deck-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: all 0.2s;
  cursor: pointer;
}

.deck-item:hover {
  border-color: var(--primary);
}

.deck-item.deck-starred {
  border-color: rgba(255, 200, 0, 0.4);
}

.deck-info {
  flex: 1;
  min-width: 0;
  text-align: left;
}

.deck-item.deck-dragging {
  opacity: 0.4;
}

.deck-item.deck-drop-target {
  border-color: var(--primary);
  border-style: dashed;
  background: rgba(255, 107, 107, 0.07);
}

.deck-drag-handle {
  color: var(--text-muted);
  font-size: 0.9rem;
  line-height: 1;
  cursor: grab;
  flex-shrink: 0;
  user-select: none;
  opacity: 0;
  width: 0;
  overflow: hidden;
  transition: opacity 0.15s, width 0.15s;
  letter-spacing: -2px;
}

.deck-item:hover .deck-drag-handle {
  opacity: 1;
  width: 1.2rem;
}

.deck-star-btn {
  background: none;
  border: none;
  font-size: 1.15rem;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.2rem;
  line-height: 1;
  transition: color 0.15s, transform 0.15s;
}

.deck-star-btn:hover { color: #ffc800; transform: scale(1.2); }
.deck-star-btn.starred { color: #ffc800; }

.folder-item.folder-drop-over {
  border-color: var(--primary);
  background: rgba(255, 107, 107, 0.1);
}

#folder-drop-overlay {
  display: none;
  position: fixed;
  inset: 8px;
  border: 2px dashed var(--primary);
  border-radius: 12px;
  background: rgba(108, 99, 255, 0.04);
  pointer-events: none;
  z-index: 999;
}
#folder-drop-overlay.active {
  display: block;
}

.deck-info h3 { margin-bottom: 0.25rem; }

.deck-meta {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.deck-actions {
  display: flex;
  gap: 0.5rem;
  flex-shrink: 0;
}

.deck-actions .btn {
  padding: 0.3rem 0.6rem;
  font-size: 0.8rem;
}

.deck-actions .deck-menu-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  cursor: pointer;
  border-radius: 8px;
  padding: 0.3rem 0.5rem;
  font-size: 1rem;
  line-height: 1;
  transition: all 0.15s;
}
.deck-actions .deck-menu-btn:hover { background: var(--surface-2); color: var(--text); }

.deck-menu-popup {
  position: absolute;
  right: 0;
  top: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.18);
  min-width: 150px;
  padding: 0.35rem 0;
  z-index: 100;
}
.deck-menu-popup button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.5rem 1rem;
  border: none;
  background: none;
  color: var(--text);
  font-size: 0.88rem;
  cursor: pointer;
  font-family: inherit;
}
.deck-menu-popup button:hover { background: var(--surface-2); }
.deck-menu-popup button.danger { color: var(--danger); }

.folders-list {
  display: grid;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.folder-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.9rem 1.25rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  transition: all 0.2s;
}
.folder-item {
  flex-wrap: wrap;
}
.folder-item:hover { border-color: var(--primary); }
.folder-item > div:first-child { flex: 1; min-width: 0; text-align: left; }
.folder-item .folder-icon { margin-right: 0.5rem; font-size: 1.1rem; }
.folder-item .folder-name { font-weight: 600; }
.folder-item .folder-count { color: var(--text-muted); font-size: 0.85rem; margin-left: 0.5rem; }

/* Folder hover preview */
.folder-preview {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  transition: max-height 0.3s ease, opacity 0.2s ease, padding 0.3s ease;
  padding-top: 0;
  border-top: 0 solid transparent;
}

.folder-item:hover .folder-preview {
  max-height: 200px;
  opacity: 1;
  padding-top: 0.6rem;
  margin-top: 0.2rem;
  border-top: 1px solid var(--border);
}

.folder-preview-item {
  font-size: 0.82rem;
  padding: 0.3rem 0.6rem;
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.4;
}

.folder-preview-folder {
  color: var(--primary);
  background: rgba(108, 99, 255, 0.08);
}

.folder-preview-deck {
  color: var(--text-muted);
}

.folder-preview-more {
  font-style: italic;
  color: var(--text-muted);
  opacity: 0.7;
  font-size: 0.78rem;
}

.folder-breadcrumb {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  margin-bottom: 1rem;
  font-size: 0.9rem;
  color: var(--text-muted);
}
.folder-breadcrumb a {
  color: var(--primary);
  text-decoration: none;
  cursor: pointer;
}
.folder-breadcrumb a:hover { text-decoration: underline; }

.move-folder-tree {
  max-height: 320px;
  overflow-y: auto;
  margin-bottom: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.25rem 0;
}

.move-folder-node {
  display: flex;
  align-items: center;
  padding: 0.55rem 0.75rem;
  cursor: pointer;
  transition: background 0.12s;
  gap: 0.5rem;
  font-size: 0.92rem;
  position: relative;
}
.move-folder-node:hover { background: var(--surface-2); }
.move-folder-node.selected { background: rgba(108,99,255,0.12); color: var(--primary); font-weight: 600; }
.move-folder-node.selected::before {
  content: '';
  position: absolute;
  left: 0;
  top: 4px;
  bottom: 4px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--primary);
}

.move-folder-node .mf-icon {
  flex-shrink: 0;
  font-size: 1.05rem;
  width: 1.4rem;
  text-align: center;
}
.move-folder-node .mf-toggle {
  flex-shrink: 0;
  width: 1.2rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.7rem;
  cursor: pointer;
  user-select: none;
  transition: transform 0.15s;
}
.move-folder-node .mf-toggle.expanded { transform: rotate(90deg); }
.move-folder-node .mf-label { flex: 1; }
.move-folder-node .mf-count {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-weight: 400;
}

.move-folder-children { overflow: hidden; }

.move-new-folder-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}
.move-new-folder-row input {
  flex: 1;
  padding: 0.4rem 0.7rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.88rem;
  outline: none;
  font-family: inherit;
}
.move-new-folder-row input:focus { border-color: var(--primary); }

.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 3rem;
}

.back-btn {
  margin-bottom: 0;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  padding: 0.75rem 1.5rem;
  border-radius: 8px;
  background: var(--success);
  color: #fff;
  font-weight: 500;
  animation: slideIn 0.3s ease;
  z-index: 100;
}

.toast.error { background: var(--danger); }

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

.hidden { display: none !important; }

/* Chat UI */
.chat-container {
  display: flex;
  flex-direction: column;
  height: 65vh;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}

.chat-messages {
  flex: 1;
  padding: 1.5rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.chat-empty {
  margin: auto;
  color: var(--text-muted);
  text-align: center;
  font-size: 1.1rem;
}

.chat-bubble {
  max-width: 80%;
  padding: 1rem;
  border-radius: 12px;
  line-height: 1.5;
  animation: fadeIn 0.3s ease;
}

.chat-bubble.user {
  align-self: flex-end;
  background: var(--primary);
  color: #fff;
  border-bottom-right-radius: 2px;
}

.chat-bubble.assistant {
  align-self: flex-start;
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom-left-radius: 2px;
}

.chat-bubble.assistant h1, .chat-bubble.assistant h2, .chat-bubble.assistant h3 {
  margin: 0.5rem 0;
  font-size: 1.1rem;
}

.chat-bubble.assistant p {
  margin: 0.5rem 0;
}

.chat-bubble.assistant ul {
  margin: 0.5rem 0 0.5rem 1.5rem;
}

.chat-bubble.assistant pre {
  background: var(--bg);
  padding: 0.75rem;
  border-radius: 8px;
  overflow-x: auto;
  margin: 0.5rem 0;
}

.chat-bubble.assistant code {
  background: rgba(0,0,0,0.3);
  padding: 0.2rem 0.4rem;
  border-radius: 4px;
}

.chat-input-bar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem;
  background: var(--surface);
  border-top: 1px solid var(--border);
}

.chat-send-group {
  display: flex;
  position: relative;
}

/* global input TTS button removed; per-message TTS uses .chat-msg-tts */

.chat-msg-tts {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-left: 0.5rem;
  padding: 0.25rem 0.5rem;
  border-radius: 6px;
  background: rgba(0,0,0,0.04);
  border: 1px solid rgba(0,0,0,0.06);
  cursor: pointer;
  font-size: 0.95rem;
}
.chat-msg-tts.active {
  background: linear-gradient(90deg, rgba(108,99,255,0.12), rgba(108,99,255,0.06));
  border-color: rgba(108,99,255,0.35);
}

.chat-send-btn {
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
  padding-right: 1.25rem;
  padding-left: 1.25rem;
}

.chat-mode-btn {
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
  border-left: 1px solid rgba(255, 255, 255, 0.2);
  padding: 0 0.5rem;
}

.chat-mode-menu {
  position: absolute;
  bottom: calc(100% + 0.5rem);
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.5);
  min-width: 200px;
  z-index: 50;
  overflow: hidden;
}

.chat-mode-option {
  padding: 0.75rem 1rem;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  transition: background 0.2s;
}

.chat-mode-option:hover {
  background: var(--surface-2);
}

.chat-mode-option.active {
  background: rgba(255, 107, 107, 0.1);
  border-left: 3px solid var(--primary);
}

.chat-mode-option strong {
  font-size: 0.9rem;
  color: var(--text);
  margin-bottom: 0.2rem;
}

.chat-mode-option span {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.chat-mode-option.warn strong {
  color: #d97706;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(4px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 2rem;
  max-width: 450px;
  width: 100%;
  box-shadow: 0 20px 60px rgba(0,0,0,0.6);
  /* Keep modal within viewport and allow internal scrolling on small screens */
  max-height: 90vh;
  overflow: auto;
}

.modal h3 {
  margin-bottom: 1rem;
  color: #d97706;
  font-size: 1.1rem;
}

.modal p {
  color: var(--text-muted);
  font-size: 0.9rem;
  line-height: 1.6;
  margin-bottom: 1.5rem;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
}

.chat-input {
  flex: 1;
  padding: 0.75rem 1rem;
  border-radius: 24px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  outline: none;
  font-size: 0.95rem;
  transition: border-color 0.2s;
}

.chat-input:focus {
  border-color: var(--primary);
}

/* Nav auth section */
.auth-section {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  border-left: 1px solid var(--border);
  padding-left: 1rem;
}
.user-profile {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--primary);
}
.btn-ghost-sm {
  background: transparent;
  border-color: var(--border);
  padding: 0.25rem 0.55rem;
  font-size: 0.78rem;
}

/* Usage Indicator */
.usage-indicator {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 0.8rem;
  border-radius: 12px;
  background: var(--surface-2);
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
  transition: color 0.3s;
}

.usage-indicator.warning {
  color: #d97706; /* amber */
}

.usage-indicator.danger {
  color: var(--danger);
}

/* Topic Headers – Flashcard grouping */
.topic-header {
  font-size: 1rem;
  font-weight: 700;
  color: var(--primary);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

/* Auth section in nav */
.auth-section {
  margin-left: auto;
}

#user-profile {
  white-space: nowrap;
}

/* Keyboard Hints */
.keyboard-hints {
  text-align: center;
  margin-top: 1rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  opacity: 0.6;
}

.keyboard-hints span {
  margin: 0 0.5rem;
}

.keyboard-hints kbd {
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 0.1rem 0.3rem;
  border-radius: 4px;
  font-family: inherit;
  box-shadow: 0 1px 1px rgba(0,0,0,0.2);
}

.shortcut-overlay {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--surface);
  border: 1px solid var(--primary);
  padding: 2rem;
  border-radius: 16px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.5);
  z-index: 200;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 1rem 1.5rem;
  align-items: center;
}

.shortcut-overlay.hidden {
  display: none !important;
}

.shortcut-overlay h3 {
  grid-column: 1 / -1;
  text-align: center;
  margin-bottom: 0.5rem;
}

.shortcut-overlay kbd {
  justify-self: end;
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 0.3rem 0.6rem;
  border-radius: 6px;
  font-family: inherit;
  font-weight: 600;
}

/* Responsive */
@media (max-width: 600px) {
  main { padding: 1rem; }
  .upload-area { padding: 2rem 1rem; }
  .flashcards-grid { grid-template-columns: 1fr; }
}

/* ── Auth Gate ───────────────────────────────────────────────────────────── */
.auth-gate {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  flex-direction: row;
}

.auth-gate.hidden { display: none; }

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

/* ── Left hero panel ── */
.auth-gate-hero {
  flex: 1;
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 3rem;
  background: linear-gradient(160deg, #fde8d8 0%, #f5dff5 50%, #d8eafd 100%);
}

.auth-gate-hero-glow {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 80% 60% at 30% 30%, rgba(255,107,107,0.12) 0%, transparent 60%),
    radial-gradient(ellipse 60% 40% at 80% 80%, rgba(78,205,196,0.08) 0%, transparent 50%);
  pointer-events: none;
}

.auth-gate-hero::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(200,185,170,0.3) 1px, transparent 1px),
    linear-gradient(90deg, rgba(200,185,170,0.3) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: radial-gradient(ellipse 100% 100% at 30% 20%, black 20%, transparent 75%);
}

.auth-gate-hero-inner {
  position: relative;
  max-width: 480px;
  animation: fadeUp 0.5s ease;
}

.auth-gate-logo-mark {
  display: inline-block;
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--primary);
  text-decoration: none;
  margin-bottom: 2.5rem;
}

.auth-gate-headline {
  font-size: clamp(1.75rem, 2.5vw + 0.5rem, 2.75rem);
  font-weight: 900;
  line-height: 1.15;
  letter-spacing: -0.03em;
  margin-bottom: 1.25rem;
  color: var(--text);
}

.auth-gate-headline-accent {
  color: var(--primary);
}

.auth-gate-hero-sub {
  color: var(--text-muted);
  font-size: 0.95rem;
  line-height: 1.7;
  margin-bottom: 2rem;
  max-width: 400px;
}

.auth-gate-features {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  margin-bottom: 2.5rem;
}

.auth-gate-feature {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  font-size: 0.875rem;
  color: var(--text-muted);
}

.auth-gate-feature-icon {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgba(0,201,123,0.15);
  color: var(--success);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.auth-gate-powered {
  font-size: 0.75rem;
  color: var(--text-muted);
  letter-spacing: 0.04em;
}

/* ── Right login panel ── */
.auth-gate-login {
  width: 440px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2.5rem;
  background: var(--surface);
  border-left: 1px solid var(--border);
  overflow-y: auto;
}

.auth-gate-card {
  width: 100%;
  max-width: 340px;
  animation: fadeUp 0.45s ease 0.1s both;
}

.auth-gate-card-logo {
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--primary);
  margin-bottom: 1.75rem;
}

.auth-gate-card-title {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 0.4rem;
  color: var(--text);
}

.auth-gate-card-sub {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-bottom: 1.75rem;
  line-height: 1.5;
}

.auth-gate-input {
  width: 100%;
  padding: 0.8rem 1rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.2s;
  margin-bottom: 0.65rem;
  font-family: inherit;
}
.auth-gate-input:focus { border-color: var(--primary); }
.auth-gate-input::placeholder { color: var(--text-muted); }

.auth-gate-error {
  font-size: 0.82rem;
  color: var(--danger);
  min-height: 1.2em;
  margin-bottom: 0.5rem;
}

.auth-gate-granted {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
  color: var(--success);
  font-weight: 600;
  background: rgba(0,201,123,0.1);
  border: 1px solid rgba(0,201,123,0.2);
  border-radius: 8px;
  padding: 0.6rem 0.9rem;
  margin-bottom: 1.25rem;
}

.auth-gate-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.65rem;
  padding: 0.8rem 1.5rem;
  font-size: 0.95rem;
  font-weight: 600;
  border-radius: 10px;
  width: 100%;
  cursor: pointer;
}

.auth-gate-footer-note {
  margin-top: 1.5rem;
  font-size: 0.78rem;
  color: rgba(139,143,168,0.55);
  text-align: center;
}
.auth-gate-footer-note a {
  color: var(--primary);
  text-decoration: none;
  opacity: 0.8;
}
.auth-gate-footer-note a:hover { opacity: 1; }

/* Mobile: stack vertically */
@media (max-width: 1024px) {
  .auth-gate { flex-direction: column; overflow-y: auto; }
  .auth-gate-hero { padding: 3rem 1.5rem 2rem; min-height: auto; }
  .auth-gate-hero::before { display: none; }
  .auth-gate-headline { font-size: 1.75rem; }
  .auth-gate-login { width: 100%; border-left: none; border-top: 1px solid var(--border); padding: 2rem 1.5rem 3rem; }
}

/* ── Canvas PDF Viewer ─────────────────────────────────── */
.pdf-viewer-host {
  height: 100%;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.pdf-viewer-wrap {
  height: 100%;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  background: var(--surface);
  min-height: 0;
}

/* Scrollable page stack — no extra background gaps */
.pdf-canvas-wrap {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  background: #2a2a2a;
  scroll-behavior: smooth;
}

/* Each page sits in its own wrapper; inner holds canvases for correct overlay alignment */
.pdf-page-wrap {
  display: flex;
  justify-content: center;
  align-items: center;
  background: #2a2a2a;
  /* thin divider between pages */
  border-bottom: 3px solid #1a1a1a;
}

.pdf-page-wrap:last-child {
  border-bottom: none;
}

/* Inner wrapper sized to the canvas — overlays are relative to this, not the black bars */
.pdf-page-inner {
  position: relative;
  display: block;
  line-height: 0;
}

.pdf-main-canvas {
  display: block;
  width: 100%;
  height: auto;
}

.pdf-overlay-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.pdf-annotation-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none; /* enabled by JS when annotation mode is on */
}

/* Annotation toolbar */
.pdf-annot-toolbar {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.35rem 1rem;
  background: var(--surface-2);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  flex-wrap: wrap;
}

.pdf-annot-toolbar.hidden { display: none; }

.annot-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  flex-shrink: 0;
}

.annot-colors {
  display: flex;
  gap: 0.3rem;
  align-items: center;
}

.annot-color {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
  transition: transform 0.15s, border-color 0.15s;
  flex-shrink: 0;
}

.annot-color:hover { transform: scale(1.2); }
.annot-color.active {
  border-color: #fff;
  transform: scale(1.15);
  box-shadow: 0 0 0 1px rgba(255,255,255,0.3);
}

.annot-sizes {
  display: flex;
  gap: 0.2rem;
  align-items: center;
}

.annot-size {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 0.15rem 0.45rem;
  border-radius: 5px;
  cursor: pointer;
  font-size: 0.7rem;
  font-weight: 700;
  transition: all 0.15s;
  line-height: 1.4;
}

.annot-size:hover, .annot-size.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

/* Active state for annotate toggle and eraser */
.pdf-ctrl-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.pdf-ctrl-btn.annot-eraser.active {
  background: var(--danger);
  border-color: var(--danger);
}

.pdf-ctrl-btn.annot-highlight.active {
  background: #b8860b;
  border-color: #b8860b;
  color: #fff;
}

/* Separator between nav and annotate button */
.pdf-ctrl-sep {
  width: 1px;
  height: 1.2rem;
  background: var(--border);
  margin: 0 0.25rem;
}

.pdf-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  padding: 0.45rem 1rem;
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.pdf-ctrl-btn {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  width: 2rem;
  height: 2rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 1.2rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

.pdf-ctrl-btn:hover { background: var(--border); }

.pdf-page-label {
  font-size: 0.85rem;
  color: var(--text-muted);
  min-width: 5rem;
  text-align: center;
}

.pdf-load-err {
  color: var(--text-muted);
  padding: 2rem;
  text-align: center;
}

/* Ask AI – side-by-side PDF + chat */
.chat-with-pdf {
  display: grid;
  grid-template-columns: 3fr 2fr;
  gap: 1.5rem;
  height: 85vh;
  align-items: stretch;
  min-height: 0;
}

/* Make the chat-with-pdf container positionable for the draggable splitter */
.chat-with-pdf {
  position: relative;
}

.chat-with-pdf > * {
  min-height: 0;
  overflow: hidden;
}

.chat-with-pdf.no-pdf {
  grid-template-columns: 1fr;
}

.chat-pdf-pane {
  position: relative;
  height: 100%;
  display: flex;
  flex-direction: column;
}

/* Draggable splitter between PDF and chat panes */
.chat-splitter {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 8px;
  margin-left: -4px;
  background: linear-gradient(180deg, rgba(255,255,255,0.03), rgba(255,255,255,0.01));
  cursor: col-resize;
  z-index: 60;
  border-radius: 4px;
  box-shadow: 0 0 0 1px rgba(255,255,255,0.02) inset;
}
.chat-splitter:hover { background: linear-gradient(180deg, rgba(108,99,255,0.12), rgba(108,99,255,0.06)); }

.chat-pdf-pane iframe.preview-pane {
  flex: 1;
  min-height: 0;
}

.chat-with-pdf .chat-container {
  height: 100%;
}

/* Slide reference links inside chat bubbles */
.slide-ref-link {
  display: inline-block;
  background: rgba(255, 107, 107, 0.15);
  border: 1px solid var(--primary);
  color: var(--primary);
  border-radius: 6px;
  padding: 0.1rem 0.5rem;
  font-size: 0.82em;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.2s;
  margin: 0 0.1em;
}

.slide-ref-link:hover {
  background: rgba(255, 107, 107, 0.3);
}

/* If a slide-ref has an explicit data-phrase (i.e. shows phrase text),
   render it as normal inline text rather than a pill-style link. */
.slide-ref-link[data-phrase] {
  display: inline;
  background: transparent;
  border: none;
  padding: 0;
  margin: 0 0.08em;
  color: var(--primary);
  font-weight: 600;
  border-radius: 0;
  text-decoration: none;
}
.slide-ref-link[data-phrase]:hover {
  background: transparent;
  color: var(--primary);
}

/* Keep `data-phrase` slide refs purple and remove underline for all states */
.slide-ref-link[data-phrase],
.slide-ref-link[data-phrase]:link,
.slide-ref-link[data-phrase]:visited,
.slide-ref-link[data-phrase]:hover,
.slide-ref-link[data-phrase]:active,
.slide-ref-link[data-phrase]:focus {
  color: var(--primary) !important;
  text-decoration: none !important;
  font-weight: 600 !important;
}

/* Slide hover popover */
.slide-hover-popover {
  position: fixed;
  z-index: 9999;
  pointer-events: none;
  border: 2px solid var(--primary);
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 8px 32px rgba(0,0,0,0.7);
  background: var(--surface);
  max-width: 420px;
  transition: opacity 0.15s ease;
}

.slide-hover-popover.hidden {
  opacity: 0;
  display: none !important;
}

.slide-hover-popover canvas {
  display: block;
  max-width: 100%;
  height: auto;
}

/* Markdown table styling for Ask AI and notes */
.md-table-wrap { overflow: auto; margin: 0.75rem 0; }
.md-table-wrap table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.md-table-wrap th, .md-table-wrap td {
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid rgba(255,255,255,0.04);
  text-align: left;
  font-size: 0.95rem;
}
.md-table-wrap thead th {
  background: rgba(108,99,255,0.06);
  color: var(--text);
  font-weight: 700;
}
.md-table-wrap tr:last-child td { border-bottom: none; }

/* Ensure tables inside chat bubbles and notes look consistent */
.chat-bubble.assistant .md-table-wrap table,
.notes-content .md-table-wrap table {
  background: transparent;
  border: 1px solid var(--border);
}

/* ── Quiz ──────────────────────────────────────────────────────────────────── */
.quiz-container {
  max-width: 780px;
  margin: 0 auto;
  padding: 1.5rem 0;
}

.quiz-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 2rem;
  gap: 1rem;
}

.quiz-question {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem;
  margin-bottom: 1.25rem;
  transition: border-color 0.2s;
}

.quiz-question.answered { border-color: var(--border); }

.quiz-q-text {
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.55;
  margin-bottom: 1rem;
  color: var(--text);
}

.quiz-q-num {
  color: var(--primary);
  margin-right: 0.4rem;
}

.quiz-options {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.quiz-option {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 0.7rem 1rem;
  text-align: left;
  cursor: pointer;
  font-size: 0.9rem;
  line-height: 1.45;
  transition: background 0.15s, border-color 0.15s;
}

.quiz-option:hover:not(:disabled) {
  background: var(--border);
  border-color: var(--primary);
}

.quiz-option.correct {
  background: rgba(0, 201, 123, 0.15);
  border-color: var(--success);
  color: var(--success);
  font-weight: 600;
}

.quiz-option.wrong {
  background: rgba(255, 77, 106, 0.12);
  border-color: var(--danger);
  color: var(--danger);
}

.quiz-option:disabled { cursor: default; }

.quiz-explanation {
  margin-top: 0.9rem;
  padding: 0.75rem 1rem;
  background: rgba(108, 99, 255, 0.08);
  border-left: 3px solid var(--primary);
  border-radius: 0 6px 6px 0;
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.quiz-score {
  text-align: center;
  padding: 2.5rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  margin-top: 1rem;
}

.quiz-score-num {
  font-size: 2.5rem;
  font-weight: 700;
  color: var(--primary);
  line-height: 1.1;
}

.quiz-score-label {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-top: 0.3rem;
}

.quiz-loading {
  text-align: center;
  padding: 3rem 1rem;
}

.quiz-error {
  color: var(--danger);
  padding: 1.5rem;
  text-align: center;
}

.quiz-style-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.quiz-style-chip {
  padding: 0.4rem 0.85rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.quiz-style-chip:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.quiz-style-chip.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

/* ── Paywall modal ───────────────────────────────────────────────────────── */
.paywall-modal {
  max-width: 656px;
  width: 100%;
  padding: 0;
  overflow: hidden;
}

/* Make paywall modal scrollable when content is taller than viewport */
.paywall-modal {
  max-height: 90vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.paywall-header {
  padding: 1.75rem 2rem 1.25rem;
  border-bottom: 1px solid var(--border);
}

.paywall-header h3 {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text) !important;
  margin-bottom: 0.35rem;
}

.paywall-header p {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-bottom: 0;
}

.paywall-plans {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  padding: 1.25rem 2rem;
}

/* Responsive paywall: single column on small screens */
@media (max-width: 720px) {
  .paywall-modal {
    max-width: 95vw;
    margin: 0.5rem;
    border-radius: 12px;
  }
  .paywall-header {
    padding: 1rem 1rem 0.75rem;
  }
  .paywall-plans {
    grid-template-columns: 1fr;
    padding: 1rem;
    gap: 0.75rem;
  }
  .paywall-plan-card {
    padding: 1rem;
    border-radius: 12px;
  }
  .paywall-plan-price { font-size: 1.6rem; }
  .paywall-plan-name { font-size: 1rem; }
  .paywall-plan-features li { font-size: 0.9rem; }
  .paywall-topup { padding: 0.75rem 1rem 1rem; }
  .paywall-footer { padding: 0.75rem 1rem 1rem; display:flex; gap:0.5rem; flex-direction:column }
  .paywall-plan-billed { font-size: 0.85rem; }
}

/* Plan cards */
.paywall-plan-card {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1.25rem;
  background: var(--surface-2);
  display: flex;
  flex-direction: column;
  transition: border-color 0.2s, transform 0.2s;
  position: relative;
}
.paywall-plan-card:hover {
  border-color: var(--primary);
  transform: translateY(-2px);
}

/* Pro featured card */
.paywall-plan-card--pro {
  border-color: var(--primary);
  background: linear-gradient(160deg, rgba(255,107,107,0.06) 0%, var(--surface-2) 60%);
  box-shadow: 0 0 0 1px var(--primary), 0 8px 24px rgba(255,107,107,0.15);
}
.paywall-plan-card--pro:hover {
  transform: translateY(-3px);
  box-shadow: 0 0 0 1px var(--primary), 0 12px 32px rgba(255,107,107,0.22);
}

.paywall-plan-most-popular {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  background: rgba(255, 107, 107, 0.12);
  color: var(--primary);
  border: 1px solid rgba(255, 107, 107, 0.3);
  padding: 0.2rem 0.6rem;
  border-radius: 20px;
  margin-bottom: 0.65rem;
  align-self: flex-start;
}

.paywall-plan-name {
  font-weight: 700;
  font-size: 1.05rem;
  margin-bottom: 0.4rem;
}

.paywall-plan-price {
  font-size: 2rem;
  font-weight: 800;
  color: var(--primary);
  line-height: 1;
  margin-bottom: 0.3rem;
}
.paywall-plan-price span {
  font-size: 0.8rem;
  font-weight: 400;
  color: var(--text-muted);
}

.billing-interval {
  padding: 0.35rem 0.6rem;
  border-radius: 8px;
  font-weight: 700;
}

.billing-pill {
  display: inline-block;
  background: var(--success);
  color: #fff;
  padding: 0.18rem 0.6rem;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.78rem;
  box-shadow: 0 1px 0 rgba(0,0,0,0.06);
}

.paywall-plan-credits {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}

.paywall-plan-saving {
  font-size: 0.76rem;
  font-weight: 600;
  color: #16a34a;
  margin-bottom: 0.75rem;
}

/* Feature list */
.paywall-plan-features {
  list-style: none;
  padding: 0;
  margin: 0 0 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  flex: 1;
}
.paywall-plan-features li {
  font-size: 0.8rem;
  color: var(--text-muted);
  display: flex;
  align-items: flex-start;
  gap: 0.4rem;
}
.paywall-plan-features li::before {
  content: '✓';
  color: var(--success);
  font-weight: 700;
  flex-shrink: 0;
  margin-top: 0.05rem;
}
.paywall-plan-card--pro .paywall-plan-features li {
  color: var(--text);
}

/* CTA buttons */
.paywall-plan-btn {
  width: 100%;
  padding: 0.6rem 1rem;
  font-size: 0.88rem;
  font-weight: 600;
}
.paywall-plan-btn--pro {
  background: linear-gradient(135deg, var(--primary), #ff6b9d);
  box-shadow: 0 4px 14px rgba(255,107,107,0.35);
}
.paywall-plan-btn--pro:hover {
  background: linear-gradient(135deg, var(--primary-hover), #e0558a);
  box-shadow: 0 4px 18px rgba(255,107,107,0.5);
}

.paywall-plan-badge {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--primary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.3rem;
}
.paywall-plan-card.is-current {
  border-color: var(--primary);
}

/* Top-up section */
.paywall-topup {
  padding: 1rem 2rem 1.25rem;
  border-top: 1px solid var(--border);
}
.paywall-topup-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.65rem;
  flex-wrap: wrap;
}
.paywall-topup-title {
  font-weight: 600;
  font-size: 0.9rem;
}
.paywall-topup-rate {
  font-size: 0.78rem;
  color: var(--text-muted);
}
.paywall-topup-row {
  display: flex;
  gap: 0.75rem;
  align-items: center;
}
.paywall-topup-input-wrap {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.75rem;
  background: var(--surface-2);
  flex: 1;
  transition: border-color 0.2s;
}
.paywall-topup-input-wrap:focus-within {
  border-color: var(--primary);
}
.paywall-topup-input-wrap span {
  color: var(--text-muted);
  font-size: 0.95rem;
}
.paywall-topup-input-wrap input {
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 0.95rem;
  width: 100%;
  outline: none;
}
.paywall-topup-preview {
  color: var(--text-muted);
  font-size: 0.88rem;
  white-space: nowrap;
}

/* Footer */
.paywall-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.85rem 2rem 1.25rem;
  border-top: 1px solid var(--border);
}
.paywall-billing-btn {
  font-size: 0.82rem;
  opacity: 0.6;
}

/* ── Deck toolbar (back + export buttons) ────────────────────────────────── */
.deck-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

/* ── PDF fullscreen mode ─────────────────────────────────────────────────── */
.pdf-viewer-host:fullscreen,
.pdf-viewer-host:-webkit-full-screen {
  background: #000;
  display: flex;
  flex-direction: column;
}

.pdf-viewer-host:fullscreen .pdf-viewer-wrap,
.pdf-viewer-host:-webkit-full-screen .pdf-viewer-wrap {
  border: none;
  border-radius: 0;
  height: 100%;
}

.pdf-viewer-host:fullscreen .pdf-canvas-wrap,
.pdf-viewer-host:-webkit-full-screen .pdf-canvas-wrap {
  scroll-snap-type: y mandatory;
}

.pdf-viewer-host:fullscreen .pdf-page-wrap,
.pdf-viewer-host:-webkit-full-screen .pdf-page-wrap {
  scroll-snap-align: start;
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
}

.pdf-viewer-host:fullscreen .pdf-page-wrap .pdf-main-canvas,
.pdf-viewer-host:-webkit-full-screen .pdf-page-wrap .pdf-main-canvas {
  max-width: 100% !important;
  max-height: calc(100vh - 50px) !important;
  height: auto !important;
  width: auto !important;
  object-fit: contain;
}

.pdf-viewer-host:fullscreen .pdf-page-wrap .pdf-overlay-canvas,
.pdf-viewer-host:fullscreen .pdf-page-wrap .pdf-annotation-canvas,
.pdf-viewer-host:-webkit-full-screen .pdf-page-wrap .pdf-overlay-canvas,
.pdf-viewer-host:-webkit-full-screen .pdf-page-wrap .pdf-annotation-canvas {
  max-width: 100% !important;
  max-height: calc(100vh - 50px) !important;
  height: auto !important;
  width: auto !important;
}

.pdf-viewer-host:fullscreen .pdf-controls,
.pdf-viewer-host:-webkit-full-screen .pdf-controls {
  background: rgba(26, 29, 39, 0.95);
  backdrop-filter: blur(8px);
}

/* ── Annotation offline warning ──────────────────────────────────────────── */
.pdf-annot-offline-warn {
  margin-left: auto;
  padding: 0.2rem 0.55rem;
  background: #7c3a00;
  color: #ffcc80;
  border-radius: 4px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  white-space: nowrap;
  cursor: default;
  animation: annot-warn-pulse 2s ease-in-out infinite;
}

@keyframes annot-warn-pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.6; }
}

/* ── Mobile: slide-up notes panel ────────────────────────────────────────── */
.mobile-notes-toggle {
  display: none;
}

@media (max-width: 1024px) {
  /* Nav */
  nav { padding: 0.75rem 1rem; flex-wrap: wrap; gap: 0.5rem; }
  .nav-links { flex-wrap: wrap; gap: 0.35rem; width: 100%; justify-content: center; }
  .nav-btn { padding: 0.4rem 0.7rem; font-size: 0.8rem; }
  .auth-section { border-left: none; padding-left: 0; }
  .usage-indicator { font-size: 0.75rem; }
  main { padding: 1rem; }

  /* Compact deck toolbar */
  .deck-toolbar {
    margin-bottom: 0.35rem;
    gap: 0.4rem;
    align-items: center;
  }
  .deck-toolbar .btn {
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
    margin-bottom: 0;
    white-space: nowrap;
  }

  /* Hide the drag splitter between PDF and notes */
  .notes-container > .chat-splitter {
    display: none !important;
  }

  /* Notes container: presentation full screen, notes as overlay */
  .notes-container {
    grid-template-columns: 1fr !important;
    height: calc(100dvh - 220px);
    position: relative;
    overflow: hidden;
  }

  .notes-container > .pdf-pane-wrapper,
  .notes-container > iframe.preview-pane {
    height: 100%;
    padding-right: 0;
  }

  .notes-container > .notes-pane-wrapper,
  .notes-container > .notes-pane {
    position: absolute !important;
    bottom: 0;
    left: 0;
    right: 0;
    height: 70vh;
    transform: translateY(100%);
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 80; /* ensure on top of iframe */
    background: var(--surface);
    border-top: 2px solid var(--primary);
    border-radius: 16px 16px 0 0;
    padding-left: 0;
    box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.5);
    pointer-events: none; /* don't block presentation when closed */
  }

  /* When the container has the open flag allow interactions and show panel */
  .notes-container.mobile-notes-open > .notes-pane-wrapper,
  .notes-container.mobile-notes-open > .notes-pane {
    transform: translateY(0) !important;
    pointer-events: auto;
    z-index: 80;
    background: var(--surface) !important;
  }

  /* Safety: force notes to be overlay and not affect layout on small screens */
  .notes-container > .notes-pane-wrapper,
  .notes-container > .notes-pane {
    position: absolute !important;
    transform: translateY(100%) !important;
  }

  /* overlay that captures taps outside the notes panel */
  .notes-container > .notes-overlay {
    position: absolute;
    inset: 0;
    z-index: 70; /* below notes pane but above iframe */
    background: transparent;
  }

  /* Ensure the toggle button stays above the overlay and notes pane so it's always clickable */
  .mobile-notes-toggle {
    z-index: 90 !important;
  }

  /* Very small screens (narrow phones) — make notes a fixed overlay and keep toggle fixed */
  @media (max-width: 480px) {
    .notes-container > .notes-pane-wrapper,
    .notes-container > .notes-pane {
      position: fixed !important;
      left: 0 !important;
      right: 0 !important;
      bottom: 0 !important;
      height: 72vh !important;
      transform: translateY(100%);
      transition: transform 0.28s cubic-bezier(0.2,0,0,1);
      z-index: 80 !important;
      pointer-events: none;
    }

    .notes-container.mobile-notes-open > .notes-pane-wrapper,
    .notes-container.mobile-notes-open > .notes-pane {
      transform: translateY(0) !important;
      pointer-events: auto !important;
    }

    .notes-container > .notes-overlay {
      position: fixed !important;
      inset: 0 !important;
      z-index: 75 !important;
    }

    .mobile-notes-toggle {
      position: fixed !important;
      bottom: 1.5rem !important;
      left: 50% !important;
      transform: translateX(-50%) !important;
      z-index: 95 !important;
    }
  }

  /* Drag handle at top of slide-up panel */
  .notes-container.mobile-notes-open > .notes-pane-wrapper::before,
  .notes-container.mobile-notes-open > .notes-pane::before {
    content: '';
    display: block;
    width: 40px;
    height: 4px;
    background: var(--text-muted);
    border-radius: 2px;
    margin: 0.6rem auto 0.4rem;
    opacity: 0.5;
  }

  /* Toggle button — sits above the PDF controls bar */
  .mobile-notes-toggle {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    position: absolute;
    bottom: 3.2rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: 55;
    background: var(--primary);
    color: #fff;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(108, 99, 255, 0.4);
    transition: opacity 0.2s;
  }

  .mobile-notes-toggle:active {
    opacity: 0.85;
  }

  .mobile-notes-toggle.hidden-toggle {
    display: none;
  }

  /* Tabs: scrollable on mobile */
  .tabs { overflow-x: auto; flex-wrap: nowrap; }
  .tab { white-space: nowrap; font-size: 0.82rem; padding: 0.6rem 0.8rem; }

  /* Ask AI: hide PDF pane, chat only */
  .chat-with-pdf {
    grid-template-columns: 1fr !important;
    height: calc(100dvh - 220px);
  }
  .chat-with-pdf .chat-pdf-pane {
    display: none;
  }
  .chat-with-pdf .chat-splitter {
    display: none !important;
  }

  /* Flashcards */
  .flashcards-grid { grid-template-columns: 1fr; }

  /* Anki study card */
  .anki-front, .anki-back { min-height: 180px; padding: 1.5rem 1.25rem; }
  .anki-buttons { gap: 0.4rem; }
  .anki-btn { min-width: 60px; padding: 0.5rem 0.7rem; }

  /* PDF viewer: free scroll, letterboxed slides */
  .pdf-canvas-wrap {
    background: #000;
  }

  .pdf-page-wrap {
    background: #000;
    border-bottom: 2px solid #111;
  }

  /* Paywall grid */
  .paywall-plans { grid-template-columns: 1fr; }
  .paywall-modal { max-width: 95vw; }
}

/* Landscape phones: still show single-column notes + one slide at a time */
@media (max-height: 500px) and (orientation: landscape) {
  .notes-container {
    grid-template-columns: 1fr !important;
    height: calc(100vh - 80px);
    position: relative;
    overflow: hidden;
  }

/* Prevent scroll chaining from presentation iframe/notes to the page */
.notes-container, .preview-pane, .notes-pane {
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

  .notes-container > .chat-splitter {
    display: none !important;
  }

  .notes-container > .pdf-pane-wrapper,
  .notes-container > iframe.preview-pane {
    height: 100%;
    padding-right: 0;
  }

  .notes-container > .notes-pane-wrapper,
  .notes-container > .notes-pane {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 70vh;
    transform: translateY(100%);
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 50;
    background: #1c1f2b;
    border-top: 2px solid var(--primary);
    border-radius: 16px 16px 0 0;
    padding-left: 0;
    box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.5);
  }

  .notes-container.mobile-notes-open > .notes-pane-wrapper,
  .notes-container.mobile-notes-open > .notes-pane {
    transform: translateY(0);
  }

  .mobile-notes-toggle {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    position: absolute;
    bottom: 0.5rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: 55;
    background: var(--primary);
    color: #fff;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(108, 99, 255, 0.4);
  }

  .pdf-canvas-wrap {
    background: #000;
  }

  .pdf-page-wrap {
    background: #000;
    border-bottom: 2px solid #111;
  }

  nav { padding: 0.5rem 1rem; }
  .nav-links { flex-wrap: wrap; gap: 0.25rem; }
}
