/* 雲記本：只用系統字型，不從外部載入任何資源 */
:root {
  --paper: #F5F6F2;
  --surface: #FFFFFF;
  --sunk: #ECEEE8;
  --ink: #1E2A3A;
  --muted: #56606C;
  --line: #DDE1DA;
  --accent: #2E7D6B;
  --accent-ink: #FFFFFF;
  --accent-soft: #E3F0EC;
  --marker: #F4D35E;
  --marker-soft: #FBF0C2;
  --danger: #B4432F;
  --shadow: 0 1px 2px rgba(30, 42, 58, .06), 0 8px 24px rgba(30, 42, 58, .08);
  --sans: -apple-system, "PingFang TC", "Noto Sans TC", "Noto Sans CJK TC", "Microsoft JhengHei", "Heiti TC", system-ui, sans-serif;
  --serif: "Songti TC", "Noto Serif TC", "Noto Serif CJK TC", "PMingLiU", "MingLiU", serif;
  --r: 10px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --fs: 1.12;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #12171D; --surface: #1A2129; --sunk: #222A33; --ink: #E4E8EC; --muted: #93A0AC; --line: #2C3540;
    --accent: #5DBAA4; --accent-ink: #0E1A17; --accent-soft: #1F3530; --marker: #E9C64A; --marker-soft: #3B3420;
    --danger: #E07862; --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.35); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #12171D; --surface: #1A2129; --sunk: #222A33; --ink: #E4E8EC; --muted: #93A0AC; --line: #2C3540;
  --accent: #5DBAA4; --accent-ink: #0E1A17; --accent-soft: #1F3530; --marker: #E9C64A; --marker-soft: #3B3420;
  --danger: #E07862; --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.35); color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font: 16px/1.6 var(--sans); -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent; overflow: hidden;
}
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; flex: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
a { color: var(--accent); }

.btn {
  display: inline-flex; align-items: center; gap: 6px; justify-content: center;
  min-height: 40px; padding: 0 14px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  text-decoration: none; font-size: 15px; white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.danger { color: var(--danger); }
.btn.danger.solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.small { min-height: 32px; padding: 0 10px; font-size: 14px; }
.btn.wide { width: 100%; }
.btn svg { width: 18px; height: 18px; }
.icon-btn {
  display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 8px;
  border: 0; background: transparent; color: var(--ink); flex: none;
}
.icon-btn:hover { background: var(--sunk); }
.icon-btn[aria-pressed="true"] { color: var(--ink); background: var(--marker-soft); }
.linklike { border: 0; background: none; color: var(--accent); padding: 8px; }
.muted { color: var(--muted); font-size: 14px; }
.form-error { color: var(--danger); min-height: 1.4em; margin: 4px 0; font-size: 14px; }

/* ---------- 品牌記號：三張疊起的紙 ---------- */
.brand-mark, .auth-mark { position: relative; width: 22px; height: 22px; }
.brand-mark span, .auth-mark span { position: absolute; left: 0; right: 0; height: 5px; border-radius: 2px; }
.brand-mark span:nth-child(1), .auth-mark span:nth-child(1) { top: 2px; background: var(--accent); }
.brand-mark span:nth-child(2), .auth-mark span:nth-child(2) { top: 9px; left: 4px; background: var(--marker); }
.brand-mark span:nth-child(3), .auth-mark span:nth-child(3) { top: 16px; right: 6px; background: var(--ink); opacity: .75; }

/* ---------- 登入 ---------- */
.auth { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; overflow: auto; height: 100%; }
.auth-card { width: min(380px, 100%); }
.auth-mark { width: 44px; height: 44px; margin-bottom: 18px; }
.auth-mark span { height: 10px; border-radius: 3px; }
.auth-mark span:nth-child(1) { top: 2px; }
.auth-mark span:nth-child(2) { top: 17px; left: 8px; }
.auth-mark span:nth-child(3) { top: 32px; right: 12px; }
.auth h1 { font: 600 34px/1.2 var(--serif); margin: 0 0 6px; letter-spacing: .02em; }
.auth-lead { color: var(--muted); margin: 0 0 24px; }
.auth label, .stack label { display: block; font-size: 14px; color: var(--muted); margin-bottom: 12px; }
.auth input, .stack input, .dialog input[type="text"], .dialog input:not([type]) {
  display: block; width: 100%; margin-top: 4px; height: 46px; padding: 0 12px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--ink); font-size: 16px;
}
.auth input:focus, .stack input:focus, .dialog input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.auth .btn.primary { height: 48px; margin-top: 4px; font-size: 16px; }
.auth .linklike { display: block; margin: 14px auto 0; }

