:root {
  color-scheme: light dark;
  /* Modern color palette */
  --primary-color: #6366f1;
  --primary-hover: #5b5ff7;
  --secondary-color: #64748b;
  --success-color: #10b981;
  --success-hover: #059669;
  --danger-color: #ef4444;
  --danger-hover: #dc2626;
  --warning-color: #f59e0b;
  --warning-hover: #d97706;
  --info-color: #06b6d4;
  --info-hover: #0891b2;
  --light-blue-color: #87ceeb;
  --light-blue-hover: #5fc3e8;
  --background-color: #f8fafc;
  --surface-color: #ffffff;
  --border-color: #e2e8f0;
  --text-primary: #1e293b;
  --text-secondary: #64748b;
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  --border-radius: 0.5rem;
  --border-radius-sm: 0.375rem;
  --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

@media print {
  .main-container { height: auto !important; }
  .top-controls, .left-panel, .resizer { display: none !important; }
  .panels-container { flex-direction: column !important; }
  .right-panel { flex: none !important; margin: 0 !important; }
  #output { border: none !important; padding: 20px !important; }
  .mermaid-controls { display: none !important; }
  .fullscreen-viewer { display: none !important; }
}

body {
  background: linear-gradient(135deg, var(--background-color) 0%, #f1f5f9 100%);
  height: 100vh;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', sans-serif;
}

.main-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  padding: 1.5rem;
  gap: 1rem;
}

.panels-container {
  display: flex;
  flex-direction: row;
  flex: 1 1 auto;
  min-height: 0;
  gap: 1rem;
  /* Make opaque to hide rendering layer underneath */
  background: linear-gradient(135deg, var(--background-color) 0%, #f1f5f9 100%);
  position: relative;
  z-index: 0;
}

.top-controls {
  background: var(--surface-color);
  border-radius: var(--border-radius);
  padding: 1.5rem;
  box-shadow: var(--shadow-md);
  flex-shrink: 0;
  border: 1px solid var(--border-color);
  backdrop-filter: blur(10px);
  background: rgba(255, 255, 255, 0.95);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

.logo-container {
  display: flex;
  align-items: flex-start;
  flex-shrink: 0;
  gap: 0.75rem;
  cursor: pointer;
  transition: var(--transition);
}

.logo-container a {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  text-decoration: none;
  color: inherit;
  height: 100%;
}

.logo-container a:focus {
  outline: none;
}

.logo-container a:focus-visible {
  outline: 2px solid var(--primary-color);
  outline-offset: 4px;
  border-radius: 4px;
}

.logo-container:hover .logo {
  transform: scale(1.05);
  filter: brightness(1.1);
}

.logo-container:hover .logo-title {
  color: var(--primary-hover);
  transform: translateY(-1px);
}

.logo {
  height: 40px;
  width: auto;
  object-fit: contain;
  transition: var(--transition);
  color: var(--primary-color);
}

.logo-title {
  font-size: 1.75rem;
  font-weight: 700;
  color: #334650 !important;
  margin: 0;
  letter-spacing: -0.02em;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', sans-serif;
  transition: var(--transition);
  text-decoration: none;
}

.left-panel, .right-panel {
  background: var(--surface-color);
  border-radius: var(--border-radius);
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--border-color);
  backdrop-filter: blur(10px);
  background: rgba(255, 255, 255, 0.95);
}

.left-panel {
  flex: 0 0 40%;
  min-width: 200px;
  transition: var(--transition);
}

.left-panel.hidden {
  flex: 0 0 0 !important;
  min-width: 0 !important;
  max-width: 0 !important;
  overflow: hidden;
  opacity: 0;
  transition: var(--transition);
}

.right-panel {
  flex: 1 1 auto;
  min-width: 200px;
}

.resizer {
  width: 1rem;
  background: var(--border-color);
  cursor: col-resize;
  position: relative;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
  border-radius: var(--border-radius-sm);
  margin: 0 0.5rem;
}

.resizer:hover {
  background: var(--secondary-color);
  transform: scaleX(1.2);
}

.resizer::after {
  content: '⋮';
  color: var(--text-secondary);
  font-size: 1rem;
  line-height: 1;
  writing-mode: vertical-rl;
  transition: var(--transition);
}

.resizer:hover::after {
  color: var(--surface-color);
}

.left-panel.hidden + .resizer {
  display: none;
}
.mermaid-context-menu {
  position: fixed;
  background: var(--surface-color);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  box-shadow: var(--shadow-lg);
  z-index: 1000;
  padding: 0.5rem 0;
  min-width: 150px;
  backdrop-filter: blur(10px);
  background: rgba(255, 255, 255, 0.95);
}

.mermaid-context-menu button {
  display: block;
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: none;
  background: none;
  text-align: left;
  cursor: pointer;
  font-size: 0.875rem;
  color: var(--text-primary);
  transition: var(--transition);
  font-weight: 500;
}

.mermaid-context-menu button:hover {
  background: var(--primary-color);
  color: white;
}

/* =============================================================================
   MERMAID DIAGRAM STYLING
   ============================================================================= */

.mermaid-container {
  margin: var(--space-lg) 0;
  padding: var(--space-md);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  background: var(--surface-color);
}

.mermaid-controls {
  gap: 0.375rem !important;
  font-style: normal !important; /* Override any inherited italic styling */
}

.mermaid-controls .btn {
  padding: 0.25rem 0.5rem;
  font-size: 0.75rem;
  border-radius: var(--border-radius-sm);
  box-shadow: var(--shadow-sm);
  font-style: normal !important; /* Ensure buttons are never italic */
  font-weight: 500 !important; /* Proper button font weight */
}

.mermaid-controls .btn i {
  font-style: normal !important; /* Ensure icons are never italic */
}

/* Enhanced Mermaid diagram styling */
.mermaid {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif !important;
  text-align: center;
  margin: var(--space-md) 0;
}

.mermaid .node rect,
.mermaid .node circle,
.mermaid .node ellipse,
.mermaid .node polygon {
  stroke-width: 2px !important;
}

.mermaid .edgePath path {
  stroke-width: 2px !important;
  opacity: 0.5 !important; /* Make arrows 50% lighter by reducing opacity */
}

.mermaid .arrowheadPath {
  opacity: 0.5 !important; /* Make arrowheads 50% lighter */
}

.mermaid .edgeLabel {
  background-color: transparent !important; /* Remove background from transition labels */
  color: var(--text-primary) !important;
  font-size: 14px !important;
  font-weight: 500 !important;
  padding: 2px 4px !important; /* Reduced padding since no background */
  border-radius: 4px !important;
  border: none !important; /* Remove border since no background */
}

.mermaid .labelBkg {
  background-color: transparent !important; /* Remove background from generated labelBkg div */
  background: transparent !important; /* Override any inline background styles */
}

/* Override dynamically generated MermaidJS inline styles */
[id^="mermaid-"] .edgeLabel {
  background-color: transparent !important; /* Override dynamic inline styles with ID selectors */
  background: transparent !important; /* Force transparent background on all dynamically generated diagrams */
}

[id^="mermaid-"] .labelBkg {
  background-color: transparent !important; /* Override dynamic labelBkg styles */
  background: transparent !important; /* Force transparent on dynamically generated labelBkg elements */
}

/* Flowchart specific styling */
.mermaid .node .label {
  color: var(--text-primary) !important;
  font-size: 14px !important;
  font-weight: 500 !important;
}

/* Override any super light backgrounds - keep only main violet */
.mermaid .node rect[fill*="#f"],
.mermaid .node rect[fill*="f8fafc"],
.mermaid .node rect[fill*="f1f5f9"] {
  fill: #6366f1 !important; /* Use main violet for all nodes */
}

/* Remove any super light backgrounds from containers */
.mermaid g[fill*="#f8fafc"],
.mermaid g[fill*="#f1f5f9"] {
  fill: transparent !important;
}

/* Sequence diagram styling */
.mermaid .actor {
  stroke: var(--border-color) !important;
  fill: var(--surface-color) !important;
}

.mermaid .actor-line {
  stroke: var(--border-color) !important;
}

.mermaid .messageLine0,
.mermaid .messageLine1 {
  stroke: var(--text-secondary) !important;
}

.mermaid .messageText {
  fill: var(--text-primary) !important;
  font-size: 14px !important;
}

.mermaid .note {
  fill: #fef3c7 !important;
  stroke: #f59e0b !important;
}

/* Gantt chart styling */
.mermaid .section {
  font-size: 14px !important;
  font-weight: 600 !important;
}

/* Class diagram styling */
.mermaid .classBox {
  fill: var(--surface-color) !important;
  stroke: var(--border-color) !important;
}

/* State diagram styling */
.mermaid .state-title {
  font-size: 14px !important;
  font-weight: 600 !important;
}

/* Entity relationship diagram styling */
.mermaid .er.relationshipLabel {
  fill: var(--text-primary) !important;
}

/* Pie chart styling */
.mermaid .pieChart .slice {
  stroke-width: 2px !important;
}

/* Git graph styling */
.mermaid .commit-id,
.mermaid .commit-msg,
.mermaid .branch-label {
  font-size: 12px !important;
  font-weight: 500 !important;
}

/* Fullscreen viewer styles */
.fullscreen-viewer {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(30, 41, 59, 0.95);
  z-index: 9999;
  overflow: hidden;
  user-select: none;
  backdrop-filter: blur(10px);
}

.fullscreen-viewer .viewer-controls {
  position: fixed;
  top: 1.5rem;
  right: 1.5rem;
  display: flex;
  gap: 0.75rem;
  z-index: 10000;
}

.fullscreen-viewer .viewer-btn {
  width: 3rem;
  height: 3rem;
  border: none;
  border-radius: var(--border-radius);
  color: white;
  font-size: 1.125rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-lg);
  transition: var(--transition);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.fullscreen-viewer .zoom-in-btn {
  background: var(--success-color);
}

.fullscreen-viewer .zoom-out-btn {
  background: var(--warning-color);
}

.fullscreen-viewer .zoom-fit-btn {
  background: var(--info-color);
}

.fullscreen-viewer .close-btn {
  background: var(--danger-color);
}

.fullscreen-viewer .viewer-btn:hover {
  transform: translateY(-2px) scale(1.05);
  box-shadow: 0 0.5rem 2rem rgba(0, 0, 0, 0.3);
}

.fullscreen-viewer .viewer-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  cursor: grab;
  overflow: hidden;
}

.fullscreen-viewer .viewer-canvas.dragging {
  cursor: grabbing;
}

.fullscreen-viewer .diagram-container {
  position: absolute;
  transition: transform 0.2s ease;
  transform-origin: 0 0;
  background: white;
  border-radius: 0.5rem;
  padding: 0;
  box-shadow: 0 0.5rem 2rem rgba(0, 0, 0, 0.3);
}

.fullscreen-viewer .diagram-container .mermaid {
  padding: 2rem;
}

.fullscreen-viewer .zoom-info {
  position: fixed;
  top: 5.5rem;
  right: 1.5rem;
  background: rgba(30, 41, 59, 0.9);
  color: white;
  padding: 0.5rem 1rem;
  border-radius: var(--border-radius);
  font-size: 0.875rem;
  font-weight: 500;
  z-index: 10000;
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: var(--shadow-lg);
}

/* Responsive Design */
@media (max-width: 1399px) {
  .logo-tagline {
    display: none;
  }
}

@media (max-width: 768px) {
  .main-container {
    padding: 1rem;
    gap: 0.75rem;
  }
  
  .top-controls {
    padding: 1rem;
    flex-direction: column;
    align-items: flex-start;
    gap: 1rem;
  }
  
  .logo-container {
    order: -1;
  }
  
  .logo {
    height: 36px;
  }
  
  .logo-title {
    font-size: 1.5rem;
  }
  
  .controls-group {
    flex-direction: column;
    align-items: flex-end;
    gap: 0.75rem;
    width: 100%;
  }
  
  .controls-section {
    flex-wrap: wrap;
    justify-content: flex-end;
  }
  
  .controls-divider {
    height: 1px;
    width: 100%;
    margin: 0;
  }
  
  .panels-container {
    flex-direction: column;
    gap: 0.75rem;
  }
  
  .left-panel {
    flex: 0 0 40vh;
    min-width: auto;
  }
  
  .resizer {
    display: none;
  }
  
  .fullscreen-viewer .viewer-controls {
    top: 1rem;
    right: 1rem;
    gap: 0.5rem;
  }
  
  .fullscreen-viewer .viewer-btn {
    width: 2.5rem;
    height: 2.5rem;
    font-size: 1rem;
  }
  
  .fullscreen-viewer .zoom-info {
    top: 4.5rem;
    right: 1rem;
    padding: 0.5rem 0.75rem;
    font-size: 0.8125rem;
  }
}

@media (max-width: 480px) {
  .main-container {
    padding: 0.75rem;
  }
  
  .top-controls {
    padding: 0.75rem;
  }
  
  .logo {
    height: 32px;
  }
  
  .logo-title {
    font-size: 1.25rem;
  }
  
  .btn-sm {
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
  }
  
  .controls-section span {
    display: none;
  }
}
/* Modern Button Styles */
.btn {
  border: none;
  border-radius: var(--border-radius-sm);
  font-weight: 500;
  font-size: 0.875rem;
  padding: 0.5rem 1rem;
  transition: var(--transition);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  text-decoration: none;
  outline: none;
  position: relative;
  overflow: hidden;
}

.btn:focus {
  outline: 2px solid var(--primary-color);
  outline-offset: 2px;
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none !important;
}

.btn-primary {
  background: var(--primary-color);
  color: white;
  box-shadow: var(--shadow-sm);
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.btn-success {
  background: var(--success-color);
  color: white;
  box-shadow: var(--shadow-sm);
}

.btn-success:hover:not(:disabled) {
  background: var(--success-hover);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.btn-danger {
  background: var(--danger-color);
  color: white;
  box-shadow: var(--shadow-sm);
}

.btn-danger:hover:not(:disabled) {
  background: var(--danger-hover);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.btn-warning {
  background: var(--warning-color);
  color: white;
  box-shadow: var(--shadow-sm);
}

.btn-warning:hover:not(:disabled) {
  background: var(--warning-hover);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.btn-info {
  background: var(--info-color);
  color: white;
  box-shadow: var(--shadow-sm);
}

.btn-info:hover:not(:disabled) {
  background: var(--info-hover);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.btn-secondary, .btn-outline-secondary {
  background: var(--surface-color);
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
}

.btn-secondary:hover:not(:disabled), .btn-outline-secondary:hover:not(:disabled) {
  background: var(--secondary-color);
  color: white;
  border-color: var(--secondary-color);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.btn-outline-dark {
  background: var(--surface-color);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
}

.btn-outline-dark:hover:not(:disabled) {
  background: var(--text-primary);
  color: var(--surface-color);
  border-color: var(--text-primary);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.btn-sm {
  padding: 0.375rem 0.75rem;
  font-size: 0.8125rem;
}

.btn-group {
  display: inline-flex;
  border-radius: var(--border-radius-sm);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.btn-group .btn {
  border-radius: 0;
  border-right: 1px solid rgba(255, 255, 255, 0.2);
}

.btn-group .btn:first-child {
  border-radius: var(--border-radius-sm) 0 0 var(--border-radius-sm);
}

.btn-group .btn:last-child {
  border-radius: 0 var(--border-radius-sm) var(--border-radius-sm) 0;
  border-right: none;
}

/* Custom Button Styles for Top Panel */
#render-btn {
  background: var(--secondary-color);
  color: white;
  box-shadow: var(--shadow-sm);
}

#render-btn:hover:not(:disabled) {
  background: #52525b;
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

#export-docx-btn {
  background: #1F4E79;
  color: white;
  box-shadow: var(--shadow-sm);
}

#export-docx-btn:hover:not(:disabled) {
  background: #2B5797;
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

#share-btn {
  background: var(--success-color);
  color: white;
  box-shadow: var(--shadow-sm);
}

#share-btn:hover:not(:disabled) {
  background: var(--success-hover);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

#copy-content-btn {
  background: var(--light-blue-color);
  color: white;
  box-shadow: var(--shadow-sm);
}

#copy-content-btn:hover:not(:disabled) {
  background: var(--light-blue-hover);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

/* Form Controls */
.form-check-input {
  accent-color: var(--secondary-color);
}

.form-check-label {
  color: var(--text-primary);
  font-weight: 500;
}

#md-input {
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  background: var(--surface-color);
  color: var(--text-primary);
  transition: var(--transition);
}

#md-input:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

/* Improved Visual Hierarchy */
.controls-group {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.controls-section {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem;
  border-radius: var(--border-radius-sm);
  background: rgba(99, 102, 241, 0.05);
  border: 1px solid rgba(99, 102, 241, 0.1);
}

.controls-divider {
  width: 1px;
  height: 2rem;
  background: var(--border-color);
  margin: 0 0.5rem;
}

/* =============================================================================
   COMPREHENSIVE TYPOGRAPHY SYSTEM FOR MARKDOWN CONTENT
   ============================================================================= */

/* Typography Variables */
:root {
  /* Typography Scale (Major Third - 1.25 ratio) */
  --font-size-xs: 0.75rem;      /* 12px */
  --font-size-sm: 0.875rem;     /* 14px */
  --font-size-base: 1rem;       /* 16px */
  --font-size-lg: 1.125rem;     /* 18px */
  --font-size-xl: 1.25rem;      /* 20px */
  --font-size-2xl: 1.5rem;      /* 24px */
  --font-size-3xl: 1.875rem;    /* 30px */
  --font-size-4xl: 2.25rem;     /* 36px */
  --font-size-5xl: 3rem;        /* 48px */
  
  /* Line Heights */
  --line-height-tight: 1.25;
  --line-height-normal: 1.5;
  --line-height-relaxed: 1.625;
  --line-height-loose: 2;
  
  /* Spacing Scale */
  --space-xs: 0.25rem;
  --space-sm: 0.5rem;
  --space-md: 1rem;
  --space-lg: 1.5rem;
  --space-xl: 2rem;
  --space-2xl: 2.5rem;
  --space-3xl: 3rem;
  
  /* Typography Colors */
  --text-primary: #1a1a1a;
  --text-secondary: #4a4a4a;
  --text-muted: #6b7280;
  --text-link: #2563eb;
  --text-link-hover: #1d4ed8;
  
  /* Code Colors */
  --code-bg: #f8fafc;
  --code-text: #374151;
  --code-border: #e2e8f0;
  --pre-bg: #1e293b;
  --pre-text: #e2e8f0;
}

/* =============================================================================
   OUTPUT CONTAINER BASE STYLES
   ============================================================================= */

#output {
  /* Base Typography */
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  font-size: var(--font-size-base);
  line-height: var(--line-height-normal);
  color: var(--text-primary);
  
  /* Content Spacing */
  padding: var(--space-xl);
  
  /* Text Rendering */
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  
  /* Improve text spacing */
  word-spacing: 0.05em;
  letter-spacing: 0.01em;
}

/* =============================================================================
   HEADINGS - HIERARCHICAL TYPOGRAPHY
   ============================================================================= */

#output h1,
#output h2,
#output h3,
#output h4,
#output h5,
#output h6 {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  font-weight: 700;
  line-height: var(--line-height-tight);
  color: var(--text-primary);
  margin-top: var(--space-2xl);
  margin-bottom: var(--space-md);
  letter-spacing: -0.025em;
  scroll-margin-top: 4rem; /* For anchor link navigation */
}

#output h1 {
  font-size: var(--font-size-4xl);
  margin-top: 0;
  margin-bottom: var(--space-lg);
  padding-bottom: var(--space-sm);
  border-bottom: 2px solid var(--border-color);
}

#output h2 {
  font-size: var(--font-size-3xl);
  margin-top: var(--space-3xl);
  padding-bottom: var(--space-xs);
  border-bottom: 1px solid var(--border-color);
}

#output h3 {
  font-size: var(--font-size-2xl);
  margin-top: var(--space-2xl);
}

