* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --accent: #0a84ff;
    --safe-area-inset-bottom: env(safe-area-inset-bottom);
}

html {
    height: 100%;
    overflow: hidden; /* Re-enable for adaptive height */
}
body {
    height: 100%; /* Ensure body also takes full height */
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', Roboto, 'PingFang SC', 'Microsoft YaHei', sans-serif;
    background: transparent; /* Make body transparent to see particles */
    display: flex; /* Use flexbox for vertical layout */
    flex-direction: column;
    padding: 10px; /* Overall padding around the container */
    /* Adjust padding-bottom for new quick-insert-bar height */
    padding-bottom: calc(10px + 52px + var(--safe-area-inset-bottom)); 
}

/* Particle background canvas */
#particles-js {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    background-color: #f5f5f7; /* Default light background */
}

/* 回到顶部按钮样式 */
.back-to-top {
    position: fixed;
    bottom: calc(10px + 52px + 20px + var(--safe-area-inset-bottom)); /* Above quick-insert-bar + gap */
    right: 20px;
}
.container {
    max-width: 640px;
    width: 100%;
    margin: 0 auto;
    background: rgba(255, 255, 255, 0.85); /* Semi-transparent background */
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.1);
    border: 1px solid rgba(255, 255, 255, 0.5);

    /* Flexbox for container children */
    display: flex;
    flex-direction: column;
    flex-grow: 1; /* Allow container to grow to fill available space */
    overflow: hidden; /* Important to contain content-section scrolling */
}

.header {
    background: transparent; /* Inherit glass effect */
    color: #1d1d1f;
    padding: 15px 20px 10px 20px; /* Reduced padding */
    text-align: center;
    border-bottom: 1px solid rgba(60,60,67,0.12);
    flex-shrink: 0; /* Prevent header from shrinking */
}

.header h1 {
    font-size: 22px; /* Slightly smaller h1 */
    margin-bottom: 0; /* No subtitle anymore */
    font-weight: 700;
}

.header h1 .grad {
    background: linear-gradient(135deg, var(--accent) 0%, #34c759 100%);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.header p { 
    color: #6e6e73; 
    font-size: 13px; 
}

/* New wrapper for sticky top controls */
.top-controls-wrapper {
    flex-shrink: 0; /* Prevent from shrinking */
    position: sticky; /* Make the whole wrapper sticky */
    top: 0;
    z-index: 20;
    background: rgba(255,255,255,0.7);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid rgba(60,60,67,0.12);
}

.style-selector {
    padding: 4px 0; /* Reduced padding */
}

.theme-buttons {
    display: flex;
    gap: 10px;
    padding: 4px 15px;
    overflow-x: auto;
    -ms-overflow-style: none; /* IE and Edge */
    scrollbar-width: none;  /* Firefox */
}

.theme-buttons::-webkit-scrollbar {
  display: none; /* Chrome, Safari, Opera */
}

.theme-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 6px;
    border-radius: 12px;
    transition: background-color 0.2s ease;
    flex-shrink: 0;
}

.theme-btn:hover {
    background: #f0f0f0;
}

.theme-swatch {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 2px solid #fff;
    box-shadow: 0 0 0 1px rgba(0,0,0,0.1), inset 0 1px 2px rgba(0,0,0,0.1);
}

.theme-name {
    font-size: 11px;
    font-weight: 500;
    color: #3a3a3c;
}

.theme-btn.active .theme-swatch {
    box-shadow: 0 0 0 2px var(--accent);
}

.theme-btn.active .theme-name {
    color: var(--accent);
    font-weight: 600;
}

.toolbar {
    display: flex;
    gap: 10px; /* Increased gap slightly */
    padding: 10px 15px;
    flex-wrap: nowrap;
    justify-content: flex-start; /* Align left for scrolling */
    overflow-x: auto;
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
    -ms-overflow-style: none;
    scrollbar-width: none;
}

.toolbar::-webkit-scrollbar {
  display: none;
}

.btn {
    padding: 0 16px; /* Horizontal padding */
    height: 38px; /* Fixed height */
    border: none;
    border-radius: 19px; /* Full pill shape */
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    flex: 0 0 auto; /* Don't shrink, allow scroll */
    box-shadow: none; /* Remove heavy shadow */
    white-space: nowrap;
    background: #F2F2F7; /* Default Grey */
    color: #1d1d1f;
}

