:root {
    --uhtomic-max: 76rem;
    --uhtomic-reading: 48rem;
    --uhtomic-line: color-mix(in oklab, var(--foreground) 16%, transparent);
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; }
a { text-underline-offset: .18em; }
.inline { display: inline; margin: 0; }
.cluster { display: flex; align-items: center; flex-wrap: wrap; gap: .65rem; }
.eyebrow { margin: 0 0 .45rem; color: var(--muted-foreground); font-size: .74rem; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; }
.form-error { color: var(--danger); font-weight: 650; }

.app-header {
    min-height: 3.75rem;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 1.5rem;
    padding: .65rem clamp(1rem, 3vw, 2.25rem);
    border-bottom: 1px solid var(--uhtomic-line);
    background: var(--background);
}
.app-header--guest { grid-template-columns: 1fr; }
.wordmark { color: inherit; font-family: Georgia, 'Times New Roman', serif; font-size: 1.45rem; font-weight: 700; letter-spacing: -.04em; text-decoration: none; }
.app-header nav { display: flex; gap: clamp(.8rem, 2.6vw, 1.65rem); }
.app-header nav a { color: var(--muted-foreground); font-size: .87rem; text-decoration: none; }
.app-header nav a[aria-current="page"] { color: inherit; font-weight: 700; }
.header-actions { justify-self: end; display: flex; align-items: center; gap: .6rem; }
.header-actions .button, .header-actions button { margin: 0; white-space: nowrap; }
.account-trigger span { margin-left: .2rem; color: var(--muted-foreground); }
.account-menu [popover] { padding: .3rem; }
.account-menu [popover] form { margin: 0; }
.account-menu [role="menuitem"] { min-height: 2.25rem; color: var(--foreground); text-decoration: none; border-radius: .2rem; }
.account-menu button[role="menuitem"] { border-color: transparent; font-weight: 400; }

