:root {
    --user-font: 'Times New Roman', Times, serif;
    --user-font-size: 16px;
    --user-line-height: 1.4;
    --user-letter-spacing: 0px;
    --border-color: #e2e8f0;
    --tab-bar-bg: #f8fafc;
    --tab-bg: #e2e8f0;
    --tab-active-bg: #ffffff;
    --card-bg: #ffffff;
    --text-color: #0f172a;
    --muted-text: #64748b;
    --primary-slate: #1e293b;
    --primary-slate-hover: #0f172a;
    --accent-blue: #3b82f6;
}

* {
    box-sizing: border-box;
}

body {
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    margin: 0;
    padding: 0 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    background-color: #ffffff;
    color: var(--text-color);
    min-height: 100vh;
}

/* Minimal Top Header (Note Title Only) */
.top-title-bar {
    width: 100%;
    max-width: 850px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: 20px;
    margin-bottom: 12px;
}

.single-file-title {
    font-size: 20px;
    font-weight: 700;
    cursor: pointer;
    user-select: none;
    padding: 4px 10px;
    border: 1px transparent solid;
    border-radius: 6px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: #0f172a;
    text-align: center;
}

.single-file-title:hover {
    background-color: #f1f5f9;
}

.single-file-title-input {
    font-size: 20px;
    font-weight: 700;
    padding: 4px 8px;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    outline: none;
    font-family: inherit;
    color: #0f172a;
    text-align: center;
}

/* Workspace Container (Max Width 850px) */
.workspace-container {
    width: 100%;
    max-width: 850px;
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
}

.editor-wrapper {
    width: 100%;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    position: relative;
    resize: both;
    overflow: hidden;
    background: var(--card-bg);
    margin: 0 auto;
    align-self: center;
    max-width: 100%;
    box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.04);
}

.editor-wrapper.hide-border {
    border: none !important;
    box-shadow: none !important;
}

.editor-content {
    width: 100%;
    height: 100%;
    border: none;
    outline: none;
    padding: 24px;
    overflow-y: auto;
    white-space: pre-wrap;
    word-wrap: break-word;
    color: inherit;
    font-family: var(--user-font);
    font-size: var(--user-font-size);
    line-height: var(--user-line-height);
    letter-spacing: var(--user-letter-spacing);
}

.editor-content div {
    min-height: 1.4em; 
    min-height: calc(var(--user-font-size) * var(--user-line-height));
}

/* Controls Bar Below Workspace Container */
.bottom-controls-bar {
    width: 100%;
    max-width: 850px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 16px;
}

.controls-group-left {
    display: flex;
    align-items: center;
    flex: 1;
}

.controls-group-center {
    display: flex;
    align-items: center;
    gap: 8px;
    justify-content: center;
}

.controls-group-right {
    display: flex;
    align-items: center;
    gap: 10px;
    justify-content: flex-end;
    flex: 1;
}

.folder-btn {
    background: #f1f5f9;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: #64748b;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.folder-btn:hover {
    background: #e2e8f0;
    color: #0f172a;
}

.icon-nav-btn {
    background: #f1f5f9;
    border: 1px solid #e2e8f0;
    font-size: 15px;
    font-weight: 600;
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    cursor: pointer;
    color: #64748b;
    transition: all 0.2s;
}

.icon-nav-btn:hover {
    background: #e2e8f0;
    color: #0f172a;
}

