:root {
    color-scheme: light;
    --surface-base: #f5f1eb;
    --surface-elevated: #fdf9f2;
    --surface-overlay: #ffffff;
    --text-primary: #221f2d;
    --text-secondary: #584f68;
    --text-muted: #82788f;
    --color-primary: #7d3fc7;
    --color-primary-hover: #6932ab;
    --color-secondary: #c93a8d;
    --color-secondary-hover: #ac2e76;
    --color-success: #1f8a55;
    --color-success-hover: #176c42;
    --color-highlight: #d0ac16;
    --color-highlight-ink: #6f5900;
    --color-highlight-text: #2d2502;
    --color-border: #d8d0df;
    --color-border-soft: rgb(216 208 223 / 0.55);
    --color-border-strong: rgb(216 208 223 / 0.8);
    --color-code-bg: #f3eef7;
    --color-notice-bg: #eee7f5;
    --color-notice-text: #3f3256;
    --color-notice-outline: rgb(125 63 199 / 0.16);
    --color-selection: #f6e58f;
    --color-selection-text: #221f2d;
    --color-shadow: rgb(34 31 45 / 0.08);
    --color-shadow-strong: rgb(34 31 45 / 0.14);
    --button-text: #fffdf8;
    --button-secondary-text: var(--text-primary);
    --link-color: var(--color-primary);
    --link-hover: var(--color-primary-hover);
    --link-underline: rgb(125 63 199 / 0.26);
    --accent-primary-soft: rgb(125 63 199 / 0.1);
    --accent-secondary-soft: rgb(201 58 141 / 0.1);
    --accent-success-soft: rgb(31 138 85 / 0.12);
    --accent-highlight-soft: rgb(208 172 22 / 0.16);
    --input-bg: var(--surface-overlay);
    --input-border-hover: #bbb0c8;
    --surface-row: rgb(34 31 45 / 0.035);
    --surface-row-hover: rgb(34 31 45 / 0.06);
    --surface-handle: rgb(34 31 45 / 0.06);
    --surface-handle-active: rgb(125 63 199 / 0.14);
    --focus-ring: rgb(125 63 199 / 0.24);
    --syntax-text: #2b2238;
    --syntax-keyword: #c93a8d;
    --syntax-title: #7d3fc7;
    --syntax-number: #3159b8;
    --syntax-string: #22606e;
    --syntax-builtin: #ab5c18;
    --syntax-comment: #786e86;
    --syntax-tag: #1f8a55;
    --syntax-bullet: #8d6b08;
    --syntax-addition: #176c42;
    --syntax-addition-bg: rgb(31 138 85 / 0.12);
    --syntax-deletion: #a3325e;
    --syntax-deletion-bg: rgb(201 58 141 / 0.12);
    --diff-modified: #956d00;
    --theme-color: #f5f1eb;
}

@media (prefers-color-scheme: dark) {
    :root {
        color-scheme: dark;
        --surface-base: #19161f;
        --surface-elevated: #221d2b;
        --surface-overlay: #2b2436;
        --text-primary: #f3eef8;
        --text-secondary: #cabfda;
        --text-muted: #988fa7;
        --color-primary: #bd93f9;
        --color-primary-hover: #c9a7fb;
        --color-secondary: #ff79c6;
        --color-secondary-hover: #ff93d0;
        --color-success: #50fa7b;
        --color-success-hover: #75ff98;
        --color-highlight: #f1fa8c;
        --color-highlight-ink: #f1fa8c;
        --color-highlight-text: #26220b;
        --color-border: #3a3347;
        --color-border-soft: rgb(58 51 71 / 0.55);
        --color-border-strong: rgb(58 51 71 / 0.8);
        --color-code-bg: #1d1826;
        --color-notice-bg: #2a2436;
        --color-notice-text: #e3d8f6;
        --color-notice-outline: rgb(189 147 249 / 0.18);
        --color-selection: #5d4a1d;
        --color-selection-text: #f7f4dc;
        --color-shadow: rgb(0 0 0 / 0.28);
        --color-shadow-strong: rgb(0 0 0 / 0.4);
        --button-text: #18131f;
        --button-secondary-text: var(--text-primary);
        --link-color: var(--color-primary);
        --link-hover: var(--color-highlight);
        --link-underline: rgb(189 147 249 / 0.28);
        --accent-primary-soft: rgb(189 147 249 / 0.14);
        --accent-secondary-soft: rgb(255 121 198 / 0.14);
        --accent-success-soft: rgb(80 250 123 / 0.14);
        --accent-highlight-soft: rgb(241 250 140 / 0.16);
        --input-bg: #1c1724;
        --input-border-hover: #534862;
        --surface-row: rgb(243 238 248 / 0.03);
        --surface-row-hover: rgb(243 238 248 / 0.05);
        --surface-handle: rgb(243 238 248 / 0.06);
        --surface-handle-active: rgb(189 147 249 / 0.22);
        --focus-ring: rgb(189 147 249 / 0.32);
        --syntax-text: #efe8f8;
        --syntax-keyword: #ff79c6;
        --syntax-title: #bd93f9;
        --syntax-number: #93b7ff;
        --syntax-string: #8be9fd;
        --syntax-builtin: #ffb86c;
        --syntax-comment: #988fa7;
        --syntax-tag: #50fa7b;
        --syntax-bullet: #f1fa8c;
        --syntax-addition: #b8ffc9;
        --syntax-addition-bg: rgb(80 250 123 / 0.16);
        --syntax-deletion: #ffd0e6;
        --syntax-deletion-bg: rgb(255 121 198 / 0.18);
        --diff-modified: #ffd866;
        --theme-color: #19161f;
    }
}

