:root {
    color-scheme: dark;
    --canvas: #181b22;
    --panel: #222630;
    --field: #1b1e27;
    --hover: #2d3341;
    --text: #eef0f7;
    --muted: #b0b8ca;
    --line: #373e4e;
    --control: #566176;
    --accent: #b4bdff;
    --accent-fill: #a3aaff;
    --accent-ink: #191e40;
    --selected: #33395a;
    --danger: #ffadb4;
    --radius: 12px;
    font: 16px/1.5 Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--canvas); color: var(--text); }
h1, h2, p { margin: 0; }
h1 { font-size: clamp(1.7rem, 4vw, 2.15rem); line-height: 1.15; letter-spacing: -.035em; }
h2 { font-size: 1.1rem; line-height: 1.35; overflow-wrap: anywhere; }
a { color: var(--accent); text-underline-offset: .2em; }
button, input, textarea { font: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

.site-header { background: var(--panel); border-bottom: 1px solid var(--line); }
.header-content, main {
    width: min(100%, 1192px);
    margin-inline: auto;
    padding-inline: clamp(16px, 4vw, 40px);
}
.header-content { display: flex; align-items: center; gap: 28px; min-height: 64px; }
.brand {
    display: inline-flex;
    align-items: center;
    gap: 9px;
    flex-shrink: 0;
    color: var(--text);
    font-size: 1.05rem;
    font-weight: 750;
    letter-spacing: -.025em;
    text-decoration: none;
}
.brand-mark {
    display: grid;
    place-items: center;
    width: 30px;
    height: 30px;
    border-radius: 8px;
    background: var(--accent-fill);
    color: var(--accent-ink);
    font-size: .95rem;
}
.section-nav { display: flex; gap: 4px; align-items: center; }
.section-nav a {
    padding: 7px 11px;
    border-radius: 7px;
    color: var(--muted);
    font-size: .9rem;
    font-weight: 650;
    text-decoration: none;
}
.section-nav a:hover { background: var(--hover); color: var(--text); }
.section-nav a[aria-current="page"] { background: var(--selected); color: var(--accent); }
.logout { margin: 0 0 0 auto; }
.logout button { white-space: nowrap; }

main { padding-block: clamp(24px, 5vw, 48px); }
.page-heading, .panel-heading, .editor-status, .toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}
.page-heading, .panel-heading { justify-content: space-between; }
.page-heading { margin-bottom: 18px; gap: 12px; }
.panel-heading { margin-bottom: 14px; gap: 12px; }
.panel {
    min-width: 0;
    padding: clamp(16px, 3vw, 22px);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--panel);
}

