/* 
 * Worksheet Base Styles - Premium 2026 Design System
 * Aligned with Jolly Grid Landing Page Theme
 * Methodology: BEM (Block Element Modifier)
 * Version: 3.1 (December 2025)
 */

/* ============================================
   THEME VARIABLES - UNIFIED WITH LANDING PAGE
   ============================================ */

/* Light Theme (Default) */
:root,
[data-theme="light"] {
    /* Layout Dimensions */
    --sidebar-width: 380px;
    --header-height: 60px;
    
    /* Primary accent - Purple (matching landing page) */
    --c-primary: #8b5cf6;
    --c-primary-hover: #7c3aed;
    --c-primary-light: rgba(139, 92, 246, 0.08);
    --c-primary-glow: rgba(139, 92, 246, 0.2);
    
    /* Secondary accent - Pink */
    --c-secondary: #ec4899;
    --c-secondary-light: rgba(236, 72, 153, 0.08);
    
    /* Status colors */
    --c-success: #10b981;
    --c-success-light: rgba(16, 185, 129, 0.1);
    --c-warning: #f97316;
    --c-danger: #ef4444;
    
    /* Backgrounds - Clean white */
    --c-bg-app: #ffffff;
    --c-bg-panel: #ffffff;
    --c-bg-input: #fafbfc;
    --c-bg-card: #ffffff;
    --c-bg-hover: rgba(139, 92, 246, 0.04);
    --c-bg-section: #fafbfc;
    
    /* Text - Dark readable */
    --c-text-main: #111827;
    --c-text-secondary: #374151;
    --c-text-muted: #6b7280;
    --c-text-subtle: #9ca3af;
    --c-text-inverse: #ffffff;
    
    /* Borders - Subtle */
    --c-border: rgba(0, 0, 0, 0.08);
    --c-border-light: rgba(0, 0, 0, 0.04);
    --c-border-medium: rgba(0, 0, 0, 0.12);
    --c-border-focus: var(--c-primary);
    
    /* Gradients - Purple to Pink */
    --c-gradient: linear-gradient(135deg, #8b5cf6 0%, #ec4899 100%);
    --c-gradient-hover: linear-gradient(135deg, #7c3aed 0%, #db2777 100%);
    --c-gradient-subtle: linear-gradient(135deg, rgba(139, 92, 246, 0.1) 0%, rgba(236, 72, 153, 0.1) 100%);
    --c-glow: 0 0 0 3px var(--c-primary-glow);
    
    /* Shadows - Soft and elegant */
    --c-shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.03);
    --c-shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.03), 0 2px 8px rgba(0, 0, 0, 0.04);
    --c-shadow: 0 2px 8px rgba(0, 0, 0, 0.04), 0 4px 16px rgba(0, 0, 0, 0.03);
    --c-shadow-md: 0 4px 12px rgba(0, 0, 0, 0.05), 0 2px 6px rgba(0, 0, 0, 0.03);
    --c-shadow-lg: 0 6px 20px rgba(0, 0, 0, 0.06), 0 4px 12px rgba(0, 0, 0, 0.04);
    --c-shadow-glow: 0 4px 20px rgba(139, 92, 246, 0.15);
    --c-panel-shadow: 0 0 40px rgba(0, 0, 0, 0.04);
    --c-footer-shadow: 0 -4px 20px rgba(0, 0, 0, 0.03);
    
    /* Worksheet (Always White for Print) */
    --c-sheet-bg: #ffffff;
    --c-sheet-text: #000000;
    --c-answer: #dc2626;
    
    /* Typography */
    --font-ui: 'Nunito', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-sheet: 'Roboto Mono', 'SF Mono', 'Consolas', monospace;
    
    /* Spacing */
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 12px;
    --space-lg: 16px;
    --space-xl: 24px;
    
    /* Border Radius */
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --radius-xl: 18px;
    --radius-full: 9999px;
    
    /* Transitions */
    --transition-fast: 0.15s ease;
    --transition-base: 0.2s ease;
    --transition-slow: 0.3s ease;
    
    /* Paper Dimensions */
    --paper-width: 210mm;
    --paper-height: 297mm;
    --paper-padding: 15mm;
}

