/* ==============================================================================
   ZenStudy: High-Focus Systems Learning Interface
   Aesthetic Philosophy: Japanese Minimalism (Ma) & Dieter Rams Functionalism
   ============================================================================== */

:root {
  /* Dimensions & Spacing */
  --sidebar-width: 320px;
  --topbar-height: 56px;
  --reading-max-width: 820px;
  --font-base-size: 18px;
  
  /* Fonts */
  --font-serif: 'Newsreader', Garamond, Georgia, serif;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', Menlo, Monaco, Consolas, monospace;
  --font-reading: var(--font-serif);
}

/* ==============================================================================
   THEMES: Obsidian Dark (Default), Washi Sepia, Studio Light
   ============================================================================== */

/* 1. Obsidian Dark */
[data-theme="dark"] {
  --bg-app: #08090d;
  --bg-sidebar: #0e1017;
  --bg-surface: #131722;
  --bg-card: #181d2a;
  --bg-hover: #1f2536;
  --border: #22283a;
  --border-focus: #38bdf8;
  
  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  --text-faint: #64748b;
  --text-code: #38bdf8;

  --accent: #38bdf8;
  --accent-glow: rgba(56, 189, 248, 0.15);
  --accent-green: #34d399;
  --accent-amber: #fbbf24;
  --accent-rose: #f43f5e;

  --prose-body: #e2e8f0;
  --prose-heading: #ffffff;
  --prose-code-bg: #141824;
}

/* 2. Washi Sepia */
[data-theme="sepia"] {
  --bg-app: #fbf9f4;
  --bg-sidebar: #f5efe6;
  --bg-surface: #ede4d6;
  --bg-card: #ffffff;
  --bg-hover: #e5dac9;
  --border: #dfd3c1;
  --border-focus: #c84b31;
  
  --text-main: #2b2621;
  --text-muted: #6b635b;
  --text-faint: #9c9288;
  --text-code: #c84b31;

  --accent: #c84b31;
  --accent-glow: rgba(200, 75, 49, 0.12);
  --accent-green: #2d8a5c;
  --accent-amber: #b87b14;
  --accent-rose: #c84b31;

  --prose-body: #332d28;
  --prose-heading: #1e1a17;
  --prose-code-bg: #efe8dc;
}

/* 3. Studio Light */
[data-theme="light"] {
  --bg-app: #ffffff;
  --bg-sidebar: #f8fafc;
  --bg-surface: #f1f5f9;
  --bg-card: #ffffff;
  --bg-hover: #e2e8f0;
  --border: #e2e8f0;
  --border-focus: #2563eb;
  
  --text-main: #0f172a;
  --text-muted: #64748b;
  --text-faint: #94a3b8;
  --text-code: #2563eb;

  --accent: #2563eb;
  --accent-glow: rgba(37, 99, 235, 0.1);
  --accent-green: #10b981;
  --accent-amber: #f59e0b;
  --accent-rose: #ef4444;

  --prose-body: #1e293b;
  --prose-heading: #0f172a;
  --prose-code-bg: #f8fafc;
}

/* Font Family Overrides */
[data-font="sans"] {
  --font-reading: var(--font-sans);
}
[data-font="serif"] {
  --font-reading: var(--font-serif);
}

/* Base Reset & Box Sizing */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-sans);
  background: var(--bg-app);
  color: var(--text-main);
  height: 100vh;
  overflow: hidden;
  transition: background 0.25s ease, color 0.25s ease;
  -webkit-font-smoothing: antialiased;
}

/* Top Progress Bar */
#reading-progress-bar {
  position: fixed;
  top: 0;
  left: 0;
  height: 3px;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--accent-green));
  z-index: 1000;
  transition: width 0.1s ease-out;
}

/* Main Container Layout */
#app-container {
  display: flex;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}

/* ==============================================================================
   SIDEBAR NAVIGATION
   ============================================================================== */

#sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), margin-left 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  z-index: 50;
  overflow: hidden;
}