/* ---------- 主版面 ---------- */
.main { display: grid; grid-template-columns: 232px 340px 1fr; height: 100%; }
.sidebar {
  display: flex; flex-direction: column; background: var(--sunk); border-right: 1px solid var(--line);
  padding: calc(14px + var(--safe-top)) 10px calc(10px + var(--safe-bottom)); overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 6px 10px 18px; font: 600 19px/1 var(--serif); }
.folders { flex: 1; }
.folder-item {
  display: flex; align-items: center; gap: 10px; width: 100%; min-height: 40px; padding: 0 10px;
  border: 0; border-radius: 8px; background: transparent; text-align: left; color: var(--ink);
}
.folder-item span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.folder-item em { font-style: normal; font-size: 13px; color: var(--muted); }
.folder-item:hover { background: rgba(127, 127, 127, .1); }
.folder-item.active { background: var(--surface); box-shadow: inset 3px 0 0 var(--accent); font-weight: 600; }
.folder-item svg { color: var(--muted); }
.folder-add {
  display: flex; align-items: center; gap: 10px; width: 100%; min-height: 38px; padding: 0 10px; margin-top: 4px;
  border: 1px dashed var(--line); border-radius: 8px; background: transparent; color: var(--muted); font-size: 14px;
}
.sidebar-foot { border-top: 1px solid var(--line); padding-top: 8px; margin-top: 8px; }

.list-pane { position: relative; display: flex; flex-direction: column; min-width: 0; border-right: 1px solid var(--line); background: var(--paper); }
.pane-head {
  display: flex; align-items: center; gap: 6px; min-height: 56px;
  padding: calc(8px + var(--safe-top)) 12px 8px;
}
.pane-head h2 { flex: 1; margin: 0 0 0 4px; font: 600 20px/1.3 var(--serif); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search { position: relative; margin: 0 12px 8px; }
.search svg { position: absolute; left: 11px; top: 11px; width: 18px; height: 18px; color: var(--muted); }
.search input {
  width: 100%; height: 40px; padding: 0 12px 0 36px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--surface); font-size: 15px;
}
.search input:focus { outline: none; border-color: var(--accent); }
.offline-bar { margin: 0 12px 8px; padding: 8px 12px; border-radius: 8px; background: var(--marker-soft); font-size: 14px; }

