* {
    box-sizing: border-box;
}

:root {
    color-scheme: dark;

    --sidebar-width: 260px;
    --editor-width: 760px;

    --bg-primary: #202020;
    --bg-secondary: #1b1b1a;
    --bg-surface: #272727;
    --bg-surface-hover: #303030;

    --text-primary: #e8e8e8;
    --text-secondary: #b8b8b8;
    --text-muted: #7f7f7f;

    --border-color: #2d2d2d;
    --border-strong: #3a3a3a;

    --hover-bg: rgba(255, 255, 255, 0.06);
    --selected-bg: rgba(255, 255, 255, 0.10);

    --radius-sm: 5px;
    --radius-md: 7px;
}

html,
body {
    margin: 0;
    width: 100%;
    min-height: 100%;
}

body {
    font-family:
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        sans-serif;

    font-size: 16px;
    line-height: 1.5;

    color: var(--text-primary);
    background: var(--bg-primary);
}

/* App layout */

.app {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

.sidebar {
    display: flex;
    flex-direction: column;
    flex: 0 0 var(--sidebar-width);
    height: 100vh;
    overflow: hidden;

    padding: 16px 10px;

    border-right: 1px solid var(--border-color);
    background: var(--bg-secondary);
}

.note-editor {
    flex: 1;
    min-width: 0;
    height: 100vh;
    overflow-y: auto;

    background: var(--bg-primary);
}

hr {
    height: 0;
    margin: 6px 0;
    border: 0;
    border-top: 1px solid var(--border-strong);
}

/* Sidebar */

.sidebar-header {
    flex-shrink: 0;
    padding-bottom: 6px;
}

.sidebar-content {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
}

.sidebar-footer {
    flex-shrink: 0;
    margin-top: 12px;
    padding-top: 8px;
    border-top: 1px solid var(--border-color);
}

.logout-icon {
    display: inline-flex;
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.logout-icon svg {
    width: 100%;
    height: 100%;
}

.sidebar-title {
    margin: 6px 10px 16px;

    font-size: 30px;
    line-height: 1.2;
    font-weight: 700;
}

.new-note-button,
.logout-button {
    display: flex;
    align-items: center;
    gap: 8px;

    width: 100%;
    padding: 9px 10px;

    border: 0;
    border-radius: var(--radius-md);

    background: transparent;
    color: var(--text-secondary);

    font: inherit;
    font-weight: 500;

    text-align: left;
    cursor: pointer;
}

.logout-button {
    font-size: 14px;
}

.new-note-button:hover,
.logout-button:hover {
    background: var(--hover-bg);
}

.section-title {
    margin: 20px 0 6px;
    padding: 0 10px;
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 600;
    line-height: 1.5;
    letter-spacing: 0.04em;
}

.section-header {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 28px;
    margin: 20px 0 6px;
    padding-right: 5px;
}

.section-header > .section-title {
    flex: 1;
    min-width: 0;
    margin: 0;
}

.sidebar-notes ul,
.sidebar-folders ul {
    margin: 0;
    padding: 0;
    list-style: none;
}

/* Folders */

.sidebar-folders {
    margin: 12px 0;
}

.note-folder {
    position: relative;
}

.note-folder + .note-folder {
    margin-top: 3px;
}

.note-folder-summary {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 38px;
    padding: 8px 42px 8px 10px;
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    font-size: 14px;
    font-weight: 600;
    line-height: 1.4;
    list-style: none;
    cursor: pointer;
}

.note-folder-summary::-webkit-details-marker {
    display: none;
}

.note-folder-summary::before {
    content: "";
    flex: 0 0 6px;
    height: 6px;
    margin-right: 2px;
    border-right: 1.5px solid currentColor;
    border-bottom: 1.5px solid currentColor;
    transform: rotate(-45deg);
}

.note-folder-details[open] > .note-folder-summary::before {
    transform: rotate(45deg);
}

.note-folder-summary:hover {
    background: var(--hover-bg);
    color: var(--text-primary);
}

.note-folder-summary:focus-visible {
    outline: 2px solid var(--text-secondary);
    outline-offset: -2px;
}

.note-folder-name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.sidebar-folders .note-folder-notes {
    margin: 4px 0 8px 13px;
    padding-left: 9px;
    border-left: 1px solid var(--border-strong);
}

.note-folder-notes .note-item-open {
    font-size: 14px;
}

.note-folder-empty {
    padding: 8px 10px;
    color: var(--text-muted);
    font-size: 13px;
}

.note-folder-details[open] > .note-folder-summary {
    color: var(--text-primary);
}

.note-folder-editing {
    padding: 4px 10px;
}

.note-folder-name-input {
    width: 100%;
    min-width: 0;
    padding: 6px 8px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--bg-primary);
    color: var(--text-primary);
    font: inherit;
    font-size: 14px;
}

.note-folder-name-input:focus {
    outline: 1px solid var(--text-secondary);
    outline-offset: 1px;
}

/* Note item */

.note-item {
    display: flex;
    align-items: center;

    width: 100%;
    min-height: 38px;

    border-radius: var(--radius-md);
}

.note-item:hover {
    background: var(--hover-bg);
}

.note-item.selected {
    background: var(--selected-bg);
}

.note-item-open {
    flex: 1;
    min-width: 0;

    padding: 8px 10px;

    border: 0;
    background: transparent;

    color: var(--text-primary);

    font: inherit;
    line-height: 1.4;

    text-align: left;
    cursor: pointer;

    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

/* Document */

.note-document {
    width: min(100%, var(--editor-width));
    margin: 0 auto;

    padding: 72px 48px 160px;
}

.note-header {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    margin-bottom: 28px;
}

.note-header .note-tags {
    margin-top: 12px;
}

.note-title {
    display: block;
    width: 100%;
    min-height: 1.3em;
    margin: 0;
    padding: 0;

    resize: none;
    overflow: hidden;
    border: 0;
    border-radius: 4px;
    outline: 1px solid transparent;
    outline-offset: 6px;

    background: transparent;
    color: var(--text-primary);
    caret-color: var(--text-primary);

    font: inherit;
    font-size: clamp(28px, 4vw, 36px);
    line-height: 1.3;
    font-weight: 700;
    letter-spacing: -0.02em;
    overflow-wrap: anywhere;

    transition: outline-color 120ms ease;
}

.note-title:focus-visible {
    outline-color: var(--border-strong);
}

.note-title::placeholder {
    color: var(--text-muted);
}

/* Blocks */

.note-block {
    position: relative;

    border-radius: 6px;
    outline: 1px solid transparent;
    outline-offset: 4px;

    transition: outline-color 120ms ease;
}

.note-block:focus-within {
    outline-color: rgba(255, 255, 255, 0.14);
}

/*
 * Extend hover hit area into the left gutter,
 * so the add button does not disappear while moving to it.
 */
.note-block::before {
    content: "";

    position: absolute;
    top: 0;
    bottom: 0;
    left: -40px;

    width: 40px;
}

.text-block {
    display: block;

    width: 100%;
    min-height: 28px;
    padding: 1px 0;

    border: 0;
    outline: 0;
    resize: none;
    overflow: hidden;

    background: transparent;
    color: var(--text-primary);

    font: inherit;
    font-size: 17px;
    line-height: 1.6;
}

.text-content {
    padding: 2px 0;

    font-size: 17px;
    line-height: 1.65;
    font-weight: 400;
}

.text-t1 {
    padding: 18px 0 8px;

    font-size: 32px;
    line-height: 1.25;
    font-weight: 700;
}

.text-t2 {
    padding: 14px 0 6px;

    font-size: 26px;
    line-height: 1.3;
    font-weight: 700;
}

.text-t3 {
    padding: 10px 0 4px;

    font-size: 21px;
    line-height: 1.4;
    font-weight: 650;
}

.text-t4 {
    padding: 6px 0 2px;

    font-size: 18px;
    line-height: 1.5;
    font-weight: 600;
}
.text-block::placeholder {
    color: #707070;
}

.task-list-item {
    display: flex;
    align-items: flex-start;
    gap: 10px;
}

.task-list-checkbox {
    flex: none;
    width: 18px;
    height: 18px;
    margin-top: 7px;
    cursor: pointer;
}

.task-list-text {
    flex: 1;
    min-width: 0;
}

.task-list-checkbox:checked + .task-list-text {
    text-decoration: line-through;
    opacity: 0.55;
}

/* Shared menu */

.menu {
    position: relative;

    z-index: 10;

    opacity: 0;
    pointer-events: none;

    transition: opacity 120ms ease;
}

.menu[open] {
    z-index: 30;
    opacity: 1;
    pointer-events: auto;
}

.menu-trigger {
    display: flex;
    align-items: center;
    justify-content: center;

    width: 28px;
    height: 28px;
    padding: 0;

    border-radius: 6px;

    color: var(--text-muted);

    font-size: 20px;
    line-height: 1;

    cursor: pointer;
    user-select: none;

    transition:
        background-color 120ms ease,
        color 120ms ease;
}

.menu-trigger:hover {
    background: rgba(255, 255, 255, 0.07);
    color: var(--text-secondary);
}

.menu-trigger::marker {
    content: "";
}

.menu-trigger::-webkit-details-marker {
    display: none;
}

.menu-trigger:focus-visible {
    outline: 2px solid var(--text-secondary);
    outline-offset: 2px;
}

.menu-popup {
    position: absolute;
    top: 32px;
    left: 0;

    z-index: 20;

    min-width: 150px;
    padding: 6px;

    border: 1px solid var(--border-strong);
    border-radius: 8px;

    background: var(--bg-surface);

    box-shadow:
        0 8px 24px rgba(0, 0, 0, 0.34),
        0 2px 8px rgba(0, 0, 0, 0.26);
}

.menu-item {
    display: flex;
    align-items: center;

    width: 100%;
    padding: 8px 10px;

    border: 0;
    border-radius: 6px;

    background: transparent;
    color: var(--text-primary);

    font: inherit;
    font-size: 15px;

    text-align: left;
    cursor: pointer;

    text-decoration: none;
}

.menu-item:hover {
    background: var(--bg-surface-hover);
}

/* Menu placement and visibility */

.block-menu {
    position: absolute;
    top: 2px;
    left: -36px;
}

.folder-section-menu {
    flex: 0 0 28px;
}

.folder-item-menu {
    position: absolute;
    top: 5px;
    right: 5px;
}

.note-block:focus-within .block-menu,
.section-header:hover > .folder-section-menu,
.section-header:focus-within > .folder-section-menu,
.note-item:hover > .note-item-menu,
.note-item:focus-within > .note-item-menu,
.note-folder:hover > .folder-item-menu,
.note-folder:focus-within > .folder-item-menu {
    opacity: 1;
    pointer-events: auto;
}

.note-item-menu {
    flex: 0 0 28px;
    margin-right: 5px;
}

.note-item-menu > .menu-popup,
.folder-item-menu > .menu-popup,
.folder-section-menu > .menu-popup {
    left: auto;
    right: 0;
    width: 180px;
}

@media (hover: none) {
    .note-item-menu,
    .folder-item-menu,
    .folder-section-menu {
        opacity: 1;
        pointer-events: auto;
    }
}

/* Image block */

.image-upload {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;

    width: 100%;
    min-height: 120px;

    border: 1px dashed #484848;
    border-radius: 8px;

    background: #252525;
    color: var(--text-muted);

    cursor: pointer;

    transition:
        background-color 120ms ease,
        border-color 120ms ease,
        color 120ms ease;
}

.image-upload:hover {
    border-color: #606060;
    background: #2b2b2b;
    color: var(--text-secondary);
}

.image-upload-input {
    display: none;
}

.image-upload-icon {
    font-size: 22px;
    line-height: 1;
}

.image-upload-text {
    font-size: 15px;
    font-weight: 500;
}

.image-block-content {
    position: relative;

    width: 100%;
    margin: 4px 0;
}

.image-block-image {
    display: block;

    max-width: 100%;
    height: auto;

    border-radius: 8px;
}

/* Code block */

.code-block {
    position: relative;
    margin: 12px 0;
    border-radius: 6px;
    overflow: hidden;
    background: #0d1117;
}

.code-block-preview {
    margin: 0;
    min-height: 64px;
    cursor: text;
    overflow-x: auto;
}

.code-block-editor {
    display: none;
    width: 100%;
    min-height: 96px;
    padding: 16px;
    border: 0;
    outline: 0;
    resize: none;
    background: transparent;
    color: var(--text-primary);
    font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
    font-size: 14px;
    line-height: 1.6;
    tab-size: 4;
}

.code-block.is-editing .code-block-preview {
    display: none;
}
.code-block.is-editing .code-block-editor {
    display: block;
}
.code-block:focus-within {
    outline: 1px solid var(--border-strong);
}

.code-block.is-editing > .block-toolbar {
    display: none;
}

/* Shared block toolbar */

.block-toolbar {
    position: absolute;
    z-index: 1;
    top: 8px;
    right: 8px;

    display: flex;
    gap: 6px;

    opacity: 0;
    pointer-events: none;

    transition: opacity 120ms ease;
}

:is(.image-block-content, .code-block):hover > .block-toolbar,
:is(.image-block-content, .code-block):focus-within > .block-toolbar {
    opacity: 1;
    pointer-events: auto;
}

.block-toolbar-action {
    display: flex;
    align-items: center;
    justify-content: center;

    min-height: 30px;
    padding: 5px 10px;

    border: 1px solid rgba(255, 255, 255, 0.10);
    border-radius: 6px;

    background: rgba(32, 32, 32, 0.94);
    color: var(--text-secondary);

    font: inherit;
    font-size: 13px;
    font-weight: 500;

    cursor: pointer;

    box-shadow:
        0 1px 4px rgba(0, 0, 0, 0.30),
        0 1px 2px rgba(0, 0, 0, 0.24);

    transition:
        background-color 120ms ease,
        color 120ms ease;
}

.block-toolbar-action:hover {
    background: var(--bg-primary);
    color: var(--text-primary);
}

.block-toolbar-action:focus-visible {
    outline: 2px solid var(--text-secondary);
    outline-offset: 2px;
}

/* Login and registration */
.app.login-body {
    display: block;
    height: auto;
    min-height: 100vh;
    min-height: 100dvh;
    overflow: auto;
}

.login-page {
    min-height: 100vh;
    min-height: 100dvh;
    display: grid;
    place-items: center;
    padding: 32px 20px;
}

.login-panel {
    width: 100%;
    max-width: 400px;
    padding: 36px;
    background: var(--bg-surface);
    border: 1px solid var(--border-strong);
    border-radius: 16px;
    box-shadow: 0 20px 60px rgb(0 0 0 / 18%);
}

.login-header {
    margin-bottom: 28px;
}

.login-title {
    margin: 0;
    font-size: 30px;
    font-weight: 650;
    letter-spacing: -1px;
}

.login-subtitle {
    margin: 8px 0 0;
    color: var(--text-secondary);
    font-size: 14px;
}

.login-form {
    display: grid;
    gap: 20px;
}

.login-field {
    display: grid;
    gap: 8px;
}

.login-field label {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
}

.login-input {
    width: 100%;
    min-width: 0;
    padding: 12px 14px;
    font: inherit;
    color: var(--text-primary);
    background: var(--bg-secondary);
    border: 1px solid var(--border-strong);
    border-radius: 8px;
}

.login-input:focus-visible {
    outline: 2px solid #a5b4fc;
    outline-offset: 2px;
}

.login-submit {
    width: 100%;
    padding: 12px 16px;
    border: 0;
    border-radius: 8px;
    background: #e8e8e8;
    color: #202020;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}

.login-submit:hover {
    background: #fff;
}

.login-submit:focus-visible {
    outline: 2px solid #a5b4fc;
    outline-offset: 3px;
}

@media (max-width: 480px) {
    .login-panel {
        padding: 28px 24px;
    }
}

#login-result:empty,
.register-result:empty {
    display: none;
}

#login-result,
.register-result {
    color: #fca5a5;
    font-size: 14px;
    overflow-wrap: anywhere;
}

.auth-footer {
    margin: 24px 0 0;
    text-align: center;
    color: var(--text-secondary);
    font-size: 14px;
}

.auth-footer a {
    color: var(--text-primary);
    text-underline-offset: 3px;
}

.auth-footer a:hover {
    color: #a5b4fc;
}

/* Folder picker: second level stays within the sidebar popup. */
.menu-submenu-trigger {
    list-style: none;
}

.menu-submenu-trigger::-webkit-details-marker {
    display: none;
}

.menu-popup:has(> .menu-submenu[open]) > :not(.menu-submenu),
.menu-submenu[open] > .menu-submenu-trigger {
    display: none;
}

.menu-submenu-content {
    max-height: 240px;
    overflow-y: auto;
    overflow-wrap: anywhere;
}

.menu-empty {
    margin: 0;
    padding: 8px 10px;
    color: var(--text-secondary);
    font-size: 13px;
}

/* Note tags */
.note-tags, .note-tag {
    display: flex;
    align-items: center;
}

.note-tags {
    flex-wrap: wrap;
    gap: 6px 18px;
    color: var(--text-secondary);
    font-size: 13px;
}

.note-tag { position: relative; margin: 0; max-width: calc(100% - 18px); }
.note-tag-name { min-width: 0; overflow-wrap: anywhere; }

.note-tag-input, .note-tag-remove, .note-tag-add {
    border: 0;
    background: transparent;
    color: inherit;
    font: inherit;
    padding: 4px 0;
}

.note-tag-input { width: 90px; min-width: 0; }
.note-tag-input::placeholder { color: var(--text-muted); }
.note-tag-remove, .note-tag-add { cursor: pointer; width: 14px; flex-shrink: 0; }
.note-tag-remove {
    position: absolute;
    left: 100%;
    top: 50%;
    transform: translateY(-50%);
    opacity: 0;
    pointer-events: none;
}
.note-tag:hover .note-tag-remove,
.note-tag:focus-within .note-tag-remove { opacity: 1; pointer-events: auto; }
.note-tag:hover, .note-tag-add:hover { color: var(--text-primary); }

@media (hover: none) {
    .note-tag-remove { opacity: 1; pointer-events: auto; }
}
