/* ============================================================
   PaperGenAI v2.0 — Design System (Glassmorphism)
   Single-Page App  |  Inter + Outfit  |  Dark / Light
   ============================================================ */

/* ── Google Fonts ── */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Outfit:wght@500;600;700&display=swap');

/* ── CSS Variables — Light (default) ── */
:root {
  /* Background */
  --bg-image: url('/assets/bg-image-day.jpg');

  /* Glass */
  --glass-bg: rgba(255, 255, 255, 0.72);
  --glass-border: rgba(255, 255, 255, 0.5);
  --glass-shadow: 0 8px 32px rgba(0, 0, 0, 0.08);

  /* Text */
  --text-primary: #000000;
  --text-muted: #555559;

  /* Accent palette */
  --accent: #007AFF;
  --accent-glow: rgba(0, 122, 255, 0.45);
  --purple: #a855f7;
  --emerald: #10b981;
  --red: #ef4444;
  --amber: #f59e0b;

  /* Surfaces */
  --surface: rgba(255, 255, 255, 0.6);
  --surface-hover: rgba(255, 255, 255, 0.85);
  --input-bg: rgba(255, 255, 255, 0.5);
  --input-border: rgba(0, 0, 0, 0.1);
  --divider: rgba(0, 0, 0, 0.06);

  /* Misc */
  --radius: 1rem;
  --radius-sm: 0.5rem;
  --transition: 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

/* ── Dark Mode ── */
html.dark {
  --bg-image: url('/assets/bg-image-night.jpg');

  --glass-bg: rgba(30, 30, 35, 0.65);
  --glass-border: rgba(255, 255, 255, 0.08);
  --glass-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);

  --text-primary: #f5f5f7;
  --text-muted: #98989d;

  --surface: rgba(40, 40, 48, 0.6);
  --surface-hover: rgba(50, 50, 58, 0.8);
  --input-bg: rgba(255, 255, 255, 0.06);
  --input-border: rgba(255, 255, 255, 0.1);
  --divider: rgba(255, 255, 255, 0.06);
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
a { color: inherit; text-decoration: none; }
img { max-width: 100%; display: block; }
button { cursor: pointer; font-family: inherit; border: none; background: none; }
input, textarea, select { font-family: inherit; }
ul, ol { list-style: none; }

/* ── Body ── */
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 1rem;
  line-height: 1.6;
  color: var(--text-primary);
  background-image: var(--bg-image);
  background-size: cover;
  background-position: center top;
  background-repeat: no-repeat;
  background-attachment: fixed;
  min-height: 100vh;
  overflow-x: hidden;
  transition: background-image 1s ease;
}
body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -1;
  background-image: var(--bg-image);
  background-size: cover;
  background-position: center top;
  background-repeat: no-repeat;
  opacity: 1;
  transition: opacity 1s ease;
}
html.dark body::before {
  opacity: 1;
}

/* ── Font Display ── */
.font-display {
  font-family: 'Outfit', 'Inter', sans-serif;
}
h1, h2, h3, h4 {
  font-family: 'Outfit', 'Inter', sans-serif;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.2;
  color: #000000;
}
html.dark h1, html.dark h2, html.dark h3, html.dark h4 {
  color: #f5f5f7;
}

/* ── Glassmorphism Classes ── */
.glass {
  background: var(--glass-bg);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border: 1px solid var(--glass-border);
  box-shadow: var(--glass-shadow);
}
.glass-card {
  background: var(--glass-bg);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border: 1px solid var(--glass-border);
  box-shadow: var(--glass-shadow);
  border-radius: 1.5rem;
  padding: 1.5rem;
}
.glass-input {
  background: var(--input-bg);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--input-border);
  border-radius: var(--radius-sm);
  padding: 0.625rem 0.875rem;
  color: var(--text-primary);
  font-size: 0.875rem;
  outline: none;
  width: 100%;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.glass-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.glass-input::placeholder { color: var(--text-muted); }

select.glass-input {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 2rem;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236e6e73' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  cursor: pointer;
}
html.dark select.glass-input {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2398989d' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
}

textarea.glass-input { resize: vertical; min-height: 2.5rem; }

/* ── App Layout ── */
.app-container {
  max-width: 960px;
  margin: 0 auto;
  padding: 1.5rem 1rem 6rem;
  min-height: 100vh;
}