.sidebar-header {
  padding: 18px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-badge {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
}

.brand-text {
  display: flex;
  flex-direction: column;
}

.brand-title {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.brand-sub {
  font-size: 11px;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Quick Resume Card */
.resume-card {
  margin: 14px 16px;
  padding: 12px 14px;
  background: var(--accent-glow);
  border: 1px solid var(--accent);
  border-radius: 10px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.resume-icon {
  color: var(--accent);
}

.resume-info {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
}

.resume-label {
  font-size: 10px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.08em;
}

.resume-chapter {
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.resume-btn {
  background: var(--accent);
  color: #000;
  border: none;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.15s ease;
}

.resume-btn:hover {
  transform: translateX(2px);
}

/* Live Hardware Status Pill */
.hardware-pill {
  margin: 0 16px 12px 16px;
  padding: 8px 12px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.hardware-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent-green);
  box-shadow: 0 0 8px var(--accent-green);
}

.hardware-text {
  display: flex;
  flex-direction: column;
  font-size: 11px;
}

.hardware-text strong {
  color: var(--accent-green);
}

.hardware-text small {
  color: var(--text-faint);
  font-family: var(--font-mono);
  font-size: 10px;
}

/* TOC Navigation List */
#toc-nav {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
}

.toc-group-title {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--text-faint);
  margin-bottom: 8px;
  padding-left: 8px;
}

.chapter-btn {
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  margin-bottom: 4px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 3px;
  transition: all 0.15s ease;
}

.chapter-btn:hover {
  background: var(--bg-hover);
  color: var(--text-main);
}

.chapter-btn.active {
  background: var(--bg-surface);
  border-color: var(--border-focus);
  color: var(--text-main);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.chapter-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  font-weight: 600;
}

.chapter-badge {
  font-size: 9px;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--bg-hover);
  color: var(--accent);
  font-family: var(--font-mono);
}

.chapter-meta-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: var(--text-faint);
}

.lab-item {
  width: 100%;
  text-align: left;
  padding: 9px 12px;
  margin-bottom: 4px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  transition: all 0.15s ease;
}

.lab-item:hover {
  border-color: var(--accent);
  color: var(--text-main);
}

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
}

.footer-btn {
  flex: 1;
  padding: 8px 10px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-muted);
  font-size: 11px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: all 0.15s ease;
}

.footer-btn:hover {
  background: var(--bg-hover);
  color: var(--text-main);
}

/* ==============================================================================
   MAIN CONTENT & TOP ACTION BAR
   ============================================================================== */

#main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  position: relative;
  overflow: hidden;
}

#top-bar {
  height: var(--topbar-height);
  border-bottom: 1px solid var(--border);
  background: var(--bg-sidebar);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  z-index: 40;
}

.top-left {
  display: flex;
  align-items: center;
  gap: 14px;
}

.breadcrumb {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
}

.top-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.icon-btn {
  width: 32px;
  height: 32px;
  border-radius: 6px;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s ease;
}

.icon-btn:hover {
  background: var(--bg-surface);
  color: var(--text-main);
  border-color: var(--border);
}

.font-toggle-group, .size-controls, .theme-controls {
  display: flex;
  align-items: center;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 2px;
}

.font-btn {
  padding: 4px 10px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
  border-radius: 4px;
  cursor: pointer;
}

.font-btn.active {
  background: var(--bg-card);
  color: var(--text-main);
  box-shadow: 0 1px 4px rgba(0,0,0,0.1);
}

.theme-btn {
  width: 28px;
  height: 28px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.theme-btn.active {
  background: var(--bg-card);
  color: var(--accent);
}

.pill-btn {
  padding: 6px 12px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text-main);
  font-size: 12px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.pill-btn:hover {
  border-color: var(--accent);
}

/* ==============================================================================
   READING CANVAS & TYPOGRAPHY (EDITORIAL QUALITY)
   ============================================================================== */

#reading-scroll-area {
  flex: 1;
  overflow-y: auto;
  scroll-behavior: smooth;
  padding: 40px 24px 120px 24px;
}

#article-wrapper {
  max-width: var(--reading-max-width);
  margin: 0 auto;
  font-family: var(--font-reading);
  font-size: var(--font-base-size);
  line-height: 1.8;
  color: var(--prose-body);
  transition: max-width 0.3s ease;
}

/* Markdown Prose Styling */
#article-wrapper h1 {
  font-family: var(--font-sans);
  font-size: 2.3em;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--prose-heading);
  margin: 32px 0 16px 0;
  line-height: 1.25;
}

