:root {
  --bg: #f2f2f7; --card: #ffffff; --text: #000; --muted: #8a8a8e; --sep: rgba(60,60,67,.18);
  --accent: #e3a10a; --danger: #ff3b30; --search: rgba(118,118,128,.12); --bar: rgba(249,249,249,.88);
  --pin: #ff9f0a; --sheet: #ffffff; --kb: 0px;
  --top: env(safe-area-inset-top); --bottom: env(safe-area-inset-bottom);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", sans-serif;
  -webkit-text-size-adjust: 100%;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #000; --card: #1c1c1e; --text: #fff; --muted: #8d8d93; --sep: rgba(84,84,88,.6);
    --accent: #ffd60a; --search: rgba(118,118,128,.24); --bar: rgba(22,22,22,.88); --sheet: #2c2c2e; }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); overscroll-behavior: none; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
.hidden { display: none !important; }
.muted { color: var(--muted); }

.view { position: fixed; inset: 0; display: flex; flex-direction: column; background: var(--bg); }
#editor-view { background: var(--card); }
.scroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 0 16px 24px; }

/* nav bar */
.nav { display: flex; justify-content: space-between; align-items: center; min-height: 44px;
  padding: calc(var(--top) + 4px) 8px 4px; }
.nav-btn { color: var(--accent); font-size: 17px; display: flex; align-items: center; gap: 4px; padding: 6px 8px; }
.nav-btn.back svg { width: 12px; height: 20px; }
.nav-btn.icon svg { width: 26px; height: 26px; }
.nav-btn.done { font-weight: 600; }
.nav-right { display: flex; align-items: center; }

.large-title { font-size: 34px; font-weight: 700; margin: 2px 0 10px; letter-spacing: .3px; }
.search-wrap { margin-bottom: 14px; }
.search { width: 100%; border: 0; border-radius: 10px; background: var(--search); color: var(--text);
  font-size: 17px; padding: 8px 10px 8px 32px; outline: none; -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Ccircle cx='8.5' cy='8.5' r='6' fill='none' stroke='%238a8a8e' stroke-width='2'/%3E%3Cpath d='m13 13 5 5' stroke='%238a8a8e' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: 9px center; background-size: 16px; }
