:root {
    --bg: #fafafa;
    --surface: #ffffff;
    --border: #e5e5e5;
    --text: #1a1a1a;
    --text-muted: #8a8a8a;
    --accent: #2563eb;
    --danger: #d1453b;
    --radius: 10px;
    color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    -webkit-font-smoothing: antialiased;
}

[x-cloak] { display: none !important; }

button {
    font-family: inherit;
    cursor: pointer;
}

/* ---------- Top bar ---------- */

.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 14px 12px 8px;
    background: var(--bg);
}

.icon-btn {
    width: 40px;
    height: 40px;
    border: none;
    background: transparent;
    border-radius: 999px;
    font-size: 22px;
    color: var(--text);
    display: flex;
    align-items: center;
    justify-content: center;
}
.icon-btn:active { background: var(--border); }

.date-jump {
    position: relative;
    flex: 1;
    display: flex;
    justify-content: center;
}

.date-label {
    border: none;
    background: transparent;
    font-size: 17px;
    font-weight: 600;
    padding: 6px 12px;
    border-radius: 999px;
    color: var(--text);
}
.date-label:active { background: var(--border); }

.date-picker-popover {
    position: absolute;
    top: 40px;
    left: 50%;
    transform: translateX(-50%);
    width: 280px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 8px 24px rgba(0,0,0,0.12);
    z-index: 30;
    padding: 12px;
}

.dp-row {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-bottom: 8px;
}

.dp-years {
    justify-content: center;
}

.dp-chip {
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text);
    font-size: 13px;
    font-weight: 500;
    padding: 6px 10px;
    border-radius: 999px;
}
.dp-years .dp-chip {
    flex: 1;
    text-align: center;
    font-weight: 600;
}
.dp-months .dp-chip {
    flex: 1 0 21%;
    text-align: center;
    padding: 6px 4px;
}
.dp-chip.active {
    background: var(--text);
    border-color: var(--text);
    color: #fff;
}

.dp-weekday-labels {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    text-align: center;
    font-size: 11px;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.dp-days {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 2px;
}

.dp-day {
    aspect-ratio: 1;
    border: none;
    background: transparent;
    border-radius: 999px;
    font-size: 13px;
    color: var(--text);
    display: flex;
    align-items: center;
    justify-content: center;
}
.dp-day:active { background: var(--bg); }
.dp-day.today {
    font-weight: 700;
    color: var(--accent);
}
.dp-day.active {
    background: var(--text);
    color: #fff;
}
.dp-day.blank {
    visibility: hidden;
    pointer-events: none;
}

.subbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 14px 10px;
}

.link-btn {
    border: none;
    background: transparent;
    color: var(--accent);
    font-size: 14px;
    font-weight: 500;
    padding: 6px 4px;
}

.new-note-btn {
    margin-left: auto;
    border: none;
    background: var(--text);
    color: #fff;
    font-size: 14px;
    font-weight: 600;
    padding: 9px 16px;
    border-radius: 999px;
}
.new-note-btn:active { opacity: 0.8; }

/* ---------- Block list ---------- */

.block-list {
    max-width: 680px;
    margin: 0 auto;
    padding: 4px 12px 120px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.empty-state {
    color: var(--text-muted);
    font-size: 15px;
    text-align: center;
    margin-top: 40px;
}

.block {
    position: relative;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: visible;
}

.block:not(.is-editing) .block-toolbar {
    display: none;
}

.block:not(.is-editing) .editor-surface {
    cursor: text;
}

.add-note-card {
    background: transparent;
    border: 1.5px dashed var(--border);
    border-radius: var(--radius);
    padding: 14px;
    font-size: 15px;
    color: var(--text-muted);
    text-align: left;
    width: 100%;
}
.add-note-card:active {
    background: var(--surface);
}

.editor-surface {
    padding: 12px 14px 16px;
    font-size: 15px;
    line-height: 1.5;
    min-height: 32px;
}

.editor-surface .tiptap { outline: none; }
.editor-surface .tiptap p { margin: 0 0 0.5em; }
.editor-surface .tiptap p:last-child { margin-bottom: 0; }
.editor-surface .tiptap ul, .editor-surface .tiptap ol { margin: 0 0 0.5em; padding-left: 1.3em; }
.editor-surface .tiptap a { color: var(--accent); }
.editor-surface .tiptap p.is-editor-empty:first-child::before {
    content: "Write something\2026";
    color: var(--text-muted);
    float: left;
    height: 0;
    pointer-events: none;
}

.editor-surface .tiptap ul[data-type="taskList"] {
    list-style: none;
    padding-left: 0;
    margin: 0 0 0.5em;
}
.editor-surface .tiptap ul[data-type="taskList"] li {
    display: flex;
    align-items: flex-start;
    gap: 8px;
}
.editor-surface .tiptap ul[data-type="taskList"] li > label {
    margin-top: 3px;
    user-select: none;
}
.editor-surface .tiptap ul[data-type="taskList"] li > div {
    flex: 1;
}
.editor-surface .tiptap ul[data-type="taskList"] li[data-checked="true"] > div {
    color: var(--text-muted);
    text-decoration: line-through;
}
.editor-surface .tiptap ul[data-type="taskList"] input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--text);
    cursor: pointer;
}

