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

:root {
    --bg: #0e0b16;
    --sidebar-bg: #1a1428;
    --card-bg: #2d2244;
    --accent: #7b2d8e;
    --accent-light: #a855c8;
    --accent-glow: rgba(168, 85, 200, 0.15);
    --gold: #c9a84c;
    --text: #f5f0ff;
    --text-dim: #9485a8;
    --border: rgba(168, 85, 200, 0.12);
    --border-strong: rgba(168, 85, 200, 0.25);
}

body {
    font-family: -apple-system, "PingFang SC", "SF Pro Display", "Microsoft YaHei", sans-serif;
    background: var(--bg);
    color: var(--text);
    height: 100vh;
    overflow: hidden;
}

.app {
    display: flex;
    height: 100vh;
}

/* ---------- 左侧栏 ---------- */
.sidebar {
    width: 240px;
    min-width: 240px;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    backdrop-filter: blur(20px);
}

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

.sidebar-header h1 {
    font-size: 17px;
    font-weight: 700;
    letter-spacing: 2px;
}

.sidebar-header h1 a {
    text-decoration: none;
    background: linear-gradient(135deg, var(--accent-light), #e0c3fc);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    transition: opacity 0.2s;
}

.sidebar-header h1 a:hover { opacity: 0.7; }

.sidebar-header button {
    width: 30px;
    height: 30px;
    border: 1px solid var(--border-strong);
    border-radius: 8px;
    background: transparent;
    color: var(--accent-light);
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.sidebar-header button:hover {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

#note-list {
    list-style: none;
    overflow-y: auto;
    flex: 1;
    padding: 8px;
}

#note-list::-webkit-scrollbar { width: 4px; }
#note-list::-webkit-scrollbar-track { background: transparent; }
#note-list::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 4px; }

#note-list li {
    padding: 12px 14px;
    border-radius: 10px;
    cursor: pointer;
    margin-bottom: 4px;
    transition: all 0.2s;
    border: 1px solid transparent;
}

#note-list li:hover {
    background: var(--accent-glow);
    border-color: var(--border-strong);
}

#note-list li.active {
    background: linear-gradient(135deg, var(--accent), #5a1d6e);
    border-color: var(--accent-light);
    box-shadow: 0 4px 20px rgba(123, 45, 142, 0.3);
}

.note-item-date {
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0.5px;
}

.note-item-preview {
    font-size: 12px;
    color: var(--text-dim);
    margin-top: 3px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#note-list li.active .note-item-preview { color: rgba(255,255,255,0.65); }

/* ---------- 右侧编辑区 ---------- */
.editor {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: linear-gradient(180deg, var(--bg) 0%, #120e1e 100%);
}

.editor-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 24px;
    border-bottom: 1px solid var(--border);
    min-height: 52px;
}

#note-date {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-dim);
    letter-spacing: 1px;
}

.editor-actions button {
    background: none;
    border: none;
    font-size: 17px;
    cursor: pointer;
    padding: 6px 10px;
    border-radius: 8px;
    transition: all 0.2s;
}

.editor-actions button:hover {
    background: var(--accent-glow);
}

.editor-body {
    flex: 1;
    position: relative;
    overflow: hidden;
}

/* WYSIWYG 编辑器 */
.note-editor {
    width: 100%;
    height: 100%;
    padding: 28px 32px;
    background: transparent;
    color: var(--text);
    outline: none;
    font-size: 16px;
    line-height: 2;
    font-family: inherit;
    letter-spacing: 0.3px;
    overflow-y: auto;
    cursor: text;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.note-editor:empty::before {
    content: attr(data-placeholder);
    color: var(--text-dim);
    font-style: italic;
    pointer-events: none;
}

.note-editor[contenteditable="false"] { cursor: default; }

/* ---------- WYSIWYG 富文本样式 ---------- */

.note-editor h1 {
    font-size: 28px;
    font-weight: 800;
    margin: 24px 0 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
    background: linear-gradient(135deg, var(--text), var(--accent-light));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.note-editor h2 {
    font-size: 22px;
    font-weight: 700;
    margin: 20px 0 10px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border);
    color: var(--text);
}

.note-editor h3 {
    font-size: 18px;
    font-weight: 700;
    margin: 16px 0 8px;
    color: var(--accent-light);
}

.note-editor h4 {
    font-size: 16px;
    font-weight: 600;
    margin: 14px 0 6px;
    color: var(--accent-light);
    opacity: 0.85;
}

.note-editor h5, .note-editor h6 {
    font-size: 14px;
    font-weight: 600;
    margin: 12px 0 6px;
    color: var(--text-dim);
}

.note-editor h1:first-child,
.note-editor h2:first-child,
.note-editor h3:first-child { margin-top: 0; }

.note-editor p {
    font-size: 16px;
    line-height: 2;
    margin: 8px 0;
    color: var(--text);
}

.note-editor strong {
    color: var(--accent-light);
    font-weight: 700;
}

.note-editor em {
    color: var(--text);
    font-style: italic;
    opacity: 0.85;
}

.note-editor a {
    color: var(--accent-light);
    text-decoration: none;
    border-bottom: 1px solid rgba(168, 85, 200, 0.3);
    transition: border-color 0.2s;
}

.note-editor a:hover { border-color: var(--accent-light); }

.note-editor ul, .note-editor ol {
    padding-left: 24px;
    margin: 8px 0;
}

.note-editor li {
    font-size: 16px;
    line-height: 2;
    color: var(--text);
}

.note-editor li::marker { color: var(--accent-light); }

.note-editor blockquote {
    border-left: 3px solid var(--accent);
    padding: 8px 16px;
    margin: 12px 0;
    background: var(--accent-glow);
    border-radius: 0 8px 8px 0;
    color: var(--text-dim);
    font-style: italic;
}

.note-editor code {
    background: rgba(168, 85, 200, 0.15);
    color: var(--accent-light);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 14px;
    font-family: "SF Mono", "Fira Code", monospace;
}

.note-editor pre {
    background: var(--sidebar-bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 16px 20px;
    margin: 12px 0;
    overflow-x: auto;
}

.note-editor pre code {
    background: transparent;
    padding: 0;
    font-size: 14px;
    line-height: 1.6;
    color: var(--text);
}

.note-editor hr {
    border: none;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--accent), transparent);
    margin: 24px 0;
}

