*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* ---- Toolbar（リボン風） ---- */
/* 1段目：アプリ名とボード名 / 2段目：グループ名 + ボタン。
   高さは --toolbar-h にまとめてあり、#canvas とポップオーバーの位置がこれに追随する
   （JS 側は #toolbar の実際の高さを見るので、ここを変えるだけでよい）。 */
:root {
  --toolbar-h: 52px;
  /* 図形パレットの幅。閉じているときは 0 で、#canvas がその分だけ広がる
     （座標変換は #canvas の実寸を見ているので、これだけでズレなく追随する） */
  --palette-w: 0px;
}

body.palette-open {
  --palette-w: 208px;
}

#toolbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--toolbar-h);
  background: #1a1b26;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 12px;
  z-index: 100;
  box-shadow: 0 1px 0 rgba(255,255,255,0.07), 0 2px 8px rgba(0,0,0,0.4);
}

/* アプリ名とボード名。グループと同じ行に置く */
.ribbon-lead {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: none;
}

.app-title {
  font-size: 14px;
  font-weight: 700;
  color: #c0caf5;
  letter-spacing: -0.3px;
  margin-right: 8px;
  user-select: none;
}

/* ---- ボード名 ---- */
#board-name {
  color: #a9b1d6;
  font-size: 13px;
  padding: 4px 8px;
  border-radius: 6px;
  cursor: text;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  user-select: none;
}

#board-name:hover {
  background: #2a2b3d;
  color: #c0caf5;
}

#board-name-input {
  width: 200px;
  background: #12131c;
  border: 1px solid #3a3b50;
  border-radius: 6px;
  padding: 4px 8px;
  color: #c0caf5;
  font-size: 13px;
  font-family: inherit;
  outline: none;
}

#board-name-input:focus {
  border-color: #7aa2f7;
}

#board-name-input[hidden] {
  display: none;
}

/* ---- グループ ---- */
/* はみ出しは src/ribbon.js が「⋯」メニューへ退避させて解消するが、
   計測前の一瞬などに崩れないよう overflow: hidden も掛けておく */
.ribbon-groups {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 5px;
  /* 枠の上辺に重ねたグループ名がはみ出すぶんの余白。
     overflow: hidden で切られないよう、ここで場所を確保しておく */
  padding-top: 8px;
  min-width: 0;
  overflow: hidden;
}

/* グループはボタンを枠でぐるっと囲み、その上に小さくグループ名を出す。
   縮ませない：横幅が足りない分は src/ribbon.js が「⋯」へ退避させて解消する
   （flex で縮むとボタンの文字が潰れ、幅の実測値も当てにならなくなる） */
.ribbon-group {
  position: relative;
  display: flex;
  align-items: center;
  flex: none;
  border: 1px solid #7a83b8;
  border-radius: 8px;
  padding: 3px 9px;
}

/* グループ名は枠線の上辺に重ねる（fieldset の legend と同じ見せ方）。
   ツールバーと同じ背景を敷いて、文字の下の線を隠している */
.ribbon-group-label {
  position: absolute;
  top: -7px;
  left: 50%;
  transform: translateX(-50%);
  background: #1a1b26;
  padding: 0 5px;
  font-size: 10px;
  line-height: 12px;
  color: #c0caf5;
  letter-spacing: 0.5px;
  white-space: nowrap;
  user-select: none;
}

.ribbon-group-items {
  display: flex;
  align-items: center;
  gap: 5px;
  flex: none;
}

/* ---- ボタン ---- */
/* hidden を付けた要素は必ず消えるようにする。
   #toolbar button の display 指定のほうが [hidden] より詳細度が高く、
   「⋯」を hidden にしても消えない問題があったため */
#toolbar [hidden] {
  display: none !important;
}

#toolbar button, .toolbar-btn {
  display: inline-flex;
  align-items: center;
  height: 24px;
  padding: 0 10px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  background: #2a2b3d;
  color: #a9b1d6;
  transition: background 0.12s, color 0.12s;
  user-select: none;
  white-space: nowrap;
}