#output h4 {
  font-size: var(--font-size-xl);
  margin-top: var(--space-lg);
}

#output h5 {
  font-size: var(--font-size-lg);
  margin-top: var(--space-lg);
  font-weight: 600;
}

#output h6 {
  font-size: var(--font-size-base);
  margin-top: var(--space-lg);
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* =============================================================================
   PARAGRAPHS & BODY TEXT
   ============================================================================= */

#output p {
  margin-top: 0;
  margin-bottom: var(--space-lg);
  color: var(--text-primary);
  line-height: var(--line-height-normal);
}

/* First paragraph after headings */
#output h1 + p,
#output h2 + p,
#output h3 + p,
#output h4 + p,
#output h5 + p,
#output h6 + p {
  margin-top: var(--space-sm);
}

/* Lead paragraph styling */
#output > p:first-of-type {
  font-size: var(--font-size-lg);
  line-height: var(--line-height-relaxed);
  color: var(--text-secondary);
  margin-bottom: var(--space-xl);
}

/* =============================================================================
   LINKS & EMPHASIS
   ============================================================================= */

#output a {
  color: var(--text-link);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
  transition: all 0.2s ease;
}

#output a:hover {
  color: var(--text-link-hover);
  text-decoration-thickness: 2px;
}

#output a:focus {
  outline: 2px solid var(--text-link);
  outline-offset: 2px;
  border-radius: 2px;
}