/* ── Panel System ── */
.panel {
  display: none;
  animation: fadeInUp 0.4s ease both;
}
.panel.active {
  display: block;
}

/* ── Buttons ── */
.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.75rem 1.5rem;
  border-radius: var(--radius);
  font-size: 0.9375rem;
  font-weight: 600;
  color: #fff;
  background: linear-gradient(135deg, var(--accent) 0%, #0055cc 100%);
  box-shadow: 0 4px 14px var(--accent-glow);
  border: none;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}
.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px var(--accent-glow);
}
.btn-primary:active { transform: translateY(0); }
.btn-primary:disabled {
  opacity: 0.5;
  pointer-events: none;
}
.btn-primary svg { width: 1.1rem; height: 1.1rem; }

.btn-outline {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.625rem 1.25rem;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-primary);
  background: transparent;
  border: 1px solid var(--glass-border);
  cursor: pointer;
  transition: all var(--transition);
}
.btn-outline:hover {
  background: var(--surface);
  transform: translateY(-1px);
}

.btn-sm {
  padding: 0.375rem 0.875rem;
  font-size: 0.8125rem;
  border-radius: var(--radius-sm);
}

.btn-icon-only {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: var(--radius-sm);
  background: transparent;
  border: 1px solid var(--glass-border);
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition);
}
.btn-icon-only:hover { background: var(--surface); color: var(--text-primary); }
.btn-icon-only svg { width: 1rem; height: 1rem; }

/* ── Chapter Pills ── */
.ch-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 2.25rem;
  padding: 0 0.75rem;
  border-radius: 0.5rem;
  font-size: 0.8125rem;
  font-weight: 500;
  border: 1px solid var(--glass-border);
  background: var(--surface);
  color: var(--text-primary);
  cursor: pointer;
  transition: all var(--transition);
}
.ch-btn:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
}
.ch-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  box-shadow: 0 2px 10px var(--accent-glow);
}

/* ── Dock (Bottom Navigation) ── */
.dock {
  position: fixed;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 0.25rem;
  padding: 0.5rem 0.75rem;
  border-radius: 1.5rem;
  z-index: 1000;
  max-width: 420px;
  width: calc(100% - 2rem);
  justify-content: space-around;
}
.dock-btn {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
  padding: 0.5rem 0.625rem;
  border-radius: 0.75rem;
  font-size: 0.625rem;
  font-weight: 500;
  color: var(--text-muted);
  background: transparent;
  border: none;
  cursor: pointer;
  transition: all var(--transition);
  min-width: 3rem;
}
.dock-btn i, .dock-btn svg { width: 1.25rem; height: 1.25rem; }
.dock-btn span {
  font-size: 0.6rem;
  letter-spacing: 0.02em;
}
.dock-btn:hover { color: var(--text-primary); }
.dock-btn.active {
  color: var(--accent);
}
.dock-btn.active::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 0.75rem;
  background: var(--accent);
  opacity: 0.12;
  animation: pulseGlow 2s infinite;
}

/* ── Home Panel ── */
.home-greeting {
  font-size: clamp(1.5rem, 4vw, 2rem);
  margin-bottom: 0.25rem;
}
.home-subtitle {
  font-size: 0.9375rem;
  color: var(--text-muted);
  margin-bottom: 1.5rem;
}
.stat-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}
.stat-card {
  padding: 1rem;
  border-radius: var(--radius);
  text-align: center;
}
.stat-card .stat-value {
  font-family: 'Outfit', sans-serif;
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--accent);
}
.stat-card .stat-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.125rem;
}
.quick-start-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-top: 1rem;
}
.quick-card {
  padding: 1.25rem;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all var(--transition);
  position: relative;
  overflow: hidden;
}
.quick-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
}
.quick-card .qc-icon {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 0.625rem;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 0.75rem;
  font-size: 1.25rem;
}
.quick-card h3 {
  font-size: 1rem;
  margin-bottom: 0.25rem;
}
.quick-card p {
  font-size: 0.8125rem;
  color: var(--text-muted);
  line-height: 1.5;
}
.quick-card .qc-arrow {
  position: absolute;
  top: 1rem;
  right: 1rem;
  color: var(--text-muted);
  transition: all var(--transition);
}
.quick-card:hover .qc-arrow {
  color: var(--accent);
  transform: translateX(3px);
}
.quick-card .qc-arrow svg { width: 1rem; height: 1rem; }

