/* ============================================================
   オンライン ホワイトボード
   ノードUI（付箋 / 図形 / 矢印コネクタ / 無限キャンバス）
   ============================================================ */

/* Precision White（Vercel/shadcn系）＝ライト。ダークは data-theme="dark" で上書き */
:root {
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", "Menlo", "Consolas", monospace;
  --radius: 12px;
  --bg: #ffffff; /* ページ背景 */
  --surface: #ffffff; /* ツールバー/フッター/ドロワー */
  --canvas-bg: #fafafa;
  --grid-line: #ededed;
  --ink: #0a0a0a;
  --muted: #737373;
  --line: #e5e5e5;
  --line-strong: #d4d4d4;
  --accent: #0070f3;
  --accent-weak: #eaf2ff;
  --cta-bg: #0a0a0a;
  --cta-fg: #ffffff;
  --cta-hover: #333333;
  --hover: #f5f5f5;
  --active: #f2f2f2;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.06), 0 1px 1px rgba(0, 0, 0, 0.04);
  --wire: #6b7280;
  --select-outline: #0a0a0a;
  --marquee-bg: rgba(0, 112, 243, 0.07);
  --toast-bg: #0a0a0a;
  --toast-fg: #ffffff;
  /* ノード（未指定色=テーマ既定） */
  --node-folder: #f4f4f5;
  --node-file: #ffffff;
  --node-shape: #ffffff;
  --node-sticky: #fef9c3;
  --node-text: #1f2937;
  --node-border: #d4d4d4;
  --node-border-soft: #e5e5e5;
  --shape-border: #171717;
}
:root[data-theme="dark"] {
  --bg: #0b0b0c;
  --surface: #151517;
  --canvas-bg: #0e0e10;
  --grid-line: #1c1c20;
  --ink: #ededed;
  --muted: #8a8a90;
  --line: #2a2a2e;
  --line-strong: #3a3a40;
  --accent: #3b9dff;
  --accent-weak: #16283e;
  --cta-bg: #ffffff; /* ダークは白ボタン */
  --cta-fg: #0a0a0a;
  --cta-hover: #d9d9d9;
  --hover: #1e1e22;
  --active: #26262b;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
  --wire: #7c7c84;
  --select-outline: #ffffff;
  --marquee-bg: rgba(59, 157, 255, 0.14);
  --toast-bg: #f5f5f5;
  --toast-fg: #0a0a0a;
  --node-folder: #1f1f24;
  --node-file: #17171a;
  --node-shape: #17171a;
  --node-sticky: #34320f;
  --node-text: #e6e6e6;
  --node-border: #3a3a42;
  --node-border-soft: #2a2a2e;
  --shape-border: #6b6b72;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  font-family: system-ui, -apple-system, "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Meiryo", sans-serif;
  font-size: 16px;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ---------- ヘッダー ---------- */
.app-head {
  /* 横並び1行。中央列(h1)を厳密にセンタリングし、キッカーはその左に添える */
  padding: 10px 24px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: baseline;
  column-gap: 10px;
}
.app-kicker {
  grid-column: 1;
  justify-self: end;
  font-family: var(--mono);
  font-size: 1rem;
  color: var(--muted);
  letter-spacing: 0;
  margin: 0;
  white-space: nowrap;
}
.app-head h1 {
  grid-column: 2;
  margin: 0;
  font-size: 1.7rem;
  letter-spacing: -0.03em;
  font-weight: 800;
  white-space: nowrap;
  /* 白文字＋黒の縁取り（中抜きアウトライン） */
  color: var(--bg);
  -webkit-text-stroke: 1.5px var(--ink);
  paint-order: stroke fill;
}
.head-right {
  grid-column: 3;
  justify-self: end;
  display: flex;
  align-items: center;
  gap: 6px;
}
.lang-switch {
  font-family: var(--mono);
  font-size: 1rem;
  color: var(--muted);
  text-decoration: none;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 2px 8px;
  transition: color 0.15s, border-color 0.15s;
}
.lang-switch:hover {
  color: var(--ink);
  border-color: var(--line-strong);
}
/* テーマ切替（言語ボタンの左） */
.theme-toggle {
  appearance: none;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--muted);
  width: 32px;
  height: 30px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}
.theme-toggle:hover {
  color: var(--ink);
  border-color: var(--line-strong);
}
.theme-toggle svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.theme-toggle .icon-sun {
  display: none;
}
[data-theme="dark"] .theme-toggle .icon-sun {
  display: block;
}
[data-theme="dark"] .theme-toggle .icon-moon {
  display: none;
}