#toolbar button:hover, .toolbar-btn:hover {
  background: #3a3b50;
  color: #c0caf5;
}

#btn-add-sticky {
  background: #ffd700 !important;
  color: #1a1b26 !important;
  font-weight: 600 !important;
}

#btn-add-sticky:hover {
  background: #f0c800 !important;
}

#btn-import { display: none; }
#btn-image { display: none; }

#btn-shapes[aria-pressed="true"],
#btn-connector.active,
#btn-draw.active {
  background: #4a90e2 !important;
  color: #fff !important;
}

#toolbar button:disabled {
  opacity: 0.35;
  cursor: default;
  background: #2a2b3d !important;
  color: #6b7280 !important;
}

#toolbar button:disabled:hover {
  background: #2a2b3d !important;
  color: #6b7280 !important;
}

#zoom-label {
  min-width: 40px;
  text-align: center;
  font-size: 12px;
  font-weight: 600;
  color: #a9b1d6;
  user-select: none;
}

/* ---- グループのはみ出し分を入れる「⋯」とそのメニュー ---- */

.ribbon-more {
  padding: 0 8px !important;
  font-size: 14px !important;
}

.ribbon-more[hidden] { display: none; }

/* ツールバーから下りてくるメニューなので、白い #context-menu ではなくツールバーと同じ暗色にする */
.ribbon-menu {
  position: fixed;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 160px;
  background: #24252f;
  border: 1px solid #3a3b50;
  border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.45);
  padding: 4px;
  z-index: 200;
}

.ribbon-menu[hidden] { display: none; }

/* メニューの中では横並び用の見た目をやめ、左揃えの一覧にする。
   #btn-add-sticky などの ID 指定 + !important に勝つ必要があるので #toolbar を前置している */
#toolbar .ribbon-menu button,
#toolbar .ribbon-menu .toolbar-btn {
  width: 100%;
  height: auto;
  font-size: 13px;
  text-align: left;
  background: none !important;
  color: #c0caf5 !important;
  font-weight: 500 !important;
  padding: 8px 12px;
  border-radius: 5px;
}

#toolbar .ribbon-menu button:hover,
#toolbar .ribbon-menu .toolbar-btn:hover {
  background: #3a3b50 !important;
}

#toolbar .ribbon-menu button:disabled,
#toolbar .ribbon-menu button:disabled:hover {
  background: none !important;
  color: #6b7280 !important;
}

/* 選択中コネクタの青は状態表示なのでメニュー内でも残す */
#toolbar .ribbon-menu #btn-shapes[aria-pressed="true"],
#toolbar .ribbon-menu #btn-connector.active,
#toolbar .ribbon-menu #btn-draw.active {
  background: #4a90e2 !important;
  color: #fff !important;
}

#toolbar .ribbon-menu #zoom-label {
  padding: 8px 12px;
  text-align: left;
}

/* ---- Canvas ---- */
/* ---- 図形パレット（部品置き場） ---- */
/* 「挿入」の「◇ 図形」で開閉する左のサイドパネル。中身は src/shapes.js のカタログから生成する。 */

/* display: flex が UA の hidden（display:none）に勝ってしまうので、閉じているときを明示する */
#shape-palette[hidden] {
  display: none;
}

#shape-palette {
  position: fixed;
  top: var(--toolbar-h);
  left: 0;
  width: var(--palette-w);
  height: calc(100% - var(--toolbar-h));
  background: #ffffff;
  border-right: 1px solid #e2e2ea;
  box-shadow: 2px 0 8px rgba(0,0,0,0.06);
  display: flex;
  flex-direction: column;
  z-index: 50;
  user-select: none;
}

.palette-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 8px 8px 12px;
  border-bottom: 1px solid #ececf2;
  font-size: 13px;
  font-weight: 600;
  color: #44454f;
  flex: none;
}

#palette-close {
  border: none;
  background: transparent;
  color: #8a8b96;
  font-size: 16px;
  line-height: 1;
  padding: 2px 6px;
  border-radius: 6px;
  cursor: pointer;
}