/* ── Chatbot Panel ── */
.chat-select-view {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.chat-active-view {
  display: none;
  flex-direction: column;
  height: calc(100vh - 12rem);
  min-height: 400px;
}
.chat-active-view.visible {
  display: flex;
}
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--divider);
}
.chat-header-info {
  font-size: 0.875rem;
  font-weight: 600;
}
.chat-header-actions {
  display: flex;
  gap: 0.5rem;
}
.chat-pills {
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  overflow-x: auto;
  border-bottom: 1px solid var(--divider);
}
.chat-pill {
  padding: 0.375rem 0.75rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 500;
  background: var(--surface);
  border: 1px solid var(--glass-border);
  color: var(--text-primary);
  cursor: pointer;
  white-space: nowrap;
  transition: all var(--transition);
}
.chat-pill:hover { border-color: var(--accent); color: var(--accent); }

.chat-body {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.msg-row { display: flex; }
.msg-row.user { justify-content: flex-end; }
.msg-row.bot { justify-content: flex-start; }
.msg-bubble {
  max-width: 80%;
  border-radius: 1.125rem;
  padding: 0.75rem 1rem;
  font-size: 0.875rem;
  line-height: 1.6;
  word-break: break-word;
}
.msg-row.user .msg-bubble {
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 0.25rem;
}
.msg-row.bot .msg-bubble {
  background: var(--surface);
  color: var(--text-primary);
  border: 1px solid var(--glass-border);
  border-bottom-left-radius: 0.25rem;
}
.msg-bubble p { margin: 0.25em 0; }
.msg-bubble ul, .msg-bubble ol { padding-left: 1.25em; margin: 0.25em 0; }
.msg-bubble code {
  background: rgba(0,0,0,0.06);
  padding: 0.15em 0.35em;
  border-radius: 0.25rem;
  font-size: 0.8125rem;
}
html.dark .msg-bubble code { background: rgba(255,255,255,0.08); }
.msg-bubble pre {
  background: rgba(0,0,0,0.05);
  padding: 0.75rem;
  border-radius: var(--radius-sm);
  overflow-x: auto;
  margin: 0.5em 0;
}
html.dark .msg-bubble pre { background: rgba(255,255,255,0.05); }

.chat-input-row {
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--divider);
  align-items: flex-end;
}
.chat-input-row textarea {
  flex: 1;
  min-height: 2.5rem;
  max-height: 8rem;
  resize: none;
}
.chat-send-btn {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  cursor: pointer;
  flex-shrink: 0;
  transition: all var(--transition);
}
.chat-send-btn:hover { transform: scale(1.05); box-shadow: 0 4px 14px var(--accent-glow); }
.chat-send-btn:disabled { opacity: 0.4; pointer-events: none; }
.chat-send-btn svg { width: 1.1rem; height: 1.1rem; }

/* Typing indicator */
.typing-indicator {
  display: flex;
  gap: 4px;
  align-items: center;
  padding: 0.75rem 1rem;
  background: var(--surface);
  border: 1px solid var(--glass-border);
  border-radius: 1.125rem;
  border-bottom-left-radius: 0.25rem;
  width: fit-content;
}
.typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: typingBounce 1.2s infinite;
}
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

/* ── Quiz Panel ── */
.quiz-view { display: none; }
.quiz-view.visible { display: block; }

.qty-btn {
  padding: 0.5rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 500;
  border: 1px solid var(--glass-border);
  background: var(--surface);
  color: var(--text-primary);
  cursor: pointer;
  transition: all var(--transition);
}
.qty-btn:hover { border-color: var(--accent); }
.qty-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.progress-track {
  height: 0.5rem;
  border-radius: 9999px;
  background: var(--surface);
  overflow: hidden;
  margin-top: 0.5rem;
}
.progress-fill {
  height: 100%;
  border-radius: 9999px;
  background: linear-gradient(90deg, var(--accent), var(--purple));
  transition: width 0.4s ease;
}

