/* Design informed by unslop — Damir Sokolovsky (@heydamir), CC BY 4.0.
   https://heydamir.design/unslop */

@font-face {
    font-family: "Manrope";
    src: url("fonts/Manrope-Variable.ttf") format("truetype");
    font-style: normal;
    font-weight: 200 800;
    font-display: swap;
}

@font-face {
    font-family: "Lora";
    src: url("fonts/Lora-Variable.ttf") format("truetype");
    font-style: normal;
    font-weight: 400 700;
    font-display: swap;
}

:root {
    color-scheme: dark;
    --background: #1b1b19;
    --surface: #242421;
    --line: #3b3b35;
    --text: #eee9df;
    --secondary: #b9b5aa;
    --muted: #aaa69a;
    --accent: #d1ba88;
    --paper: #eee6d5;
    --paper-raised: #f8f3e8;
    --paper-ink: #292923;
    --paper-secondary: #605b4f;
    --paper-line: #c9bfac;
    --focus: #dec591;
    --radius: 8px;
}

* { box-sizing: border-box; }

html { min-height: 100%; }

body {
    min-width: 0;
    min-height: 100vh;
    min-height: 100svh;
    margin: 0;
    display: flex;
    flex-direction: column;
    background: var(--background);
    color: var(--text);
    font: 400 16px/1.6 "Manrope", sans-serif;
    -webkit-text-size-adjust: 100%;
}

h1, h2, p { margin: 0; }

h1, h2 {
    font-family: "Lora", Georgia, serif;
    font-weight: 400;
    line-height: 1.2;
    overflow-wrap: anywhere;
}

a {
    color: inherit;
    text-underline-offset: 4px;
    text-decoration-thickness: 1px;
    transition: color 160ms ease-out;
}

a:hover { color: var(--accent); }

button, input, textarea { font: inherit; }

button, a, input, textarea { -webkit-tap-highlight-color: transparent; }

:focus-visible {
    outline: 2px solid var(--focus);
    outline-offset: 4px;
}

.skip-link {
    position: fixed;
    inset-block-start: 12px;
    inset-inline-start: 16px;
    z-index: 10;
    padding: 12px 16px;
    background: var(--paper);
    color: var(--paper-ink);
    transform: translateY(-200%);
}

.skip-link:focus { transform: none; }

.site-header {
    width: min(100% - 64px, 1280px);
    min-height: 104px;
    margin-inline: auto;
    padding-block: 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    border-bottom: 1px solid var(--line);
}

.brand {
    display: flex;
    align-items: center;
    flex-shrink: 0;
    gap: 12px;
    text-decoration: none;
    font-size: 16px;
    font-weight: 500;
    line-height: 1.4;
}

.brand img { display: block; object-fit: contain; }

.site-nav {
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 24px;
    font-size: 14px;
}

.site-nav a {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    text-decoration: none;
    white-space: nowrap;
}

.current-user {
    max-width: 240px;
    color: var(--secondary);
    overflow-wrap: anywhere;
}

.page-shell {
    flex: 1;
    width: min(100% - 64px, 1280px);
    min-width: 0;
    margin-inline: auto;
    padding-block: 48px 64px;
}

.site-footer {
    width: min(100% - 64px, 1280px);
    margin-inline: auto;
    padding-block: 24px;
    border-top: 1px solid var(--line);
    color: var(--muted);
    font-size: 12px;
}

.site-footer span { margin-inline: 8px; }

.messages {
    display: grid;
    gap: 8px;
    margin-bottom: 24px;
}

.message {
    padding: 16px 20px;
    border: 1px solid var(--line);
    border-inline-start: 3px solid var(--accent);
    border-radius: 4px;
    background: var(--surface);
    color: var(--text);
    font-size: 14px;
    overflow-wrap: anywhere;
}