#palette-close:hover {
  background: #f0f0f5;
  color: #44454f;
}

#palette-body {
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px 16px;
}

.palette-category {
  font-size: 11px;
  color: #8a8b96;
  padding: 10px 4px 4px;
}

.palette-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
}

.palette-item {
  border: 1px solid transparent;
  background: transparent;
  border-radius: 6px;
  padding: 4px 2px 3px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  color: #6b6c78;
}

.palette-item:hover {
  background: #f2f6fd;
  border-color: #c6dcf7;
}

.palette-item svg {
  display: block;
}

/* サムネイルは実際の図形と同じ Shapes.pathD() で描く */
.palette-item svg path {
  fill: #ffffff;
  fill-rule: evenodd;
  stroke: #4a90e2;
  stroke-width: 1.5;
}

.palette-item-label {
  font-size: 9px;
  line-height: 1.2;
  text-align: center;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#canvas {
  position: fixed;
  top: var(--toolbar-h); left: var(--palette-w);
  width: calc(100% - var(--palette-w));
  height: calc(100% - var(--toolbar-h));
  background: #f5f5f8;
  cursor: default;
  user-select: none;
}

#canvas.connecting,
#canvas.drawing {
  cursor: crosshair;
}

/* Spaceキー押下中はパン待機カーソル、実際にドラッグ中はグラブ中カーソル */
#canvas.pan-ready {
  cursor: grab;
}

#canvas.panning {
  cursor: grabbing;
}

/* ---- Empty state ---- */
#empty-hint {
  pointer-events: none;
  opacity: 0.4;
}

/* ---- Sticky note ---- */
.sticky-bg {
  cursor: grab;
  filter: drop-shadow(2px 3px 6px rgba(0,0,0,0.18));
  transition: filter 0.1s;
}

.node.selected .sticky-bg {
  stroke: #4a90e2;
  stroke-width: 2.5;
  filter: drop-shadow(2px 3px 10px rgba(74,144,226,0.35));
}

.sticky-fo {
  pointer-events: none;
  overflow: visible;
}

/* 文字divを包む flex ラッパー。縦位置（上/中/下）は align-items をインラインで指定する */
.sticky-text-wrap {
  width: 100%;
  height: 100%;
  display: flex;
  overflow: hidden;
}

.sticky-text {
  width: 100%;
  max-height: 100%;
  padding: 10px 12px;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 14px;
  line-height: 1.55;
  color: #333;
  word-break: break-word;
  outline: none;
  overflow: hidden;
  cursor: inherit;
  user-select: none;
}

.sticky-text[contenteditable="true"] {
  user-select: text;
  cursor: text;
  overflow: auto;
}

/* ---- Shape ---- */
.shape-bg {
  cursor: grab;
  filter: drop-shadow(2px 3px 6px rgba(0,0,0,0.14));
  transition: filter 0.1s;
}

.node.selected .shape-bg {
  stroke-width: 3 !important;
  filter: drop-shadow(0 0 8px rgba(74,144,226,0.45));
}

.shape-fo {
  pointer-events: none;
  overflow: visible;
}

.shape-text-wrap {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  /* 横位置は内側の .shape-text の text-align で制御する */
}

.shape-text {
  width: 100%;
  text-align: center;
  padding: 6px 10px;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 14px;
  line-height: 1.4;
  color: #333;
  word-break: break-word;
  outline: none;
  user-select: none;
  cursor: inherit;
  min-width: 4px;
}

.shape-text[contenteditable="true"] {
  user-select: text;
  cursor: text;
}

/* ---- Image ---- */
.image-el {
  cursor: grab;
  filter: drop-shadow(2px 3px 6px rgba(0,0,0,0.14));
}

.image-frame {
  pointer-events: none;
}

.node.selected .image-frame {
  stroke: #4a90e2;
  stroke-width: 2.5;
}

