/* Font Loading Styles */
@font-face {
    font-family: 'Tiempos Headline';
    src: url('https://cdn.msar.me/fonts/Tiempos/TiemposHeadlineWeb-Regular.woff2') format('woff2'),
         url('https://cdn.msar.me/fonts/Tiempos/TiemposHeadlineWeb-Regular.woff') format('woff');
    font-weight: 400;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'Tiempos Headline';
    src: url('https://cdn.msar.me/fonts/Tiempos/TiemposHeadlineWeb-Semibold.woff2') format('woff2'),
         url('https://cdn.msar.me/fonts/Tiempos/TiemposHeadlineWeb-Semibold.woff') format('woff');
    font-weight: 600;
    font-style: normal;
    font-display: swap;
}

/* CSS Variables for consistent theming */
:root {
    /* Light theme colors */
    --bg-primary: #faf9f6;
    --bg-secondary: #ffffff;
    --bg-tertiary: #f8f7f4;
    --bg-quaternary: #f0efeb;
    --text-primary: #2c2a27;
    --text-secondary: #5a5651;
    --text-tertiary: #a8a5a0;
    --border-primary: #e5e3df;
    --border-secondary: #d4d1cc;
    --accent-primary: #6b5b73;
    --accent-secondary: #524459;
    --success: #4ade80;
    --error: #e74c3c;
    --warning: #f1c232;
    
    /* Layout values */
    --header-height: 73px;
    --sidebar-width: 320px;
    --border-radius: 6px;
    --border-radius-sm: 4px;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.15);
}

/* Dark theme overrides */
body.dark {
    --bg-primary: #1a1a1a;
    --bg-secondary: #2d2d2d;
    --bg-tertiary: #3a3a3a;
    --bg-quaternary: #4a4a4a;
    --text-primary: #e8e6e3;
    --text-secondary: #b8b5b2;
    --text-tertiary: #666;
    --border-primary: #404040;
    --border-secondary: #555;
    --accent-primary: #9b8bc7;
    --accent-secondary: #b8a6d1;
    --success: #4ade80;
    --error: #e74c3c;
    --warning: #d4a42a;
}

/* Global Styles */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

body, .editor, .preview, input, button, textarea, select {
    font-family: "Crimson Text", "Times New Roman", "SimSun", "Songti SC", "宋体", "STSong", serif;
}

body {
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    height: 100vh;
    overflow: hidden;
    font-kerning: normal;
    font-variant-ligatures: common-ligatures;
    font-feature-settings: "kern" 1;
    -webkit-overflow-scrolling: touch;
    min-height: 100vh;
    position: relative;
}

/* Layout Components */
.header {
    background-color: var(--bg-secondary);
    border-bottom: 1px solid var(--border-primary);
    padding: 16px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: var(--shadow-sm);
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 200;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    min-height: var(--header-height);
    padding-top: max(16px, env(safe-area-inset-top));
}

.header-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.header h1 {
    font-size: 20px;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: -0.5px;
    line-height: 1.2;
    height: 24px;
    display: flex;
    align-items: center;
}

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

/* Button Styles */
.btn, .menu-btn, .settings-btn, .new-file-btn, .export-option-btn, 
.option-btn, .close-btn, .close-sidebar-btn, .recent-file-btn {
    border: 1px solid var(--border-secondary);
    background: var(--bg-secondary);
    color: var(--text-primary);
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    font-family: inherit;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
}

.btn {
    padding: 8px 16px;
    font-size: 14px;
    gap: 6px;
    min-height: 36px;
    line-height: 1.2;
}

.menu-btn {
    background: none;
    border: none;
    font-size: 18px;
    padding: 8px;
    width: 36px;
    height: 36px;
}

.btn:hover:not(:disabled), .menu-btn:hover, .settings-btn:hover:not(:disabled) {
    background: var(--bg-tertiary);
    border-color: var(--border-secondary);
}

.btn.primary, .new-file-btn {
    background: var(--text-primary);
    color: var(--bg-primary);
    border-color: var(--text-primary);
}


