/* ============================================
   1. CSS Variables
   ============================================ */
:root {
  --bg-app: #f3faf8;
  --bg-panel: #ffffff;
  --bg-canvas: #f7fcfb;
  --bg-hover: #e8f5f1;
  --bg-active: #d5f0e8;
  --text-primary: #16332c;
  --text-secondary: #4d6b63;
  --text-tertiary: #7a968e;
  --border: #d5e8e1;
  --border-strong: #b4d4c9;
  --accent: #0d9488;
  --accent-hover: #0f766e;
  --accent-soft: #ccfbf1;
  --accent-sky: #0284c7;
  --accent-mint: #14b8a6;
  --accent-coral: #f97316;
  --danger: #e5484d;
  --danger-soft: #fdecec;
  --success: #059669;
  --success-soft: #d1fae5;
  --warning: #d97706;

  --shadow-sm: 0 1px 2px rgba(13, 68, 58, 0.05);
  --shadow-md: 0 8px 24px rgba(13, 68, 58, 0.08);
  --shadow-lg: 0 16px 40px rgba(13, 68, 58, 0.12);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 22px;

  --font: "Noto Sans KR", "Plus Jakarta Sans", -apple-system, BlinkMacSystemFont, sans-serif;
  --font-display: "Plus Jakarta Sans", "Noto Sans KR", sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  --sidebar-width: 260px;
  --panel-width: 300px;
  --toolbar-height: 54px;
  --header-height: 62px;

  --transition: 160ms ease;
  --node-max-width: 220px;
  --dot-grid: radial-gradient(circle, #b9d8cf 1.1px, transparent 1.1px);
  --dot-size: 20px;
}

[data-theme="dark"] {
  --bg-app: #0f1a18;
  --bg-panel: #162421;
  --bg-canvas: #12201d;
  --bg-hover: #1e322d;
  --bg-active: #1a3a33;
  --text-primary: #e8f5f1;
  --text-secondary: #9dbdb4;
  --text-tertiary: #6f9188;
  --border: #2a403a;
  --border-strong: #3d5a52;
  --accent: #2dd4bf;
  --accent-hover: #5eead4;
  --accent-soft: #134e4a;
  --accent-sky: #38bdf8;
  --accent-mint: #2dd4bf;
  --accent-coral: #fb923c;
  --danger: #f07178;
  --danger-soft: #3a1f22;
  --success: #34d399;
  --success-soft: #064e3b;
  --warning: #fbbf24;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.25);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.45);
  --dot-grid: radial-gradient(circle, #2a403a 1.1px, transparent 1.1px);
}

/* ============================================
   2. Reset
   ============================================ */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  -webkit-text-size-adjust: 100%;
  height: 100%;
}

body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-primary);
  background: var(--bg-app);
  height: 100%;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

button,
input,
textarea,
select {
  font: inherit;
  color: inherit;
}

button {
  background: none;
  border: none;
  cursor: pointer;
}

ul,
ol {
  list-style: none;
}

img,
svg {
  display: block;
  max-width: 100%;
}

/* Canvas connection SVG must not shrink to the zero-sized world box */
.canvas-world,
.present-world {
  overflow: visible;
}

.connections-layer,
.canvas-world > svg,
.present-world > svg {
  max-width: none !important;
  max-height: none !important;
  overflow: visible !important;
  flex-shrink: 0;
}

[hidden] {
  display: none !important;
}

/* ============================================
   3. Common Elements
   ============================================ */
#app {
  height: 100%;
  display: flex;
  flex-direction: column;
}

.view {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  transition: background var(--transition), color var(--transition);
}

.icon-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.icon-btn:active {
  background: var(--border);
}

.icon-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  pointer-events: none;
}

.icon-btn-sm {
  width: 28px;
  height: 28px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-weight: 500;
  font-size: 13px;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
  border: 1px solid transparent;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-ghost.is-active,
.settings-option.is-active,
#btn-line-color-auto.is-active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-hover);
}

.btn-ghost {
  color: var(--text-secondary);
  border-color: var(--border);
  background: var(--bg-panel);
}

.btn-ghost:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

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

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

.btn-sm {
  padding: 5px 10px;
  font-size: 12px;
}

.empty-hint {
  color: var(--text-tertiary);
  font-size: 13px;
  padding: 20px 0;
  text-align: center;
}

.narrow-notice {
  position: fixed;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 8px 16px;
  font-size: 12px;
  color: var(--text-secondary);
  box-shadow: var(--shadow-md);
  max-width: calc(100% - 24px);
  text-align: center;
}

[data-theme="light"] .icon-moon,
[data-theme="dark"] .icon-sun {
  display: none !important;
}

[data-theme="dark"] .icon-moon,
[data-theme="light"] .icon-sun {
  display: block !important;
}

/* ============================================
   4. Home Screen
   ============================================ */
.view-home {
  overflow-y: auto;
  background:
    radial-gradient(ellipse 70% 45% at 15% -10%, rgba(45, 212, 191, 0.22), transparent 55%),
    radial-gradient(ellipse 60% 40% at 90% 5%, rgba(14, 165, 233, 0.16), transparent 50%),
    radial-gradient(ellipse 50% 35% at 50% 100%, rgba(251, 146, 60, 0.08), transparent 55%),
    var(--bg-app);
}

.home-header {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--header-height);
  padding: 0 28px;
  background: color-mix(in srgb, var(--bg-app) 78%, transparent);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid color-mix(in srgb, var(--border) 70%, transparent);
}

.home-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-emoji {
  font-size: 26px;
  line-height: 1;
  filter: drop-shadow(0 2px 4px rgba(13, 148, 136, 0.2));
  animation: logo-pop 0.6s ease both;
}

