:root {
  --fs: 17px; --pad: 24px; --lh: 1.75; --maxw: 760px; --kb: 0px;
  --bg: #ffffff; --fg: #1f1f1f; --muted: #787774; --side: #f7f7f5; --line: #e8e7e4; --hover: rgba(55,53,47,.07); --active: rgba(55,53,47,.11);
  --accent: #2d6fd8; --accent-fg: #fff; --link: #2361c4; --danger: #d44c47; --warn-bg: #fdf3dc; --warn-fg: #6b4e0f; --card: #ffffff; --shadow: 0 6px 28px rgba(15,15,15,.14), 0 1px 3px rgba(15,15,15,.1);
  --code-bg: rgba(135,131,120,.15); --sel: rgba(45,111,216,.22);
  --sans: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Noto Sans CJK JP", "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
  --serif: "Hiragino Mincho ProN", "Yu Mincho", "Noto Serif JP", "Noto Serif CJK JP", serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #191919; --fg: #e3e3e1; --muted: #9b9a97; --side: #202020; --line: #2f2f2f; --hover: rgba(255,255,255,.055); --active: rgba(255,255,255,.09);
  --accent: #4f8ef0; --link: #7aaaf5; --danger: #ef6b66; --warn-bg: #3a3020; --warn-fg: #f0d9a6; --card: #232323; --shadow: 0 8px 30px rgba(0,0,0,.5);
  --code-bg: rgba(255,255,255,.08); --sel: rgba(79,142,240,.35);
  color-scheme: dark;
}
:root[data-theme="paper"] {
  --bg: #f5efe0; --fg: #3a3226; --muted: #8a7d68; --side: #ece3cf; --line: #ddd1b6; --hover: rgba(90,70,30,.07); --active: rgba(90,70,30,.12);
  --accent: #8a5a2b; --link: #7a4a1c; --danger: #b2483b; --warn-bg: #f3e2b8; --warn-fg: #5d4415; --card: #f9f4e8; --shadow: 0 6px 26px rgba(70,50,20,.18);
  --code-bg: rgba(110,90,50,.12); --sel: rgba(138,90,43,.22);
}
:root[data-theme="paper"] body { background-image: radial-gradient(rgba(120,95,50,.035) 1px, transparent 1px); background-size: 4px 4px; }
:root[data-font="serif"] .note-title, :root[data-font="serif"] .cm-content { font-family: var(--serif); }

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--fg); font-family: var(--sans); font-size: 15px; -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; display: flex; overflow: hidden; }
button { font: inherit; color: inherit; }
a { color: var(--link); }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--muted); font-size: 13px; line-height: 1.6; }
.pre { white-space: pre-wrap; line-height: 1.6; }
.boot { margin: auto; color: var(--muted); }
.ic { display: inline-flex; width: 18px; height: 18px; flex: none; }
.ic svg { width: 100%; height: 100%; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.ic svg .fill { fill: currentColor; stroke: none; }
.icon-btn { border: 0; background: none; width: 34px; height: 34px; border-radius: 7px; display: inline-flex; align-items: center; justify-content: center; cursor: pointer; color: var(--muted); flex: none; }
.icon-btn:hover { background: var(--hover); color: var(--fg); }
.btn { border: 1px solid var(--line); background: var(--card); color: var(--fg); border-radius: 8px; padding: 7px 13px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; font-size: 14px; line-height: 1.3; white-space: nowrap; }
.btn:hover { background: var(--hover); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--danger); }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
.btn .ic { width: 16px; height: 16px; }
.input { width: 100%; border: 1px solid var(--line); background: var(--bg); color: var(--fg); border-radius: 8px; padding: 9px 11px; font: inherit; font-size: 15px; outline: none; }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--sel); }
.select { width: auto; padding: 8px; }
.select.small { padding: 4px 6px; font-size: 13px; }
.pill { font-size: 12px; color: var(--muted); border: 1px solid var(--line); border-radius: 99px; padding: 2px 9px; white-space: nowrap; }
.warn-text { color: var(--danger); font-size: 13px; }