/* ---- 手書き（フリーハンド）の線 ---- */
/* 線そのもの（.draw-path）の色・太さ・線端は src/view.js が要素の属性として直接付ける。
   書き出した .svg をブラウザで開いたときも同じ見た目になるようにするため、ここには
   見た目に必須の指定を置かない（io.js の EXPORT_CSS へ転記する必要がなくなる）。
   .draw-path に non-scaling-stroke を付けていないのも意図的で、手書きの線はボード上の
   実体なので、ズームや拡大縮小では線幅も一緒に変わるのが正しい。 */
.draw-path {
  fill: none;
  pointer-events: none;
}

/* クリック判定を広げるための透明な太い線（コネクタの .edge-hit と同じ役割）。
   実際の太さは線の太さに応じて src/view.js が設定する */
.draw-hit {
  fill: none;
  stroke: transparent;
  pointer-events: stroke;
  cursor: grab;
}

/* 描画中のプレビュー線。確定前なのでクリック対象にしない */
.draw-temp {
  pointer-events: none;
}

/* 選択枠は線に直接引けないので、画像ノードと同じく外接矩形に出す */
.draw-frame {
  pointer-events: none;
}

.node.selected .draw-frame {
  stroke: #4a90e2;
  stroke-width: 2.5;
}

/* ---- Text node（背景・枠なしテキスト） ---- */
.text-frame {
  fill: transparent; /* 背景は見せないが、クリック・ドラッグの当たり判定として必要 */
  cursor: grab;
  stroke: transparent;
  stroke-width: 1;
}

/* 非選択時：ホバー中だけ薄い破線枠を出して位置がわかるようにする */
.node.text-node:hover .text-frame {
  stroke: #999;
  stroke-dasharray: 4 3;
}

/* 選択時：他ノードと同じ選択枠を表示する（ホバーの破線より優先） */
.node.selected .text-frame {
  stroke: #4a90e2 !important;
  stroke-width: 2;
  stroke-dasharray: none !important;
}

.text-fo {
  pointer-events: none;
  overflow: visible;
}

.text-content {
  width: 100%;
  height: 100%;
  padding: 4px 6px;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  line-height: 1.4;
  text-align: left;
  word-break: break-word;
  outline: none;
  overflow: hidden;
  cursor: inherit;
  user-select: none;
}

.text-content[contenteditable="true"] {
  user-select: text;
  cursor: text;
  overflow: auto;
}

/* ---- Resize handles ---- */
.resize-handle {
  display: none;
  fill: #fff;
  stroke: #4a90e2;
  stroke-width: 1.5;
}

/* ズームで拡大縮小されてもストローク（線）幅は画面上一定に保つ。
   ハンドル自体の大きさや選択枠の太さがズームで変わるのは許容する。 */
.sticky-bg, .shape-bg, .image-frame, .text-frame, .resize-handle, .edge-line, .edge-hit,
.draw-frame, .draw-hit {
  vector-effect: non-scaling-stroke;
}

/* リサイズハンドルは単一選択時のみ表示する（複数選択時はグループ移動の誤操作を防ぐ） */
.node.solo-selected .resize-handle {
  display: block;
}

/* ---- リンクバッジ（ノード右上の🔗マーク） ---- */
/* クリックでリンクを開く小さなボタン。ノード本体のドラッグ・選択とは別扱いにする */
.link-badge {
  font-size: 13px;
  cursor: pointer;
  user-select: none;
}

/* 絵文字だけでは的が小さいので、透明な矩形を重ねて当たり判定を広げる。
   fill:none のままでも当たるよう pointer-events: all を指定する */
.link-badge-hit {
  fill: none;
  pointer-events: all;
}

.link-badge:hover text {
  opacity: 0.6;
}

/* ---- 矩形選択（ラバーバンド） ---- */
.rubber-band {
  fill: rgba(74, 144, 226, 0.08);
  stroke: #4a90e2;
  stroke-width: 1;
  stroke-dasharray: 4 3;
  vector-effect: non-scaling-stroke;
  pointer-events: none;
}

/* グループ選択中に出す破線枠。選択を示すだけの表示なのでクリック対象にはしない
   （グループはメンバーのノードをクリックして選ぶ） */
