/* =========================================================
   ノート v1.1 デザイン（色・文字・余白を全画面でそろえる）
   ========================================================= */
:root {
  --bg: #ffffff;
  --bg-side: #f5f5f7;
  --bg-list: #fbfbfc;
  --bg-hover: #eef0f4;
  --bg-active: #e5ebfb;
  --text: #1c1d21;
  --text-sub: #6b6f7a;
  --text-faint: #9a9ea8;
  --border: #e6e7eb;
  --accent: #3a63d8;
  --accent-soft: #e8eefc;
  --accent-text: #ffffff;
  --danger: #d23b2f;
  --warn-bg: #fff4e3;
  --warn-text: #7a4a00;
  --radius: 10px;
  --shadow: 0 10px 32px rgba(20, 24, 40, .18);
  --font: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic UI", "Meiryo", "Segoe UI", sans-serif;
  /* 本文の見た目（「設定」で変えられる。この端末の表示だけ） */
  --note-font-size: 16px;
  --note-line-height: 1.75;
  --note-para-space: 0px;
  --kb-offset: 0px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #18191c;
    --bg-side: #121315;
    --bg-list: #16171a;
    --bg-hover: #24262b;
    --bg-active: #23305a;
    --text: #ececee;
    --text-sub: #a3a6ae;
    --text-faint: #6e717a;
    --border: #2c2e33;
    --accent: #7c9dff;
    --accent-soft: #23305a;
    --accent-text: #0f1220;
    --danger: #ff6b5b;
    --warn-bg: #3a2c12;
    --warn-text: #f5d9a6;
    --shadow: 0 10px 32px rgba(0, 0, 0, .5);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text); font-family: var(--font); font-size: 15px;
  -webkit-font-smoothing: antialiased; -webkit-text-size-adjust: 100%;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.ico { display: block; flex-shrink: 0; }
.t-ico { display: inline-block; min-width: 20px; text-align: center; font-size: 14px; line-height: 20px; }
.t-ico.small { font-size: 12px; }
.lbl { min-width: 0; }

.app {
  display: grid;
  grid-template-columns: 260px 330px 1fr;
  /* 行の高さを画面の高さに固定する（長いノートを開いても画面全体が伸びず、本文・一覧・左の欄がそれぞれの中でスクロールする） */
  grid-template-rows: minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
}
.sidebar, .list, .editor { min-height: 0; }
.scrim { display: none; }

/* ---------- 共通の部品 ---------- */
.icon-btn {
  min-width: 34px; height: 34px; border-radius: 8px; line-height: 1;
  display: inline-flex; align-items: center; justify-content: center; gap: 4px; color: var(--text-sub);
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }
.icon-btn.on { color: var(--accent); }
.icon-btn.small { min-width: 26px; height: 26px; }
.icon-btn.small .ico { width: 16px; height: 16px; }
.btn { border: 1px solid var(--border); border-radius: 8px; padding: 6px 12px; background: var(--bg); }
.btn:hover { background: var(--bg-hover); }
.btn.danger { color: var(--danger); }
.btn.small, .link-btn.small { font-size: 12px; padding: 4px 10px; }
.btn-primary {
  background: var(--accent); color: var(--accent-text);
  border-radius: 8px; padding: 9px 14px; font-weight: 600;
}
.btn-primary:hover { filter: brightness(1.05); }
.link-btn { text-align: left; font-size: 13px; color: var(--text-sub); padding: 6px 10px; border-radius: 8px; }
.link-btn:hover { background: var(--bg-hover); color: var(--text); }
.link-btn.danger { color: var(--danger); }
.spacer { flex: 1; }
.count { color: var(--text-faint); font-size: 12px; font-variant-numeric: tabular-nums; }

/* 小さな浮き出しメニュー（並び順・…・ノートの操作） */
.popover {
  position: fixed; z-index: 30; min-width: 220px; max-width: calc(100vw - 24px);
  background: var(--bg); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); padding: 6px;
}
.menu-item {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  padding: 9px 10px; border-radius: 8px; font-size: 14px; min-height: 40px;
}
.menu-item:hover, .menu-item:focus-visible { background: var(--bg-hover); outline: none; }
.menu-item.danger { color: var(--danger); }
.menu-item .check { margin-left: auto; color: var(--accent); }
.menu-item .ico { color: var(--text-sub); }
.menu-sep { height: 1px; background: var(--border); margin: 4px 6px; }
.menu-title { font-size: 12px; color: var(--text-faint); padding: 6px 10px 2px; }