.app-shell { width: min(calc(100% - 2rem), var(--uhtomic-max)); margin: 0 auto; padding: clamp(2rem, 5vw, 4rem) 0 5rem; }
.reading-shell { width: min(calc(100% - 2rem), 58rem); margin: 0 auto; padding: 2rem 0 5rem; }
.gallery-shell { width: min(calc(100% - 2rem), 92rem); margin: 0 auto; padding: clamp(2rem, 5vw, 4rem) 0 5rem; }
.narrow-shell { width: min(calc(100% - 2rem), var(--uhtomic-reading)); margin: 0 auto; padding: 4rem 0; }
.back-link { display: inline-block; margin-bottom: 2rem; color: var(--muted-foreground); font-size: .84rem; text-decoration: none; }
.page-heading { display: flex; justify-content: space-between; align-items: end; gap: 2rem; margin-bottom: 1.5rem; }
.page-heading h1, .empty-state h1, .error-shell h1 { margin: 0; letter-spacing: -.035em; }
.page-heading > p, .page-heading > div > p:last-child { color: var(--muted-foreground); }
.notes-heading, .search-heading { align-items: end; }
.note-search { width: min(100%, 31rem); margin: 0; }
.note-search label { display: block; margin-bottom: .35rem; color: var(--muted-foreground); font-size: .72rem; }
.note-search > div { display: flex; gap: .45rem; }
.note-search input, .note-search button { margin: 0; }
.note-search input { min-width: 0; }
.note-search button { white-space: nowrap; }
.empty-state { max-width: 38rem; padding: clamp(2rem, 7vw, 5rem) 0; }
.empty-state > p:not(.eyebrow) { color: var(--muted-foreground); font-size: 1.05rem; }
.note-list { border-top: 1px solid var(--uhtomic-line); }
.note-row { display: grid; grid-template-columns: minmax(8rem, 1fr) 5fr; gap: 1.5rem; padding: 1.3rem 0; border-bottom: 1px solid var(--uhtomic-line); }
.note-row time, .note-row small { color: var(--muted-foreground); font-size: .82rem; }
.note-time a { color: inherit; text-decoration: none; }
.note-row h2 { margin: 0 0 .35rem; font-family: Georgia, 'Times New Roman', serif; font-size: 1.25rem; font-weight: 500; }
.note-row h2 a { color: inherit; text-decoration: none; }
.note-row h2 a:hover { text-decoration: underline; }
.note-summary > p { max-width: 48rem; margin: .2rem 0 .8rem; color: var(--muted-foreground); font-family: Georgia, 'Times New Roman', serif; line-height: 1.55; }
.note-summary footer { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.note-pagination { display: flex; justify-content: space-between; gap: 1rem; padding-top: 1.25rem; }
.note-pagination a:last-child { margin-left: auto; }
.note-pills { display: flex; gap: .4rem; flex-wrap: wrap; }
.note-pills a { padding: .15rem .45rem; border-radius: .25rem; background: color-mix(in oklab, #436c50 11%, transparent); color: #355b41; font-size: .75rem; text-decoration: none; }
.note-pills a.person { background: color-mix(in oklab, #7a5c39 11%, transparent); color: #73532f; }

.note-full > header { display: flex; justify-content: space-between; align-items: start; gap: 2rem; padding-bottom: 1.5rem; border-bottom: 1px solid var(--uhtomic-line); }
.note-full h1 { max-width: 48rem; margin: 0; font-family: Georgia, 'Times New Roman', serif; font-size: clamp(2rem, 5vw, 3.65rem); font-weight: 400; line-height: 1.08; letter-spacing: -.045em; }
.note-byline { display: flex; flex-wrap: wrap; gap: .5rem 1.2rem; margin: 1rem 0 2.5rem; color: var(--muted-foreground); font-size: .82rem; }
.note-byline a { color: inherit; }
.note-prose { font-family: Georgia, 'Times New Roman', serif; font-size: clamp(1.02rem, 1.7vw, 1.15rem); line-height: 1.72; }
.note-prose > * { max-width: 46rem; }
.note-prose h1, .note-prose h2, .note-prose h3 { margin-top: 1.7em; line-height: 1.2; }
.note-prose blockquote { border-left: .2rem solid var(--uhtomic-line); padding-left: 1.2rem; color: var(--muted-foreground); }
.note-prose pre { overflow-x: auto; }
.note-full > .note-pills { margin-top: 2rem; }
.section-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; }
.section-heading h2, .related-notes h2 { font-family: Georgia, 'Times New Roman', serif; font-weight: 500; }
.attachment-section { margin-top: 3.5rem; padding-top: 1.5rem; border-top: 1px solid var(--uhtomic-line); }
.attachment-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(11rem, 1fr)); gap: .6rem; }
.attachment { position: relative; min-height: 9rem; overflow: hidden; border-radius: .25rem; background: color-mix(in oklab, currentColor 5%, transparent); color: inherit; text-decoration: none; }
.attachment img { width: 100%; height: 12rem; object-fit: cover; display: block; }
.attachment span { display: block; padding: .5rem .6rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .75rem; }
.attachment--file { display: flex; flex-direction: column; justify-content: end; padding: 1rem; }
.related-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 2rem; margin-top: 3rem; }
.related-notes { border-top: 1px solid var(--uhtomic-line); }
.related-notes ul { padding: 0; list-style: none; }
.related-notes li { display: flex; justify-content: space-between; gap: 1rem; padding: .55rem 0; border-bottom: 1px solid var(--uhtomic-line); }
.related-notes li time { color: var(--muted-foreground); font-size: .76rem; white-space: nowrap; }
.taxonomy-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(13rem, 1fr)); border-top: 1px solid var(--uhtomic-line); }
.taxonomy-item { display: flex; justify-content: space-between; padding: .85rem .5rem; border-bottom: 1px solid var(--uhtomic-line); color: inherit; text-decoration: none; }
.taxonomy-item small { color: var(--muted-foreground); }
.person-note { max-width: 46rem; margin: -1rem 0 2rem; padding: 1rem 1.2rem; border-left: .2rem solid var(--uhtomic-line); color: var(--muted-foreground); }
.gallery-grid { columns: 5 13rem; column-gap: .55rem; }
.gallery-item { position: relative; display: block; break-inside: avoid; margin: 0 0 .55rem; overflow: hidden; border-radius: .2rem; background: color-mix(in oklab, currentColor 5%, transparent); }
.gallery-item img { display: block; width: 100%; height: auto; }
.gallery-item span { position: absolute; inset: auto 0 0; padding: 2rem .65rem .55rem; background: linear-gradient(transparent, rgba(0,0,0,.68)); color: white; font-size: .72rem; opacity: 0; transition: opacity .16s ease; }
.gallery-item:hover span, .gallery-item:focus span { opacity: 1; }
.empty-copy { padding: 2rem 0; color: var(--muted-foreground); }
.archive-years { border-top: 1px solid var(--uhtomic-line); }
.archive-year { display: grid; grid-template-columns: minmax(8rem, 1fr) 5fr; gap: 1.5rem; padding: 1.4rem 0; border-bottom: 1px solid var(--uhtomic-line); }
.archive-year h2 { margin: 0; font-family: Georgia, 'Times New Roman', serif; font-weight: 500; }
.archive-year ul { margin: 0; padding: 0; list-style: none; }
.archive-year li + li { border-top: 1px solid var(--uhtomic-line); }
.archive-year a { display: flex; justify-content: space-between; gap: 1rem; padding: .65rem 0; color: inherit; text-decoration: none; }
.archive-year a:hover span { text-decoration: underline; }
.archive-year small { color: var(--muted-foreground); }

