:root {
    --bg-color: #fcfcfc;
    --text-color: #1a1a1a;
    --sidebar-bg: rgba(255, 255, 255, 0.85);
    --sidebar-border: #eaeaea;
    --primary-color: #3b82f6;
    --danger-color: #ef4444;
    --hover-bg: #f3f4f6;
    --font-family: 'Inter', sans-serif;
    --glass-blur: blur(16px);
    
    /* Typography Settings Defaults */
    --title-font: 'Inter'; --title-weight: 700; --title-size: 2.8rem;
    --h1-font: 'Inter'; --h1-weight: 700; --h1-size: 2.5rem;
    --h2-font: 'Inter'; --h2-weight: 600; --h2-size: 2rem;
    --h3-font: 'Inter'; --h3-weight: 500; --h3-size: 1.5rem;
    --h4-font: 'Inter'; --h4-weight: 500; --h4-size: 1.2rem;
    --body-font: 'Inter'; --body-weight: 400; --body-size: 1.1rem;
    --bullet-font: 'Inter'; --bullet-weight: 400; --bullet-size: 1rem;
    --alpha-font: 'Inter'; --alpha-weight: 400; --alpha-size: 1rem;
    --num-font: 'Inter'; --num-weight: 400; --num-size: 1rem;
    --quote-font: 'Inter'; --quote-weight: 400; --quote-size: 1.1rem;
    --code-font: 'monospace'; --code-weight: 400; --code-size: 0.9rem;
    
    /* Neumorphism Colors (Light) */
    --neu-bg: #f0f3f6;
    --neu-light: #ffffff;
    --neu-dark: #d1d9e6;
    --neu-shadow: 6px 6px 12px var(--neu-dark), -6px -6px 12px var(--neu-light);
    --neu-inner-shadow: inset 4px 4px 8px var(--neu-dark), inset -4px -4px 8px var(--neu-light);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body {
    font-family: var(--font-family);
    background-color: var(--bg-color);
    color: var(--text-color);
    overflow: hidden;
    height: 100vh;
}

.hidden { display: none !important; }

/* Login Screen */
#login-screen {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    background: linear-gradient(135deg, #fdfbfb 0%, #ebedee 100%);
}
.login-box {
    background: white;
    padding: 3rem;
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.08);
    text-align: center;
}
.login-box h1 { margin-bottom: 0.5rem; font-weight: 600; letter-spacing: -0.02em; }
.login-box p { color: #666; margin-bottom: 2rem; }
.btn {
    padding: 0.75rem 1.5rem;
    border-radius: 8px;
    border: none;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: var(--font-family);
    font-size: 1rem;
}
.btn.primary { background: var(--primary-color); color: white; }
.btn.primary:hover { opacity: 0.9; transform: translateY(-1px); }
.btn.danger { background: var(--danger-color); color: white; }
.btn.danger:hover { opacity: 0.9; }
.btn.secondary { background: var(--hover-bg); color: var(--text-color); }
.btn.secondary:hover { background: #e5e7eb; }
.btn.text-btn { background: none; color: #666; padding: 0.5rem; text-align: left; }
.btn.text-btn:hover { color: var(--text-color); background: var(--hover-bg); }

/* Layout */
#app {
    display: flex;
    height: 100vh;
    transition: transform 0.3s ease;
}

#menu-toggle {
    position: fixed;
    top: 2rem;
    left: 2rem;
    z-index: 100;
    width: 48px;
    height: 48px;
    background: var(--bg-color);
    border-radius: 50%;
    box-shadow: var(--neu-shadow);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    border: none;
    color: var(--text-color);
    cursor: pointer;
}
#menu-toggle:active {
    box-shadow: var(--neu-inner-shadow);
}
#menu-toggle.fade-out {
    opacity: 0;
    pointer-events: none;
}

/* Sidebar */
.sidebar {
    width: 320px;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--sidebar-border);
    display: flex;
    flex-direction: column;
    position: absolute;
    left: -320px;
    top: 0;
    bottom: 0;
    z-index: 90;
    transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.sidebar.open { left: 0; }

