:root {
  --bg: #F9F9F7;
  --surface: #FFFFFF;
  --ink: #1D1D1F;
  --muted: #71717A;
  --line: #E6E6E2;
  --indigo: #2B4C7E;
  --indigo-soft: rgba(43, 76, 126, 0.08);
  --danger: #B42318;
  --radius: 12px;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --font-mincho: 'Shippori Mincho', 'Hiragino Mincho ProN', serif;
  --font-sans: 'Inter', 'Noto Sans JP', -apple-system, BlinkMacSystemFont, sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  user-select: none;
}

body.theme-modern .el-font-mincho { font-family: var(--font-sans) !important; }
body.theme-mincho .el-font-sans { font-family: var(--font-mincho) !important; }

/* 極薄トップバー */
.topbar {
  height: 52px;
  padding: 0 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg);
  border-bottom: 1px solid transparent;
  transition: border-color 240ms var(--ease);
  position: relative;
  z-index: 40;
}

body.editing .topbar {
  border-bottom-color: var(--line);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 18px;
}

.brand {
  font-family: var(--font-mincho);
  font-weight: 700;
  font-size: 16px;
  letter-spacing: 0.08em;
  color: var(--ink);
}

.member-pill-trigger {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 5px 12px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.035);
  border: 1px solid transparent;
  font-size: 13px;
  color: var(--ink);
  cursor: pointer;
  transition: background 180ms var(--ease), border-color 180ms var(--ease);
}

.member-pill-trigger:hover {
  background: rgba(0, 0, 0, 0.06);
}

.member-counter {
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  font-size: 12px;
}

.topbar-center {
  display: flex;
  align-items: center;
  gap: 6px;
}

.member-tab {
  border: none;
  background: transparent;
  padding: 6px 10px;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 1.5px solid transparent;
  transition: color 180ms var(--ease), border-color 180ms var(--ease);
}

.member-tab:hover { color: var(--ink); }
.member-tab.active {
  color: var(--ink);
  font-weight: 600;
  border-bottom-color: var(--indigo);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 14px;
}

.quiet-btn {
  border: none;
  background: transparent;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
  padding: 5px 8px;
  border-radius: 6px;
  transition: color 160ms, background 160ms;
}

.quiet-btn:hover {
  color: var(--ink);
  background: rgba(0, 0, 0, 0.04);
}

.quiet-btn.active {
  color: var(--indigo);
  background: var(--indigo-soft);
  font-weight: 600;
}

/* 全体表示ズーム・編集用コントロールバー */
.edit-subbar {
  display: none;
  height: 44px;
  padding: 0 28px;
  background: #FFFFFF;
  border-bottom: 1px solid var(--line);
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  z-index: 35;
}

body.editing .edit-subbar {
  display: flex;
}

.subbar-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.subbar-label {
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.03em;
}

.mini-btn {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  font-size: 12px;
  padding: 4px 9px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 140ms;
}

.mini-btn:hover {
  border-color: var(--indigo);
  color: var(--indigo);
}

.mini-btn.primary {
  background: var(--indigo);
  color: #fff;
  border-color: var(--indigo);
}

.mini-btn.danger:hover {
  border-color: var(--danger);
  color: var(--danger);
}

.scale-slider {
  width: 96px;
  accent-color: var(--indigo);
  cursor: pointer;
}

.scale-val {
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  min-width: 38px;
  text-align: right;
}

/* メインステージ */
.workspace {
  height: calc(100vh - 52px);
  width: 100%;
  padding: 12px 28px 20px;
  display: flex;
  position: relative;
  transition: height 200ms var(--ease);
}

body.editing .workspace {
  height: calc(100vh - 96px - 52px);
}

/* Stage 1: 題フォーカス */
.stage-focus {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 12vw;
  background: var(--bg);
  z-index: 25;
  cursor: pointer;
  transition: opacity 280ms var(--ease), transform 320ms var(--ease);
}