.section-head { font-size: 20px; font-weight: 700; margin: 8px 4px 8px; display: flex; align-items: center; gap: 8px; }
.sync-dot { width: 8px; height: 8px; border-radius: 50%; background: #34c759; display: inline-block; }
.sync-dot.offline { background: var(--muted); }
.sync-dot.syncing { background: var(--accent); }
.sync-dot.error { background: var(--danger); }
.footnote { color: var(--muted); font-size: 13px; margin: 8px 4px; }
.link-btn { color: var(--danger); font-size: 15px; margin: 18px 4px; }

/* grouped lists */
.group { list-style: none; margin: 0 0 18px; padding: 0; background: var(--card); border-radius: 12px; overflow: hidden; }
.row { position: relative; overflow: hidden; }
.row + .row::before { content: ""; position: absolute; top: 0; left: 16px; right: 0; border-top: .5px solid var(--sep); z-index: 2; }
.row-inner { position: relative; z-index: 1; background: var(--card); display: flex; align-items: center; gap: 12px;
  padding: 11px 16px; min-height: 44px; transition: transform .2s ease; touch-action: pan-y; }
.row.dragging .row-inner { transition: none; }
.row-actions { position: absolute; inset: 0 0 0 auto; display: flex; z-index: 0; }
.row-actions button { width: 76px; color: #fff; font-size: 15px; font-weight: 500; }
.act-pin { background: var(--pin); } .act-del { background: var(--danger); } .act-move { background: #5856d6; }
.folder-icon { width: 26px; height: 26px; color: var(--accent); flex: none; }
.row-title { flex: 1; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-count { color: var(--muted); font-size: 17px; }
.chev { width: 8px; height: 14px; color: #c4c4c7; flex: none; }
.edit-del { width: 22px; height: 22px; border-radius: 50%; background: var(--danger); color: #fff; font-weight: 700; flex: none; line-height: 22px; text-align: center; }

.note-row .row-inner { display: block; padding: 10px 16px; }
.note-title { font-weight: 600; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.note-sub { font-size: 15px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.note-sub .date { color: var(--text); opacity: .75; margin-right: 6px; }
.note-thumb { float: right; width: 44px; height: 44px; border-radius: 6px; object-fit: cover; margin-left: 10px; }
.note-folder { font-size: 13px; color: var(--muted); margin-top: 2px; }
.empty { text-align: center; color: var(--muted); margin-top: 60px; font-size: 17px; }
mark { background: rgba(255,214,10,.45); color: inherit; border-radius: 2px; }

/* toolbar */
.toolbar { display: flex; justify-content: space-between; align-items: center; background: var(--bar);
  -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px); border-top: .5px solid var(--sep);
  padding: 6px 14px calc(var(--bottom) + 6px); min-height: 50px; }
.toolbar-label { font-size: 12px; color: var(--text); }
.tool { color: var(--accent); width: 40px; height: 40px; display: grid; place-items: center; }
.tool svg { width: 27px; height: 27px; }
.aa { font-size: 20px; font-weight: 500; letter-spacing: -.5px; }
.editor-toolbar { position: fixed; left: 0; right: 0; bottom: var(--kb); z-index: 5; }
body.kb-open .editor-toolbar { padding-bottom: 6px; }

/* editor */
.editor-scroll { padding: 0 20px calc(110px + var(--kb)); }
.note-date { text-align: center; color: var(--muted); font-size: 13px; margin: 4px 0 10px; }
.editor { outline: none; font-size: 17px; line-height: 1.4; min-height: 60vh; word-wrap: break-word; caret-color: var(--accent); }
.editor:empty::before, .editor > h1:only-child:has(> br:only-child)::before { content: "Title"; color: var(--muted); position: absolute; pointer-events: none; }
.editor h1 { font-size: 28px; font-weight: 700; margin: 0 0 6px; line-height: 1.2; }
.editor h2 { font-size: 22px; font-weight: 700; margin: 14px 0 4px; }
.editor h3 { font-size: 19px; font-weight: 600; margin: 12px 0 4px; }
.editor p, .editor div { margin: 0; min-height: 1.4em; }
.editor ul, .editor ol { margin: 0; padding-left: 26px; }
.editor img { max-width: 100%; border-radius: 10px; display: block; margin: 8px 0; }
.editor ul.checklist { list-style: none; padding-left: 4px; }
.editor ul.checklist > li { position: relative; padding-left: 32px; min-height: 28px; line-height: 26px; }
.editor ul.checklist > li::before { content: ""; position: absolute; left: 0; top: 2px; width: 22px; height: 22px;
  border-radius: 50%; border: 1.6px solid #c4c4c7; box-sizing: border-box; }
.editor ul.checklist > li.checked::before { background: var(--accent); border-color: var(--accent);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 22 22'%3E%3Cpath d='m6.5 11.3 3 3 6-6.3' fill='none' stroke='white' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E"); }
.editor ul.checklist > li.checked { color: var(--muted); }
.file-att { display: inline-flex; align-items: center; gap: 8px; background: var(--search); border-radius: 10px;
  padding: 8px 12px; margin: 6px 0; color: var(--text); text-decoration: none; font-size: 15px; user-select: none; -webkit-user-select: none; }
.file-att::before { content: "📎"; }

/* sheets */
.backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.3); z-index: 20; }
.sheet { position: fixed; left: 8px; right: 8px; bottom: calc(var(--bottom) + 8px); background: var(--sheet);
  border-radius: 14px; z-index: 21; padding: 12px; box-shadow: 0 8px 30px rgba(0,0,0,.2); animation: up .22s ease; }
#format-sheet { bottom: calc(var(--kb) + 8px); }
@keyframes up { from { transform: translateY(30px); opacity: 0; } }
.sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; padding: 0 4px; }
.sheet-close { width: 30px; height: 30px; border-radius: 50%; background: var(--search); font-size: 20px; line-height: 1; color: var(--muted); }
.styles-row { display: flex; gap: 6px; overflow-x: auto; margin-bottom: 10px; }
.styles-row button { padding: 8px 12px; border-radius: 8px; white-space: nowrap; font-size: 15px; }
.styles-row button.on { background: var(--accent); color: #000; }
.st-title { font-weight: 700; font-size: 18px !important; } .st-heading { font-weight: 700; } .st-sub { font-weight: 600; }
.fmt-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 2px; background: var(--search); border-radius: 10px; overflow: hidden; margin-bottom: 8px; }
.fmt-row button { padding: 10px 0; font-size: 17px; background: var(--sheet); }
.sheet.action { padding: 0; background: transparent; box-shadow: none; }
.action .group-a { background: var(--sheet); border-radius: 14px; overflow: hidden; margin-bottom: 8px; }
.action .title-a { white-space: pre-line; text-align: center; color: var(--muted); font-size: 13px; padding: 12px; border-bottom: .5px solid var(--sep); }
.action button { display: block; width: 100%; padding: 16px; font-size: 18px; color: var(--accent); text-align: center; }
.action button + button { border-top: .5px solid var(--sep); }
.action button.destructive { color: var(--danger); }
.action button.cancel { font-weight: 600; }
.action input { width: calc(100% - 24px); margin: 12px; padding: 10px; border-radius: 8px; border: .5px solid var(--sep);
  background: var(--bg); color: var(--text); font-size: 17px; }

/* login */
#login { justify-content: center; align-items: center; padding: 24px; }
.login-box { width: 100%; max-width: 340px; text-align: center; }
.login-icon { width: 84px; height: 84px; border-radius: 19px; }
.login-box h1 { margin: 12px 0 4px; }
.login-box input { width: 100%; padding: 13px; font-size: 17px; border-radius: 10px; border: 0; background: var(--card); color: var(--text); margin: 18px 0 10px; }
.btn-primary { width: 100%; padding: 13px; font-size: 17px; font-weight: 600; border-radius: 10px; background: var(--accent); color: #000; }
.error { color: var(--danger); min-height: 20px; font-size: 15px; }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--bottom) + 70px); background: rgba(0,0,0,.8);
  color: #fff; padding: 9px 16px; border-radius: 20px; font-size: 14px; z-index: 30; }

@media (min-width: 700px) { .scroll { max-width: 680px; width: 100%; margin: 0 auto; } }
@media (prefers-color-scheme: dark) { .toast { background: rgba(60,60,64,.95); } }
