:root {
    color-scheme: light dark;
    --bg: #f4f1ea;
    --surface: #fffdfa;
    --surface-muted: #ebe7dd;
    --text: #1f2528;
    --muted: #66706d;
    --border: #d7d0c4;
    --accent: #2c6f62;
    --accent-strong: #184f45;
    --danger: #9f3d35;
    --shadow: 0 12px 32px rgba(31, 37, 40, 0.08);
    font-family: ui-sans-serif, "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

[data-theme="dark"] {
    color-scheme: dark;
    --bg: #161817;
    --surface: #202321;
    --surface-muted: #2b302d;
    --text: #ece9df;
    --muted: #a9b1aa;
    --border: #3c423e;
    --accent: #7ab8a7;
    --accent-strong: #a5d6ca;
    --danger: #e0877f;
    --shadow: none;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        color-scheme: dark;
        --bg: #161817;
        --surface: #202321;
        --surface-muted: #2b302d;
        --text: #ece9df;
        --muted: #a9b1aa;
        --border: #3c423e;
        --accent: #7ab8a7;
        --accent-strong: #a5d6ca;
        --danger: #e0877f;
        --shadow: none;
    }
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100dvh;
    background: var(--bg);
    color: var(--text);
    overflow: hidden;
}

button,
input,
textarea {
    font: inherit;
}

.app {
    min-height: 100dvh;
    display: grid;
    grid-template-rows: auto 1fr auto;
    padding: 14px;
    gap: 10px;
}

.toolbar,
.footerbar {
    min-height: 52px;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 10px;
    padding: 8px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: color-mix(in srgb, var(--surface) 92%, transparent);
    box-shadow: var(--shadow);
}

.toolbar-group,
.stats {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.note-id {
    max-width: 34vw;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    padding: 0 8px;
    color: var(--muted);
    font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
    font-size: 13px;
}

.status-pill {
    min-width: 88px;
    padding: 7px 10px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--surface-muted);
    color: var(--accent-strong);
    font-size: 13px;
    font-weight: 600;
    text-align: center;
    white-space: nowrap;
}

.status-pill[data-state="unsaved"],
.status-pill[data-state="error"],
.status-pill[data-state="offline"] {
    color: var(--danger);
}

.status-pill[data-state="saving"] {
    color: var(--muted);
}

.button,
.link-button {
    min-height: 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 0 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
    text-decoration: none;
    cursor: pointer;
    transition: border-color 140ms ease, background 140ms ease, color 140ms ease;
}

.button:hover,
.link-button:hover,
.button:focus-visible,
.link-button:focus-visible {
    border-color: var(--accent);
    outline: none;
}

.button.primary {
    border-color: var(--accent);
    background: var(--accent);
    color: var(--surface);
    font-weight: 700;
}

[data-theme="dark"] .button.primary {
    color: #101412;
}

.pin-dialog {
    width: min(92vw, 380px);
    padding: 18px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--shadow);
}

.pin-dialog::backdrop {
    background: rgba(20, 22, 21, 0.38);
}

.pin-form,
.lock-panel {
    display: grid;
    gap: 12px;
}

.pin-title {
    margin: 0;
    font-size: 18px;
    line-height: 1.25;
}

.pin-help,
.pin-message {
    margin: 0;
    color: var(--muted);
    font-size: 13px;
    line-height: 1.45;
}

.pin-message[data-state="error"] {
    color: var(--danger);
}

.pin-input {
    width: 100%;
    min-height: 44px;
    padding: 0 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
    letter-spacing: 0;
}

.pin-input:focus {
    border-color: var(--accent);
    outline: none;
}

.pin-row {
    display: flex;
    gap: 8px;
}

.pin-row .button {
    flex: 1 1 auto;
}

.lock-shell {
    min-height: 100dvh;
    display: grid;
    grid-template-rows: auto 1fr;
    padding: 14px;
    gap: 10px;
}

.lock-wrap {
    display: grid;
    place-items: center;
    min-height: 0;
}

.lock-panel {
    width: min(92vw, 380px);
    padding: 18px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.editor-form {
    min-height: 0;
    display: grid;
}

.editor {
    width: 100%;
    height: 100%;
    min-height: 0;
    resize: none;
    padding: 22px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--shadow);
    outline: none;
    line-height: 1.55;
    font-size: 17px;
    text-wrap: pretty;
}

.editor:focus {
    border-color: var(--accent);
}

.stats {
    color: var(--muted);
    font-size: 13px;
    white-space: nowrap;
}

.stat {
    min-width: 78px;
    text-align: right;
}

@media (max-width: 720px) {
    body {
        overflow: auto;
    }

    .app {
        min-height: 100dvh;
        grid-template-rows: auto minmax(55dvh, 1fr) auto;
        padding: 8px;
    }

    .toolbar,
    .footerbar {
        align-items: stretch;
        flex-direction: column;
    }

    .toolbar-group,
    .stats {
        width: 100%;
        flex-wrap: wrap;
    }

    .button,
    .link-button {
        min-height: 44px;
        flex: 1 1 auto;
    }

    .note-id {
        max-width: 100%;
        flex: 1 1 100%;
        padding: 4px 2px;
    }

    .status-pill {
        flex: 1 1 auto;
        min-height: 44px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .editor {
        padding: 16px;
        font-size: 16px;
    }

    .stat {
        min-width: 0;
        flex: 1 1 40%;
        text-align: left;
    }
}
