* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

[hidden] {
    display: none !important;
}

:root {
    --bg: #f5f5f4;
    --panel: #ffffff;
    --ink: #1c1917;
    --muted: #6b6560;
    --accent: #3b5bdb;
    --accent-dark: #2f4ab8;
    --border: #e2e0dd;
    --danger: #c92a2a;
    --code-bg: #f1efec;
}

html,
body {
    height: 100%;
}

body {
    font-family: system-ui, -apple-system, "Segoe UI", Tahoma, sans-serif;
    background-color: var(--bg);
    color: var(--ink);
    line-height: 1.5;
}

.app {
    display: grid;
    grid-template-columns: 260px 1fr;
    grid-template-rows: auto 1fr;
    grid-template-areas:
        "top top"
        "side main";
    min-height: 100%;
}

.topbar {
    grid-area: top;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 16px;
    background-color: var(--panel);
    border-bottom: 1px solid var(--border);
}

.sidebar {
    grid-area: side;
    background-color: var(--panel);
    border-inline-end: 1px solid var(--border);
    overflow-y: auto;
}

.note-list {
    list-style: none;
}

.note-item {
    display: flex;
    flex-direction: column;
    width: 100%;
    text-align: start;
    padding: 10px 16px;
    border: none;
    border-bottom: 1px solid var(--border);
    background: none;
    font: inherit;
    color: inherit;
    cursor: pointer;
}

.note-item:hover {
    background-color: #f7f7f5;
}

.note-item[aria-current="true"] {
    background-color: #eef1fd;
    box-shadow: inset 3px 0 0 var(--accent);
}

.note-title {
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.note-time {
    font-size: 0.78rem;
    color: var(--muted);
}

.empty,
.no-selection {
    padding: 24px 16px;
    color: var(--muted);
}

.no-selection {
    grid-area: main;
}

.pane-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-inline-end: 12px;
}

button.primary,
button.danger {
    font: inherit;
    font-size: 0.9rem;
    padding: 6px 14px;
    border-radius: 8px;
    cursor: pointer;
}

button.primary {
    background-color: var(--accent);
    border: 1px solid var(--accent);
    color: #fff;
}

button.primary:hover {
    background-color: var(--accent-dark);
}

button.danger {
    margin-top: 8px;
    background: none;
    border: 1px solid var(--danger);
    color: var(--danger);
}

button.danger:hover {
    background-color: #fff0f0;
}

.topbar h1 {
    font-size: 1.25rem;
}

.workspace {
    grid-area: main;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1px;
    background-color: var(--border);
}

.editor-pane,
.preview-pane {
    display: flex;
    flex-direction: column;
    background-color: var(--panel);
    min-width: 0;
}

.pane-title {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
    padding: 10px 16px 0;
}

#editor {
    flex: 1;
    min-height: 60vh;
    width: 100%;
    border: none;
    resize: none;
    padding: 12px 16px;
    font: 0.95rem/1.6 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
    color: var(--ink);
    background-color: transparent;
}

.preview {
    padding: 12px 16px 24px;
    overflow-wrap: anywhere;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

.preview h1,
.preview h2,
.preview h3,
.preview h4,
.preview h5,
.preview h6 {
    line-height: 1.25;
    margin: 1em 0 0.5em;
}

.preview h1 {
    font-size: 1.7rem;
}

.preview h2 {
    font-size: 1.4rem;
}

.preview h3 {
    font-size: 1.2rem;
}

.preview > :first-child {
    margin-top: 0;
}

.preview p,
.preview ul,
.preview ol,
.preview pre {
    margin-bottom: 0.9em;
}

.preview ul,
.preview ol {
    padding-inline-start: 1.5em;
}

.preview a {
    color: var(--accent);
}

.preview code {
    font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
    font-size: 0.9em;
    background-color: var(--code-bg);
    padding: 1px 5px;
    border-radius: 4px;
}

.preview pre {
    background-color: var(--code-bg);
    padding: 12px;
    border-radius: 8px;
    overflow-x: auto;
}

.preview pre code {
    padding: 0;
    background: none;
}

.save-state {
    margin-inline-start: auto;
    font-size: 0.8rem;
    color: var(--muted);
}

.save-state.error {
    color: var(--danger);
    font-weight: 600;
}

.search {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
}

.search input {
    width: 100%;
    font: inherit;
    padding: 7px 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background-color: var(--bg);
    color: var(--ink);
}

:focus-visible {
    outline: 3px solid #f59f00;
    outline-offset: 2px;
}

#editor:focus-visible,
.note-item:focus-visible {
    outline-offset: -3px;
}

@media (max-width: 760px) {
    .app {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto 1fr;
        grid-template-areas:
            "top"
            "side"
            "main";
    }

    .sidebar {
        max-height: 35vh;
        border-inline-end: none;
        border-bottom: 1px solid var(--border);
    }

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

    #editor {
        min-height: 40vh;
    }

    .topbar {
        flex-wrap: wrap;
    }

    .save-state {
        order: 3;
        flex-basis: 100%;
        margin-inline-start: 0;
    }
}
