/* ====================== Rich — tokens ====================== */
:root {
    --safe-top: 0px;
    --bottom-inset: 0px;
    --bg:        #ffffff;
    --surface:   #ffffff;
    --surface-2: #f4f5f7;
    --border:    #ebecef;
    --text:      #1a1c20;
    --text-2:    #707684;
    --text-3:    #a4a9b4;
    --accent:    #2f6df6;
    --danger:    #e5484d;
    --line:      1px solid var(--border);
    --radius:    14px;
    --radius-sm: 10px;
    --tap: rgba(0,0,0,.045);
}
[data-theme="dark"] {
    --bg:        #0e0f12;
    --surface:   #16181d;
    --surface-2: #1d2026;
    --border:    #262a31;
    --text:      #eef0f3;
    --text-2:    #8b91a0;
    --text-3:    #5b6170;
    --accent:    #5b8dff;
    --danger:    #ff6166;
    --tap: rgba(255,255,255,.05);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; height: 100%; overscroll-behavior: none; }
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg); color: var(--text);
    display: flex; flex-direction: column;
    height: 100vh; height: 100dvh; font-size: 15px;
}
.ic { display: block; }
button { font-family: inherit; }
#safe-top { height: var(--safe-top); flex: 0 0 auto; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideup { from { transform: translateY(100%); } to { transform: none; } }

/* ====================== top bar ====================== */
.topbar { flex: 0 0 auto; display: flex; align-items: center; gap: 4px; padding: 8px 10px 6px 18px; border-bottom: var(--line); }
.title-input { flex: 1; min-width: 0; border: none; background: none; outline: none; color: var(--text); font-size: 19px; font-weight: 800; }
.title-input::placeholder { color: var(--text-3); }
.iconbtn { background: none; border: none; cursor: pointer; color: var(--text-2); display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px; border-radius: 10px; flex: 0 0 auto; }
.iconbtn:active { background: var(--tap); }
.iconbtn.accent { color: var(--accent); }

.editor-area { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; padding: 6px 18px 0; }