@keyframes logo-pop {
  from { transform: scale(0.85); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.brand-name {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--text-primary);
}

.home-header-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.home-main {
  max-width: 980px;
  width: 100%;
  margin: 0 auto;
  padding: 28px 28px 64px;
}

.home-hero {
  text-align: center;
  margin-bottom: 28px;
  animation: hero-in 0.5s ease both;
}

@keyframes hero-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.home-hero-kicker {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--accent-hover);
  background: var(--accent-soft);
  padding: 6px 12px;
  border-radius: 999px;
  margin-bottom: 14px;
}

.home-hero-title {
  margin-bottom: 10px;
}

.brand-hero {
  font-family: var(--font-display);
  font-size: clamp(2rem, 5vw, 2.75rem);
  font-weight: 800;
  letter-spacing: -0.04em;
  background: linear-gradient(120deg, #0f766e 0%, #0284c7 55%, #0d9488 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

[data-theme="dark"] .brand-hero {
  background: linear-gradient(120deg, #5eead4 0%, #38bdf8 55%, #2dd4bf 100%);
  -webkit-background-clip: text;
  background-clip: text;
}

.home-hero-sub {
  max-width: 420px;
  margin: 0 auto;
  font-size: 15px;
  color: var(--text-secondary);
  line-height: 1.55;
}

.home-credit {
  margin-top: 48px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  text-align: center;
}

.home-credit p {
  font-size: 12px;
  color: var(--text-tertiary);
  line-height: 1.5;
}

.home-credit a {
  color: var(--text-secondary);
  text-decoration: none;
}

.home-credit a:hover {
  color: var(--accent);
  text-decoration: underline;
}

.start-cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 44px;
}

.start-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  text-align: left;
  padding: 22px 22px 18px;
  min-height: 200px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-sm);
  transition: border-color var(--transition), box-shadow 0.22s ease, transform 0.22s ease;
  overflow: hidden;
}

.start-card::after {
  content: "";
  position: absolute;
  inset: auto -20% -40% auto;
  width: 140px;
  height: 140px;
  border-radius: 50%;
  opacity: 0.35;
  pointer-events: none;
  transition: transform 0.3s ease;
}

.start-card--map::after { background: #99f6e4; }
.start-card--lesson::after { background: #7dd3fc; }
.start-card--blank::after { background: #fdba74; }

.start-card:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow-md);
  transform: translateY(-4px);
}

.start-card:hover::after {
  transform: scale(1.15);
}

.start-card:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.start-card-badge {
  position: absolute;
  top: 14px;
  right: 14px;
  font-size: 11px;
  font-weight: 700;
  color: #0369a1;
  background: #e0f2fe;
  padding: 3px 8px;
  border-radius: 999px;
  z-index: 1;
}

[data-theme="dark"] .start-card-badge {
  color: #7dd3fc;
  background: #0c4a6e;
}

.start-card-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 52px;
  height: 52px;
  border-radius: 16px;
  font-size: 28px;
  margin-bottom: 16px;
  line-height: 1;
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--border) 80%, transparent);
}