/* Dark Theme - Matching Landing Page */
[data-theme="dark"] {
    /* Primary accent - Lighter purple for dark mode */
    --c-primary: #a78bfa;
    --c-primary-hover: #c4b5fd;
    --c-primary-light: rgba(167, 139, 250, 0.12);
    --c-primary-glow: rgba(167, 139, 250, 0.25);
    
    /* Secondary accent - Pink */
    --c-secondary: #f472b6;
    --c-secondary-light: rgba(244, 114, 182, 0.12);
    
    /* Status colors */
    --c-success: #34d399;
    --c-success-light: rgba(52, 211, 153, 0.15);
    
    /* Backgrounds - Deep blue-black (matching landing) */
    --c-bg-app: #080c18;
    --c-bg-panel: #0c1424;
    --c-bg-input: #121a2e;
    --c-bg-card: rgba(18, 22, 32, 0.75);
    --c-bg-hover: rgba(167, 139, 250, 0.08);
    --c-bg-section: #0c1424;
    
    /* Text - Light readable */
    --c-text-main: #f8fafc;
    --c-text-secondary: rgba(248, 250, 252, 0.88);
    --c-text-muted: rgba(248, 250, 252, 0.65);
    --c-text-subtle: rgba(248, 250, 252, 0.45);
    --c-text-inverse: #111827;
    
    /* Borders - Subtle glow */
    --c-border: rgba(255, 255, 255, 0.08);
    --c-border-light: rgba(255, 255, 255, 0.04);
    --c-border-medium: rgba(255, 255, 255, 0.12);
    --c-border-focus: var(--c-primary);
    
    /* Gradients - Purple to Pink */
    --c-gradient: linear-gradient(135deg, #a78bfa 0%, #f472b6 100%);
    --c-gradient-hover: linear-gradient(135deg, #c4b5fd 0%, #f9a8d4 100%);
    --c-gradient-subtle: linear-gradient(135deg, rgba(167, 139, 250, 0.15) 0%, rgba(244, 114, 182, 0.15) 100%);
    --c-glow: 0 0 0 3px var(--c-primary-glow);
    
    /* Shadows - Deeper for dark mode */
    --c-shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.2);
    --c-shadow-sm: 0 2px 6px rgba(0, 0, 0, 0.2), 0 1px 2px rgba(0, 0, 0, 0.12);
    --c-shadow: 0 4px 16px rgba(0, 0, 0, 0.28), 0 2px 6px rgba(0, 0, 0, 0.16);
    --c-shadow-md: 0 6px 20px rgba(0, 0, 0, 0.3), 0 3px 8px rgba(0, 0, 0, 0.2);
    --c-shadow-lg: 0 10px 36px rgba(0, 0, 0, 0.35), 0 4px 12px rgba(0, 0, 0, 0.2);
    --c-shadow-glow: 0 6px 32px rgba(167, 139, 250, 0.25);
    --c-panel-shadow: 0 0 48px rgba(0, 0, 0, 0.4);
    --c-footer-shadow: 0 -8px 32px rgba(0, 0, 0, 0.3);
}

/* ============================================
   RESET & BASE
   ============================================ */
* { 
    box-sizing: border-box; 
    margin: 0; 
    padding: 0; 
}

body {
    font-family: var(--font-ui);
    background-color: var(--c-bg-app);
    color: var(--c-text-main);
    height: 100vh;
    overflow: hidden;
    transition: background-color var(--transition-slow), color var(--transition-slow);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ============================================
   APP LAYOUT (2-column: Sidebar + Stage)
   ============================================ */
.app {
    display: grid;
    grid-template-columns: var(--sidebar-width) 1fr;
    height: 100vh;
}

/* ============================================
   SIDEBAR PANEL - Premium 2026 Design
   ============================================ */
.panel {
    background: var(--c-bg-panel);
    border-right: 1px solid var(--c-border);
    display: flex;
    flex-direction: column;
    z-index: 10;
    box-shadow: var(--c-panel-shadow);
    height: 100vh;
    max-height: 100vh;
    overflow: hidden;
    transition: background-color var(--transition-slow), 
                border-color var(--transition-slow), 
                box-shadow var(--transition-slow);
}

/* ============================================
   PANEL HEADER - Clean & Modern
   ============================================ */
.panel__header {
    min-height: var(--header-height);
    height: var(--header-height);
    padding: 0 var(--space-lg);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-md);
    border-bottom: 1px solid var(--c-border);
    background: var(--c-bg-panel);
    flex-shrink: 0;
    transition: background-color var(--transition-slow), 
                border-color var(--transition-slow);
}

/* Navigation Button - Back */
.panel__nav-btn {
    color: var(--c-text-secondary);
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: var(--radius-md);
    transition: all var(--transition-base);
    background: var(--c-bg-input);
    border: 1px solid var(--c-border);
    flex-shrink: 0;
    cursor: pointer;
}

.panel__nav-btn:hover {
    background: var(--c-primary);
    color: var(--c-text-inverse);
    border-color: var(--c-primary);
    transform: translateX(-2px);
    box-shadow: var(--c-shadow-md);
}

.panel__nav-btn:active {
    transform: translateX(-1px) scale(0.98);
}

/* Center Section */
.panel__center {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-md);
    flex: 1;
    min-width: 0;
}

.panel__logo-link {
    display: flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    transition: transform var(--transition-base);
    flex-shrink: 0;
}

.panel__logo-link:hover {
    transform: scale(1.05);
}

.panel__logo-img {
    height: 28px;
    width: auto;
    display: block;
}