.option-btn {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.875rem 1rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--glass-border);
  background: var(--surface);
  color: var(--text-primary);
  font-size: 0.875rem;
  cursor: pointer;
  transition: all var(--transition);
  margin-bottom: 0.5rem;
}
.option-btn:hover { border-color: var(--accent); transform: translateX(4px); }
.option-btn.selected {
  border-color: var(--accent);
  background: rgba(0, 122, 255, 0.1);
}
.option-btn.correct {
  border-color: var(--emerald);
  background: rgba(16, 185, 129, 0.12);
  color: var(--emerald);
}
.option-btn.incorrect {
  border-color: var(--red);
  background: rgba(239, 68, 68, 0.1);
  color: var(--red);
}

.results-card {
  text-align: center;
  padding: 2rem;
  position: relative;
}
.award-icon {
  font-size: 4rem;
  animation: awardBounce 0.6s ease both;
  margin-bottom: 1rem;
}
.score-display {
  font-family: 'Outfit', sans-serif;
  font-size: 3rem;
  font-weight: 700;
  color: var(--accent);
}
.score-display .score-of {
  font-size: 1.25rem;
  color: var(--text-muted);
  font-weight: 400;
}
.results-msg {
  font-size: 1.125rem;
  font-weight: 600;
  margin: 0.5rem 0 1rem;
}

.quiz-breakdown {
  text-align: left;
  margin-top: 1.5rem;
}
.breakdown-item {
  padding: 0.75rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--glass-border);
  margin-bottom: 0.5rem;
  font-size: 0.8125rem;
}
.breakdown-item.is-correct { border-left: 3px solid var(--emerald); }
.breakdown-item.is-wrong { border-left: 3px solid var(--red); }

/* Spin ring for quiz loading */
.spin-ring {
  display: inline-block;
  width: 3rem;
  height: 3rem;
  border: 3px solid var(--glass-border);
  border-top: 3px solid var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 2rem auto;
}

/* Blob decorations */
.blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(60px);
  opacity: 0.15;
  pointer-events: none;
}
.blob-1 { width: 200px; height: 200px; background: var(--accent); top: -50px; right: -50px; }
.blob-2 { width: 150px; height: 150px; background: var(--purple); bottom: -40px; left: -40px; }

/* ── Paper Generator Panel ── */
.paper-layout {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* Paper Loading Overlay */
.paper-loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 1500;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.3s ease both;
}
.paper-loading-card {
  background: var(--glass-bg);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid var(--glass-border);
  border-radius: 1.5rem;
  padding: 2.5rem 2rem;
  max-width: 380px;
  width: 90%;
  text-align: center;
  animation: fadeInUp 0.4s ease both;
  box-shadow: 0 24px 80px rgba(0,0,0,0.3);
}
.paper-loading-spinner {
  position: relative;
  width: 4rem;
  height: 4rem;
  margin: 0 auto 1.25rem;
}
.pls-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 3px solid transparent;
  border-top-color: var(--accent);
  animation: paperSpin 1s linear infinite;
}
.pls-ring-2 {
  inset: 6px;
  border-top-color: var(--purple);
  animation-duration: 1.4s;
  animation-direction: reverse;
}
.pls-ring-3 {
  inset: 12px;
  border-top-color: var(--emerald);
  animation-duration: 1.8s;
}
@keyframes paperSpin {
  to { transform: rotate(360deg); }
}
.paper-loading-text {
  font-family: 'Outfit', sans-serif;
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 0.75rem;
}
.paper-loading-bar {
  height: 4px;
  border-radius: 4px;
  background: var(--surface);
  overflow: hidden;
  margin: 0 auto 0.75rem;
  max-width: 200px;
}
.paper-loading-bar-fill {
  height: 100%;
  width: 0%;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--accent), var(--purple), var(--emerald));
  animation: paperBarProgress 2s ease-in-out infinite;
}
@keyframes paperBarProgress {
  0% { width: 0%; margin-left: 0; }
  50% { width: 70%; margin-left: 15%; }
  100% { width: 0%; margin-left: 100%; }
}
.paper-loading-sub {
  font-size: 0.8125rem;
  color: var(--text-muted);
}

.chapter-wrap {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.5rem;
  margin-top: 0.5rem;
}
@media (min-width: 768px) {
  .chapter-wrap { grid-template-columns: repeat(6, 1fr); }
}
@media (max-width: 480px) {
  .chapter-wrap { grid-template-columns: repeat(4, 1fr); }
}