#article-wrapper h2 {
  font-family: var(--font-sans);
  font-size: 1.6em;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--prose-heading);
  margin: 44px 0 16px 0;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
  line-height: 1.3;
}

#article-wrapper h3 {
  font-family: var(--font-sans);
  font-size: 1.25em;
  font-weight: 600;
  color: var(--prose-heading);
  margin: 32px 0 12px 0;
  line-height: 1.35;
}

#article-wrapper p {
  margin-bottom: 22px;
}

#article-wrapper ul, #article-wrapper ol {
  margin-bottom: 24px;
  padding-left: 28px;
}

#article-wrapper li {
  margin-bottom: 8px;
}

#article-wrapper blockquote {
  border-left: 3px solid var(--accent);
  background: var(--bg-surface);
  padding: 16px 20px;
  border-radius: 0 8px 8px 0;
  margin: 24px 0;
  font-style: italic;
}

#article-wrapper hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 40px 0;
}

#article-wrapper code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  background: var(--prose-code-bg);
  border: 1px solid var(--border);
  padding: 2px 6px;
  border-radius: 4px;
  color: var(--text-code);
}

#article-wrapper pre {
  background: var(--prose-code-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
  overflow-x: auto;
  margin: 28px 0;
  position: relative;
}

#article-wrapper pre code {
  background: transparent;
  border: none;
  padding: 0;
  color: var(--text-main);
  font-size: 0.86em;
  line-height: 1.6;
}

/* Tables */
#article-wrapper table {
  width: 100%;
  border-collapse: collapse;
  margin: 28px 0;
  font-size: 0.9em;
}

#article-wrapper th, #article-wrapper td {
  border: 1px solid var(--border);
  padding: 10px 14px;
  text-align: left;
}

#article-wrapper th {
  background: var(--bg-surface);
  font-weight: 600;
  color: var(--prose-heading);
}

/* Interactive Quiz Cards in Markdown */
.quiz-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  margin: 28px 0;
}

.quiz-question {
  font-family: var(--font-sans);
  font-size: 1.05em;
  font-weight: 600;
  color: var(--prose-heading);
  margin-bottom: 16px;
}

.quiz-option {
  padding: 12px 16px;
  margin-bottom: 8px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.95em;
  transition: all 0.15s ease;
}

.quiz-option:hover {
  border-color: var(--accent);
}

.quiz-option.correct {
  background: rgba(52, 211, 153, 0.12);
  border-color: var(--accent-green);
  color: var(--accent-green);
  font-weight: 600;
}

.quiz-option.incorrect {
  background: rgba(244, 63, 94, 0.12);
  border-color: var(--accent-rose);
  color: var(--accent-rose);
}

.quiz-explanation {
  margin-top: 16px;
  padding: 14px 18px;
  background: var(--bg-hover);
  border-radius: 8px;
  font-size: 0.9em;
  display: none;
  animation: fadeIn 0.2s ease;
}

/* Chapter Pagination Footer */
.pagination-footer {
  margin-top: 60px;
  padding-top: 32px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.page-nav-btn {
  padding: 10px 20px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-main);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all 0.15s ease;
}

.page-nav-btn:hover {
  border-color: var(--accent);
}

.mark-complete-btn {
  padding: 10px 20px;
  background: var(--accent-glow);
  border: 1px solid var(--accent);
  border-radius: 8px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all 0.15s ease;
}

.mark-complete-btn.completed {
  background: var(--accent-green);
  color: #000;
  border-color: var(--accent-green);
}

/* ==============================================================================
   ZEN FOCUS MODE OVERRIDES
   ============================================================================== */

body.zen-mode #sidebar {
  transform: translateX(-100%);
  margin-left: calc(-1 * var(--sidebar-width));
}

body.zen-mode #article-wrapper {
  max-width: 780px;
}

body.zen-mode #top-bar {
  opacity: 0.4;
  transition: opacity 0.2s ease;
}

body.zen-mode #top-bar:hover {
  opacity: 1.0;
}

/* ==============================================================================
   DRAWERS: Bookmarks & AI Companion
   ============================================================================== */

.drawer {
  position: fixed;
  top: 0;
  right: -380px;
  width: 380px;
  height: 100vh;
  background: var(--bg-sidebar);
  border-left: 1px solid var(--border);
  box-shadow: -8px 0 32px rgba(0, 0, 0, 0.25);
  display: flex;
  flex-direction: column;
  transition: right 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  z-index: 100;
}

