: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;
}

.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: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

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

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

.icon-btn {
  width: 42px;
  height: 42px;
  border: 0;
  border-radius: 14px;
  background: var(--primary);
  color: #fff;
  font-size: 26px;
  line-height: 1;
  box-shadow: 0 10px 20px rgba(37, 99, 235, 0.25);
}

.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 34px;   /* 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;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
}

.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.04em;
  outline: none;
}

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

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

.btn {
  border: 0;
  border-radius: 13px;
  padding: 11px 14px;
  background: var(--text);
  color: #fff;
  font-weight: 700;
}

.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;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  color: #fff;
  font-size: 18px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  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.02em;
}

.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: 11000;
  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.06em;
  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);
}

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

/* 子メモを同じ親メモ内の先頭/末尾へ移動するドロップゾーン（ドラッグ中のみ表示） */
.root-drop-zone {
  margin: 6px 4px 4px;
  padding: 7px 10px;
  border: 1.5px dashed transparent;
  border-radius: 10px;
  text-align: center;
  font-size: 0.72rem;
  color: transparent;
  cursor: default;
  pointer-events: none;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}

.sibling-edge-drop-zone + .sibling-edge-drop-zone {
  margin-top: 2px;
}

/* ドラッグ操作中はゾーンを表示してインタラクティブにする */
.is-dragging .root-drop-zone {
  border-color: var(--line);
  color: var(--muted);
  pointer-events: all;
}

.root-drop-zone.drag-target {
  border-color: var(--primary) !important;
  background: var(--primary-soft);
  color: var(--primary) !important;
}

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

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

.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;
  }

  .sidebar {
    min-height: 45vh;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .editor {
    min-height: 55vh;
    padding: 22px;
  }

  .editor-top {
    flex-direction: column;
  }

  .actions {
    justify-content: flex-start;
  }

  .title-input {
    font-size: 28px;
  }
}

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

.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;
}

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

.templates-close {
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 50%;
  background: var(--panel-soft);
  color: var(--muted);
  font-size: 15px;
  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-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;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  border: 0;
  border-radius: 10px;
  padding: 0 9px;
  background: var(--panel-soft);
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
}

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

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

.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) {
  .templates-dialog {
    padding: 18px;
  }

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

  .template-actions {
    justify-content: flex-start;
  }
}

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

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

.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.08em;
  text-transform: uppercase;
}

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

.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-dialog.is-verifying {
    padding: 26px 20px 24px;
  }

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

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

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

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

.account-menu-email {
  padding: 10px 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;
}

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