.panel__divider {
    width: 1px;
    height: 20px;
    background: var(--c-border);
    flex-shrink: 0;
    opacity: 0.6;
}

.panel__title {
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    background: var(--c-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    white-space: nowrap;
    margin: 0;
}

/* Action Buttons Group */
.panel__actions {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}

/* Icon Buttons - Clean Style */
.panel__action-btn {
    color: var(--c-text-muted);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: 8px;
    transition: all 0.15s ease;
    background: transparent;
    border: none;
    cursor: pointer;
    position: relative;
}

.panel__action-btn .material-icons-round {
    font-size: 20px;
}

.panel__action-btn:hover {
    background: var(--c-primary-light);
    color: var(--c-primary);
}

.panel__action-btn:active {
    transform: scale(0.92);
}

/* Tooltip for action buttons */
.panel__action-btn[title]::after {
    content: attr(title);
    position: absolute;
    bottom: -28px;
    left: 50%;
    transform: translateX(-50%);
    padding: 4px 8px;
    background: var(--c-text-main);
    color: var(--c-bg-panel);
    font-size: 10px;
    font-weight: 600;
    white-space: nowrap;
    border-radius: 4px;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.15s ease;
    pointer-events: none;
    z-index: 100;
}

.panel__action-btn:hover::after {
    opacity: 1;
    visibility: visible;
}

/* Theme Toggle Button - Premium Sun/Moon Toggle */
.theme-toggle-btn {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 10px;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    background: var(--c-bg-input);
    border: 1.5px solid var(--c-border);
    cursor: pointer;
    overflow: hidden;
}

.theme-toggle-btn .material-icons-round {
    font-size: 20px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Light mode - show moon icon (dark_mode) with blue tint */
[data-theme="light"] .theme-toggle-btn {
    color: #64748b;
}

[data-theme="light"] .theme-toggle-btn:hover {
    background: linear-gradient(135deg, #1e293b 0%, #334155 100%);
    border-color: #475569;
    color: #f8fafc;
    box-shadow: 0 4px 12px rgba(30, 41, 59, 0.25);
}

[data-theme="light"] .theme-toggle-btn:hover .material-icons-round {
    transform: rotate(-20deg) scale(1.1);
    color: #c4b5fd;
}

/* Dark mode - show sun icon (light_mode) with warm glow */
[data-theme="dark"] .theme-toggle-btn {
    color: #fbbf24;
    background: rgba(251, 191, 36, 0.08);
    border-color: rgba(251, 191, 36, 0.25);
}

[data-theme="dark"] .theme-toggle-btn:hover {
    background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
    border-color: #fbbf24;
    color: #f59e0b;
    box-shadow: 0 4px 16px rgba(251, 191, 36, 0.35);
}

[data-theme="dark"] .theme-toggle-btn:hover .material-icons-round {
    transform: rotate(20deg) scale(1.15);
    color: #d97706;
}

.theme-toggle-btn:active {
    transform: scale(0.9);
}

/* Icon visibility */
[data-theme="light"] .theme-toggle-btn .icon-dark { display: none; }
[data-theme="light"] .theme-toggle-btn .icon-light { display: block; }
[data-theme="dark"] .theme-toggle-btn .icon-dark { display: block; }
[data-theme="dark"] .theme-toggle-btn .icon-light { display: none; }

.mobile-only { display: none; }

/* ============================================
   PANEL CONTENT - Scrollable Area
   ============================================ */
.panel__content {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 16px;
    scrollbar-width: thin;
    scrollbar-color: var(--c-border) transparent;
    min-height: 0;
}

.panel__content::-webkit-scrollbar { width: 5px; }
.panel__content::-webkit-scrollbar-track { background: transparent; }
.panel__content::-webkit-scrollbar-thumb { 
    background-color: var(--c-border); 
    border-radius: var(--radius-full);
}
.panel__content::-webkit-scrollbar-thumb:hover { 
    background-color: var(--c-text-muted); 
}

/* ============================================
   PANEL FOOTER - Sticky Actions
   ============================================ */
.panel__footer {
    padding: 12px 16px;
    border-top: 1px solid var(--c-border);
    background: var(--c-bg-panel);
    z-index: 10;
    box-shadow: var(--c-footer-shadow);
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex-shrink: 0;
    transition: background-color var(--transition-slow), 
                border-color var(--transition-slow);
}

.panel__footer-row {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 4px;
}

.panel__footer-row .btn {
    width: 100%;
}

.panel__footer-row .btn--secondary {
    order: -1;  /* Share button on top */
}

/* ============================================
   CONTROL GROUPS - Organized Sections
   ============================================ */
.control-group {
    margin-bottom: 16px;
    padding-bottom: 14px;
    border-bottom: 1px solid var(--c-border-light);
}

.control-group:last-child {
    margin-bottom: 0;
    padding-bottom: 0;
    border-bottom: none;
}

.control-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}

.control-header-actions {
    display: flex;
    gap: 6px;
    align-items: center;
}

.control-item {
    margin-bottom: 10px;
}

.control-item:last-child { margin-bottom: 0; }

/* Section Labels */
.control-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--c-text-muted);
    letter-spacing: 0.8px;
    margin-bottom: 10px;
}