.stage-focus.hidden {
  opacity: 0;
  pointer-events: none;
  transform: translateY(-10px);
}

.focus-meta {
  font-size: 13px;
  color: var(--muted);
  letter-spacing: 0.08em;
  margin-bottom: 24px;
}

.focus-title {
  font-family: var(--font-mincho);
  font-size: clamp(30px, 3.8vw, 52px);
  font-weight: 700;
  line-height: 1.42;
  color: var(--ink);
  text-align: center;
  max-width: 900px;
}

.focus-hint {
  position: absolute;
  bottom: 34px;
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.06em;
  opacity: 0.72;
}

/* Stage 2: 左右ペイン */
.split-container {
  display: flex;
  width: 100%;
  height: 100%;
  gap: 0;
  transform-origin: center top;
  transition: transform 220ms var(--ease);
}

.pane-left {
  height: 100%;
  display: flex;
  flex-direction: column;
  position: relative;
  min-width: 22%;
  max-width: 64%;
  padding-right: 14px;
}

.pane-left-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  padding: 0 4px;
}

.hypo-pills {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.hypo-dot {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  padding: 2px 8px;
  border-radius: 999px;
  cursor: pointer;
}

.hypo-dot.active {
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
}

.tag-input {
  border: none;
  background: transparent;
  font-size: 12px;
  color: var(--muted);
  text-align: right;
  width: 140px;
  outline: none;
}

body.editing .tag-input {
  border-bottom: 1px dashed var(--line);
  color: var(--ink);
}

/* スプリッター（左右比率調整） */
.splitter-v {
  width: 14px;
  cursor: col-resize;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  flex-shrink: 0;
}

.splitter-v::after {
  content: "";
  width: 1px;
  height: 44%;
  background: var(--line);
  transition: background 180ms, width 180ms;
}

.splitter-v:hover::after,
.splitter-v.dragging::after {
  width: 2px;
  background: var(--indigo);
}

.ratio-badge {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--ink);
  color: #fff;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  padding: 3px 8px;
  border-radius: 999px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 150ms;
}

.splitter-v.dragging .ratio-badge {
  opacity: 1;
}

/* 右ペイン（図解＋オプション詳細） */
.pane-right {
  flex: 1;
  height: 100%;
  display: flex;
  flex-direction: column;
  padding-left: 14px;
  min-width: 0;
}

/* 自由キャンバス共通スタイル */
.canvas-shell {
  position: relative;
  flex: 1;
  width: 100%;
  overflow: hidden;
  border-radius: var(--radius);
}

.pane-left .canvas-shell {
  background: transparent;
}

body.editing .pane-left .canvas-shell {
  border: 1px dashed rgba(43, 76, 126, 0.25);
  background: rgba(255, 255, 255, 0.45);
}

.pane-right .canvas-shell {
  background: var(--surface);
  border: 1px solid var(--line);
}

.canvas-stage {
  position: absolute;
  inset: 0;
  transform-origin: 0 0;
}

.arrow-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  overflow: visible;
}

.arrow-hit {
  pointer-events: stroke;
  cursor: pointer;
}

.guide-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.snap-guide-v {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 1px;
  background: var(--indigo);
  opacity: 0.65;
}

.snap-guide-h {
  position: absolute;
  left: 0;
  right: 0;
  height: 1px;
  background: var(--indigo);
  opacity: 0.65;
}

/* キャンバス内要素 */
.c-el {
  position: absolute;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 10px 14px;
  border-radius: 10px;
  transition: box-shadow 140ms, border-color 140ms;
  word-break: break-word;
  overflow-wrap: anywhere;
}

body.editing .c-el {
  cursor: grab;
}

body.editing .c-el:active {
  cursor: grabbing;
}

body.editing .c-el.selected {
  outline: 1.5px solid var(--indigo);
  outline-offset: 2px;
}