/* ---------- サイドバー ---------- */
#side { width: 268px; flex: none; background: var(--side); border-right: 1px solid var(--line); display: flex; flex-direction: column; height: 100%; min-height: 0; }
body.side-collapsed #side { display: none; }
.side-head { display: flex; align-items: center; gap: 2px; padding: 10px 8px 6px 14px; }
.side-close { display: none; }
.brand { font-weight: 700; font-size: 16px; cursor: pointer; letter-spacing: .02em; }
.plus-folder { position: relative; }
.search { display: flex; align-items: center; gap: 6px; margin: 2px 10px 6px; padding: 0 9px; border-radius: 7px; background: var(--hover); color: var(--muted); }
.search input { flex: 1; border: 0; background: none; color: var(--fg); padding: 8px 0; font: inherit; font-size: 14px; outline: none; min-width: 0; }
.search .ic { width: 15px; height: 15px; }
.tree { flex: 1; overflow-y: auto; padding: 2px 6px 20px; min-height: 0; }
.tree-section { font-size: 12px; color: var(--muted); font-weight: 600; padding: 14px 10px 4px; display: flex; align-items: center; gap: 6px; }
.tree-section .ic { width: 14px; height: 14px; }
.tree-section.drop, .row.drop { background: var(--sel); border-radius: 6px; }
.tree-empty { color: var(--muted); font-size: 13px; padding: 6px 12px; }
.tree-empty.small { font-size: 12px; padding: 3px 0 3px calc(var(--d) * 16px + 34px); }
.row { display: flex; align-items: center; gap: 4px; min-height: 31px; padding: 2px 4px 2px calc(var(--d) * 16px + 4px); border-radius: 6px; cursor: pointer; font-size: 14px; position: relative; flex-wrap: wrap; user-select: none; }
.row:hover { background: var(--hover); }
.row.active { background: var(--active); font-weight: 600; }
.row .row-ic { width: 16px; height: 16px; color: var(--muted); }
.row-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row.unsynced .row-name::after { content: "●"; color: var(--accent); font-size: 8px; vertical-align: middle; margin-left: 5px; }
.row-badge { font-size: 11px; color: var(--muted); border: 1px solid var(--line); border-radius: 99px; padding: 0 6px; }
.twisty, .twisty-space { width: 20px; height: 22px; flex: none; border: 0; background: none; padding: 0; display: inline-flex; align-items: center; justify-content: center; color: var(--muted); cursor: pointer; border-radius: 4px; }
.twisty:hover { background: var(--active); }
.twisty .ic { width: 14px; height: 14px; transition: transform .12s; }
.twisty.open .ic { transform: rotate(90deg); }
.row-more { border: 0; background: none; width: 26px; height: 24px; border-radius: 5px; display: inline-flex; align-items: center; justify-content: center; color: var(--muted); cursor: pointer; opacity: 0; }
.row:hover .row-more, .row.active .row-more { opacity: 1; }
.row-more:hover { background: var(--active); }
.hit { flex-basis: 100%; font-size: 12px; color: var(--muted); padding: 0 6px 4px 46px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.side-foot { border-top: 1px solid var(--line); padding: 6px 8px; display: flex; align-items: center; gap: 6px; }
.side-link { border: 0; background: none; display: inline-flex; align-items: center; gap: 6px; padding: 6px 8px; border-radius: 6px; cursor: pointer; color: var(--muted); font-size: 13px; }
.side-link:hover { background: var(--hover); color: var(--fg); }
.side-link .ic { width: 16px; height: 16px; }
.side-status { margin-left: auto; font-size: 12px; color: var(--muted); cursor: pointer; display: none; }

/* ---------- 本体 ---------- */
#main { flex: 1; min-width: 0; display: flex; flex-direction: column; height: 100%; }
#bar { display: flex; align-items: center; gap: 4px; padding: 6px 10px; min-height: 46px; padding-top: max(6px, env(safe-area-inset-top)); }
.crumbs { display: flex; align-items: center; gap: 4px; min-width: 0; overflow: hidden; white-space: nowrap; font-size: 14px; }
.crumbs a { color: var(--muted); text-decoration: none; padding: 3px 5px; border-radius: 5px; overflow: hidden; text-overflow: ellipsis; max-width: 220px; }
.crumbs a[href]:hover { background: var(--hover); color: var(--fg); }
.crumbs a.cur { color: var(--fg); }
.crumbs .sep { color: var(--muted); opacity: .6; }
.status { border: 0; background: none; font-size: 12px; color: var(--muted); padding: 4px 8px; border-radius: 6px; cursor: pointer; white-space: nowrap; }
.status:hover { background: var(--hover); }
.status.ok::before { content: "✓ "; }
.status.busy { color: var(--muted); }
.status.off { color: #b7791f; }
.status.err { color: var(--danger); }
.status.err::before { content: "⚠ "; }
.only-mobile { display: none; }
#view { flex: 1; overflow-y: auto; min-height: 0; }
.page { padding: 12px var(--pad) 120px; max-width: calc(var(--maxw) + var(--pad) * 2); margin: 0 auto; width: 100%; }
.page-head { display: flex; align-items: center; gap: 8px; margin: 18px 0 14px; flex-wrap: wrap; }
.page-head h1 { font-size: 26px; margin: 0; font-weight: 700; word-break: break-word; }
.page-head h1.editable { cursor: text; border-radius: 6px; padding: 0 4px; margin-left: -4px; }
.page-head h1.editable:hover { background: var(--hover); }
.head-ic { width: 26px; height: 26px; color: var(--muted); }
.sub-head { font-size: 14px; color: var(--muted); margin: 30px 0 10px; font-weight: 600; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; }
.card { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); color: var(--fg); text-decoration: none; min-width: 0; }
.card:hover { background: var(--hover); }
.card-ic { width: 22px; height: 22px; color: var(--muted); margin-top: 1px; }
.card-text { min-width: 0; flex: 1; }
.card-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-snip { font-size: 13px; color: var(--muted); margin-top: 4px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; line-height: 1.5; word-break: break-all; }
.card-sub { font-size: 12px; color: var(--muted); margin-top: 3px; }
.card.unsynced .card-sub { color: var(--accent); }
.empty { color: var(--muted); padding: 24px 4px; grid-column: 1 / -1; }
.banner { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; background: var(--hover); border-radius: 8px; padding: 9px 12px; margin: 10px 0; font-size: 13px; }
.banner.warn { background: var(--warn-bg); color: var(--warn-fg); }
.trash-list { display: flex; flex-direction: column; gap: 4px; margin-top: 10px; }
.trash-row { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; }
.trash-row:hover { background: var(--hover); }
.trash-name { flex: 1; min-width: 0; }
.trash-name a { color: var(--fg); text-decoration: none; }

/* ---------- メモ ---------- */
.note-page { padding-top: 4px; }
.note-title { display: block; width: 100%; border: 0; outline: none; resize: none; background: none; color: var(--fg); font: inherit; font-size: calc(var(--fs) * 1.75); font-weight: 700; line-height: 1.3; padding: 18px 0 4px; overflow: hidden; }
.note-title::placeholder { color: var(--muted); opacity: .55; }
.note-meta { font-size: 12px; color: var(--muted); display: flex; gap: 8px; align-items: center; flex-wrap: wrap; min-height: 18px; margin-bottom: 6px; }
.note-meta .unsent { color: var(--accent); }
.toolbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 1px; padding: 4px 0; background: var(--bg); border-bottom: 1px solid var(--line); margin-bottom: 8px; overflow-x: auto; scrollbar-width: none; }
.toolbar::-webkit-scrollbar { display: none; }
.toolbar.hidden { display: none; }
.tb { border: 0; background: none; width: 34px; height: 32px; border-radius: 6px; display: inline-flex; align-items: center; justify-content: center; color: var(--muted); cursor: pointer; flex: none; }
.tb:hover { background: var(--hover); color: var(--fg); }
.tb-sep { width: 1px; height: 18px; background: var(--line); margin: 0 4px; flex: none; }
.editor-host { min-height: 50vh; }