.control-label::before {
    content: '';
    width: 3px;
    height: 10px;
    background: var(--c-gradient);
    border-radius: var(--radius-full);
}

.control-sublabel {
    font-size: 12px;
    color: var(--c-text-secondary);
    font-weight: 600;
    display: block;
    margin-bottom: 6px;
}

.control-value {
    font-size: 11px;
    font-weight: 700;
    color: var(--c-primary);
    background: var(--c-primary-light);
    padding: 3px 8px;
    border-radius: 5px;
    min-width: 36px;
    text-align: center;
}

/* ============================================
   FORM INPUTS - Clean Modern Style
   ============================================ */
.control-input,
.control-select {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--c-border);
    border-radius: var(--radius-md);
    font-size: 13px;
    font-family: var(--font-ui);
    font-weight: 500;
    color: var(--c-text-main);
    background-color: var(--c-bg-input);
    transition: border-color 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease;
}

.control-input::placeholder {
    color: var(--c-text-muted);
}

.control-input:hover,
.control-select:hover {
    border-color: var(--c-primary);
    background-color: var(--c-bg-card);
}

.control-input:focus,
.control-select:focus {
    outline: none;
    border-color: var(--c-primary);
    box-shadow: 0 0 0 3px var(--c-primary-light);
    background-color: var(--c-bg-card);
}

/* Select dropdown with custom arrow */
.control-select {
    appearance: none !important;
    -webkit-appearance: none !important;
    -moz-appearance: none !important;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%238b5cf6' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10l-5 5z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 38px;
    cursor: pointer;
}

/* Dark mode form inputs */
[data-theme="dark"] .control-input,
[data-theme="dark"] .control-select {
    background-color: var(--c-bg-input);
    border-color: var(--c-border);
    color: var(--c-text-main);
}

[data-theme="dark"] .control-select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%23a78bfa' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10l-5 5z'/%3E%3C/svg%3E");
}

[data-theme="dark"] .control-input:hover,
[data-theme="dark"] .control-select:hover {
    border-color: var(--c-primary);
    background-color: rgba(167, 139, 250, 0.04);
}

[data-theme="dark"] .control-input:focus,
[data-theme="dark"] .control-select:focus {
    border-color: var(--c-primary);
    box-shadow: 0 0 0 3px var(--c-primary-light);
    background-color: rgba(167, 139, 250, 0.04);
}

[data-theme="dark"] .control-select option {
    background-color: #0c1424;
    color: #f8fafc;
}

[data-theme="dark"] .control-input::placeholder {
    color: #64748b;
}

.control-textarea {
    width: 100%;
    padding: 8px 12px;
    border: 1.5px solid var(--c-border);
    border-radius: 8px;
    font-size: 13px;
    font-family: var(--font-ui);
    color: var(--c-text-main);
    background: var(--c-bg-input);
    resize: vertical;
    min-height: 60px;
    transition: all 0.2s ease;
}

.control-textarea:focus {
    outline: none;
    border-color: var(--c-primary);
    box-shadow: var(--c-glow);
}

/* ============================================
   RANGE SLIDER - Clean Design
   ============================================ */
.control-range {
    width: 100%;
    cursor: pointer;
    height: 4px;
    background: var(--c-border);
    border-radius: 4px;
    appearance: none;
    margin: 8px 0;
}

.control-range::-webkit-slider-thumb {
    appearance: none;
    width: 16px;
    height: 16px;
    background: var(--c-primary);
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 1px 4px rgba(0,0,0,0.2);
    transition: all 0.15s ease;
    border: 2px solid var(--c-bg-panel);
}

.control-range::-webkit-slider-thumb:hover { 
    transform: scale(1.1);
}

.control-range::-webkit-slider-thumb:active { 
    transform: scale(1.05);
}

.control-range::-moz-range-thumb {
    width: 16px;
    height: 16px;
    background: var(--c-primary);
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 1px 4px rgba(0,0,0,0.2);
    border: 2px solid var(--c-bg-panel);
}

.control-row {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 14px;
    color: var(--c-text-main);
    font-weight: 500;
}

/* ============================================
   TOGGLE GRID - Clean Button Selection
   ============================================ */
.toggle-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
}