.c-el.kind-title,
.c-el.kind-text {
  background: transparent;
  border: 1px solid transparent;
  padding: 4px 6px;
}

.c-el.kind-box {
  background: #FFFFFF;
  border: 1px solid var(--line);
}

.c-el.kind-box.acc-indigo {
  border-color: var(--indigo);
  background: var(--indigo-soft);
}

.c-el.kind-box.acc-dark {
  background: var(--ink);
  color: #FFFFFF;
  border-color: var(--ink);
}

.c-el.kind-box.acc-muted {
  background: #F4F4F1;
  border-color: transparent;
}

.c-el.kind-pill {
  border-radius: 999px;
  background: #F3F3EF;
  border: 1px solid transparent;
  padding: 10px 20px;
}

.c-el.kind-pill.acc-indigo {
  background: #FFFFFF;
  border: 1.5px solid var(--indigo);
}

.c-el.kind-circle {
  border-radius: 50%;
  background: rgba(113, 113, 122, 0.08);
  border: 1px solid rgba(113, 113, 122, 0.3);
}

.c-el.kind-circle.acc-indigo {
  background: rgba(43, 76, 126, 0.09);
  border-color: var(--indigo);
}

.c-el.kind-bar {
  background: transparent;
  border: none;
  padding: 6px 8px;
  justify-content: space-between;
}

.bar-track {
  width: 100%;
  height: 10px;
  border-radius: 999px;
  background: #EFEFEB;
  overflow: hidden;
  margin-top: 8px;
}

.bar-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--muted);
  transition: width 260ms var(--ease);
}

.c-el.acc-indigo .bar-fill {
  background: var(--indigo);
}

.c-el.kind-axis {
  background: transparent;
  border: none;
  pointer-events: auto;
}

.c-el.kind-image {
  padding: 0;
  background: transparent;
  overflow: hidden;
}

.c-el.kind-image img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
}

.c-el.kind-icon {
  background: transparent;
  align-items: center;
  gap: 6px;
}

.el-main {
  line-height: 1.45;
  white-space: pre-wrap;
}

.el-sub {
  font-size: 0.78em;
  color: var(--muted);
  margin-top: 4px;
  line-height: 1.4;
  white-space: pre-wrap;
}

.c-el.acc-dark .el-sub { color: rgba(255, 255, 255, 0.75); }
.c-el.acc-indigo .el-main { color: var(--indigo); }
.c-el.acc-muted .el-main { color: var(--muted); }

.el-font-mincho { font-family: var(--font-mincho); }
.el-font-sans { font-family: var(--font-sans); }

/* リサイズハンドル */
.resize-handle {
  display: none;
  position: absolute;
  width: 10px;
  height: 10px;
  background: #fff;
  border: 1.5px solid var(--indigo);
  border-radius: 50%;
  z-index: 15;
}

body.editing .c-el.selected .resize-handle {
  display: block;
}

.rh-nw { top: -5px; left: -5px; cursor: nwse-resize; }
.rh-ne { top: -5px; right: -5px; cursor: nesw-resize; }
.rh-sw { bottom: -5px; left: -5px; cursor: nesw-resize; }
.rh-se { bottom: -5px; right: -5px; cursor: nwse-resize; }

/* 矢印ハンドル */
.arrow-handle {
  pointer-events: auto;
  cursor: move;
}

/* 左ペイン下部（静かなステータス＆メモ） */
.pane-left-footer {
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 8px;
}

.status-select {
  border: none;
  background: transparent;
  font-size: 12px;
  color: var(--muted);
  cursor: pointer;
  outline: none;
}

/* 右ペイン下部：詳細タブ（初期は非表示） */
.splitter-h {
  height: 10px;
  cursor: row-resize;
  display: flex;
  align-items: center;
  justify-content: center;
}

.splitter-h::after {
  content: "";
  height: 1px;
  width: 32%;
  background: var(--line);
}