#output strong,
#output b {
  font-weight: 700;
  color: var(--text-primary);
}

#output em,
#output i {
  font-style: italic;
}

#output mark {
  background-color: #fef3c7;
  color: var(--text-primary);
  padding: 0.125em 0.25em;
  border-radius: 0.25em;
}

/* =============================================================================
   LISTS - STRUCTURED CONTENT
   ============================================================================= */

#output ul,
#output ol {
  margin-top: 0;
  margin-bottom: var(--space-lg);
  padding-left: var(--space-xl);
}

#output li {
  margin-bottom: var(--space-sm);
  line-height: var(--line-height-normal);
}

#output li > p {
  margin-bottom: var(--space-sm);
}

#output li:last-child {
  margin-bottom: 0;
}

/* Nested lists */
#output ul ul,
#output ul ol,
#output ol ul,
#output ol ol {
  margin-top: var(--space-sm);
  margin-bottom: var(--space-sm);
}

/* Custom list markers */
#output ul > li {
  list-style-type: disc;
}

#output ul ul > li {
  list-style-type: circle;
}

#output ul ul ul > li {
  list-style-type: square;
}

#output ol {
  list-style-type: decimal;
}

#output ol ol {
  list-style-type: lower-alpha;
}

#output ol ol ol {
  list-style-type: lower-roman;
}

