:root {
  --bg: #f6f7fb;
  --panel: #ffffff;
  --panel-soft: #f0f3f8;
  --text: #1f2937;
  --muted: #6b7280;
  --line: #e5e7eb;
  --primary: #2563eb;
  --primary-soft: #dbeafe;
  --danger: #dc2626;
  --shadow: 0 20px 50px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans JP", sans-serif;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  height: 100vh;
}

.mobile-menu-btn,
.mobile-menu-backdrop {
  display: none;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 22px;
  border-right: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(12px);
  overflow: hidden;
}

.brand {
  display: grid;
  gap: 12px;
}

.brand-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: 32px;
  letter-spacing: 0;
}

.icon-btn {
  width: 100%;
  min-height: 54px;
  border: 0;
  border-radius: 12px;
  padding: 8px 6px;
  background: var(--primary);
  color: #fff;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 800;
  line-height: 1.15;
  box-shadow: 0 10px 20px rgba(37, 99, 235, 0.25);
}

.icon-btn .btn-icon {
  font-size: 18px;
}

.icon-btn .btn-label {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mindmap-switch-btn {
  width: fit-content;
  min-height: 42px;
  border: 1px solid #bfdbfe;
  border-radius: 12px;
  padding: 10px 14px;
  background: #eff6ff;
  color: #1d4ed8;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 800;
  box-shadow: 0 8px 20px rgba(37, 99, 235, 0.12);
}

.mindmap-switch-btn:hover {
  background: #dbeafe;
}

.search-box {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.search-box input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  background: var(--panel-soft);
  outline: none;
}

.search-box input:focus {
  border-color: var(--primary);
  background: #fff;
}


.tree-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.tree {
  flex: 1;
  overflow: auto;
  padding-right: 4px;
}

.tree-node {
  margin: 4px 0;
}

.tree-row {
  position: relative;              /* drag-before の ::before アンカー */
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr) auto auto;   /* badge 列を追加 */
  align-items: center;
  gap: 4px;
  width: 100%;
  border: 0;
  border-radius: 12px;
  padding: 7px 7px;
  background: transparent;
  color: var(--text);
  text-align: left;
}

.tree-row:hover {
  background: var(--panel-soft);
}

.tree-row.active {
  background: var(--primary-soft);
  color: #1d4ed8;
  font-weight: 700;
}

.tree-row.pinned {
  background: #f8fbff;
}

.tree-row.pinned.active {
  background: var(--primary-soft);
}

.tree-row.checked .tree-title {
  font-weight: 800;
}

.tree-row.drag-target {
  outline: 2px solid var(--primary);
}

/* 上半分ドロップ: 「ここに挿入」ライン */
.tree-row.drag-before::before {
  content: "";
  position: absolute;
  top: -1px;
  left: 8px;
  right: 8px;
  height: 2px;
  background: var(--primary);
  border-radius: 1px;
  pointer-events: none;
}

.tree-insert-zone {
  position: relative;
  height: 0;
  margin: 0 8px;
  pointer-events: none;
  transition: height 0.12s ease, margin 0.12s ease;
}

.is-dragging .tree-insert-zone {
  height: 12px;
  margin-block: 1px;
  pointer-events: auto;
}

.tree-insert-zone::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 8px;
  right: 8px;
  height: 2px;
  border-radius: 999px;
  background: transparent;
  transform: translateY(-50%);
  transition: background 0.12s ease, box-shadow 0.12s ease;
}

.tree-insert-zone.drag-target::before {
  background: var(--primary);
  box-shadow: 0 0 0 4px var(--primary-soft);
}

/* ブランチ数バッジ */
.tree-count-badge {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  background: var(--panel-soft);
  border-radius: 10px;
  padding: 1px 6px;
  min-width: 18px;
  text-align: center;
  flex-shrink: 0;
  line-height: 1.5;
}

.toggle {
  color: var(--muted);
  font-size: 13px;
}

.tree-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tree-title-wrap {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 5px;
}

.tree-pin {
  flex-shrink: 0;
  font-size: 12px;
  line-height: 1;
}

.tree-check {
  flex-shrink: 0;
  font-size: 20px;
  line-height: 1;
  filter: drop-shadow(0 1px 1px rgba(15, 23, 42, 0.14));
}

.tree-add {
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 10px;
  padding: 0;
  background: transparent;
  color: var(--muted);
  font-size: 15px;
  font-weight: 800;
}

.tree-add:hover {
  background: #fff;
  color: var(--primary);
}

.tree-children {
  margin-left: 18px;
  padding-left: 10px;
  border-left: 1px solid var(--line);
}

.editor {
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 28px;
}

.editor-top {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 16px;
}

.breadcrumb {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.title-input {
  width: min(760px, 100%);
  border: 0;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--text);
  font-size: 36px;
  font-weight: 800;
  letter-spacing: 0;
  outline: none;
}

.title-input:focus {
  border-color: var(--primary);
}

.actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.btn {
  border: 0;
  border-radius: 13px;
  padding: 11px 14px;
  background: var(--text);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-weight: 700;
  line-height: 1.2;
  white-space: nowrap;
}

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.btn-label {
  min-width: 0;
}

.btn:hover {
  filter: brightness(1.05);
}

.btn:disabled {
  cursor: not-allowed;
  filter: none;
  opacity: 0.42;
}

.btn.ghost {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
}

.btn.danger {
  background: #fee2e2;
  color: var(--danger);
}

.check-toggle-btn {
  min-width: 44px;
  padding-inline: 12px;
}

.check-toggle-btn.active {
  background: #dcfce7;
  color: #166534;
  border-color: #bbf7d0;
}

.selected-info {
  min-height: 28px;
  margin-bottom: 14px;
  color: var(--muted);
  font-size: 13px;
}