.group-frame {
  fill: none;
  stroke: #4a90e2;
  stroke-width: 1.5;
  stroke-dasharray: 8 5;
  vector-effect: non-scaling-stroke;
  pointer-events: none;
}

/* ---- コネクタ（エッジ） ---- */
#edges-layer {
  cursor: default;
}

.edge-line {
  fill: none;
  pointer-events: none;
}

/* クリック判定を広げるための透明な太い線 */
.edge-hit {
  fill: none;
  stroke: transparent;
  stroke-width: 12;
  pointer-events: stroke;
  cursor: pointer;
}

/* 選択中は太い当たり判定パス（.edge-hit）を淡い青のハイライトとして見せる。
   線自体（.edge-line）の色・太さは変えない（スタイル変更結果が選択中も見えるようにするため） */
.edge.selected .edge-hit {
  stroke: rgba(74, 144, 226, 0.28);
}

/* ---- 右クリックメニュー（重なり順の変更・削除） ---- */
#context-menu {
  position: fixed;
  display: none;
  flex-direction: column;
  min-width: 160px;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.22);
  padding: 4px;
  z-index: 200;
  user-select: none;
}

#context-menu.open {
  display: flex;
}

#context-menu button {
  border: none;
  background: none;
  text-align: left;
  padding: 8px 12px;
  font-size: 13px;
  border-radius: 5px;
  cursor: pointer;
  color: #333;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

#context-menu button:hover {
  background: #f0f0f5;
}

.context-menu-sep {
  height: 1px;
  background: #eee;
  margin: 4px 2px;
}

/* ---- リンクのURLを表示するポップオーバー ---- */
#link-popover {
  position: fixed;
  display: none;
  align-items: center;
  gap: 6px;
  max-width: 340px;
  background: #1a1b26;
  border-radius: 8px;
  padding: 7px 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.28);
  z-index: 150;
  font-size: 13px;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

#link-popover.open {
  display: flex;
}

#link-popover a {
  color: #7aa2f7;
  text-decoration: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 220px;
}

#link-popover a:hover {
  text-decoration: underline;
}

#link-popover button {
  flex: none;
  border: none;
  background: none;
  color: #a9b1d6;
  cursor: pointer;
  font-size: 12px;
  padding: 3px 6px;
  border-radius: 5px;
  white-space: nowrap;
  font-family: inherit;
}

#link-popover button:hover {
  background: #3a3b50;
  color: #fff;
}

/* 編集モード（URL入力欄 + 保存/キャンセル/削除）は表示モードより横幅が必要なため広げる */
#link-popover.editing {
  max-width: 420px;
}

#link-popover input#link-input {
  flex: 1;
  min-width: 200px;
  background: #12131c;
  border: 1px solid #3a3b50;
  border-radius: 5px;
  padding: 5px 8px;
  color: #c0caf5;
  font-size: 13px;
  font-family: inherit;
  outline: none;
}

#link-popover input#link-input:focus {
  border-color: #7aa2f7;
}

/* ---- リンクバッジのツールチップ（ホバー中にURLを表示する） ---- */
/* ポップオーバーと同じ見た目に揃える。ホバー中に出すだけなのでクリックは受け取らない */
#link-tooltip {
  position: fixed;
  display: none;
  max-width: 360px;
  background: #1a1b26;
  color: #c0caf5;
  border-radius: 6px;
  padding: 5px 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.28);
  z-index: 160;
  font-size: 12px;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
}

#link-tooltip.open {
  display: block;
}

/* ---- テキストスタイル編集ポップオーバー（文字サイズ・色・太字・横位置） ---- */
#text-style-popover {
  position: fixed;
  display: none;
  flex-direction: column; /* 「付箋」「文字」の行を縦に並べる */
  align-items: stretch;
  gap: 4px;
  background: #1a1b26;
  border-radius: 8px;
  padding: 6px 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.28);
  z-index: 150;
  font-size: 12px;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

#text-style-popover.open {
  display: flex;
}