.message.error { border-inline-start-color: #d99d8e; }
.message.success { border-inline-start-color: #a7b49a; }

.eyebrow {
    margin-bottom: 16px;
    color: var(--accent);
    font-size: 14px;
}

.auth-page .page-shell {
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.auth-layout {
    display: grid;
    grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr);
    align-items: center;
    gap: 80px;
}

.auth-copy { max-width: 560px; }

.auth-copy h1 {
    max-width: 520px;
    font-size: clamp(40px, 4.5vw, 64px);
    line-height: 1.15;
}

.auth-description {
    max-width: 460px;
    margin-top: 32px;
    color: var(--secondary);
    font-size: 17px;
    line-height: 1.8;
}

.auth-footnote {
    width: fit-content;
    margin-top: 48px;
    padding-top: 16px;
    border-top: 1px solid var(--line);
    color: var(--muted);
    font-size: 12px;
}

.paper {
    color-scheme: light;
    background: var(--paper);
    color: var(--paper-ink);
    border: 1px solid var(--paper-line);
    border-radius: 12px;
    --focus: #65502c;
}

.paper a:hover { color: #735020; }

.auth-form {
    width: 100%;
    max-width: 480px;
    justify-self: end;
    padding: 36px;
}

.auth-form h2, .note-dialog h2 { font-size: 32px; }

.form-description {
    margin-top: 8px;
    margin-bottom: 24px;
    color: var(--paper-secondary);
    font-size: 14px;
}

label {
    display: block;
    margin-block: 20px 8px;
    font-size: 14px;
    font-weight: 500;
}

input, textarea {
    display: block;
    width: 100%;
    min-width: 0;
    min-height: 48px;
    padding: 12px;
    border: 1px solid #a79e8c;
    border-radius: var(--radius);
    background: var(--paper-raised);
    color: var(--paper-ink);
    font-size: 16px;
    line-height: 1.5;
    transition: border-color 160ms ease-out;
}

input:hover, textarea:hover { border-color: #746d5e; }
input:focus, textarea:focus { border-color: #65502c; }
input::placeholder, textarea::placeholder { color: #736c5e; opacity: 1; }
textarea { resize: vertical; }

.field-help {
    margin-top: 8px;
    color: var(--paper-secondary);
    font-size: 12px;
    line-height: 1.5;
}

button {
    min-height: 48px;
    padding: 12px 20px;
    border: 1px solid transparent;
    border-radius: var(--radius);
    background: var(--paper);
    color: var(--paper-ink);
    font-size: 14px;
    font-weight: 500;
    line-height: 1.5;
    cursor: pointer;
    transition: background-color 160ms ease-out, border-color 160ms ease-out;
}

button:hover { background: #fff7e7; }
.paper button { background: var(--paper-ink); color: var(--paper-raised); }
.paper button:hover { background: #44443a; }

.auth-form > button { width: 100%; margin-top: 28px; }

.form-switch {
    margin-top: 24px;
    color: var(--paper-secondary);
    font-size: 13px;
    line-height: 1.8;
    text-align: center;
    overflow-wrap: anywhere;
}

.form-switch a { color: var(--paper-ink); }

.notes-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    margin-bottom: 40px;
}

.notes-heading h1 { font-size: 44px; }
.notes-heading .eyebrow { margin-bottom: 8px; }
.new-note-button { flex-shrink: 0; }

.note-dialog {
    width: min(640px, calc(100% - 32px));
    max-height: calc(100vh - 32px);
    max-height: calc(100svh - 32px);
    padding: 32px;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.note-dialog::backdrop { background: rgb(0 0 0 / 72%); }

.dialog-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 24px;
}

.paper .dialog-close {
    flex-shrink: 0;
    min-height: 44px;
    padding: 8px;
    background: transparent;
    color: var(--paper-secondary);
    text-decoration: underline;
    text-underline-offset: 4px;
    font-weight: 400;
}

.paper .dialog-close:hover { background: #dfd5c1; color: var(--paper-ink); }
.importance-input { max-width: 160px; }
.dialog-actions { margin-top: 24px; display: flex; justify-content: flex-end; }

.sql-error {
    min-width: 0;
    margin-bottom: 32px;
    padding: 24px;
    border: 1px solid #77594f;
    border-radius: var(--radius);
    background: var(--surface);
}

.sql-error h2 {
    margin-bottom: 12px;
    color: #e7b5a6;
    font: 500 16px/1.5 "Manrope", sans-serif;
}

.sql-error pre {
    max-width: 100%;
    max-height: 320px;
    margin: 0;
    overflow: auto;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    color: var(--text);
    font: 400 14px/1.7 ui-monospace, monospace;
    tab-size: 4;
}

.note-collection { overflow: clip; }

.collection-labels {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 120px 96px;
    gap: 24px;
    padding: 20px 32px;
    border-bottom: 1px solid var(--paper-line);
    color: var(--paper-secondary);
    font-size: 12px;
}

.collection-labels > :nth-child(2) { text-align: end; }
.note-list { margin: 0; padding: 0; list-style: none; }
.note-list li + li { border-top: 1px solid var(--paper-line); }

.note-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 120px 96px;
    align-items: center;
    gap: 24px;
    min-height: 104px;
    padding: 24px 32px;
    text-decoration: none;
    transition: background-color 160ms ease-out;
}

.note-row:hover { background: #e2d8c3; color: var(--paper-ink); }
.note-row:focus-visible { outline-offset: -6px; }

.note-id {
    width: fit-content;
    max-width: 100%;
    padding-bottom: 8px;
    border-bottom: 1px solid currentColor;
    font-size: 14px;
    font-variant-numeric: tabular-nums;
    overflow-wrap: anywhere;
}

.row-importance {
    min-width: 0;
    text-align: end;
    font-size: 28px;
    font-variant-numeric: tabular-nums;
    overflow-wrap: anywhere;
}

.row-open { color: var(--paper-secondary); text-align: end; font-size: 13px; }

.empty-state { max-width: 640px; padding: 64px 48px 80px; }
.empty-caption { margin-bottom: 24px; color: var(--paper-secondary); font-size: 13px; }
.empty-state h2 { max-width: 440px; margin-bottom: 20px; font-size: 36px; }
.empty-state > p:last-child { color: var(--paper-secondary); line-height: 1.8; }

.back-link {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    margin-bottom: 16px;
    color: var(--secondary);
    font-size: 14px;
}

.large-note { padding: 40px 48px 64px; }

.note-topline {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 32px;
    margin-bottom: 28px;
}

.note-importance {
    max-width: 45%;
    color: var(--paper-secondary);
    font-size: 13px;
    overflow-wrap: anywhere;
}

.note-importance span { margin-inline-start: 8px; color: var(--paper-ink); font-variant-numeric: tabular-nums; }
.note-author { margin-bottom: 16px; color: var(--paper-secondary); font-size: 13px; overflow-wrap: anywhere; }
.large-note h2 { max-width: 920px; margin-bottom: 32px; font-size: clamp(32px, 4vw, 48px); }
.note-text { max-width: 80ch; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 16px; line-height: 1.9; }

@media (max-width: 960px) {
    .auth-layout { gap: 40px; }
    .auth-form { padding: 28px; }
    .auth-copy h1 { font-size: 44px; }
    .site-nav { gap: 16px; }
    .current-user { max-width: 160px; }
}

@media (max-width: 720px) {
    .site-header, .page-shell, .site-footer { width: calc(100% - 40px); }
    .site-header { flex-wrap: wrap; gap: 16px; }
    .site-nav { width: 100%; flex-wrap: wrap; gap: 8px 24px; }
    .current-user { max-width: none; flex-basis: 100%; }
    .page-shell { padding-block: 32px 48px; }
    .auth-layout { grid-template-columns: minmax(0, 1fr); gap: 32px; }
    .auth-copy { max-width: 560px; }
    .auth-copy h1 { max-width: 480px; font-size: 40px; }
    .auth-description { margin-top: 20px; font-size: 16px; }
    .auth-footnote { display: none; }
    .auth-form { max-width: none; padding: 28px; }
    .notes-heading { align-items: flex-start; flex-direction: column; gap: 24px; margin-bottom: 32px; }
    .notes-heading h1 { font-size: 36px; }
    .collection-labels, .note-row { grid-template-columns: minmax(0, 1fr) 96px; gap: 16px; padding-inline: 24px; }
    .row-open { display: none; }
    .note-row { min-height: 96px; }
    .large-note { padding: 28px 24px 40px; }
    .note-topline { gap: 20px; }
    .empty-state { padding: 40px 28px 48px; }
    .empty-state h2 { font-size: 32px; }
}

@media (max-width: 420px) {
    .auth-form { padding: 24px; }
    .auth-copy h1 { font-size: 36px; }
    .auth-form h2, .note-dialog h2 { font-size: 28px; }
    .note-dialog { padding: 24px 20px; }
    .dialog-heading { align-items: flex-start; gap: 8px; }
    .dialog-heading h2 { max-width: 192px; }
    .collection-labels, .note-row { padding-inline: 20px; grid-template-columns: minmax(0, 1fr) 80px; }
    .note-topline { flex-direction: column; gap: 16px; }
    .note-importance { max-width: 100%; }
    .sql-error { padding: 20px; }
}

@media (prefers-reduced-motion: reduce) {
    a, button, input, textarea, .note-row { transition: none; }
}