.btn:disabled {
    background: var(--bg-quaternary);
    color: var(--text-tertiary);
    border-color: var(--border-primary);
    cursor: not-allowed;
}

.btn-danger {
    background: var(--error);
    color: white;
    border-color: var(--error);
}


.btn i {
    font-size: 13px;
    flex-shrink: 0;
}

/* Main Content */
.main-content {
    display: flex;
    height: calc(100vh - var(--header-height) - env(safe-area-inset-top));
    margin-top: calc(var(--header-height) + env(safe-area-inset-top));
    -webkit-overflow-scrolling: touch;
    position: relative;
    z-index: 1;
}

.container {
    flex: 1;
    display: flex;
}

.editor-panel, .preview-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.editor-panel {
    border-right: 1px solid var(--border-primary);
    background: var(--bg-secondary);
}

.panel-header {
    padding: 12px 24px;
    border-bottom: 1px solid var(--border-primary);
    background: var(--bg-tertiary);
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
    line-height: 1.2;
    height: 41px;
    display: flex;
    align-items: center;
}

.editor {
    flex: 1;
    border: none;
    outline: none;
    resize: none;
    padding: 24px;
    font-family: inherit;
    line-height: 1.8;
    color: var(--text-primary);
    background: var(--bg-secondary);
}

.preview {
    flex: 1;
    padding: 24px;
    overflow-y: auto;
    background: var(--bg-primary);
    line-height: 1.8;
    box-sizing: border-box;
}

/* Preview Content Styles */
.preview h1, .preview h2, .preview h3, .preview h4, .preview h5, .preview h6 {
    color: var(--text-primary);
    margin: 1.5em 0 0.75em 0;
    font-weight: 600;
    line-height: 1.3;
}

.preview h1:first-child, .preview h2:first-child, .preview h3:first-child, 
.preview h4:first-child, .preview h5:first-child, .preview h6:first-child {
    margin-top: 0;
}

.preview h1 { font-size: 2em; }
.preview h2 { font-size: 1.5em; }
.preview h3 { font-size: 1.25em; }
.preview h4 { font-size: 1.1em; }
.preview h5 { font-size: 1em; }
.preview h6 { font-size: 0.9em; }

.preview p {
    margin: 1em 0;
    text-align: justify;
}

.preview p:first-child,
.preview ul:first-child,
.preview ol:first-child,
.preview blockquote:first-child,
.preview pre:first-child {
    margin-top: 0;
}

.preview ul, .preview ol {
    margin: 1em 0;
    padding-left: 2em;
}

.preview li {
    margin: 0.5em 0;
}

.preview blockquote {
    border-left: 4px solid var(--border-secondary);
    padding-left: 1em;
    margin: 1em 0;
    color: var(--text-secondary);
    font-style: italic;
}

.preview code {
    background: var(--bg-quaternary);
    border: 1px solid var(--border-primary);
    border-radius: 3px;
    padding: 2px 6px;
    font-family: "Courier New", monospace;
    font-size: 0.9em;
}

.preview kbd {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-secondary);
    border-radius: 3px;
    padding: 1px 4px;
    font-family: "Courier New", monospace;
    font-size: 0.75em;
    font-weight: 500;
    color: var(--text-primary);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1), inset 0 1px 0 rgba(255, 255, 255, 0.3);
    border-bottom-width: 1.5px;
    display: inline-block;
    vertical-align: baseline;
    line-height: 1.2;
}

.preview pre {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-primary);
    border-radius: var(--border-radius);
    padding: 0;
    margin: 1em 0;
    overflow-x: auto;
}

.preview pre code {
    background: none;
    border: none;
    padding: 16px;
    display: block;
}

/* Code highlighting styles */
.preview pre {
    position: relative;
}

.preview pre code.hljs {
    display: block;
    overflow-x: auto;
    padding: 16px;
    background: var(--bg-secondary) !important;
    color: var(--text-primary) !important;
    border: none;
    border-radius: 0;
    font-size: 0.875em;
    line-height: 1.5;
}