/* Task Lists */
#output input[type="checkbox"] {
  margin-right: var(--space-sm);
  transform: scale(1.1);
}

/* =============================================================================
   CODE - TECHNICAL CONTENT
   ============================================================================= */

#output code {
  font-family: 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, 'Courier New', monospace;
  font-size: 0.9em;
  background: var(--code-bg);
  color: var(--code-text);
  padding: 0.2em 0.4em;
  border-radius: 0.25em;
  border: 1px solid var(--code-border);
  font-weight: 500;
}

#output pre {
  background: var(--pre-bg);
  color: var(--pre-text);
  padding: var(--space-lg);
  border-radius: var(--border-radius);
  overflow-x: auto;
  margin: var(--space-lg) 0;
  border: 1px solid var(--border-color);
  font-size: var(--font-size-sm);
  line-height: var(--line-height-relaxed);
  
  /* Scrollbar styling */
  scrollbar-width: thin;
  scrollbar-color: #64748b transparent;
}

#output pre::-webkit-scrollbar {
  height: 8px;
}

#output pre::-webkit-scrollbar-track {
  background: transparent;
}

#output pre::-webkit-scrollbar-thumb {
  background: #64748b;
  border-radius: 4px;
}

#output pre code {
  background: none;
  color: inherit;
  padding: 0;
  border: none;
  font-size: inherit;
}