.icon-btn {
    padding: 6px 10px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.secondary-btn {
    background-color: #ffffff;
    border: 1px solid #cbd5e1;
    padding: 8px 16px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    color: #334155;
    border-radius: 8px;
    transition: all 0.2s;
}

.secondary-btn:hover {
    background-color: #f8fafc;
    border-color: #94a3b8;
}

.primary-btn {
    background-color: var(--primary-slate);
    border: 1px solid var(--primary-slate);
    padding: 8px 16px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    color: #ffffff;
    border-radius: 8px;
    transition: all 0.2s;
}

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

/* Tab Bar */
.tab-bar-wrapper {
    display: none;
    width: 100%;
    background: var(--tab-bar-bg);
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    align-items: center;
    padding: 8px 12px;
    margin-top: 14px;
    gap: 8px;
    position: relative;
    user-select: none;
}

.tab-nav-btn {
    background: transparent;
    border: none;
    padding: 6px 10px;
    font-size: 16px;
    cursor: pointer;
    color: var(--muted-text);
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 32px;
}

.tab-nav-btn:hover {
    background: rgba(0, 0, 0, 0.04);
    color: var(--text-color);
}

.tabs-scroll-area {
    display: flex;
    align-items: center;
    gap: 6px;
    overflow-x: auto;
    scroll-behavior: smooth;
    flex-grow: 1;
    scrollbar-width: none;
    padding: 2px 0;
}

.tabs-scroll-area::-webkit-scrollbar {
    display: none;
}

.tab {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 6px 14px;
    background: var(--tab-bg);
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    min-width: 120px;
    max-width: 180px;
    white-space: nowrap;
    transition: all 0.15s ease;
}

.tab:hover {
    background: #e2e8f0;
}

.tab.active {
    background: var(--tab-active-bg);
    border-color: #cbd5e1;
    font-weight: 600;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.tab-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex-grow: 1;
}

.tab-close {
    font-size: 14px;
    opacity: 0.6;
    cursor: pointer;
    border-radius: 50%;
    width: 18px;
    height: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.tab-close:hover {
    opacity: 1;
    background: #ef4444;
    color: white;
}

.tab-list-popover {
    display: none;
    position: absolute;
    bottom: 50px;
    right: 10px;
    background: var(--card-bg);
    border: 1px solid #cbd5e1;
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.15);
    border-radius: 6px;
    max-height: 250px;
    overflow-y: auto;
    z-index: 100;
    width: 240px;
    padding: 6px;
    font-size: 13px;
}

.tab-list-popover.show {
    display: block;
}

.tab-list-item {
    padding: 8px 10px;
    cursor: pointer;
    border-radius: 4px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tab-list-item:hover {
    background: #f1f5f9;
}

.tab-list-item.active {
    font-weight: bold;
    color: var(--primary-slate);
    background: #eff6ff;
}

/* KaTeX Rendered Formula Nodes */
.katex-rendered-node {
    display: inline-block;
    background: transparent;
    border: none;
    border-radius: 0;
    padding: 0;
    margin: 0 2px;
    cursor: pointer;
    user-select: none;
    vertical-align: middle;
    transition: opacity 0.15s;
}

.katex-rendered-node:hover {
    opacity: 0.85;
}

/* Modals */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(3px);
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal {
    background: white;
    padding: 24px;
    border: 1px solid #e2e8f0;
    width: 90%;
    max-width: 500px;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
    max-height: 85vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    border-radius: 12px;
}

.modal h2 {
    margin-top: 0;
    margin-bottom: 16px;
    font-size: 18px;
    font-weight: 700;
}

.typography-body {
    font-size: 13px;
    line-height: 1.6;
    color: var(--text-color);
}

.form-group {
    margin-bottom: 14px;
    display: flex;
    flex-direction: column;
}

.form-group label {
    font-size: 13px;
    font-weight: 500;
    margin-bottom: 6px;
}

.form-group input[type="number"],
.form-group select,
.form-group input[type="text"] {
    padding: 8px 12px;
    font-size: 14px;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    outline: none;
}

.checkbox-group {
    flex-direction: row;
    align-items: center;
    gap: 10px;
}

.checkbox-group label {
    margin-bottom: 0;
    cursor: pointer;
}

.modal-buttons {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
}

.cancel-btn {
    background-color: #ffffff;
    border: 1px solid #cbd5e1;
    padding: 8px 16px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    color: #475569;
    border-radius: 6px;
    transition: background 0.15s;
}

.cancel-btn:hover {
    background-color: #f8fafc;
}

.save-btn {
    background-color: var(--primary-slate);
    border: 1px solid var(--primary-slate);
    padding: 8px 16px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    color: #ffffff;
    border-radius: 6px;
    transition: background 0.15s;
}

.save-btn:hover {
    background-color: var(--primary-slate-hover);
}

.install-link {
    font-size: 13px;
    color: #2563eb;
    text-decoration: none;
    font-weight: 600;
}

.install-link:hover {
    text-decoration: underline;
}

.files-action-btn {
    background-color: #ffffff;
    border: 1px solid #cbd5e1;
    padding: 8px 14px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    color: #334155;
    border-radius: 6px;
    transition: all 0.2s;
}

.files-action-btn:hover {
    background-color: #f1f5f9;
}

/* Pagination Controls */
.pagination-controls {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 12px;
    margin-top: 14px;
}

.pagination-controls button {
    background-color: #ffffff;
    border: 1px solid #cbd5e1;
    padding: 6px 14px;
    font-size: 12px;
    font-weight: 500;
    border-radius: 6px;
    cursor: pointer;
    color: #334155;
    transition: all 0.15s;
}

.pagination-controls button:hover:not(:disabled) {
    background-color: #f1f5f9;
}

.pagination-controls button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* File List & Items */
.file-list {
    overflow-y: auto;
    flex-grow: 1;
    border: 1px solid #e2e8f0;
    padding: 6px;
    margin-top: 10px;
    min-height: 220px;
    border-radius: 6px;
}

.file-item {
    padding: 10px;
    border-bottom: 1px solid #f1f5f9;
    cursor: pointer;
    border-radius: 4px;
}

.file-item:hover {
    background-color: #f8fafc;
}

.trash-icon-svg {
    width: 16px;
    height: 16px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    cursor: pointer;
    color: var(--muted-text);
    transition: color 0.15s;
}

.trash-icon-svg:hover {
    color: #ef4444;
}

mark.highlight {
    background-color: #fde047;
    color: black;
    font-weight: bold;
    padding: 0 2px;
    border-radius: 2px;
}

.counters {
    font-size: 13px;
    color: var(--muted-text);
    margin-top: 14px;
    text-align: center;
    display: none;
}

/* Timer & Stopwatch Controls */
.time-tools-layout {
    display: flex;
    gap: 16px;
    justify-content: center;
    width: 100%;
    max-width: 850px;
    flex-wrap: wrap;
    margin-top: 16px;
}

.tool-widget {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    padding: 14px;
    border-radius: 10px;
    text-align: center;
    min-width: 200px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

.tool-header {
    font-size: 11px;
    font-weight: 700;
    margin-bottom: 6px;
    color: var(--muted-text);
}

.tool-display {
    font-size: 24px;
    font-weight: 700;
    font-family: monospace;
    margin-bottom: 10px;
}

.editable-time {
    outline: none;
    border-bottom: 1px dashed var(--muted-text);
}

.editable-time:focus {
    border-bottom-color: var(--accent-blue);
}

.tool-actions {
    display: flex;
    gap: 8px;
    justify-content: center;
}

.tool-btn-primary {
    background-color: var(--primary-slate);
    border: 1px solid var(--primary-slate);
    color: white;
    padding: 5px 14px;
    font-size: 12px;
    font-weight: 600;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.15s;
}

.tool-btn-primary:hover {
    background-color: var(--primary-slate-hover);
}

.tool-btn-secondary {
    background-color: #ffffff;
    border: 1px solid #cbd5e1;
    color: #334155;
    padding: 5px 14px;
    font-size: 12px;
    font-weight: 500;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.15s;
}

.tool-btn-secondary:hover {
    background-color: #f1f5f9;
}

/* Vim Status Indicator */
#vim-status {
    display: none;
    position: absolute;
    bottom: 12px;
    right: 16px;
    font-family: monospace;
    font-weight: bold;
    font-size: 11px;
    color: #fff;
    background: #333;
    padding: 3px 8px;
    border-radius: 4px;
    pointer-events: none;
    z-index: 20;
}

/* Toast Notification */
#toast {
    visibility: hidden;
    min-width: 240px;
    background-color: #1e293b;
    color: #fff;
    text-align: center;
    border-radius: 6px;
    padding: 10px 18px;
    position: fixed;
    z-index: 2000;
    left: 50%;
    bottom: 30px;
    transform: translateX(-50%);
    font-size: 13px;
    opacity: 0;
    transition: opacity 0.3s, visibility 0.3s;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

#toast.show {
    visibility: visible;
    opacity: 1;
}

/* Footer */
.bottom-footer {
    width: 100%;
    max-width: 850px;
    margin-top: auto;
    padding: 24px 0;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    font-size: 13px;
    color: var(--muted-text);
}

.bottom-footer a {
    color: var(--muted-text);
    text-decoration: none;
    transition: color 0.15s;
}

.bottom-footer a:hover {
    color: var(--text-color);
}

.dot-separator {
    color: #cbd5e1;
}

/* Mobile Responsiveness Rules */
@media (max-width: 600px) {
    body { 
        padding: 0 16px; 
    }

    .bottom-controls-bar {
        display: flex;
        flex-wrap: wrap;
        justify-content: center;
        align-items: center;
        gap: 8px;
    }

    /* Unwrap container boxes on mobile so buttons become direct flex items */
    .controls-group-left,
    .controls-group-center {
        display: contents;
    }

    /* Row 1: Left Arrow (1), File Explorer Folder (2), Right Arrow (3) */
    #btn-prev-note { order: 1; }
    #btn-files     { order: 2; }
    #btn-next-note { order: 3; }

    /* Row 2: Settings & + New Note Buttons */
    .controls-group-right {
        order: 4;
        flex-basis: 100%;
        width: 100%;
        display: flex;
        justify-content: center;
        gap: 10px;
        margin-top: 4px;
    }

    .bottom-footer { 
        justify-content: center; 
        flex-wrap: wrap; 
        text-align: center; 
    }
}

/* Dark Mode Overrides */
body.dark-mode {
    --card-bg: #18181b;
    --text-color: #f4f4f5;
    --tab-bar-bg: #27272a;
    --tab-bg: #3f3f46;
    --tab-active-bg: #18181b;
    --border-color: #3f3f46;
    --muted-text: #a1a1aa;
    --primary-slate: #3b82f6;
    --primary-slate-hover: #2563eb;
    background-color: #09090b;
}

body.dark-mode .single-file-title {
    color: var(--text-color);
}

body.dark-mode .single-file-title:hover {
    background-color: #27272a;
}

body.dark-mode .folder-btn,
body.dark-mode .secondary-btn,
body.dark-mode .files-action-btn,
body.dark-mode .cancel-btn,
body.dark-mode .tool-btn-secondary,
body.dark-mode .pagination-controls button {
    background-color: #18181b;
    border-color: #3f3f46;
    color: #e2e8f0;
}

body.dark-mode .folder-btn:hover,
body.dark-mode .secondary-btn:hover,
body.dark-mode .files-action-btn:hover,
body.dark-mode .cancel-btn:hover,
body.dark-mode .tool-btn-secondary:hover,
body.dark-mode .pagination-controls button:hover:not(:disabled) {
    background-color: #27272a;
}

body.dark-mode .icon-nav-btn {
    background: #27272a;
    border-color: #3f3f46;
    color: #a1a1aa;
}

body.dark-mode .icon-nav-btn:hover {
    background: #3f3f46;
    color: #f4f4f5;
}

body.dark-mode .modal {
    background: #18181b;
    color: #f4f4f5;
    border-color: #3f3f46;
}

body.dark-mode input[type="text"],
body.dark-mode input[type="number"],
body.dark-mode select {
    background-color: #27272a;
    color: #f4f4f5;
    border-color: #3f3f46;
}

body.dark-mode .file-list {
    background-color: #09090b;
    border-color: #3f3f46;
}

body.dark-mode .file-item {
    border-color: #27272a;
}

body.dark-mode .file-item:hover {
    background-color: #27272a;
}

body.dark-mode .tab-list-item:hover {
    background-color: #27272a;
}

/* Live Markdown Styles */
.md-live { 
    cursor: text; 
}
h1.md-live { 
    font-size: 1.8em; 
    margin-bottom: 0.3em; 
    border-bottom: 1px solid var(--border-color); 
    display: block; 
    font-weight: bold;
}
h2.md-live { 
    font-size: 1.5em; 
    margin-bottom: 0.3em; 
    display: block; 
    font-weight: bold;
}
h3.md-live { 
    font-size: 1.2em; 
    margin-bottom: 0.3em; 
    display: block; 
    font-weight: bold;
}
blockquote.md-live { 
    border-left: 4px solid var(--accent-blue); 
    padding-left: 1em; 
    color: var(--muted-text); 
    display: block; 
    margin: 0;
}
code.md-live { 
    background: rgba(0,0,0,0.05); 
    padding: 2px 4px; 
    border-radius: 3px; 
    font-family: monospace; 
    font-size: 0.9em; 
}
body.dark-mode code.md-live { 
    background: rgba(255,255,255,0.1); 
}

li.md-live {
    display: list-item;
    margin-left: 1.5em;
    cursor: text;
}

table.md-live {
    border-collapse: collapse;
    margin: 12px 0;
    width: 100%;
    cursor: pointer;
}

table.md-live th, table.md-live td {
    border: 1px solid #cbd5e1;
    padding: 6px 12px;
    text-align: left;
    font-size: 0.95em;
}

table.md-live th {
    background-color: rgba(0, 0, 0, 0.05);
    font-weight: bold;
}

body.dark-mode table.md-live th, 
body.dark-mode table.md-live td {
    border-color: #3f3f46;
}

body.dark-mode table.md-live th {
    background-color: rgba(255, 255, 255, 0.1);
}