.btn:active { 
    transform: scale(0.96); 
    opacity: 0.8;
}

/* Primary Action: Format (Solid Black) */
.btn-primary {
    background: #000000;
    color: #ffffff;
}
.btn-primary:hover {
    background: #333333;
}

/* Secondary Action: Undo (Light Grey) */
.btn-secondary {
    background: #E5E5EA;
    color: #000000;
}
.btn-secondary:hover {
    background: #D1D1D6;
}

/* Success Action: Copy (Solid Emerald) */
.btn-success {
    background: #10B981;
    color: #ffffff;
}
.btn-success:hover {
    background: #059669;
}

/* Info Action: Preview (Solid Blue) */
.btn-info {
    background: #007AFF;
    color: #ffffff;
}
.btn-info:hover {
    background: #0062cc;
}

/* Warning Action: Clear (Solid Red) */
.btn-warning {
    background: #FF3B30;
    color: #ffffff;
}
.btn-warning:hover {
    background: #d93025;
}

/* AI Buttons */
.btn-ai-score {
    background: #f59e0b;
    color: #ffffff;
}
.btn-ai-score:hover {
    background: #d97706;
}
.btn-ai-human {
    background: #14b8a6;
    color: #ffffff;
}
.btn-ai-human:hover {
    background: #0f766e;
}

.btn.busy {
    opacity: 0.7;
    pointer-events: none;
    cursor: wait;
}

/* Dark Mode Adjustments for Buttons */
@media (prefers-color-scheme: dark) {
    .btn-primary {
        background: #ffffff;
        color: #000000;
    }
    .btn-primary:hover {
        background: #e5e5e5;
    }
    
    .btn-secondary {
        background: #3a3a3c;
        color: #ffffff;
    }
    .btn-secondary:hover {
        background: #48484a;
    }

    .btn-success {
        background: #34c759; /* Slightly brighter green for dark mode */
    }
    
    .btn-info {
        background: #0a84ff; /* Brighter blue */
    }
    
    .btn-warning {
        background: #ff453a; /* Brighter red */
    }
}

.content-section {
    padding: 15px;
    position: relative;
    flex-grow: 1; /* Allow content section to grow and take remaining space */
    display: flex;
    flex-direction: column;
    overflow: hidden; /* Contain editor/preview scrolling */
}

.editor {
    width: 100%;
    flex-grow: 1; /* Allow editor to grow within content-section */
    min-height: 0; /* Important for flex items to allow shrinking */
    border: 1px solid rgba(60,60,67,0.24);
    border-radius: 12px;
    outline: none;
    font-family: inherit;
    font-size: 16px;
    line-height: 1.6;
    padding: 15px;
    resize: none; /* Disable vertical resize, flexbox handles height */
    background: transparent; /* Inherit glass effect */
    transition: all 0.3s ease;
    overflow-y: auto; /* Allow internal scrolling */
    overscroll-behavior: contain;
    color: #1d1d1f;
}

.editor:focus { 
    border-color: var(--accent); 
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent); 
}

.editor.hidden {
    display: none;
}

.preview-content {
    line-height: 1.8;
    color: #333;
    background: transparent; /* Inherit glass effect */
    padding: 15px;
    border: 1px solid rgba(60,60,67,0.24);
    border-radius: 12px;
    flex-grow: 1; /* Allow preview to grow within content-section */
    min-height: 0; /* Important for flex items to allow shrinking */
    overflow-x: auto;
    overflow-y: auto; /* Allow internal scrolling */
    overscroll-behavior: contain;
    display: none;
    transition: all 0.3s ease;
}

.preview-content.show { 
    display: block; 
    border-color: var(--accent); 
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent); 
}

/* 底部快捷插入工具栏 */
.quick-insert-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    gap: 8px;
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-top: 1px solid rgba(60,60,67,0.15);
    padding: 8px 15px; /* Reduced padding */
    padding-bottom: calc(8px + var(--safe-area-inset-bottom)); /* Reduced padding */
    flex-wrap: nowrap;
    overflow-x: auto;
    z-index: 100;
    -ms-overflow-style: none; /* IE and Edge */
    scrollbar-width: none;  /* Firefox */
}

.typing-mode .quick-insert-bar {
    top: 0;
    bottom: auto;
    border-top: none;
    border-bottom: 1px solid rgba(60,60,67,0.15);
    box-shadow: 0 6px 20px rgba(0,0,0,0.08);
}