/* post buttons bar (published as inline keyboard under the post) */
.btnbar { flex: 0 0 auto; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 8px 18px calc(10px + var(--bottom-inset)); border-top: var(--line); }
.btn-chips { display: flex; gap: 6px; flex-wrap: wrap; min-width: 0; }
.btn-chip { display: inline-flex; align-items: center; gap: 6px; max-width: 200px; background: var(--accent); color: #fff; border: none; border-radius: 999px; padding: 7px 12px; font-size: 13px; font-weight: 700; cursor: pointer; }
.btn-chip span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.btn-chip .ic { flex: 0 0 auto; }
.chip-add { display: inline-flex; align-items: center; gap: 5px; background: none; border: 1px dashed var(--border); color: var(--text-3); border-radius: 999px; padding: 7px 12px; font-size: 13px; font-weight: 700; cursor: pointer; }

/* ====================== modals ====================== */
.modal-overlay { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.4); display: flex; align-items: flex-end; justify-content: center; animation: fade .15s ease; }
.modal-overlay[hidden] { display: none; }
#prompt-modal { z-index: 60; }
#confirm-modal { z-index: 70; }
.modal-sheet { width: 100%; max-width: 540px; background: var(--surface); border-radius: 20px 20px 0 0; padding: 8px 18px calc(18px + var(--bottom-inset)); max-height: 80vh; overflow-y: auto; animation: slideup .22s cubic-bezier(.2,.8,.2,1); }
.modal-handle { width: 36px; height: 4px; border-radius: 2px; background: var(--border); margin: 0 auto 12px; }
.modal-sheet h3 { margin: 4px 0 10px; font-size: 17px; }
.modal-footer { display: flex; gap: 10px; margin-top: 18px; }
.btn-primary, .btn-ghost, .btn-danger { flex: 1; border: none; border-radius: var(--radius-sm); padding: 13px; font-size: 15px; font-weight: 700; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 7px; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-ghost { background: var(--surface-2); color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.full { width: 100%; flex: none; margin-top: 10px; }
.prompt-input { width: 100%; border: var(--line); background: var(--surface-2); color: var(--text); border-radius: var(--radius-sm); padding: 12px; font-size: 16px; outline: none; }
.hint { color: var(--text-3); font-size: 13px; line-height: 1.5; }

.post-list, .channel-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.post-list li, .channel-list li { display: flex; align-items: center; gap: 11px; padding: 11px 10px; border-radius: var(--radius-sm); cursor: pointer; }
.post-list li.active { background: var(--surface-2); }
.post-list li:active, .channel-list li:active { background: var(--tap); }
.pl-ic { width: 36px; height: 36px; border-radius: 9px; background: var(--surface-2); color: var(--accent); display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto; }
.pl-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.pl-main b { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pl-main small { color: var(--text-3); font-size: 12px; }
.pl-del { background: none; border: none; color: var(--text-3); cursor: pointer; display: inline-flex; padding: 6px; }

.toast { position: fixed; left: 50%; bottom: calc(28px + var(--bottom-inset)); transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-size: 13px; font-weight: 600; z-index: 90; }
.toast[hidden] { display: none; }

.round-check { width: 22px; height: 22px; flex: 0 0 auto; cursor: pointer; border: 2px solid var(--text-3); border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; color: #fff; transition: background .15s, border-color .15s; }
.round-check .ic { width: 14px; height: 14px; opacity: 0; }
.round-check.checked { background: var(--accent); border-color: var(--accent); }
.round-check.checked .ic { opacity: 1; }

.file-del { position: absolute; top: 4px; right: 4px; width: 21px; height: 21px; border-radius: 50%; background: rgba(0,0,0,.55); color: #fff; border: none; cursor: pointer; display: flex; align-items: center; justify-content: center; padding: 0; }

/* ===== Block editor ===== */
.rich-wrap { flex: 1 1 auto; min-height: 0; flex-direction: column; }
.rich-wrap[hidden] { display: none; }
.blocks-root { flex: 1 1 auto; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 4px 0 40px; }
.blk { position: relative; padding: 2px 30px 2px 0; border-radius: 8px; }
.blk-menu { position: absolute; right: 0; top: 4px; width: 26px; height: 26px; border: none; background: none; color: var(--text-3); display: inline-flex; align-items: center; justify-content: center; cursor: pointer; opacity: .55; }
.blk:focus-within .blk-menu { opacity: 1; }
.blk-actions { position: absolute; right: 28px; top: 0; display: flex; gap: 2px; background: var(--surface); border: var(--line); border-radius: 10px; padding: 3px; z-index: 5; box-shadow: 0 4px 14px rgba(0,0,0,.15); }
.blk-actions button { width: 32px; height: 30px; border: none; background: none; color: var(--text-2); border-radius: 7px; display: inline-flex; align-items: center; justify-content: center; cursor: pointer; }
.blk-actions button.danger { color: var(--danger); }
.blk-actions button:active { background: var(--tap); }
.blk-text { min-height: 26px; outline: none; font-size: 16px; line-height: 1.5; padding: 3px 0; -webkit-user-select: text; }
.blk-text:empty::before { content: attr(data-ph); color: var(--text-3); pointer-events: none; }
.blk-h1 .blk-text { font-size: 24px; font-weight: 800; }
.blk-h2 .blk-text { font-size: 20px; font-weight: 800; }
.blk-h3 .blk-text { font-size: 17px; font-weight: 700; }
.blk-footer .blk-text { font-size: 13px; color: var(--text-3); }
.li-row { display: flex; align-items: flex-start; gap: 9px; }
.li-row .blk-text { flex: 1; }
.li-row .round-check { margin-top: 6px; flex: 0 0 auto; }
.li-marker { color: var(--text-2); font-weight: 700; margin-top: 4px; min-width: 14px; text-align: right; }
.blk-quote .blk-text { border-left: 3px solid var(--accent); background: var(--surface-2); padding: 8px 12px; border-radius: 0 8px 8px 0; color: var(--text-2); }
.blk-pull .blk-text { text-align: center; font-style: italic; font-size: 18px; color: var(--text-2); padding: 8px 12px; }
.blk-cite { width: 100%; border: none; background: none; color: var(--text-3); font-size: 13px; padding: 2px 12px; outline: none; }
.blk-lang { width: 100%; border: none; background: none; color: var(--text-3); font-size: 12px; font-family: ui-monospace, Menlo, monospace; padding: 2px 0; outline: none; }
.blk-code { width: 100%; border: var(--line); background: var(--surface-2); color: var(--text); border-radius: 10px; padding: 10px 12px; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; resize: none; outline: none; min-height: 60px; overflow: hidden; }
.blk-divider hr { border: none; border-top: 1px solid var(--border); margin: 10px 0; }
.blk-summary { width: 100%; border: none; background: var(--surface-2); border-radius: 9px; padding: 9px 12px; font-weight: 700; font-size: 15px; color: var(--text); outline: none; }
.blk-toggle-body { margin: 6px 0 0 12px; border-left: 2px solid var(--border); padding-left: 10px; }
.ed-add { display: flex; align-items: center; gap: 6px; margin: 10px 0; border: 1px dashed var(--border); background: none; color: var(--text-3); border-radius: 10px; padding: 9px 14px; font-size: 14px; font-weight: 600; cursor: pointer; }
/* table */
.tbl-wrap { border: var(--line); border-radius: 10px; overflow-x: auto; }
.tbl { display: table; width: 100%; border-collapse: collapse; }
.tbl-row { display: table-row; }
.tbl-cell { display: table-cell; border: 1px solid var(--border); padding: 7px 9px; font-size: 14px; min-width: 60px; outline: none; }
.tbl-wrap.header .tbl-row:first-child .tbl-cell { background: var(--surface-2); font-weight: 700; }
.tbl-wrap.striped .tbl-row:nth-child(even) .tbl-cell { background: var(--surface-2); }
.tbl-bar { display: flex; gap: 5px; flex-wrap: wrap; margin-top: 7px; }
.tbl-bar button { padding: 7px 10px; border: none; background: var(--surface-2); color: var(--text); border-radius: 8px; font-weight: 700; font-size: 12px; cursor: pointer; }
.tbl-bar button.on { background: var(--accent); color: #fff; }
/* media blocks */
.media-prev { width: 120px; height: 120px; border-radius: 12px; background: var(--surface-2); background-size: cover; background-position: center; position: relative; display: flex; align-items: center; justify-content: center; }
.media-kind { font-weight: 800; color: var(--text-3); }
.media-pick { padding: 6px 0; }
.pick-grid { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 8px; }
.pick-thumb { flex: 0 0 auto; width: 64px; height: 64px; border-radius: 10px; background: var(--surface-2); background-size: cover; background-position: center; cursor: pointer; border: 2px solid transparent; }
.pick-thumb:active { border-color: var(--accent); }
.pick-btns { display: flex; gap: 8px; }
.pick-btn { flex: 1; padding: 10px; border: var(--line); background: var(--surface-2); color: var(--text); border-radius: 9px; font-weight: 700; font-size: 13px; cursor: pointer; }
.gal-row { display: flex; gap: 8px; overflow-x: auto; padding: 4px 0; }
.gal-thumb { flex: 0 0 auto; width: 64px; height: 64px; border-radius: 10px; background: var(--surface-2); background-size: cover; background-position: center; position: relative; display: flex; align-items: center; justify-content: center; color: var(--text-3); }
.gal-add { flex: 0 0 auto; width: 64px; height: 64px; border-radius: 10px; border: 1px dashed var(--border); background: none; color: var(--text-3); cursor: pointer; display: flex; align-items: center; justify-content: center; }
/* slash menu */
.slash-ov { position: fixed; inset: 0; z-index: 120; background: rgba(0,0,0,.4); display: flex; align-items: flex-end; justify-content: center; animation: fade .15s ease; }
.slash-sheet { width: 100%; max-width: 540px; background: var(--surface); border-radius: 20px 20px 0 0; padding: 14px 16px calc(14px + var(--bottom-inset)); max-height: 65vh; display: flex; flex-direction: column; gap: 10px; animation: slideup .22s cubic-bezier(.2,.8,.2,1); }
.slash-search { border: var(--line); background: var(--surface-2); color: var(--text); border-radius: 10px; padding: 11px 13px; font-size: 15px; outline: none; }
.slash-list { overflow-y: auto; -webkit-overflow-scrolling: touch; }
.slash-cat { font-size: 11px; font-weight: 800; color: var(--text-3); text-transform: uppercase; letter-spacing: .05em; margin: 12px 2px 4px; }
.slash-item { display: flex; align-items: center; gap: 12px; padding: 9px 6px; border-radius: 10px; cursor: pointer; }
.slash-item:active { background: var(--tap); }
.slash-ic { width: 36px; height: 36px; border-radius: 9px; background: var(--surface-2); color: var(--accent); display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto; }
.slash-tx { display: flex; flex-direction: column; min-width: 0; }
.slash-tx b { font-size: 15px; }
.slash-tx small { color: var(--text-3); font-size: 12px; }
/* floating selection bar */
.selbar { position: fixed; z-index: 130; display: none; gap: 2px; background: var(--surface); border: var(--line); border-radius: 12px; padding: 4px; box-shadow: 0 6px 20px rgba(0,0,0,.25); }
.selbar button { width: 34px; height: 32px; border: none; background: none; color: var(--text); border-radius: 8px; display: inline-flex; align-items: center; justify-content: center; cursor: pointer; }
.selbar button:active { background: var(--accent); color: #fff; }


/* rendered rich content (shared by the editor and the read-only note) */
.rich-content h1, .rich-content h2, .rich-content h3 { font-weight: 800; margin: .6em 0 .3em; line-height: 1.25; }
.rich-content h1 { font-size: 20px; } .rich-content h2 { font-size: 18px; } .rich-content h3 { font-size: 16px; }
.rich-content p { margin: .4em 0; }
.rich-content blockquote { margin: .5em 0; padding: 6px 12px; border-left: 3px solid var(--accent); color: var(--text-2); background: var(--surface-2); border-radius: 0 8px 8px 0; }
.rich-content code { background: var(--surface-2); padding: 1px 5px; border-radius: 5px; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .92em; }
.rich-content pre { background: var(--surface-2); padding: 10px 12px; border-radius: 8px; overflow-x: auto; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .9em; white-space: pre; }
.rich-content pre code { background: none; padding: 0; }
.rich-content hr { border: none; border-top: 1px solid var(--border); margin: 12px 0; }
.rich-content a { color: var(--accent); text-decoration: underline; }
.rich-content table { border-collapse: collapse; width: 100%; margin: .5em 0; font-size: 14px; }
.rich-content th, .rich-content td { border: 1px solid var(--border); padding: 5px 8px; text-align: left; }
.rich-content th { background: var(--surface-2); font-weight: 700; }
.rich-content .tg-spoiler { background: var(--text-3); color: transparent; border-radius: 4px; box-decoration-break: clone; cursor: pointer; }
.rich-content .tg-spoiler.revealed { background: var(--surface-2); color: inherit; }
.rich-content aside { margin: .8em 0; text-align: center; font-style: italic; font-size: 17px; color: var(--text-2); }
.rich-content aside cite, .rich-content blockquote cite { display: block; margin-top: 4px; font-style: normal; font-size: 12px; color: var(--text-3); }
.rich-content footer { font-size: 13px; color: var(--text-3); margin: .5em 0; }
.rich-content details { margin: .5em 0; background: var(--surface-2); border-radius: 10px; padding: 8px 12px; }
.rich-content summary { font-weight: 700; cursor: pointer; }
.rich-content ul.task-list { list-style: none; padding-left: 4px; }
.rich-content ul.task-list li { display: flex; align-items: flex-start; gap: 8px; margin: 4px 0; cursor: pointer; }
.rich-content ul.task-list li::before { content: ""; width: 18px; height: 18px; flex: 0 0 auto; margin-top: 2px; border: 2px solid var(--text-3); border-radius: 50%; }
.rich-content ul.task-list li[data-done="1"] { color: var(--text-3); text-decoration: line-through; }
.rich-content ul.task-list li[data-done="1"]::before { background: var(--accent); border-color: var(--accent); content: "✓"; color: #fff; font-size: 12px; font-weight: 800; display: flex; align-items: center; justify-content: center; }
.rich-content figure { margin: .7em 0; }
.rich-content figure img, .rich-content figure video { max-width: 100%; border-radius: 12px; display: block; }
.rich-content figure audio { width: 100%; }
.rich-content figcaption { font-size: 12px; color: var(--text-3); margin-top: 4px; text-align: center; }
.rich-content tg-collage, .rich-content tg-slideshow { display: flex; gap: 6px; overflow-x: auto; margin: .7em 0; }
.rich-content tg-collage img, .rich-content tg-slideshow img, .rich-content tg-collage video, .rich-content tg-slideshow video { height: 110px; border-radius: 10px; flex: 0 0 auto; }
.rich-content table[striped] tr:nth-child(even) td { background: var(--surface-2); }

.card-subtasks { flex: 0 0 auto; padding: 8px 18px; border-top: var(--line); }
.card-files { flex: 0 0 auto; padding: 8px 18px calc(12px + var(--bottom-inset)); border-top: var(--line); }
.card-section-head { display: flex; align-items: center; gap: 8px; }
.card-section-head .sub-title, .card-section-head > span[data-i18n] { font-size: 12px; font-weight: 700; color: var(--text-2); text-transform: uppercase; letter-spacing: .04em; }
.card-section-head .sub-count { font-size: 12px; color: var(--text-3); font-weight: 600; }
.card-section-head .grow { flex: 1; }
.card-section-head .iconbtn { width: 32px; height: 32px; color: var(--accent); }
.sub-chev { color: var(--text-3); display: inline-flex; transition: transform .18s; }
#subtasks-section.expanded .sub-chev { transform: rotate(180deg); }
#subtasks-toggle { cursor: pointer; }
.modal-subtasks { margin-top: 8px; max-height: 28vh; overflow-y: auto; }
.modal-subtasks[hidden] { display: none; }

/* flip-in when the card is opened from the Now screen via swipe-up */
.card-full.flip-in { animation: flipIn .4s cubic-bezier(.2,.8,.2,1); }
@keyframes flipIn { from { transform: rotateX(-88deg); opacity: .2; } to { transform: rotateX(0); opacity: 1; } }
.now.flip-out { animation: flipOut .2s ease forwards; transform-origin: center; }
@keyframes flipOut { to { transform: perspective(1000px) rotateX(72deg) scale(.92); opacity: 0; } }