.drawer.open {
  right: 0;
}

.drawer-header {
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.drawer-header h3 {
  font-size: 15px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}

.close-drawer-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
}

.drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
}

.drawer-desc {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 16px;
  line-height: 1.5;
}

.ai-prompt-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  margin-bottom: 12px;
}

.ai-prompt-title {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
}

.ai-prompt-text {
  font-size: 12px;
  color: var(--text-muted);
  font-style: italic;
  margin-bottom: 10px;
  line-height: 1.4;
}

.copy-prompt-btn {
  padding: 6px 12px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 11px;
  color: var(--text-main);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
}

.copy-prompt-btn:hover {
  border-color: var(--accent);
}

/* ==============================================================================
   INTERACTIVE LABS & MODAL SIMULATORS
   ============================================================================== */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

.modal-overlay.open {
  display: flex;
}

.modal-content {
  width: 90%;
  max-width: 800px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.4);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.modal-header {
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-body {
  padding: 24px;
  max-height: 80vh;
  overflow-y: auto;
}

/* RoPE Canvas & Controls */
.rope-container {
  display: flex;
  gap: 24px;
}

.rope-canvas-box {
  flex: 1;
  height: 320px;
  background: var(--bg-app);
  border: 1px solid var(--border);
  border-radius: 12px;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.rope-controls {
  width: 280px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.slider-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.slider-group label {
  font-size: 12px;
  font-weight: 600;
  display: flex;
  justify-content: space-between;
}

.slider-group input[type="range"] {
  accent-color: var(--accent);
}

/* Memory Calculator Styles */
.calc-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 24px;
}

.calc-gauge {
  background: var(--bg-app);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.gauge-val {
  font-size: 2.2em;
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--accent-green);
  margin: 8px 0;
}

.gauge-status {
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.gauge-status.safe {
  background: rgba(52, 211, 153, 0.15);
  color: var(--accent-green);
}

.gauge-status.warning {
  background: rgba(251, 191, 36, 0.15);
  color: var(--accent-amber);
}

.gauge-status.danger {
  background: rgba(244, 63, 94, 0.15);
  color: var(--accent-rose);
}

/* ==============================================================================
   EXPANDED VISUALIZER SUITE STYLING
   ============================================================================== */

/* 1. Attention Heatmap */
.attn-matrix-container {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.attn-controls-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg-surface);
  padding: 10px 16px;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.attn-table {
  border-collapse: separate;
  border-spacing: 4px;
  margin: 0 auto;
}

.attn-cell {
  width: 52px;
  height: 52px;
  text-align: center;
  vertical-align: middle;
  border-radius: 6px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.1s ease, box-shadow 0.1s ease;
  position: relative;
}

.attn-cell:hover {
  transform: scale(1.08);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  z-index: 10;
}

.attn-cell.masked {
  background: rgba(255, 255, 255, 0.03);
  color: var(--text-faint);
  border: 1px dashed var(--border);
}

.attn-header-token {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  padding: 6px;
  color: var(--text-muted);
}

.attn-tooltip-box {
  background: var(--bg-surface);
  border: 1px solid var(--accent);
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 12px;
  line-height: 1.5;
}

/* 2. Sampling Bar Chart */
.sampling-chart-box {
  background: var(--bg-app);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  position: relative;
}

.prob-bar-row {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 12px;
  font-family: var(--font-mono);
}

.prob-token-name {
  width: 120px;
  text-align: right;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.prob-bar-track {
  flex: 1;
  height: 18px;
  background: var(--bg-surface);
  border-radius: 4px;
  overflow: hidden;
  position: relative;
}

.prob-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-green));
  border-radius: 4px;
  transition: width 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.prob-bar-fill.masked-tail {
  background: var(--text-faint);
  opacity: 0.3;
}

.prob-pct-val {
  width: 55px;
  text-align: left;
}

/* 3. Roofline & Speedometer */
.roofline-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

.speedometer-card {
  background: var(--bg-app);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.speed-number {
  font-size: 3em;
  font-weight: 800;
  font-family: var(--font-mono);
  color: var(--accent);
  line-height: 1;
  margin: 10px 0;
}

/* 4. MLA vs GQA Comparison */
.mla-comparison-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-top: 16px;
}

.mla-card {
  background: var(--bg-app);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.mla-bar-visual {
  width: 48px;
  background: var(--accent);
  border-radius: 6px;
  margin: 16px 0;
  transition: height 0.3s ease;
}

/* 5. Architecture Cards */
.arch-card-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.arch-model-card {
  background: var(--bg-app);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.arch-model-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
}

.arch-block-stack {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 14px;
}

.arch-block-pill {
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 11px;
  font-family: var(--font-mono);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
}

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

/* ==============================================================================
   10. GOOGLE AUTHENTICATION GATE & USER PROFILE
   ============================================================================== */

.auth-overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 9, 13, 0.94);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  padding: 20px;
  animation: fadeIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.auth-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(56, 189, 248, 0.1);
  border-radius: 20px;
  width: 100%;
  max-width: 440px;
  padding: 36px 32px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  position: relative;
}

.auth-brand {
  margin-bottom: 20px;
}

.auth-logo {
  width: 52px;
  height: 52px;
  border-radius: 14px;
  background: linear-gradient(135deg, rgba(56, 189, 248, 0.2), rgba(52, 211, 153, 0.15));
  border: 1px solid var(--accent);
  color: var(--accent);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 12px;
}

.auth-brand h2 {
  font-family: var(--font-sans);
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.5px;
  margin: 0 0 4px 0;
  color: var(--text-main);
}

.auth-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.4;
  margin: 0;
}