/* ---------- ツールバー ---------- */
.toolbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  background: var(--surface);
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}
.tool-group {
  display: flex;
  align-items: center;
  gap: 4px;
}
.tool-sep {
  width: 1px;
  height: 26px;
  background: var(--line);
  margin: 0 4px;
}
.tool {
  appearance: none;
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink);
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.tool svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.tool:hover {
  background: var(--hover);
}
.tool.is-active {
  background: var(--active);
  border-color: var(--line);
  color: var(--ink);
}
.tool.danger:hover {
  background: #fef2f2;
  color: #dc2626;
}
.tool.zoom-label {
  width: auto;
  padding: 0 10px;
  font-size: 0.95rem;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}
.tool.tpl-btn {
  /* 右端に絶対配置＝他アイコンは justify-content:center で中央寄せのまま */
  position: absolute;
  right: 16px;
  top: 50%;
  transform: translateY(-50%);
  width: auto;
  gap: 6px;
  padding: 0 16px;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--cta-fg);
  background: var(--cta-bg);
  border-color: var(--cta-bg);
}
.tool.tpl-btn:hover {
  background: var(--cta-hover);
  border-color: var(--cta-hover);
}
.tool.tpl-btn span {
  white-space: nowrap;
}
/* 矢印の設定（アイコン並び） */
.wire-tools {
  display: flex;
  align-items: center;
  gap: 2px;
}
.wt-div {
  width: 1px;
  height: 20px;
  background: var(--line);
  margin: 0 4px;
}
.tool.wt {
  width: 36px;
  height: 36px;
}

/* 色ピッカー（トリガー＋ドロワー） */
.color-picker {
  position: relative;
  display: flex;
  align-items: center;
}
.color-trigger {
  width: 40px;
  height: 40px;
}
.color-dot {
  display: block;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 1px solid rgba(15, 23, 42, 0.18);
  /* 塗りつぶしのカラーホイール（中心まで色を残す） */
  background: conic-gradient(#ff4d4d, #ffd24d, #b6ff4d, #4dff88, #4dd2ff, #4d6bff, #b64dff, #ff4db6, #ff4d4d);
}
.color-drawer {
  position: absolute;
  top: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  display: grid;
  grid-template-columns: repeat(8, 26px);
  gap: 6px;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  z-index: 60;
}
.color-drawer[hidden] {
  display: none;
}

/* 色スウォッチ */
.swatch {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid rgba(15, 23, 42, 0.12);
  cursor: pointer;
  padding: 0;
  transition: transform 0.12s, box-shadow 0.12s;
}
.swatch:hover {
  transform: scale(1.12);
}
.swatch.is-active {
  border-color: var(--ink);
  box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--ink);
}

/* ---------- ステージ / キャンバス ---------- */
.stage {
  position: relative;
  height: calc(100vh - 190px); /* dvh非対応ブラウザ用フォールバック */
  height: calc(100dvh - 190px); /* モバイルのアドレスバー変動に追従 */
  min-height: 460px;
  margin: 0;
  border-bottom: 1px solid var(--line);
}
.canvas {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background-color: var(--canvas-bg);
  /* 方眼（graph paper）グリッド＝schematic感。applyCameraでsize/positionを動的更新 */
  background-image: linear-gradient(to right, var(--grid-line) 1px, transparent 1px),
    linear-gradient(to bottom, var(--grid-line) 1px, transparent 1px);
  background-size: 24px 24px;
  background-position: 0 0;
  cursor: default;
  touch-action: none;
}
/* 範囲選択（マーキー）の矩形 */
.marquee {
  position: absolute;
  border: 1px solid var(--accent);
  background: var(--marquee-bg);
  pointer-events: none;
  z-index: 5;
}
.canvas.tool-sticky,
.canvas.tool-rect,
.canvas.tool-ellipse,
.canvas.tool-diamond,
.canvas.tool-folder,
.canvas.tool-file {
  cursor: crosshair;
}
.canvas.tool-connector {
  cursor: cell;
}
.world {
  position: absolute;
  top: 0;
  left: 0;
  width: 0;
  height: 0;
  transform-origin: 0 0;
}