[data-theme="light"] {
    color-scheme: light;
    --surface-base: #f5f1eb;
    --surface-elevated: #fdf9f2;
    --surface-overlay: #ffffff;
    --text-primary: #221f2d;
    --text-secondary: #584f68;
    --text-muted: #82788f;
    --color-primary: #7d3fc7;
    --color-primary-hover: #6932ab;
    --color-secondary: #c93a8d;
    --color-secondary-hover: #ac2e76;
    --color-success: #1f8a55;
    --color-success-hover: #176c42;
    --color-highlight: #d0ac16;
    --color-highlight-ink: #6f5900;
    --color-highlight-text: #2d2502;
    --color-border: #d8d0df;
    --color-border-soft: rgb(216 208 223 / 0.55);
    --color-border-strong: rgb(216 208 223 / 0.8);
    --color-code-bg: #f3eef7;
    --color-notice-bg: #eee7f5;
    --color-notice-text: #3f3256;
    --color-notice-outline: rgb(125 63 199 / 0.16);
    --color-selection: #f6e58f;
    --color-selection-text: #221f2d;
    --color-shadow: rgb(34 31 45 / 0.08);
    --color-shadow-strong: rgb(34 31 45 / 0.14);
    --button-text: #fffdf8;
    --button-secondary-text: var(--text-primary);
    --link-color: var(--color-primary);
    --link-hover: var(--color-primary-hover);
    --link-underline: rgb(125 63 199 / 0.26);
    --accent-primary-soft: rgb(125 63 199 / 0.1);
    --accent-secondary-soft: rgb(201 58 141 / 0.1);
    --accent-success-soft: rgb(31 138 85 / 0.12);
    --accent-highlight-soft: rgb(208 172 22 / 0.16);
    --input-bg: var(--surface-overlay);
    --input-border-hover: #bbb0c8;
    --surface-row: rgb(34 31 45 / 0.035);
    --surface-row-hover: rgb(34 31 45 / 0.06);
    --surface-handle: rgb(34 31 45 / 0.06);
    --surface-handle-active: rgb(125 63 199 / 0.14);
    --focus-ring: rgb(125 63 199 / 0.24);
    --syntax-text: #2b2238;
    --syntax-keyword: #c93a8d;
    --syntax-title: #7d3fc7;
    --syntax-number: #3159b8;
    --syntax-string: #22606e;
    --syntax-builtin: #ab5c18;
    --syntax-comment: #786e86;
    --syntax-tag: #1f8a55;
    --syntax-bullet: #8d6b08;
    --syntax-addition: #176c42;
    --syntax-addition-bg: rgb(31 138 85 / 0.12);
    --syntax-deletion: #a3325e;
    --syntax-deletion-bg: rgb(201 58 141 / 0.12);
    --diff-modified: #956d00;
    --theme-color: #f5f1eb;
}