.note-list { list-style: none; margin: 0; padding: 0 8px 96px; overflow-y: auto; flex: 1; -webkit-overflow-scrolling: touch; }
.note-item {
  position: relative; display: flex; gap: 12px; padding: 12px 12px 12px 14px; border-radius: var(--r);
  cursor: pointer; border-bottom: 1px solid var(--line);
}
.note-item:hover { background: var(--sunk); }
.note-item.active { background: var(--surface); box-shadow: var(--shadow); border-bottom-color: transparent; }
.note-item.pinned::before {
  content: ""; position: absolute; left: 0; top: 14px; width: 4px; height: 22px; border-radius: 0 3px 3px 0; background: var(--marker);
}
.note-main { flex: 1; min-width: 0; }
.note-item h3 { margin: 0; font: 600 17px/1.35 var(--serif); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.note-item h3.untitled { color: var(--muted); font-weight: 400; }
.note-snippet {
  margin: 3px 0 0; color: var(--muted); font-size: 14px; line-height: 1.5;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; word-break: break-all;
}
.note-foot { display: flex; gap: 10px; align-items: center; margin-top: 6px; font-size: 12.5px; color: var(--muted); }
.note-foot svg { width: 14px; height: 14px; }
.note-foot span { display: inline-flex; align-items: center; gap: 3px; }
.note-cover { width: 58px; height: 58px; border-radius: 8px; object-fit: cover; background: var(--sunk); flex: none; }
mark, .note-snippet b { background: var(--marker-soft); color: inherit; border-radius: 2px; }

.empty { padding: 48px 24px; text-align: center; color: var(--muted); }
.empty strong { display: block; color: var(--ink); font: 600 18px/1.4 var(--serif); margin-bottom: 6px; }

.fab {
  position: absolute; right: 16px; bottom: calc(16px + var(--safe-bottom));
  display: inline-flex; align-items: center; gap: 6px; height: 50px; padding: 0 20px 0 16px; border-radius: 25px;
  border: 0; background: var(--accent); color: var(--accent-ink); font-weight: 600; box-shadow: var(--shadow);
}
.fab svg { width: 22px; height: 22px; stroke-width: 2.2; }

/* ---------- 編輯器 ---------- */
.editor-pane { position: relative; min-width: 0; background: var(--surface); display: flex; flex-direction: column; }
.editor-empty { flex: 1; display: grid; place-items: center; color: var(--muted); padding: 24px; text-align: center; }
.editor { display: flex; flex-direction: column; height: 100%; }
.editor-head { border-bottom: 1px solid var(--line); gap: 4px; }
.editor-head select {
  max-width: 40%; height: 34px; padding: 0 8px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--paper); font-size: 14px;
}
.save-state { flex: 1; font-size: 13px; color: var(--muted); padding-left: 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.save-state.error { color: var(--danger); }
.head-actions { display: flex; gap: 2px; }
.trash-banner { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 10px 16px; background: var(--marker-soft); font-size: 14px; }
.trash-banner span { flex: 1; min-width: 200px; }
.editor-scroll { flex: 1; overflow-y: auto; padding: 24px clamp(16px, 5vw, 56px) calc(48px + var(--safe-bottom)); -webkit-overflow-scrolling: touch; }
.editor-scroll > * { max-width: 760px; margin-left: auto; margin-right: auto; }
.note-title {
  display: block; width: 100%; border: 0; resize: none; overflow: hidden; background: transparent; padding: 0;
  font: 600 clamp(24px, 4vw, 32px)/1.3 var(--serif); letter-spacing: .01em;
}
.note-title:focus { outline: none; }
.note-title::placeholder { color: var(--muted); opacity: .45; }
.note-meta { margin: 6px auto 14px; font-size: 13px; color: var(--muted); }
.toolbar {
  position: sticky; top: -24px; z-index: 2; display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none;
  padding: 6px 0; margin-bottom: 8px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.toolbar::-webkit-scrollbar { display: none; }
.toolbar button {
  flex: none; min-width: 36px; height: 34px; padding: 0 9px; border: 0; border-radius: 6px; background: transparent; font-size: 14px; color: var(--ink);
}
.toolbar button:hover, .toolbar button.on { background: var(--sunk); }
.note-body {
  min-height: 40vh; outline: none; font-size: 17px; line-height: 1.8; word-wrap: break-word; padding-bottom: 24px;
}
.note-body { position: relative; }
.note-body.is-empty::before { content: attr(data-placeholder); position: absolute; left: 0; top: 0; color: var(--muted); opacity: .6; pointer-events: none; }
.note-body h2, .content h2 { font: 600 22px/1.4 var(--serif); margin: 1.1em 0 .4em; }
.note-body h1, .content h1 { font: 600 26px/1.4 var(--serif); margin: 1.1em 0 .4em; }
.note-body h3, .content h3 { font: 600 19px/1.4 var(--serif); }
.note-body blockquote, .content blockquote { margin: .8em 0; padding: 2px 0 2px 16px; border-left: 3px solid var(--accent); color: var(--muted); }
.note-body p, .content p { margin: 0 0 .6em; }
.note-body ul, .note-body ol { padding-left: 1.5em; }
.note-body ul[data-type="todo"], .content ul[data-type="todo"] { list-style: none; padding-left: 0; }
.note-body ul[data-type="todo"] > li, .content ul[data-type="todo"] > li { position: relative; padding-left: 30px; }
.note-body ul[data-type="todo"] > li::before, .content ul[data-type="todo"] > li::before {
  content: ""; position: absolute; left: 2px; top: .42em; width: 18px; height: 18px; box-sizing: border-box;
  border: 1.6px solid var(--muted); border-radius: 4px; cursor: pointer; background: var(--surface);
}
.note-body ul[data-type="todo"] > li[data-checked="true"], .content ul[data-type="todo"] > li[data-checked="true"] { color: var(--muted); text-decoration: line-through; }
.note-body ul[data-type="todo"] > li[data-checked="true"]::before, .content ul[data-type="todo"] > li[data-checked="true"]::before {
  border-color: var(--accent); background: var(--accent) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M3.5 8.5l3 3 6-7' fill='none' stroke='white' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center/14px no-repeat;
}
.note-body pre, .content pre { background: var(--sunk); padding: 12px; border-radius: 8px; overflow-x: auto; font-size: 14px; }
.note-body a { word-break: break-all; }

/* ---------- 附件 ---------- */
.attachments { border-top: 1px dashed var(--line); padding-top: 18px; margin-top: 8px; }
.attach-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; margin-bottom: 12px; }
.gallery button { position: relative; aspect-ratio: 1; padding: 0; border: 0; border-radius: 8px; overflow: hidden; background: var(--sunk); }
.gallery img { width: 100%; height: 100%; object-fit: cover; display: block; }
.file-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.file-row {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--r);
  background: var(--paper); cursor: pointer; text-align: left; width: 100%;
}
.file-row:hover { border-color: var(--muted); }
.file-badge {
  display: grid; place-items: center; width: 42px; height: 50px; border-radius: 4px 12px 4px 4px; flex: none;
  font-size: 12px; font-weight: 700; color: #fff; letter-spacing: .02em;
}
.file-badge.pdf { background: #C4473A; }
.file-badge.docx, .file-badge.office { background: #2F5DA8; }
.file-badge.video { background: #6B4FA0; }
.file-badge.audio { background: #A0613A; }
.file-badge.text { background: #5B6573; }
.file-badge.other { background: #7A8290; }
.file-info { flex: 1; min-width: 0; }
.file-info strong { display: block; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-info span { font-size: 13px; color: var(--muted); }
.uploads { display: grid; gap: 6px; margin-bottom: 10px; }
.upload-row { font-size: 13px; color: var(--muted); }
.upload-row .bar { height: 4px; border-radius: 2px; background: var(--sunk); overflow: hidden; margin-top: 3px; }
.upload-row .bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.upload-row.error { color: var(--danger); }
.drop-hint { font-size: 13px; color: var(--muted); margin-top: 14px; }
.drop-zone {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center;
  background: color-mix(in srgb, var(--accent) 18%, transparent); border: 3px dashed var(--accent);
  font: 600 22px/1 var(--serif); color: var(--ink); pointer-events: none;
}

/* ---------- 檔案預覽 ---------- */
.viewer { position: fixed; inset: 0; z-index: 40; background: #0D1116; color: #E8ECEF; display: flex; flex-direction: column; }
.viewer-head { display: flex; align-items: center; gap: 6px; padding: calc(6px + var(--safe-top)) 8px 6px; background: #151B22; }
.viewer-head .icon-btn { color: #E8ECEF; }
.viewer-head .icon-btn:hover { background: rgba(255,255,255,.1); }
.viewer-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 15px; }
.viewer-page { font-size: 13px; color: #9AA5B1; white-space: nowrap; }
.viewer-body { flex: 1; overflow: auto; -webkit-overflow-scrolling: touch; position: relative; touch-action: pan-x pan-y pinch-zoom; }
.viewer-body.image { display: grid; place-items: center; }
.viewer-body > img { max-width: 100%; max-height: 100%; object-fit: contain; display: block; }
.viewer-body video, .viewer-body audio { max-width: 100%; max-height: 100%; margin: auto; display: block; }
.viewer-body.pdf { background: #2A3038; padding: 12px 0 calc(24px + var(--safe-bottom)); }
.pdf-page { display: block; margin: 0 auto 12px; background: #fff; box-shadow: 0 2px 10px rgba(0,0,0,.4); max-width: calc(100% - 16px); }
.viewer-body.docx { background: #2A3038; padding: 12px 0; }
.viewer-body.docx .docx-wrapper { background: transparent !important; padding: 0 !important; }
.viewer-body.docx section.docx { box-shadow: 0 2px 10px rgba(0,0,0,.4); margin: 0 auto 12px !important; max-width: calc(100vw - 16px); color: #000; }
.viewer-body.text pre { white-space: pre-wrap; word-break: break-word; padding: 16px; margin: 0; font-size: 15px; line-height: 1.7; }
.viewer-msg { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; gap: 14px; padding: 24px; color: #C9D1D9; }
.viewer-msg .btn { justify-self: center; }
.viewer-nav {
  position: absolute; top: 50%; width: 44px; height: 64px; margin-top: -32px; border: 0; border-radius: 8px;
  background: rgba(0,0,0,.35); color: #fff; display: grid; place-items: center;
}
.viewer-nav.prev { left: 8px; } .viewer-nav.next { right: 8px; }

/* ---------- 對話框 ---------- */
.dialog {
  border: 0; border-radius: 14px; padding: 0; width: min(420px, calc(100vw - 32px)); background: var(--surface); color: var(--ink);
  box-shadow: var(--shadow);
}
.dialog::backdrop { background: rgba(10, 14, 20, .45); }
.dialog form { padding: 20px; }
.dialog h3 { margin: 0 0 10px; font: 600 19px/1.4 var(--serif); }
.dialog p { margin: 0 0 10px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.share-link { display: flex; gap: 8px; }
.share-link input { flex: 1; }
.dialog.sheet { width: min(520px, 100vw); max-height: min(88vh, 900px); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 14px 6px 20px; position: sticky; top: 0; background: var(--surface); }
.sheet-head h3 { margin: 0; font: 600 20px/1.4 var(--serif); }
.sheet-body { padding: 0 20px 20px; }
.sheet-body section { padding: 14px 0; border-bottom: 1px solid var(--line); }
.sheet-body section:last-child { border-bottom: 0; }
.sheet-body h4 { margin: 0 0 8px; font-size: 15px; }
.check { display: flex; gap: 8px; align-items: center; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: transparent; padding: 7px 14px; font-size: 14px; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--accent-soft); color: var(--ink); font-weight: 600; }
.plain-list { list-style: none; padding: 0; margin: 8px 0; font-size: 14px; }
.plain-list li { display: flex; justify-content: space-between; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--line); }
.plain-list code { font-size: 15px; letter-spacing: .08em; }

.toast {
  position: fixed; left: 50%; bottom: calc(84px + var(--safe-bottom)); z-index: 60; transform: translate(-50%, 20px);
  padding: 10px 16px; border-radius: 10px; background: var(--ink); color: var(--paper); font-size: 14px;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.toast button { margin-left: 10px; border: 0; background: none; color: var(--marker); font-weight: 600; }

.scrim { display: none; }
.only-mobile { display: none; }
.only-touch { display: none; }
@media (hover: none) and (pointer: coarse) { .only-touch { display: inline-flex; } .only-desktop { display: none; } }

/* ---------- 平板 ---------- */
@media (max-width: 1080px) {
  .main { grid-template-columns: 300px 1fr; }
  .sidebar {
    position: fixed; z-index: 30; top: 0; bottom: 0; left: 0; width: min(290px, 84vw);
    transform: translateX(-102%); transition: transform .22s ease; box-shadow: var(--shadow);
  }
  body.drawer-open .sidebar { transform: none; }
  body.drawer-open .scrim { display: block; position: fixed; inset: 0; z-index: 29; background: rgba(10, 14, 20, .4); }
  .list-pane .only-mobile { display: inline-grid; }
}
/* ---------- 手機 ---------- */
@media (max-width: 720px) {
  .main { grid-template-columns: 100%; }
  .list-pane, .editor-pane { grid-row: 1; grid-column: 1; border: 0; }
  body.view-list .editor-pane { display: none; }
  body.view-editor .list-pane { display: none; }
  .only-mobile { display: inline-grid; }
  .editor-scroll { padding-top: 16px; }
  .toolbar { top: -16px; }
  .note-body { font-size: 17px; }
  .viewer-nav { display: none; }
}

/* ============ 大字、好按：適合長輩與手機 ============ */
:root[data-size="m"] { --fs: 1; }
:root[data-size="l"] { --fs: 1.12; }
:root[data-size="xl"] { --fs: 1.28; }
body { font-size: calc(16px * var(--fs)); }
.btn { min-height: 48px; font-size: calc(16px * var(--fs)); padding: 0 16px; border-radius: 10px; }
.btn.small { min-height: 44px; font-size: calc(15px * var(--fs)); }
.icon-btn { width: 48px; height: 48px; }
.icon-btn svg { width: 24px; height: 24px; }
.icon-btn.labeled { width: auto; min-width: 56px; height: 56px; padding: 0 8px; display: inline-flex; flex-direction: column; gap: 1px; }
.icon-btn.labeled span { font-size: calc(12.5px * var(--fs)); line-height: 1.2; }
.icon-btn.labeled#backToList { flex-direction: row; gap: 2px; font-weight: 600; }
.icon-btn.labeled#backToList span { font-size: calc(17px * var(--fs)); }
#deleteBtn { color: var(--danger); }
.auth h1 { font-size: calc(34px * var(--fs)); }
.auth input, .stack input, .dialog input:not([type]), .dialog input[type="text"] { height: 52px; font-size: calc(17px * var(--fs)); }
.auth .btn.primary { height: 56px; font-size: calc(18px * var(--fs)); }
.auth label, .stack label { font-size: calc(15px * var(--fs)); }
.folder-item { min-height: 52px; font-size: calc(17px * var(--fs)); }
.folder-add { min-height: 48px; font-size: calc(15px * var(--fs)); }
.pane-head { min-height: 64px; }
.pane-head h2 { font-size: calc(22px * var(--fs)); }
.search input { height: 50px; font-size: calc(17px * var(--fs)); padding-left: 42px; border-radius: 10px; }
.search svg { top: 14px; left: 13px; width: 22px; height: 22px; }
.note-item { padding: 16px 14px 16px 16px; }
.note-item h3 { font-size: calc(19px * var(--fs)); }
.note-snippet { font-size: calc(15.5px * var(--fs)); color: var(--muted); }
.note-foot { font-size: calc(14px * var(--fs)); }
.note-cover { width: 68px; height: 68px; }
.note-item.pinned::before { width: 5px; height: 28px; top: 18px; }
.empty { font-size: calc(16px * var(--fs)); }
.empty strong { font-size: calc(20px * var(--fs)); }
.fab { height: 60px; padding: 0 26px 0 20px; border-radius: 30px; font-size: calc(18px * var(--fs)); }
.fab svg { width: 26px; height: 26px; }
.save-state { font-size: calc(14px * var(--fs)); }
.save-state.ok { color: var(--accent); }
.note-title { font-size: calc(28px * var(--fs)); }
.note-meta { font-size: calc(13.5px * var(--fs)); }
.note-body { font-size: calc(18px * var(--fs)); line-height: 1.85; }
.note-body ul[data-type="todo"] > li { padding-left: 38px; margin: 4px 0; }
.note-body ul[data-type="todo"] > li::before { width: 24px; height: 24px; border-width: 2px; top: .3em; border-radius: 6px; }
.note-body ul[data-type="todo"] > li[data-checked="true"]::before { background-size: 18px; }
.note-options { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 12px auto 4px; }
.folder-pick { position: relative; display: inline-flex; align-items: center; }
.folder-pick svg { position: absolute; left: 12px; color: var(--muted); pointer-events: none; }
.folder-pick select {
  height: 44px; padding: 0 12px 0 40px; border: 1px solid var(--line); border-radius: 22px; background: var(--paper);
  font-size: calc(15px * var(--fs)); max-width: 62vw;
}
.chip {
  display: inline-flex; align-items: center; gap: 6px; height: 44px; padding: 0 16px 0 12px; border-radius: 22px;
  border: 1px solid var(--line); background: var(--paper); font-size: calc(15px * var(--fs)); color: var(--ink);
}
.chip[aria-pressed="true"] { background: var(--marker-soft); border-color: var(--marker); font-weight: 600; }
.toolbar { gap: 6px; padding: 8px 0; flex-wrap: wrap; overflow: visible; position: static; }
.toolbar button {
  height: 44px; padding: 0 14px; font-size: calc(15.5px * var(--fs)); border: 1px solid var(--line); border-radius: 10px; background: var(--surface);
}
.toolbar button mark { padding: 0 2px; }
.toolbar .extra { display: none; }
.toolbar.expanded .extra { display: inline-block; }
.toolbar .more { color: var(--muted); border-style: dashed; }
.attach-actions .btn { min-height: 52px; font-size: calc(16px * var(--fs)); }
.attach-actions svg { width: 22px; height: 22px; }
.gallery { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }
.file-row { padding: 14px; }
.file-info strong { font-size: calc(16.5px * var(--fs)); }
.file-info span { font-size: calc(14px * var(--fs)); }
.file-badge { width: 46px; height: 56px; font-size: 13px; }
.trash-banner { font-size: calc(15px * var(--fs)); }
.dialog { width: min(460px, calc(100vw - 24px)); }
.dialog h3 { font-size: calc(21px * var(--fs)); }
.dialog p { font-size: calc(16px * var(--fs)); }
.dialog-actions .btn { min-height: 52px; flex: 1 1 auto; }
.seg button { padding: 10px 18px; font-size: calc(15px * var(--fs)); }
.sheet-body h4 { font-size: calc(17px * var(--fs)); }
.muted { font-size: calc(14.5px * var(--fs)); }
.toast { font-size: calc(16px * var(--fs)); padding: 14px 20px; border-radius: 12px; bottom: calc(96px + var(--safe-bottom)); }
.viewer-head .icon-btn { width: 52px; height: 52px; }
.viewer-name { font-size: calc(16px * var(--fs)); }
.viewer-page { font-size: calc(14px * var(--fs)); }

@media (max-width: 720px) {
  .editor-head { padding-left: 4px; padding-right: 4px; }
  .editor-scroll { padding-bottom: calc(120px + var(--safe-bottom)); }
  .note-title { font-size: calc(26px * var(--fs)); }
  /* 手機：照片、拍照、檔案三個大按鈕固定在畫面最下方 */
  .attach-actions {
    position: fixed; z-index: 5; left: 0; right: 0; bottom: 0; margin: 0;
    display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 8px;
    padding: 8px 10px calc(8px + var(--safe-bottom)); background: var(--surface); border-top: 1px solid var(--line);
    box-shadow: 0 -4px 16px rgba(30, 42, 58, .06);
  }
  .attach-actions .btn { flex-direction: column; gap: 2px; min-height: 64px; padding: 0 4px; font-size: calc(15px * var(--fs)); }
  .attach-actions .btn svg { width: 26px; height: 26px; }
  body.typing .attach-actions { display: none; }
  .attachments { border-top: 1px dashed var(--line); }
  .toast { bottom: calc(100px + var(--safe-bottom)); }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* ============ 手機安裝引導 ============ */
html.ins-open, html.ins-open body { overflow: hidden; }
.ins {
  position: fixed; inset: 0; z-index: 100; overflow-y: auto; background: var(--paper);
  display: flex; align-items: center; justify-content: center;
  padding: calc(24px + var(--safe-top)) 20px calc(24px + var(--safe-bottom));
}
.ins-card { width: min(440px, 100%); text-align: left; }
.ins-icon img { width: 84px; height: 84px; border-radius: 20px; display: block; box-shadow: var(--shadow); margin-bottom: 22px; }
.ins h2 { font: 600 calc(28px * var(--fs))/1.3 var(--serif); margin: 0 0 10px; }
.ins-lead { font-size: calc(17px * var(--fs)); color: var(--muted); margin: 0 0 22px; line-height: 1.7; }
.ins-steps { list-style: none; counter-reset: s; margin: 0 0 20px; padding: 0; display: grid; gap: 12px; }
.ins-steps li {
  counter-increment: s; position: relative; padding: 14px 14px 14px 62px; border-radius: 14px;
  background: var(--surface); border: 1px solid var(--line); font-size: calc(18px * var(--fs)); line-height: 1.6;
}
.ins-steps li::before {
  content: counter(s); position: absolute; left: 14px; top: 50%; transform: translateY(-50%);
  width: 34px; height: 34px; border-radius: 50%; background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; font-weight: 700; font-size: 18px;
}
.ins-key {
  display: inline-grid; place-items: center; width: 34px; height: 34px; vertical-align: middle; margin: 0 2px;
  border-radius: 8px; background: var(--sunk); color: var(--accent);
}
.ins-key svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.ins-key svg circle { fill: currentColor; stroke: none; }
.ins-btn {
  display: flex; align-items: center; justify-content: center; width: 100%; min-height: 58px; margin: 0 0 12px;
  border: 0; border-radius: 14px; background: var(--accent); color: var(--accent-ink);
  font-size: calc(19px * var(--fs)); font-weight: 700; padding: 8px 16px;
}
.ins-btn.big { min-height: 66px; font-size: calc(21px * var(--fs)); }
.ins-btn.ghost { background: transparent; color: var(--accent); border: 1.5px solid var(--line); font-weight: 600; font-size: calc(16px * var(--fs)); word-break: break-all; }
.ins-small { font-size: calc(15px * var(--fs)); color: var(--muted); margin: 0 0 12px; }
.ins-later {
  display: block; margin: 18px auto 0; padding: 12px 16px; border: 0; background: none;
  color: var(--muted); font-size: calc(15px * var(--fs)); text-decoration: underline; text-underline-offset: 3px;
}
.ins-arrow {
  position: fixed; left: 50%; bottom: calc(6px + var(--safe-bottom)); transform: translateX(-50%);
  font-size: 40px; line-height: 1; color: var(--accent); animation: ins-bob 1.4s ease-in-out infinite;
}
@keyframes ins-bob { 50% { transform: translate(-50%, 8px); } }
@media (prefers-reduced-motion: reduce) { .ins-arrow { animation: none; } }

/* ============ 登入連結、家人清單 ============ */
.auth-hint { margin: 0 0 22px; padding: 14px 16px; border-radius: 12px; background: var(--accent-soft); font-size: calc(15.5px * var(--fs)); line-height: 1.7; }
.member-list { list-style: none; padding: 0; margin: 12px 0 0; display: grid; gap: 8px; }
.member-list li { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--paper); }
.member-list .who { flex: 1; min-width: 0; }
.member-list .who strong { display: block; font-size: calc(16.5px * var(--fs)); }
.member-list .who span { font-size: calc(13.5px * var(--fs)); color: var(--muted); }
.qr-box { display: grid; place-items: center; margin: 4px 0 14px; }
.qr-box svg, .qr-box img { width: min(240px, 70vw); height: auto; background: #fff; padding: 10px; border-radius: 12px; border: 1px solid var(--line); }
.link-tip { font-size: calc(14px * var(--fs)); color: var(--muted); margin: 10px 0 0; }
details#pwBox { margin-top: 14px; }
details#pwBox summary { cursor: pointer; color: var(--accent); font-size: calc(15px * var(--fs)); padding: 6px 0; }
details#pwBox form { margin-top: 10px; }

/* ============ 影片 ============ */
.gallery button.is-video img { filter: brightness(.85); }
.gallery .play-badge {
  position: absolute; left: 50%; top: 50%; width: 46px; height: 46px; margin: -23px 0 0 -23px; border-radius: 50%;
  background: rgba(0, 0, 0, .55); box-shadow: 0 0 0 2px rgba(255, 255, 255, .85);
}
.gallery .play-badge::after {
  content: ""; position: absolute; left: 18px; top: 13px; border-style: solid; border-width: 10px 0 10px 16px;
  border-color: transparent transparent transparent #fff;
}
.gallery .video-name {
  display: flex; align-items: flex-end; width: 100%; height: 100%; padding: 8px; font-size: 13px; color: #fff;
  background: linear-gradient(160deg, #3a4a5c, #1e2a3a); word-break: break-all; text-align: left;
}
.viewer-body.video { display: grid; place-items: center; background: #000; }
.viewer-body.video video { width: 100%; max-height: 100%; }
.stack select { display: block; width: 100%; margin-top: 4px; height: 52px; padding: 0 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--ink); font-size: calc(16px * var(--fs)); }
details#storageBox { margin: 6px 0 10px; }
details#storageBox summary { cursor: pointer; color: var(--accent); font-size: calc(15px * var(--fs)); padding: 6px 0; }
details#storageBox form { margin-top: 10px; }
#migrateBox { margin-top: 8px; }
.stack label.check { display: flex; align-items: center; gap: 10px; color: var(--ink); }
.stack label.check input { width: 22px; height: 22px; margin: 0; flex: none; display: inline-block; }