.start-card--map .start-card-icon { background: #ccfbf1; }
.start-card--lesson .start-card-icon { background: #e0f2fe; }
.start-card--blank .start-card-icon { background: #ffedd5; }

[data-theme="dark"] .start-card--map .start-card-icon { background: #134e4a; }
[data-theme="dark"] .start-card--lesson .start-card-icon { background: #0c4a6e; }
[data-theme="dark"] .start-card--blank .start-card-icon { background: #7c2d12; }

.start-card-body {
  flex: 1;
  z-index: 1;
}

.start-card-title {
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 700;
  margin-bottom: 6px;
  letter-spacing: -0.02em;
}

.start-card-desc {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.45;
}

.start-card-cta {
  margin-top: 16px;
  font-size: 13px;
  font-weight: 700;
  color: var(--accent);
  z-index: 1;
  transition: transform var(--transition);
}

.start-card:hover .start-card-cta {
  transform: translateX(3px);
}

.home-section {
  margin-bottom: 36px;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.section-title {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 28px 16px;
  background: color-mix(in srgb, var(--bg-panel) 70%, transparent);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  text-align: center;
}

.empty-state-icon {
  font-size: 28px;
  line-height: 1;
  margin-bottom: 4px;
}

.empty-state-text {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
}

.empty-state-hint {
  font-size: 12px;
  color: var(--text-tertiary);
}

.empty-state .btn {
  margin-top: 10px;
}

.empty-hint {
  color: var(--text-tertiary);
  font-size: 13px;
  padding: 20px 0;
  text-align: center;
}

.recent-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 12px;
}

.recent-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  text-align: left;
  padding: 16px 18px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  transition: border-color var(--transition), box-shadow var(--transition), transform var(--transition);
  cursor: pointer;
  width: 100%;
}

.recent-card:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.recent-card-title {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 8px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

.recent-card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}

.meta-tag {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--bg-hover);
  color: var(--text-secondary);
}

.meta-tag.type {
  background: var(--accent-soft);
  color: var(--accent-hover);
}

.recent-card-time {
  font-size: 12px;
  color: var(--text-tertiary);
}

.workspace-tree {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 8px;
  min-height: 80px;
}

.tree-item {
  user-select: none;
}

.tree-row {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  min-height: 34px;
  transition: background var(--transition);
}

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

.tree-row.is-active {
  background: var(--accent-soft);
  color: var(--accent);
}

.tree-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  color: var(--text-tertiary);
  border-radius: 4px;
}

.tree-toggle:hover {
  background: var(--border);
  color: var(--text-primary);
}

.tree-toggle.is-leaf {
  visibility: hidden;
}

.tree-toggle svg {
  transition: transform var(--transition);
}

.tree-item.is-collapsed > .tree-children {
  display: none;
}

.tree-item.is-collapsed > .tree-row .tree-toggle svg {
  transform: rotate(-90deg);
}

.tree-label {
  flex: 1;
  min-width: 0;
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
  background: none;
  border: none;
  text-align: left;
  color: inherit;
  padding: 0;
}

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

.tree-row:hover .tree-actions,
.tree-row:focus-within .tree-actions {
  display: flex;
}

.tree-children {
  padding-left: 16px;
}

.tree-icon {
  flex-shrink: 0;
  color: var(--text-tertiary);
}

.tree-row.is-active .tree-icon {
  color: var(--accent);
}

/* ============================================
   5. Work Screen
   ============================================ */
.view-work {
  height: 100%;
}

.work-body {
  flex: 1;
  display: flex;
  min-height: 0;
  position: relative;
}

.view-work.is-left-collapsed .left-sidebar {
  width: 0 !important;
  min-width: 0;
  border: none;
  overflow: hidden;
}

.view-work.is-left-collapsed .sidebar-resize {
  display: none;
}

.view-work.is-right-collapsed .right-panel {
  width: 0 !important;
  min-width: 0;
  border: none;
  overflow: hidden;
}

.view-work.is-right-collapsed .panel-resize {
  display: none;
}

/* ============================================
   6. Sidebar
   ============================================ */
.left-sidebar {
  position: relative;
  width: var(--sidebar-width);
  min-width: 180px;
  max-width: 400px;
  flex-shrink: 0;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 10;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 12px 8px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-title {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
  padding-left: 4px;
}

.sidebar-tree {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.sidebar-resize,
.panel-resize {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 5px;
  cursor: col-resize;
  z-index: 20;
  background: transparent;
}

.sidebar-resize {
  right: -2px;
}

.panel-resize {
  left: -2px;
}

.sidebar-resize:hover,
.panel-resize:hover,
.sidebar-resize:focus-visible,
.panel-resize:focus-visible {
  background: var(--accent);
  opacity: 0.4;
}

/* ============================================
   7. Toolbar
   ============================================ */
.work-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--toolbar-height);
  padding: 0 12px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  gap: 12px;
  z-index: 30;
}

.toolbar-left,
.toolbar-center,
.toolbar-right {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
}

.toolbar-left {
  flex: 1;
}

.toolbar-center {
  flex-shrink: 0;
}

.toolbar-right {
  flex: 1;
  justify-content: flex-end;
}

.doc-title-input {
  flex: 1;
  min-width: 80px;
  max-width: 320px;
  padding: 6px 10px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 14px;
  letter-spacing: -0.02em;
  background: transparent;
  transition: border-color var(--transition), background var(--transition);
}

.doc-title-input:hover {
  background: var(--bg-hover);
}

.doc-title-input:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--bg-panel);
}

.save-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-tertiary);
  white-space: nowrap;
  padding: 0 8px;
}

.save-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--success);
  flex-shrink: 0;
}

.save-status.is-saving .save-dot {
  background: var(--warning);
  animation: pulse 1s ease infinite;
}

.save-status.is-error .save-dot {
  background: var(--danger);
}

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.4;
  }
}

.toolbar-divider {
  width: 1px;
  height: 20px;
  background: var(--border);
  margin: 0 4px;
}

.zoom-label {
  min-width: 48px;
  padding: 4px 6px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  text-align: center;
}

.zoom-label:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

/* ============================================
   8. Canvas
   ============================================ */
.canvas-area {
  flex: 1;
  min-width: 0;
  position: relative;
  background: var(--bg-canvas);
  overflow: hidden;
}

.canvas-viewport {
  width: 100%;
  height: 100%;
  overflow: hidden;
  cursor: grab;
  background-image: var(--dot-grid);
  background-size: var(--dot-size) var(--dot-size);
  position: relative;
  touch-action: none;
}

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

.canvas-viewport.is-space {
  cursor: grab;
}

.canvas-world {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
  will-change: transform;
}

.connections-layer {
  position: absolute;
  top: 0;
  left: 0;
  overflow: visible !important;
  pointer-events: none;
  z-index: 1;
  max-width: none !important;
  max-height: none !important;
}

.nodes-layer {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 2;
}

.canvas-empty {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  pointer-events: none;
  z-index: 0;
}

.canvas-empty-icon {
  font-size: 36px;
  line-height: 1;
  margin-bottom: 4px;
  animation: float-soft 2.4s ease-in-out infinite;
}

@keyframes float-soft {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

.canvas-empty p {
  color: var(--text-secondary);
  font-size: 15px;
  font-weight: 600;
}

.canvas-empty-hint {
  font-size: 12px !important;
  font-weight: 400 !important;
  color: var(--text-tertiary) !important;
}

.canvas-controls {
  position: absolute;
  bottom: 16px;
  right: 16px;
  pointer-events: none;
}

.zoom-display {
  font-size: 11px;
  color: var(--text-tertiary);
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 4px 8px;
  font-variant-numeric: tabular-nums;
  box-shadow: var(--shadow-sm);
}

.connection-line {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ============================================
   9. Nodes
   ============================================ */
.mind-node {
  position: absolute;
  min-width: 100px;
  max-width: var(--node-max-width);
  padding: 10px 14px;
  background: var(--bg-panel);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  cursor: grab;
  user-select: none;
  transition: box-shadow var(--transition), border-color var(--transition);
  word-break: break-word;
  z-index: 2;
  touch-action: none;
}

.mind-node:hover {
  box-shadow: 0 2px 8px rgba(31, 35, 40, 0.08);
}

.mind-node.is-selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  z-index: 5;
}

.mind-node.is-dragging {
  cursor: grabbing;
  opacity: 0.92;
  z-index: 10;
  box-shadow: var(--shadow-md);
}

.mind-node.is-center {
  min-width: 140px;
  max-width: 260px;
  padding: 14px 18px;
  font-weight: 600;
  border-width: 2px;
}

.mind-node.has-color {
  border-left-width: 4px;
}

.node-title {
  font-size: 13px;
  line-height: 1.4;
  outline: none;
  min-height: 1.2em;
}

.mind-node.is-center .node-title {
  font-size: 15px;
  text-align: center;
}

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

.node-badge {
  display: inline-block;
  font-size: 10px;
  margin-top: 4px;
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--bg-hover);
  color: var(--text-secondary);
}