[data-theme="dark"] {
    color-scheme: dark;
    --surface-base: #19161f;
    --surface-elevated: #221d2b;
    --surface-overlay: #2b2436;
    --text-primary: #f3eef8;
    --text-secondary: #cabfda;
    --text-muted: #988fa7;
    --color-primary: #bd93f9;
    --color-primary-hover: #c9a7fb;
    --color-secondary: #ff79c6;
    --color-secondary-hover: #ff93d0;
    --color-success: #50fa7b;
    --color-success-hover: #75ff98;
    --color-highlight: #f1fa8c;
    --color-highlight-ink: #f1fa8c;
    --color-highlight-text: #26220b;
    --color-border: #3a3347;
    --color-border-soft: rgb(58 51 71 / 0.55);
    --color-border-strong: rgb(58 51 71 / 0.8);
    --color-code-bg: #1d1826;
    --color-notice-bg: #2a2436;
    --color-notice-text: #e3d8f6;
    --color-notice-outline: rgb(189 147 249 / 0.18);
    --color-selection: #5d4a1d;
    --color-selection-text: #f7f4dc;
    --color-shadow: rgb(0 0 0 / 0.28);
    --color-shadow-strong: rgb(0 0 0 / 0.4);
    --button-text: #18131f;
    --button-secondary-text: var(--text-primary);
    --link-color: var(--color-primary);
    --link-hover: var(--color-highlight);
    --link-underline: rgb(189 147 249 / 0.28);
    --accent-primary-soft: rgb(189 147 249 / 0.14);
    --accent-secondary-soft: rgb(255 121 198 / 0.14);
    --accent-success-soft: rgb(80 250 123 / 0.14);
    --accent-highlight-soft: rgb(241 250 140 / 0.16);
    --input-bg: #1c1724;
    --input-border-hover: #534862;
    --surface-row: rgb(243 238 248 / 0.03);
    --surface-row-hover: rgb(243 238 248 / 0.05);
    --surface-handle: rgb(243 238 248 / 0.06);
    --surface-handle-active: rgb(189 147 249 / 0.22);
    --focus-ring: rgb(189 147 249 / 0.32);
    --syntax-text: #efe8f8;
    --syntax-keyword: #ff79c6;
    --syntax-title: #bd93f9;
    --syntax-number: #93b7ff;
    --syntax-string: #8be9fd;
    --syntax-builtin: #ffb86c;
    --syntax-comment: #988fa7;
    --syntax-tag: #50fa7b;
    --syntax-bullet: #f1fa8c;
    --syntax-addition: #b8ffc9;
    --syntax-addition-bg: rgb(80 250 123 / 0.16);
    --syntax-deletion: #ffd0e6;
    --syntax-deletion-bg: rgb(255 121 198 / 0.18);
    --diff-modified: #ffd866;
    --theme-color: #19161f;
}

* {
    box-sizing: border-box;
}

::selection {
    background: var(--color-selection);
    color: var(--color-selection-text);
}

html {
    background: var(--surface-base);
}

body {
    font-family:
        -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    line-height: 1.7;
    color: var(--text-primary);
    max-width: 800px;
    margin: 0 auto;
    padding: 1.25rem 1rem 2.5rem;
    background: var(--surface-base);
}

h1,
h2,
h3,
h4,
h5,
h6 {
    color: var(--text-primary);
    line-height: 1.15;
    margin: 2rem 0 0.8rem;
}

h1 {
    font-size: clamp(2rem, 5vw, 2.7rem);
    font-weight: 690;
    letter-spacing: -0.035em;
    margin-top: 0;
    margin-bottom: 1.35rem;
}

h2 {
    font-size: clamp(1.45rem, 3vw, 1.8rem);
    font-weight: 620;
    letter-spacing: -0.02em;
    padding-left: 0.85rem;
    border-left: 4px solid var(--color-primary);
}

h3 {
    font-size: 1.02rem;
    font-weight: 620;
    letter-spacing: 0.085em;
    text-transform: uppercase;
    color: var(--color-secondary);
}

h4,
h5,
h6 {
    color: var(--text-secondary);
    font-size: 1rem;
    font-weight: 580;
}

p,
ul,
ol,
blockquote,
pre,
table,
form,
.upload-card,
.reorder-page,
.notice,
.pdf-actions {
    margin-top: 0;
    margin-bottom: 1.25rem;
}

ul,
ol {
    padding-left: 1.4rem;
}

li + li {
    margin-top: 0.35rem;
}

li::marker {
    color: var(--color-highlight);
}

a {
    color: var(--link-color);
    text-decoration: underline;
    text-decoration-color: var(--link-underline);
    text-underline-offset: 0.16em;
    transition:
        color 120ms ease,
        text-decoration-color 120ms ease;
}

a:hover {
    color: var(--link-hover);
    text-decoration-color: currentcolor;
}

.nav {
    display: flex;
    flex-wrap: wrap;
    gap: 0.65rem 0.75rem;
    align-items: center;
    padding: 0.8rem 0.95rem;
    margin-bottom: 1.9rem;
    border-radius: 18px;
    background: var(--surface-elevated);
    box-shadow:
        0 1px 0 var(--color-shadow),
        0 10px 28px -22px var(--color-shadow-strong);
}

.nav a,
.nav button {
    margin: 0;
}

.nav a {
    display: inline-flex;
    align-items: center;
    min-height: 2.25rem;
    padding: 0.3rem 0.55rem;
    border-radius: 999px;
    color: var(--text-secondary);
    font-size: 0.95rem;
    font-weight: 600;
    text-decoration: none;
}

.nav a:hover {
    background: var(--accent-primary-soft);
    color: var(--text-primary);
}

.nav a[href="/new"]:hover,
.nav a[href^="/upload"]:hover {
    background: var(--accent-success-soft);
    color: var(--color-success);
}