.content-input {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 24px;
  background: var(--panel);
  box-shadow: var(--shadow);
  color: var(--text);
  font-size: 16px;
  line-height: 1.8;
  outline: none;
  cursor: text;
  word-break: break-word;
}

/* Enter で生成される空行（中身が空の <div>）が高さ0で消えてしまわないようにする */
.content-input > div {
  min-height: 1.8em;
}

.content-input:focus {
  border-color: var(--primary);
}

/* プレースホルダー（空のとき .is-empty クラスで表示） */
.content-input.is-empty::before {
  content: attr(data-placeholder);
  position: absolute;
  top: 24px;
  left: 24px;
  right: 24px;
  color: #9ca3af;
  pointer-events: none;
}

.content-input.is-empty.is-focused::before,
.content-input.is-empty:focus::before {
  opacity: 0;
}

/* ── インラインメディア（Apple Notes 風） ────────────────── */

/* figure ラッパー：テキストの流れの中に自然に挿入される */
.inline-media-figure {
  position: relative;
  display: inline-block;
  width: 75%;
  max-width: 75%;
  margin: 8px 0;
  border-radius: 16px;
  overflow: hidden;
  background: var(--panel-soft);
  user-select: none;          /* contenteditable="false" でアトミック */
  -webkit-user-drag: none;
  vertical-align: top;
  line-height: 0;             /* figure 内の余分な行高をリセット */
}

/* 画像：幅いっぱいに広がり、縦は最大 70vh まで */
.inline-media-figure img.inline-media {
  display: block;
  width: 100%;
  height: auto;
  max-height: 70vh;
  object-fit: contain;
  border-radius: 16px;
  cursor: zoom-in;
  -webkit-user-drag: none;
  transition: filter 0.18s;
}

.inline-media-figure:hover img.inline-media {
  filter: brightness(0.94);
}

/* 動画：幅いっぱい、縦最大 60vh */
.inline-media-figure video.inline-media {
  display: block;
  width: 100%;
  max-height: 60vh;
  object-fit: contain;
  border-radius: 16px;
  background: #000;
  -webkit-user-drag: none;
}

/* ✕ ボタンは廃止（右クリックメニューの「削除」に統合） */
.inline-media-del {
  display: none !important;
}

/* ── ライトボックス ─────────────────────────────────────── */

.lightbox-overlay {
  position: fixed;
  inset: 0;
  z-index: 10000;
  background: rgba(0, 0, 0, 0.88);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: overlayIn 0.15s ease both;
  cursor: zoom-out;
}

.lightbox-img {
  max-width:  95vw;
  max-height: 92vh;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.6);
  animation: dialogIn 0.18s cubic-bezier(0.34, 1.3, 0.64, 1) both;
  cursor: default;
}

.lightbox-close {
  position: fixed;
  top: 18px;
  right: 22px;
  min-height: 40px;
  border: 0;
  border-radius: 999px;
  padding: 0 14px;
  background: rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  transition: background 0.15s;
  z-index: 10001;
}

.lightbox-close:hover {
  background: rgba(255, 255, 255, 0.28);
}

/* ── /ライトボックス ───────────────────────────────────── */

/* ── トリミングモーダル ─────────────────────────────────── */

.crop-overlay {
  position: fixed;
  inset: 0;
  z-index: 10000;
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: overlayIn 0.15s ease both;
}

.crop-dialog {
  background: var(--panel);
  border-radius: 24px;
  padding: 24px;
  width:  min(calc(100vw - 32px), 960px);
  max-height: calc(100vh - 32px);
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 4px 6px rgba(15,23,42,.04), 0 24px 64px rgba(15,23,42,.22);
  animation: dialogIn 0.2s cubic-bezier(0.34, 1.3, 0.64, 1) both;
}

.crop-title {
  margin: 0;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 0;
}

.crop-hint {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.crop-canvas-wrap {
  overflow: auto;
  border-radius: 12px;
  background: #1a1a1a;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 120px;
}

#cropCanvas {
  display: block;
  touch-action: none;      /* ポインターイベントのみ、スクロール抑制 */
  cursor: crosshair;
  border-radius: 8px;
}