/* A4 Preview */
/* A4 Preview - paper frame view */
.a4-scroll-wrap {
  background: var(--surface);
  border-radius: 1rem;
  padding: 0.75rem;
  max-height: 55rem;
  overflow-y: auto;
  border: 1px solid var(--glass-border);
}
html.dark .a4-scroll-wrap { background: rgba(255, 255, 255, 0.04); }

.a4-page {
  background: white;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06), 0 0 0 1px rgba(0,0,0,0.02);
  border-radius: 0.375rem;
  width: 210mm;
  max-width: 100%;
  min-height: 297mm;
  padding: 12mm 14mm;
  margin-inline: auto;
  margin-bottom: 1.25rem;
  position: relative;
  transition: box-shadow 0.3s ease;
}
.a4-page:last-child { margin-bottom: 0; }
.a4-page:hover {
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.1);
}
.paper-a4 {
  font-family: 'Times New Roman', Georgia, serif;
  font-size: 11pt;
  line-height: 1.5;
  color: #000;
}
.reduced-motion .paper-loading-bar-fill {
  animation: none;
  width: 60%;
}
.paper-a4 h1, .paper-a4 h2, .paper-a4 h3 { font-family: 'Times New Roman', Georgia, serif; color: #000; margin: 0.4em 0 0.3em; text-align: center; }
.paper-a4 h1 { font-size: 14pt; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; }
.paper-a4 h2 { font-size: 12pt; font-weight: 700; }
.paper-a4 h3 { font-size: 11pt; font-weight: 700; text-align: left; }
.paper-a4 p, .paper-a4 li { font-size: 11pt; margin: 0.25em 0; }
.paper-a4 ul, .paper-a4 ol { padding-left: 1.4em; margin: 0.3em 0; }
.paper-a4 hr { border: 0; border-top: 1px solid #000; margin: 0.6em 0; }
.paper-a4 strong { color: #000; }
.paper-a4 table { width: 100%; border-collapse: collapse; font-size: 10.5pt; }
.paper-a4 table th, .paper-a4 table td { border: 1px solid #000; padding: 3px 6px; }
.paper-a4 table.options-table,
.paper-a4 table.options-table tr,
.paper-a4 table.options-table td { border: none !important; padding: 2px 4px !important; }
.paper-a4 table.options-table td { width: 25%; }

/* Authentic board headers */
.paper-header { margin-bottom: 1.5rem; color: #000; text-align: left; }
.paper-header .board-name { font-size: 12pt; font-weight: 800; text-align: center; text-transform: uppercase; margin-bottom: 0.25rem; letter-spacing: 0.5px; }
.paper-header .paper-type-title { font-size: 11pt; font-weight: 700; text-align: center; text-transform: uppercase; margin-bottom: 0.75rem; letter-spacing: 1px; }
.header-info-table { width: 100% !important; border-collapse: collapse !important; margin-bottom: 0.5rem !important; }
.header-info-table td { border: 1px solid #000 !important; padding: 4px 8px !important; font-size: 10pt !important; }
.roll-no-table td { border: 1px solid #000 !important; width: 16px !important; height: 18px !important; padding: 0 !important; text-align: center !important; }

/* Variant tabs */
.variant-tabs {
  display: inline-flex;
  border-radius: var(--radius-sm);
  background: var(--surface);
  padding: 0.25rem;
  gap: 0.25rem;
  margin-bottom: 0.75rem;
}
.variant-tab {
  padding: 0.375rem 0.875rem;
  font-size: 0.8125rem;
  font-weight: 500;
  border-radius: calc(var(--radius-sm) - 2px);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  border: none;
  transition: all var(--transition);
}
.variant-tab.active {
  background: var(--glass-bg);
  color: var(--text-primary);
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}

.paper-actions {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
  flex-wrap: wrap;
}

/* Empty state */
.empty-state {
  min-height: 20rem;
  border: 1px dashed var(--glass-border);
  border-radius: var(--radius);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--text-muted);
  gap: 0.5rem;
  padding: 2rem;
}
.empty-state svg { width: 3rem; height: 3rem; opacity: 0.3; margin-bottom: 0.5rem; }

/* ── History Panel ── */
.history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--glass-border);
  background: var(--surface);
  margin-bottom: 0.5rem;
  transition: all var(--transition);
}
.history-item:hover { border-color: var(--accent); }
.history-item-info h4 {
  font-size: 0.9375rem;
  margin-bottom: 0.125rem;
}
.history-item-info p {
  font-size: 0.75rem;
  color: var(--text-muted);
}
.history-item-actions {
  display: flex;
  gap: 0.375rem;
}

/* ── Settings Panel ── */
.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--glass-border);
  margin-bottom: 0.75rem;
  background: var(--surface);
}
.setting-info h4 {
  font-size: 0.9375rem;
  margin-bottom: 0.125rem;
}
.setting-info p {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Toggle Switch */
.toggle {
  position: relative;
  width: 2.75rem;
  height: 1.5rem;
  border-radius: 9999px;
  background: var(--text-muted);
  cursor: pointer;
  transition: background var(--transition);
  flex-shrink: 0;
}
.toggle.on { background: var(--accent); }
.toggle .knob {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 1.125rem;
  height: 1.125rem;
  border-radius: 50%;
  background: white;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
  transition: transform var(--transition);
}
.toggle.on .knob { transform: translateX(1.25rem); }

/* ── Toast Notifications ── */
#toastStack {
  position: fixed;
  top: 1.5rem;
  right: 1.5rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.8125rem;
  font-weight: 500;
  max-width: 22rem;
  pointer-events: all;
  animation: fadeInUp 0.35s ease both;
  border: 1px solid var(--glass-border);
  cursor: pointer;
}
.toast.success {
  background: rgba(16, 185, 129, 0.15);
  color: var(--emerald);
  border-color: rgba(16, 185, 129, 0.3);
}
.toast.error {
  background: rgba(239, 68, 68, 0.15);
  color: var(--red);
  border-color: rgba(239, 68, 68, 0.3);
}
.toast.info {
  background: rgba(0, 122, 255, 0.15);
  color: var(--accent);
  border-color: rgba(0, 122, 255, 0.3);
}
.toast svg { width: 1rem; height: 1rem; flex-shrink: 0; }
.toast.toast-out { animation: fadeOutRight 0.3s ease forwards; }

/* ── Modals ── */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}
.overlay.open { display: flex; }

.modal-box {
  background: var(--glass-bg);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid var(--glass-border);
  border-radius: 1.5rem;
  padding: 2rem;
  max-width: 560px;
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
  animation: fadeInUp 0.35s ease both;
  color: var(--text-primary);
}
.modal-box h2 {
  font-size: 1.375rem;
  margin-bottom: 1rem;
}
.modal-box p {
  font-size: 0.9rem;
  color: var(--text-muted);
  line-height: 1.7;
  margin-bottom: 0.75rem;
}
.modal-close {
  float: right;
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
  border: none;
  font-size: 1.25rem;
  transition: all var(--transition);
}
.modal-close:hover { background: var(--surface-hover); color: var(--text-primary); }

/* ── FAQ Modal Styles ── */
.faq-list {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}
.faq-item {
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  overflow: hidden;
}
.faq-q {
  font-weight: 600;
  font-size: 0.875rem;
  padding: 0.75rem 1rem;
  cursor: pointer;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  transition: background var(--transition);
  user-select: none;
}
.faq-q:hover {
  background: var(--surface-hover);
}
.faq-q::after {
  content: '+';
  font-size: 1.25rem;
  font-weight: 400;
  color: var(--accent);
  margin-left: auto;
  flex-shrink: 0;
}
.faq-item.open .faq-q::after {
  content: '−';
}
.faq-a {
  font-size: 0.8125rem;
  color: var(--text-muted);
  line-height: 1.7;
  padding: 0 1rem 0.875rem;
  display: none;
}
.faq-item.open .faq-a {
  display: block;
  animation: fadeIn 0.3s ease both;
}

/* ── Footer Links ── */
.footer-links {
  display: flex;
  justify-content: center;
  gap: 1.5rem;
  flex-wrap: wrap;
  padding: 1rem 0 2rem;
  font-size: 0.75rem;
  color: var(--text-muted);
}
.footer-links a {
  color: var(--text-muted);
  transition: color var(--transition);
}
.footer-links a:hover { color: var(--accent); }

/* ── Form helpers ── */
.form-group { margin-bottom: 0.75rem; }
.form-group label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
@media (max-width: 480px) { .form-grid { grid-template-columns: 1fr; } }

.checkbox-wrap {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--glass-border);
  background: var(--surface);
  cursor: pointer;
  font-size: 0.8125rem;
}
.checkbox-wrap input[type="checkbox"] {
  accent-color: var(--accent);
  width: 1rem;
  height: 1rem;
}