/* Override highlight.js default colors for light theme */
:root:not(.dark) .preview .hljs-keyword,
:root:not(.dark) .preview .hljs-selector-tag,
:root:not(.dark) .preview .hljs-literal,
:root:not(.dark) .preview .hljs-type {
    color: #d73a49;
}

:root:not(.dark) .preview .hljs-string,
:root:not(.dark) .preview .hljs-doctag {
    color: #032f62;
}

:root:not(.dark) .preview .hljs-title,
:root:not(.dark) .preview .hljs-section,
:root:not(.dark) .preview .hljs-selector-id {
    color: #6f42c1;
}

:root:not(.dark) .preview .hljs-comment,
:root:not(.dark) .preview .hljs-quote {
    color: #6a737d;
    font-style: italic;
}

:root:not(.dark) .preview .hljs-number {
    color: #005cc5;
}

:root:not(.dark) .preview .hljs-variable,
:root:not(.dark) .preview .hljs-template-variable,
:root:not(.dark) .preview .hljs-attribute {
    color: #e36209;
}

/* Override highlight.js default colors for dark theme */
body.dark .preview .hljs-keyword,
body.dark .preview .hljs-selector-tag,
body.dark .preview .hljs-literal,
body.dark .preview .hljs-type {
    color: #ff7b72 !important;
}

body.dark .preview .hljs-string,
body.dark .preview .hljs-doctag {
    color: #a5c9ea !important;
}

body.dark .preview .hljs-title,
body.dark .preview .hljs-section,
body.dark .preview .hljs-selector-id {
    color: #d2a8ff !important;
}

body.dark .preview .hljs-comment,
body.dark .preview .hljs-quote {
    color: #8b949e !important;
    font-style: italic;
}

body.dark .preview .hljs-number {
    color: #79c0ff !important;
}

body.dark .preview .hljs-variable,
body.dark .preview .hljs-template-variable,
body.dark .preview .hljs-attribute {
    color: #ffa657 !important;
}

body.dark .preview .hljs-function,
body.dark .preview .hljs-params {
    color: #d2a8ff !important;
}

body.dark .preview .hljs-built_in,
body.dark .preview .hljs-class {
    color: #ffa657 !important;
}

body.dark .preview .hljs-meta {
    color: #79c0ff !important;
}

body.dark .preview .hljs-tag {
    color: #7ee787 !important;
}

body.dark .preview .hljs-name {
    color: #7ee787 !important;
}

body.dark .preview .hljs-attr {
    color: #79c0ff !important;
}

/* Ensure proper text color in dark mode */
body.dark .preview pre code.hljs {
    background: var(--bg-secondary) !important;
    color: #e6edf3 !important;
}

/* Code highlighting styles are now handled by external CSS themes with custom overrides */
/* Light theme: github.min.css + custom light overrides */
/* Dark theme: github-dark.min.css + custom dark overrides */

.preview table {
    border-collapse: collapse;
    width: 100%;
    margin: 1em 0;
}

.preview th, .preview td {
    border: 1px solid var(--border-primary);
    padding: 8px 12px;
    text-align: left;
}

.preview th {
    background: var(--bg-tertiary);
    font-weight: 600;
}

.preview a {
    color: var(--accent-primary);
    text-decoration: underline;
}

.preview a:hover {
    color: var(--accent-secondary);
}

.preview hr {
    border: none;
    border-top: 1px solid var(--border-primary);
    margin: 2em 0;
}

.preview img {
    max-width: 100%;
    height: auto;
    margin: 1em 0;
    border-radius: var(--border-radius);
}

/* Footnote Styles */
.preview .footnotes-separator {
    margin: 2em 0 1em 0;
    border: none;
    border-top: 2px solid var(--border-primary);
}

.preview .footnotes-section {
    margin-top: 1em;
}

.preview .footnote {
    padding: 0.5em 0;
    margin: 0.5em 0;
    font-size: 0.9em;
    color: var(--text-secondary);
    line-height: 1.5;
    position: relative;
    padding-left: 2em;
}

.preview .footnote > p:first-of-type {
    display: inline;
    margin: 0;
}