.toggle-btn {
    position: relative;
    padding: 8px 6px;
    border: 1.5px solid var(--c-border);
    background: var(--c-bg-input);
    border-radius: 8px;
    font-size: 10px;
    cursor: pointer;
    color: var(--c-text-muted);
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    font-family: var(--font-ui);
    font-weight: 600;
    min-height: 48px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.toggle-btn:hover {
    border-color: var(--c-primary);
    background: var(--c-primary-light);
    color: var(--c-primary);
}

.toggle-btn:active {
    transform: scale(0.98);
}

.toggle-btn.active {
    border-color: transparent;
    background: var(--c-gradient);
    color: white;
    box-shadow: 0 2px 12px var(--c-primary-glow);
}

/* Dark mode active state */
[data-theme="dark"] .toggle-btn.active {
    background: var(--c-gradient);
    border-color: transparent;
    box-shadow: 0 2px 16px var(--c-primary-glow);
}

.toggle-btn.full-width {
    grid-column: span 2;
    flex-direction: row;
    justify-content: center;
    gap: 6px;
    min-height: 38px;
}

.toggle-btn .material-icons-round {
    font-size: 16px;
    opacity: 0.9;
}

.toggle-btn.active .material-icons-round {
    opacity: 1;
}

/* ============================================
   FOOTER TOGGLE - Switch with Label
   ============================================ */
.footer-toggle {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 14px;
    font-weight: 600;
    font-size: 13px;
    color: var(--c-text-main);
    background: var(--c-bg-input);
    border-radius: var(--radius-md);
    border: 1px solid var(--c-border);
    transition: all 0.2s ease;
}

.footer-toggle:hover {
    border-color: var(--c-primary);
    background: var(--c-primary-light);
}

/* ============================================
   TOGGLE SWITCH - Clean Modern Style
   ============================================ */
.switch {
    position: relative;
    display: inline-block;
    width: 38px;
    height: 20px;
    flex-shrink: 0;
}

.switch input { 
    opacity: 0; 
    width: 0; 
    height: 0; 
}

.slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background-color: var(--c-border-medium);
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.slider:before {
    position: absolute;
    content: "";
    height: 14px;
    width: 14px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}

input:checked + .slider {
    background: var(--c-gradient);
}

input:checked + .slider:before {
    transform: translateX(18px);
}

.slider.round { border-radius: 20px; }
.slider.round:before { border-radius: 50%; }

/* ============================================
   BUTTONS - Premium Gradient Style
   ============================================ */
.btn {
    width: 100%;
    padding: 12px 16px;
    border: none;
    border-radius: var(--radius-md);
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    font-family: var(--font-ui);
    letter-spacing: 0.3px;
}

.btn--primary {
    background: var(--c-gradient);
    color: white;
    box-shadow: var(--c-shadow-glow);
}

.btn--primary:hover {
    background: var(--c-gradient-hover);
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(139, 92, 246, 0.35);
}

[data-theme="dark"] .btn--primary:hover {
    box-shadow: 0 8px 28px rgba(167, 139, 250, 0.4);
}

.btn--primary:active {
    transform: translateY(0);
    box-shadow: var(--c-shadow-glow);
}

.btn--secondary {
    background: transparent;
    color: var(--c-primary);
    border: 1.5px solid var(--c-primary);
    box-shadow: none;
}

.btn--secondary:hover {
    background: var(--c-primary-light);
    transform: translateY(-1px);
}

.btn--secondary:active {
    transform: translateY(0);
}

/* Mini Buttons - Compact Actions */
.btn-mini {
    background: var(--c-bg-panel);
    border: 1.5px solid var(--c-border);
    color: var(--c-text-secondary);
    font-size: 11px;
    padding: 6px 14px;
    border-radius: 8px;
    cursor: pointer;
    text-transform: uppercase;
    font-weight: 700;
    transition: all 0.15s ease;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    letter-spacing: 0.3px;
}

.btn-mini:hover {
    background: var(--c-primary-light);
    color: var(--c-primary);
    border-color: var(--c-primary);
}

.btn-mini:active {
    transform: scale(0.98);
}

/* ============================================
   PREVIEW STAGE - Canvas Area
   ============================================ */
.stage {
    background: var(--c-bg-app);
    position: relative;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: background-color var(--transition-slow);
}

/* Light mode grid pattern */
[data-theme="light"] .stage {
    background-image: 
        radial-gradient(#e2e8f0 1.5px, transparent 1.5px);
    background-size: 24px 24px;
}

/* Dark mode grid pattern */
[data-theme="dark"] .stage {
    background-image: 
        linear-gradient(rgba(255, 255, 255, 0.02) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, 0.02) 1px, transparent 1px);
    background-size: 32px 32px;
}

.stage__toolbar {
    height: 56px;
    background: transparent;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding: 0 var(--space-xl);
    gap: var(--space-md);
    flex-shrink: 0;
}

.toolbar-info {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    font-size: 12px;
    font-weight: 600;
    color: var(--c-text-muted);
    background: var(--c-bg-panel);
    padding: var(--space-sm) var(--space-lg);
    border-radius: var(--radius-full);
    border: 1px solid var(--c-border);
    transition: all var(--transition-base);
}

.toolbar-info:hover {
    border-color: var(--c-text-muted);
}

.stage__content {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-xl);
    display: flex;
    flex-direction: column;
    align-items: center;
    scrollbar-width: thin;
    scrollbar-color: var(--c-border) transparent;
}

