:root {
    --bg: #f3efe6;
    --bg-deep: #1c1915;
    --surface: rgba(251, 248, 243, 0.94);
    --ink: #1c1915;
    --muted: #6d665d;
    --line: rgba(28, 25, 21, 0.12);
    --line-strong: rgba(28, 25, 21, 0.22);
    --sage: #0f6e56;
    --sage-soft: #e5f2ed;
    --gold: #c4a574;
    --danger: #8f2d2d;
    --danger-soft: #f8eceb;
    --shadow: 0 18px 40px rgba(28, 25, 21, 0.08);
    --serif: "Fraunces", "Iowan Old Style", Palatino, Georgia, serif;
    --sans: "Figtree", "Avenir Next", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
    min-height: 100vh;
    font-family: var(--sans);
    font-size: 16px;
    line-height: 1.5;
    color: var(--ink);
    background:
        radial-gradient(1100px 480px at 8% -10%, rgba(15, 110, 86, 0.09), transparent 55%),
        radial-gradient(800px 420px at 100% 0%, rgba(196, 165, 116, 0.2), transparent 50%),
        var(--bg);
}

h1, h2, h3 { font-weight: 560; }

h1 {
    margin: 0;
    font-family: var(--serif);
    font-size: clamp(44px, 6vw, 72px);
    letter-spacing: -0.035em;
    line-height: 0.94;
}

a { color: inherit; }

button, input, textarea { font: inherit; color: inherit; }

.skip {
    position: absolute;
    left: 16px;
    top: -40px;
    background: var(--ink);
    color: #f6f1e8;
    padding: 8px 12px;
    border-radius: 999px;
    z-index: 20;
}

.skip:focus { top: 12px; }

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 16px 28px;
    background: rgba(243, 239, 230, 0.84);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(16px);
}

.brand, .auth-brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    font-weight: 700;
    letter-spacing: -0.03em;
    font-size: 18px;
}

.mark {
    width: 32px;
    height: 32px;
    display: grid;
    place-items: center;
    border-radius: 10px;
    background: var(--ink);
    color: #f3efe6;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.user-pill {
    padding: 6px 10px;
    border-radius: 999px;
    background: rgba(28, 25, 21, 0.06);
    font-size: 13px;
    font-weight: 600;
}

.page {
    width: min(880px, calc(100% - 40px));
    margin: 0 auto;
    padding: 42px 0 80px;
}

.page.narrow { width: min(680px, calc(100% - 40px)); }

.page-head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 20px;
}

.eyebrow {
    margin: 0 0 10px;
    color: var(--sage);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.16em;
    text-transform: uppercase;
}

.eyebrow-light { color: var(--gold); }

.count, .lede, .fine, .auth-foot {
    color: var(--muted);
}

.count { margin: 10px 0 0; font-weight: 600; }

.lede {
    max-width: 46ch;
    margin: 12px 0 0;
    font-size: 17px;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: 1px solid transparent;
    border-radius: 999px;
    padding: 11px 16px;
    background: transparent;
    text-decoration: none;
    font-size: 14px;
    font-weight: 700;
    line-height: 1;
    cursor: pointer;
    transition: transform 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}

.btn:hover { transform: translateY(-1px); }

.btn:active { transform: translateY(0); }