.typing-mode .content-section {
    padding-top: calc(70px + env(safe-area-inset-top, 0px));
}

.quick-insert-bar::-webkit-scrollbar {
  display: none; /* Chrome, Safari, Opera */
}

.quick-btn {
    padding: 8px 14px; /* Reduced padding */
    background: #e9e9eb;
    border: none;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    color: #1d1d1f;
    touch-action: manipulation;
    flex: 0 0 auto;
    min-height: 36px; /* Reduced height */
}

.quick-btn:active { 
    background: var(--accent); 
    color: #fff; 
    transform: scale(0.95); 
}

.success-message {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(-100px);
    background: #34c759;
    color: white;
    padding: 12px 20px;
    border-radius: 25px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    transition: transform 0.3s ease;
    z-index: 1001;
    font-size: 14px;
    font-weight: 500;
}

.success-message.show {
    transform: translateX(-50%) translateY(0);
}

/* Modal */
.modal {
    position: fixed;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(0, 0, 0, 0.45);
    z-index: 1005;
}
.modal.show {
    display: flex;
}
.modal__content {
    width: 100%;
    max-width: 520px;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 16px;
    box-shadow: 0 18px 40px rgba(0,0,0,0.18);
    border: 1px solid rgba(255, 255, 255, 0.6);
    padding: 18px 18px 14px 18px;
}
.modal__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 10px;
}
.modal__title {
    font-size: 16px;
    font-weight: 700;
    color: #111827;
}
.modal__close {
    border: none;
    background: #111827;
    color: #ffffff;
    border-radius: 10px;
    padding: 6px 12px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}
.modal__close:active {
    transform: scale(0.98);
}
.modal__body {
    white-space: pre-wrap;
    color: #1f2937;
    font-size: 14px;
    line-height: 1.7;
    max-height: 60vh;
    overflow-y: auto;
    padding-right: 4px;
}
.modal__body h1,
.modal__body h2,
.modal__body h3 {
    margin: 12px 0 8px;
    font-size: 16px;
    font-weight: 700;
    color: inherit;
}
.modal__body p {
    margin: 8px 0;
}
.modal__body ul,
.modal__body ol {
    margin: 8px 0 8px 18px;
}
.modal__body li {
    margin: 4px 0;
}
.modal__body strong {
    color: inherit;
    font-weight: 700;
}
.modal__body em {
    font-style: italic;
}

.upload-progress {
    position: fixed;
    top: 70px;
    left: 50%;
    transform: translateX(-50%);
    width: 320px;
    max-width: 90%;
    background: rgba(0,0,0,0.82);
    color: #fff;
    padding: 12px 14px;
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.25);
    display: none;
    z-index: 1002;
}
.upload-progress.show {
    display: block;
}
.upload-progress__label {
    font-size: 14px;
    margin-bottom: 8px;
    font-weight: 600;
    letter-spacing: 0.2px;
}
.upload-progress__bar {
    width: 100%;
    height: 8px;
    background: rgba(255,255,255,0.16);
    border-radius: 6px;
    overflow: hidden;
}
.upload-progress__fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(135deg, #4ade80, #22c55e);
    transition: width 0.2s ease;
    border-radius: 6px;
}

.hidden-copy-area {
    position: absolute;
    left: -9999px;
    opacity: 0;
}

/* ===========================
   Auth Page
   =========================== */
.hidden {
    display: none !important;
}

body.auth-page {
    background: #f3f4f6;
    padding: 24px;
}

.auth-container {
    max-width: 420px;
    margin: 0 auto;
    padding: 24px;
    background: #ffffff;
    border-radius: 16px;
    box-shadow: 0 18px 40px rgba(0, 0, 0, 0.08);
    border: 1px solid rgba(0, 0, 0, 0.05);
}

.auth-container .header {
    border-bottom: none;
    padding: 0 0 12px 0;
}

.auth-container .header h1 {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-size: 22px;
}