/* ポップオーバーの1行。行頭のラベルで「付箋の色」と「文字設定」を見分けられるようにする */
.tsp-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.tsp-row-label {
  flex: none;
  min-width: 28px;
  font-size: 11px;
  color: #7a82a6;
  user-select: none;
}

.tsp-group {
  display: flex;
  align-items: center;
  gap: 2px;
}

.tsp-sep {
  width: 1px;
  height: 18px;
  background: #3a3b50;
  margin: 0 2px;
  flex: none;
}

#text-style-popover button {
  flex: none;
  border: none;
  background: none;
  color: #a9b1d6;
  cursor: pointer;
  border-radius: 5px;
  padding: 4px 6px;
  font-size: 12px;
  line-height: 1;
  font-family: inherit;
}

#text-style-popover button:not(.tsp-swatch):hover {
  background: #3a3b50;
  color: #fff;
}

#text-style-popover button:disabled {
  opacity: 0.35;
  cursor: default;
}

#text-style-popover button.active {
  background: #4a90e2;
  color: #fff;
}

.tsp-size-label {
  min-width: 18px;
  text-align: center;
  color: #c0caf5;
  font-size: 12px;
}

.tsp-swatch {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  padding: 0;
  border: 2px solid transparent;
  box-sizing: border-box;
}

.tsp-swatch:hover {
  border-color: #7aa2f7;
}

.tsp-swatch-white {
  border-color: #55566e;
}

.tsp-swatch.active {
  border-color: #4a90e2;
}

/* 付箋の背景色スウォッチは文字色（丸）と区別するため角丸四角にする */
.tsp-swatch-bg {
  border-radius: 4px;
}

.tsp-bold {
  font-weight: 700;
}

.tsp-align svg {
  display: block;
}

.tsp-line svg, .tsp-arrow svg {
  display: block;
}

/* 付箋の縦横比ボタン（1:1 / 3:2） */
.tsp-aspect {
  font-size: 11px;
  padding: 4px 6px;
  letter-spacing: 0.3px;
}

/* ---- 通知トースト（容量超過・読み込み失敗などを alert の代わりに表示） ---- */
#toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  display: none;
  background: #1a1b26;
  color: #fff;
  padding: 10px 16px;
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.28);
  font-size: 13px;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  z-index: 200;
  max-width: 80vw;
}

#toast.open {
  display: block;
}

/* ---- ウェルカム画面 ---- */
#welcome-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 300;
  padding: 16px;
}

#welcome-overlay[hidden] {
  display: none;
}

#welcome-dialog {
  background: #fff;
  border-radius: 10px;
  max-width: 560px;
  width: 100%;
  max-height: calc(100vh - 32px);
  overflow: auto;
  padding: 22px 26px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.28);
  color: #333;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 14px;
  line-height: 1.6;
}

#welcome-dialog h2 {
  margin: 0 0 4px;
  font-size: 18px;
}

#welcome-dialog h3 {
  font-size: 14px;
  margin-top: 18px;
  margin-bottom: 4px;
  color: #1a1b26;
}

#welcome-dialog ul {
  margin: 0;
  padding-left: 20px;
}

#welcome-dialog li {
  margin: 3px 0;
}

#welcome-dialog strong {
  color: #4a90e2;
}

#welcome-dialog kbd {
  display: inline-block;
  border: 1px solid #ccc;
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 12px;
  background: #f5f5f8;
  font-family: inherit;
}

.welcome-note {
  font-size: 12px;
  color: #777;
  margin-top: 12px;
}

.welcome-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 20px;
  padding-top: 14px;
  border-top: 1px solid #eee;
}

.welcome-check {
  cursor: pointer;
  user-select: none;
  display: flex;
  align-items: center;
  gap: 6px;
}

#welcome-close {
  background: #4a90e2;
  color: #fff;
  border: none;
  border-radius: 7px;
  padding: 8px 18px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

#welcome-close:hover {
  background: #3b7fd0;
}

/* 「データはどこに保存される？」「データ量の目安と制限」は、
   最初は見出しだけを出し、クリックで中身を開く（h3 と同じ見た目の summary にする） */
.welcome-section {
  margin-top: 18px;
}