/* =============================================================================
   BLOCKQUOTES & CITATIONS
   ============================================================================= */

#output blockquote {
  margin: var(--space-xl) 0;
  padding: var(--space-md) var(--space-lg);
  border-left: 4px solid var(--primary-color);
  background: #f8fafc;
  border-radius: 0 var(--border-radius-sm) var(--border-radius-sm) 0;
  font-style: italic;
  color: var(--text-secondary);
  position: relative;
}

#output blockquote::before {
  content: '"';
  font-size: var(--font-size-4xl);
  color: var(--primary-color);
  position: absolute;
  left: var(--space-md);
  top: 0;
  line-height: 1;
  opacity: 0.5;
}

#output blockquote p {
  margin: 0;
  padding-left: var(--space-lg);
}

#output blockquote p:first-child {
  margin-top: 0;
}

#output blockquote p:last-child {
  margin-bottom: 0;
}

#output blockquote cite {
  display: block;
  text-align: right;
  margin-top: var(--space-sm);
  font-style: normal;
  font-size: var(--font-size-sm);
  color: var(--text-muted);
}

#output blockquote cite::before {
  content: '— ';
}

/* =============================================================================
   TABLES - STRUCTURED DATA
   ============================================================================= */

#output table {
  width: 100%;
  border-collapse: collapse;
  margin: var(--space-xl) 0;
  font-size: var(--font-size-sm);
  overflow-x: auto;
  display: block;
  white-space: nowrap;
}