/* ── Animations ── */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes fadeOutRight {
  from { opacity: 1; transform: translateX(0); }
  to { opacity: 0; transform: translateX(1.5rem); }
}
@keyframes pulseGlow {
  0% { opacity: 0.12; }
  50% { opacity: 0.22; }
  100% { opacity: 0.12; }
}
@keyframes typingBounce {
  0%, 80%, 100% { transform: translateY(0); }
  40% { transform: translateY(-6px); }
}
@keyframes spin {
  to { transform: rotate(360deg); }
}
@keyframes awardBounce {
  0% { transform: scale(0); }
  60% { transform: scale(1.2); }
  100% { transform: scale(1); }
}

.animate-fade-in { animation: fadeIn 0.4s ease both; }
.animate-fade-in-up { animation: fadeInUp 0.5s ease both; }

/* ── Reduce Motion ── */
html.reduce-motion *,
html.reduce-motion *::before,
html.reduce-motion *::after {
  animation-duration: 0.01ms !important;
  transition-duration: 0.01ms !important;
}

/* ── Utility ── */
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }
.text-sm { font-size: 0.875rem; }
.text-xs { font-size: 0.75rem; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); border: 0; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mb-1 { margin-top: 0.5rem; }
.gap-sm { gap: 0.5rem; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.justify-center { justify-content: center; }
.flex-wrap { flex-wrap: wrap; }
.flex-1 { flex: 1; }
.w-full { width: 100%; }

/* ── Scrollbar ── Hide completely but keep scroll functionality */
* {
  scrollbar-width: none; /* Firefox */
  -ms-overflow-style: none; /* IE/Edge */
}
*::-webkit-scrollbar {
  display: none; /* Chrome/Safari/Opera */
}

/* ── Responsive ── */
@media (max-width: 640px) {
  .app-container { padding: 1rem 0.75rem 5.5rem; }
  .stat-row { grid-template-columns: 1fr 1fr; gap: 0.5rem; }
  .quick-start-grid { grid-template-columns: 1fr; }
  .msg-bubble { max-width: 90%; }
  .dock { bottom: 0.5rem; padding: 0.375rem 0.5rem; border-radius: 1.25rem; }
}

/* ── Print ── */
@media print {
  .no-print { display: none !important; }
  body { background: white !important; }
  .a4-page { box-shadow: none; margin: 0; page-break-after: always; }
  .a4-scroll-wrap { max-height: none; overflow: visible; padding: 0; border: none; background: none; }
  .dock, .app-container > *:not(.panel.active) { display: none !important; }
}

/* ── Section headings ── */
.section-title {
  font-size: 1.25rem;
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.section-title svg { width: 1.25rem; height: 1.25rem; color: var(--accent); }

/* ── Smooth Enhancements ── */
html {
  scroll-behavior: smooth;
  -webkit-tap-highlight-color: transparent;
}
* {
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
}
button, a, [role="button"] {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

/* Smooth interactive hover states */
button, .quick-card, .dock-btn, .qty-btn, .ch-btn, .option-btn,
.history-item, .chat-pill, .variant-tab, .faq-q, .modal-close {
  transition: all var(--transition) cubic-bezier(0.16, 1, 0.3, 1);
}

/* Smooth active press feedback */
button:active:not(:disabled), .quick-card:active, .qty-btn:active, .ch-btn:active {
  transform: scale(0.96);
  opacity: 0.85;
}

/* Smooth sliding transitions for panels */
.panel {
  display: none;
  animation: fadeInUp 0.4s cubic-bezier(0.16, 1, 0.3, 1) both;
}
.panel.active {
  display: block;
  animation: fadeInUp 0.45s cubic-bezier(0.16, 1, 0.3, 1) both;
}

/* Smooth modal open/close */
.overlay {
  transition: opacity 0.3s ease, visibility 0.3s ease;
  opacity: 0;
  visibility: hidden;
}
.overlay.open {
  opacity: 1;
  visibility: visible;
}
.modal-box {
  transition: transform 0.35s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.3s ease;
  transform: scale(0.92) translateY(20px);
  opacity: 0;
}
.overlay.open .modal-box {
  transform: scale(1) translateY(0);
  opacity: 1;
}

/* Smooth hover lift for cards */
.quick-card, .history-item, .glass-card {
  transition: transform var(--transition), box-shadow var(--transition), border-color var(--transition);
}
.quick-card:hover, .history-item:hover {
  transform: translateY(-3px);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.12);
}

/* Smooth progress bar */
.progress-fill {
  transition: width 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}

/* Smooth option selection */
.option-btn {
  transform: translateX(0);
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}
.option-btn:hover {
  transform: translateX(6px);
}

/* Smooth chat bubbles */
.msg-row {
  animation: slideIn 0.35s cubic-bezier(0.16, 1, 0.3, 1) both;
}
@keyframes slideIn {
  from { opacity: 0; transform: translateY(12px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* Smooth toast stack */
#toastStack {
  position: fixed;
  top: 1.5rem;
  right: 1.5rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
}
.toast {
  pointer-events: all;
  animation: toastIn 0.4s cubic-bezier(0.16, 1, 0.3, 1) both;
  transition: all 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}
.toast.toast-out {
  animation: toastOut 0.35s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}
@keyframes toastIn {
  from { opacity: 0; transform: translateX(100%) scale(0.9); }
  to { opacity: 1; transform: translateX(0) scale(1); }
}
@keyframes toastOut {
  from { opacity: 1; transform: translateX(0) scale(1); }
  to { opacity: 0; transform: translateX(120%) scale(0.9); }
}

/* Responsive smoothness */
@media (max-width: 768px) {
  .paper-layout {
    gap: 1rem;
  }
  .glass-card {
    padding: 1.25rem;
    border-radius: 1.25rem;
  }
  .a4-scroll-wrap {
    padding: 0.5rem;
    max-height: 45rem;
  }
}
@media (max-width: 640px) {
  .app-container {
    padding: 1rem 0.75rem 5.5rem;
    transition: padding 0.3s ease;
  }
  .stat-row {
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
    transition: all 0.3s ease;
  }
  .quick-start-grid {
    grid-template-columns: 1fr;
    gap: 0.625rem;
  }
  .msg-bubble {
    max-width: 90%;
  }
  .dock {
    bottom: 0.5rem;
    padding: 0.375rem 0.5rem;
    border-radius: 1.25rem;
    transition: all 0.3s ease;
  }

  /* Mobile: dock ke upar content chipakne se bachao */
  .panel {
    padding-bottom: 5.5rem;
  }
  #previewContent, #a4Page, #historyList, #chatBody {
    max-height: calc(100vh - 18rem);
    overflow-y: auto;
  }

  .history-item {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.75rem;
  }
  .history-item-actions {
    width: 100%;
    justify-content: flex-end;
  }
}

/* Smooth input focus */
.glass-input {
  transition: border-color 0.25s cubic-bezier(0.16, 1, 0.3, 1),
              box-shadow 0.25s cubic-bezier(0.16, 1, 0.3, 1),
              background-color 0.25s ease;
}

/* Smooth loading overlay */
.paper-loading-overlay {
  animation: fadeIn 0.3s cubic-bezier(0.16, 1, 0.3, 1) both;
}
.paper-loading-card {
  animation: scaleIn 0.4s cubic-bezier(0.16, 1, 0.3, 1) both;
}
@keyframes scaleIn {
  from { opacity: 0; transform: scale(0.9) translateY(20px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

/* Smooth A4 page load */
@keyframes pageLoad {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}
.a4-page {
  animation: pageLoad 0.4s cubic-bezier(0.16, 1, 0.3, 1) both;
}
.a4-page:nth-child(1) { animation-delay: 0ms; }
.a4-page:nth-child(2) { animation-delay: 80ms; }
.a4-page:nth-child(3) { animation-delay: 160ms; }
.a4-page:nth-child(4) { animation-delay: 240ms; }

/* Smooth theme transition */
html.dark, html:not(.dark) {
  transition: background-color 0.5s ease, color 0.5s ease;
}
body, body::before {
  transition: background-image 1s ease, opacity 1s ease;
}
