:root {
    color-scheme: light;
    --bg: #f6f7f9;
    --surface: #ffffff;
    --ink: #1f2328;
    --muted: #656d76;
    --line: #d8dee4;
    --line-soft: #eaeef2;
    --indigo: #3730a3;
    --indigo-hover: #2e2787;
    --indigo-soft: #eef2ff;
    --orange: #f97316;
    --orange-hover: #ea580c;
    --orange-soft: #fff7ed;
    --green: #16794c;
    --red: #b42318;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family:
        -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial,
        sans-serif;
    font-size: 14px;
    line-height: 1.5;
}

button,
input {
    font: inherit;
}

button {
    border: 1px solid transparent;
    border-radius: 8px;
    background: var(--indigo);
    color: #fff;
    cursor: pointer;
    font-weight: 600;
    transition:
        background-color 150ms ease,
        border-color 150ms ease,
        color 150ms ease;
}

button:hover {
    background: var(--indigo-hover);
}

input {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    color: var(--ink);
}

input:focus {
    border-color: var(--indigo);
    box-shadow: 0 0 0 3px rgba(55, 48, 163, 0.16);
    outline: none;
}

h1,
h2,
p {
    margin-top: 0;
}

.lookup-page {
    display: grid;
    min-height: 100vh;
    place-items: center;
    padding: 32px 16px;
}

.lookup-card {
    width: min(760px, 100%);
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.lookup-copy {
    padding: 32px 32px 20px;
    border-bottom: 1px solid var(--line-soft);
}

.lookup-copy h1 {
    margin-bottom: 12px;
    font-size: 32px;
    line-height: 1.2;
}

.lookup-copy p {
    max-width: 640px;
    margin-bottom: 12px;
    color: var(--muted);
    font-size: 16px;
}

.lookup-form {
    padding: 24px 32px 32px;
}

.lookup-form label,
.header-search label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
}

.lookup-form input {
    height: 44px;
    padding: 0 12px;
}

.lookup-form button {
    background: var(--orange);
    width: 100%;
    min-height: 44px;
    margin-top: 12px;
}

.lookup-form button:hover {
    background: var(--orange-hover);
}

.lookup-form p {
    margin: 10px 0 0;
    color: var(--muted);
}

.message {
    margin: 0 32px 32px;
    padding: 16px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #fff;
}

.message h2 {
    margin-bottom: 6px;
    font-size: 18px;
}

.message p {
    margin-bottom: 0;
    color: var(--muted);
}

.error-message {
    border-color: #f1b4af;
    background: #fff8f7;
}

.error-message h2 {
    color: var(--red);
}

.top-nav {
    display: flex;
    min-height: 56px;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    border-bottom: 1px solid var(--line);
    background: var(--surface);
    padding: 0 24px;
}

.brand-link {
    color: var(--indigo);
    font-size: 18px;
    font-weight: 700;
    text-decoration: none;
}

.external-link {
    color: var(--muted);
    font-size: 13px;
    text-decoration: none;
}

.external-link:hover {
    color: var(--indigo);
    text-decoration: underline;
}

.content {
    width: min(1200px, calc(100% - 48px));
    min-width: 0;
    margin: 0 auto;
    padding: 24px 0;
}

.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 24px;
    margin-bottom: 20px;
}

.page-header h1 {
    margin-bottom: 4px;
    font-size: 28px;
    line-height: 1.2;
}

.page-header p {
    margin-bottom: 0;
    color: var(--muted);
}

.header-search {
    width: 380px;
}

.header-search div {
    display: flex;
    gap: 8px;
}

.header-search input {
    height: 38px;
    padding: 0 10px;
}

.header-search button {
    min-width: 84px;
    min-height: 38px;
}

.content > .message {
    margin: 0;
}

.explorer {
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--surface);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.explorer-head {
    display: grid;
    grid-template-columns: minmax(280px, 1fr) 160px 124px;
    gap: 12px;
    padding: 10px 16px;
    border-bottom: 1px solid var(--line);
    background: #f6f8fa;
    color: var(--muted);
    font-size: 13px;
    font-weight: 600;
}

.folder {
    border-bottom: 1px solid var(--line-soft);
}

.folder:last-child {
    border-bottom: 0;
}

summary {
    display: grid;
    grid-template-columns: 20px 20px minmax(0, 1fr) auto;
    gap: 8px;
    align-items: center;
    min-height: 44px;
    padding: 0 16px;
    list-style: none;
    cursor: pointer;
}

summary::-webkit-details-marker {
    display: none;
}

summary:hover,
.file-row:hover {
    background: #f6f8fa;
}

.twisty::before {
    content: "+";
    display: inline-grid;
    width: 16px;
    height: 16px;
    place-items: center;
    border: 1px solid var(--line);
    border-radius: 4px;
    color: var(--muted);
    font-size: 12px;
}

.folder[open] > summary .twisty::before {
    content: "-";
}