.nav a[href^="/search"]:hover {
    background: var(--accent-highlight-soft);
    color: var(--color-highlight-ink);
}

.nav a[href^="/git"]:hover,
.nav a[href^="/push/subscribe"]:hover,
.nav a[href^="/edit"]:hover {
    background: var(--accent-secondary-soft);
    color: var(--color-secondary);
}

.theme-toggle,
.pwa-refresh {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid transparent;
    padding: 0.42rem 0.7rem;
    border-radius: 999px;
    font: inherit;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition:
        background-color 120ms ease,
        color 120ms ease,
        border-color 120ms ease;
}

.theme-toggle {
    color: var(--color-secondary);
}

.theme-toggle:hover,
.pwa-refresh:hover {
    color: var(--text-primary);
}

.theme-toggle:hover {
    background: var(--accent-secondary-soft);
    color: var(--color-secondary);
}

.pwa-refresh {
    color: var(--color-success);
}

.pwa-refresh:hover {
    background: var(--accent-success-soft);
    color: var(--color-success);
}

/* Breadcrumbs */
.breadcrumbs {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0.15rem;
    margin-top: 0;
    margin-bottom: 0.75rem;
    font-size: 1rem;
    font-weight: 400;
    line-height: 1.5;
}

.breadcrumbs a {
    color: var(--text-muted);
    text-decoration: none;
    transition: color 120ms ease;
}

.breadcrumbs a:hover {
    color: var(--link-color);
}

.breadcrumb-sep {
    color: var(--color-border);
    margin: 0 0.1rem;
    font-weight: 400;
}

.breadcrumb-current {
    color: var(--text-primary);
}

/* Directory card grid */
.dir-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 0.65rem;
    margin-bottom: 1.25rem;
}

.dir-card {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.75rem 0.85rem;
    border-radius: 12px;
    background: var(--surface-elevated);
    box-shadow:
        inset 0 0 0 1px var(--color-border-soft),
        0 1px 0 var(--color-shadow);
    color: var(--text-primary);
    text-decoration: none;
    transition:
        background-color 120ms ease,
        box-shadow 120ms ease,
        transform 120ms ease;
}

.dir-card:hover {
    background: var(--surface-overlay);
    box-shadow:
        inset 0 0 0 1px var(--color-border-strong),
        0 2px 8px var(--color-shadow);
    color: var(--text-primary);
    transform: translateY(-1px);
}

.dir-card:active {
    transform: translateY(0);
}

.dir-card-icon {
    flex-shrink: 0;
    width: 1.35rem;
    height: 1.35rem;
}

.dir-card-folder .dir-card-icon {
    color: var(--color-primary);
}

.dir-card-file .dir-card-icon {
    color: var(--text-muted);
}

.dir-card-parent .dir-card-icon {
    color: var(--text-secondary);
}