.node-badge.is-high {
  background: var(--danger-soft);
  color: var(--danger);
}

.node-badge.is-done {
  background: var(--success-soft);
  color: var(--success);
}

/* ============================================
   10. Detail Panel
   ============================================ */
.right-panel {
  position: relative;
  width: var(--panel-width);
  min-width: 220px;
  max-width: 420px;
  flex-shrink: 0;
  background: var(--bg-panel);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 10;
}

.panel-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}

.panel-heading {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
  margin: 20px 0 10px;
}

.panel-heading:first-child {
  margin-top: 0;
}

.info-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.info-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
}

.info-row dt {
  color: var(--text-tertiary);
  flex-shrink: 0;
}

.info-row dd {
  text-align: right;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.shortcut-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 12px;
  color: var(--text-secondary);
}

.shortcut-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

kbd {
  display: inline-block;
  padding: 2px 6px;
  font-family: var(--font-mono);
  font-size: 11px;
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-primary);
}

.guide-text {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.55;
}

.field-label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  margin: 14px 0 6px;
}

.field-label:first-of-type {
  margin-top: 0;
}

.field-input,
.field-textarea,
.field-select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-app);
  transition: border-color var(--transition);
}

.field-input:focus,
.field-textarea:focus,
.field-select:focus {
  outline: none;
  border-color: var(--accent);
}

.field-textarea {
  resize: vertical;
  min-height: 100px;
  line-height: 1.5;
}

.color-swatches {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.color-swatch {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: var(--swatch, var(--bg-panel));
  transition: transform var(--transition), box-shadow var(--transition);
}

.color-swatch:hover {
  transform: scale(1.08);
}

.color-swatch.is-active {
  box-shadow: 0 0 0 2px var(--accent);
  border-color: var(--bg-panel);
}

.color-swatch[data-color=""] {
  background:
    linear-gradient(135deg, transparent 45%, var(--border-strong) 45%, var(--border-strong) 55%, transparent 55%),
    var(--bg-panel);
}

/* ============================================
   11. Modal
   ============================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(15, 18, 25, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  animation: fadeIn 120ms ease;
}

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

.modal {
  width: 100%;
  max-width: 420px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  animation: slideUp 160ms ease;
  outline: none;
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px 0;
}

.modal-title {
  font-size: 16px;
  font-weight: 600;
}

.modal-body {
  padding: 16px 18px;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 0 18px 18px;
}

.modal-body .field-label {
  margin-top: 0;
}

.modal-desc {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 12px;
  line-height: 1.5;
}

.settings-group {
  margin-bottom: 16px;
}

.settings-group:last-child {
  margin-bottom: 0;
}

.settings-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.settings-options {
  display: flex;
  gap: 8px;
}

.settings-option {
  flex: 1;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  text-align: center;
  font-size: 13px;
  transition: border-color var(--transition), background var(--transition);
}

.settings-option:hover {
  background: var(--bg-hover);
}

.settings-option.is-active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 500;
}

.search-results {
  max-height: 280px;
  overflow-y: auto;
  margin-top: 12px;
}

.search-result-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  transition: background var(--transition);
}

.search-result-item:hover {
  background: var(--bg-hover);
}

.search-result-title {
  font-weight: 500;
  font-size: 13px;
}

.search-result-meta {
  font-size: 12px;
  color: var(--text-tertiary);
  margin-top: 2px;
}

.context-menu {
  position: fixed;
  z-index: 1100;
  min-width: 160px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: 4px;
}

.context-menu-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--text-primary);
  text-align: left;
}

.context-menu-item:hover {
  background: var(--bg-hover);
}

.context-menu-item.is-danger {
  color: var(--danger);
}

.context-menu-sep {
  height: 1px;
  background: var(--border);
  margin: 4px 0;
}

.tooltip {
  position: fixed;
  z-index: 1200;
  padding: 5px 8px;
  font-size: 12px;
  background: var(--text-primary);
  color: var(--bg-panel);
  border-radius: 4px;
  pointer-events: none;
  white-space: nowrap;
  max-width: 240px;
  box-shadow: var(--shadow-sm);
}

[data-theme="dark"] .tooltip {
  background: #e8eaed;
  color: #12141a;
}

/* ============================================
   12. Dark Mode
   ============================================ */
[data-theme="dark"] .mind-node:hover {
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

[data-theme="dark"] .home-header {
  background: color-mix(in srgb, var(--bg-app) 90%, transparent);
}

/* ============================================
   13. Responsive
   ============================================ */
@media (max-width: 1024px) {
  .start-cards {
    grid-template-columns: 1fr;
  }

  .home-main {
    padding: 24px 20px 48px;
  }

  .home-hero-sub {
    max-width: none;
  }

  .left-sidebar {
    width: 220px;
  }

  .right-panel {
    width: 260px;
  }
}

@media (max-width: 768px) {
  .home-header {
    padding: 0 16px;
  }

  .work-toolbar {
    padding: 0 8px;
    gap: 4px;
  }

  .doc-title-input {
    max-width: 140px;
  }

  #save-status-text {
    display: none;
  }

  .left-sidebar {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 40;
    box-shadow: var(--shadow-lg);
  }

  .right-panel {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    z-index: 40;
    box-shadow: var(--shadow-lg);
  }

  .view-work.is-left-collapsed .left-sidebar,
  .view-work.is-right-collapsed .right-panel {
    box-shadow: none;
  }

  .recent-list {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  .brand-name {
    font-size: 16px;
  }

  .toolbar-center {
    gap: 0;
  }
}

/* ============================================
   14. Accessibility
   ============================================ */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.icon-btn:focus-visible,
.btn:focus-visible,
.start-card:focus-visible,
.tree-label:focus-visible,
.color-swatch:focus-visible,
.settings-option:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.mind-node:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

.sidebar-tree::-webkit-scrollbar,
.panel-content::-webkit-scrollbar,
.workspace-tree::-webkit-scrollbar,
.view-home::-webkit-scrollbar {
  width: 6px;
}

.sidebar-tree::-webkit-scrollbar-thumb,
.panel-content::-webkit-scrollbar-thumb,
.workspace-tree::-webkit-scrollbar-thumb,
.view-home::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 3px;
}

/* ============================================
   15. Phase 2 — Nodes, Relations, Selection
   ============================================ */
.icon-btn.is-active {
  background: var(--accent-soft);
  color: var(--accent);
}

.mind-node {
  transition: box-shadow var(--transition), border-color var(--transition), left 180ms ease, top 180ms ease;
}

.mind-node.is-dragging,
.mind-node.no-anim {
  transition: none;
}

.mind-node.shape-rect {
  border-radius: 4px;
}

.mind-node.shape-capsule {
  border-radius: 999px;
  padding-left: 18px;
  padding-right: 18px;
}

.mind-node.shape-underline {
  border-radius: 0;
  border-width: 0 0 2.5px 0;
  background: transparent;
  box-shadow: none;
  padding-left: 4px;
  padding-right: 4px;
}

.mind-node.shape-underline.is-selected {
  box-shadow: none;
  background: var(--accent-soft);
}

.mind-node.is-relation-source {
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 45%, transparent);
  border-color: var(--accent);
}

