:root {
    color-scheme: light dark;
    --bg: #f4f1ea;
    --surface: #fbf9f4;
    --surface-raised: #f4f1ea;
    --text: #26241f;
    --muted: #7d786d;
    --faint: #a7a196;
    --border: #e1dbcf;
    --hover: #ebe6db;
    --accent: #2f6d4f;
    --accent-soft: #dfece4;
    --warning: #9a6519;
    --error: #b04435;
    --selection: #cfe4d7;
    --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
    --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #171814;
        --surface: #1d1e1a;
        --surface-raised: #232420;
        --text: #ece8dd;
        --muted: #9d988b;
        --faint: #716d64;
        --border: #30312b;
        --hover: #2b2c26;
        --accent: #8ac9a6;
        --accent-soft: #26382d;
        --warning: #d2a45b;
        --error: #e08070;
        --selection: #355744;
    }
}

* {
    box-sizing: border-box;
}

html,
body {
    height: 100%;
}

body {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    margin: 0;
    overflow: hidden;
    background: var(--bg);
    color: var(--text);
    font-family: var(--sans);
    -webkit-text-size-adjust: 100%;
    text-rendering: optimizeLegibility;
}

.toolbar {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 54px;
    padding: 0 18px;
    border-bottom: 1px solid var(--border);
    background: var(--surface-raised);
}

.identity {
    display: flex;
    min-width: 0;
    align-items: center;
    gap: 9px;
}

.mark {
    position: relative;
    flex: 0 0 auto;
    width: 13px;
    height: 17px;
    border: 1.5px solid var(--accent);
    border-radius: 2px;
}

.mark::after {
    position: absolute;
    top: 4px;
    right: 2.5px;
    left: 2.5px;
    height: 1.5px;
    background: var(--accent);
    box-shadow: 0 4px 0 var(--accent);
    content: "";
}

.label {
    color: var(--text);
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0.02em;
    white-space: nowrap;
}

.note-id {
    overflow: hidden;
    max-width: 24vw;
    padding: 2px 7px;
    border: 1px solid var(--border);
    border-radius: 5px;
    color: var(--muted);
    font-family: var(--mono);
    font-size: 11px;
    line-height: 18px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.note-id::before {
    margin-right: 2px;
    color: var(--faint);
    content: "#";
}

.toolbar-actions {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    gap: 4px;
}

.status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-right: 5px;
    color: var(--muted);
    font-size: 12px;
    line-height: 1;
    white-space: nowrap;
}

.status::before {
    width: 6px;
    height: 6px;
    flex: 0 0 auto;
    border-radius: 50%;
    background: var(--accent);
    content: "";
}

.status[data-state="dirty"]::before {
    background: var(--warning);
}

.status[data-state="saving"]::before {
    background: var(--warning);
    animation: status-pulse 1s ease-in-out infinite;
}

.status[data-state="error"] {
    color: var(--error);
}

.status[data-state="error"]::before {
    background: var(--error);
}

@keyframes status-pulse {
    50% {
        opacity: 0.3;
        transform: scale(0.75);
    }
}

.tool-button {
    display: inline-flex;
    height: 32px;
    align-items: center;
    justify-content: center;
    gap: 5px;
    padding: 0 9px;
    border-radius: 6px;
    color: var(--muted);
    font-size: 12px;
    line-height: 1;
    text-decoration: none;
    touch-action: manipulation;
    transition: background-color 120ms ease, color 120ms ease;
}

.tool-button:hover {
    background: var(--hover);
    color: var(--text);
}

.tool-button:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

.icon {
    width: 16px;
    height: 16px;
    fill: none;
    stroke: currentColor;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 1.7;
}

.editor {
    position: relative;
    display: flex;
    flex: 1 1 auto;
    min-height: 0;
    background: var(--surface);
}

#content {
    width: 100%;
    height: 100%;
    flex: 1 1 auto;
    margin: 0;
    padding: clamp(20px, 3.2vw, 42px) clamp(18px, 5vw, 72px);
    overflow-y: auto;
    border: 0;
    border-radius: 0;
    outline: 0;
    background: var(--surface);
    color: var(--text);
    caret-color: var(--accent);
    font-family: var(--mono);
    font-size: 16px;
    font-variant-ligatures: none;
    line-height: 1.7;
    resize: none;
    tab-size: 4;
    white-space: pre-wrap;
    overflow-wrap: break-word;
    overscroll-behavior: contain;
    scrollbar-color: var(--border) transparent;
}

#content::placeholder {
    color: var(--faint);
    opacity: 1;
}

#content::selection {
    background: var(--selection);
}

.noscript {
    position: fixed;
    right: 16px;
    bottom: 16px;
    left: 16px;
    z-index: 2;
    margin: 0;
    padding: 12px 16px;
    border: 1px solid var(--error);
    border-radius: 8px;
    background: var(--surface);
    color: var(--error);
    font-size: 13px;
    text-align: center;
}

@media (max-width: 560px) {
    .toolbar {
        min-height: 50px;
        gap: 8px;
        padding: 0 10px;
    }

    .note-id {
        max-width: 86px;
    }

    .status {
        margin-right: 0;
        font-size: 11px;
    }

    .tool-button {
        width: 34px;
        height: 34px;
        padding: 0;
    }

    .button-text {
        display: none;
    }

    #content {
        padding: 18px 16px calc(24px + env(safe-area-inset-bottom));
        font-size: 16px;
        line-height: 1.65;
    }
}

@media (max-width: 380px) {
    .label {
        display: none;
    }

    .note-id {
        max-width: 72px;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