.crop-btns {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

/* ── /トリミングモーダル ────────────────────────────────── */

/* メディアサイズバリアント（右クリックメニューで変更） */
.inline-media-figure[data-size="small"]  {
  width: min(120px, 36vw);
  max-width: min(120px, 36vw);
}
.inline-media-figure[data-size="medium"],
.inline-media-figure[data-size="large"]  {
  width: 75%;
  max-width: 75%;
}

/* 旧データで残った入力行。新しい画像まわりでは透明な span を使う */
.media-text-line {
  min-height: 1.9em;
  margin: 8px 0;
  line-height: 1.8;
}

.media-caret-anchor {
  position: relative;
  display: inline-block;
  width: 8px;
  min-width: 8px;
  margin: 0 -4px;
  padding: 0;
  min-height: var(--media-caret-height, 1.8em);
  line-height: var(--media-caret-height, 1.8em);
  vertical-align: top;
  white-space: pre;
  caret-color: transparent;
  cursor: text;
  overflow: visible;
}

/* margin の負値で画像と重なっているため、画像より手前（前側のアンカー）でも
   キャレットバーが画像の背景に隠れないよう手前に出す */
.media-caret-anchor.is-active-media-caret {
  z-index: 1;
}

.media-caret-anchor.is-active-media-caret::after {
  content: "";
  position: absolute;
  top: 0;
  left: 50%;
  width: 1.5px;
  height: var(--media-caret-height, 1.8em);
  background: currentColor;
  border-radius: 1px;
  transform: translateX(-50%);
  pointer-events: none;
  animation: mediaCaretBlink 1s steps(1, end) infinite;
}

@keyframes mediaCaretBlink {
  0%, 49% { opacity: 1; }
  50%, 100% { opacity: 0; }
}

/* 旧データのアンカーでも IME の入力位置が左上へ飛ばないようにする */
.media-cursor-anchor {
  display: inline-block;
  min-width: 1px;
  min-height: 1em;
  vertical-align: baseline;
}

/* ── /インラインメディア ─────────────────────────────────── */

.status-bar {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 4px 0;
  color: var(--muted);
  font-size: 13px;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  max-width: 360px;
  padding: 14px 16px;
  border-radius: 16px;
  background: #111827;
  color: #fff;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: 0.2s;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

/* ── カスタム確認モーダル ────────────────────────────────── */

.confirm-overlay {
  /* デフォルト非表示。JS が .open を付けたとき表示 */
  display: none;
  position: fixed;
  inset: 0;
  z-index: 13000;
  align-items: center;
  justify-content: center;
  background: rgba(15, 23, 42, 0.32);
}

.confirm-overlay.open {
  display: flex;
  animation: overlayIn 0.18s ease both;
}

@keyframes overlayIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.confirm-dialog {
  background: var(--panel);
  border-radius: 24px;
  padding: 28px 28px 20px;
  width: min(360px, calc(100vw - 40px));
  box-shadow:
    0 4px 6px rgba(15, 23, 42, 0.04),
    0 24px 64px rgba(15, 23, 42, 0.16);
  animation: dialogIn 0.2s cubic-bezier(0.34, 1.4, 0.64, 1) both;
}

@keyframes dialogIn {
  from { opacity: 0; transform: scale(0.90) translateY(12px); }
  to   { opacity: 1; transform: scale(1)    translateY(0);    }
}

.confirm-msg {
  margin: 0 0 24px;
  color: var(--text);
  font-size: 15px;
  font-weight: 500;
  line-height: 1.65;
}

.confirm-btns {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

/* ── /カスタム確認モーダル ───────────────────────────────── */

/* ── 右クリックコンテキストメニュー ─────────────────────── */

.context-menu {
  position: fixed;
  z-index: 9999;
  min-width: 186px;
  padding: 6px 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 8px 32px rgba(15, 23, 42, 0.14), 0 2px 8px rgba(15, 23, 42, 0.08);
  animation: ctxFadeIn 0.1s ease;
}

@keyframes ctxFadeIn {
  from { opacity: 0; transform: scale(0.96) translateY(-4px); }
  to   { opacity: 1; transform: scale(1)    translateY(0); }
}

/* コンテキストメニューのセクションラベル */
.ctx-section-label {
  padding: 6px 16px 4px;
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: 0;
  text-transform: uppercase;
  pointer-events: none;
}

.ctx-item {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 9px 16px;
  border: 0;
  background: transparent;
  color: var(--text);
  font-size: 14px;
  text-align: left;
  cursor: pointer;
  transition: background 0.1s;
}

.ctx-item:hover:not(:disabled) {
  background: var(--panel-soft);
}

.ctx-item:disabled {
  color: var(--muted);
  cursor: default;
  opacity: 0.45;
}

.ctx-danger {
  color: var(--danger);
}

.ctx-sep {
  height: 1px;
  margin: 5px 0;
  background: var(--line);
}

/* ツリー行のインライン名前変更入力 */
.tree-rename-input {
  width: 100%;
  border: 1.5px solid var(--primary);
  border-radius: 6px;
  padding: 1px 6px;
  background: #fff;
  font: inherit;
  font-size: 14px;
  color: var(--text);
  outline: none;
  box-shadow: 0 0 0 3px var(--primary-soft);
}

/* ── /右クリックコンテキストメニュー ─────────────────────── */

/* ── メディア添付ボタン ───────────────────────────────────── */

.media-add-btn {
  font-size: 14px;
  letter-spacing: 0;
}

.undo-btn {
  min-width: 86px;
}

/* エディタエリアへのドラッグオーバー */
.editor.media-drag-over {
  outline: 3px dashed var(--primary);
  outline-offset: -6px;
  border-radius: 24px;
  background: var(--primary-soft);
}

.editor.media-drag-over > * {
  pointer-events: none;
}

@media (max-width: 860px) {
  .app-shell {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 100vh;
    min-height: 100dvh;
    padding-top: calc(62px + env(safe-area-inset-top));
  }

  body.has-mobile-menu-open {
    overflow: hidden;
  }

  .mobile-menu-btn {
    position: fixed;
    top: calc(10px + env(safe-area-inset-top));
    left: 12px;
    z-index: 11200;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    min-width: 88px;
    min-height: 44px;
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 0 12px;
    background: rgba(255, 255, 255, 0.96);
    color: var(--text);
    box-shadow: 0 12px 28px rgba(15, 23, 42, 0.16);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    font-weight: 800;
  }

  .mobile-menu-icon {
    width: 18px;
    font-size: 20px;
  }

  .mobile-menu-text {
    font-size: 13px;
    line-height: 1;
  }

  .app-shell.mobile-menu-open .mobile-menu-btn {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
  }

  .mobile-menu-backdrop:not([hidden]) {
    position: fixed;
    inset: 0;
    z-index: 11000;
    display: block;
    background: rgba(15, 23, 42, 0.38);
    animation: overlayIn 0.16s ease both;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 11100;
    width: min(86vw, 360px);
    height: 100vh;
    height: 100dvh;
    min-height: 0;
    gap: 12px;
    padding: calc(70px + env(safe-area-inset-top)) 16px 18px;
    border-bottom: 0;
    border-right: 1px solid var(--line);
    box-shadow: 20px 0 42px rgba(15, 23, 42, 0.18);
    transform: translateX(-105%);
    transition: transform 0.22s ease;
    will-change: transform;
  }

  .app-shell.mobile-menu-open .sidebar {
    transform: translateX(0);
  }

  .brand {
    gap: 10px;
  }

  .brand-actions {
    gap: 6px;
  }

  .eyebrow {
    font-size: 11px;
  }

  h1 {
    font-size: 28px;
  }

  .icon-btn {
    min-height: 48px;
    padding: 7px 5px;
    font-size: 11px;
  }

  .icon-btn .btn-icon {
    font-size: 17px;
  }

  .search-box {
    gap: 6px;
  }

  .search-box input {
    padding: 11px 12px;
  }

  .tree {
    min-height: 0;
    padding-right: 0;
  }

  .tree-row {
    grid-template-columns: 50px minmax(0, 1fr) auto auto;
    min-height: 42px;
    padding: 5px 6px 5px 0;
  }

  .toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 50px;
    min-height: 44px;
    margin: -5px 0;
    border-radius: 12px;
    font-size: 17px;
    touch-action: manipulation;
  }

  .tree-add {
    opacity: 1;
    background: var(--panel-soft);
  }

  .tree-children {
    margin-left: 12px;
    padding-left: 8px;
  }

  .editor {
    min-height: calc(100dvh - 62px - env(safe-area-inset-top));
    padding: 18px 16px 20px;
  }

  .editor-top {
    flex-direction: column;
    gap: 12px;
    margin-bottom: 12px;
  }

  .editor-top > div {
    width: 100%;
  }

  .actions {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    justify-content: stretch;
    gap: 8px;
  }

  .actions .btn {
    width: 100%;
    min-height: 44px;
    padding: 11px 10px;
    white-space: normal;
  }

  .check-toggle-btn,
  .undo-btn {
    min-width: 0;
  }

  .title-input {
    width: 100%;
    font-size: 28px;
    line-height: 1.2;
  }

  .selected-info {
    min-height: 0;
    margin-bottom: 10px;
    font-size: 12px;
    line-height: 1.5;
  }

  .content-input {
    min-height: clamp(320px, 50dvh, 520px);
    border-radius: 18px;
    padding: 18px;
    font-size: 16px;
  }

  .content-input.is-empty::before {
    top: 18px;
    left: 18px;
    right: 18px;
  }

  .status-bar {
    flex-wrap: wrap;
    gap: 6px;
    font-size: 12px;
  }

  .context-menu {
    z-index: 11300;
    max-width: calc(100vw - 16px);
  }

  .account-menu {
    left: 8px !important;
    right: 8px !important;
    width: auto;
    min-width: 0;
  }
}

/* ── テンプレートパネル ─────────────────────────────────── */

.templates-overlay {
  position: fixed;
  inset: 0;
  z-index: 10000;
  background: rgba(15, 23, 42, 0.38);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: overlayIn 0.1s ease both;
}

.templates-dialog {
  background: var(--panel);
  border-radius: 24px;
  padding: 24px;
  width: min(calc(100vw - 32px), 480px);
  max-height: calc(100vh - 64px);
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 4px 6px rgba(15, 23, 42, .04), 0 24px 64px rgba(15, 23, 42, .22);
  animation: dialogIn 0.14s ease-out both;
}

.templates-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.templates-title {
  margin: 0;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 0;
}

.templates-close {
  min-width: 32px;
  height: 32px;
  border: 0;
  border-radius: 999px;
  padding: 0 12px;
  background: var(--panel-soft);
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  font-size: 13px;
  font-weight: 800;
  line-height: 1;
}

.templates-close:hover {
  background: var(--line);
  color: var(--text);
}

.templates-hint {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.templates-section {
  display: grid;
  gap: 8px;
}

.templates-section-title {
  margin: 0;
  color: var(--text);
  font-size: 13px;
  font-weight: 800;
}

.templates-save-row {
  display: flex;
  gap: 8px;
}

.templates-save-row input {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  background: var(--panel-soft);
  outline: none;
}

.templates-save-row input:focus {
  border-color: var(--primary);
  background: #fff;
}

.templates-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  overflow-y: auto;
}

.templates-empty {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
  padding: 18px 0;
}

.template-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
}

.template-item.is-previewing {
  border-color: var(--primary);
}

.template-item.is-official {
  border-color: var(--primary-soft);
  background: #f8fbff;
}

.template-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.template-title-line {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 6px;
}

.template-name {
  font-weight: 700;
  font-size: 14px;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.template-badge {
  flex-shrink: 0;
  border-radius: 999px;
  padding: 2px 7px;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 11px;
  font-weight: 800;
  line-height: 1.3;
}

.template-meta {
  font-size: 12px;
  color: var(--muted);
}

.template-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 4px;
  flex-shrink: 0;
}

.template-action-btn {
  min-width: 32px;
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  border: 0;
  border-radius: 10px;
  padding: 8px 9px;
  background: var(--panel-soft);
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.2;
  white-space: nowrap;
}

.template-action-btn:hover {
  background: var(--line);
}

.template-action-btn.is-active {
  background: var(--primary-soft);
  color: var(--primary);
}

.template-action-btn.ctx-danger:hover {
  background: #fee2e2;
}

.template-preview {
  grid-column: 1 / -1;
  display: grid;
  gap: 8px;
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

.template-preview-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.template-preview-label {
  margin: 0;
  color: var(--text);
  font-size: 12px;
  font-weight: 800;
}

.template-preview-count {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.template-preview-tree,
.template-preview-children {
  margin: 0;
  padding: 0;
  list-style: none;
}

.template-preview-tree {
  max-height: 260px;
  overflow-y: auto;
}

.template-preview-children {
  margin-top: 7px;
  margin-left: 12px;
  padding-left: 12px;
  border-left: 2px solid var(--line);
}

.template-preview-node {
  display: grid;
  gap: 3px;
}

.template-preview-node + .template-preview-node {
  margin-top: 8px;
}

.template-preview-title {
  margin: 0;
  color: var(--text);
  font-size: 13px;
  font-weight: 800;
}

.template-preview-content {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.template-rename-input {
  width: 100%;
  border: 1.5px solid var(--primary);
  border-radius: 6px;
  padding: 1px 6px;
  background: #fff;
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  outline: none;
  box-shadow: 0 0 0 3px var(--primary-soft);
}

@media (max-width: 520px) {
  .toast {
    right: 12px;
    bottom: 12px;
    left: 12px;
    max-width: none;
    border-radius: 14px;
  }

  .confirm-dialog {
    width: calc(100vw - 24px);
    border-radius: 18px;
    padding: 22px 18px 18px;
  }

  .confirm-btns {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .confirm-btns .btn {
    width: 100%;
  }

  .lightbox-close {
    top: 12px;
    right: 12px;
  }

  .crop-overlay {
    align-items: stretch;
    padding: 10px;
  }

  .crop-dialog {
    width: 100%;
    max-height: calc(100dvh - 20px);
    margin: auto 0;
    border-radius: 18px;
    padding: 16px;
    overflow: hidden;
  }

  .crop-canvas-wrap {
    max-height: 54dvh;
  }

  .crop-btns {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .crop-btns .btn {
    width: 100%;
  }

  .context-menu {
    max-height: calc(100dvh - 16px);
    overflow-y: auto;
  }

  .ctx-item {
    min-height: 44px;
    padding: 10px 14px;
  }

  .templates-overlay {
    align-items: flex-end;
    padding: 10px;
  }

  .templates-dialog {
    width: 100%;
    max-height: calc(100dvh - 20px);
    border-radius: 18px 18px 0 0;
    padding: 16px;
  }

  .templates-save-row {
    flex-direction: column;
  }

  .templates-save-row .btn {
    width: 100%;
  }

  .templates-list {
    min-height: 0;
  }

  .template-item {
    grid-template-columns: 1fr;
    padding: 10px;
  }

  .template-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    justify-content: stretch;
    gap: 6px;
  }

  .template-action-btn {
    width: 100%;
    min-height: 40px;
  }

  .template-preview-tree {
    max-height: 34dvh;
  }
}

/* ── /テンプレートパネル ─────────────────────────────────── */

/* ── マインドマップ ─────────────────────────────────────── */

.mindmap-overlay {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: flex;
  animation: overlayIn 0.12s ease both;
}

.mindmap-panel {
  width: 100%;
  height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #f8fafc;
}

.mindmap-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.94);
}

.mindmap-title-wrap {
  min-width: 0;
  flex: 1;
}

.mindmap-eyebrow {
  margin: 0 0 3px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.mindmap-title-input {
  width: 100%;
  border: 0;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--text);
  font-size: 24px;
  font-weight: 800;
  outline: none;
}

.mindmap-title-input:focus {
  border-color: var(--primary);
}

.mindmap-head-actions,
.mindmap-tool-grid,
.mindmap-zoom-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.mindmap-body {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
}

.mindmap-tools {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 22px;
  border-right: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(12px);
  overflow-y: auto;
}

.mindmap-tool-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.mindmap-sidebar-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.mindmap-tools .mindmap-tool-grid {
  gap: 8px;
}

.mindmap-tool-btn,
.mindmap-icon-btn {
  border: 0;
  background: var(--panel-soft);
  color: var(--text);
  font-weight: 800;
}

.mindmap-tool-btn {
  min-height: 42px;
  border-radius: 12px;
  padding: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  line-height: 1.2;
}

.mindmap-tools .mindmap-tool-btn {
  min-height: 54px;
  padding: 8px 6px;
  background: var(--primary);
  color: #fff;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  line-height: 1.15;
  box-shadow: 0 10px 20px rgba(37, 99, 235, 0.25);
}

.mindmap-tools .mindmap-tool-btn:hover:not(:disabled) {
  background: #1d4ed8;
}

.mindmap-tools .mindmap-tool-btn .btn-icon {
  font-size: 18px;
}

.mindmap-tools .mindmap-tool-btn .btn-label {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mindmap-tool-btn:hover,
.mindmap-icon-btn:hover {
  background: var(--line);
}

.mindmap-tool-btn.danger {
  background: #fee2e2;
  color: var(--danger);
}

.mindmap-tools .mindmap-tool-btn.danger {
  background: #fee2e2;
  color: var(--danger);
  box-shadow: none;
}

.mindmap-tools .mindmap-tool-btn.danger:hover:not(:disabled) {
  background: #fecaca;
}

.mindmap-tool-btn:disabled,
.mindmap-icon-btn:disabled {
  cursor: not-allowed;
  opacity: 0.42;
}

.mindmap-icon-btn {
  width: 42px;
  height: 42px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.mindmap-list-panel {
  min-width: 260px;
  max-width: 320px;
  max-height: 360px;
  overflow-y: auto;
  padding: 8px 0;
}

.mindmap-context-menu {
  min-width: 236px;
}

.mindmap-link-context-menu {
  min-width: 204px;
}

.mindmap-context-color-panel {
  display: grid;
  gap: 8px;
  padding: 8px 12px 10px;
}

.mindmap-context-color-title {
  margin: 0;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  line-height: 1.2;
}

.mindmap-context-color-row {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
}

.mindmap-context-color-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.mindmap-context-color-palette {
  display: grid;
  grid-template-columns: repeat(4, 30px);
  gap: 6px;
  justify-content: start;
}

.mindmap-context-color-palette .mindmap-color-swatch {
  min-height: 28px;
  border-radius: 10px;
}

.mindmap-context-color-palette .mindmap-color-swatch::before {
  width: 18px;
  height: 18px;
}

.mindmap-context-color-palette.is-link-only {
  grid-template-columns: repeat(4, 30px);
}

.mindmap-list-header {
  margin: 0;
  padding: 4px 16px 8px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.mindmap-list-items {
  list-style: none;
  margin: 0;
  padding: 0;
}

.mindmap-list-item {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 0 8px;
  border-radius: 10px;
}

.mindmap-list-item.is-active {
  background: var(--primary-soft);
}

.mindmap-list-open {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding: 8px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.mindmap-list-item:not(.is-active) .mindmap-list-open:hover {
  background: var(--panel-soft);
}

.mindmap-list-title {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
  font-size: 14px;
  font-weight: 800;
}

.mindmap-list-date {
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
}

.mindmap-list-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
}

.mindmap-list-icon-btn {
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  font-size: 13px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.mindmap-list-icon-btn:hover {
  background: var(--line);
}

.mindmap-list-icon-btn.danger:hover {
  background: #fee2e2;
}

.mindmap-list-icon-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.mindmap-list-rename {
  flex: 1;
  min-width: 0;
  box-sizing: border-box;
  margin: 4px 0;
  border: 1px solid var(--primary);
  border-radius: 8px;
  padding: 7px 8px;
  font-size: 14px;
  font-weight: 800;
  color: var(--text);
  outline: none;
}

.mindmap-field {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.mindmap-field input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  background: var(--panel-soft);
  color: var(--text);
  outline: none;
}

.mindmap-field input:focus {
  border-color: var(--primary);
  background: #fff;
}

.mindmap-color-panel {
  display: grid;
  gap: 8px;
}

.mindmap-section-label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.mindmap-color-rows {
  display: grid;
  gap: 10px;
}

.mindmap-color-row {
  position: relative;
  display: block;
}

.mindmap-color-current {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 8px;
  background: #fff;
  color: var(--text);
  display: grid;
  gap: 8px;
  font-size: 12px;
  font-weight: 800;
  line-height: 1;
}

.mindmap-color-current:not(.is-disabled):hover,
.mindmap-color-current:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.mindmap-color-current.is-disabled {
  opacity: 0.45;
}

.mindmap-color-current-trigger {
  width: 100%;
  min-height: 40px;
  border: 0;
  border-radius: 10px;
  padding: 6px 8px;
  background: transparent;
  color: var(--text);
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 7px;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.mindmap-color-current-trigger:hover:not(:disabled),
.mindmap-color-current-trigger:focus-visible {
  background: var(--panel-soft);
  outline: none;
}

.mindmap-color-current-trigger:disabled {
  cursor: not-allowed;
}

.mindmap-color-current-swatch {
  width: 22px;
  height: 22px;
  border: 1px solid rgba(15, 23, 42, 0.18);
  border-radius: 50%;
  background: var(--mindmap-current-color, #ffffff);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.55);
  flex: 0 0 auto;
}

.mindmap-color-current-label {
  white-space: nowrap;
}

.mindmap-color-current-caret {
  color: var(--muted);
  font-size: 13px;
  transition: transform 0.14s ease;
}

.mindmap-color-current.is-open .mindmap-color-current-caret {
  transform: rotate(180deg);
}

.mindmap-color-palette {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
  justify-content: start;
}

.mindmap-color-palette[hidden] {
  display: none;
}

.mindmap-color-swatch {
  width: 100%;
  min-width: 0;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0;
  background: #fff;
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.06);
  cursor: pointer;
}

.mindmap-color-swatch::before {
  content: "";
  width: 22px;
  height: 22px;
  border: 1px solid rgba(15, 23, 42, 0.16);
  border-radius: 50%;
  background: var(--mindmap-swatch-color, #ffffff);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.42);
  flex: 0 0 auto;
}

.mindmap-color-swatch:hover:not(:disabled),
.mindmap-color-swatch:focus-visible,
.mindmap-color-swatch.is-active {
  border-color: #111827;
  outline: 2px solid rgba(37, 99, 235, 0.28);
  outline-offset: 2px;
}

.mindmap-color-swatch:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.mindmap-color-input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.mindmap-zoom-row {
  justify-content: space-between;
  padding: 8px;
  border-radius: 14px;
  background: var(--panel-soft);
}

.mindmap-zoom-label {
  min-width: 58px;
  text-align: center;
  color: var(--text);
  font-size: 13px;
  font-weight: 800;
}

.mindmap-status {
  margin: auto 0 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  line-height: 1.5;
}

.mindmap-canvas {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background:
    linear-gradient(rgba(148, 163, 184, 0.18) 1px, transparent 1px),
    linear-gradient(90deg, rgba(148, 163, 184, 0.18) 1px, transparent 1px),
    #f8fafc;
  background-size: 32px 32px;
  cursor: grab;
  touch-action: none;
}

.mindmap-canvas.is-panning {
  cursor: grabbing;
}

.mindmap-scene {
  position: absolute;
  top: 0;
  left: 0;
  width: 2600px;
  height: 1800px;
  transform-origin: 0 0;
}

.mindmap-svg,
.mindmap-nodes {
  position: absolute;
  inset: 0;
  width: 2600px;
  height: 1800px;
}

.mindmap-svg {
  overflow: visible;
  pointer-events: none;
}

.mindmap-link {
  fill: none;
  stroke: var(--mindmap-link-color, #93c5fd);
  stroke-width: 4;
  stroke-linecap: round;
  pointer-events: none;
}

.mindmap-link-hit {
  fill: none;
  stroke: transparent;
  stroke-width: 18;
  stroke-linecap: round;
  pointer-events: stroke;
  cursor: context-menu;
}

.mindmap-node {
  position: absolute;
  width: 172px;
  min-height: 54px;
  border: 1px solid var(--mindmap-node-border, #3b82f6);
  border-radius: 16px;
  padding: 10px 12px;
  background: var(--mindmap-node-fill, #ffffff);
  color: var(--mindmap-node-text, var(--text));
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-size: 14px;
  font-weight: 800;
  line-height: 1.35;
  white-space: normal;
  word-break: break-word;
  box-shadow: 0 10px 22px rgba(15, 23, 42, 0.12);
  transform: translate(-50%, -50%);
  cursor: grab;
  touch-action: none;
}

.mindmap-node.is-dragging {
  cursor: grabbing;
  z-index: 5;
}

.mindmap-node.is-root {
  min-height: 66px;
  background: var(--mindmap-node-fill, var(--primary));
  color: var(--mindmap-node-text, #fff);
  border-color: var(--mindmap-node-border, var(--primary));
  font-size: 15px;
}

.mindmap-node.is-selected {
  outline: 4px solid rgba(37, 99, 235, 0.2);
  border-color: var(--mindmap-node-border, var(--primary));
}

.mindmap-node:hover {
  border-color: var(--mindmap-node-border, var(--primary));
}

.mindmap-node-title {
  display: block;
  max-width: 100%;
}

.mindmap-node-count {
  position: absolute;
  top: -8px;
  right: -8px;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border: 2px solid #fff;
  border-radius: 999px;
  background: #0f766e;
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
  box-shadow: 0 4px 10px rgba(15, 118, 110, 0.22);
  pointer-events: none;
}

.mindmap-node.is-editing {
  visibility: hidden;
}

.mindmap-node-edit {
  position: absolute;
  width: 172px;
  min-height: 54px;
  border: 1px solid var(--primary);
  border-radius: 16px;
  padding: 10px 12px;
  background: #ffffff;
  color: var(--text);
  font-size: 14px;
  font-weight: 800;
  line-height: 1.35;
  text-align: center;
  transform: translate(-50%, -50%);
  z-index: 6;
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.2);
}

.mindmap-node-edit.is-root {
  min-height: 66px;
  font-size: 15px;
  background: var(--primary);
  color: #fff;
}

.mindmap-add-child-btn {
  position: absolute;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: #0f766e;
  font-size: 16px;
  font-weight: 700;
  line-height: 1;
  padding: 0;
  display: grid;
  place-items: center;
  transform: translate(-50%, -50%);
  box-shadow: none;
  cursor: pointer;
  isolation: isolate;
  z-index: 4;
}

.mindmap-add-child-btn::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 24px;
  height: 24px;
  border: 1px solid rgba(15, 118, 110, 0.36);
  border-radius: 50%;
  background: #ecfdf5;
  box-shadow: 0 2px 6px rgba(15, 118, 110, 0.18);
  pointer-events: none;
  transform: translate(-50%, -50%);
  transition: background 0.12s ease, border-color 0.12s ease, box-shadow 0.12s ease, transform 0.12s ease;
  z-index: -1;
}

.mindmap-add-child-btn:hover,
.mindmap-add-child-btn:focus-visible {
  color: #fff;
}

.mindmap-add-child-btn:hover::before,
.mindmap-add-child-btn:focus-visible::before {
  background: #0f766e;
  border-color: #0f766e;
  box-shadow: 0 4px 12px rgba(15, 118, 110, 0.25);
  transform: translate(-50%, -50%) scale(1.04);
}

.mindmap-add-child-btn:focus-visible {
  outline: 2px solid rgba(15, 118, 110, 0.28);
  outline-offset: -4px;
}

@media (max-width: 860px) {
  .mindmap-head {
    align-items: flex-start;
    padding: calc(12px + env(safe-area-inset-top)) 12px 12px;
  }

  .mindmap-title-input {
    font-size: 20px;
  }

  .mindmap-list-panel {
    left: 8px !important;
    right: 8px !important;
    width: auto;
    min-width: 0;
    max-width: none;
  }

  .mindmap-body {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr);
  }

  .mindmap-tools {
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding: 10px 12px;
    max-height: 260px;
  }

  .mindmap-tool-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .mindmap-tool-btn {
    min-height: 44px;
    padding: 8px 6px;
    flex-direction: column;
    gap: 3px;
    font-size: 11px;
  }

  .mindmap-field {
    gap: 5px;
  }

  .mindmap-node {
    width: 150px;
    min-height: 50px;
    border-radius: 14px;
    font-size: 13px;
  }

  .mindmap-node.is-root {
    min-height: 58px;
    font-size: 14px;
  }

  .mindmap-node-edit {
    width: 150px;
    min-height: 50px;
    border-radius: 14px;
    font-size: 13px;
  }

  .mindmap-node-edit.is-root {
    min-height: 58px;
    font-size: 14px;
  }
}

@media (max-width: 520px) {
  .mindmap-head-actions {
    gap: 6px;
  }

  .mindmap-head .mindmap-tool-btn {
    width: 48px;
    min-height: 42px;
  }

  .mindmap-head .mindmap-tool-btn .btn-label {
    display: none;
  }

  .mindmap-tool-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* ── /マインドマップ ────────────────────────────────────── */

/* ── アカウント認証 ───────────────────────────────────────── */

.auth-overlay {
  display: flex;
  position: fixed;
  inset: 0;
  z-index: 12000;
  align-items: center;
  justify-content: center;
  background: rgba(15, 23, 42, 0.32);
}

.auth-dialog {
  background: var(--panel);
  border-radius: 24px;
  padding: 32px 28px 28px;
  width: min(380px, calc(100vw - 40px));
  box-shadow:
    0 4px 6px rgba(15, 23, 42, 0.04),
    0 24px 64px rgba(15, 23, 42, 0.16);
  animation: dialogIn 0.2s cubic-bezier(0.34, 1.4, 0.64, 1) both;
}

.auth-dialog.is-verifying {
  width: min(560px, calc(100vw - 32px));
}

.auth-eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

#authTitle {
  margin: 0 0 20px;
  font-size: 24px;
  letter-spacing: 0;
}

.auth-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 20px;
  padding: 4px;
  background: var(--panel-soft);
  border-radius: 14px;
}

.auth-tab {
  flex: 1;
  padding: 9px 0;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
  transition: background 0.15s, color 0.15s;
}

.auth-tab.active {
  background: var(--panel);
  color: var(--text);
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.08);
}

.auth-note {
  margin: -8px 0 18px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  line-height: 1.6;
}

#authForm {
  display: grid;
  gap: 14px;
}

.auth-field {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.auth-field input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  background: var(--panel-soft);
  outline: none;
  font-size: 15px;
  color: var(--text);
}

.auth-field input:focus {
  border-color: var(--primary);
  background: #fff;
}

.auth-remember {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.auth-remember input {
  width: 16px;
  height: 16px;
}

.auth-submit {
  width: 100%;
  text-align: center;
  padding: 13px 0;
  font-size: 15px;
}

.auth-error {
  margin: 0;
  padding: 10px 14px;
  border-radius: 12px;
  background: #fee2e2;
  color: var(--danger);
  font-size: 13px;
  font-weight: 600;
  line-height: 1.5;
}

.auth-info {
  margin: 0;
  padding: 10px 14px;
  border-radius: 12px;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 13px;
  font-weight: 600;
  line-height: 1.5;
}

.auth-link {
  display: block;
  margin: 14px auto 0;
  border: 0;
  background: transparent;
  color: var(--primary);
  font-size: 13px;
  font-weight: 700;
  text-align: center;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.auth-not-configured {
  display: grid;
  gap: 10px;
  padding: 16px;
  border-radius: 14px;
  background: #fef3c7;
  color: #92400e;
  font-size: 13px;
  line-height: 1.6;
}

.auth-not-configured p {
  margin: 0;
}

.auth-not-configured code {
  padding: 1px 5px;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.08);
  font-size: 12px;
}

.auth-verify {
  display: grid;
  gap: 18px;
  text-align: center;
}

.auth-verify-avatar {
  width: 86px;
  height: 86px;
  display: grid;
  place-items: center;
  margin: 4px auto 0;
  border-radius: 50%;
  background: #1f4979;
  color: #dbeafe;
  font-size: 40px;
  line-height: 1;
}

.auth-verify-name {
  margin: 0;
  color: #1f3b66;
  font-size: 22px;
  font-weight: 800;
  line-height: 1.25;
}

.auth-verify-email {
  margin: -14px 0 0;
  color: var(--muted);
  font-size: 15px;
  word-break: break-all;
}

.auth-verify-alert {
  display: grid;
  gap: 14px;
  border: 1.5px solid #facc15;
  border-radius: 14px;
  padding: 18px;
  background: #fef3c7;
  color: #7c5700;
  text-align: left;
}

.auth-verify-alert p {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
  line-height: 1.7;
}

.auth-verify-resend,
.auth-verify-refresh,
.auth-verify-logout {
  width: 100%;
  border-radius: 999px;
  padding: 15px 18px;
  font-size: 16px;
  font-weight: 800;
  text-align: center;
}

.auth-verify-resend {
  border: 0;
  background: #eab308;
  color: #fff;
}

.auth-verify-help {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  line-height: 1.7;
}

.auth-verify-refresh {
  background: #1f3b66;
  color: #fff;
}

.auth-verify-logout {
  background: #ef4444;
}

.auth-verify-delete {
  width: fit-content;
  margin: 2px auto 0;
  border: 0;
  background: transparent;
  color: var(--danger);
  font-size: 14px;
  font-weight: 800;
  text-decoration: underline;
  text-underline-offset: 4px;
}

@media (max-width: 520px) {
  .auth-overlay {
    align-items: stretch;
    padding: 12px;
    overflow-y: auto;
  }

  .auth-dialog {
    width: 100%;
    max-height: calc(100dvh - 24px);
    margin: auto 0;
    border-radius: 18px;
    padding: 24px 18px;
    overflow-y: auto;
  }

  .auth-dialog.is-verifying {
    width: 100%;
    padding: 24px 18px;
  }

  .auth-verify-alert {
    padding: 14px;
  }

  .auth-verify-resend,
  .auth-verify-refresh,
  .auth-verify-logout {
    font-size: 15px;
  }
}

/* ── /アカウント認証 ──────────────────────────────────────── */

/* ── アカウントメニュー ───────────────────────────────────── */

.account-menu {
  min-width: 240px;
  z-index: 10020;
}

.account-menu-name {
  padding: 10px 16px 0;
  color: var(--text);
  font-size: 14px;
  font-weight: 800;
  word-break: break-all;
}

.account-menu-email {
  padding: 2px 16px 2px;
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
  word-break: break-all;
}

.account-menu-status {
  padding: 2px 16px 8px;
  color: var(--muted);
  font-size: 12px;
}

.account-menu-name-edit {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 4px 16px 10px;
}

.account-menu-name-edit input {
  width: 100%;
  box-sizing: border-box;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 7px 10px;
  background: var(--panel-soft);
  outline: none;
  font-size: 13px;
  color: var(--text);
}

.account-menu-name-edit input:focus {
  border-color: var(--primary);
  background: #fff;
}

.account-menu-name-actions {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
}

.account-menu-name-actions .btn-sm {
  padding: 6px 12px;
  border-radius: 10px;
  font-size: 12px;
}

/* ── /アカウントメニュー ──────────────────────────────────── */