button, .button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 38px;
    padding: 6px 12px;
    border: 1px solid var(--control);
    border-radius: 7px;
    background: var(--panel);
    color: var(--text);
    font-size: .875rem;
    font-weight: 650;
    text-decoration: none;
    cursor: pointer;
}
button:hover, .button:hover { background: var(--hover); }
.button-primary { border-color: var(--accent-fill); background: var(--accent-fill); color: var(--accent-ink); }
.button-primary:hover { border-color: #c1c7ff; background: #c1c7ff; }
.button-danger { color: var(--danger); }
.button-danger:hover { background: #402d39; }
button:disabled { border-color: var(--line); background: var(--field); color: var(--muted); cursor: default; }

label { display: block; font-size: .9rem; font-weight: 650; }
input:not([type="hidden"], [type="checkbox"]), textarea {
    width: 100%;
    min-width: 0;
    border: 1px solid var(--control);
    border-radius: 8px;
    background: var(--field);
    color: var(--text);
}
input:not([type="file"], [type="hidden"], [type="checkbox"]) { min-height: 42px; padding: 8px 10px; }
textarea {
    display: block;
    min-height: 220px;
    padding: 14px;
    resize: vertical;
    font: .925rem/1.65 ui-monospace, "SFMono-Regular", Consolas, monospace;
}
small, .feedback, .note-times, .note-count { color: var(--muted); font-size: .85rem; }
.feedback:empty { display: none; }
.error {
    margin-bottom: 14px;
    padding: 10px 12px;
    border: 1px solid #61505d;
    border-radius: 8px;
    background: #382833;
    color: var(--danger);
}
.empty-state {
    display: grid;
    min-height: 152px;
    place-items: center;
    align-content: center;
    color: var(--muted);
    text-align: center;
}
.slot-nav {
    display: grid;
    grid-template-columns: repeat(10, minmax(0, 1fr));
    gap: 7px;
    margin-bottom: 16px;
}
.slot {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 7px 4px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    color: var(--text);
    text-decoration: none;
}
.slot:hover { border-color: var(--control); background: var(--hover); }
.slot strong { font-size: 1rem; font-variant-numeric: tabular-nums; }
.slot small { font-size: .75rem; }
.slot.filled { border-color: #425e59; background: #293d3b; }
.slot.filled:hover { background: #324b47; }
.slot.filled small { color: #b1dbce; font-weight: 650; }
.slot[aria-current="page"] { border-color: var(--accent-fill); background: var(--selected); color: var(--accent); }
.slot.filled[aria-current="page"] { background: #324b47; }

.markdown-panel textarea { height: clamp(320px, 55vh, 680px); }
.editor-status:has(.save-status:not(:empty)) { margin-bottom: 8px; }
.save-status { font-size: .875rem; color: var(--muted); }
.save-status:empty { position: absolute; }
.button-primary[data-state="success"]:not(:disabled) { border-color: #81cda8; background: #b7f3d3; color: #173229; }
.save-status[data-state="success"] {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 5px 9px;
    border: 1px solid #416758;
    border-radius: 7px;
    background: #233d35;
    color: #b7f3d3;
}
.save-status[data-state="success"]::before { content: "✓" / ""; font-weight: 700; }
.save-status[data-state="error"] { color: var(--danger); }
.note-saved { margin-bottom: 14px; }
.markdown-preview { overflow-wrap: anywhere; line-height: 1.65; }
.markdown-preview > :first-child { margin-top: 0; }
.markdown-preview > :last-child { margin-bottom: 0; }
.markdown-preview :where(p, ul, ol, pre, blockquote, table) { margin-block: .9em; }
.markdown-preview img { max-width: 100%; height: auto; }
.markdown-preview pre { overflow-x: auto; padding: 12px; border-radius: 8px; background: var(--field); }
.markdown-preview :not(pre) > code { padding: 2px 4px; border-radius: 4px; background: var(--field); }
.markdown-preview blockquote {
    margin-inline: 0;
    padding-inline: 1em;
    border-inline-start: 3px solid var(--control);
    color: var(--muted);
}
.markdown-preview table { display: block; overflow-x: auto; border-collapse: collapse; }
.markdown-preview :where(th, td) { padding: 6px 10px; border: 1px solid var(--line); }
.markdown-preview hr { border: 0; border-top: 1px solid var(--control); }
.markdown-preview li:has(> input[type="checkbox"], > p:first-child > input[type="checkbox"]) {
    position: relative;
    margin-inline-start: -1.5rem;
    padding-inline-start: 1.5rem;
    list-style: none;
}
.markdown-preview li > p:first-child:has(> input[type="checkbox"]) { margin-block-start: 0; }
.markdown-preview li > input[type="checkbox"],
.markdown-preview li > p:first-child > input[type="checkbox"] {
    position: absolute;
    inset-inline-start: 0;
    inset-block-start: calc((1lh - 1rem) / 2);
    display: grid;
    place-items: center;
    inline-size: 1rem;
    block-size: 1rem;
    margin: 0;
    appearance: none;
    border: 1px solid var(--muted);
    border-radius: 4px;
    background: var(--field);
    opacity: 1;
}
.markdown-preview input[type="checkbox"]:checked {
    border-color: var(--accent-fill);
    background: var(--accent-fill);
}
.markdown-preview input[type="checkbox"]:checked::before {
    content: "";
    width: .34rem;
    height: .57rem;
    border: solid var(--accent-ink);
    border-width: 0 2px 2px 0;
    transform: translateY(-1px) rotate(45deg);
}
@media (forced-colors: active) {
    .markdown-preview input[type="checkbox"]:checked { forced-color-adjust: none; }
}

.image-layout, .notes-layout {
    display: grid;
    grid-template-columns: minmax(230px, 1fr) minmax(0, 2fr);
    gap: 14px;
    align-items: start;
}
.image-controls h2 { margin-bottom: 14px; }
#image-form { display: grid; gap: 10px; }
#image-file { padding: 6px; font-size: .85rem; }
#image-file::file-selector-button {
    margin-right: 8px;
    padding: 4px 8px;
    border: 0;
    border-radius: 4px;
    background: var(--selected);
    color: var(--accent);
    font: inherit;
    cursor: pointer;
}
#image-paste {
    display: grid;
    gap: 5px;
    margin-block: 3px;
    padding: 12px;
    border: 1px dashed var(--control);
    border-radius: 8px;
    background: var(--field);
    font-size: .9rem;
    cursor: text;
}
#image-paste span { color: var(--muted); font-size: .85rem; }
#image-paste:focus { border-color: var(--accent); background: var(--selected); }
kbd { font: inherit; font-weight: 650; }
#image-status { margin-top: 12px; }
#image-pending { display: block; max-width: 100%; max-height: 240px; margin-top: 12px; border-radius: 7px; }
.image-stage {
    display: grid;
    place-items: center;
    min-height: clamp(224px, 40vh, 370px);
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--field);
    color: var(--muted);
    text-align: center;
}
.clipboard-image { display: block; max-width: 100%; max-height: 70vh; object-fit: contain; }

.notes-layout { grid-template-columns: minmax(230px, 1fr) minmax(0, 2.25fr); }
.notes-sidebar .panel-heading { margin-bottom: 10px; }
.note-count { font-variant-numeric: tabular-nums; }
.note-list { display: grid; gap: 4px; list-style: none; margin: 0; padding: 0; }
.note-list a {
    display: grid;
    gap: 2px;
    padding: 9px 10px;
    border-radius: 7px;
    color: var(--text);
    font-weight: 650;
    text-decoration: none;
    overflow-wrap: anywhere;
}
.note-list a:hover { background: var(--hover); }
.note-list a[aria-current="page"] { background: var(--selected); color: var(--accent); }
.note-list small { font-weight: 400; }
.note-times { margin: -4px 0 16px; font-variant-numeric: tabular-nums; }
.note-form { display: grid; gap: 8px; }
.note-form label[for="note-markdown"] { margin-top: 6px; }
.note-form textarea { height: clamp(240px, 43vh, 580px); }
.note-form .toolbar { margin-bottom: 6px; }

.login-layout { display: grid; place-items: center; padding-block: clamp(48px, 11vh, 112px); }
.login { display: grid; gap: 16px; width: min(100%, 400px); padding: clamp(22px, 5vw, 32px); }
.login h1 { margin-bottom: 4px; }
.login label input { display: block; margin-top: 5px; }
.login .button-primary { margin-top: 4px; }
.login .error { margin-bottom: 0; }

@media (max-width: 740px) {
    .slot-nav { grid-template-columns: repeat(5, minmax(0, 1fr)); }
    .notes-layout, .image-layout { grid-template-columns: minmax(0, 1fr); }
    .note-list { max-height: 240px; overflow-y: auto; padding: 4px; }
}

@media (max-width: 520px) {
    .header-content {
        display: grid;
        grid-template-columns: 1fr auto;
        gap: 6px;
        min-height: 64px;
        padding-block: 10px;
    }
    .section-nav { grid-row: 2; grid-column: 1 / -1; }
    .logout { grid-row: 1; grid-column: 2; }
}