.mind-node.is-hidden-collapsed {
  display: none !important;
}

.mind-node.is-sticky {
  background: #fef9c3;
  border-color: #fde047;
}

[data-theme="dark"] .mind-node.is-sticky {
  background: #3f3a1e;
  border-color: #a16207;
}

.mind-node .node-icon {
  display: inline-block;
  margin-right: 4px;
}

.mind-node .node-thumb {
  display: block;
  width: 100%;
  max-height: 80px;
  object-fit: cover;
  border-radius: 6px;
  margin-bottom: 6px;
}

.node-add-btn,
.node-collapse-btn {
  position: absolute;
  display: none;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--bg-panel);
  border: 1.5px solid var(--border);
  color: var(--text-secondary);
  z-index: 6;
  box-shadow: var(--shadow-sm);
}

.mind-node:hover .node-add-btn,
.mind-node.is-selected .node-add-btn,
.mind-node:hover .node-collapse-btn,
.mind-node.is-selected .node-collapse-btn,
.mind-node.has-children .node-collapse-btn {
  display: inline-flex;
}

.node-add-btn {
  right: -11px;
  top: 50%;
  transform: translateY(-50%);
}

.node-add-btn:hover,
.node-collapse-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
}

.node-collapse-btn {
  left: -11px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 10px;
  font-weight: 600;
}

.node-collapse-badge {
  font-size: 10px;
  color: var(--text-tertiary);
  margin-left: 4px;
  font-weight: 500;
}

.connection-line.hierarchy {
  fill: none;
  stroke: var(--link-color, var(--accent));
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0.95;
  pointer-events: none;
}

.connection-line.relation {
  fill: none;
  stroke-width: 2.5;
  stroke-linecap: round;
  cursor: pointer;
  pointer-events: stroke;
  opacity: 0.9;
}

.connection-line.relation.is-selected {
  stroke: var(--accent) !important;
  stroke-width: 3;
}

.connection-line.relation.dashed {
  stroke-dasharray: 6 4;
}

.relation-label {
  font-size: 11px;
  fill: var(--text-secondary);
  pointer-events: none;
}

.selection-box {
  position: absolute;
  border: 1.5px dashed var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  pointer-events: none;
  z-index: 50;
}

.multi-toolbar {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
}

.multi-count {
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  padding: 0 6px;
}

.minimap {
  position: absolute;
  right: 16px;
  bottom: 48px;
  z-index: 30;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  width: 160px;
}

.minimap.is-collapsed {
  width: auto;
  height: auto;
}

.minimap.is-collapsed canvas {
  display: none;
}

.minimap-toggle {
  position: absolute;
  top: 2px;
  right: 2px;
  z-index: 2;
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-tertiary);
  border-radius: 4px;
}

.minimap-toggle:hover {
  background: var(--bg-hover);
}

#minimap-canvas {
  display: block;
  cursor: pointer;
  width: 160px;
  height: 100px;
}

.canvas-mode {
  position: relative;
  width: 100%;
  height: 100%;
}

.document-mode {
  height: 100%;
  overflow-y: auto;
  background: var(--bg-canvas);
  padding: 28px 32px 64px;
}

.document-mode-header {
  max-width: 720px;
  margin: 0 auto 24px;
}

.document-mode-title {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 4px;
}

.document-mode-hint {
  font-size: 13px;
  color: var(--text-secondary);
}

.document-outline {
  max-width: 720px;
  margin: 0 auto;
}

.doc-item {
  border-left: 2px solid var(--border);
  margin-left: 0;
}

.doc-item-row {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  margin-bottom: 2px;
}

.doc-item-row:hover {
  background: var(--bg-hover);
}