.stage__content::-webkit-scrollbar { width: 8px; }
.stage__content::-webkit-scrollbar-track { background: transparent; }
.stage__content::-webkit-scrollbar-thumb { 
    background-color: var(--c-border); 
    border-radius: var(--radius-full);
}

.sheets-wrapper {
    display: flex;
    flex-direction: column;
    gap: var(--space-xl);
    align-items: center;
    padding-bottom: var(--space-xl);
}

/* ============================================
   WORKSHEET SHEET (Paper - Always White)
   ============================================ */
.sheet {
    width: var(--paper-width);
    height: var(--paper-height);
    background: #ffffff !important;
    padding: var(--paper-padding);
    box-shadow: 
        0 4px 6px -1px rgba(0, 0, 0, 0.1),
        0 10px 20px -5px rgba(0, 0, 0, 0.1),
        0 25px 50px -12px rgba(0, 0, 0, 0.15);
    margin-bottom: var(--space-xl);
    position: relative;
    display: flex;
    flex-direction: column;
    border-radius: 4px;
    overflow: hidden;
    color: #000 !important;
    box-sizing: border-box;
    transition: box-shadow var(--transition-base);
}

.sheet:hover {
    box-shadow: 
        0 8px 12px -2px rgba(0, 0, 0, 0.1),
        0 16px 32px -8px rgba(0, 0, 0, 0.15),
        0 32px 64px -16px rgba(0, 0, 0, 0.2);
}

.sheet--a4 {
    --paper-width: 210mm;
    --paper-height: 296mm; /* 1mm buffer from 297mm */
}

.sheet--letter {
    --paper-width: 215.9mm;
    --paper-height: 278mm; /* 1.4mm buffer from 279.4mm */
}

.sheet--legal {
    --paper-width: 215.9mm;
    --paper-height: 353mm; /* ~2.5mm buffer from 355.6mm to prevent overflow */
}

/* Sheet Header */
.sheet__header {
    border-bottom: 2px solid #000;
    margin-bottom: 12px;
    padding-bottom: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.sheet__brand {
    display: flex;
    align-items: center;
    gap: 16px;
}

.sheet__title {
    font-size: 24px;
    font-weight: 800;
    color: #000 !important;
    margin: 0;
    font-family: var(--font-ui);
}

.sheet__logo {
    height: 48px;
    width: auto;
    object-fit: contain;
}

.sheet__meta {
    display: grid;
    grid-template-columns: auto auto;
    gap: 8px 24px;
    align-items: center;
}

.meta-item:nth-child(1) {
    grid-column: 1 / -1;
    justify-self: end;
}

.meta-item {
    display: flex;
    align-items: baseline;
    gap: 8px;
    font-family: var(--font-ui);
    font-size: 14px;
    font-weight: 500;
    color: #000 !important;
    flex-shrink: 0;
}

.meta-line {
    width: 100px;
    min-width: 100px;
    height: 1em;
    border-bottom: 1px solid #000 !important;
    display: inline-block;
    flex-shrink: 0;
}

.meta-line.long { 
    width: 300px;
    min-width: 300px;
}

/* Sheet Footer */
.sheet__footer {
    margin-top: auto; /* Push to bottom in flex container */
    text-align: center;
    font-size: 10px;
    color: #999 !important;
    padding-top: 10px;
    border-top: 1px solid #eee;
    text-transform: uppercase;
    letter-spacing: 1px;
    flex-shrink: 0;
}

/* Sheet Grid - takes remaining space */
.sheet__grid {
    flex: 1 0 auto;
}

/* ============================================
   PRINT STYLES
   ============================================
   
   STRATEGY: Keep it simple
   - Screen styles already make .sheet look like paper
   - Print just: hides UI, removes shadows, ensures page fit
   - JS injects @page { size: A4/letter } dynamically
   
   ============================================ */

@media print {
    /* Page setup - size comes from JS injection */
    @page { margin: 0; }

    /* Preserve colors exactly as shown on screen */
    * {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
        color-adjust: exact !important;
    }

    /* ---- HIDE UI ELEMENTS ---- */
    .panel,
    .stage__toolbar,
    .mobile-only,
    .footer-toggle,
    .theme-toggle-btn,
    .btn,
    .btn-mini,
    aside,
    nav {
        display: none !important;
    }

    /* ---- LAYOUT RESET ---- */
    html, body {
        margin: 0 !important;
        padding: 0 !important;
        background: white !important;
    }

    /* Flatten container hierarchy - sheets flow directly */
    .app,
    .stage,
    .stage__content {
        display: contents !important;
    }

    .sheets-wrapper,
    #sheets-container {
        display: block !important;
        margin: 0 !important;
        padding: 0 !important;
        background: transparent !important;
    }

    /* ---- THE SHEET (PAPER) ----
       Each sheet = exactly one printed page
       Inherits flex layout from screen styles */
    .sheet {
        /* Page dimensions - MATCH SCREEN EXACTLY */
        width: var(--paper-width) !important;
        height: var(--paper-height) !important;
        min-height: var(--paper-height) !important;
        max-height: var(--paper-height) !important;
        
        /* Spacing - match screen padding ratio */
        padding: 12mm !important;
        margin: 0 !important;
        
        /* Clean print appearance */
        box-shadow: none !important;
        border: none !important;
        border-radius: 0 !important;
        
        /* Page breaks */
        page-break-after: always !important;
        page-break-inside: avoid !important;
        
        /* Clip any overflow */
        overflow: hidden !important;
    }

    /* Last sheet: no trailing blank page */
    .sheet:last-child {
        page-break-after: avoid !important;
    }

    /* ---- SHEET CONTENT ---- */
    
    /* Grid fills available space and spreads content */
    .sheet__grid {
        flex: 1 1 auto !important;
        min-height: 0 !important;
        overflow: hidden !important;
        align-content: space-between !important;
        height: 100% !important;
    }

    /* Footer stays at bottom */
    .sheet__footer {
        display: none !important;
    }

    /* Answers in red */
    .problem--solved .problem__answer,
    .problem--solved .comparison-box,
    .answer {
        color: #d93025 !important;
    }

    /* Prevent problems from breaking across pages */
    .problem {
        break-inside: avoid !important;
    }
}