.detail-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.detail-tabs {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 20px;
  height: 40px;
  border-bottom: 1px solid var(--line);
}

.detail-tab-btn {
  border: none;
  background: transparent;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
  height: 100%;
  border-bottom: 2px solid transparent;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.detail-tab-btn.active {
  color: var(--ink);
  font-weight: 600;
  border-bottom-color: var(--ink);
}

.detail-body-wrap {
  flex: 1;
  padding: 16px 22px;
  overflow-y: auto;
}

.detail-text-view {
  font-size: 15px;
  line-height: 1.7;
  color: var(--ink);
  white-space: pre-wrap;
}

.detail-textarea {
  width: 100%;
  height: 100%;
  border: none;
  resize: none;
  outline: none;
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.65;
  color: var(--ink);
}

.add-detail-trigger {
  display: none;
  margin-top: 8px;
  justify-content: flex-end;
}

body.editing .add-detail-trigger {
  display: flex;
}

/* 編集モード下部ドック（テンプレ・パーツ・素材） */
.edit-dock {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 52px;
  background: #FFFFFF;
  border-top: 1px solid var(--line);
  padding: 0 24px;
  align-items: center;
  justify-content: space-between;
  z-index: 45;
}

body.editing .edit-dock {
  display: flex;
}

/* 選択時だけ浮かぶミニ・フローティングバー */
.floating-bar {
  position: fixed;
  z-index: 60;
  background: #1D1D1F;
  color: #FFFFFF;
  border-radius: 10px;
  padding: 6px 10px;
  display: none;
  align-items: center;
  gap: 6px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.16);
}

.floating-bar.visible {
  display: flex;
}

.fb-btn {
  border: none;
  background: transparent;
  color: rgba(255, 255, 255, 0.85);
  font-size: 12px;
  padding: 4px 7px;
  border-radius: 5px;
  cursor: pointer;
}

.fb-btn:hover { background: rgba(255, 255, 255, 0.14); color: #fff; }
.fb-btn.active { background: var(--indigo); color: #fff; }
.fb-sep { width: 1px; height: 16px; background: rgba(255, 255, 255, 0.2); }
.fb-val { font-size: 11px; font-variant-numeric: tabular-nums; color: #D4D4D8; min-width: 34px; text-align: center; }

/* モーダル・ドロワー（メモ、一覧、テンプレ選択、共有） */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(29, 29, 31, 0.28);
  backdrop-filter: blur(4px);
  z-index: 80;
  display: none;
  align-items: center;
  justify-content: center;
}

.overlay.open {
  display: flex;
}

.modal-card {
  background: #FFFFFF;
  border-radius: 14px;
  border: 1px solid var(--line);
  width: min(760px, 92vw);
  max-height: 82vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-head {
  padding: 16px 22px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-body {
  padding: 20px 22px;
  overflow-y: auto;
}

.tpl-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
}

.tpl-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px 12px;
  text-align: left;
  background: #fff;
  cursor: pointer;
  transition: border-color 140ms, background 140ms;
}

.tpl-card:hover {
  border-color: var(--indigo);
  background: var(--indigo-soft);
}

.tpl-card strong { display: block; font-size: 13px; margin-bottom: 4px; }
.tpl-card span { font-size: 11px; color: var(--muted); }

/* 先生メモドロワー */
.memo-drawer {
  position: fixed;
  right: 28px;
  bottom: 24px;
  width: min(420px, 90vw);
  background: #FFFFFF;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.12);
  z-index: 70;
  display: none;
  flex-direction: column;
  gap: 10px;
}

.memo-drawer.open { display: flex; }

.memo-drawer textarea {
  width: 100%;
  min-height: 110px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.6;
  outline: none;
  resize: vertical;
}

.toast {
  position: fixed;
  bottom: 64px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  font-size: 12px;
  padding: 8px 16px;
  border-radius: 999px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms;
  z-index: 100;
}

.toast.show { opacity: 1; }