/* ---------- Block toolbar ---------- */

.block-toolbar {
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 6px 8px;
    border-top: 1px solid var(--border);
}

.tb-btn {
    width: 30px;
    height: 30px;
    border: none;
    background: transparent;
    border-radius: 6px;
    font-size: 14px;
    color: var(--text);
    display: flex;
    align-items: center;
    justify-content: center;
}
.tb-btn:active { background: var(--bg); }

.save-btn {
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 600;
    padding: 6px 10px;
    border-radius: 6px;
    margin-right: 2px;
}
.block.is-dirty .save-btn {
    color: var(--accent);
}
.save-btn:active {
    background: var(--bg);
}

.block.is-dirty::before {
    content: "";
    position: absolute;
    top: 8px;
    right: 8px;
    width: 7px;
    height: 7px;
    border-radius: 999px;
    background: var(--accent);
}
.block.is-editing.is-dirty::before {
    display: none;
}

.tb-sep {
    width: 1px;
    height: 18px;
    background: var(--border);
    margin: 0 4px;
}

.tb-spacer { flex: 1; }

/* ---------- Block settings menu ---------- */

.block-menu { position: relative; }

.menu-popover {
    position: absolute;
    right: 0;
    bottom: 36px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 8px 24px rgba(0,0,0,0.12);
    min-width: 220px;
    z-index: 20;
    padding: 10px;
}

.menu-label {
    font-size: 12px;
    color: var(--text-muted);
    padding: 4px 6px 8px;
}

.weekday-chips {
    display: flex;
    gap: 4px;
    padding: 0 2px 10px;
}

.chip {
    width: 28px;
    height: 28px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: transparent;
    font-size: 12px;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
}
.chip.active {
    background: var(--text);
    border-color: var(--text);
    color: #fff;
}

.menu-item {
    display: block;
    width: 100%;
    text-align: left;
    border: none;
    background: transparent;
    padding: 9px 6px;
    font-size: 14px;
    border-radius: 6px;
    color: var(--text);
}
.menu-item:active { background: var(--bg); }
.menu-item.danger { color: var(--danger); }

/* ---------- Scope modal ---------- */

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.35);
    display: flex;
    align-items: flex-end;
    justify-content: center;
    z-index: 50;
}

.modal-sheet {
    background: var(--surface);
    width: 100%;
    max-width: 420px;
    border-radius: 16px 16px 0 0;
    padding: 10px 10px calc(10px + env(safe-area-inset-bottom));
    display: flex;
    flex-direction: column;
}

.modal-title {
    font-size: 13px;
    color: var(--text-muted);
    text-align: center;
    padding: 10px 10px 6px;
}

.modal-option, .modal-cancel {
    border: none;
    background: transparent;
    padding: 14px 10px;
    font-size: 16px;
    text-align: center;
    border-top: 1px solid var(--border);
    color: var(--text);
}
.modal-option:active, .modal-cancel:active { background: var(--bg); }

.modal-cancel {
    margin-top: 8px;
    border-top: none;
    background: var(--bg);
    border-radius: 10px;
    font-weight: 600;
}

/* ---------- Login ---------- */

.login-body {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.login-form {
    width: 100%;
    max-width: 320px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.login-form h1 {
    font-size: 22px;
    margin: 0 0 4px;
    text-align: center;
}

.login-form label {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 13px;
    color: var(--text-muted);
}

.login-form input[type="text"],
.login-form input[type="password"] {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 12px;
    font-size: 15px;
    font-family: inherit;
    color: var(--text);
}

.login-form button {
    margin-top: 6px;
    border: none;
    background: var(--text);
    color: #fff;
    border-radius: 8px;
    padding: 11px;
    font-size: 15px;
    font-weight: 600;
}

.login-error {
    color: var(--danger);
    font-size: 13px;
    margin: 0;
    text-align: center;
}

/* ---------- Desktop ---------- */

@media (min-width: 700px) {
    .topbar { padding-top: 22px; }
    .modal-backdrop { align-items: center; }
    .modal-sheet {
        border-radius: 14px;
        max-width: 340px;
    }
}
