* { -webkit-tap-highlight-color: transparent; }

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

@view-transition { navigation: auto; }

:root {
    --bg:          #ffffff;
    --surface:     #ffffff;
    --border:      rgba(0,0,0,.09);
    --border-mid:  rgba(0,0,0,.16);
    --text-primary:   #1a1a18;
    --text-secondary: #6b6a65;
    --text-hint:      #b0afaa;
    --accent:      #534AB7;
    --accent-dark: #3C3489;
    --danger:      #993C1D;
    --danger-bg:   #FAECE7;
    --radius-md:   8px;
    --radius-lg:   12px;
    --font-sans:   'DM Sans', sans-serif;
    --font-mono:   'DM Mono', monospace;
}

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

[hidden] { display: none !important; }

body {
    background-color: var(--bg);
    font-family: var(--font-sans);
    font-size: 15px;
    color: var(--text-primary);
    min-height: 100vh;
    min-height: 100dvh;
    padding-top: 40px;
}

h1, h2, h3, h4, h5, h6 {
    font-family: var(--font-sans);
    font-weight: 500;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.container {
    max-width: 750px;
    margin: 0 auto;
    padding: 0 1.5rem;
    padding-bottom: 1.5rem;
}

/* Header bar */
.header-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-bottom: 1.25rem;
    border-bottom: 0.5px solid var(--border);
    margin-bottom: 1.25rem;
}
.header-bar h2 {
    font-size: 20px;
    font-weight: 500;
    color: var(--text-primary);
}

.header-actions a {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 32px;
    padding: 0 12px;
    font-size: 13px;
    line-height: 1;
}
.header-actions svg {
    width: 16px;
    height: 16px;
}

/* Settings and all grey buttons */
.btn-ghost {
    font-size: 13px;
    font-family: var(--font-sans);
    padding: 6px 14px;
    border-radius: var(--radius-md);
    border: 0.5px solid var(--border-mid);
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    text-decoration: none;
    transition: background .15s, color .15s;
}
.btn-ghost:hover {
    background: #f0eeec;
    text-decoration: none;
    color: var(--text-primary);
}

/* Toolbar */
.toolbar {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 1.25rem;
    flex-wrap: wrap;
}

/* Search */
.search-wrap {
    display: flex;
    align-items: center;
    flex: 1;
    min-width: 180px;
    height: 36px;
    border: 0.5px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface);
    transition: border .15s;
    overflow: hidden;
}
.search-wrap:focus-within { border-color: var(--border-mid); }

.search-wrap input {
    flex: 1;
    height: 100%;
    padding: 0 12px;
    border: none;
    font-size: 13px;
    font-family: var(--font-sans);
    background: transparent;
    color: var(--text-primary);
    outline: none;
}
.search-wrap input::placeholder { color: var(--text-hint); }

/* Toggle pill inside search */
.search-toggle {
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 3px 4px 3px 6px;
    border-right: 0.5px solid var(--border);
    flex-shrink: 0;
}
.toggle-btn {
    padding: 2px 9px;
    font-size: 11px;
    font-weight: 500;
    font-family: var(--font-sans);
    border-radius: 99px;
    border: none;
    background: transparent;
    cursor: pointer;
    color: var(--text-hint);
    transition: background .15s, color .15s;
    white-space: nowrap;
    line-height: 18px;
}
.toggle-btn.active {
    background: var(--accent);
    color: #fff;
}

/* Tag dropdown */
.tag-dropdown-wrap { position: relative; }
.tag-select-btn {
    height: 36px; padding: 0 12px;
    display: flex; align-items: center; gap: 6px;
    border: 0.5px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface);
    color: var(--text-primary);
    font-size: 13px;
    font-family: var(--font-sans);
    cursor: pointer;
    white-space: nowrap;
    transition: border .15s;
    width: 70px;
    flex-shrink: 0;
}
.tag-select-btn:hover { border-color: var(--border-mid); }
.tag-select-btn .chevron { font-size: 10px; color: var(--text-hint); margin-left: 2px; }