.auth-restriction-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(56, 189, 248, 0.08);
  border: 1px solid rgba(56, 189, 248, 0.25);
  color: var(--accent);
  font-size: 12px;
  padding: 8px 14px;
  border-radius: 30px;
  margin-bottom: 24px;
  font-family: var(--font-sans);
}

.auth-error-banner {
  background: rgba(244, 63, 94, 0.12);
  border: 1px solid var(--accent-rose);
  color: var(--accent-rose);
  font-size: 12px;
  font-weight: 500;
  padding: 10px 14px;
  border-radius: 10px;
  margin-bottom: 18px;
  width: 100%;
  line-height: 1.4;
  text-align: left;
}

.google-btn-wrapper {
  margin-bottom: 20px;
  width: 100%;
  display: flex;
  justify-content: center;
  min-height: 44px;
}

.auth-divider {
  width: 100%;
  display: flex;
  align-items: center;
  text-align: center;
  margin: 12px 0 18px 0;
}

.auth-divider::before,
.auth-divider::after {
  content: '';
  flex: 1;
  border-bottom: 1px solid var(--border);
}

.auth-divider span {
  padding: 0 10px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: var(--text-faint);
}

.passkey-box {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.passkey-input-row {
  display: flex;
  gap: 8px;
  width: 100%;
}

.passkey-input-row input {
  flex: 1;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  color: var(--text-main);
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13px;
  font-family: var(--font-sans);
  outline: none;
  transition: border-color 0.2s ease;
}

.passkey-input-row input:focus {
  border-color: var(--accent);
}

.passkey-btn {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  color: var(--text-main);
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.passkey-btn:hover {
  background: var(--bg-hover);
  border-color: var(--accent);
  color: var(--accent);
}

.passkey-hint {
  font-size: 11px;
  color: var(--text-faint);
  line-height: 1.3;
  text-align: left;
}

.passkey-hint code {
  color: var(--accent);
  background: var(--bg-surface);
  padding: 2px 4px;
  border-radius: 4px;
}

.auth-footer-note {
  margin-top: 24px;
  font-size: 11px;
  color: var(--text-faint);
  display: flex;
  align-items: center;
  gap: 6px;
}

/* User Profile Badge in Top-Right */
.user-slot {
  display: flex;
  align-items: center;
  gap: 8px;
}

.user-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  padding: 4px 10px 4px 4px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-main);
}

.user-avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
}

.user-logout-btn {
  background: transparent;
  border: none;
  color: var(--text-faint);
  cursor: pointer;
  padding: 2px;
  display: flex;
  align-items: center;
  transition: color 0.2s ease;
}

.user-logout-btn:hover {
  color: var(--accent-rose);
}

/* PWA Install Button */
.pwa-btn {
  background: rgba(52, 211, 153, 0.15) !important;
  color: var(--accent-green) !important;
  border: 1px solid rgba(52, 211, 153, 0.3) !important;
}