.doc-item-row.is-selected {
  background: var(--accent-soft);
  border-left-color: var(--accent);
}

.doc-item-toggle {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  color: var(--text-tertiary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  margin-top: 1px;
}

.doc-item-toggle:hover {
  background: var(--border);
}

.doc-item-title {
  flex: 1;
  font-size: 14px;
  font-weight: 500;
  border: none;
  background: transparent;
  outline: none;
  min-width: 0;
  padding: 2px 4px;
  border-radius: 4px;
}

.doc-item-title:focus {
  background: var(--bg-panel);
  box-shadow: 0 0 0 1.5px var(--accent);
}

.doc-item-note {
  font-size: 12px;
  color: var(--text-tertiary);
  margin: 0 0 4px 34px;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.doc-item-children {
  padding-left: 20px;
}

.doc-item.is-collapsed > .doc-item-children {
  display: none;
}

.doc-move-btns {
  display: none;
  gap: 2px;
}

.doc-item-row:hover .doc-move-btns {
  display: flex;
}

.note-toolbar {
  display: flex;
  gap: 2px;
  margin-bottom: 6px;
  padding: 4px;
  background: var(--bg-hover);
  border-radius: var(--radius-sm);
}

.note-editor {
  min-height: 100px;
  max-height: 220px;
  overflow-y: auto;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-app);
  line-height: 1.55;
  font-size: 13px;
}

.note-editor:focus {
  outline: none;
  border-color: var(--accent);
}

.note-editor:empty::before {
  content: attr(data-placeholder);
  color: var(--text-tertiary);
}

.checklist-editor,
.links-editor {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 8px;
}

.check-item,
.link-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.check-item input[type="text"],
.link-item input {
  flex: 1;
  min-width: 0;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-app);
  font-size: 12px;
}

.check-item.is-done input[type="text"] {
  text-decoration: line-through;
  color: var(--text-tertiary);
}

.image-preview img {
  max-width: 100%;
  max-height: 140px;
  border-radius: var(--radius-sm);
  object-fit: cover;
}

.image-actions {
  display: flex;
  gap: 6px;
  margin-top: 6px;
}

.field-hint {
  font-size: 11px;
  color: var(--text-tertiary);
  margin-top: 4px;
}

.field-label-sm {
  font-size: 11px;
  color: var(--text-tertiary);
  margin: 8px 0 4px;
}

.style-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 10px;
}

.custom-color-row {
  display: flex;
  gap: 8px;
  margin-top: 8px;
  align-items: center;
}

.custom-color {
  width: 36px;
  height: 32px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 2px;
  background: var(--bg-app);
  cursor: pointer;
}

.field-row-check {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 14px;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
}

.search-highlight {
  background: color-mix(in srgb, var(--warning) 40%, transparent);
  border-radius: 2px;
  padding: 0 1px;
}

.shortcut-help-grid {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 16px;
  font-size: 13px;
}

.shortcut-help-grid dt {
  color: var(--text-secondary);
}

.shortcut-help-grid dd {
  text-align: right;
}

.layout-options {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.card-type-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

@media (max-width: 768px) {
  .minimap {
    display: none;
  }

  .multi-toolbar {
    max-width: calc(100% - 24px);
    flex-wrap: wrap;
    justify-content: center;
  }

  .document-mode {
    padding: 16px;
  }
}

/* ============================================
   Phase 3 — density
   ============================================ */
[data-density="comfortable"] {
  --node-pad-y: 12px;
  --node-pad-x: 16px;
  --row-gap: 10px;
}

[data-density="comfortable"] body {
  font-size: 14.5px;
}

[data-density="comfortable"] .mind-node {
  padding: 12px 16px;
}

[data-density="compact"] {
  --node-pad-y: 5px;
  --node-pad-x: 9px;
  --row-gap: 4px;
}

[data-density="compact"] body {
  font-size: 13px;
}

[data-density="compact"] .mind-node {
  padding: 5px 9px;
}

[data-density="compact"] .tree-item-row,
[data-density="compact"] .doc-item-row {
  padding-top: 3px;
  padding-bottom: 3px;
}

[data-density="comfortable"] .tree-item-row,
[data-density="comfortable"] .doc-item-row {
  padding-top: 8px;
  padding-bottom: 8px;
}

/* ============================================
   Phase 3 — subject accents
   ============================================ */
[data-subject="korean"] {
  --accent: #c2410c;
  --accent-hover: #9a3412;
  --accent-soft: #fff2ea;
}

[data-subject="math"] {
  --accent: #1d4ed8;
  --accent-hover: #1e40af;
  --accent-soft: #eaf0ff;
}

[data-subject="english"] {
  --accent: #7c3aed;
  --accent-hover: #6d28d9;
  --accent-soft: #f3edff;
}

[data-subject="social"] {
  --accent: #b45309;
  --accent-hover: #92400e;
  --accent-soft: #fdf3e3;
}

[data-subject="science"] {
  --accent: #047857;
  --accent-hover: #065f46;
  --accent-soft: #e7f6ef;
}

[data-subject="arts"] {
  --accent: #db2777;
  --accent-hover: #be185d;
  --accent-soft: #fdeef5;
}

[data-theme="dark"][data-subject="korean"] {
  --accent: #fb923c;
  --accent-soft: #33231a;
}

[data-theme="dark"][data-subject="math"] {
  --accent: #60a5fa;
  --accent-soft: #17233a;
}

[data-theme="dark"][data-subject="english"] {
  --accent: #a78bfa;
  --accent-soft: #241f3a;
}

[data-theme="dark"][data-subject="social"] {
  --accent: #fbbf24;
  --accent-soft: #322616;
}

[data-theme="dark"][data-subject="science"] {
  --accent: #34d399;
  --accent-soft: #142c25;
}

[data-theme="dark"][data-subject="arts"] {
  --accent: #f472b6;
  --accent-soft: #331b27;
}

/* ============================================
   Phase 3 — template gallery
   ============================================ */
.modal.is-wide {
  max-width: 880px;
  width: min(880px, calc(100vw - 32px));
}

.template-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px;
  margin-top: 4px;
}