.preview .footnote > p:not(:first-of-type) {
    margin: 0.5em 0;
}

.preview .footnote > pre {
    margin: 0.5em 0;
}

.preview .footnote > *:last-child {
    margin-bottom: 0;
}

.preview .footnote sup {
    font-weight: 600;
    color: var(--text-primary);
    position: absolute;
    left: 0;
    top: 0.5em;
}

.preview .footnote-backref, .preview .footnote-ref {
    margin-left: 0.5em;
    text-decoration: none;
    color: var(--warning);
    font-weight: 600;
    display: inline;
}

.preview .footnote-backref:hover, .preview .footnote-ref:hover {
    text-decoration: underline;
}

.preview sup {
    vertical-align: super;
    font-size: 0.75em;
    line-height: 0;
}

.footnote-highlight {
    background-color: #fff3cd !important;
}

/* Dark theme footnote highlight */
body.dark .footnote-highlight {
    background-color: #4a4a00 !important;
}

/* Details and Summary Styles */
.preview details {
    border: 1px solid var(--border-primary);
    border-radius: var(--border-radius);
    margin: 1em 0;
    background: var(--bg-primary);
}

.preview details[open] {
    box-shadow: var(--shadow-sm);
}

.preview details summary {
    padding: 12px 16px;
    background: var(--bg-tertiary);
    border-radius: var(--border-radius) var(--border-radius) 0 0;
    cursor: pointer;
    font-weight: 600;
    color: var(--text-primary);
    user-select: none;
    outline: none;
    position: relative;
    list-style: none;
}

.preview details[open] summary {
    border-radius: var(--border-radius) var(--border-radius) 0 0;
    border-bottom: 1px solid var(--border-primary);
    margin-bottom: 0;
}

.preview details summary:hover {
    background: var(--bg-quaternary);
}

.preview details summary:focus {
    box-shadow: 0 0 0 2px var(--accent-primary);
}

.preview details summary::marker,
.preview details summary::-webkit-details-marker {
    display: none;
}

.preview details summary::before {
    content: '▶';
    display: inline-block;
    margin-right: 8px;
    font-size: 0.8em;
    color: var(--accent-primary);
}


.preview details > *:not(summary) {
    padding: 12px 16px;
    margin: 0;
}

.preview details > ul,
.preview details > ol {
    padding: 12px 16px 12px 40px;
    margin: 0;
}

.preview details ul li,
.preview details ol li {
    margin: 0.3em 0;
    line-height: 1.5;
}

.preview details > blockquote {
    padding: 12px 16px;
    margin: 8px 0;
    border-left: 4px solid var(--border-secondary);
}

.preview details blockquote {
    margin: 8px 0 !important;
}

.preview details > pre {
    padding: 12px 16px;
    margin: 0;
}

.preview details > p:first-of-type {
    margin-top: 0;
}

.preview details > p:last-child,
.preview details > ul:last-child,
.preview details > ol:last-child,
.preview details > blockquote:last-child,
.preview details > pre:last-child {
    margin-bottom: 0;
}

/* Sidebar */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-primary);
    display: flex;
    flex-direction: column;
    z-index: 150;
    box-shadow: 2px 0 8px rgba(0, 0, 0, 0.1);
}


.sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    visibility: hidden;
    z-index: 100;
}

.sidebar-overlay.active {
    visibility: visible;
}

.sidebar-header {
    padding: 24px 20px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.sidebar-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
    line-height: 1.2;
    height: 22px;
    display: flex;
    align-items: center;
}

.close-sidebar-btn {
    background: none;
    border: none;
    font-size: 18px;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 4px;
    border-radius: var(--border-radius-sm);
}

.close-sidebar-btn:hover {
    color: var(--text-primary);
    background: var(--bg-tertiary);
}