.btn-primary { background: var(--ink); color: #f6f1e8; }
.btn-primary:hover { background: #000; }

.btn-ghost {
    border-color: var(--line-strong);
    background: rgba(255, 255, 255, 0.45);
}

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #731f1f; }

.btn-quiet { color: var(--muted); padding-inline: 12px; }
.btn-quiet:hover { color: var(--ink); }

.btn-block { width: 100%; }

.flash {
    margin-top: 22px;
    padding: 12px 14px;
    border-radius: 14px;
    font-weight: 600;
}

.flash-ok { background: var(--sage-soft); color: #0c4f3e; }
.flash-error { background: var(--danger-soft); color: var(--danger); }

.search {
    display: flex;
    gap: 8px;
    margin-top: 26px;
}

.search input, .field input, .field textarea, .editor input, .editor textarea {
    width: 100%;
    border: 1px solid var(--line-strong);
    border-radius: 14px;
    background: #fff;
    padding: 12px 14px;
    font-size: 16px;
}

.search input { border-radius: 999px; padding-inline: 16px; }

.field textarea, .editor textarea {
    min-height: 240px;
    resize: vertical;
    line-height: 1.6;
}

input:focus, textarea:focus {
    outline: none;
    border-color: var(--sage);
    box-shadow: 0 0 0 4px rgba(15, 110, 86, 0.15);
}

.is-invalid { border-color: var(--danger) !important; }

.note-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 18px;
}

.note-card {
    display: grid;
    grid-template-columns: 10px minmax(0, 1fr) auto;
    gap: 16px;
    align-items: stretch;
    overflow: hidden;
    padding: 18px 18px 18px 0;
    border: 1px solid var(--line);
    border-radius: 20px;
    background: var(--surface);
    transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}

.note-card:hover {
    transform: translateY(-2px);
    border-color: transparent;
    box-shadow: var(--shadow);
}

.swatch { border-radius: 0 6px 6px 0; }
.swatch-0 { background: #0f6e56; }
.swatch-1 { background: #8a5a2b; }
.swatch-2 { background: #3d4f7c; }
.swatch-3 { background: #8c3d3d; }

.note-link {
    min-width: 0;
    color: inherit;
    text-decoration: none;
}

.note-link h2 {
    margin: 0 0 4px;
    font-family: var(--serif);
    font-size: 24px;
    letter-spacing: -0.03em;
}

.note-link p {
    margin: 0;
    color: var(--muted);
}

.note-side {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    justify-content: space-between;
    gap: 12px;
}

.when {
    color: var(--muted);
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.link-danger {
    color: var(--danger);
    font-size: 13px;
    font-weight: 700;
    text-decoration: none;
}

.link-danger:hover { text-decoration: underline; }

.empty, .preview, .editor, .help {
    margin-top: 22px;
    padding: 22px;
    border: 1px solid var(--line);
    border-radius: 24px;
    background: var(--surface);
}

.empty h2, .preview h2, .help h2, .auth-card h2 {
    margin: 0;
    font-family: var(--serif);
    font-size: 32px;
    letter-spacing: -0.03em;
}

.empty p { color: var(--muted); }
.empty .btn { margin-top: 8px; }

.preview p {
    white-space: pre-wrap;
    color: var(--ink);
}

.editor, .stack { display: grid; gap: 16px; }
.stack { margin-top: 22px; }

.field { display: grid; gap: 6px; }

.field label {
    font-size: 13px;
    font-weight: 700;
}

.field-error {
    margin: 0;
    color: var(--danger);
    font-size: 13px;
    font-weight: 600;
}

.form-actions, .confirm-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}

.form-actions-main, .confirm-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.confirm-actions { margin-top: 18px; justify-content: flex-start; }

.sql-panel { margin-top: 28px; }

.sql-panel summary {
    width: fit-content;
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
}

.sql-panel pre, .help pre, .error-detail {
    overflow: auto;
    margin: 12px 0 0;
    padding: 14px 16px;
    border-radius: 14px;
    background: var(--bg-deep);
    color: #f3efe6;
    font-size: 13px;
    line-height: 1.55;
}

.help { display: grid; gap: 8px; }
.help h2 { font-size: 22px; margin-top: 8px; }
.fine { margin: 18px 0 0; font-size: 14px; }

body.auth {
    background: var(--bg-deep);
}

.auth-layout {
    display: grid;
    grid-template-columns: 1.05fr 0.95fr;
    min-height: 100vh;
}

.auth-aside {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 32px;
    padding: 36px 56px 32px;
    color: #f6f1e8;
    background:
        radial-gradient(520px 320px at 12% 18%, rgba(15, 110, 86, 0.55), transparent 70%),
        radial-gradient(440px 300px at 90% 85%, rgba(196, 165, 116, 0.32), transparent 72%),
        #1c1915;
}

.auth-brand { color: #f6f1e8; }
.auth-brand .mark { background: rgba(246, 241, 232, 0.08); color: #f6f1e8; }

.auth-aside h1 {
    max-width: 9ch;
    color: #f6f1e8;
}

.ops {
    list-style: none;
    margin: 32px 0 0;
    padding: 0;
    max-width: 360px;
}

.ops li {
    display: flex;
    align-items: baseline;
    gap: 16px;
    padding: 10px 0;
    border-top: 1px solid rgba(246, 241, 232, 0.16);
    font-family: var(--serif);
    font-size: 30px;
    letter-spacing: -0.03em;
}

.ops span {
    font-family: var(--sans);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.14em;
    color: var(--gold);
}

.auth-foot { margin: 0; color: rgba(246, 241, 232, 0.62); }

.auth-panel {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px 28px;
    background:
        radial-gradient(800px 420px at 100% 0%, rgba(196, 165, 116, 0.2), transparent 50%),
        var(--bg);
}

.auth-card { width: min(420px, 100%); }

.auth-card h2 { font-size: 40px; }

.demo {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 18px 0 0;
    padding: 12px 14px;
    border: 1px dashed var(--line-strong);
    border-radius: 14px;
    background: #fff;
    font-weight: 700;
}

.demo span {
    color: var(--muted);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.14em;
    text-transform: uppercase;
}

.demo .dot { letter-spacing: 0; font-size: 14px; }

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

input:focus-visible, textarea:focus-visible { outline: none; }

@media (max-width: 860px) {
    .auth-layout { grid-template-columns: 1fr; }
    .auth-aside { padding: 28px 22px 8px; gap: 18px; }
    .auth-aside h1 { font-size: 46px; }
    .ops li { font-size: 24px; }
    .auth-foot { display: none; }
    .auth-panel { padding: 12px 20px 48px; align-items: start; }
}

@media (max-width: 640px) {
    .topbar { padding: 14px 16px; }
    .page { width: min(100% - 28px, 880px); padding-top: 28px; }
    .page-head, .note-card { grid-template-columns: 8px minmax(0, 1fr); }
    .page-head { display: flex; flex-direction: column; align-items: flex-start; }
    .note-side {
        grid-column: 2;
        flex-direction: row;
        align-items: center;
    }
    .search { flex-wrap: wrap; }
    .search input { min-width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        transition: none !important;
        scroll-behavior: auto !important;
    }
}