#output thead {
  background: var(--code-bg);
}

#output th {
  font-weight: 600;
  text-align: left;
  padding: var(--space-md);
  border-bottom: 2px solid var(--border-color);
  color: var(--text-primary);
}

#output td {
  padding: var(--space-md);
  border-bottom: 1px solid var(--border-color);
  vertical-align: top;
}

#output tbody tr:hover {
  background: #f8fafc;
}

/* Table wrapper for horizontal scrolling */
#output .table-wrapper {
  overflow-x: auto;
  margin: var(--space-xl) 0;
}

#output .table-wrapper table {
  margin: 0;
  min-width: 100%;
  white-space: nowrap;
}

/* =============================================================================
   HORIZONTAL RULES & DIVIDERS
   ============================================================================= */

#output hr {
  border: none;
  height: 2px;
  background: linear-gradient(to right, transparent, var(--border-color), transparent);
  margin: var(--space-3xl) 0;
}

/* =============================================================================
   IMAGES & MEDIA
   ============================================================================= */

#output img {
  max-width: 100%;
  height: auto;
  border-radius: var(--border-radius-sm);
  box-shadow: var(--shadow-sm);
  margin: var(--space-lg) 0;
}

#output figure {
  margin: var(--space-xl) 0;
  text-align: center;
}