.folder-icon,
.file-icon {
    display: inline-flex;
    width: 20px;
    height: 20px;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--line);
    border-radius: 4px;
    background: #f6f8fa;
    color: var(--muted);
}

.folder-icon {
    display: inline-block;
    height: 14px;
    align-self: center;
    position: relative;
    border-color: #d6a33f;
    background: #f7c768;
}

.folder-icon::before {
    content: "";
    position: absolute;
    top: -5px;
    left: 2px;
    width: 9px;
    height: 5px;
    border: 1px solid #d6a33f;
    border-bottom: 0;
    border-radius: 4px 4px 0 0;
    background: #f8d27c;
}

.html-icon {
    border-color: #f2b087;
    background: #fff4ed;
    color: var(--orange);
}

.audio-icon {
    border-color: #9bd5b5;
    background: #effaf4;
    color: var(--green);
}

.source-icon {
    border-color: #a9c1f7;
    background: #eef4ff;
    color: var(--indigo);
}

.pdf-icon {
    border-color: #f1b4af;
    background: #fff8f7;
    color: var(--red);
}

.image-icon {
    border-color: #a9c1f7;
    background: #eef4ff;
    color: var(--indigo);
}

.video-icon,
.youtube-icon {
    border-color: #f1b4af;
    background: #fff8f7;
    color: #c2410c;
}

.text-icon,
.unknown-icon {
    border-color: var(--line);
    background: #f6f8fa;
    color: var(--muted);
}

.document-icon {
    border-color: #c7c2f0;
    background: var(--indigo-soft);
    color: var(--indigo);
}

.presentation-icon {
    border-color: #fed7aa;
    background: var(--orange-soft);
    color: var(--orange);
}

.spreadsheet-icon {
    border-color: #9bd5b5;
    background: #effaf4;
    color: var(--green);
}

.link-icon {
    border-color: #c7c2f0;
    background: var(--indigo-soft);
    color: var(--indigo);
}

.file-icon svg {
    width: 15px;
    height: 15px;
    fill: currentColor;
}

.node-name,
.file-name {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.node-name {
    font-weight: 600;
}

.node-meta,
.file-type {
    color: var(--muted);
    font-size: 13px;
}

.children {
    padding-bottom: 6px;
}

.file-row {
    display: grid;
    grid-template-columns: 34px 20px minmax(0, 1fr) 160px 124px;
    gap: 8px;
    align-items: center;
    min-height: 38px;
    padding: 0 16px;
}

.connector {
    align-self: stretch;
    border-right: 1px solid var(--line-soft);
}

.file-actions {
    display: flex;
    justify-content: flex-end;
    gap: 6px;
}

.icon-button,
.icon-link {
    display: inline-flex;
    width: 28px;
    height: 28px;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    color: var(--muted);
    padding: 0;
    text-decoration: none;
}

.icon-button:hover,
.icon-link:hover {
    border-color: #c7c2f0;
    background: var(--indigo-soft);
    color: var(--indigo);
}

.icon-button.copied {
    border-color: #9bd5b5;
    background: #effaf4;
    color: var(--green);
}

.icon-button svg,
.icon-link svg {
    width: 16px;
    height: 16px;
    fill: currentColor;
}

.hidden-note {
    display: none;
}

.preview-modal {
    width: min(920px, calc(100% - 32px));
    max-height: min(760px, calc(100% - 32px));
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 0;
    box-shadow: var(--shadow);
}

.preview-modal.audio-modal {
    width: min(420px, calc(100% - 32px));
}

.preview-modal::backdrop {
    background: rgba(31, 35, 40, 0.42);
}

.modal-titlebar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--line);
}

.modal-titlebar button {
    min-height: 32px;
    padding: 0 12px;
}

.modal-body {
    min-height: 280px;
    max-height: calc(100vh - 120px);
    overflow: auto;
    padding: 20px;
}

.audio-modal .modal-body {
    display: grid;
    min-height: 280px;
    place-items: center;
    padding: 12px;
}

.modal-body iframe,
.modal-body video,
.modal-body audio,
.modal-body img {
    width: 100%;
    max-width: 100%;
}

.modal-body iframe {
    min-height: 70vh;
    border: 1px solid var(--line);
    border-radius: 8px;
}

.modal-body img {
    height: auto;
}

.note-preview img {
    max-width: 100%;
}

.note-preview {
    color: var(--ink);
    font-size: 15px;
    line-height: 1.65;
}

.note-preview > *:first-child {
    margin-top: 0;
}

.note-preview > *:last-child {
    margin-bottom: 0;
}

.note-preview h1,
.note-preview h2,
.note-preview h3,
.note-preview h4,
.note-preview h5,
.note-preview h6 {
    margin: 24px 0 10px;
    color: var(--ink);
    line-height: 1.25;
}

.note-preview h1 {
    font-size: 28px;
}

.note-preview h2 {
    font-size: 22px;
}

.note-preview h3 {
    font-size: 18px;
}