/* ============================================
   RESPONSIVE - Mobile First
   ============================================ */
@media (max-width: 1024px) {
    :root {
        --sidebar-width: 100%;
    }

    .mobile-only { display: flex; }

    body {
        height: auto;
        overflow: auto;
    }

    .app {
        grid-template-columns: 1fr;
        height: auto;
        min-height: 100vh;
    }

    .panel {
        height: auto;
        max-height: none;
        border-right: none;
        border-bottom: 1px solid var(--c-border);
        overflow: visible;
    }

    /* Hide panel content and footer by default on mobile */
    .panel > .panel__content,
    .panel > .panel__footer { 
        display: none !important; 
    }

    /* Show panel content and footer when panel is open */
    .panel.open > .panel__content { 
        display: block !important; 
    }
    
    .panel.open > .panel__footer { 
        display: flex !important;
        flex-direction: column;
    }
    
    /* Visual feedback for mobile toggle button when panel is open */
    .panel.open .mobile-only {
        background: var(--c-primary);
        color: #fff;
    }
    
    .mobile-only {
        transition: background 0.2s ease, color 0.2s ease, transform 0.2s ease;
    }
    
    .mobile-only:active {
        transform: scale(0.9);
    }

    .panel__header {
        position: sticky;
        top: 0;
        z-index: 20;
    }

    .panel__content {
        overflow-y: visible;
        padding: var(--space-lg);
        min-height: auto;
    }

    .panel__footer {
        position: relative;
        box-shadow: none;
        padding: var(--space-lg);
    }

    .stage {
        height: auto;
        min-height: 60vh;
        padding-bottom: var(--space-xl);
    }

    .stage__toolbar {
        padding: 0 var(--space-md);
        justify-content: center;
        height: 48px;
    }

    .stage__content {
        padding: var(--space-md);
        overflow-x: hidden;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Mobile sheet container - scale to fit screen width */
    .sheets-wrapper {
        width: 100%;
        max-width: 100%;
        padding: var(--space-sm);
        display: flex;
        flex-direction: column;
        align-items: center;
    }

    /* Scale sheet to fit mobile screen */
    .sheet {
        /* Use viewport-based width that fits within screen */
        width: calc(100vw - 32px);
        max-width: 100%;
        min-width: auto;
        height: auto;
        min-height: auto;
        /* Maintain paper aspect ratio */
        aspect-ratio: 210 / 297;
        margin-bottom: var(--space-lg);
        padding: 4%;
        /* Ensure content is readable */
        font-size: clamp(8px, 2vw, 14px);
        transform-origin: top center;
        box-sizing: border-box;
    }
    
    .sheet__logo {
        height: clamp(16px, 4vw, 32px);
    }

    .sheet__title {
        font-size: clamp(12px, 3vw, 20px);
    }

    .meta-item {
        font-size: clamp(8px, 2vw, 12px);
    }

    .meta-line {
        width: clamp(40px, 12vw, 80px);
        min-width: auto;
    }

    .meta-line.long {
        width: clamp(80px, 25vw, 200px);
        min-width: auto;
    }

    .sheet__meta {
        gap: var(--space-sm);
    }

    /* No scroll hint needed - sheet fits screen */
    .stage__content::before {
        display: none;
    }
}

/* Tablet - medium scaled sheet */
@media (max-width: 900px) and (min-width: 601px) {
    .sheet {
        width: calc(100vw - 48px);
        max-width: 500px;
        padding: 5%;
        font-size: clamp(10px, 2.2vw, 16px);
    }
    
    .sheet__logo {
        height: clamp(20px, 4vw, 36px);
    }

    .sheet__title {
        font-size: clamp(14px, 3.5vw, 22px);
    }
    
    .meta-line {
        width: clamp(50px, 10vw, 80px);
    }
    
    .meta-line.long {
        width: clamp(120px, 25vw, 220px);
    }
}

@media (max-width: 600px) {
    .panel__content {
        padding: var(--space-md);
    }

    .toggle-grid {
        grid-template-columns: 1fr 1fr;
        gap: var(--space-xs);
    }

    .panel__title {
        font-size: 12px;
    }

    .panel__header {
        padding: 0 var(--space-md);
        gap: var(--space-sm);
        height: 56px;
    }

    .panel__nav-btn {
        width: 36px;
        height: 36px;
    }

    .panel__action-btn {
        width: 32px;
        height: 32px;
    }

    .panel__action-btn .material-icons-round {
        font-size: 18px;
    }

    .control-group {
        margin-bottom: var(--space-lg);
        padding-bottom: var(--space-lg);
    }

    .toggle-btn {
        padding: var(--space-sm) var(--space-xs);
        font-size: 11px;
    }

    .toggle-icon {
        font-size: 18px;
    }

    /* Phone-optimized sheet - fits screen without scrolling */
    .sheet {
        width: calc(100vw - 24px);
        max-width: 100%;
        min-width: auto;
        padding: 3%;
        font-size: clamp(6px, 1.8vw, 12px);
    }

    .sheet__header {
        padding-bottom: 2px;
        margin-bottom: 4px;
        border-bottom-width: 1px;
    }

    .sheet__logo {
        height: clamp(12px, 3.5vw, 24px);
    }

    .sheet__title {
        font-size: clamp(10px, 2.8vw, 16px);
    }

    .sheet__brand {
        gap: 8px;
    }

    .sheet__meta {
        flex-wrap: wrap;
        gap: 4px 8px;
    }

    .meta-item {
        font-size: clamp(6px, 1.6vw, 10px);
    }

    .meta-line {
        width: clamp(30px, 10vw, 60px);
        min-width: auto;
    }

    .meta-line.long {
        width: clamp(60px, 20vw, 140px);
        min-width: auto;
    }

    .sheet__footer {
        font-size: clamp(6px, 1.5vw, 10px);
        padding-top: 4px;
    }

    .btn {
        padding: var(--space-md) var(--space-lg);
        font-size: 13px;
    }

    .footer-toggle {
        padding: var(--space-sm) var(--space-md);
        font-size: 12px;
    }
}

/* ============================================
   UTILITY CLASSES
   ============================================ */

/* Visibility */
.hidden { display: none !important; }
.sr-only { 
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

/* ============================================
   MODIFIER CLASSES
   ============================================ */

/* Footer toggle variants */
.footer-toggle--transparent {
    background: transparent;
    border: none;
    padding: 0;
}

/* Switch variants */
.switch--small {
    transform: scale(0.85);
    transform-origin: right center;
}

/* Control sublabel variants */
.control-sublabel--inline {
    margin: 0;
}

/* Toggle grid variants */
.toggle-grid--2col {
    grid-template-columns: 1fr 1fr;
}

.toggle-grid--3col {
    grid-template-columns: 1fr 1fr 1fr;
}

/* Spacing utilities */
.mt-xs { margin-top: var(--space-xs); }
.mt-sm { margin-top: var(--space-sm); }
.mt-md { margin-top: var(--space-md); }
.mt-lg { margin-top: var(--space-lg); }
.mt-xl { margin-top: var(--space-xl); }

.mb-xs { margin-bottom: var(--space-xs); }
.mb-sm { margin-bottom: var(--space-sm); }
.mb-md { margin-bottom: var(--space-md); }
.mb-lg { margin-bottom: var(--space-lg); }
.mb-xl { margin-bottom: var(--space-xl); }
.mb-0 { margin-bottom: 0; }

/* Icon size utilities */
.icon-sm { font-size: 16px !important; }
.icon-md { font-size: 20px !important; }
.icon-lg { font-size: 24px !important; }

/* Text utilities */
.text-muted { color: var(--c-text-muted) !important; }
.text-primary { color: var(--c-primary) !important; }
.text-success { color: var(--c-success) !important; }
.text-warning { color: var(--c-warning) !important; }
.text-error { color: var(--c-error) !important; }

/* Flex utilities */
.flex { display: flex !important; }
.flex-1 { flex: 1 !important; }
.items-center { align-items: center !important; }
.justify-between { justify-content: space-between !important; }
.gap-xs { gap: var(--space-xs) !important; }
.gap-sm { gap: var(--space-sm) !important; }
.gap-md { gap: var(--space-md) !important; }