.editor-shell { width: min(calc(100% - 2rem), 64rem); margin: 0 auto; padding: 1.5rem 0 5rem; }
.editor-topline { min-height: 2rem; display: flex; justify-content: space-between; align-items: start; gap: 1rem; }
.editor-topline .back-link { margin: 0; }
#save-status { color: var(--muted-foreground); font-size: .78rem; }
#save-status[data-state="saved"] { color: #28673d; font-weight: 650; }
#save-status[data-state="error"] { color: #a22626; font-weight: 650; }
.rich-editor { min-height: 20rem; margin-top: 1.5rem; padding: clamp(1rem, 3vw, 2rem); border: 1px solid var(--uhtomic-line); border-radius: .35rem; background: var(--background); font-family: Georgia, 'Times New Roman', serif; font-size: 1.08rem; line-height: 1.65; }
.rich-editor:focus-within { border-color: color-mix(in oklab, currentColor 40%, transparent); box-shadow: 0 0 0 2px color-mix(in oklab, currentColor 8%, transparent); }
.rich-editor .tiptap { min-height: 17rem; outline: 0; }
.rich-editor .tiptap > *:first-child { margin-top: 0; }
.rich-editor .tiptap p.is-editor-empty:first-child::before { float: left; height: 0; color: var(--muted-foreground); content: attr(data-placeholder); pointer-events: none; }
.editor-help { margin: .6rem 0 1.2rem; color: var(--muted-foreground); font-size: .74rem; }
.editor-assets { margin: 1.1rem 0; padding: .75rem; border: 1px solid var(--uhtomic-line); border-radius: .3rem; }
.editor-assets .section-heading { margin-bottom: .5rem; }
.editor-assets .section-heading h2 { font-size: .82rem; }
.editor-asset { display: grid; grid-template-columns: 3rem minmax(0, 1fr) auto; align-items: center; gap: .7rem; padding: .45rem 0; border-top: 1px solid var(--uhtomic-line); font-size: .78rem; }
.editor-asset img, .editor-asset-file { width: 3rem; height: 2.5rem; border-radius: .2rem; object-fit: cover; background: color-mix(in oklab, currentColor 5%, transparent); }
.editor-asset-file { display: grid; place-items: center; font-size: .65rem; font-weight: 750; }
.editor-asset > span:nth-child(2) { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.editor-asset button { margin: 0; padding: .3rem .5rem; font-size: .7rem; }
.attachment-picker { display: flex; width: 100%; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1.1rem; padding: .75rem 1rem; border: 1px dashed var(--uhtomic-line); border-radius: .3rem; background: transparent; color: inherit; font-weight: 400; text-align: left; cursor: pointer; }
.attachment-picker:focus-visible { outline: 2px solid var(--foreground); outline-offset: 2px; }
.attachment-input { position: absolute; inline-size: 1px; block-size: 1px; opacity: 0; }
.attachment-picker small { color: var(--muted-foreground); }
.pending-attachments { margin: -0.55rem 0 1.1rem; border-top: 1px solid var(--uhtomic-line); }
.pending-attachments > div { display: flex; align-items: center; justify-content: space-between; gap: 1rem; min-height: 2.7rem; border-bottom: 1px solid var(--uhtomic-line); font-size: .78rem; }
.pending-attachments span { min-width: 0; overflow: hidden; color: var(--muted-foreground); text-overflow: ellipsis; white-space: nowrap; }
.pending-attachments button { margin: 0; padding: .3rem .5rem; font-size: .72rem; }
.note-metadata { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)) auto; align-items: end; gap: .85rem; padding: 1rem; }
.note-metadata label { margin: 0; }
.switch-row { padding-bottom: .7rem; white-space: nowrap; }
.editor-actions { display: flex; justify-content: flex-end; gap: .65rem; margin-top: 1rem; }
.editor-actions .button, .editor-actions button { margin: 0; }
.delete-note { margin-top: 2.5rem; padding-top: 1.25rem; border-top: 1px solid var(--uhtomic-line); text-align: right; }
.import-shell { padding: 2rem 0 5rem; }
.import-shell > section:first-of-type { margin: 2rem 0 1.5rem; }
.import-shell form { margin: 1.5rem 0; padding: 1.25rem; border: 1px solid var(--uhtomic-line); border-radius: .35rem; }
.import-shell form small, .import-report .muted { color: var(--muted-foreground); }
.import-report { margin-top: 2rem; padding-top: 1.5rem; border-top: 1px solid var(--uhtomic-line); }
.import-report dl { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1px; overflow: hidden; border: 1px solid var(--uhtomic-line); border-radius: .3rem; background: var(--uhtomic-line); }
.import-report dl div { min-width: 0; padding: .75rem; background: var(--background); }
.import-report dt { color: var(--muted-foreground); font-size: .72rem; }
.import-report dd { margin: .25rem 0 0; font-weight: 700; overflow-wrap: anywhere; }
.tag-mention, .person-mention { display: inline-block; border-radius: .22rem; padding: 0 .2rem; }
.tag-mention { background: color-mix(in oklab, #436c50 13%, transparent); color: #355b41; }
.person-mention { background: color-mix(in oklab, #7a5c39 13%, transparent); color: #73532f; }
.note-link { color: #315f73; text-decoration-style: dotted; text-underline-offset: .18em; }
.note-link-pending { color: #806223; }
.suggestion-popup, .note-link-picker { z-index: 1000; max-height: 18rem; overflow-y: auto; min-width: 15rem; padding: .3rem; border: 1px solid var(--uhtomic-line); border-radius: .35rem; background: var(--background); box-shadow: 0 .5rem 1.5rem rgba(0,0,0,.14); font-family: ui-sans-serif, sans-serif; font-size: .85rem; }
.suggestion-item { padding: .5rem .65rem; border-radius: .25rem; cursor: pointer; }
.suggestion-item.is-selected, .suggestion-item:hover { background: color-mix(in oklab, currentColor 8%, transparent); }
.suggestion-item-create { display: flex; gap: .5rem; }
.suggestion-item-prefix { color: var(--muted-foreground); }
.tiptap-bubble-menu { position: fixed; z-index: 1001; display: none; padding: .25rem; border: 1px solid var(--uhtomic-line); border-radius: .3rem; background: #222; color: #fff; box-shadow: 0 .4rem 1.2rem rgba(0,0,0,.18); }
.tiptap-bubble-menu-button { margin: 0; padding: .35rem .55rem; border: 0; background: transparent; color: inherit; font-size: .75rem; }

.login-shell { width: min(calc(100% - 2rem), 58rem); min-height: calc(100vh - 3.75rem); margin: 0 auto; display: grid; grid-template-columns: 1fr minmax(18rem, 24rem); align-items: center; gap: clamp(2rem, 8vw, 7rem); padding: 3rem 0; }
.login-shell section h1 { margin: 0 0 .7rem; font-family: Georgia, 'Times New Roman', serif; font-size: clamp(2.5rem, 7vw, 5.5rem); font-weight: 400; letter-spacing: -.06em; }
.login-shell section > p:last-child { color: var(--muted-foreground); max-width: 30rem; }
.login-shell form { padding: 1.4rem; border: 1px solid var(--uhtomic-line); border-radius: .45rem; background: var(--background); }
.login-shell form button { width: 100%; }
.error-shell { text-align: center; }

@media (max-width: 720px) {
    .app-header { grid-template-columns: 1fr auto; gap: .65rem; }
    .app-header nav { grid-column: 1 / -1; grid-row: 2; overflow-x: auto; padding-top: .25rem; }
    .header-actions > form { display: none; }
    .login-shell { grid-template-columns: 1fr; align-content: center; }
    .login-shell section h1 { font-size: 3.5rem; }
    .page-heading { align-items: start; flex-direction: column; gap: 1rem; }
    .note-search { width: 100%; }
    .note-row, .archive-year { grid-template-columns: 1fr; gap: .45rem; }
    .note-full > header { flex-direction: column; }
    .related-grid { grid-template-columns: 1fr; }
    .gallery-grid { columns: 2 9rem; }
    .note-metadata { grid-template-columns: 1fr; }
    .switch-row { padding-bottom: 0; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; }
}