.sidebar-content {
    flex: 1;
    padding: 16px 20px 24px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.sidebar-section {
    margin-bottom: 32px;
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

.sidebar-section:last-child {
    margin-bottom: 0;
}

.sidebar-section-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 16px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    line-height: 1.2;
    height: 17px;
    display: flex;
    align-items: center;
}

.sidebar-footer {
    border-top: 1px solid var(--border-primary);
    padding: 20px;
}

.settings-btn {
    width: 100%;
    padding: 12px 16px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-primary);
    border-radius: 8px;
    cursor: pointer;
    font-family: inherit;
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 48px;
    line-height: 1.2;
    justify-content: flex-start;
    margin-bottom: 12px;
}

.settings-btn:last-child {
    margin-bottom: 0;
}

.new-file-btn {
    width: 100%;
    padding: 12px 16px;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 600;
    gap: 12px;
    min-height: 48px;
    line-height: 1.2;
    justify-content: flex-start;
    margin-bottom: 16px;
}

.new-file-icon, .settings-icon {
    font-size: 16px;
    width: 16px;
    text-align: center;
    flex-shrink: 0;
}

.settings-icon {
    color: var(--text-secondary);
}

.new-file-icon {
    color: var(--bg-primary);
}

/* Recent Files */
.recent-files-list {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
}

.recent-file-item {
    display: flex;
    align-items: center;
    padding: 8px 12px;
    margin-bottom: 4px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-primary);
    border-radius: var(--border-radius);
    cursor: pointer;
    position: relative;
}

.recent-file-item:hover {
    background: var(--bg-quaternary);
    border-color: var(--border-secondary);
}

.recent-file-item:last-child {
    margin-bottom: 0;
}

.recent-file-info {
    flex: 1;
    min-width: 0;
}

.recent-file-title {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.recent-file-meta {
    font-size: 11px;
    color: var(--text-secondary);
    display: flex;
    gap: 8px;
}

.recent-file-actions {
    display: flex;
    gap: 4px;
}


.recent-file-btn {
    width: 20px;
    height: 20px;
    border: none;
    background: none;
    cursor: pointer;
    border-radius: 3px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    color: var(--text-secondary);
}

.recent-file-btn:hover {
    background: var(--border-secondary);
    color: var(--text-primary);
}

.recent-file-btn.delete:hover {
    background: var(--error);
    color: white;
}

.no-recent-files {
    text-align: center;
    color: var(--text-tertiary);
    font-size: 13px;
    padding: 20px 12px;
    font-style: italic;
}

/* Modal Styles */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

#language-error-modal {
    z-index: 10000;
}


.modal-panel {
    background: var(--bg-secondary);
    border-radius: 12px;
    box-shadow: var(--shadow-md);
    width: 90%;
    max-width: 480px;
    max-height: 85vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}


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

.modal-header h2 {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
    line-height: 1.2;
    height: 22px;
    display: flex;
    align-items: center;
}

.close-btn {
    background: none;
    border: none;
    font-size: 18px;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 4px;
    border-radius: var(--border-radius-sm);
}

.close-btn:hover {
    color: var(--text-primary);
    background: var(--bg-tertiary);
}

.modal-body {
    padding: 24px;
    position: relative;
    flex: 1;
    overflow-y: auto;
    min-height: 0;
}

/* Settings */
.setting-group {
    margin-bottom: 24px;
}

.setting-group:has(.toggle-switch-container) {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.setting-group:has(.setting-options),
.setting-group:has(.font-size-slider) {
    display: block;
}

.setting-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
    line-height: 1.2;
    height: 24px;
}

.setting-group:has(.setting-options) .setting-label,
.setting-group:has(.font-size-slider) .setting-label {
    margin-bottom: 8px;
    flex: none;
}

.setting-group:has(.toggle-switch-container) .setting-label {
    flex: 1;
    margin-bottom: 0;
}

.setting-label i {
    font-size: 13px;
    color: var(--text-secondary);
    flex-shrink: 0;
}

.setting-options {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.option-btn {
    padding: 8px 16px;
    font-size: 14px;
    min-height: 36px;
    line-height: 1.2;
    vertical-align: middle;
}

.option-btn:hover {
    background: var(--bg-tertiary);
}

.option-btn.active {
    background: var(--text-primary);
    color: var(--bg-primary);
    border-color: var(--text-primary);
}

.font-size-slider {
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: var(--border-primary);
    outline: none;
    appearance: none;
    cursor: pointer;
}

.font-size-slider::-webkit-slider-thumb {
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--text-primary);
    cursor: pointer;
}