.dir-card-name {
    font-size: 0.95rem;
    font-weight: 550;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

@media (max-width: 600px) {
    .dir-grid {
        grid-template-columns: 1fr;
    }
}

/* Manage page */
.manage-drag-source {
    cursor: default;
}

.manage-handle {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 1.6rem;
    height: 1.6rem;
    padding: 0;
    border: none;
    border-radius: 4px;
    background: var(--surface-handle, var(--surface-overlay));
    color: var(--text-muted);
    cursor: grab;
    touch-action: none;
}

.manage-handle svg {
    width: 1rem;
    height: 1rem;
}

.manage-handle:active {
    cursor: grabbing;
}

.manage-drop-target.manage-drop-over {
    box-shadow:
        inset 0 0 0 2px var(--color-primary),
        0 2px 8px var(--color-shadow);
    background: var(--surface-overlay);
}

.manage-drag-source.is-dragging {
    opacity: 0.45;
}

.manage-delete-btn {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 1.6rem;
    height: 1.6rem;
    margin-left: auto;
    padding: 0;
    border: none;
    border-radius: 4px;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    transition: color 120ms ease, background-color 120ms ease;
}

.manage-delete-btn svg {
    width: 0.9rem;
    height: 0.9rem;
}

.manage-delete-btn:hover {
    color: var(--color-danger, #c53030);
    background: var(--surface-overlay);
}

label {
    display: block;
    margin: 0 0 0.45rem;
    color: var(--text-secondary);
    font-size: 0.95rem;
    font-weight: 650;
}

textarea,
input[type="text"],
input[type="search"],
input[type="password"],
input[type="file"] {
    width: 100%;
    max-width: 100%;
    padding: 0.8rem 0.95rem;
    border: 1px solid var(--color-border);
    border-radius: 12px;
    background: var(--input-bg);
    color: var(--text-primary);
    box-shadow: inset 0 1px 0 rgb(255 255 255 / 0.03);
    transition:
        border-color 120ms ease,
        box-shadow 120ms ease,
        background-color 120ms ease;
}

textarea {
    min-height: 400px;
    font-family: "Monaco", "Menlo", "Ubuntu Mono", monospace;
    font-size: 0.94rem;
    line-height: 1.5;
    resize: vertical;
}

input[type="file"] {
    padding: 0.65rem 0.75rem;
}

input::placeholder,
textarea::placeholder {
    color: var(--text-muted);
}

textarea:hover,
input[type="text"]:hover,
input[type="search"]:hover,
input[type="password"]:hover,
input[type="file"]:hover {
    border-color: var(--input-border-hover);
}

textarea:focus,
input[type="text"]:focus,
input[type="search"]:focus,
input[type="password"]:focus,
input[type="file"]:focus,
button:focus-visible,
a:focus-visible {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 4px var(--focus-ring);
}

button {
    background: var(--color-success);
    color: var(--button-text);
    padding: 0.8rem 1.2rem;
    border: 1px solid transparent;
    border-radius: 12px;
    font-size: 0.98rem;
    font-weight: 650;
    letter-spacing: -0.01em;
    cursor: pointer;
    margin-top: 0.9rem;
    transition:
        background-color 120ms ease,
        color 120ms ease,
        border-color 120ms ease,
        transform 120ms ease;
}

button:hover {
    background: var(--color-success-hover);
}

button:active {
    transform: translateY(1px);
}

input[readonly],
textarea[readonly] {
    background: var(--surface-elevated);
}

code {
    background: var(--accent-highlight-soft);
    color: var(--color-highlight-ink);
    padding: 0.16rem 0.42rem;
    border-radius: 8px;
    font-family: "Monaco", "Menlo", "Ubuntu Mono", monospace;
    font-size: 0.9em;
}

pre {
    background: var(--color-code-bg);
    padding: 1rem 1.1rem;
    border-radius: 16px;
    overflow-x: auto;
    box-shadow: inset 0 0 0 1px var(--color-border-soft);
}

pre code {
    background: transparent;
    padding: 0;
    border-radius: 0;
    box-shadow: none;
}

.notice,
.upload-card,
.reorder-page,
.pdf-viewer-frame,
.git-diff,
.todo-quick-add,
.reorder-empty,
#push-status:empty,
#push-status:not(:empty) {
    border-radius: 16px;
}

.notice {
    background: var(--color-notice-bg);
    color: var(--color-notice-text);
    padding: 0.9rem 1rem;
    box-shadow: inset 0 0 0 1px var(--color-notice-outline);
}

.upload-card {
    padding: 1.15rem;
    background: var(--surface-elevated);
    box-shadow:
        inset 0 0 0 1px var(--color-border-soft),
        0 14px 30px -26px var(--color-shadow-strong);
}

.upload-field {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: center;
}

.upload-field > * {
    flex: 1 1 220px;
}

.upload-field button {
    flex: 0 0 auto;
    margin-top: 0;
}

.upload-status {
    min-height: 1.3rem;
    margin-top: 0.75rem;
    color: var(--text-secondary);
}

.upload-status[data-state="error"] {
    color: var(--color-secondary);
}

.upload-status[data-state="info"] {
    color: var(--text-secondary);
}

.upload-output {
    margin-top: 1rem;
    padding-top: 1rem;
}

.pdf-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.pdf-actions a {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 2.9rem;
    padding: 0.8rem 1.2rem;
    border-radius: 12px;
    background: var(--surface-elevated);
    color: var(--text-primary);
    font-weight: 650;
    text-decoration: none;
    box-shadow: inset 0 0 0 1px var(--color-border-soft);
}

.pdf-actions a:hover {
    background: var(--accent-primary-soft);
    color: var(--color-primary);
}

.pdf-viewer-frame {
    display: block;
    width: 100%;
    min-height: 70vh;
    border: 1px solid var(--color-border);
    background: var(--surface-overlay);
    box-shadow:
        inset 0 1px 0 rgb(255 255 255 / 0.03),
        0 18px 34px -28px var(--color-shadow-strong);
}

.todo-checkbox {
    margin-right: 0.5rem;
    transform: translateY(1px);
    accent-color: var(--color-success);
}

.todo-checkbox:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}

.todo-quick-add {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.75rem;
    margin: 0.85rem 0 1.25rem 1.4rem;
    padding: 0.85rem 0.95rem;
    background: var(--surface-elevated);
    box-shadow: inset 0 0 0 1px var(--color-border-soft);
}

.todo-quick-add label {
    margin: 0;
}

.todo-quick-add input[type="text"] {
    flex: 1;
    min-width: 200px;
}

.todo-quick-add button {
    margin-top: 0;
    padding: 0.68rem 1rem;
    font-size: 0.92rem;
}