.auth-container .header h1 .grad {
    background: linear-gradient(135deg, #0a84ff 0%, #34c759 100%);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.auth-container .header p {
    color: #6b7280;
    margin-top: 6px;
    font-size: 14px;
}

.auth-body {
    margin-top: 4px;
}

.auth-tabs {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    background: #f5f7fb;
    padding: 6px;
    border-radius: 10px;
}

.auth-tab {
    border: none;
    background: transparent;
    padding: 10px 12px;
    border-radius: 8px;
    font-weight: 600;
    color: #4b5563;
    cursor: pointer;
    transition: all 0.2s ease;
}

.auth-tab.active {
    background: linear-gradient(135deg, #0a84ff 0%, #34c759 100%);
    color: #ffffff;
    box-shadow: 0 8px 18px rgba(10, 132, 255, 0.18);
}

.auth-form {
    margin-top: 16px;
    display: grid;
    gap: 12px;
}

.auth-form .input-group {
    display: grid;
    gap: 6px;
}

.auth-form label {
    font-size: 14px;
    color: #374151;
    font-weight: 600;
}

.auth-form input {
    width: 100%;
    padding: 12px 14px;
    border-radius: 10px;
    border: 1px solid #e5e7eb;
    background: #f9fafb;
    transition: all 0.2s ease;
    font-size: 14px;
}

.auth-form input:focus {
    outline: none;
    border-color: #0a84ff;
    box-shadow: 0 0 0 4px rgba(10, 132, 255, 0.15);
    background: #ffffff;
}

.auth-message {
    margin-top: 12px;
    padding: 10px 12px;
    border-radius: 10px;
    font-size: 14px;
    display: none;
}

.auth-message.success {
    display: block;
    background: #ecfdf3;
    color: #166534;
    border: 1px solid #bbf7d0;
}

.auth-message.error {
    display: block;
    background: #fef2f2;
    color: #991b1b;
    border: 1px solid #fecdd3;
}

.auth-submit {
    width: 100%;
    padding: 12px 14px;
    border-radius: 10px;
    border: none;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.08);
}

.auth-submit.btn-primary {
    background: linear-gradient(135deg, #0a84ff 0%, #4f9eff 100%);
    color: #fff;
}

.auth-submit.btn-success {
    background: linear-gradient(135deg, #34c759 0%, #2bbf52 100%);
    color: #fff;
}

.auth-submit:disabled {
    opacity: 0.7;
    cursor: not-allowed;
    box-shadow: none;
}

.invite-hint {
    font-size: 13px;
    color: #6b7280;
    display: flex;
    align-items: center;
    gap: 8px;
}

.invite-hint span::before {
    content: '📮';
    margin-right: 6px;
}

.mode-indicator {
    position: absolute;
    top: 0;
    right: 15px;
    background: var(--accent);
    color: #fff;
    padding: 4px 8px;
    border-radius: 0 0 8px 8px;
    font-size: 12px;
    font-weight: 500;
    display: none;
    z-index: 5;
}

.mode-indicator.show {
    display: block;
}

/* 通用预览样式 */
.preview-content ul, .preview-content ol { margin: 10px 0; padding: 0 0 0 25px; }
.preview-content li { margin: 6px 0; line-height: 1.8; color: #333; }
.preview-content a { color: #0a84ff; text-decoration: none; border-bottom: 1px solid rgba(10,132,255,0.2); }
.preview-content img { 
    display: block;
    max-width: 100%; 
    height: auto; 
    margin: 12px auto; 
    border-radius: 8px; 
}
.preview-content hr { height: 1px; border: none; margin: 20px 0; background: #e9ecef; }
.preview-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 14px 0;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    overflow: hidden;
}
.preview-content th,
.preview-content td {
    padding: 10px 12px;
    border: 1px solid #e5e7eb;
    text-align: left;
    line-height: 1.8;
}
.preview-content th {
    background: #f8fafc;
    font-weight: 700;
    color: #111;
}
.preview-content tr:nth-child(even) td {
    background: #fbfdff;
}
.preview-content del { color: #999; }
.preview-content code {
    font-family: 'SF Mono', 'Menlo', 'monospace';
    background: #f2f2f7;
    padding: 2px 5px;
    border-radius: 5px;
    font-size: 0.9em;
}
.preview-content pre {
    background: #f2f2f7;
    padding: 12px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 12px 0;
}
.preview-content pre code {
    background: transparent;
    padding: 0;
}
.preview-content blockquote {
    border-left: 3px solid var(--accent);
    padding-left: 15px;
    margin: 12px 0;
    color: #555;
}

/* ================================== */
/*         Preview Focus Mode         */
/* ================================== */
body.preview-focused {
    padding: 0 !important; /* Remove all body padding */
}
body.preview-focused .header,
body.preview-focused .style-selector,
body.preview-focused .quick-insert-bar,
body.preview-focused .back-to-top,
body.preview-focused .toolbar .hide-on-preview {
    display: none;
}
body.preview-focused .container {
    max-width: 100%;
    width: 100%; /* Ensure full width */
    margin: 0; /* Remove auto margins */
    border-radius: 0;
    box-shadow: none;
    border: none; /* Remove border */
}
body.preview-focused .toolbar {
    justify-content: flex-end; /* Push remaining buttons to the right */
    background: rgba(255, 255, 255, 0.95); /* Ensure toolbar is visible */
}
body.preview-focused .content-section {
    padding: 0; /* Remove content section padding */
}
body.preview-focused .preview-content.show {
    border-radius: 0;
    border: none;
}

/* Typing mode: hide top controls to maximize editing space */
body.typing-mode .header,
body.typing-mode .top-controls-wrapper {
    display: none !important;
}
body.typing-mode .container {
    max-width: 100%;
    width: 100%;
    margin-top: 0;
}

.typing-exit-btn {
    position: fixed;
    bottom: 70px;
    right: 16px;
    z-index: 100;
    padding: 10px 14px;
    border: none;
    border-radius: 10px;
    background: linear-gradient(135deg, #0a84ff 0%, #34c759 100%);
    color: #fff;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.12);
    display: none;
}

body.typing-mode .typing-exit-btn {
    display: block;
}

/* ================================== */
/*           Dark Mode Styles         */
/* ================================== */
@media (prefers-color-scheme: dark) {
    :root {
        --accent-dark: #0a84ff; /* Accent can often stay the same or be slightly brighter */
    }

    body {
        background: transparent; /* Keep body transparent */
    }

    #particles-js {
        background-color: #000; /* Dark background for particles canvas */
    }

    .container {
        background: rgba(28, 28, 30, 0.85); /* Semi-transparent background */
        backdrop-filter: blur(10px);
        -webkit-backdrop-filter: blur(10px);
        border-color: rgba(84,84,88,0.65);
    }

    .header {
        background: transparent; /* Inherit glass effect */
        color: #f5f5f7;
        border-bottom-color: rgba(84,84,88,0.65);
    }

    .header p {
        color: #8e8e93;
    }

    /* Sticky top bar with blur effect */
    .top-controls-wrapper {
        background: rgba(28,28,30,0.7);
        border-bottom-color: rgba(84,84,88,0.65);
    }
    
    .style-selector,
    .toolbar {
        border-bottom-color: rgba(84,84,88,0.65);
    }

    .theme-btn:hover {
        background: #2c2c2e;
    }

    .theme-swatch {
        border-color: #3a3a3c;
        box-shadow: 0 0 0 1px rgba(0,0,0,0.2), inset 0 1px 2px rgba(0,0,0,0.2);
    }

    .theme-name {
        color: #aeaeb2;
    }

    .theme-btn.active .theme-name {
        color: var(--accent-dark);
    }
    
    .btn-secondary {
        background: #3a3a3c;
        color: #f5f5f7;
        border-color: rgba(84,84,88,0.65);
    }

    .editor,
    .preview-content {
        background: transparent; /* Inherit glass effect */
        color: #f5f5f7;
        border-color: rgba(84,84,88,0.65);
    }
    
    .editor:focus,
    .preview-content.show { 
        border-color: var(--accent-dark); 
        box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent-dark) 20%, transparent); 
    }

    /* Bottom quick insert bar */
    .quick-insert-bar {
        background: rgba(28,28,30,0.8);
        border-top-color: rgba(84,84,88,0.65);
    }

    .quick-btn {
        background: #3a3a3c;
        color: #f5f5f7;
    }
    
    .quick-btn:active { 
        background: var(--accent-dark); 
        color: #fff;
    }

    /* Preview content specific styles */
    .preview-content ul, 
    .preview-content ol,
    .preview-content li {
        color: #f5f5f7;
    }

    .preview-content a {
        color: var(--accent-dark);
        border-bottom-color: rgba(10,132,255,0.4);
    }

    .preview-content hr {
        background: rgba(84,84,88,0.65);
    }

    .preview-content del {
        color: #8e8e93;
    }

    .preview-content code {
        color: #f5f5f7;
        background: #2c2c2e;
    }

    .preview-content pre {
        background: #2c2c2e;
    }

    .preview-content blockquote {
        border-left-color: var(--accent-dark);
        color: #aeaeb2;
    }

    .preview-content table {
        border-color: rgba(84,84,88,0.65);
        background: #1c1c1e;
    }
    .preview-content th,
    .preview-content td {
        border-color: rgba(84,84,88,0.65);
        color: #f5f5f7;
    }
    .preview-content th {
        background: #2c2c2e;
    }
    .preview-content tr:nth-child(even) td {
        background: #1f1f21;
    }

    .modal__content {
        background: rgba(28, 28, 30, 0.95);
        border-color: rgba(84,84,88,0.65);
    }
    .modal__title {
        color: #f5f5f7;
    }
    .modal__body {
        color: #e5e7eb;
    }
    .modal__close {
        background: #f5f5f7;
        color: #111827;
    }
}

/* ================================== */
/*           Mobile Optimization      */
/* ================================== */
@media (max-width: 600px) {
    body {
        padding: 0;
        padding-bottom: calc(50px + var(--safe-area-inset-bottom));
    }

    .container {
        border-radius: 0;
        border: none;
        box-shadow: none;
        background: rgba(255, 255, 255, 0.98); /* More solid on mobile */
    }

    /* Compact Header */
    .header {
        padding: 10px 15px 5px 15px;
    }
    .header h1 {
        font-size: 18px;
    }

    /* Sticky Controls */
    .top-controls-wrapper {
        background: rgba(255,255,255,0.95);
        backdrop-filter: blur(15px);
        -webkit-backdrop-filter: blur(15px);
    }

    /* Scrollable Toolbars */
    .style-selector, 
    .toolbar {
        padding: 5px 10px;
    }
    
    .theme-buttons {
        gap: 8px;
    }
    
    .theme-btn {
        padding: 4px;
    }
    
    .theme-swatch {
        width: 24px;
        height: 24px;
    }

    .btn {
        padding: 8px 12px;
        font-size: 13px;
        min-height: 36px;
    }

    /* Editor Area */
    .content-section {
        padding: 10px;
    }

    .editor, 
    .preview-content {
        padding: 12px;
        font-size: 16px; /* Prevent iOS zoom on focus */
        border-radius: 8px;
    }

    /* Scrollable Toolbars */
    .style-selector, 
    .toolbar {
        padding: 5px 10px;
    }
    
    .toolbar {
        justify-content: flex-start; /* Align left to allow scroll */
    }

    .btn {
        padding: 8px 12px;
        font-size: 14px;
        min-height: 36px;
        white-space: nowrap; /* Prevent text wrap */
        flex: 0 0 auto; /* Prevent shrinking */
    }

    /* Bottom Bar */
    .quick-insert-bar {
        padding: 8px 12px;
        padding-bottom: calc(8px + var(--safe-area-inset-bottom));
        background: rgba(255, 255, 255, 0.98);
        border-top: 1px solid rgba(0,0,0,0.08);
        box-shadow: 0 -4px 10px rgba(0,0,0,0.03);
        gap: 10px;
    }
    
    .quick-btn {
        padding: 6px 12px;
        font-size: 13px;
        min-height: 34px;
        border-radius: 18px; /* Pill shape */
        background: #f2f2f7;
        flex: 0 0 auto;
    }
    
    .quick-btn:active {
        background: var(--accent);
        transform: scale(0.96);
    }

    /* Adjust Back to Top */
    .back-to-top {
        bottom: calc(60px + var(--safe-area-inset-bottom));
        right: 15px;
        width: 40px;
        height: 40px;
        line-height: 40px;
        font-size: 18px;
    }
}

@media (max-width: 360px) {
    .btn {
        padding: 8px 8px;
        font-size: 12px;
    }
    .header h1 {
        font-size: 16px;
    }
}

@media (max-width: 600px) and (prefers-color-scheme: dark) {
    .container {
        background: rgba(28, 28, 30, 0.98);
    }
    .top-controls-wrapper {
        background: rgba(28,28,30,0.95);
    }
    .quick-insert-bar {
        background: rgba(28,28,30,0.95);
        border-top: 1px solid rgba(255,255,255,0.1);
    }
}