.font-size-slider::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--text-primary);
    cursor: pointer;
    border: none;
}

.font-size-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 8px;
    font-size: 12px;
    color: var(--text-secondary);
}

.setting-buttons {
    display: flex;
    gap: 12px;
}

.setting-btn-half {
    flex: 1;
    width: auto !important;
}

.confirm-modal .modal-panel {
    max-width: 400px;
}

.confirm-modal .modal-body {
    text-align: center;
    padding: 32px 24px 24px;
}

.confirm-modal .modal-message {
    font-size: 16px;
    color: var(--text-primary);
    margin-bottom: 24px;
}

.confirm-modal .modal-buttons {
    display: flex;
    gap: 12px;
    justify-content: center;
}

.link-url-container {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-primary);
    border-radius: 6px;
    padding: 12px;
    margin: 12px 0;
    word-break: break-all;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 14px;
    color: var(--text-primary);
    text-align: left;
    max-height: 120px;
    overflow-y: auto;
    min-height: 40px;
    display: flex;
    align-items: center;
}

.link-url-container #link-url {
    width: 100%;
    line-height: 1.4;
}

/* Export Options */
.export-options {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 24px;
}

.export-option-btn {
    width: 100%;
    padding: 16px 20px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-primary);
    border-radius: 8px;
    cursor: pointer;
    font-family: inherit;
    font-size: 15px;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 12px;
    text-align: left;
}

.export-option-btn:hover {
    background: var(--bg-quaternary);
    border-color: var(--border-secondary);
}

.export-option-btn i {
    font-size: 18px;
    color: var(--text-secondary);
    width: 20px;
    text-align: center;
    flex-shrink: 0;
}

/* Copyright */
.copyright-info {
    text-align: center;
    font-size: 12px;
    color: var(--text-tertiary);
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border-primary);
}

/* Toast */
.toast {
    position: fixed;
    top: 80px;
    right: 24px;
    background: var(--text-primary);
    color: var(--bg-primary);
    padding: 12px 20px;
    border-radius: 8px;
    box-shadow: var(--shadow-md);
    font-size: 14px;
    font-weight: 500;
    z-index: 1000;
    pointer-events: none;
    display: flex;
    align-items: center;
    gap: 8px;
}


.toast-icon {
    font-size: 16px;
    color: var(--success);
}

/* Loading Overlays */
.initial-loading-overlay, .language-loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
}

.initial-loading-overlay {
    z-index: 99999;
}

.language-loading-overlay {
    z-index: 9999;
    display: none;
}

.initial-loading-overlay.hide {
    pointer-events: none;
}


.language-loading-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 24px;
}

.language-loading-spinner {
    position: relative;
    display: inline-block;
    width: 60px;
    height: 60px;
}

.spinner-ring {
    box-sizing: border-box;
    display: block;
    position: absolute;
    width: 48px;
    height: 48px;
    margin: 6px;
    border: 3px solid #ffffff;
    border-radius: 50%;
    animation: spinner-ring 1.2s cubic-bezier(0.5, 0, 0.5, 1) infinite;
    border-color: #ffffff transparent transparent transparent;
}

.spinner-ring:nth-child(1) { animation-delay: -0.45s; }
.spinner-ring:nth-child(2) { animation-delay: -0.3s; }
.spinner-ring:nth-child(3) { animation-delay: -0.15s; }

@keyframes spinner-ring {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.language-loading-text {
    color: #ffffff;
    font-size: 16px;
    font-weight: 500;
    letter-spacing: 0.5px;
    text-align: center;
    animation: loading-text-pulse 1.5s ease-in-out infinite;
}

@keyframes loading-text-pulse {
    0%, 100% { opacity: 0.7; }
    50% { opacity: 1; }
}

/* Desktop Toolbar */
.desktop-toolbar {
    position: relative;
    display: none;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-primary);
    font-size: 13px;
    flex-wrap: wrap;
    overflow-x: auto;
    overflow-y: hidden;
}