.note-preview p,
.note-preview ul,
.note-preview ol,
.note-preview blockquote,
.note-preview pre,
.note-preview table {
    margin: 0 0 16px;
}

.note-preview ul,
.note-preview ol {
    padding-left: 24px;
}

.note-preview li + li {
    margin-top: 4px;
}

.note-preview a {
    color: var(--indigo);
    text-decoration: underline;
    text-underline-offset: 2px;
}

.note-preview blockquote {
    border-left: 3px solid var(--orange);
    padding: 8px 14px;
    color: var(--muted);
    background: var(--orange-soft);
}

.note-preview code {
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 2px 5px;
    background: #f6f8fa;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.92em;
}

.note-preview pre {
    overflow: auto;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 12px;
    background: #f6f8fa;
}

.note-preview pre code {
    border: 0;
    padding: 0;
    background: transparent;
}

.note-preview table {
    width: 100%;
    border-collapse: collapse;
    overflow-wrap: anywhere;
}

.note-preview th,
.note-preview td {
    border: 1px solid var(--line);
    padding: 8px 10px;
    text-align: left;
    vertical-align: top;
}

.note-preview th {
    background: #f6f8fa;
    font-weight: 600;
}

.note-preview hr {
    height: 1px;
    margin: 24px 0;
    border: 0;
    background: var(--line);
}

.note-preview img,
.note-preview video,
.note-preview iframe {
    max-width: 100%;
    border-radius: 8px;
}

.note-preview .katex-display {
    overflow-x: auto;
    overflow-y: hidden;
    padding: 4px 0;
}

.audio-player {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--indigo);
    color: #fff;
    box-shadow: var(--shadow);
}

.audio-player audio {
    display: none;
}

.audio-art {
    display: flex;
    min-height: 240px;
    flex-direction: column;
    justify-content: space-between;
    padding: 28px 24px 22px;
}

.audio-play {
    display: inline-flex;
    width: 52px;
    height: 52px;
    min-height: 52px;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    border: 0;
    border-radius: 50%;
    background: #fff;
    color: var(--indigo);
    padding: 0;
}

.audio-play:hover {
    background: #f6f7f9;
}

.audio-play svg {
    width: 22px;
    height: 22px;
    fill: currentColor;
}

.audio-title {
    overflow: hidden;
    color: #fff;
    font-size: 24px;
    font-weight: 700;
    line-height: 1.2;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-align: center;
}

.audio-subtitle {
    margin-top: 4px;
    color: rgba(255, 255, 255, 0.72);
    font-size: 12px;
    text-align: center;
}

.audio-progress {
    margin-top: auto;
}

.audio-duration {
    flex: 0 0 auto;
    color: rgba(255, 255, 255, 0.72);
    font-size: 12px;
    font-variant-numeric: tabular-nums;
}

.audio-seek {
    width: 100%;
    height: 4px;
    padding: 0;
    border: 0;
    accent-color: var(--orange);
}

.audio-time {
    display: flex;
    justify-content: space-between;
    margin-top: 8px;
    color: rgba(255, 255, 255, 0.72);
    font-size: 12px;
    font-variant-numeric: tabular-nums;
}

.audio-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 18px;
    margin-top: 22px;
}

.audio-skip {
    display: inline-flex;
    width: 34px;
    height: 34px;
    min-height: 34px;
    align-items: center;
    justify-content: center;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: rgba(255, 255, 255, 0.82);
    padding: 0;
}

.audio-skip:hover {
    background: rgba(255, 255, 255, 0.1);
}

.audio-skip svg {
    width: 18px;
    height: 18px;
    fill: currentColor;
}

.audio-next {
    margin-top: 18px;
    color: rgba(255, 255, 255, 0.72);
    font-size: 12px;
    font-weight: 600;
    text-align: center;
}

@media (max-width: 900px) {
    .top-nav {
        align-items: center;
        flex-direction: row;
        gap: 12px;
        padding: 14px 16px;
    }

    .page-header {
        display: block;
    }

    .header-search {
        width: 100%;
        margin-top: 16px;
    }

    .explorer-head {
        display: none;
    }

    summary {
        grid-template-columns: 20px 20px minmax(0, 1fr);
    }

    .node-meta {
        grid-column: 3;
    }

    .file-row {
        grid-template-columns: 28px 20px minmax(0, 1fr);
        padding-top: 8px;
        padding-bottom: 8px;
    }

    .file-type,
    .file-actions {
        grid-column: 3;
    }

    .file-actions {
        justify-content: flex-start;
    }
}

@media (max-width: 560px) {
    .lookup-copy,
    .lookup-form {
        padding-left: 20px;
        padding-right: 20px;
    }

    .lookup-copy h1 {
        font-size: 28px;
    }

    .message {
        margin-left: 20px;
        margin-right: 20px;
    }

    .content {
        width: min(100% - 24px, 1200px);
        padding: 16px 0;
    }

    .header-search div {
        display: grid;
    }
}