.template-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-align: left;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-panel);
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition),
    transform var(--transition), box-shadow var(--transition);
  box-shadow: var(--shadow-sm);
}

.template-card:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
}

.template-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 14px;
  font-size: 24px;
  line-height: 1;
  background: var(--bg-hover);
  margin-bottom: 4px;
}

.template-name {
  font-weight: 600;
  font-size: 14px;
}

.template-desc {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.45;
}

.template-use {
  font-size: 11px;
  color: var(--accent);
}

.template-preview {
  margin-top: 4px;
  font-size: 11px;
  color: var(--text-tertiary);
  line-height: 1.4;
}

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

.note-block-row {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 6px;
}

/* ============================================
   Phase 3 — presentation order panel
   ============================================ */
.order-actions {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.order-list {
  max-height: 340px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.order-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-panel);
}

.order-index {
  min-width: 22px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 11px;
  font-weight: 600;
}

.order-title {
  flex: 1;
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ============================================
   Phase 3 — presentation mode
   ============================================ */
.present-overlay {
  position: fixed;
  inset: 0;
  z-index: 400;
  display: flex;
  flex-direction: column;
  background: var(--bg-canvas);
}

.present-overlay[hidden] {
  display: none;
}

body.is-presenting #app {
  visibility: hidden;
}

.present-stage {
  flex: 1;
  display: flex;
  min-height: 0;
}

.present-viewport {
  position: relative;
  flex: 1;
  overflow: hidden;
  background-image: var(--dot-grid);
  background-size: var(--dot-size) var(--dot-size);
}

.present-world {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
  transition: transform 320ms cubic-bezier(0.22, 0.61, 0.36, 1);
}

.present-connections {
  position: absolute;
  top: 0;
  left: 0;
  overflow: visible;
  pointer-events: none;
}

.present-node {
  position: absolute;
  transition: opacity 240ms ease, filter 240ms ease, box-shadow 240ms ease;
  cursor: default;
}

.present-node.is-present-hidden,
.present-connections .is-present-hidden {
  opacity: 0;
  pointer-events: none;
}

.present-node.is-present-current {
  box-shadow: 0 0 0 3px var(--accent), var(--shadow-lg);
}

.present-connections path {
  transition: opacity 240ms ease;
}

.present-notes {
  width: 340px;
  flex-shrink: 0;
  border-left: 1px solid var(--border);
  background: var(--bg-panel);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.present-notes[hidden] {
  display: none;
}

.present-notes-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.present-notes-body {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  font-size: 14px;
  line-height: 1.65;
}

.present-note-title {
  font-size: 16px;
  margin-bottom: 8px;
}

.present-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  background: var(--bg-panel);
}

.present-bar-spacer {
  flex: 1;
}

.present-btn {
  min-width: 38px;
  height: 34px;
  padding: 0 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-panel);
  color: var(--text-secondary);
  font-size: 13px;
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
}

.present-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.present-btn-exit:hover {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: var(--danger);
}

.present-progress {
  min-width: 72px;
  text-align: center;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  color: var(--text-secondary);
}

/* ============================================
   Phase 3 — onboarding
   ============================================ */
.onboarding {
  position: fixed;
  inset: 0;
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15, 18, 25, 0.45);
  padding: 20px;
}

.onboarding[hidden] {
  display: none;
}

.onboarding-card {
  width: min(440px, 100%);
  background: var(--bg-panel);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 26px;
}

.onboarding-progress {
  display: flex;
  gap: 6px;
  margin-bottom: 16px;
}

.onboard-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--border-strong);
  transition: background var(--transition), width var(--transition);
}

.onboard-dot.is-active {
  width: 20px;
  border-radius: 4px;
  background: var(--accent);
}

.onboarding-title {
  font-size: 19px;
  margin-bottom: 8px;
}

.onboarding-desc {
  font-size: 14px;
  line-height: 1.65;
  color: var(--text-secondary);
  margin-bottom: 22px;
}

.onboarding-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.onboard-dont {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-tertiary);
  cursor: pointer;
}

/* ============================================
   Phase 3 — read-only
   ============================================ */
.readonly-banner {
  position: fixed;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 300;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 7px 10px 7px 16px;
  border-radius: 999px;
  background: var(--warning);
  color: #1f2328;
  font-size: 13px;
  font-weight: 600;
  box-shadow: var(--shadow-md);
}

.readonly-banner[hidden] {
  display: none;
}

body.is-readonly .mind-node {
  cursor: default;
}

body.is-readonly .node-add-btn,
body.is-readonly .node-collapse-btn,
body.is-readonly .multi-toolbar,
body.is-readonly #btn-add-card,
body.is-readonly #btn-relation-tool,
body.is-readonly #btn-layout,
body.is-readonly #btn-insert-block {
  display: none;
}

body.is-readonly .canvas-empty {
  display: none;
}

/* ============================================
   Phase 3 — export / version / storage modals
   ============================================ */
.export-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--border);
}

.export-tab {
  padding: 8px 14px;
  font-size: 13px;
  color: var(--text-secondary);
  border-bottom: 2px solid transparent;
  cursor: pointer;
}

.export-tab.is-active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 600;
}

.export-preview {
  margin-top: 12px;
  max-height: 300px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-hover);
}

.export-preview:empty {
  display: none;
}

.export-preview img {
  display: block;
  max-width: 100%;
}