/* CodeMirror */
.cm-editor { font-size: var(--fs); line-height: var(--lh); color: var(--fg); background: transparent; outline: none !important; }
.cm-editor .cm-scroller { font-family: var(--sans); line-height: var(--lh); overflow: visible; }
.cm-content { padding: 4px 0 40vh; caret-color: var(--fg); font-family: var(--sans); }
.cm-line { padding: 0 2px; word-break: break-word; }
.cm-cursor { border-left: 2px solid var(--fg) !important; }
.cm-selectionBackground { background: var(--sel) !important; }
.cm-editor.cm-focused .cm-selectionBackground { background: var(--sel) !important; }
.cm-placeholder { color: var(--muted); opacity: .6; }
.cm-li { padding-left: calc(var(--li, 0) * 1.6em + 1.6em) !important; text-indent: -1.6em; }
.cm-li > * { text-indent: 0; }
.cm-bullet { display: inline-block; width: 1.6em; text-indent: 0; text-align: center; color: var(--fg); user-select: none; }
.cm-num { text-align: right; padding-right: .35em; width: 1.6em; font-variant-numeric: tabular-nums; }
.cm-check { cursor: pointer; vertical-align: -0.12em; }
.cm-check svg { width: 1.02em; height: 1.02em; fill: none; stroke: var(--muted); stroke-width: 1.5; }
.cm-check.on svg rect { fill: var(--accent); stroke: var(--accent); }
.cm-check.on svg path { stroke: #fff; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.cm-task.done { color: var(--muted); text-decoration: line-through; text-decoration-color: rgba(128,128,128,.6); }
.cm-task.done .cm-bullet { text-decoration: none; }
.cm-h { font-weight: 700; }
.cm-h1 { font-size: 1.6em; line-height: 1.35; padding-top: .6em !important; }
.cm-h2 { font-size: 1.32em; line-height: 1.4; padding-top: .45em !important; }
.cm-h3 { font-size: 1.12em; padding-top: .3em !important; }
.cm-quote { border-left: 3px solid var(--fg); padding-left: 14px !important; }
.cm-hr { border-bottom: 1px solid var(--line); color: transparent; line-height: .6; margin-bottom: .6em; }
.cm-codeline { font-family: var(--mono); font-size: .88em; background: var(--code-bg); }
.cm-code { font-family: var(--mono); font-size: .88em; background: var(--code-bg); border-radius: 4px; padding: .1em .3em; color: #eb5757; }
:root[data-theme="dark"] .cm-code { color: #ff8b80; }
.cm-strong { font-weight: 700; }
.cm-strike { text-decoration: line-through; color: var(--muted); }
.cm-hidden { display: none; }
.cm-link { color: var(--link); text-decoration: underline; text-decoration-color: color-mix(in srgb, var(--link) 45%, transparent); text-underline-offset: 2px; cursor: pointer; }
.cm-link-src, .cm-src { color: var(--muted); }
.cm-math { display: inline-block; vertical-align: middle; max-width: 100%; overflow-x: auto; cursor: pointer; padding: 0 .1em; border-radius: 4px; }
.cm-math:hover { background: var(--hover); }
.cm-math .katex-display { display: inline-block; margin: .15em 0; text-align: left; }
.cm-math .katex-display > .katex { text-align: left; }
.cm-math.err { color: var(--danger); font-family: var(--mono); }
.cm-math-src { font-family: var(--mono); font-size: .9em; background: var(--code-bg); border-radius: 3px; }
.cm-image { display: block; margin: 6px 0; cursor: zoom-in; text-indent: 0; }
.cm-image img { max-width: 100%; max-height: 70vh; border-radius: 6px; display: block; }
.cm-image.uploading { display: flex; gap: 10px; align-items: center; padding: 18px; border: 1px dashed var(--line); border-radius: 8px; color: var(--muted); font-size: 14px; cursor: default; }
.cm-image.broken { color: var(--muted); font-size: 13px; padding: 10px; border: 1px dashed var(--line); border-radius: 6px; }
.spin { width: 16px; height: 16px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.cm-preview { position: relative; margin: 4px 0 10px; max-width: 620px; text-indent: 0; line-height: 1.45; font-family: var(--sans); }
.cm-li + .cm-preview, .cm-preview { margin-left: 0; }
.pv-body { display: flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; text-decoration: none; color: var(--fg); background: var(--card); min-height: 74px; }
.pv-body:hover { background: var(--hover); }
.pv-text { flex: 1; min-width: 0; padding: 10px 14px; display: flex; flex-direction: column; gap: 3px; justify-content: center; }
.pv-title { font-size: 14px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pv-desc { font-size: 12px; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.pv-desc:empty { display: none; }
.pv-site { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; overflow: hidden; white-space: nowrap; }
.pv-icon { width: 14px; height: 14px; border-radius: 3px; }
.pv-thumb { width: 150px; flex: none; position: relative; background: var(--hover); }
.pv-thumb img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.cm-preview.noimg .pv-thumb, .cm-preview.loading .pv-thumb { display: none; }
.cm-preview.loading .pv-title { color: var(--muted); font-weight: 400; }
.cm-preview.bare .pv-body { min-height: 0; }
.cm-preview.bare .pv-title { font-weight: 400; color: var(--muted); font-size: 13px; }
.cm-preview.imgonly .pv-thumb { width: 100%; height: 200px; }
.cm-preview.imgonly .pv-text { display: none; }
.pv-close { position: absolute; top: -8px; right: -8px; width: 24px; height: 24px; border-radius: 50%; border: 1px solid var(--line); background: var(--bg); color: var(--muted); cursor: pointer; font-size: 15px; line-height: 1; display: flex; align-items: center; justify-content: center; opacity: 0; transition: opacity .12s; padding: 0; }
.cm-preview:hover .pv-close { opacity: 1; }
.pv-close:hover { color: var(--fg); background: var(--hover); }
@media (hover: none) { .pv-close { opacity: .85; } .row-more { opacity: .7; } }

/* ---------- メニュー・窓 ---------- */
.menu { position: fixed; z-index: 1000; background: var(--card); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); padding: 5px; min-width: 190px; max-width: min(340px, calc(100vw - 16px)); }
.menu-item { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 8px 11px; border-radius: 6px; cursor: pointer; font-size: 14px; }
.menu-item:hover { background: var(--hover); }
.menu-item.danger { color: var(--danger); }
.menu-item:disabled { opacity: .4; }
.menu-sep { height: 1px; background: var(--line); margin: 4px 6px; }
.menu-url { font-size: 12px; color: var(--muted); padding: 6px 11px 8px; word-break: break-all; border-bottom: 1px solid var(--line); margin-bottom: 4px; max-height: 4.5em; overflow: hidden; }
.modal-wrap, .settings-wrap, .tab-stop { position: fixed; inset: 0; z-index: 900; background: rgba(15,15,15,.4); display: flex; align-items: center; justify-content: center; padding: 16px; }
.tab-stop { z-index: 2000; }
.modal { background: var(--card); color: var(--fg); border-radius: 14px; box-shadow: var(--shadow); width: min(440px, 100%); max-height: calc(100vh - 32px); display: flex; flex-direction: column; overflow: hidden; }
.modal.wide { width: min(780px, 100%); }
.modal-head { display: flex; align-items: center; padding: 10px 10px 4px 18px; }
.modal-title { flex: 1; font-weight: 700; font-size: 16px; }
.modal-body { padding: 8px 18px 14px; overflow-y: auto; }
.modal-body p { margin: 6px 0 12px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 10px 18px 16px; flex-wrap: wrap; }
.form { display: flex; flex-direction: column; gap: 12px; }
.form label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); }
.pick-list { display: flex; flex-direction: column; max-height: 55vh; overflow-y: auto; gap: 1px; }
.pick { display: flex; align-items: center; gap: 7px; text-align: left; border: 0; background: none; padding: 8px 8px 8px calc(var(--d) * 18px + 8px); border-radius: 6px; cursor: pointer; font-size: 14px; }
.pick:hover { background: var(--hover); }
.pick.sel { background: var(--sel); }
.pick.disabled { opacity: .4; cursor: default; }
.pick .row-ic { width: 16px; height: 16px; color: var(--muted); }
.pick-section { font-size: 12px; color: var(--muted); padding: 10px 8px 4px; font-weight: 600; }
.history { display: flex; gap: 14px; min-height: 50vh; }
.hist-list { width: 210px; flex: none; overflow-y: auto; max-height: 65vh; display: flex; flex-direction: column; gap: 2px; }
.hist-item { text-align: left; border: 0; background: none; padding: 7px 9px; border-radius: 6px; cursor: pointer; font-size: 13px; }
.hist-item:hover { background: var(--hover); }
.hist-item.sel { background: var(--sel); }
.hist-pane { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.hist-title { font-weight: 700; margin-bottom: 6px; }
.hist-body { flex: 1; white-space: pre-wrap; word-break: break-word; font-family: var(--sans); font-size: 14px; line-height: 1.65; background: var(--hover); border-radius: 8px; padding: 12px; margin: 0; max-height: 52vh; overflow-y: auto; }
.share-sec { margin-bottom: 18px; }
.share-sec .label { font-weight: 600; font-size: 13px; margin-bottom: 8px; }
.row-form { display: flex; gap: 6px; flex-wrap: wrap; }
.row-form .input[type=email] { flex: 1; min-width: 200px; }
.members, .links { display: flex; flex-direction: column; gap: 6px; }
.member, .link-row { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.link-row .card-sub { word-break: break-all; }
.viewer { position: fixed; inset: 0; z-index: 950; background: rgba(0,0,0,.88); display: flex; flex-direction: column; align-items: center; justify-content: center; }
.viewer img { max-width: 100%; max-height: calc(100% - 70px); object-fit: contain; cursor: zoom-out; }
.viewer-bar { position: absolute; left: 0; right: 0; bottom: 0; display: flex; gap: 8px; align-items: center; padding: 12px 14px calc(12px + env(safe-area-inset-bottom)); background: linear-gradient(transparent, rgba(0,0,0,.6)); flex-wrap: wrap; }
.viewer-name { color: #ddd; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewer .btn { background: rgba(255,255,255,.12); color: #fff; border-color: rgba(255,255,255,.2); }
#toast { position: fixed; left: 50%; bottom: calc(24px + var(--kb) + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px); background: #2b2b2b; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px; z-index: 3000; opacity: 0; pointer-events: none; transition: .2s; max-width: min(520px, calc(100vw - 32px)); line-height: 1.5; box-shadow: var(--shadow); }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- 設定 ---------- */
.settings { background: var(--bg); color: var(--fg); width: min(680px, 100%); height: min(860px, calc(100vh - 32px)); border-radius: 14px; box-shadow: var(--shadow); display: flex; flex-direction: column; overflow: hidden; }
.set-head { display: flex; align-items: center; padding: 12px 12px 10px 20px; border-bottom: 1px solid var(--line); padding-top: max(12px, env(safe-area-inset-top)); }
.set-title { font-weight: 700; font-size: 17px; display: flex; align-items: center; gap: 8px; }
.set-body { flex: 1; overflow-y: auto; padding: 4px 20px 40px; padding-bottom: calc(40px + env(safe-area-inset-bottom)); }
.set-sec { padding: 14px 0 6px; border-bottom: 1px solid var(--line); }
.set-sec:last-child { border-bottom: 0; }
.set-sec h3 { font-size: 13px; color: var(--muted); margin: 4px 0 10px; font-weight: 700; letter-spacing: .04em; }
.set-sec p { line-height: 1.65; margin: 6px 0 10px; font-size: 14px; }
.set-item { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 9px 0; flex-wrap: wrap; }
.set-label { font-size: 14px; }
.seg { display: inline-flex; background: var(--hover); border-radius: 9px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg button { border: 0; background: none; padding: 6px 12px; border-radius: 7px; cursor: pointer; font-size: 13px; color: var(--muted); }
.seg button.on { background: var(--card); color: var(--fg); box-shadow: 0 1px 3px rgba(0,0,0,.14); font-weight: 600; }
.range { display: flex; align-items: center; gap: 10px; }
.range input { width: 180px; accent-color: var(--accent); }
.range-val { font-size: 13px; color: var(--muted); min-width: 64px; text-align: right; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin: 8px 0; }
.help { margin: 4px 0 8px; padding-left: 1.2em; font-size: 13.5px; line-height: 1.75; }

/* ---------- ログイン ---------- */
body.login-page { display: flex; align-items: center; justify-content: center; overflow: auto; }
.login { margin: auto; width: min(380px, 100%); padding: 32px 22px; text-align: center; }
.login h1 { margin: 10px 0 6px; font-size: 26px; }
.login-logo { width: 54px; height: 54px; margin: 0 auto; color: var(--accent); }
.login-logo svg { width: 100%; height: 100%; fill: none; stroke: currentColor; stroke-width: 1.4; stroke-linejoin: round; stroke-linecap: round; }
.gbtn { margin: 26px auto 10px; display: inline-flex; align-items: center; gap: 12px; padding: 11px 22px; border-radius: 99px; border: 1px solid var(--line); background: var(--card); cursor: pointer; font-size: 15px; font-weight: 600; box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.gbtn:hover { background: var(--hover); }
.gbtn .g { width: 20px; height: 20px; display: inline-flex; }
.gbtn .g svg { width: 100%; height: 100%; }
.login-share { font-size: 14px; margin-top: 14px; line-height: 1.6; }
.login-note { margin-top: 26px; text-align: left; }
.dev { display: flex; gap: 6px; margin-top: 16px; }

/* ---------- スマホ ---------- */
@media (max-width: 760px) {
  body { font-size: 16px; }
  #side { position: fixed; inset: 0; width: 100%; z-index: 20; display: none; border: 0; padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom); }
  body.show-side #side { display: flex; }
  body.side-collapsed #side { display: none; }
  body.show-side.side-collapsed #side { display: flex; }
  .only-desktop { display: none; }
  .only-mobile { display: inline-flex; }
  body[data-route="home"] #main { display: none; }
  .side-head { padding: 10px 6px 6px 16px; }
  .brand { font-size: 20px; }
  .row { min-height: 40px; font-size: 15.5px; }
  .row-more { opacity: .7; width: 32px; height: 32px; }
  .side-status { display: inline; }
  .crumbs a { max-width: 130px; }
  .crumbs a:not(:last-child), .crumbs .sep { display: none; }
  #bar { padding-left: 4px; }
  .page { padding: 4px max(14px, var(--pad)) 120px; padding-left: max(14px, calc(var(--pad) * .6)); padding-right: max(14px, calc(var(--pad) * .6)); }
  .cards { grid-template-columns: 1fr; gap: 8px; }
  .page-head h1 { font-size: 23px; }
  .toolbar { position: fixed; left: 0; right: 0; bottom: var(--kb); top: auto; margin: 0; padding: 4px 6px calc(4px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); border-bottom: 0; z-index: 30; display: none; }
  body.editing[data-route="note"] .toolbar:not(.hidden) { display: flex; }
  body.kb-open .toolbar { padding-bottom: 4px; }
  .tb { width: 42px; height: 38px; }
  /* 設定は画面いっぱい */
  .settings-wrap { padding: 0; }
  .settings { width: 100%; height: 100%; border-radius: 0; box-shadow: none; }
  .set-item { flex-direction: column; align-items: stretch; }
  .range input { flex: 1; width: auto; }
  .modal-wrap { align-items: flex-end; padding: 0; }
  .modal, .modal.wide { width: 100%; border-radius: 16px 16px 0 0; max-height: 92vh; padding-bottom: env(safe-area-inset-bottom); }
  .history { flex-direction: column; }
  .hist-list { width: auto; max-height: 28vh; }
  .pv-thumb { width: 96px; }
  .cm-content { padding-bottom: 50vh; }
}
@media (min-width: 761px) { .side-close { display: none !important; } }