.pwa-btn:hover {
  background: rgba(52, 211, 153, 0.25) !important;
}

/* ==============================================================================
   11. MOBILE RESPONSIVE ENGINE & TOUCH OPTIMIZATIONS
   ============================================================================== */

.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 80;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

body.mobile-sidebar-open .sidebar-backdrop {
  opacity: 1;
  pointer-events: auto;
}

/* Media Query: Tablets & Mobile (<= 860px) */
@media (max-width: 860px) {
  :root {
    --sidebar-width: 290px;
    --font-base-size: 16px;
  }

  #sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 90;
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.5);
  }

  body.mobile-sidebar-open #sidebar {
    transform: translateX(0);
  }

  #mobile-menu-btn {
    display: inline-flex !important;
  }

  #main-content {
    margin-left: 0 !important;
    width: 100% !important;
  }

  .breadcrumb {
    max-width: 140px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 12px;
  }

  .font-toggle-group,
  .size-controls {
    display: none !important;
  }

  #article-wrapper {
    padding: 16px 14px 60px 14px;
  }

  .modal-content {
    width: 95vw !important;
    max-width: 95vw !important;
    max-height: 90vh !important;
    padding: 18px 14px !important;
    margin: 10px;
  }

  .calc-grid,
  .roofline-grid,
  .mla-comparison-grid {
    grid-template-columns: 1fr !important;
  }

  .pagination-footer {
    flex-direction: column;
    gap: 10px;
  }

  .page-nav-btn,
  .mark-complete-btn {
    width: 100%;
    justify-content: center;
  }
}

/* Media Query: Compact Mobile (<= 480px) */
@media (max-width: 480px) {
  #top-bar {
    padding: 0 10px;
  }

  .top-right {
    gap: 6px;
  }

  .pill-btn span {
    display: none;
  }

  .auth-card {
    padding: 24px 18px;
  }
}

/* ==============================================================================
   QUICK UNLOCK & GOOGLE SWITCH STYLES
   ============================================================================== */
.google-switch-row {
  margin-top: 8px;
  font-size: 12px;
  color: var(--text-muted);
}

.google-switch-row a {
  color: var(--accent);
  text-decoration: underline;
  cursor: pointer;
}

.quick-passkey-pill {
  width: 100%;
  padding: 10px 14px;
  margin-bottom: 12px;
  background: rgba(56, 189, 248, 0.08);
  border: 1px solid rgba(56, 189, 248, 0.3);
  border-radius: 8px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.quick-passkey-pill:hover {
  background: rgba(56, 189, 248, 0.16);
  border-color: var(--accent);
  transform: translateY(-1px);
}

.quick-passkey-pill code {
  background: rgba(0, 0, 0, 0.3);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 12px;
}

/* ==============================================================================
   ANTIGRAVITY LIVE COPILOT & AGENT DRAWER
   ============================================================================== */
.antigravity-btn {
  background: linear-gradient(135deg, rgba(56, 189, 248, 0.12), rgba(168, 85, 247, 0.12));
  border: 1px solid rgba(56, 189, 248, 0.4);
  color: var(--accent);
}

.antigravity-btn:hover {
  border-color: #a855f7;
  box-shadow: 0 0 12px rgba(168, 85, 247, 0.25);
}

.bridge-status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  display: inline-block;
  background: #94a3b8;
  margin-left: 2px;
}

.bridge-status-dot.online {
  background: #10b981;
  box-shadow: 0 0 6px #10b981;
}

.bridge-status-dot.offline {
  background: #ef4444;
}

.antigravity-drawer {
  width: 480px;
  max-width: 90vw;
}

.drawer-title-group {
  display: flex;
  align-items: center;
  gap: 10px;
}

.bridge-badge {
  font-size: 10px;
  padding: 3px 8px;
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-weight: 600;
  background: rgba(148, 163, 184, 0.15);
  color: var(--text-muted);
}

.bridge-badge.online {
  background: rgba(16, 185, 129, 0.15);
  color: #10b981;
}

.bridge-badge.offline {
  background: rgba(239, 68, 68, 0.15);
  color: #ef4444;
}

.status-indicator-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.drawer-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  background: var(--bg-card);
  padding: 0 16px;
}