/* コネクタ用SVG（world内・overflow可視で世界座標に直接描画） */
.wires {
  position: absolute;
  top: 0;
  left: 0;
  width: 1px;
  height: 1px;
  overflow: visible;
  pointer-events: none;
}
.wires line,
.wires path.wire {
  stroke: var(--wire);
  stroke-width: 2;
  fill: none;
}
.wires .wire-hit {
  stroke: transparent;
  stroke-width: 14;
  fill: none; /* 直角パスは暗黙クローズで塗り面ができるため必須 */
  pointer-events: stroke;
  cursor: pointer;
}
.wires marker path {
  fill: var(--wire);
  stroke: none;
}
.wires .wire.is-selected {
  stroke: var(--accent);
  stroke-width: 3;
}
.wire-preview {
  stroke: var(--accent);
  stroke-width: 2;
  stroke-dasharray: 6 5;
  fill: none;
}

/* ---------- アイテム（付箋・図形） ---------- */
.item {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px 12px;
  font-size: 16px;
  line-height: 1.4;
  color: var(--node-text);
  cursor: grab;
  user-select: none;
  overflow: hidden;
}
.item.is-dragging {
  cursor: grabbing;
}
.item .txt {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  outline: none;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}
.item.editing {
  cursor: text;
}
.item.editing .txt {
  cursor: text;
  user-select: text;
}

/* 付箋 */
.item.sticky {
  background: var(--node-sticky);
  border-radius: 4px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
  align-items: flex-start;
  justify-content: flex-start;
}
.item.sticky .txt {
  align-items: flex-start;
  justify-content: flex-start;
  text-align: left;
}

/* 図形共通 */
.item.shape {
  background: var(--node-shape);
  border: 1.5px solid var(--shape-border);
}
.item.rect {
  border-radius: 8px;
}
.item.ellipse {
  border-radius: 50%;
}
.item.diamond {
  background: transparent;
  border: none;
  overflow: visible; /* 回転した内側四角の角がクリップされないように */
}
.item.diamond .shape-bg {
  position: absolute;
  inset: 0;
  background: var(--node-shape);
  border: 1.5px solid var(--shape-border);
  /* 正方形を45度回転＋0.707倍で、四隅がボックスの上下左右辺の中点に接するひし形になる */
  transform: rotate(45deg) scale(0.707);
  border-radius: 6px;
  z-index: 0;
}
.item.diamond .txt {
  position: relative;
  z-index: 1;
}

/* ディレクトリマップ用ノード（フォルダ・ファイル） */
.item.node {
  justify-content: flex-start;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 8px;
  box-shadow: var(--shadow);
}
.item.node .node-ico {
  flex: 0 0 auto;
  font-size: 18px;
  line-height: 1;
  user-select: none;
  filter: grayscale(1);
  opacity: 0.85;
}
.item.node .txt {
  align-items: center;
  justify-content: flex-start;
  text-align: left;
  font-family: var(--mono);
  font-size: 16px;
  font-weight: 500;
  letter-spacing: -0.01em;
}
.item.folder {
  background: var(--node-folder);
  border: 1px solid var(--node-border);
}
.item.file {
  background: var(--node-file);
  border: 1px solid var(--node-border-soft);
  font-weight: 400;
}

/* 選択状態 */
.item.is-selected {
  outline: 2px solid var(--select-outline);
  outline-offset: 2px;
}
.item.is-connect-target {
  outline: 2px dashed var(--accent);
  outline-offset: 2px;
}

/* リサイズハンドル */
.rz {
  position: absolute;
  right: -6px;
  bottom: -6px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--surface);
  border: 2px solid var(--accent);
  cursor: nwse-resize;
  z-index: 3;
}

/* 空状態ヒント */
.empty-hint {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  margin: 0;
  text-align: center;
  color: var(--muted);
  font-size: 1rem;
  pointer-events: none;
}
.empty-hint.is-hidden {
  display: none;
}


/* ---------- 広告（右下フローティング・薄型透明枠 320×100） ---------- */
.footer-ad {
  position: fixed;
  right: 0;
  bottom: 0;
  z-index: 90;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 0;
  width: 320px;
  overflow: hidden;
  background: transparent;
  border: none;
  box-shadow: none;
}
.footer-ad.is-closed {
  display: none;
}
.ad-widget__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  position: relative;
  z-index: 1;
}
.ad-widget__label {
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.04em;
  background: #f1f5f9;
  padding: 2px 8px;
  border-radius: 999px;
}
.ad-widget__close {
  appearance: none;
  border: none;
  background: #f1f5f9;
  color: var(--muted);
  width: 18px;
  height: 18px;
  border-radius: 50%;
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, color 0.2s;
}
.ad-widget__close:hover {
  background: #e2e8f0;
  color: var(--ink);
}
.footer-ad ins.adsbygoogle {
  display: block;
  width: 320px;
  height: 100px;
}