.sidebar-header {
    padding: 2rem 1.5rem 1.5rem 5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.sidebar-header h2 { font-size: 1.25rem; font-weight: 600; color: #333; }
.icon-btn {
    background: none; border: none; cursor: pointer; color: #666;
    display: flex; align-items: center; justify-content: center;
    border-radius: 6px; padding: 6px; transition: 0.2s;
}
.icon-btn:hover { background: var(--hover-bg); color: var(--text-color); }

.page-list {
    list-style: none;
    flex: 1;
    overflow-y: auto;
    padding: 0 1rem;
}
.page-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.8rem 1rem;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
    margin-bottom: 0.25rem;
    color: #444;
}
.page-item:hover { background: var(--hover-bg); color: #111; }
.page-item.active { background: #eef2ff; color: var(--primary-color); font-weight: 500; }
.page-item .page-name {
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    font-size: 0.95rem; font-weight: 500;
}
.page-meta {
    font-size: 0.75rem; color: #888; margin-top: 0.25rem; line-height: 1.3;
}
.page-menu-btn { opacity: 0; align-self: flex-start; margin-top: 0.2rem; }
.page-item:hover .page-menu-btn, .page-item.active .page-menu-btn { opacity: 1; }
.page-menu-dropdown {
    position: absolute;
    background: white;
    border: 1px solid var(--sidebar-border);
    border-radius: 8px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.1);
    z-index: 110;
    padding: 0.5rem;
    display: none;
    flex-direction: column;
    min-width: 120px;
}
.page-menu-dropdown.show { display: flex; animation: fadeIn 0.15s ease-out; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(-5px); } to { opacity: 1; transform: translateY(0); } }
.page-menu-dropdown button {
    background: none; border: none; padding: 0.6rem 1rem;
    text-align: left; cursor: pointer; border-radius: 6px;
    font-family: var(--font-family); font-size: 0.9rem;
    color: var(--text-color);
    transition: background 0.1s;
}
.page-menu-dropdown button:hover { background: var(--hover-bg); }
.page-menu-dropdown button.delete { color: var(--danger-color); }

.sidebar-footer {
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

/* Main Content */
.main-content {
    flex: 1;
    padding: 6rem 15% 4rem;
    overflow-y: auto;
    transition: margin-left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    background: var(--bg-color);
}
.sidebar.open ~ .main-content { margin-left: 320px; }

.page-title-input {
    width: 100%;
    border: none;
    outline: none;
    background: transparent;
    font-family: var(--title-font);
    font-weight: var(--title-weight);
    font-size: var(--title-size);
    color: var(--text-color);
    margin-bottom: 0.5rem;
    letter-spacing: -0.02em;
    line-height: 1.2;
    resize: none;
    overflow: hidden;
}
.page-title-input::placeholder { color: #ccc; }

.editor {
    min-height: 60vh;
    outline: none;
}
.editor[placeholder]:empty:before {
    content: attr(placeholder);
    color: #a0a0a0;
    cursor: text;
}
.editor > * {
    margin-bottom: 1em;
    line-height: 1.6;
}
.editor div, .editor p, .editor span {
    font-family: var(--body-font) !important;
    font-weight: var(--body-weight);
    font-size: var(--body-size) !important;
}
.editor h1, .editor h1 span { font-family: var(--h1-font) !important; font-weight: var(--h1-weight); font-size: var(--h1-size) !important; margin: 1.5em 0 0.5em; line-height: 1.2; letter-spacing: -0.02em; }
.editor h2, .editor h2 span { font-family: var(--h2-font) !important; font-weight: var(--h2-weight); font-size: var(--h2-size) !important; margin: 1.5em 0 0.5em; line-height: 1.3; letter-spacing: -0.01em; }
.editor h3, .editor h3 span { font-family: var(--h3-font) !important; font-weight: var(--h3-weight); font-size: var(--h3-size) !important; margin: 1.2em 0 0.5em; line-height: 1.4; }
.editor h4, .editor h4 span { font-family: var(--h4-font) !important; font-weight: var(--h4-weight); font-size: var(--h4-size) !important; margin: 1.2em 0 0.5em; line-height: 1.4; }
.editor blockquote, .editor blockquote div, .editor blockquote p, .editor blockquote span {
    font-family: var(--quote-font) !important; 
    font-weight: var(--quote-weight); 
    font-size: var(--quote-size) !important;
}
.editor blockquote {
    border-left: 2px solid #ccc;
    padding-left: 1rem; margin: 1.5em 0; color: #555; font-style: italic;
}
.editor .code-block {
    font-family: var(--code-font); font-weight: var(--code-weight); font-size: var(--code-size);
    background: #1e1e1e; color: #d4d4d4; padding: 1.25rem; border-radius: 8px; overflow-x: auto;
    margin: 1.5em 0; line-height: 1.5;
}
.editor ul { padding-left: 1.5rem; margin-bottom: 1em; }
.editor ol { padding-left: 1.5rem; margin-bottom: 1em; }
.editor ul li { font-family: var(--bullet-font); font-size: var(--bullet-size); font-weight: var(--bullet-weight); margin-bottom: 0.5em; line-height: 1.6;}
.editor ol li { font-family: var(--num-font); font-size: var(--num-size); font-weight: var(--num-weight); margin-bottom: 0.5em; line-height: 1.6;}
.editor ol[type="A"] li { font-family: var(--alpha-font); font-size: var(--alpha-size); font-weight: var(--alpha-weight); }

/* Modals */
.modal {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.3);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    display: flex; justify-content: center; align-items: center;
    z-index: 200;
    opacity: 1; transition: opacity 0.2s;
}
.modal.hidden { opacity: 0; pointer-events: none; }
.modal-content {
    background: white; padding: 2.5rem; border-radius: 16px;
    box-shadow: 0 20px 50px rgba(0,0,0,0.15);
    width: 90%; max-width: 420px;
    transform: translateY(0); transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.modal.hidden .modal-content { transform: translateY(20px); }
.modal-content h3 { margin-bottom: 0.75rem; font-size: 1.5rem; font-weight: 600; }
.modal-content p { color: #666; margin-bottom: 2rem; line-height: 1.5; }
.modal-actions { display: flex; justify-content: flex-end; gap: 1rem; }

.settings-scroll { overflow-y: auto; flex: 1; margin-bottom: 0rem; padding-right: 1rem; padding-left: 0.5rem; display: flex; flex-direction: column; gap: 1rem; }
.settings-scroll::-webkit-scrollbar { width: 4px; }
.settings-scroll::-webkit-scrollbar-thumb { background: #ddd; border-radius: 4px; }

.setting-group { 
    background: var(--bg-color); 
    padding: 1.5rem; 
    border-radius: 16px; 
    box-shadow: var(--neu-shadow); 
    margin-bottom: 1rem; 
    border: none;
}
.setting-group h4 { margin-bottom: 1rem; font-weight: 600; color: var(--primary-color); font-size: 1.1rem; }
.setting-row { display: flex; flex-direction: column; gap: 0.5rem; margin-bottom: 1.25rem; }
.setting-row:last-child { margin-bottom: 0; }
.setting-row label { font-size: 0.8rem; color: #777; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; margin-left: 0.2rem; }

/* Neumorphic UI Elements */
.neu-input {
    background: var(--bg-color);
    border: none;
    border-radius: 8px;
    padding: 0.75rem 1rem;
    color: var(--text-color);
    box-shadow: var(--neu-inner-shadow);
    outline: none;
    font-family: var(--font-family);
    transition: all 0.2s ease;
    appearance: none;
    width: 100%;
}
.neu-input:focus {
    box-shadow: inset 5px 5px 10px var(--neu-dark), inset -5px -5px 10px var(--neu-light);
}

.neu-btn {
    background: var(--bg-color);
    border: none;
    border-radius: 8px;
    color: var(--text-color);
    box-shadow: var(--neu-shadow);
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: all 0.1s ease;
}
.neu-btn:active {
    box-shadow: var(--neu-inner-shadow);
}
select.neu-input {
    appearance: none;
    background-image: url("data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%2224%22%20height%3D%2224%22%20viewBox%3D%220%200%2024%2024%22%20fill%3D%22none%22%20stroke%3D%22%23666666%22%20stroke-width%3D%222%22%20stroke-linecap%3D%22round%22%20stroke-linejoin%3D%22round%22%3E%3Cpolyline%20points%3D%226%209%2012%2015%2018%209%22%3E%3C%2Fpolyline%3E%3C%2Fsvg%3E");
    background-repeat: no-repeat;
    background-position: right 1rem center;
    background-size: 1rem;
    padding-right: 2.5rem;
}
.setting-row select { appearance: none; }


@media (max-width: 768px) {
    .main-content { padding: 5rem 5% 2rem; }
    .sidebar.open ~ .main-content { margin-left: 0; }
}

/* @ Format Menu */
.format-menu {
    position: absolute;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: var(--glass-blur);
    border: 1px solid var(--sidebar-border);
    border-radius: 12px;
    box-shadow: 0 12px 36px rgba(0,0,0,0.15);
    width: 160px;
    max-height: 240px;
    overflow-y: auto;
    z-index: 150;
    padding: 0.25rem;
    animation: fadeIn 0.15s ease-out;
}
.format-menu::-webkit-scrollbar { width: 6px; }
.format-menu::-webkit-scrollbar-thumb { background: #ccc; border-radius: 3px; }
.format-item {
    padding: 0.5rem;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.1s;
}
.format-item:hover, .format-item.selected {
    background: var(--hover-bg);
}
.format-item .f-title { font-weight: 500; font-size: 0.95rem; color: #222; }
.format-item .f-desc { font-size: 0.8rem; color: #777; margin-top: 0.2rem; }


body.dark-mode {
    --bg-color: #000000;
    --text-color: #a0a0a0;
    --sidebar-bg: #000000;
    --sidebar-border: #151515;
    --hover-bg: #111111;
    
    --neu-light: #151515;
    --neu-dark: #000000;
    --neu-shadow: 6px 6px 12px var(--neu-dark), -6px -6px 12px var(--neu-light);
    --neu-inner-shadow: inset 4px 4px 8px var(--neu-dark), inset -4px -4px 8px var(--neu-light);
}
body.dark-mode .sidebar-header h2,
body.dark-mode .page-item,
body.dark-mode .setting-group h4,
body.dark-mode .format-item .f-title {
    color: #a0a0a0;
}
body.dark-mode .page-item:hover,
body.dark-mode .page-item.active {
    color: #fff;
}
body.dark-mode .page-item.active {
    background: #1a1a1a;
}
body.dark-mode .login-box,
body.dark-mode .modal-content,
body.dark-mode .page-menu-dropdown,
body.dark-mode .format-menu {
    background: #0a0a0a;
    border-color: #222;
    color: #a0a0a0;
}
body.dark-mode .setting-group {
    background: var(--bg-color);
}
body.dark-mode .page-meta {
    color: #666;
}
body.dark-mode select.neu-input {
    background-image: url("data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%2224%22%20height%3D%2224%22%20viewBox%3D%220%200%2024%2024%22%20fill%3D%22none%22%20stroke%3D%22%23a0a0a0%22%20stroke-width%3D%222%22%20stroke-linecap%3D%22round%22%20stroke-linejoin%3D%22round%22%3E%3Cpolyline%20points%3D%226%209%2012%2015%2018%209%22%3E%3C%2Fpolyline%3E%3C%2Fsvg%3E");
}
body.dark-mode .editor .code-block {
    background: #252525;
    color: #d4d4d4;
    border: 1px solid #333;
}
body.dark-mode .editor blockquote {
    border-left-color: #fff;
}
body.dark-mode #theme-select {
    background: #000 !important;
    color: #a0a0a0;
}