/* ---------- サイドバー ---------- */
.sidebar {
  background: var(--bg-side); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 14px 10px 10px; overflow: hidden;
}
.side-head { display: flex; align-items: center; justify-content: space-between; padding: 0 6px 6px 8px; }
.brand { font-weight: 700; font-size: 19px; letter-spacing: .02em; }
.sync-line {
  display: flex; align-items: flex-start; gap: 8px; width: 100%; text-align: left;
  padding: 6px 8px; border-radius: 8px; font-size: 12px; color: var(--text-sub); line-height: 1.45;
}
.sync-line:hover { background: var(--bg-hover); }
.sync-texts { display: grid; min-width: 0; }
.sync-texts > span { overflow: hidden; text-overflow: ellipsis; }
.sync-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-faint); flex-shrink: 0; margin-top: 5px; }
.sync-dot.ok { background: #31a46b; }
.sync-dot.busy { background: var(--accent); animation: pulse 1s infinite alternate; }
.sync-dot.error { background: var(--danger); }
.sync-dot.offline { background: var(--text-faint); }
.sync-detail { display: grid; gap: 1px; }
.sync-detail .warn-link { color: var(--danger); text-align: left; padding: 0; font-size: 12px; }
.detail-error { color: var(--danger); }
@keyframes pulse { from { opacity: 1; } to { opacity: .3; } }
.new-note-side {
  display: flex; align-items: center; gap: 8px; width: 100%; margin: 8px 0 6px;
  padding: 9px 12px; border-radius: 10px; font-weight: 600; font-size: 14px;
  background: var(--bg); border: 1px solid var(--border); color: var(--text);
}
.new-note-side .ico { color: var(--accent); }
.new-note-side:hover { background: var(--bg-hover); }
.side-scroll { flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; margin: 0 -4px; padding: 2px 4px 8px; overscroll-behavior: contain; }
.nav-group { display: grid; gap: 1px; margin-bottom: 6px; }
.nav-group.bottom { margin-top: 12px; padding-top: 8px; border-top: 1px solid var(--border); }
.nav-item {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  padding: 7px 10px; border-radius: 8px; min-height: 36px; font-size: 14px; color: var(--text);
}
.nav-item .ico { color: var(--text-sub); width: 18px; height: 18px; }
.nav-item .nav-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-item:hover { background: var(--bg-hover); }
.nav-item.active { background: var(--bg-active); font-weight: 600; }
.nav-item.active .ico { color: var(--accent); }
.nav-item.sub { font-size: 13.5px; min-height: 32px; padding-top: 5px; padding-bottom: 5px; }
.nav-section {
  display: flex; justify-content: space-between; align-items: center;
  margin: 12px 4px 2px 6px; min-height: 26px;
}
.section-toggle {
  display: flex; align-items: center; gap: 4px; font-size: 12px; color: var(--text-faint); font-weight: 600;
  padding: 3px 4px; border-radius: 6px; letter-spacing: .03em;
}
.section-toggle::before { content: ""; width: 0; height: 0; border-left: 4px solid transparent; border-right: 4px solid transparent; border-top: 5px solid currentColor; transition: transform .15s; }
.nav-block.collapsed .section-toggle::before { transform: rotate(-90deg); }
.nav-block.collapsed .section-body { display: none; }
.section-toggle:hover { color: var(--text); background: var(--bg-hover); }
.section-empty { font-size: 12px; color: var(--text-faint); padding: 4px 10px 6px; line-height: 1.5; }
.nav-row { position: relative; display: flex; align-items: center; }
.nav-row .nav-item { flex: 1; padding-right: 34px; }
.nav-row .row-menu {
  position: absolute; right: 2px; display: none; min-width: 28px; height: 28px; border-radius: 6px;
  align-items: center; justify-content: center; color: var(--text-sub); background: var(--bg-side);
}
.nav-row:hover .row-menu, .nav-row .row-menu:focus-visible { display: inline-flex; }
.nav-row .row-menu:hover { background: var(--bg-active); }
.nb-caret {
  position: absolute; z-index: 1; top: 50%; transform: translateY(-50%);
  width: 22px; height: 22px; display: inline-flex; align-items: center; justify-content: center;
  color: var(--text-faint); border-radius: 4px;
}
.nb-caret:hover { background: var(--bg-active); color: var(--text); }
.nb-caret .ico { width: 14px; height: 14px; }
.nb-caret.closed .ico { transform: rotate(-90deg); }
.nb-dot { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; background: var(--nb, var(--text-faint)); }
.nb-dot.cover { width: 14px; height: 14px; border-radius: 4px; }

/* ノートブックの色（プリセット） */
.c-red { --nb: #e5484d; } .c-orange { --nb: #f07c2c; } .c-yellow { --nb: #e3b008; } .c-green { --nb: #2f9e5b; }
.c-teal { --nb: #12a1a6; } .c-blue { --nb: #3a7be0; } .c-indigo { --nb: #5b5fd6; } .c-purple { --nb: #9a4fd3; }
.c-pink { --nb: #db4c8d; } .c-gray { --nb: #8a8f99; }
/* ノートブックのカバー（プリセット。画像は使わない） */
.cv-sky { background: linear-gradient(135deg, #7ec8f5, #3a7be0); }
.cv-sunset { background: linear-gradient(135deg, #ffb36b, #e5484d); }
.cv-forest { background: linear-gradient(135deg, #8fd19e, #2f7a4a); }
.cv-ocean { background: linear-gradient(135deg, #5ec7c9, #1d5f9e); }
.cv-sand { background: linear-gradient(135deg, #f3e2bd, #c79a5b); }
.cv-mint { background: linear-gradient(135deg, #d6f5e8, #6cc6a0); }
.cv-lavender { background: linear-gradient(135deg, #e5dcff, #9a83e0); }
.cv-paper { background: repeating-linear-gradient(0deg, #fbf8ef 0 22px, #e9e2cf 22px 23px); }
.cv-night { background: radial-gradient(circle at 70% 30%, #6670b8 0, #232a55 55%, #121530 100%); }
.cv-rose { background: linear-gradient(135deg, #ffd6e0, #db4c8d); }

/* ---------- ノート一覧 ---------- */
.list { background: var(--bg-list); border-right: 1px solid var(--border); display: flex; flex-direction: column; min-width: 0; position: relative; }
.list-header { display: flex; align-items: center; gap: 6px; padding: 14px 12px 6px 16px; }
.list-title { flex: 1; min-width: 0; display: flex; align-items: baseline; gap: 8px; }
.list-title h1 { font-size: 20px; margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; letter-spacing: .01em; }
.list-count { color: var(--text-faint); font-size: 13px; flex-shrink: 0; }
.alert-bar {
  display: flex; align-items: center; gap: 8px; margin: 2px 12px 6px; padding: 8px 10px; border-radius: 10px;
  background: var(--warn-bg); color: var(--warn-text); font-size: 13px; text-align: left; line-height: 1.45;
}
.alert-bar .ico { color: var(--danger); }
.nb-banner { margin: 2px 12px 8px; border-radius: 14px; overflow: hidden; border: 1px solid var(--border); background: var(--bg); }
.nb-banner .cover { height: 64px; }
.nb-banner .nb-info { display: flex; align-items: center; gap: 8px; padding: 8px 10px; }
.nb-banner .nb-path { flex: 1; min-width: 0; font-size: 12px; color: var(--text-sub); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nb-banner .children { display: flex; gap: 6px; flex-wrap: wrap; padding: 0 10px 10px; }
.child-chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px; border-radius: 999px;
  border: 1px solid var(--border); font-size: 13px; background: var(--bg-side);
}
.child-chip:hover { background: var(--bg-hover); }
.search { padding: 4px 12px 8px; }
.search input {
  width: 100%; padding: 8px 12px; border-radius: 10px;
  border: 1px solid transparent; background: var(--bg-hover); outline: none;
}
.search input:focus { border-color: var(--accent); background: var(--bg); }
.trash-actions { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 0 16px 8px; font-size: 12px; color: var(--text-sub); }
.custom-hint { font-size: 12px; color: var(--text-faint); padding: 0 16px 6px; }
.note-list { list-style: none; margin: 0; padding: 0 8px 96px; overflow-y: auto; flex: 1; overscroll-behavior: contain; }
.list-section { font-size: 12px; font-weight: 600; color: var(--text-faint); padding: 10px 10px 4px; letter-spacing: .03em; }
.note-item {
  position: relative; border-radius: 10px; margin: 1px 0; overflow: hidden;
  touch-action: pan-y; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  /* 画面の外の行は描かない（1000件でもスクロールが重くならないように） */
  content-visibility: auto; contain-intrinsic-size: auto 82px;
}
.note-row {
  position: relative; z-index: 1; display: flex; gap: 6px; align-items: flex-start;
  padding: 10px 10px 10px 12px; background: var(--bg-list); border-radius: 10px; cursor: pointer;
  transition: transform .18s ease;
}
.note-item.swiping .note-row { transition: none; }
.note-row:hover { background: var(--bg-hover); }
.note-row:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.note-item.active .note-row { background: var(--bg-active); }
.note-main { flex: 1; min-width: 0; padding-right: 22px; }
.note-title { font-weight: 600; font-size: 15px; line-height: 1.4; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: flex; align-items: center; gap: 5px; }
.note-title .ico { width: 14px; height: 14px; color: var(--accent); }
.note-snip { font-size: 13px; color: var(--text-sub); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; line-height: 1.45; }
.note-meta { display: flex; align-items: center; gap: 8px; margin-top: 4px; font-size: 12px; color: var(--text-faint); min-width: 0; }
.note-meta .nbname { display: inline-flex; align-items: center; gap: 4px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.note-meta .nbname .nb-dot { width: 7px; height: 7px; border-radius: 50%; }
.note-meta .tags { color: var(--accent); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.note-item + .note-item .note-row::before {
  content: ""; position: absolute; top: 0; left: 12px; right: 10px; border-top: 1px solid var(--border);
}
.note-item.active .note-row::before, .note-item.active + .note-item .note-row::before { display: none; }
.row-more {
  position: absolute; z-index: 2; right: 8px; top: 8px;
  width: 28px; height: 28px; border-radius: 6px; display: inline-flex; align-items: center; justify-content: center;
  color: var(--text-sub); opacity: 0; background: transparent;
}
.note-item:hover .row-more, .row-more:focus-visible { opacity: 1; }
.note-item.swiping .row-more, .note-item[data-open] .row-more { display: none; }
.row-more:hover { background: var(--bg-active); }
.drag-handle {
  flex-shrink: 0; width: 22px; height: 28px; display: inline-flex; align-items: center; justify-content: center;
  color: var(--text-faint); cursor: grab; margin-left: -6px; touch-action: none;
}
.note-item.dragging { opacity: .55; }
.note-item.drop-before .note-row { box-shadow: inset 0 3px 0 var(--accent); }
.note-item.drop-after .note-row { box-shadow: inset 0 -3px 0 var(--accent); }
/* スワイプで出る操作 */
.swipe-actions { position: absolute; top: 0; bottom: 0; display: flex; z-index: 0; }
/* スワイプしていないときは、後ろの操作ボタンを見せない（角の丸みから色がはみ出さないように） */
.note-item:not(.swiping):not([data-open]) .swipe-actions { visibility: hidden; }
.swipe-actions.left { left: 0; }
.swipe-actions.right { right: 0; }
.swipe-actions button {
  width: 76px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  font-size: 11px; color: #fff;
}
.swipe-actions .sw-pin { background: #e0a100; }
.swipe-actions .sw-trash { background: var(--danger); }
.swipe-actions .sw-quick { background: var(--accent); color: var(--accent-text); }
.empty { color: var(--text-sub); text-align: center; padding: 40px 16px; font-size: 14px; line-height: 1.7; }
.fab {
  position: absolute; right: 18px; bottom: calc(18px + env(safe-area-inset-bottom)); z-index: 5;
  width: 56px; height: 56px; border-radius: 50%; background: var(--accent); color: var(--accent-text);
  align-items: center; justify-content: center; box-shadow: 0 6px 20px rgba(40, 70, 160, .35);
}
.fab .ico { width: 26px; height: 26px; }

/* ---------- エディタ ---------- */
.editor { display: flex; flex-direction: column; min-width: 0; background: var(--bg); }
.editor-empty { margin: auto; color: var(--text-faint); font-size: 14px; }
.editor-body { display: flex; flex-direction: column; height: 100%; min-height: 0; position: relative; }
.editor-header { display: flex; align-items: center; gap: 4px; padding: 8px 12px; min-height: 50px; }
.tag-bar { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; padding: 2px 16px 8px; font-size: 13px; }
.nb-chip {
  display: inline-flex; align-items: center; gap: 6px; max-width: 60%; padding: 3px 10px 3px 8px; border-radius: 999px;
  background: var(--bg-side); border: 1px solid var(--border); font-size: 12.5px; color: var(--text-sub);
}
.nb-chip .lbl { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nb-chip .ico { width: 15px; height: 15px; }
.nb-chip:hover { background: var(--bg-hover); color: var(--text); }
.tags { display: flex; gap: 4px; flex-wrap: wrap; }
.chip {
  display: inline-flex; align-items: center; gap: 2px; color: var(--accent);
  background: var(--accent-soft); border-radius: 999px; padding: 2px 4px 2px 10px; font-size: 12.5px;
}
.chip button { color: var(--text-sub); padding: 0 5px; font-size: 13px; min-height: 22px; }
.chip button:hover { color: var(--danger); }
#tagInput {
  border: 1px dashed var(--border); border-radius: 999px; background: transparent; outline: none;
  width: 9.5em; padding: 3px 10px; color: var(--text); font-size: 12.5px;
}
#tagInput:focus { border-style: solid; border-color: var(--accent); width: 14em; }
#tagInput::placeholder { color: var(--text-faint); }
.tag-suggest { display: inline-flex; gap: 4px; flex-wrap: wrap; align-items: center; }
.tag-suggest:empty { display: none; }
.tag-suggest .hint { color: var(--text-faint); font-size: 12px; }
.tag-suggest button { border: 1px dashed var(--accent); border-radius: 999px; padding: 1px 9px; font-size: 12px; color: var(--text); }
.tag-suggest button:hover { background: var(--bg-hover); }
.tag-suggest .dismiss { border: 0; color: var(--text-sub); padding: 1px 4px; }
.trash-banner {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  margin: 0 12px 8px; padding: 10px 12px; background: var(--bg-side); border-radius: 10px; font-size: 14px;
}
.trash-banner span { flex: 1; color: var(--text-sub); }
.conflict-banner {
  display: grid; gap: 8px; margin: 0 12px 8px; padding: 10px 12px; border-radius: 10px;
  background: #fff1ef; color: #6b1d12; font-size: 13px; line-height: 1.6;
}
.conflict-banner .banner-buttons { display: flex; gap: 6px; flex-wrap: wrap; }
@media (prefers-color-scheme: dark) { .conflict-banner { background: #3a1d19; color: #ffd2ca; } }
.toolbar {
  display: flex; gap: 2px; padding: 4px 10px; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border);
  flex-wrap: wrap; align-items: center; background: var(--bg);
}
.toolbar button {
  display: inline-flex; align-items: center; gap: 4px; padding: 5px 8px; border-radius: 8px; font-size: 13px; color: var(--text-sub); min-height: 32px;
}
.toolbar button .ico { width: 18px; height: 18px; }
.toolbar button:hover { background: var(--bg-hover); color: var(--text); }
.toolbar .tb-more { color: var(--accent); }
.tool-more { padding: 6px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 2px; }

.content {
  flex: 1; min-height: 0; overflow-y: auto; padding: 18px max(24px, calc((100% - 760px) / 2)) 80px;
  outline: none; line-height: var(--note-line-height); font-size: var(--note-font-size); overflow-wrap: anywhere;
}
.content:empty::before { content: attr(data-placeholder); color: var(--text-faint); }
.content.is-empty > div:first-child::before { content: "1行目がタイトルになります"; color: var(--text-faint); font-weight: 400; pointer-events: none; }
/* 1行目はタイトル（先頭が折りたたみのときは、その見出しをタイトルとして扱う） */
.content > :first-child:not(.fold) { font-size: 1.4em; font-weight: 700; margin-top: 0; line-height: 1.4; }
.content > .fold:first-child > .fold-title { font-size: 1.4em; margin-top: 0; }
.content h2 { font-size: 1.2em; margin: 1.1em 0 .35em; line-height: 1.45; }
.content h3 { font-size: 1.06em; margin: .9em 0 .25em; line-height: 1.45; }
.content p, .content div { margin: 0; }
.content > div + div, .content .fold-body > div + div { margin-top: var(--note-para-space); }
.content ul, .content ol { margin: 4px 0; padding-left: 1.6em; }
.content blockquote { border-left: 3px solid var(--border); margin: 6px 0; padding-left: 12px; color: var(--text-sub); }
.content a { color: var(--accent); }
.content ul.checklist { list-style: none; padding-left: 0.2em; }
.content ul.checklist > li { position: relative; padding-left: 1.8em; }
.content ul.checklist > li::before {
  content: ""; position: absolute; left: 0; top: calc((var(--note-line-height) * 1em - 1.05em) / 2);
  width: 1.05em; height: 1.05em; border: 1.5px solid var(--text-sub); border-radius: 4px; cursor: pointer;
}
.content ul.checklist > li.done { color: var(--text-sub); text-decoration: line-through; }
.content ul.checklist > li.done::before { background: var(--accent); border-color: var(--accent); }
.content ul.checklist > li.done::after {
  content: "✓"; position: absolute; left: 0.2em; top: calc((var(--note-line-height) * 1em - 1.05em) / 2 - .08em);
  font-size: 0.85em; color: var(--accent-text); font-weight: 700;
}
.content[contenteditable="false"] { opacity: 0.8; }
.content img { display: block; max-width: 100%; height: auto; margin: 6px 0; border-radius: 8px; }
.content img[data-missing], .content img:not([src]) { width: 180px; height: 110px; background: var(--bg-side); border: 1px dashed var(--border); }
.content .fold { margin: 4px 0; }
.content .fold-title { position: relative; padding-left: 1.5em; margin: 12px 0 2px; }
.content .fold-title::before { content: "▾"; position: absolute; left: 0; top: 0; width: 1.3em; text-align: center; color: var(--text-sub); cursor: pointer; font-weight: 400; }
.content .fold.closed > .fold-title::before { content: "▸"; }
.content .fold-title:empty::after { content: "見出し"; color: var(--text-faint); font-weight: 400; }
.content .fold-body { margin-left: .55em; padding-left: calc(.95em - 2px); border-left: 2px solid var(--border); }
.content .fold.closed > .fold-body { display: none; }

/* ---------- 目次 ---------- */
.toc {
  position: absolute; right: 12px; top: 50px; z-index: 6;
  width: min(340px, calc(100% - 24px)); max-height: min(65vh, 520px); overflow-y: auto;
  background: var(--bg); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); padding: 6px;
}
.toc-item { display: block; width: 100%; text-align: left; padding: 8px 10px; border-radius: 8px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.toc-item:hover { background: var(--bg-hover); }
.toc-item.level2 { padding-left: 26px; color: var(--text-sub); font-size: 13px; }
.toc-empty { margin: 8px 10px; color: var(--text-sub); font-size: 13px; line-height: 1.6; }
.toc-search { width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); margin-bottom: 6px; outline: none; }
.toc-search:focus { border-color: var(--accent); }
.toc-item.hit { white-space: normal; line-height: 1.5; }
.toc-item.hit small { display: block; color: var(--text-sub); font-size: 11px; }
.toc-item mark { background: #ffe58a; color: inherit; border-radius: 2px; }

.editor-footer { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; padding: 6px 16px; border-top: 1px solid var(--border); font-size: 12px; }
.save-state { font-size: 12px; color: var(--text-faint); }
.save-state.error { color: var(--danger); font-weight: 600; }
.meta { color: var(--text-faint); font-size: 12px; }

/* ---------- 画面（ダイアログ） ---------- */
.dialog {
  border: 1px solid var(--border); border-radius: 14px; padding: 22px 22px 18px;
  background: var(--bg); color: var(--text); width: min(540px, calc(100% - 32px));
  box-shadow: var(--shadow); position: relative; max-height: calc(100dvh - 32px); overflow-y: auto;
}
.dialog::backdrop { background: rgba(10, 12, 20, .38); }
.dialog h2 { margin: 0 30px 12px 0; font-size: 18px; }
.dialog h3 { margin: 0 0 8px; font-size: 14px; }
.dialog p { margin: 0 0 12px; line-height: 1.6; }
.dialog .note { color: var(--text-sub); font-size: 13px; }
.dialog-close { position: absolute; top: 12px; right: 12px; }
.dialog-buttons { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 16px; align-items: center; }
.dialog-buttons .btn { padding: 8px 14px; }
.howto { background: var(--bg-side); border-radius: 10px; padding: 10px 12px; font-size: 14px; }
.howto summary { cursor: pointer; font-weight: 600; }
.howto ol { margin: 10px 0 6px; padding-left: 1.3em; line-height: 1.7; }
.howto .note { margin: 0; }
.summary { margin: 0; padding-left: 1.2em; line-height: 1.9; }
.summary .warn { color: var(--text-sub); }
.field-label { display: block; font-weight: 600; font-size: 14px; margin: 14px 0 6px; }
.dialog p.field-label { margin: 14px 0 6px; }
.field-select { width: 100%; padding: 9px 10px; border: 1px solid var(--border); border-radius: 10px; background: var(--bg); }
.choices { display: grid; gap: 6px; }
.choice { display: flex; gap: 10px; align-items: flex-start; text-align: left; width: 100%; border: 1px solid var(--border); border-radius: 10px; padding: 9px 12px; background: var(--bg); }
.choice:hover { background: var(--bg-hover); }
.choice[aria-checked="true"] { border-color: var(--accent); background: var(--accent-soft); }
.choice .dot { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--text-sub); flex-shrink: 0; margin-top: 3px; }
.choice[aria-checked="true"] .dot { border-color: var(--accent); background: radial-gradient(var(--accent) 45%, transparent 50%); }
.choice b { display: block; font-size: 14px; }
.choice small { display: block; color: var(--text-sub); font-size: 12px; line-height: 1.5; margin-top: 2px; }
.export-howto { margin-top: 10px; }
.export-howto p { margin: 0 0 6px; font-weight: 600; }
.export-howto ul { margin: 0; padding-left: 1.2em; line-height: 1.7; }
.backup-list { list-style: none; margin: 0 0 8px; padding: 0; display: grid; gap: 4px; }
.backup-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; border: 1px solid var(--border); border-radius: 10px; padding: 6px 10px; }
.backup-row b { display: block; font-size: 14px; }
.backup-row small { color: var(--text-sub); font-size: 12px; }
.backup-list .note { list-style: none; color: var(--text-sub); font-size: 13px; }
.code-steps { margin: 6px 0 12px; padding-left: 1.3em; line-height: 1.9; font-size: 14px; }
.code-steps a { color: var(--accent); font-weight: 600; }
.restore-area { margin-top: 16px; border-top: 1px solid var(--border); padding-top: 4px; }
.check-list { list-style: none; padding-left: 0; }
.check-list .issue { padding: 6px 0; border-bottom: 1px solid var(--border); line-height: 1.6; }
.check-list .issue small { display: block; color: var(--text-sub); }
.check-list .issue.error, .check-list .issue.warn { color: var(--danger); }
.check-list .issue.ok { color: #31a46b; font-weight: 600; }
.sync-buttons { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }

/* 設定 */
.set-block { padding: 14px 0; border-top: 1px solid var(--border); }
.set-block:first-of-type { border-top: 0; padding-top: 2px; }
.set-row { display: grid; gap: 4px; margin: 10px 0; font-size: 14px; }
.set-row b { color: var(--accent); font-weight: 600; margin-left: 6px; }
.set-row input[type="range"] { width: 100%; accent-color: var(--accent); }
.preview { border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; margin: 6px 0 8px; background: var(--bg-list); }
.content-look { line-height: var(--note-line-height); font-size: var(--note-font-size); }
.content-look > div + div { margin-top: var(--note-para-space); }
.content-look > div:first-child { font-weight: 700; font-size: 1.2em; }
.set-links { display: grid; gap: 2px; }
.tool-order { list-style: none; margin: 6px 0; padding: 0; display: grid; gap: 4px; }
.tool-row { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border: 1px solid var(--border); border-radius: 10px; background: var(--bg); }
.tool-row .tool-name { flex: 1; font-size: 14px; display: flex; align-items: center; gap: 8px; }
.tool-row .slot { font-size: 11px; color: var(--accent); background: var(--accent-soft); border-radius: 6px; padding: 1px 6px; }
.tool-row.dragging { opacity: .5; }
.tool-row.off .tool-name { color: var(--text-faint); }
.tool-row .tool-name input { width: 20px; height: 20px; accent-color: var(--accent); margin: 0 2px 0 0; }
.menu-item.tool-edit { grid-column: 1 / -1; color: var(--accent); }
.tool-row.drop-before { box-shadow: inset 0 3px 0 var(--accent); }
.tool-row.drop-after { box-shadow: inset 0 -3px 0 var(--accent); }
/* ノートブックの編集 */
.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.swatch {
  width: 32px; height: 32px; border-radius: 50%; border: 2px solid transparent; background: var(--nb, var(--bg-side));
  display: inline-flex; align-items: center; justify-content: center; font-size: 12px; color: var(--text-sub);
}
.swatches.covers .swatch { width: 54px; height: 36px; border-radius: 8px; }
.swatch[aria-checked="true"] { border-color: var(--text); box-shadow: 0 0 0 2px var(--bg) inset; }
.swatch.none { border: 2px dashed var(--border); }
.swatch.none[aria-checked="true"] { border-color: var(--text); border-style: solid; }
.move-list { display: grid; gap: 2px; max-height: 60vh; overflow-y: auto; }

.readonly-bar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 40; display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
  padding: max(8px, env(safe-area-inset-top)) 14px 8px; background: #fff4d6; color: #5a4300; font-size: 14px; border-bottom: 1px solid #e8d38c;
}
.readonly-bar span { flex: 1; min-width: 200px; }
@media (prefers-color-scheme: dark) { .readonly-bar { background: #3a3110; color: #f5e3a6; border-color: #5a4a14; } }
.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 14px; line-height: 1.5;
  box-shadow: 0 4px 16px rgba(0,0,0,.2); z-index: 50; max-width: calc(100% - 32px);
}

.mobile-only { display: none; }
.desktop-only { display: flex; }

/* ---------- スマホ ---------- */
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .list, .editor { display: none; border-right: 0; }
  .app[data-pane="list"] .list { display: flex; }
  .app[data-pane="editor"] .editor { display: flex; }
  .mobile-only { display: inline-flex; }
  .desktop-only { display: none; }
  /* サイドバー：左から出る引き出し（画面の84%）。右側に一覧が少し見える */
  .sidebar {
    position: fixed; top: 0; bottom: 0; left: 0; z-index: 25; width: min(84vw, 360px);
    transform: translateX(-102%); transition: transform .24s ease; border-right: 0; box-shadow: none;
    padding-top: max(14px, env(safe-area-inset-top)); padding-bottom: max(10px, env(safe-area-inset-bottom));
  }
  .app[data-drawer="open"] .sidebar { transform: none; box-shadow: var(--shadow); }
  /* 起動直後は動かさない（開いた画面がいきなり引き出しの動きを見せないように） */
  .app:not(.ready) .sidebar, .app:not(.ready) .scrim { transition: none; }
  .scrim {
    display: block; position: fixed; inset: 0; z-index: 24; background: rgba(10, 12, 20, .32);
    opacity: 0; pointer-events: none; transition: opacity .24s ease;
  }
  .app[data-drawer="open"] .scrim { opacity: 1; pointer-events: auto; }
  .content { padding: 14px 18px 120px; }
  /* iPhoneは16px未満の入力欄を押すと画面が勝手に拡大されるため、入力欄は16pxにする */
  input, select, textarea, #tagInput { font-size: 16px; }
  #tagInput { width: 8.5em; }
  /* 指で押しやすい大きさ（44px前後） */
  .icon-btn { min-width: 44px; height: 44px; }
  .nav-item { min-height: 44px; padding: 9px 12px; font-size: 15px; }
  .nav-item.sub { min-height: 40px; }
  .note-row { padding: 12px 12px 12px 14px; }
  .note-title { font-size: 16px; }
  .link-btn { padding: 9px 10px; }
  .row-more { display: none; }
  .note-list.reorder .row-more { display: inline-flex; opacity: 1; width: 40px; height: 40px; }
  .note-list:not(.reorder) .note-main { padding-right: 0; }
  .note-list.reorder .note-main { padding-right: 36px; }
  .nav-row .row-menu { display: inline-flex; min-width: 40px; height: 40px; }
  .nav-row .nav-item { padding-right: 44px; }
  .menu-item { min-height: 46px; font-size: 15px; }
  /* iPhoneの画面上部の切り欠き・下部のバーに重ならないようにする */
  .list-header, .editor-header { padding-top: max(10px, env(safe-area-inset-top)); }
  .list-header { padding-left: 6px; }
  .editor-header { padding-left: 4px; padding-right: 6px; }
  .editor-footer { padding-bottom: max(8px, env(safe-area-inset-bottom)); }
  .toc { top: calc(54px + env(safe-area-inset-top)); }
  /* 編集ツール：本文を編集しているときだけ、キーボードのすぐ上に出す */
  .toolbar {
    position: fixed; left: 0; right: 0; bottom: var(--kb-offset); z-index: 20; flex-wrap: nowrap; overflow-x: auto;
    padding: 4px 6px; border-bottom: 0; box-shadow: 0 -2px 12px rgba(0,0,0,.08);
    display: none;
  }
  body.kb-editing .toolbar:not([hidden]) { display: flex; }
  body.kb-editing .content { padding-bottom: 50vh; }
  body.kb-editing:not(.kb-open) .toolbar { padding-bottom: max(4px, env(safe-area-inset-bottom)); }
  .toolbar button { min-height: 44px; min-width: 44px; justify-content: center; padding: 6px 8px; flex: 0 0 auto; white-space: nowrap; }
  .toolbar button .tb-label { display: none; }
  .tool-more { position: fixed; left: 8px; right: 8px; bottom: calc(var(--kb-offset) + 58px); top: auto !important; grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .dialog.sheet { width: 100%; max-width: 100%; height: 100dvh; max-height: 100dvh; border-radius: 0; margin: 0; padding-top: max(18px, env(safe-area-inset-top)); padding-bottom: max(18px, env(safe-area-inset-bottom)); }
  .dialog-close { top: max(10px, env(safe-area-inset-top)); }
}
@media (min-width: 761px) and (max-width: 1020px) {
  .app { grid-template-columns: 220px 280px 1fr; }
}
@media (min-width: 761px) {
  .toolbar .tb-more { border-right: 1px solid var(--border); border-radius: 0; margin-right: 4px; }
}