/* Mobile Toolbar */
.mobile-toolbar {
    position: relative;
    display: none;
    align-items: center;
    justify-content: space-between;
    gap: 4px;
    padding: 8px 12px;
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-primary);
    font-size: 13px;
    flex-wrap: nowrap;
    overflow: hidden;
}

.desktop-toolbar::-webkit-scrollbar {
    height: 6px;
}

.desktop-toolbar::-webkit-scrollbar-track {
    background: var(--bg-quaternary);
    border-radius: 3px;
}

.desktop-toolbar::-webkit-scrollbar-thumb {
    background: var(--border-secondary);
    border-radius: 3px;
}

.desktop-toolbar::-webkit-scrollbar-thumb:hover {
    background: var(--text-tertiary);
}

.desktop-toolbar.show {
    display: flex;
}

.desktop-toolbar.hidden {
    display: none;
}

.mobile-toolbar.show {
    display: flex;
}

.mobile-toolbar.hidden {
    display: none;
}

.toolbar-group {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 0 8px;
    border-right: 1px solid var(--border-secondary);
    flex-shrink: 0;
}

.toolbar-group:last-child {
    border-right: none;
}

.toolbar-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 6px;
    border-radius: var(--border-radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    color: var(--text-primary);
}

.toolbar-btn:hover {
    background: var(--border-primary);
}

.toolbar-btn i {
    font-size: 14px;
}

.toolbar-text {
    font-size: 10px;
    font-weight: 600;
    margin-left: 2px;
}

/* Mobile Toolbar Buttons */
.mobile-toolbar-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    border-radius: var(--border-radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    color: var(--text-primary);
    flex-shrink: 0;
}

.mobile-toolbar-btn:hover {
    background: var(--border-primary);
}

.mobile-toolbar-btn i {
    font-size: 14px;
}

.mobile-btn-text {
    font-size: 14px;
    font-weight: 600;
}


/* Settings Tabs */
.settings-tabs {
    position: relative;
    margin-bottom: 24px;
}

.tab-nav {
    display: flex;
    background: var(--bg-quaternary);
    border-radius: 8px;
    padding: 6px;
    gap: 4px;
    position: relative;
}

.tab-btn {
    flex-grow: 1;
    flex-shrink: 1;
    flex-basis: 0;
    padding: 10px 8px;
    background: none;
    border: none;
    cursor: pointer;
    font-family: inherit;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
    border-radius: var(--border-radius);
    position: relative;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    white-space: nowrap;
    overflow: hidden;
}

.tab-btn.active {
    color: var(--text-primary);
}

.tab-btn i {
    font-size: 13px;
}

.tab-slider {
    position: absolute;
    top: 6px;
    left: 6px;
    width: calc((100% - 12px - 8px) / 3);
    height: calc(100% - 12px);
    background: var(--bg-secondary);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-sm);
    z-index: 1;
}

.tab-content-container {
    overflow: hidden;
    width: 100%;
}

.tab-content-slider {
    display: flex;
    width: 300%;
}

.tab-content {
    width: 33.333%;
    padding: 24px 4px 0;
    flex-shrink: 0;
}


/* Toggle Switch */
.toggle-switch-container {
    display: flex;
    align-items: center;
}

.toggle-switch {
    width: 44px;
    height: 24px;
    background: var(--border-secondary);
    border-radius: 12px;
    cursor: pointer;
    position: relative;
}

.toggle-slider {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 20px;
    height: 20px;
    background: var(--bg-secondary);
    border-radius: 50%;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}


.toggle-switch.active {
    background: var(--text-primary);
}