.welcome-section > summary {
  cursor: pointer;
  user-select: none;
  list-style: none;
  font-size: 14px;
  font-weight: 700;
  color: #1a1b26;
}

.welcome-section > summary::-webkit-details-marker {
  display: none;
}

.welcome-section > summary::before {
  content: '▸ ';
  color: #4a90e2;
}

.welcome-section[open] > summary::before {
  content: '▾ ';
}

.welcome-section > ul {
  margin-top: 4px;
}

/* 対応環境の説明は1項目目だけ見せ、残りは「詳細」クリックで展開する */
.welcome-more {
  margin: 2px 0 0 20px;
}

.welcome-more summary {
  cursor: pointer;
  font-size: 12px;
  color: #4a90e2;
  user-select: none;
  list-style: none;
}

.welcome-more summary::-webkit-details-marker {
  display: none;
}

.welcome-more summary::before {
  content: '▸ ';
}

.welcome-more[open] summary::before {
  content: '▾ ';
}

.welcome-more ul {
  margin-top: 2px;
}

/* ---- 未保存の内容を破棄する前の確認ダイアログ（#confirm-overlay） ---- */
/* ウェルカム画面と同じ見た目に揃える。ウェルカム画面より手前に出す必要はないが、
   万一同時に開いても確認が前に来るよう z-index は 1 つ上にしている */

#confirm-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 310;
  padding: 16px;
}

#confirm-overlay[hidden] {
  display: none;
}

#confirm-dialog {
  background: #fff;
  border-radius: 10px;
  max-width: 460px;
  width: 100%;
  padding: 22px 26px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.28);
  color: #333;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 14px;
  line-height: 1.6;
}

#confirm-dialog h2 {
  margin: 0 0 8px;
  font-size: 17px;
}

#confirm-message {
  margin: 0;
  word-break: break-word;
}

.confirm-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 20px;
  padding-top: 14px;
  border-top: 1px solid #eee;
}

.confirm-footer button {
  border-radius: 7px;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

/* 既定の操作（保存してから新規作成）を目立たせる */
#confirm-save {
  background: #4a90e2;
  color: #fff;
  border: none;
}

#confirm-save:hover {
  background: #3b7fd0;
}

/* キャンセルと「保存せずに」は控えめにして、誤って押しにくくする */
.confirm-quiet {
  background: #fff;
  color: #555;
  border: 1px solid #ccc;
}

.confirm-quiet:hover {
  background: #f2f2f5;
}

/* ---- 設定ダイアログ（#settings-overlay） ---- */
/* ウェルカム画面・確認ダイアログと同じ見た目に揃える。
   設定項目は .settings-row を縦に積む形なので、項目が増えても CSS は変えなくてよい */

#settings-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 300;
  padding: 16px;
}

#settings-overlay[hidden] {
  display: none;
}

#settings-dialog {
  background: #fff;
  border-radius: 10px;
  max-width: 460px;
  width: 100%;
  padding: 22px 26px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.28);
  color: #333;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 14px;
  line-height: 1.6;
}

#settings-dialog h2 {
  margin: 0 0 4px;
  font-size: 17px;
}

.settings-row {
  padding: 14px 0;
  border-top: 1px solid #eee;
}

.settings-label {
  font-weight: 600;
  margin-bottom: 6px;
}

.settings-control {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 18px;
}

/* 設定項目の補足文（何に効くのかを一行で添える） */
.settings-note {
  margin-top: 6px;
  color: #777;
  font-size: 12px;
  line-height: 1.5;
}

.settings-choice {
  display: inline-flex;
  align-items: center;
  cursor: pointer;
}

.settings-choice input {
  margin: 0;
  cursor: pointer;
}

.settings-footer {
  display: flex;
  justify-content: flex-end;
  margin-top: 6px;
  padding-top: 14px;
  border-top: 1px solid #eee;
}

#settings-close {
  background: #4a90e2;
  color: #fff;
  border: none;
  border-radius: 7px;
  padding: 8px 18px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

#settings-close:hover {
  background: #3b7fd0;
}