.reorder-page {
    padding: 1rem;
    background: var(--surface-elevated);
    box-shadow:
        inset 0 0 0 1px var(--color-border-soft),
        0 14px 30px -26px var(--color-shadow-strong);
}

.reorder-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.65rem;
    align-items: center;
    margin-bottom: 1rem;
}

.reorder-toolbar-label {
    color: var(--color-secondary);
    font-size: 0.94rem;
    font-weight: 650;
}

.reorder-mode-toggle {
    background: var(--surface-overlay);
    border: 1px solid var(--color-border);
    color: var(--text-secondary);
    padding: 0.5rem 0.85rem;
    border-radius: 999px;
    font-size: 0.9rem;
    margin-top: 0;
    box-shadow: none;
}

.reorder-mode-toggle:hover {
    background: var(--surface-row);
    color: var(--text-primary);
}

.reorder-mode-toggle[aria-pressed="true"] {
    background: var(--color-secondary);
    border-color: transparent;
    color: var(--button-text);
}

.reorder-empty {
    padding: 1rem;
    color: var(--text-secondary);
    background: var(--surface-overlay);
    box-shadow: inset 0 0 0 1px var(--color-border-soft);
}

.reorder-list {
    display: grid;
    gap: 0.6rem;
}

.reorder-page[data-mode="block"] .reorder-list-line {
    display: none;
}

.reorder-page[data-mode="line"] .reorder-list-block {
    display: none;
}

.reorder-row {
    display: grid;
    grid-template-columns: 2.4rem 4rem 1fr;
    gap: 0.75rem;
    align-items: start;
    padding: 0.65rem 0.8rem;
    border-radius: 14px;
    font-family: "Monaco", "Menlo", "Ubuntu Mono", monospace;
    font-size: 0.9rem;
    min-height: 1.35em;
    background: var(--surface-overlay);
    box-shadow: inset 0 0 0 1px var(--color-border-soft);
}

.reorder-row-handle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.95rem;
    height: 1.95rem;
    border: 1px solid transparent;
    border-radius: 10px;
    background: var(--surface-handle);
    color: var(--text-secondary);
    font: inherit;
    font-weight: 700;
    letter-spacing: 0.1em;
    cursor: grab;
    user-select: none;
    touch-action: none;
    -webkit-touch-callout: none;
}

.reorder-row-handle:hover {
    background: var(--surface-handle-active);
    color: var(--text-primary);
}

.reorder-row-handle:active,
.reorder-row.is-dragging .reorder-row-handle {
    cursor: grabbing;
}

.reorder-row.is-dragging {
    opacity: 0.45;
}

.reorder-row.drop-before {
    box-shadow:
        inset 0 3px 0 0 var(--color-primary),
        inset 0 0 0 1px var(--color-border-soft);
}

.reorder-row.drop-after {
    box-shadow:
        inset 0 -3px 0 0 var(--color-primary),
        inset 0 0 0 1px var(--color-border-soft);
}

.reorder-row-meta {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    align-items: flex-end;
    color: var(--text-muted);
    user-select: none;
}

.reorder-row-range {
    text-align: right;
}

.reorder-row-kind {
    font-size: 0.75em;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--color-highlight-ink);
}

.reorder-row-text,
.reorder-row-text-inline {
    margin: 0;
    white-space: pre-wrap;
    word-break: break-word;
    font-family: inherit;
    color: var(--text-primary);
}

.reorder-row.is-blank .reorder-row-text::before {
    content: "(blank)";
    color: var(--text-muted);
}

.search-form,
.git-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: flex-start;
}

.search-form button,
.git-actions button {
    margin-top: 0;
}

.git-actions form {
    margin-bottom: 0;
}

.search-form input[type="text"] {
    flex: 1;
    min-width: 200px;
    font-size: 1rem;
}

.search-results,
.git-new-files {
    padding-left: 1.2rem;
}

.search-results li,
.git-new-files li {
    padding: 0.35rem 0;
}

.snippet {
    color: var(--text-secondary);
    font-size: 0.95rem;
    margin-top: 0.25rem;
}

table {
    width: 100%;
    margin: 1.25rem 0;
    border-collapse: separate;
    border-spacing: 0;
    overflow: hidden;
    border-radius: 14px;
    box-shadow: inset 0 0 0 1px var(--color-border-strong);
}

th,
td {
    padding: 0.8rem 0.9rem;
    text-align: left;
    border-bottom: 1px solid var(--color-border);
}

th + th,
td + td {
    border-left: 1px solid var(--color-border);
}

th {
    background: var(--surface-elevated);
    color: var(--color-primary);
    font-weight: 620;
}

tr {
    background: var(--surface-overlay);
}

tr:nth-child(even) {
    background: var(--surface-row);
}

tr:last-child td {
    border-bottom: none;
}