/* Hide mobile-only elements on desktop */
.mobile-actions {
    display: none;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    :root {
        --header-height: 65px;
        --sidebar-width: 280px;
    }
    
    body {
        height: 100vh;
        height: -webkit-fill-available;
        min-height: 100vh;
        min-height: -webkit-fill-available;
    }
    
    .header {
        padding: 12px 16px;
        min-height: var(--header-height);
        padding-top: max(12px, env(safe-area-inset-top));
        position: fixed;
        top: 0;
    }
    
    .main-content {
        height: calc(100vh - var(--header-height) - env(safe-area-inset-top) - env(safe-area-inset-bottom));
        height: calc(-webkit-fill-available - var(--header-height) - env(safe-area-inset-top) - env(safe-area-inset-bottom));
        margin-top: calc(var(--header-height) + env(safe-area-inset-top));
        position: relative;
        overflow: hidden;
    }
    
    .container {
        flex-direction: column;
        height: 100%;
        -webkit-overflow-scrolling: touch;
    }
    
    .editor-panel {
        border-right: none;
        border-bottom: 1px solid var(--border-primary);
        -webkit-overflow-scrolling: touch;
    }
    
    .editor-panel, .preview-panel {
        flex: none;
        height: 50%;
        min-height: 0;
        position: relative;
    }
    
    .editor, .preview {
        -webkit-overflow-scrolling: touch;
        position: relative;
        touch-action: pan-y;
        overscroll-behavior: contain;
        overflow-y: auto;
    }

    .sidebar {
        width: var(--sidebar-width);
        -webkit-overflow-scrolling: touch;
        top: env(safe-area-inset-top);
        bottom: env(safe-area-inset-bottom);
        height: calc(100vh - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    }
    
    .sidebar-footer {
        padding-bottom: max(20px, env(safe-area-inset-bottom) + 60px);
    }

    .btn-mobile-hidden {
        display: none !important;
    }

    .mobile-actions {
        display: none !important;
    }

    .desktop-toolbar {
        display: none !important;
    }

    .mobile-toolbar {
        display: none;
    }

    .mobile-toolbar.show {
        display: flex !important;
    }

    .mobile-toolbar.hidden {
        display: none !important;
    }

    .toolbar-group {
        flex-shrink: 0 !important;
        gap: 4px;
        display: inline-flex !important;
    }

    .toolbar-btn {
        flex-shrink: 0 !important;
        white-space: nowrap;
    }

    .btn {
        padding: 6px 10px;
        font-size: 12px;
        min-height: 30px;
        min-width: 44px;
    }

    .btn i {
        font-size: 11px;
    }
    
    .header h1 {
        font-size: 18px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    
    .menu-btn {
        width: 32px;
        height: 32px;
        font-size: 16px;
    }

    .mobile-actions {
        display: block !important;
        margin-bottom: 12px;
    }
    
    .tab-nav {
        padding: 5px;
        gap: 3px;
        border-radius: 10px;
    }
    
    .tab-btn {
        padding: 10px 4px;
        font-size: 13px;
        gap: 4px;
        flex-grow: 1;
        flex-shrink: 1;
        flex-basis: 0;
        height: 44px;
        min-height: 44px;
    }
    
    .tab-btn i {
        font-size: 12px;
        width: 12px;
    }
    
    .tab-btn span {
        font-size: 12px;
        text-overflow: ellipsis;
        overflow: hidden;
        white-space: nowrap;
    }
    
    .tab-slider {
        width: calc((100% - 10px - 6px) / 3);
        top: 5px;
        left: 5px;
        height: calc(100% - 10px);
    }
}

/* Safari specific fixes */
@supports (-webkit-touch-callout: none) {
    .tab-btn {
        display: -webkit-flex;
        -webkit-align-items: center;
        -webkit-justify-content: center;
        -webkit-flex: 1;
        min-width: 0;
    }
    
    .tab-btn i {
        -webkit-font-smoothing: antialiased;
    }
    
    .tab-nav {
        display: -webkit-flex;
        -webkit-flex-direction: row;
    }
    
    .header {
        position: -webkit-sticky;
        position: sticky;
        top: 0;
    }
    
    .main-content {
        height: calc(100vh - var(--header-height));
        margin-top: 0;
    }
    
    @media (max-width: 768px) {
        .main-content {
            height: calc(100vh - var(--header-height));
        }
        
        .sidebar-footer {
            padding-bottom: max(20px, 80px);
        }
    }
}