.export-status {
  margin-top: 10px;
  font-size: 12px;
  color: var(--text-secondary);
}

.export-status.is-error {
  color: var(--danger);
}

.import-preview {
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-hover);
  margin-bottom: 12px;
}

.import-title {
  font-weight: 600;
  font-size: 15px;
}

.import-meta {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 3px;
}

.import-sample {
  font-size: 12px;
  color: var(--text-tertiary);
  margin-top: 8px;
  line-height: 1.5;
}

.version-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 340px;
  overflow-y: auto;
}

.version-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.version-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.version-time {
  font-size: 13px;
  font-weight: 600;
}

.version-reason,
.version-count {
  font-size: 11px;
  color: var(--text-secondary);
}

.version-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.storage-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}

.storage-stats > div {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  text-align: center;
}

.storage-stats span {
  font-size: 11px;
  color: var(--text-secondary);
}

.storage-stats strong {
  font-size: 16px;
}

.settings-section-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-tertiary);
  margin: 18px 0 8px;
}

.settings-section-title:first-child {
  margin-top: 0;
}

.settings-option.is-danger {
  color: var(--danger);
}

.settings-option.is-danger:hover {
  background: var(--danger-soft);
}

.error-details {
  margin-top: 10px;
  font-size: 12px;
  color: var(--text-secondary);
}

.error-details pre {
  margin-top: 6px;
  padding: 8px;
  border-radius: var(--radius-sm);
  background: var(--bg-hover);
  white-space: pre-wrap;
  word-break: break-all;
  font-family: var(--font-mono);
  font-size: 11px;
}

.icon-btn-sm {
  width: 24px;
  height: 24px;
  font-size: 13px;
  line-height: 1;
}

/* the export cluster collapses into #btn-toolbar-more on narrow screens */
body.is-toolbar-narrow #btn-export,
body.is-toolbar-narrow #btn-import,
body.is-toolbar-narrow #btn-print,
body.is-toolbar-narrow #btn-present-order {
  display: none;
}

/* ============================================
   Phase 3 — print
   ============================================ */
@media print {
  @page {
    margin: 12mm;
  }

  html,
  body {
    height: auto !important;
    overflow: visible !important;
    background: #ffffff !important;
  }

  /* chrome + home must never appear on the sheet */
  .view-home,
  #view-home,
  .home-header,
  .home-main,
  .work-toolbar,
  .left-sidebar,
  .right-panel,
  .minimap,
  .multi-toolbar,
  .canvas-controls,
  .selection-box,
  .canvas-empty,
  .context-menu,
  .tooltip,
  .modal-overlay,
  .save-status,
  .present-overlay,
  .onboarding,
  .readonly-banner,
  .narrow-notice,
  .sidebar-resize,
  .panel-resize,
  .node-add-btn,
  .node-collapse-btn,
  .toolbar-divider,
  .icon-btn,
  .btn,
  .start-cards,
  .recent-list,
  .workspace-tree,
  .home-credit,
  .home-hero {
    display: none !important;
  }

  /* only the open work document participates */
  #app,
  #view-work,
  .view-work,
  .work-body,
  .canvas-area {
    position: static !important;
    display: block !important;
    overflow: visible !important;
    height: auto !important;
    max-height: none !important;
    width: auto !important;
    border: none !important;
    box-shadow: none !important;
    background: #ffffff !important;
    flex: none !important;
  }

  .print-doc-title {
    display: block !important;
    margin: 0 0 8mm;
    font-size: 16pt;
    font-weight: 700;
    color: #111 !important;
  }

  /* print mode picks canvas vs outline — never force both open */
  body[data-print-mode="outline"] #canvas-mode,
  body[data-print-mode="outline"] .canvas-mode {
    display: none !important;
  }

  body[data-print-mode="canvas"] #document-mode,
  body[data-print-mode="canvas"] .document-mode {
    display: none !important;
  }

  body[data-print-mode="outline"] #document-mode,
  body[data-print-mode="outline"] .document-mode {
    display: block !important;
    position: static !important;
    overflow: visible !important;
    height: auto !important;
    max-height: none !important;
    width: auto !important;
    border: none !important;
    background: #ffffff !important;
  }

  body[data-print-mode="canvas"] #canvas-mode,
  body[data-print-mode="canvas"] .canvas-mode {
    display: block !important;
    position: static !important;
    overflow: visible !important;
    height: auto !important;
    width: auto !important;
    border: none !important;
    background: #ffffff !important;
  }

  /*
   * Viewport is sized to the printable area BEFORE window.print() so fitView
   * matches what lands on paper. Keep overflow hidden to crop chrome-free.
   */
  body[data-print-mode="canvas"] .canvas-viewport {
    position: relative !important;
    width: 100% !important;
    height: 170mm !important;
    overflow: hidden !important;
    background-image: none !important;
    background: #ffffff !important;
    border: none !important;
    cursor: default !important;
  }

  body[data-print-mode="canvas"] .canvas-world {
    background: transparent !important;
  }

  .mind-node {
    box-shadow: none !important;
    break-inside: avoid;
  }

  .mind-node.is-selected,
  .mind-node.is-primary {
    outline: none !important;
    box-shadow: none !important;
  }

  .connection-line {
    stroke: #0d9488 !important;
  }

  body:not(.print-with-notes) .node-note-preview {
    display: none !important;
  }

  .document-mode-header {
    display: none !important;
  }

  .doc-item-row {
    break-inside: avoid;
  }
}

/* screen: print title is JS-injected only while printing */
.print-doc-title {
  display: none;
}

@media (max-width: 900px) {
  .present-notes {
    position: absolute;
    inset: 0;
    width: 100%;
    border-left: none;
  }

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

  .storage-stats {
    grid-template-columns: 1fr;
  }

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