.tag-panel {
    display: none;
    position: absolute;
    top: calc(100% + 6px); left: 0;
    z-index: 200;
    min-width: 255px;
    background: var(--surface);
    border: 0.5px solid var(--border-mid);
    border-radius: var(--radius-lg);
    padding: 6px;
    box-shadow: 0 8px 24px rgba(0,0,0,.08);
}
.tag-panel.open { display: block; }
.tag-panel-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 5px 8px;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: 13px;
    color: var(--text-primary);
    transition: background .1s;
    margin-bottom: 3px;
}
.tag-panel-item:hover { background: #f5f4f0; }
.tag-panel-item.selected { background: #EEEDFE; }
.tag-del-btn {
    background: none; border: none; cursor: pointer;
    padding: 2px 6px; font-size: 12px;
    color: var(--text-hint);
    border-radius: 4px; line-height: 1;
    transition: background .1s, color .1s;
}
.tag-del-btn:hover { background: var(--danger-bg); color: var(--danger); }
.tag-panel-empty {
    font-size: 13px; color: var(--text-hint);
    padding: 8px 8px;
}

.tag-panel-mode {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 10px 6px;
    border-bottom: 0.5px solid var(--border-mid);
    margin-bottom: 4px;
}
.tag-panel-mode-label {
    font-size: 11px;
    font-weight: 500;
    color: var(--text-hint, #999);
    letter-spacing: .03em;
    text-transform: uppercase;
}
.tag-mode-toggle {
    display: flex;
    gap: 3px;
    background: rgba(0,0,0,.05);
    border-radius: 99px;
    padding: 3px;
}
.tag-mode-btn {
    padding: 2px 10px;
    font-size: 11px;
    font-weight: 500;
    font-family: var(--font-sans);
    background: transparent;
    border: none;
    border-radius: 99px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: background 0.15s, color 0.15s, box-shadow 0.15s;
    line-height: 1.6;
    text-align: center;
    min-width: 36px;
}
.tag-mode-btn.active {
    background: var(--accent, #6c63ff);
    color: #fff;
    box-shadow: 0 1px 4px rgba(83,74,183,.25);
}
.tag-mode-btn:not(.active):hover {
    background: rgba(0,0,0,.07);
    color: var(--text-primary);
}
.tag-item-actions {
    display: flex;
    align-items: center;
    gap: 2px;
    opacity: 0;
    transition: opacity 0.15s;
}
.tag-panel-item:hover .tag-item-actions {
    opacity: 1;
}
.tag-action-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border: none;
    border-radius: var(--radius-sm, 4px);
    background: transparent;
    color: var(--text-hint, #aaa);
    cursor: pointer;
    padding: 0;
    transition: background 0.12s, color 0.12s;
}
.tag-action-btn:hover {
    background: var(--surface-hover, rgba(0,0,0,.07));
    color: var(--text-secondary);
}
.tag-rename-btn:hover {
    color: var(--accent, #6c63ff);
}

/* Sort dropdown */
.sort-dropdown-wrap { position: relative; }

.sort-select-btn {
    height: 36px;
    padding: 0 12px;
    display: flex;
    align-items: center;
    gap: 6px;
    border: 0.5px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface);
    color: var(--text-primary);
    font-size: 13px;
    font-family: var(--font-sans);
    cursor: pointer;
    white-space: nowrap;
    flex-shrink: 0;
    transition: border-color .15s;
}
.sort-select-btn:hover { border-color: var(--border-mid); }

.sort-panel {
    display: none;
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    z-index: 300;
    min-width: 160px;
    background: var(--surface);
    border: 0.5px solid var(--border-mid);
    border-radius: var(--radius-lg);
    padding: 6px;
    box-shadow: 0 8px 24px rgba(0,0,0,.1);
}
.sort-panel.open { display: block; }

.sort-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 5px 8px;
    gap: 12px;
    margin-bottom: 2px;
}
.sort-row-label {
    font-size: 13px;
    color: var(--text-primary);
    white-space: nowrap;
}

.sort-pill-btn {
    border: 0.5px solid var(--border-mid);
    border-radius: 99px;
    background: transparent;
    cursor: pointer;
    padding: 0;
    flex-shrink: 0;
    transition: border-color .15s, background .15s, box-shadow .15s;
}
.sort-pill-btn:hover {
    border-color: var(--accent);
    background: #EEEDFE;
    box-shadow: 0 0 0 3px rgba(83,74,183,.1);
}
.sort-pill-btn.active {
    border-color: var(--accent);
    background: var(--accent);
    box-shadow: 0 0 0 3px rgba(83,74,183,.15);
}
.sort-pill-btn.active .sort-pill-text,
.sort-pill-btn.active .sort-pill-icon { color: #fff; }

.sort-pill-inner {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px 4px 8px;
}
.sort-pill-icon {
    display: flex;
    align-items: center;
    color: var(--text-secondary);
    transition: transform .25s cubic-bezier(.34,1.56,.64,1);
}
.sort-pill-btn.flipped .sort-pill-icon { transform: rotate(180deg); }
.sort-pill-text {
    font-size: 11px;
    font-weight: 500;
    font-family: var(--font-sans);
    color: var(--text-secondary);
    white-space: nowrap;
    transition: color .15s;
    display: inline-block;
    min-width: 46px;
}

/* Add note / Edit note button */
.btn-add-note,
.btn-edit-note {
    height: 36px; padding: 0 16px;
    display: flex; align-items: center; gap: 7px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--radius-md);
    font-size: 13px;
    font-weight: 500;
    font-family: var(--font-sans);
    cursor: pointer;
    white-space: nowrap;
    text-decoration: none;
    transition: background .15s;
}
.btn-add-note:hover,
.btn-edit-note:hover { background: var(--accent-dark); text-decoration: none; color: #fff; }
.btn-add-note svg { width: 13px; height: 13px; flex-shrink: 0; }
.btn-edit-note { width: 60px; }

/* Notes grid */
.notes-grid {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

/* Note card */
.note-card {
    width: 100%;
    max-width: 800px;
    background: var(--surface);
    border: 0.5px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 14px 18px;
    display: flex;
    align-items: center;
    gap: 16px;
    transition: border .15s, box-shadow .15s;
}
.note-card:hover {
    border-color: var(--border-mid);
    box-shadow: 0 2px 8px rgba(0,0,0,.04);
}
.note-body { flex: 1; min-width: 0; }
.note-title {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 7px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.note-tags { display: flex; flex-wrap: wrap; gap: 4px; }
.note-tags .pill { box-shadow: 0 0 0 2px var(--surface); }

/* Pills */
.pill {
    display: inline-flex;
    align-items: center;
    padding: 2px 9px;
    border-radius: 99px;
    font-size: 11px;
    font-weight: 500;
    font-family: var(--font-mono);
    letter-spacing: 0.01em;
}
.pill-purple { background: #EEEDFE; color: #3C3489; }
.pill-teal   { background: #E1F5EE; color: #085041; }
.pill-coral  { background: #FAECE7; color: #712B13; }
.pill-blue   { background: #E6F1FB; color: #0C447C; }
.pill-amber  { background: #FAEEDA; color: #633806; }
.pill-pink   { background: #FBEAF0; color: #72243E; }

/* Extra pill colors */
.pill-green   { background: #E3F5E9; color: #1A5C2E; }
.pill-indigo  { background: #E8EAF6; color: #283593; }
.pill-rose    { background: #FCE4EC; color: #880E4F; }
.pill-cyan    { background: #E0F7FA; color: #00606F; }
.pill-lime    { background: #F0FBE4; color: #3B5E08; }
.pill-emerald { background: #D9F5E9; color: #065F3C; }
.pill-violet  { background: #EDE9FE; color: #4C1D95; }
.pill-fuchsia { background: #FDF4FF; color: #86198F; }
.pill-sky     { background: #E0F2FE; color: #0C4A6E; }
.pill-orange  { background: #FFF0E0; color: #7C2D12; }
.pill-red     { background: #FEECEC; color: #7F1D1D; }
.pill-yellow  { background: #FEFCE8; color: #713F12; }
.pill-slate   { background: #F1F5F9; color: #1E293B; }
.pill-gray    { background: #F3F4F6; color: #1F2937; }
.pill-zinc    { background: #F4F4F5; color: #18181B; }
.pill-neutral { background: #F5F5F5; color: #171717; }
.pill-stone   { background: #F5F5F4; color: #1C1917; }
.pill-brown   { background: #F3EDE8; color: #5C2E0E; }
.pill-gold    { background: #FDF8E1; color: #7A5700; }

/* Action icon buttons */
.note-actions { display: flex; gap: 3px; flex-shrink: 0; }
.icon-btn {
    width: 40px; height: 40px;
    display: flex; align-items: center; justify-content: center;
    border: none;
    background: transparent;
    border-radius: var(--radius-md);
    cursor: pointer;
    color: var(--text-hint);
    text-decoration: none;
    transition: background .12s, color .12s;
}
.icon-btn:hover { background: #f0eeec; color: var(--text-primary); }
.icon-btn.del:hover { background: var(--danger-bg); color: var(--danger); }
.icon-btn svg { width: 14px; height: 14px; }

/* Toast */

#toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(12px);
    background: #1a1a18;
    color: #fff;
    font-size: 13px;
    font-family: var(--font-sans);
    padding: 9px 18px;
    border-radius: var(--radius-md, 8px);
    box-shadow: 0 4px 16px rgba(0,0,0,.18);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s, transform 0.2s;
    z-index: 9999;
    white-space: nowrap;
}
#toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}
#toast.toast-error { background: var(--danger, #993C1D); }
#toast.toast-success { background: #3a9e68; }

/* Settings Dropdown */

.settings-item {
    display: block;
    width: 100%;
    text-align: left;
    padding: 7px 12px;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 13px;
    font-family: var(--font-sans);
    color: var(--text-primary);
    border-radius: var(--radius-sm, 4px);
    transition: background 0.12s;
}
.settings-item:hover {
    background: var(--surface-hover, rgba(0,0,0,.06));
}
.settings-item--danger {
    color: var(--danger, #993C1D);
}
.settings-item--danger:hover {
    background: rgba(153, 60, 29, 0.08);
}
.settings-divider {
    height: 1px;
    flex: 0 0 auto; 
    background: var(--border-mid);
    margin: 4px 0;
}

.settings-user-email {
    margin: 0 -3px -3px;
    padding: 9px 12px;

    font-family: var(--font-sans);
    font-size: 11px;
    font-weight: 500;
    line-height: 1.4;
    letter-spacing: 0.01em;

    color: var(--text-secondary, #777);
    background: var(--bg-secondary, rgba(0, 0, 0, .025));

    border-top: 1px solid var(--border, rgba(0, 0, 0, .06));
    border-radius: 0 0 7px 7px;

    text-align: center;
    overflow-wrap: anywhere;
    user-select: text;
}

/* Toolbar buttons (ghost / accent / info) */
.toolbar-btn {
    height: 36px;
    padding: 0 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border-radius: var(--radius-md);
    font-size: 13px;
    font-weight: 400;
    font-family: var(--font-sans);
    cursor: pointer;
    white-space: nowrap;
    transition: background .15s, color .15s, border-color .15s;
    flex-shrink: 0;
    min-width: 85px;
}
.toolbar-btn-ghost {
    border: 0.5px solid var(--border);
    background: var(--surface);
    color: var(--text-primary);
}
@media (hover: hover) {
    .toolbar-btn-ghost:hover {
        border-color: var(--border-mid);
        background: #f5f4f0;
    }
}
.toolbar-btn-accent {
    border: 0.5px solid transparent;
    background: var(--accent);
    color: #fff;
    font-weight: 500;
}
.toolbar-btn-accent:hover { background: var(--accent-dark); }

/* ── Markdown info button ─────────────────────────────────── */
.toolbar-btn-info {
    height: 36px;
    width: 50px;
    min-width: unset;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-md);
    border: 0.5px solid var(--border);
    background: transparent;
    color: var(--text-hint);
    cursor: pointer;
    transition: background .15s, color .15s, border-color .15s;
    flex-shrink: 0;
    text-decoration: none;
}
.toolbar-btn-info:hover {
    border-color: var(--border-mid);
    background: #f5f4f0;
    color: var(--text-secondary);
    text-decoration: none;
}

/* Markdown images (note view, edit preview, public view) */
.markdown-body img { display: block; max-width: 100%; height: auto; margin: 16px auto; border-radius: 6px; }

/* Empty state */
.no-notes {
    text-align: center;
    padding: 3.5rem 1rem;
    font-size: 14px;
    color: var(--text-hint);
    width: 100%;
}

/* Note page body (shared by note.html and note_public.html) */
.note { padding-bottom: 80vh; }

/* Note page title (shared by note.html and note_public.html) */
.header-bar h2.note-heading {
    flex: 1;
    min-width: 0;
    margin-right: 16px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Mobile: scroll the full title sideways instead of cutting it with "..." */
@media (max-width: 600px) {
    .header-bar h2.note-heading {
        overflow-x: auto;
        overflow-y: hidden;
        text-overflow: clip;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;            /* Firefox */
    }
    .header-bar h2.note-heading::-webkit-scrollbar { display: none; }  /* Chrome/Safari */
}

/* Shared mobile / touch rules */
@media (hover: none) {
    .tag-item-actions { opacity: 1; }          /* no hover on touch: show tag actions permanently */
    .tag-action-btn   { width: 32px; height: 32px; }
    .tag-del-btn      { padding: 8px 10px; font-size: 13px; }
}
@media (max-width: 600px) {
    .settings-item { padding: 12px; }
    #settingsDropdown { min-width: 200px !important; }

    #toast {
        white-space: normal;
        text-align: center;
        width: max-content;
        max-width: calc(100vw - 32px);
        bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    }
}

/* Form notices (errors / limits) */
.form-notice {
    font-size: 13px;
    line-height: 1.45;
    border-radius: var(--radius-md);
    padding: 9px 12px;
    margin-bottom: 12px;
}
.form-notice--err { background: var(--danger-bg); color: var(--danger); }

/* Danger alert box with icon (e.g. delete confirmation) */
.alert-danger {
    background: var(--danger-bg);
    border: 0.5px solid rgba(153,60,29,.18);
    border-radius: var(--radius-lg);
    padding: 18px 20px;
    display: flex;
    align-items: flex-start;
    gap: 14px;
    margin-bottom: 1.75rem;
}
.alert-danger svg { flex-shrink: 0; margin-top: 1px; stroke: var(--danger); }
.alert-danger p {
    font-size: 13px;
    color: var(--danger);
    line-height: 1.5;
    margin: 0;
}

/* Danger button (delete) */
.btn-danger {
    height: 36px;
    padding: 0 16px;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    background: var(--danger);
    color: #fff;
    border: none;
    border-radius: var(--radius-md);
    font-size: 13px;
    font-weight: 500;
    font-family: var(--font-sans);
    cursor: pointer;
    transition: opacity .15s;
}
.btn-danger:hover { opacity: .85; }

/* Row of form action buttons (submit + cancel) */
.form-actions { display: flex; align-items: center; gap: 10px; }
.form-actions .btn-ghost {
    height: 36px;
    padding: 0 16px;
    display: inline-flex;
    align-items: center;
}

/* Narrow centered card page (verify email, social login confirm) */
.center-wrap {
    max-width: 380px;
    margin: 4rem auto 0;
    padding: 0 1rem;
}
.center-card {
    background: var(--surface);
    border: 0.5px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 32px 30px 36px;
    text-align: center;
}
.center-card h1 {
    font-size: 20px;
    font-weight: 500;
    margin-bottom: 0.75rem;
    color: var(--text-primary);
}
.center-card p {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.5;
    margin-bottom: 1.5rem;
}

/* Full-width accent button */
.btn-accent-block {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 36px;
    border: 0.5px solid var(--border);
    border-radius: var(--radius-md);
    font-size: 13px;
    font-weight: 500;
    font-family: var(--font-sans);
    color: #fff;
    background: var(--accent);
    cursor: pointer;
    transition: background .15s;
}
.btn-accent-block:hover { background: var(--accent-dark); }