/* =================================================================
   BASE.CSS - Foundation Styles for MarkTide Viewer
   
   This file contains all the base styles that are theme-independent:
   - CSS Reset and universal styles
   - Layout structure and positioning
   - Typography foundations
   - Component structure without colors
   - Responsive design rules
   - Animation keyframes
   ================================================================= */

/* =================================================================
   1. CSS RESET & UNIVERSAL STYLES
   ================================================================= */

/* Utility Classes */
.visually-hidden {
  display: none !important;
}

  * {
   box-sizing: border-box;
   margin: 0;
   padding: 0;
  }
  
  html, body {
    overflow-x: hidden;
    width: 100%;
    max-width: 100vw;
  }
  
  /* =================================================================
     2. BASE LAYOUT & BODY
     ================================================================= */
  
  body {
    background-color: var(--bg-color);
    color: var(--text-color);
    transition: background-color 0.3s ease, color 0.3s ease;
    min-height: 100vh;
    font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
  }
  
  /* =================================================================
     3. LOADING SCREEN COMPONENTS
     ================================================================= */
  
  .loading-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    transition: opacity 0.5s ease, visibility 0.5s ease;
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
  }
  
  .loading-screen.fade-out {
    opacity: 0;
    visibility: hidden;
  }
  
  .loading-content {
    text-align: center;
    color: white;
    background: rgba(255, 255, 255, 0.05);
    padding: 3rem;
    border-radius: 20px;
    -webkit-backdrop-filter: blur(20px);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
    animation: contentFloat 3s ease-in-out infinite;
  }
  
  .loading-logo {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 2rem;
  }
  
  .logo-animation {
    font-size: 4rem;
    margin-bottom: 1rem;
    animation: logoFloat 2s ease-in-out infinite, logoGlow 2s ease-in-out infinite;
  }
  
  .loading-text {
    display: flex;
    flex-direction: column;
    align-items: center;
  }
  
  .loading-title {
    font-size: 2.5rem;
    font-weight: 700;
    margin: 0;
    letter-spacing: 2px;
    animation: titleSlide 1s ease-out 0.5s both;
  }
  
  .loading-subtitle {
    font-size: 1.2rem;
    font-weight: 300;
    opacity: 0.9;
    animation: subtitleSlide 1s ease-out 0.8s both;
  }
  
  .loading-progress {
    width: 300px;
    height: 6px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 10px;
    overflow: hidden;
    margin: 0 auto;
    -webkit-backdrop-filter: blur(5px);
    backdrop-filter: blur(5px);
    border: 1px solid rgba(255, 255, 255, 0.1);
  }
  
  .progress-bar {
    width: 0%;
    height: 100%;
    background: linear-gradient(90deg, var(--text-color), #f0f8ff, var(--text-color));
    border-radius: 10px;
    animation: progressFill 2s ease-in-out forwards;
    box-shadow: 0 0 10px rgba(255, 255, 255, 0.5);
    position: relative;
  }
  
  .progress-bar::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.3), transparent);
    animation: progressShine 1.5s ease-in-out infinite;
  }
  
  .loading-designer {
    margin-top: 1.5rem;
    font-size: 0.9rem;
    font-weight: 400;
    color: rgba(255, 255, 255, 0.8);
    letter-spacing: 1px;
    opacity: 0;
    transform: translateY(15px) scale(0.9);
    animation: designerFadeIn 1s ease-out 1.2s both, designerPulse 2s ease-in-out 2.5s infinite;
  }
  
  /* =================================================================
     4. APP STRUCTURE & MAIN CONTAINERS
     ================================================================= */
  
  .app-container {
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
    width: 100%;
    max-width: 100vw;
  }
  
  .content-container {
    display: flex;
    flex: 1;
    overflow: hidden; /* default: no page scroll */
    transition: all 0.3s ease;
    min-height: 0;
  }

  /* In editor-only, let the PAGE control scrolling (no container clamp) */
  body.editor-only-active .content-container {
    height: auto;
  }

  /* In preview-only, let document scroll from the top (no clamping) */
  body.preview-only-active .content-container {
    height: auto;
  }

  /* Expose header height as a CSS var; updated via JS compute path */
  .app-header { --header-height: 0px; }
  
  /* =================================================================
     5. HEADER COMPONENTS
     ================================================================= */
  
  .app-header {
    background: linear-gradient(135deg, var(--header-bg) 0%, var(--header-gradient) 100%);
    border-bottom: 1px solid var(--border-color);
    padding: 0;
    transition: all 0.3s ease;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 2px 20px rgba(0, 0, 0, 0.1);
  }
  
  .header-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 2rem;
    padding: 0.75rem 2rem;
    max-width: none;
  }
  
  /* --- Header Brand Section --- */
  .header-brand {
    display: flex;
    align-items: center;
    gap: 1.5rem;
  }
  
  .logo-wrapper {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    transition: all 0.3s ease;
  }
  
  .logo-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    background: rgba(79, 195, 247, 0.1);
    border: 1px solid rgba(79, 195, 247, 0.3);
    border-radius: 12px;
    color: var(--accent-color);
    font-size: 1.25rem;
    font-weight: 700;
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    box-shadow: 0 4px 12px rgba(79, 195, 247, 0.2);
    transition: all 0.3s ease;
  }
  
  .logo-icon:hover {
    background: rgba(79, 195, 247, 0.15);
    border-color: rgba(79, 195, 247, 0.5);
    box-shadow: 0 6px 20px rgba(79, 195, 247, 0.3);
    transform: translateY(-1px);
  }
  
  .brand-info {
    display: flex;
    flex-direction: column;
    line-height: 1;
  }
  
  .brand-title {
    font-size: 1.5rem;
    font-weight: 700;
    margin: 0;
    color: var(--text-color);
    letter-spacing: -0.02em;
    transition: all 0.3s ease;
  }
  
  .brand-title:hover {
    color: var(--accent-color);
    text-shadow: 0 0 10px rgba(79, 195, 247, 0.3);
  }
  
  .brand-subtitle {
    font-size: 0.875rem;
    color: var(--text-color);
    opacity: 0.7;
    font-weight: 500;
    margin-top: 2px;
    transition: all 0.3s ease;
  }
  
  .brand-subtitle:hover {
    opacity: 1;
    color: var(--accent-color);
  }
  
  .header-divider {
    width: 1px;
    height: 32px;
    background: var(--border-color);
    opacity: 0.5;
  }
  
  .github-badge {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: var(--button-bg);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 8px;
    color: var(--text-color);
    text-decoration: none;
    transition: all 0.2s ease;
    font-size: 0.875rem;
    font-weight: 500;
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
  }
  
  .github-badge:hover {
    background: var(--button-hover);
    color: var(--text-color);
    transform: translateY(-1px);
    border-color: var(--accent-color);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  }
  
  .github-text {
    display: none;
  }
  
  /* --- Header Statistics Section --- */
  .header-stats {
    display: flex;
    gap: 1rem;
    justify-content: center;
  }
  
  .stat-card {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    background: var(--stats-bg);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    transition: all 0.2s ease;
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
  }
  
  .stat-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
  }
  
  .stat-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    background: var(--accent-color);
    border-radius: 6px;
    color: white;
    font-size: 0.875rem;
  }
  
  .stat-content {
    display: flex;
    flex-direction: column;
    line-height: 1;
  }
  
  .stat-value {
    font-size: 1.125rem;
    font-weight: 700;
    color: var(--text-color);
  }
  
  .stat-label {
    font-size: 0.75rem;
    color: var(--text-color);
    opacity: 0.7;
    margin-top: 2px;
  }
  
  /* --- Header Actions Section --- */
  .header-actions {
    display: flex;
    align-items: center;
    gap: 1.5rem;
  }
  
  .action-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
  }
  
  .action-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.625rem 1rem;
    background: var(--button-bg);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 8px;
    color: var(--text-color);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
  }
  
  .action-btn:hover {
    background: var(--button-hover);
    transform: translateY(-1px);
    border-color: var(--accent-color);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  }
  
  .action-btn.sync-enabled {
    background: var(--button-hover);
    color: var(--text-color);
    border-color: var(--accent-color);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  }
  
  .action-btn.sync-enabled:hover {
    background: var(--button-hover);
    transform: translateY(-2px);
    border-color: var(--accent-color);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.15);
  }
  
  .action-btn.sync-disabled {
    border-color: rgba(255, 255, 255, 0.3);
    background: var(--button-bg);
  }
  
  .action-btn.sync-disabled:hover {
    background: var(--button-hover);
    transform: translateY(-1px);
    border-color: var(--accent-color);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  }
  
  .dropdown-arrow {
    font-size: 0.75rem;
    opacity: 0.7;
  }
  
  /* --- View Controls --- */
  .view-controls {
    display: flex;
    background: var(--button-bg);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 10px;
    overflow: hidden;
    transition: all 0.2s ease;
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
  }
  
  .view-controls:hover {
    border-color: var(--accent-color);
  }
  
  .view-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    background: transparent;
    border: none;
    color: var(--text-color);
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 1rem;
  }
  
  .view-btn:hover {
    background: var(--button-hover);
    color: var(--text-color);
  }
  
  .view-btn.active {
    background: var(--button-hover);
    color: var(--text-color);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
  }
  
  .view-btn + .view-btn {
    border-left: 1px solid rgba(255, 255, 255, 0.2);
  }
  
  /* --- Utility Controls --- */
  .utility-group {
    display: flex;
    gap: 0.5rem;
  }
  
  .utility-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    background: var(--button-bg);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 8px;
    color: var(--text-color);
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 1rem;
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
  }
  
  .utility-btn:hover {
    background: var(--button-hover);
    transform: translateY(-1px);
    border-color: var(--accent-color);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  }
  
  /* =================================================================
     6. MOBILE COMPONENTS
     ================================================================= */
  
  /* --- Mobile Toggle --- */
  .mobile-toggle {
    display: flex;
    flex-direction: column;
    justify-content: center;
    width: 40px;
    height: 40px;
    background: var(--button-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    gap: 4px;
    transition: all 0.2s ease;
  }
  
  .mobile-toggle:hover {
    background: var(--button-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  }
  
  .hamburger-line {
    width: 20px;
    height: 2px;
    background: var(--text-color);
    border-radius: 1px;
    transition: all 0.2s ease;
    margin: 0 auto;
  }
  
  .mobile-brand {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 600;
    color: var(--text-color);
  }
  
  .mobile-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: var(--button-bg);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-color);
    cursor: pointer;
  }
  
  /* --- Mobile Stats --- */
  .mobile-stats {
    display: flex;
    gap: 1rem;
    padding: 1rem 0;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 1rem;
  }
  
  .mobile-stat-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    color: var(--text-color);
  }
  
  .mobile-stats-container {
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.75rem;
    margin-bottom: 1rem;
  }
  
  .mobile-stats-container .stat-item {
    font-size: 0.9rem;
    color: var(--text-color);
    display: flex;
    align-items: center;
  }
  
  .mobile-stats-container .stat-item i {
    margin-right: 0.5em;
    opacity: 0.8;
  }
  
  /* --- Mobile Menu Items --- */
  .mobile-menu-item {
    background: var(--button-bg);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: var(--text-color);
    border-radius: 8px;
    padding: 0.625rem 1rem;
    font-size: 0.875rem;
    font-weight: 500;
    text-align: left;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: all 0.2s ease;
    width: 100%;
    position: relative;
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
  }
  
  .mobile-menu-item:hover {
    background: var(--button-hover);
    transform: translateY(-1px);
    border-color: var(--accent-color);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  }
  
  .mobile-menu-item:active {
    background-color: var(--button-active);
    transform: translateY(0px);
  }
  
  .mobile-menu-item.sync-enabled {
    background: var(--button-hover);
    color: var(--text-color);
    border-color: var(--accent-color);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  }
  
  .mobile-menu-item.sync-enabled:hover {
    background: var(--button-hover);
    transform: translateY(-2px);
    border-color: var(--accent-color);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.15);
  }
  
  /* --- Mobile Menu System --- */
  .mobile-menu {
    display: none;
    position: relative;
    z-index: 1001;
  }
  
  .mobile-menu-panel {
    position: fixed;
    top: 0;
    right: -300px;
    width: 280px;
    height: 100vh;
    background-color: var(--bg-color);
    box-shadow: -2px 0 10px rgba(0, 0, 0, 0.2);
    transition: right 0.3s ease;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    z-index: 1002;
  }
  
  .mobile-menu-panel.active {
    right: 0;
  }
  
  .mobile-menu-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100vh;
    background-color: rgba(0, 0, 0, 0.5);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    z-index: 1000;
  }
  
  .mobile-menu-overlay.active {
    display: block;
    opacity: 1;
    visibility: visible;
  }
  
  .mobile-menu-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
  }
  
  .mobile-menu-header h5 {
    margin: 0;
    font-size: 1.25rem;
    color: var(--text-color);
  }
  
  .mobile-menu-items {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    flex-grow: 1;
  }
  
  #close-mobile-menu.tool-button {
    padding: 0.25rem 0.5rem;
    font-size: 1rem;
  }
  
  .mobile-menu-panel .dropzone {
    margin-bottom: 0;
  }
  
  /* =================================================================
     7. DROPDOWN COMPONENTS
     ================================================================= */
  
  .modern-dropdown {
    position: relative;
    background: linear-gradient(180deg, rgba(255,255,255,0.12), rgba(255,255,255,0.06)) !important;
    border: 1px solid rgba(79, 195, 247, 0.25) !important;
    border-radius: 12px !important;
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.35) !important;
    padding: 0.5rem !important;
    margin-top: 0.5rem !important;
    -webkit-backdrop-filter: blur(22px) saturate(200%);
    backdrop-filter: blur(22px) saturate(200%);
    min-width: 230px;
  }

  .modern-dropdown::before {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: 12px;
    box-shadow: inset 0 0 0 1px rgba(255,255,255,0.08);
    pointer-events: none;
  }
  
  .modern-dropdown .dropdown-item {
    display: flex !important;
    align-items: center !important;
    gap: 0.75rem !important;
    padding: 0.7rem 0.95rem !important;
    border-radius: 8px !important;
    margin: 2px 0 !important;
    color: var(--text-color) !important;
    font-weight: 500 !important;
    transition: transform 0.15s ease, background 0.15s ease !important;
  }
  
  .modern-dropdown .dropdown-item:hover {
    background: rgba(79, 195, 247, 0.12) !important;
    transform: translateX(3px) !important;
  }

  .modern-dropdown .dropdown-item i {
    opacity: 0.9 !important;
  }

  .modern-dropdown .dropdown-item:not(:first-child) {
    border-top: 1px solid rgba(255,255,255,0.06);
  }
  
  .dropdown-menu {
    background-color: var(--bg-color);
    border-color: var(--border-color);
  }
  
  .dropdown-item {
    color: var(--text-color);
  }
  
  .dropdown-item:hover, .dropdown-item:focus {
    background-color: var(--button-hover);
    color: var(--text-color);
  }
  
  /* =================================================================
     8. EDITOR & PREVIEW PANES
     ================================================================= */
  
  .editor-pane {
    flex: 1;
    padding: 10px 0px 10px 10px;
    overflow: hidden;
    position: relative;
    transition: all 0.3s ease;
    background-color: var(--editor-bg);
    border-right: 1px solid rgba(79, 195, 247, 0.12);
    box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.1);
    width: 100%;
    max-width: 100%;
  }

  /* In editor-only, pane should not scroll; page owns the scrollbar */
  body.editor-only-active .editor-pane {
    overflow: visible;
  }

  /* Drag-and-drop highlight for editor pane */
  .editor-pane.drop-active::after {
    content: "📥  Drop your file to load";
    position: absolute;
    inset: 8px;
    border: 2px dashed rgba(79, 195, 247, 0.6);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-color);
    font-family: "JetBrains Mono", "Fira Code", Consolas, monospace;
    font-weight: 700;
    font-size: 1.05rem;
    letter-spacing: 0.1px;
    text-shadow: 0 1px 3px rgba(0,0,0,0.35);
    background: linear-gradient(180deg, rgba(79,195,247,0.045), rgba(79,195,247,0.02));
    -webkit-backdrop-filter: blur(2px) saturate(140%);
    backdrop-filter: blur(2px) saturate(140%);
    box-shadow: inset 0 0 0 2px rgba(79,195,247,0.22), 0 8px 24px rgba(0,0,0,0.22);
    pointer-events: none;
    z-index: 9;
    transition: all 120ms ease;
  }
  
  .preview-pane {
    flex: 1;
    padding: 20px;
    overflow-y: auto; /* split view default */
    overflow-x: hidden;
    position: relative;
    transition: all 0.3s ease;
    background-color: var(--preview-bg);
    box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.05);
    width: 100%;
    max-width: 100%;
  }

  /* In preview-only, native page scroll should take over (no inner scroll) */
  body.preview-only-active .preview-pane {
    overflow: visible;
  }

  /* Safety: disable any scoped webkit scrollbar skin when NOT in split */
  body.editor-only-active .editor-pane::-webkit-scrollbar,
  body.editor-only-active .editor-pane::-webkit-scrollbar-track,
  body.editor-only-active .editor-pane::-webkit-scrollbar-thumb,
  body.editor-only-active #markdown-editor::-webkit-scrollbar,
  body.editor-only-active #markdown-editor::-webkit-scrollbar-track,
  body.editor-only-active #markdown-editor::-webkit-scrollbar-thumb,
  body.preview-only-active .preview-pane::-webkit-scrollbar,
  body.preview-only-active .preview-pane::-webkit-scrollbar-track,
  body.preview-only-active .preview-pane::-webkit-scrollbar-thumb {
    width: auto !important;
    height: auto !important;
    background: initial !important;
    border: initial !important;
    box-shadow: none !important;
  }
  
  .editor-wrapper {
    position: relative;
    width: 100%;
    height: calc(100% - 44px);
    margin-top: 0;
  }
  
  /* =================================================================
     9. MARKDOWN EDITOR
     ================================================================= */
  
  #markdown-editor {
    width: 100%;
    height: 100%;
    border: none;
    background-color: var(--editor-bg);
    color: var(--text-color);
    resize: none;
    font-family: "JetBrains Mono", "Fira Code", "Consolas", "Monaco", "Lucida Console", monospace;
    font-size: 16px;
    line-height: 1.5;
    padding: 10px 10px 50px 10px;
    transition: background-color 0.3s ease, color 0.3s ease;
    overflow-y: auto; /* default in split view */
    font-feature-settings: "liga" 1, "calt" 1;
  }
  
  #markdown-editor:focus {
    outline: none;
  }
  
  /* Editor-only mode: Make textarea expand to fit content */
  /* In editor-only, the pane is the scroller, textarea expands and doesn't scroll */
  .editor-pane.native-scrollbars #markdown-editor {
    height: auto;
    min-height: 100%;
    overflow: visible;
  }
  
  /* =================================================================
     10. EDITOR STATISTICS
     ================================================================= */
  
  .editor-stats {
    position: absolute;
    bottom: 10px;
    right: 15px;
    display: flex;
    gap: 0.75rem;
    padding: 0.5rem 0.75rem;
    background: var(--button-hover);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    font-size: 0.75rem;
    color: var(--text-color);
    z-index: 5;
    transition: all 0.2s ease;
  }

  /* Keep stats bubble always visible in editor-only mode (mobile/desktop) */
  body.editor-only-active .editor-stats {
    position: fixed;
    right: 12px;
    bottom: calc(12px + env(safe-area-inset-bottom));
    z-index: 1000;
    pointer-events: none; /* purely informational */
  }
  
  .editor-stat-item {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    font-weight: 500;
  }
  
  .editor-stat-item i {
    font-size: 0.7rem;
    opacity: 0.8;
  }
  
  .editor-stat-value {
    color: var(--accent-color);
    font-weight: 600;
  }
  
  /* =================================================================
     11. TOOLBAR COMPONENTS
     ================================================================= */
  
  /* --- Base Toolbar --- */
  .toolbar {
    display: flex;
    gap: 8px;
  }
  
  .tool-button {
    background-color: var(--button-bg);
    border: 1px solid var(--border-color);
    color: var(--text-color);
    border-radius: 6px;
    padding: 6px 12px;
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
    transition: all 0.2s ease;
    -webkit-user-select: none;
    user-select: none;
  }
  
  .tool-button:hover {
    background-color: var(--button-hover);
  }
  
  .tool-button:active {
    background-color: var(--button-active);
  }
  
  .tool-button i {
    font-size: 16px;
  }
  
  /* --- Formatting Toolbar --- */
  .formatting-toolbar {
    display: flex;
    align-items: center;
    gap: 3px;
    padding: 7px 10px 10px 10px;
    justify-content: center;
    background: rgba(var(--editor-bg-rgb, 255, 255, 255), 0.8);
    border-bottom: 1px solid rgba(79, 195, 247, 0.2);
    flex-wrap: nowrap;
    position: sticky;
    top: 0;
    z-index: 10;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    backdrop-filter: blur(20px) saturate(180%);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    transition: all 0.3s ease;
    animation: toolbarGlow 3s ease-in-out infinite alternate;
    width: calc(100% - 16px);
    margin-left: 4px;
    margin-right: 12px;
  }
  
  .format-button {
    background: rgba(var(--button-bg-rgb, 248, 249, 250), 0.7);
    border: 1px solid rgba(79, 195, 247, 0.2);
    color: var(--text-color);
    border-radius: 6px;
    padding: 6px 8px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 28px;
    height: 28px;
    transition: all 0.3s ease;
    -webkit-user-select: none;
    user-select: none;
    -webkit-backdrop-filter: blur(12px) saturate(150%);
    backdrop-filter: blur(12px) saturate(150%);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  }
  
  .format-button:hover {
    background: rgba(79, 195, 247, 0.15);
    border-color: rgba(79, 195, 247, 0.6);
    color: var(--accent-color);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(79, 195, 247, 0.3);
    -webkit-backdrop-filter: blur(16px) saturate(200%);
    backdrop-filter: blur(16px) saturate(200%);
  }
  
  .format-button:active {
    background-color: rgba(79, 195, 247, 0.15);
    transform: scale(0.95);
  }
  
  .format-button i {
    font-size: 14px;
  }
  
  #format-h1, #format-h2, #format-h3 {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
    min-width: 32px;
    font-weight: 600;
  }
  
  .toolbar-separator {
    width: 2px;
    height: 20px;
    background-color: rgba(255, 255, 255, 0.3);
    margin: 0 6px;
    border-radius: 1px;
    opacity: 0.8;
  }
  
  /* =================================================================
     12. FILE HANDLING & DRAG-DROP
     ================================================================= */
  
  .file-input {
    display: none;
  }
  
  .dropzone {
    border: 2px dashed rgba(79, 195, 247, 0.4);
    border-radius: 12px;
    padding: 30px;
    text-align: center;
    margin-bottom: 10px;
    cursor: pointer;
    transition: all 0.3s ease;
    background-color: rgba(79, 195, 247, 0.05);
    position: relative;
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
  }
  
  .dropzone.active {
    border-color: rgba(79, 195, 247, 0.8);
    background-color: rgba(79, 195, 247, 0.1);
    transform: scale(1.02);
    box-shadow: 0 8px 25px rgba(79, 195, 247, 0.2);
  }
  
  .dropzone p {
    transition: transform 0.2s ease;
    color: var(--accent-color);
    font-weight: 500;
  }
  
  .dropzone:hover {
    border-color: rgba(79, 195, 247, 0.6);
    background-color: rgba(79, 195, 247, 0.08);
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(79, 195, 247, 0.15);
  }
  
  .dropzone:hover p {
    transform: scale(1.02);
  }
  
  .close-btn {
    position: absolute;
    top: 0;
    right: 0;
    background-color: var(--button-bg);
    border: 1px solid var(--border-color);
    color: var(--text-color);
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    padding: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    width: 48px;
    height: 48px;
    opacity: 0.8;
    transition: all 0.3s ease;
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    margin: 8px;
    z-index: 10;
  }
  
  .close-btn:hover {
    opacity: 1;
    background-color: rgba(255, 107, 107, 0.1);
    border-color: var(--color-danger-fg);
    color: var(--color-danger-fg);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(255, 107, 107, 0.2);
    -webkit-backdrop-filter: blur(12px);
    backdrop-filter: blur(12px);
  }
  

  
  /* =================================================================
     14. MARKDOWN PREVIEW CONTENT
     ================================================================= */
  
  .markdown-body {
    padding: 10px;
    width: 100%;
    background-color: var(--preview-bg);
    color: var(--preview-text-color);
    box-sizing: border-box;
    min-width: 200px;
    max-width: 800px;
    margin: 0 auto;
    padding: 45px;
    font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
    overflow-x: hidden;
  }

  /* Normalize heading spacing across themes */
  .markdown-body h1,
  .markdown-body h2,
  .markdown-body h3,
  .markdown-body h4,
  .markdown-body h5,
  .markdown-body h6 {
    margin-top: 2rem;
    margin-bottom: 1rem;
  }

  /* Slightly larger, document-like scale when in preview-only mode */
  body.preview-only-active .markdown-body {
    max-width: 920px;
    font-size: 1.05rem;
    line-height: 1.7;
  }

  body.preview-only-active .markdown-body h1 { font-size: 2.1em; }
  body.preview-only-active .markdown-body h2 { font-size: 1.7em; }
  body.preview-only-active .markdown-body h3 { font-size: 1.4em; }
  
  .markdown-body img {
    background-color: transparent !important;
  }
  
  /* --- Lists --- */
  .markdown-body ul {
    list-style-type: disc;
  }
  
  .markdown-body ol {
    list-style-type: decimal;
    padding-left: 2em;
    counter-reset: section;
  }
  
  .markdown-body ol > li {
    counter-increment: section;
  }
  
  .markdown-body ol > li > ol > li {
    counter-increment: subsection;
  }
  
  .markdown-body ol > li > ol > li:before {
    content: counter(section) "." counter(subsection) " ";
    float: left;
    margin-left: -2.5em;
  }
  
  .markdown-body ol ol {
    list-style-type: none;
    counter-reset: subsection;
  }
  
  .markdown-body ol ol ol {
    list-style-type: lower-roman;
  }
  
  .markdown-body li {
    margin-bottom: 0.25em;
  }
  
  .markdown-body li > p {
    margin-top: 0.5em;
    margin-bottom: 0.5em;
  }
  
  /* --- Block Elements --- */
  .markdown-body blockquote {
    color: var(--blockquote-color, #cccccc);
    border-left: 4px solid var(--accent-color);
    padding-left: 1em;
    margin: 1em 0;
  }
  
  .markdown-body hr {
    background-color: var(--hr-color, #333333);
    border: none;
    height: 1px;
    margin: 2em 0;
  }
  
  .markdown-body h1,
  .markdown-body h2,
  .markdown-body h3,
  .markdown-body h4,
  .markdown-body h5,
  .markdown-body h6 {
    font-weight: 900;
    font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  }
  
  /* --- Code Blocks --- */
  .markdown-body pre {
    background-color: var(--code-pre-bg, #f6f8fa);
    border-radius: 6px;
    padding: 16px;
    margin: 1.5em 0;
    overflow: auto;
    font-size: 85%;
    line-height: 1.45;
    font-family: "JetBrains Mono", "Fira Code", "Consolas", "Monaco", "Lucida Console", monospace;
    font-feature-settings: "liga" 1, "calt" 1;
  }
  
  .markdown-body pre code,
  .markdown-body pre code.hljs {
    background: transparent;
    padding: 0;
    border-radius: 0;
    font-family: "JetBrains Mono", "Fira Code", "Consolas", "Monaco", "Lucida Console", monospace;
    font-feature-settings: "liga" 1, "calt" 1;
  }
  
  .markdown-body code {
    background-color: var(--code-inline-bg, #f6f8fa);
    color: var(--code-inline-color, #24292e);
    padding: 0.2em 0.4em;
    border-radius: 3px;
    font-size: 85%;
    font-family: "JetBrains Mono", "Fira Code", "Consolas", "Monaco", "Lucida Console", monospace;
    font-feature-settings: "liga" 1, "calt" 1;
  }
  

  
  /* =================================================================
     15. MERMAID DIAGRAMS
     ================================================================= */
  
  .mermaid-container, .mermaid {
    text-align: center;
    margin: 1em 0;
  }
  
  .mermaid svg {
    max-width: 100%;
    height: auto;
  }
  
  /* =================================================================
     16. FOOTER
     ================================================================= */
  
  .app-footer {
    background: linear-gradient(135deg, var(--header-bg) 0%, var(--header-gradient) 100%);
    border-top: 1px solid var(--border-color);
    padding: 16px 0;
    transition: background 0.3s ease;
    flex-shrink: 0;
  }
  
  .footer-text {
    margin: 0;
    font-size: 14px;
    color: var(--text-color);
    opacity: 0.8;
    transition: color 0.3s ease, opacity 0.3s ease;
    font-weight: 500;
  }
  
  .footer-text:hover {
    opacity: 1;
  }
  
  /* Footer heart with strawberry border effect */
  .footer-heart {
    color: transparent;
    font-size: 12px;
    animation: heartbeat 2s ease-in-out infinite;
    transition: all 0.3s ease;
    -webkit-text-stroke: 0.8px var(--heart-color-light, #ff6b7a);
    filter: drop-shadow(0 0 1px rgba(255, 107, 122, 0.8));
  }
  
  .footer-heart:hover {
    -webkit-text-stroke: 1px var(--heart-color-dark, #ff4757);
    transform: scale(1.05);
    filter: drop-shadow(0 0 2px rgba(255, 71, 87, 0.9));
  }
  
  /* =================================================================
     17. SCROLLBAR CUSTOMIZATION
     ================================================================= */
  
  /* --- Main Scrollbars (Split View Only) ---
     NOTE: Blue custom scrollbars are intentionally restricted to SPLIT VIEW.
     In editor-only and preview-only modes, the browser native scrollbars must be used.
     We scope these rules to body:not(.editor-only-active):not(.preview-only-active) to ensure this. */
  body:not(.editor-only-active):not(.preview-only-active) .editor-pane::-webkit-scrollbar,
  body:not(.editor-only-active):not(.preview-only-active) .preview-pane::-webkit-scrollbar,
  body:not(.editor-only-active):not(.preview-only-active) #markdown-editor::-webkit-scrollbar {
    width: 10px;
    height: 10px;
  }
  
  body:not(.editor-only-active):not(.preview-only-active) .editor-pane::-webkit-scrollbar-track,
  body:not(.editor-only-active):not(.preview-only-active) .preview-pane::-webkit-scrollbar-track,
  body:not(.editor-only-active):not(.preview-only-active) #markdown-editor::-webkit-scrollbar-track {
    background: rgba(79, 195, 247, 0.1);
    border-radius: 5px;
  }
  
  body:not(.editor-only-active):not(.preview-only-active) .editor-pane::-webkit-scrollbar-thumb,
  body:not(.editor-only-active):not(.preview-only-active) .preview-pane::-webkit-scrollbar-thumb,
  body:not(.editor-only-active):not(.preview-only-active) #markdown-editor::-webkit-scrollbar-thumb {
    background: rgba(79, 195, 247, 0.3);
    border-radius: 5px;
    border: 1px solid rgba(79, 195, 247, 0.2);
  }
  
  body:not(.editor-only-active):not(.preview-only-active) .editor-pane::-webkit-scrollbar-thumb:hover,
  body:not(.editor-only-active):not(.preview-only-active) .preview-pane::-webkit-scrollbar-thumb:hover,
  body:not(.editor-only-active):not(.preview-only-active) #markdown-editor::-webkit-scrollbar-thumb:hover {
    background: rgba(79, 195, 247, 0.5);
    box-shadow: 0 0 10px rgba(79, 195, 247, 0.3);
  }
  
  /* --- Toolbar Scrollbars --- */
  .formatting-toolbar::-webkit-scrollbar {
    height: 2px;
  }
  
  .formatting-toolbar::-webkit-scrollbar-track {
    background: transparent;
  }
  
  .formatting-toolbar::-webkit-scrollbar-thumb {
    background: var(--accent-color);
    border-radius: 2px;
  }
  
  .formatting-toolbar::-webkit-scrollbar-thumb:hover {
    background: var(--button-active);
  }
  
  /* =================================================================
     18. UTILITY CLASSES & ACCESSIBILITY
     ================================================================= */
  
  .loading {
    opacity: 0.6;
    pointer-events: none;
  }
  
  .tooltip {
    position: absolute;
    background: var(--button-bg);
    border: 1px solid var(--border-color);
    padding: 5px 8px;
    border-radius: 4px;
    font-size: 12px;
    z-index: 1000;
    animation: fadeIn 0.2s ease;
  }
  
  .github-link {
    color: var(--text-color);
    text-decoration: none;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease, color 0.2s ease;
    margin-right: 2rem;
  }
  
  .github-link:hover {
    color: var(--accent-color);
    transform: scale(1.1);
  }
  
  .github-link i {
    font-size: 1.5rem;
  }
  
  button:focus,
  a:focus {
    outline: 2px solid var(--accent-color);
    outline-offset: 2px;
  }

  /* Border utility class used by JavaScript */
  .border-primary {
    border-color: var(--accent-color) !important;
  }