blockquote {
    padding: 0.8rem 1rem;
    border-left: 4px solid var(--color-secondary);
    background: var(--surface-elevated);
    color: var(--text-secondary);
    border-radius: 0 14px 14px 0;
}

mark {
    background: var(--accent-highlight-soft);
    color: var(--color-highlight-ink);
    padding: 0.06rem 0.22rem;
    border-radius: 6px;
}

.mermaid,
.abc-notation {
    margin: 1.25rem 0;
    overflow-x: auto;
    padding: 0.75rem;
    border-radius: 16px;
    background: var(--surface-elevated);
}

.mermaid svg,
.abc-notation svg {
    max-width: 100%;
    height: auto;
}

.abc-render-error,
.math-error {
    background: var(--color-code-bg);
    color: var(--text-secondary);
    padding: 0.75rem;
    border-radius: 14px;
    box-shadow: inset 0 0 0 1px var(--color-border-soft);
    white-space: pre-wrap;
}

/* Math rendering */
math {
    font-size: 1.1em;
}

math[display="block"] {
    display: block;
    text-align: center;
    margin: 1rem 0;
    overflow-x: auto;
}

code.math-error {
    padding: 0.2rem 0.4rem;
    border-radius: 8px;
}

pre.math-error {
    padding: 1rem;
    text-align: center;
    margin: 1rem 0;
}

#push-status {
    min-height: 1.25rem;
    margin-bottom: 1rem;
}

#push-status:not(:empty) {
    padding: 0.9rem 1rem;
    background: var(--surface-elevated);
    color: var(--text-secondary);
    box-shadow: inset 0 0 0 1px var(--color-border-soft);
}

.search-form button,
[data-copy-url],
[data-copy-markdown],
#copy-button {
    background: var(--color-highlight);
    color: var(--color-highlight-text);
}

.search-form button:hover,
[data-copy-url]:hover,
[data-copy-markdown]:hover,
#copy-button:hover {
    background: var(--color-highlight-ink);
    color: var(--surface-base);
}

#test-button {
    background: var(--color-secondary);
}

#test-button:hover {
    background: var(--color-secondary-hover);
}

form p {
    color: var(--text-secondary);
}

hr {
    border: 0;
    height: 1px;
    background: var(--color-border);
    margin: 1.75rem 0;
}

/* Magent responses */
.magent-response {
    padding: 0.8rem 1rem;
    border-left: 4px solid var(--color-primary);
    background: var(--surface-elevated);
    border-radius: 0 14px 14px 0;
    margin-bottom: 1.25rem;
}

.magent-response > :last-child {
    margin-bottom: 0;
}

.magent-thinking,
.magent-tool-call,
.magent-tool-result {
    margin-bottom: 0.75rem;
    border-radius: 12px;
    background: var(--color-code-bg);
    box-shadow: inset 0 0 0 1px var(--color-border-soft);
}

.magent-thinking > summary,
.magent-tool-call > summary,
.magent-tool-result > summary {
    padding: 0.5rem 0.75rem;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    list-style: none;
}

.magent-thinking > summary::before,
.magent-tool-call > summary::before,
.magent-tool-result > summary::before {
    content: "\25b6";
    display: inline-block;
    margin-right: 0.45rem;
    font-size: 0.65em;
    transition: transform 150ms ease;
}

.magent-thinking[open] > summary::before,
.magent-tool-call[open] > summary::before,
.magent-tool-result[open] > summary::before {
    transform: rotate(90deg);
}

.magent-thinking[open],
.magent-tool-call[open],
.magent-tool-result[open] {
    padding-bottom: 0.75rem;
}

.magent-thinking > :not(summary),
.magent-tool-call > :not(summary),
.magent-tool-result > :not(summary) {
    padding: 0 0.75rem;
}

.magent-thinking > :not(summary):last-child,
.magent-tool-call > :not(summary):last-child,
.magent-tool-result > :not(summary):last-child {
    margin-bottom: 0;
}

.magent-input pre,
.magent-result pre {
    margin-bottom: 0;
}

.magent-edit {
    margin-bottom: 0.75rem;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: inset 0 0 0 1px var(--color-border-soft);
}

.magent-edit-search,
.magent-edit-replace {
    padding: 0.5rem 0.75rem;
}

.magent-edit-search {
    background: var(--syntax-deletion-bg);
}

.magent-edit-replace {
    background: var(--syntax-addition-bg);
}

.magent-edit-search pre,
.magent-edit-replace pre {
    margin-bottom: 0;
    background: transparent;
    box-shadow: none;
    padding: 0.25rem 0;
}

.magent-accept-btn {
    margin: 0.5rem 0.75rem 0.75rem;
    padding: 0.45rem 0.9rem;
    font-size: 0.88rem;
    border-radius: 10px;
    width: auto;
}

.magent-edit[data-status="accepted"] {
    opacity: 0.55;
}