.note-editor table {
    width: 100%;
    border-collapse: collapse;
    margin: 12px 0;
}

.note-editor th {
    background: var(--card-bg);
    color: var(--accent-light);
    font-weight: 600;
    padding: 10px 14px;
    text-align: left;
    border-bottom: 2px solid var(--accent);
    font-size: 14px;
}

.note-editor td {
    padding: 8px 14px;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
    color: var(--text);
}

.note-editor tr:hover td { background: var(--accent-glow); }

.note-editor img {
    max-width: 100%;
    border-radius: 10px;
    margin: 12px 0;
}

.note-editor input[type="checkbox"] {
    accent-color: var(--accent);
    margin-right: 6px;
}

.status-bar {
    padding: 8px 24px;
    font-size: 11px;
    color: var(--text-dim);
    border-top: 1px solid var(--border);
    text-align: right;
    min-height: 30px;
    letter-spacing: 0.5px;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
}

#btn-cheatsheet {
    background: none;
    border: none;
    font-size: 16px;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 6px;
    transition: all 0.2s;
    opacity: 0.5;
}

#btn-cheatsheet:hover { opacity: 1; background: var(--accent-glow); }

/* ---------- Markdown 语法浮层 ---------- */
.cheatsheet {
    position: absolute;
    bottom: 36px;
    right: 20px;
    width: 280px;
    background: var(--sidebar-bg);
    border: 1px solid var(--border-strong);
    border-radius: 14px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5), 0 0 30px rgba(123, 45, 142, 0.1);
    z-index: 50;
    overflow: hidden;
    transform-origin: bottom right;
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1),
                opacity 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    transform: scale(1);
    opacity: 1;
}

.cheatsheet.hidden {
    transform: scale(0.85);
    opacity: 0;
    pointer-events: none;
}

.cheatsheet-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
    font-weight: 700;
    color: var(--accent-light);
    letter-spacing: 1px;
}

.cheatsheet-header button {
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 14px;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 4px;
    transition: color 0.15s;
}

.cheatsheet-header button:hover { color: var(--text); }

.cheatsheet-body {
    padding: 12px 16px 16px;
}

.cs-section { margin-bottom: 14px; }
.cs-section:last-of-type { margin-bottom: 0; }

.cs-title {
    font-size: 11px;
    font-weight: 700;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 1.5px;
    margin-bottom: 6px;
}

.cs-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 0;
    font-size: 13px;
}

.cs-row kbd {
    background: var(--bg);
    border: 1px solid var(--border-strong);
    border-radius: 5px;
    padding: 2px 8px;
    font-family: "SF Mono", "Fira Code", monospace;
    font-size: 12px;
    color: var(--accent-light);
    min-width: 80px;
}

.cs-row span { color: var(--text-dim); font-size: 12px; }
.cs-row strong { color: var(--accent-light); font-weight: 700; }
.cs-row em { color: var(--text); }
.cs-row code {
    background: rgba(168, 85, 200, 0.15);
    color: var(--accent-light);
    padding: 1px 4px;
    border-radius: 3px;
    font-size: 11px;
}

.cs-tip {
    margin-top: 12px;
    padding-top: 10px;
    border-top: 1px solid var(--border);
    font-size: 11px;
    color: var(--text-dim);
    text-align: center;
    font-style: italic;
}

/* ---------- 弹窗 ---------- */
.modal {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(10, 8, 18, 0.75);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.modal.hidden { display: none; }

.modal-box {
    background: var(--sidebar-bg);
    border: 1px solid var(--border-strong);
    border-radius: 16px;
    padding: 28px;
    width: 320px;
    box-shadow: 0 20px 60px rgba(123, 45, 142, 0.2);
}

.modal-box p {
    margin-bottom: 16px;
    font-size: 15px;
    font-weight: 600;
    letter-spacing: 0.5px;
}

.modal-box input {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--border-strong);
    border-radius: 10px;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    outline: none;
    margin-bottom: 20px;
    transition: border-color 0.2s;
}

.modal-box input:focus {
    border-color: var(--accent-light);
    box-shadow: 0 0 0 3px rgba(168, 85, 200, 0.15);
}

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

.modal-buttons button {
    padding: 10px 20px;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0.5px;
    transition: all 0.2s;
}

#modal-cancel {
    background: var(--card-bg);
    color: var(--text-dim);
}

#modal-cancel:hover {
    color: var(--text);
}

#modal-confirm {
    background: linear-gradient(135deg, var(--accent), var(--accent-light));
    color: #fff;
}

.modal-buttons button:hover { opacity: 0.85; }

/* ---------- 响应式（手机） ---------- */
@media (max-width: 600px) {
    .sidebar {
        width: 100%;
        min-width: 100%;
        position: absolute;
        z-index: 10;
        height: 100vh;
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }

    .sidebar.collapsed {
        transform: translateX(-100%);
    }

    .editor-header::before {
        content: "☰";
        font-size: 20px;
        cursor: pointer;
        margin-right: 12px;
        color: var(--accent-light);
    }

    #note-content {
        padding: 20px 16px;
    }
}