.drawer-tab {
  flex: 1;
  padding: 10px 8px;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  transition: all 0.15s ease;
}

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

.drawer-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.tab-pane {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.context-banner {
  padding: 8px 12px;
  background: var(--bg-surface);
  border-radius: 6px;
  font-size: 11px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 12px;
}

.agent-chat-stream {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 4px 0 16px 0;
  max-height: 480px;
}

.agent-msg {
  display: flex;
  gap: 10px;
  font-size: 13px;
  line-height: 1.6;
}

.agent-msg.bot .agent-avatar {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  background: linear-gradient(135deg, #38bdf8, #a855f7);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  flex-shrink: 0;
}

.agent-msg.user {
  flex-direction: row-reverse;
}

.agent-msg.user .agent-msg-body {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 12px 12px 2px 12px;
  padding: 10px 14px;
  max-width: 85%;
}

.agent-msg.bot .agent-msg-body {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 2px 12px 12px 12px;
  padding: 12px 16px;
  max-width: 88%;
}

.agent-msg-body p {
  margin: 0 0 8px 0;
}

.agent-msg-body p:last-child {
  margin-bottom: 0;
}

.quick-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 10px 0;
}

.quick-chip {
  padding: 4px 10px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  font-size: 11px;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s ease;
}

.quick-chip:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.agent-input-container {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px;
}

.agent-input-container textarea {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-main);
  font-size: 13px;
  font-family: inherit;
  resize: none;
  outline: none;
}

.agent-send-button {
  width: 32px;
  height: 32px;
  border-radius: 6px;
  background: var(--accent);
  color: #0b0f19;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: opacity 0.15s ease;
}

.agent-send-button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Edit Mode Styles */
.edit-warning-box {
  display: flex;
  gap: 12px;
  padding: 12px;
  background: rgba(168, 85, 247, 0.08);
  border: 1px solid rgba(168, 85, 247, 0.25);
  border-radius: 8px;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 14px;
}

.edit-warning-box strong {
  color: #a855f7;
  display: block;
  margin-bottom: 2px;
}

.edit-warning-box p {
  margin: 0;
  line-height: 1.4;
}

.edit-target-card {
  padding: 10px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 14px;
  font-size: 12px;
}

.edit-target-card label {
  color: var(--text-muted);
  font-size: 11px;
}

.target-title {
  font-weight: 600;
  color: var(--text-main);
  margin-top: 2px;
}

.selection-preview {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px dashed var(--border);
}

.selection-preview blockquote {
  margin: 4px 0 0 0;
  padding: 6px 10px;
  background: var(--bg-surface);
  border-left: 3px solid var(--accent);
  font-style: italic;
  font-size: 11px;
  color: var(--text-muted);
  max-height: 80px;
  overflow-y: auto;
}

.edit-input-group {
  margin-bottom: 14px;
}

.edit-input-group label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-main);
  display: block;
  margin-bottom: 6px;
}

.edit-input-group textarea {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-main);
  font-family: inherit;
  font-size: 13px;
  line-height: 1.5;
  outline: none;
  box-sizing: border-box;
}

.edit-input-group textarea:focus {
  border-color: #a855f7;
}

.apply-edit-button {
  width: 100%;
  padding: 12px;
  background: linear-gradient(135deg, #8b5cf6, #ec4899);
  border: none;
  border-radius: 8px;
  color: white;
  font-size: 13px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  transition: opacity 0.2s ease, transform 0.15s ease;
}

.apply-edit-button:hover {
  opacity: 0.92;
  transform: translateY(-1px);
}

.apply-edit-button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.edit-feedback {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 6px;
  font-size: 12px;
  line-height: 1.5;
}

.edit-feedback.success {
  background: rgba(16, 185, 129, 0.12);
  border: 1px solid rgba(16, 185, 129, 0.3);
  color: #10b981;
}

.edit-feedback.error {
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: #ef4444;
}

/* Floating Selection Action Bubble */
.selection-bubble {
  position: absolute;
  z-index: 1000;
  display: flex;
  gap: 4px;
  background: #111827;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 8px;
  padding: 4px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

.bubble-btn {
  padding: 6px 10px;
  background: transparent;
  border: none;
  border-radius: 4px;
  color: #e2e8f0;
  font-size: 11px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  transition: background 0.15s ease;
}

.bubble-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--accent);
}