.magent-edit[data-status="accepted"] .magent-accept-btn {
    background: var(--color-border);
    cursor: default;
    pointer-events: none;
}

/* Agent view */
.agent-page {
    max-width: var(--page-width);
    margin: 0 auto;
}

.agent-block {
    position: relative;
    padding: 0.25rem 0 0.25rem 1.75rem;
}

.agent-block > :last-child {
    margin-bottom: 0;
}

.agent-block-directive {
    position: relative;
}

.magent-remove-btn {
    position: absolute;
    top: 0.25rem;
    right: 0;
    width: 1.5rem;
    height: 1.5rem;
    font-size: 1rem;
    line-height: 1;
    border: none;
    background: transparent;
    color: var(--color-text-muted);
    cursor: pointer;
    border-radius: 4px;
    padding: 0;
}

.magent-remove-btn:hover {
    color: #c0392b;
    background: rgba(192, 57, 43, 0.1);
}

.agent-insert-btn {
    position: absolute;
    left: 0;
    bottom: 0;
    width: 1.25rem;
    height: 1.25rem;
    font-size: 0.8rem;
    line-height: 1;
    border: 1px solid var(--color-border);
    background: transparent;
    color: var(--color-text-muted);
    cursor: pointer;
    border-radius: 4px;
    opacity: 0.4;
    transition: opacity 0.15s;
}

.agent-insert-btn:hover {
    opacity: 1;
    background: var(--color-bg-alt);
    border-color: var(--color-primary);
    color: var(--color-primary);
}

.agent-insert-form {
    padding: 0.5rem 0;
}

.agent-insert-input {
    width: 100%;
    padding: 0.5rem;
    font-family: inherit;
    font-size: inherit;
    border: 1px solid var(--color-border);
    border-radius: 4px;
    background: var(--color-bg);
    color: var(--color-text);
    resize: vertical;
    box-sizing: border-box;
}

.agent-insert-input:focus {
    outline: none;
    border-color: var(--color-primary);
}

.agent-insert-actions {
    display: flex;
    justify-content: flex-end;
    margin-top: 0.35rem;
}

.agent-insert-submit {
    padding: 0.3rem 0.8rem;
    font-size: 0.85rem;
    border: 1px solid var(--color-primary);
    border-radius: 4px;
    background: var(--color-primary);
    color: #fff;
    cursor: pointer;
}

.agent-insert-submit:hover {
    opacity: 0.9;
}

.agent-insert-submit:disabled {
    opacity: 0.5;
    cursor: default;
}

.agent-bottom-input {
    margin-top: 1rem;
    padding-left: 1.75rem;
}

.agent-empty {
    color: var(--color-text-muted);
    font-style: italic;
    padding: 1rem 0;
}

/* Diff gutter markers */
.diff-added {
    border-left: 3px solid var(--syntax-addition);
    padding-left: 0.75rem;
}

.diff-modified {
    border-left: 3px solid var(--diff-modified);
    padding-left: 0.75rem;
}

.diff-deleted-marker {
    height: 0;
    border-top: 2px solid var(--syntax-deletion);
    margin: 0.25rem 0;
}

/* Mobile responsiveness */
@media (max-width: 600px) {
    body {
        padding: 0.65rem 0.6rem 1.4rem;
        font-size: 16px;
    }

    .nav {
        gap: 0.5rem;
        padding: 0.7rem;
        margin-bottom: 1.4rem;
        border-radius: 16px;
    }

    .nav a,
    .theme-toggle,
    .pwa-refresh {
        min-height: 2.2rem;
        padding-inline: 0.62rem;
        font-size: 0.92rem;
    }

    .nav .theme-toggle,
    .nav .pwa-refresh {
        width: auto;
    }

    h1 {
        font-size: 1.75rem;
        margin-bottom: 1rem;
    }

    h2 {
        font-size: 1.35rem;
        padding-left: 0.7rem;
    }

    h3 {
        font-size: 0.95rem;
    }

    textarea {
        min-height: 300px;
        font-size: 16px;
    }

    button {
        width: 100%;
        padding: 0.9rem 1rem;
    }

    .search-form,
    .git-actions,
    .pdf-actions,
    .upload-field,
    .todo-quick-add,
    .reorder-toolbar {
        flex-direction: column;
        align-items: stretch;
    }

    .pdf-actions a,
    .upload-field button,
    .todo-quick-add button,
    .reorder-mode-toggle {
        width: 100%;
    }

    .reorder-page {
        padding: 0.8rem;
    }

    .reorder-row {
        grid-template-columns: 2.2rem 3.25rem 1fr;
        gap: 0.55rem;
        padding: 0.65rem;
    }

    table {
        font-size: 0.92rem;
    }

    th,
    td {
        padding: 0.65rem;
    }
}