/* ---------- フッター ---------- */
footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 40px;
  color: var(--muted);
  font-size: 1rem;
  border-top: 1px solid var(--line);
  background: var(--surface);
}
footer a {
  color: var(--ink);
  text-decoration: none;
  transition: color 0.2s;
}
footer a:hover {
  color: var(--accent);
}
.footer-links {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}
.footer-links a {
  border: 1px solid var(--line);
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 1rem;
  transition: all 0.2s;
}
.footer-links a:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* ---------- トースト ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%) translateY(20px);
  background: var(--toast-bg);
  color: var(--toast-fg);
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 0.95rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 100;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ---------- レスポンシブ ---------- */
@media (max-width: 768px) {
  .app-head h1 {
    font-size: 1.4rem;
  }
  .toolbar {
    gap: 4px;
    padding: 8px 10px;
  }
  .tool {
    width: 38px;
    height: 38px;
  }
  /* 狭幅では「サンプル」を絶対配置解除して折り返しに参加させる（重なり防止） */
  .tool.tpl-btn {
    position: static;
    transform: none;
  }
  .stage {
    height: calc(100vh - 250px);
    height: calc(100dvh - 250px);
    min-height: 380px;
  }

  /* 広告：SPはfooter付近にインライン化 */
  .footer-ad {
    position: static;
    align-self: center;
    margin: 24px auto 0;
    gap: 0;
    padding: 0;
    background: none;
    border: none;
    box-shadow: none;
    z-index: auto;
  }
  .footer-ad.is-closed {
    display: flex;
  }
  .ad-widget__head {
    display: none;
  }
  .footer-ad ins.adsbygoogle {
    width: 320px;
    height: 100px;
  }

  footer {
    flex-direction: column;
    gap: 16px;
    padding: 8px 16px;
    text-align: center;
  }
  .footer-links {
    justify-content: center;
  }
}

/* ---------- howto / doc ページ ---------- */
.doc {
  max-width: 820px;
  margin: 0 auto;
  padding: 28px 20px 72px;
}
.doc h1 {
  font-size: 2rem;
  letter-spacing: -0.02em;
  font-weight: 800;
  margin: 4px 0 10px;
}
.doc .lead {
  color: var(--muted);
  font-size: 1.05rem;
  margin: 0 0 8px;
}
.doc h2 {
  font-size: 1.4rem;
  letter-spacing: -0.01em;
  font-weight: 700;
  margin: 44px 0 12px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
}
.doc h3 {
  font-size: 1.12rem;
  font-weight: 700;
  margin: 24px 0 8px;
}
.doc p,
.doc li {
  font-size: 1rem;
  line-height: 1.85;
  color: var(--ink);
}
.doc ol,
.doc ul {
  padding-left: 1.4em;
  margin: 10px 0;
}
.doc li {
  margin: 6px 0;
}
.doc a {
  color: var(--accent);
  text-decoration: none;
}
.doc a:hover {
  text-decoration: underline;
}
.doc .answer {
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  padding: 14px 18px;
  margin: 16px 0;
}
.doc .answer p {
  margin: 0;
}
.doc table {
  width: 100%;
  border-collapse: collapse;
  margin: 16px 0;
}
.doc th,
.doc td {
  border: 1px solid var(--line);
  padding: 8px 12px;
  text-align: left;
  font-size: 1rem;
  line-height: 1.6;
}
.doc th {
  background: var(--surface);
  font-weight: 700;
}
.doc kbd {
  font-family: var(--mono);
  font-size: 1rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 6px;
  padding: 1px 7px;
  white-space: nowrap;
}
.doc .faq-q {
  font-weight: 700;
  margin: 22px 0 4px;
}
.doc .cta {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 24px;
  padding: 12px 20px;
  font-weight: 700;
  color: var(--cta-fg);
  background: var(--cta-bg);
  border-radius: 8px;
  text-decoration: none;
}
.doc .cta:hover {
  background: var(--cta-hover);
  text-decoration: none;
}
.app-kicker.back {
  text-decoration: none;
}
.app-kicker.back:hover {
  color: var(--ink);
}