#output figcaption {
  font-size: var(--font-size-sm);
  color: var(--text-muted);
  margin-top: var(--space-sm);
  font-style: italic;
}

/* =============================================================================
   DEFINITION LISTS
   ============================================================================= */

#output dl {
  margin: var(--space-lg) 0;
}

#output dt {
  font-weight: 600;
  margin-top: var(--space-md);
  color: var(--text-primary);
}

#output dd {
  margin-left: var(--space-xl);
  margin-bottom: var(--space-md);
  color: var(--text-secondary);
}

/* =============================================================================
   KEYBOARD & TECHNICAL ELEMENTS
   ============================================================================= */

#output kbd {
  background: #f1f5f9;
  border: 1px solid #cbd5e1;
  border-radius: 0.25rem;
  box-shadow: 0 1px 0 #cbd5e1;
  font-family: inherit;
  font-size: 0.85em;
  padding: 0.125em 0.375em;
  color: var(--text-primary);
}

#output samp {
  font-family: 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, 'Courier New', monospace;
  background: var(--code-bg);
  padding: 0.2em 0.4em;
  border-radius: 0.25em;
  font-size: 0.9em;
}

#output var {
  font-style: italic;
  color: var(--text-link);
  font-weight: 500;
}

/* =============================================================================
   RESPONSIVE TYPOGRAPHY
   ============================================================================= */

@media (max-width: 768px) {
  #output {
    max-width: none;
    padding: var(--space-lg);
  }
  
  #output h1 {
    font-size: var(--font-size-3xl);
  }
  
  #output h2 {
    font-size: var(--font-size-2xl);
  }
  
  #output h3 {
    font-size: var(--font-size-xl);
  }
  
  #output table {
    font-size: var(--font-size-xs);
  }
  
  #output pre {
    padding: var(--space-md);
    font-size: var(--font-size-xs);
  }
}

@media (max-width: 480px) {
  #output {
    padding: var(--space-md);
  }
  
  #output h1 {
    font-size: var(--font-size-2xl);
  }
  
  #output h2 {
    font-size: var(--font-size-xl);
  }
  
  #output ul,
  #output ol {
    padding-left: var(--space-lg);
  }
}

/* =============================================================================
   DARK MODE SUPPORT
   ============================================================================= */

@media (prefers-color-scheme: dark) {
  :root {
    --text-primary: #f8fafc;
    --text-secondary: #cbd5e1;
    --text-muted: #94a3b8;
    --text-link: #60a5fa;
    --text-link-hover: #93c5fd;
    --code-bg: #1e293b;
    --code-text: #e2e8f0;
    --code-border: #374151;
    --pre-bg: #0f172a;
    --pre-text: #f1f5f9;
  }
  
  #output blockquote {
    background: #1e293b;
  }
  
  #output mark {
    background-color: #fbbf24;
    color: #1f2937;
  }
  
  #output thead {
    background: #1e293b;
  }
  
  #output tbody tr:hover {
    background: #1e293b;
  }
  
  #output kbd {
    background: #374151;
    border-color: #4b5563;
    box-shadow: 0 1px 0 #4b5563;
  }
}

/* =============================================================================
   PRINT STYLES
   ============================================================================= */

@media print {
  #output {
    max-width: none;
    padding: 0;
    color: black;
  }
  
  #output a {
    color: black;
    text-decoration: underline;
  }
  
  #output pre {
    background: #f8f9fa;
    color: black;
    border: 1px solid #dee2e6;
  }
  
  #output blockquote {
    background: #f8f9fa;
    border-left-color: #6c757d;
  }
}
