:root {
    color-scheme: light dark;
    --bg: #f3f5fa;
    --surface: #ffffff;
    --surface-alt: #f8f9fd;
    --text: #18202f;
    --muted: #647089;
    --border: #e1e6f0;
    --primary: #3557d6;
    --primary-hover: #2a46b0;
    --primary-soft: rgba(53, 87, 214, 0.12);
    --danger: #c0392b;
    --danger-hover: #a93226;
    --danger-soft: rgba(192, 57, 43, 0.1);
    --radius: 16px;
    --radius-sm: 10px;
    --shadow: 0 12px 32px rgba(24, 32, 47, 0.08);
    --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0d1220;
        --surface: #161d2e;
        --surface-alt: #1b2437;
        --text: #e8ecf7;
        --muted: #9aa6bf;
        --border: #263149;
        --primary: #6d8cff;
        --primary-hover: #8aa2ff;
        --primary-soft: rgba(109, 140, 255, 0.16);
        --danger: #ff7063;
        --danger-hover: #ff8a80;
        --danger-soft: rgba(255, 112, 99, 0.14);
        --shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
    }
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 16px;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3 {
    margin: 0 0 0.6rem;
    line-height: 1.25;
    letter-spacing: -0.01em;
}

h1 {
    font-size: clamp(1.5rem, 4vw, 1.9rem);
}

h2 {
    font-size: 1.15rem;
}

p {
    margin: 0 0 1rem;
}

a {
    color: var(--primary);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

time {
    font-variant-numeric: tabular-nums;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.topbar-inner,
.container {
    width: 100%;
    max-width: 960px;
    margin: 0 auto;
}

.topbar-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.75rem 1.25rem;
}

.container {
    padding: 1.75rem 1.25rem 3.5rem;
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 0.55rem;
    color: var(--text);
    font-size: 1.05rem;
    font-weight: 700;
    letter-spacing: 0.02em;
}

.brand:hover {
    text-decoration: none;
}

.brand-dot {
    width: 0.7rem;
    height: 0.7rem;
    border-radius: 50%;
    background: var(--primary);
    box-shadow: 0 0 0 4px var(--primary-soft);
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.4rem;
}

.form-card h1,
.form-card h2 {
    margin-bottom: 1rem;
}

.notes-section {
    margin-top: 2rem;
}

.section-title {
    margin: 0 0 0.7rem;
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    margin-bottom: 1rem;
}

.field label {
    color: var(--muted);
    font-size: 0.88rem;
    font-weight: 600;
}

input,
textarea {
    width: 100%;
    padding: 0.72rem 0.85rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-alt);
    color: var(--text);
    font: inherit;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

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

input:focus,
textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-soft);
}

textarea {
    min-height: 130px;
    resize: vertical;
}

.button {
    appearance: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.68rem 1.15rem;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    background: var(--primary);
    color: #ffffff;
    font: inherit;
    font-weight: 600;
    line-height: 1.2;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease, transform 0.05s ease;
}

.button:hover {
    background: var(--primary-hover);
    text-decoration: none;
}

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

.button:focus-visible {
    outline: 3px solid var(--primary-soft);
    outline-offset: 2px;
}

.button-ghost {
    background: transparent;
    border-color: var(--border);
    color: var(--text);
}

.button-ghost:hover {
    background: var(--surface-alt);
    border-color: var(--muted);
}

.button-danger {
    background: var(--danger);
}

.button-danger:hover {
    background: var(--danger-hover);
}

.inline-form {
    margin: 0;
}

.notes {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 1rem;
}

.note {
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
    padding: 1.1rem 1.2rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow);
    transition: border-color 0.15s ease, transform 0.15s ease;
}

.note:hover {
    border-color: var(--primary);
    transform: translateY(-2px);
}

.note h2 {
    margin: 0;
    font-size: 1.05rem;
    word-break: break-word;
}

.note-preview {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 4;
    overflow: hidden;
    margin: 0;
    color: var(--muted);
    font-size: 0.93rem;
    white-space: pre-wrap;
    word-break: break-word;
}

.note time {
    margin-top: auto;
    padding-top: 0.35rem;
    color: var(--muted);
    font-size: 0.76rem;
}

.empty {
    grid-column: 1 / -1;
    margin: 0;
    padding: 2rem 1rem;
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    color: var(--muted);
    text-align: center;
}

.note-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1rem;
}

.note-header h1 {
    margin: 0;
    word-break: break-word;
}

.icon-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: none;
    width: 2.5rem;
    height: 2.5rem;
    border: 1px solid var(--border);
    border-radius: 50%;
    background: var(--surface-alt);
    color: var(--muted);
    transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

.icon-button:hover {
    border-color: var(--primary);
    background: var(--primary-soft);
    color: var(--primary);
    text-decoration: none;
}

.icon-button:focus-visible {
    outline: 3px solid var(--primary-soft);
    outline-offset: 2px;
}

.note-meta {
    margin: 0 0 1.1rem;
    color: var(--muted);
    font-size: 0.82rem;
}

.note-text {
    margin: 0;
    font-size: 1.02rem;
    white-space: pre-wrap;
    word-break: break-word;
}

.actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.6rem;
}

.delete-form {
    margin: 1rem 0 0;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
}

.auth-page {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.25rem;
    background:
        radial-gradient(1200px 600px at 15% 10%, var(--primary-soft), transparent 60%),
        radial-gradient(1000px 500px at 85% 90%, var(--primary-soft), transparent 55%),
        var(--bg);
}

.auth-card {
    width: 100%;
    max-width: 410px;
    padding: 1.75rem;
}

.auth-card .brand {
    margin-bottom: 1.25rem;
}

.auth-card h1 {
    margin-bottom: 1.4rem;
    font-size: 1.55rem;
}

.auth-card .button {
    width: 100%;
}

.error {
    margin: 0 0 1rem;
    padding: 0.65rem 0.85rem;
    border: 1px solid var(--danger);
    border-radius: var(--radius-sm);
    background: var(--danger-soft);
    color: var(--danger);
    font-size: 0.9rem;
}

.empty-state {
    padding: 2.5rem 1.5rem;
    text-align: center;
}

.empty-state .button {
    margin-top: 0.5rem;
}

@media (max-width: 520px) {
    .topbar-inner {
        padding: 0.65rem 1rem;
    }

    .container {
        padding: 1.25rem 1rem 2.5rem;
    }

    .card {
        padding: 1.15rem;
    }

    .notes {
        grid-template-columns: 1fr;
    }
}

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