:root {
  --panel: #ffffff;
  --ink: #172026;
  --muted: #65717a;
  --line: #d8e2ea;
  --accent: #8fd6c7;
  --canvas: #f7fbff;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  font-family: "Malgun Gothic", "Apple SD Gothic Neo", sans-serif;
  background: #edf3f7;
}

button,
input,
select,
textarea,
.rich-editor {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  grid-template-rows: 66px minmax(0, 1fr);
  height: 100vh;
  overflow: hidden;
}

.app-shell.sidebar-collapsed {
  grid-template-columns: 48px minmax(0, 1fr);
}

.app-header {
  grid-column: 1 / -1;
  display: grid;
  place-items: center;
  background: #ffffff;
  border-bottom: 3px solid #0d5572;
}

.settings-panel {
  grid-column: 1;
  grid-row: 2;
  position: relative;
  background: var(--panel);
  border-right: 1px solid var(--line);
  overflow-y: auto;
  padding: 22px;
}

.sidebar-toggle {
  position: absolute;
  top: 18px;
  right: 16px;
  z-index: 4;
  display: grid;
  place-items: center;
  width: 44px;
  height: 34px;
  min-height: 0;
  padding: 0;
  border: 1px solid #9db4c0;
  background: #f9fcfe;
  color: #183544;
  font-size: 26px;
  font-weight: 800;
  line-height: 1;
}

.chevron-pair {
  transform: translateY(-1px);
}

.app-shell.sidebar-collapsed .settings-panel {
  padding: 0;
  overflow: hidden;
}

.app-shell.sidebar-collapsed .settings-panel > :not(.sidebar-toggle) {
  display: none;
}

.app-shell.sidebar-collapsed .sidebar-toggle {
  top: 18px;
  right: 2px;
}

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

.brand-logo {
  width: 48px;
  height: 48px;
  object-fit: cover;
  border-radius: 10px;
  box-shadow: 0 1px 4px rgba(20, 36, 48, 0.18);
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 28px;
  letter-spacing: 0;
}

.detail-kicker,
#zoomLabel {
  color: var(--muted);
  font-size: 12px;
}

.panel-title {
  min-height: 36px;
  padding-right: 58px;
  font-size: 16px;
  font-weight: 500;
}

.control-group {
  border-top: 1px solid var(--line);
  padding: 18px 0;
}

.control-group h2 {
  font-size: 13px;
  margin-bottom: 12px;
}

label {
  display: grid;
  gap: 7px;
  margin-bottom: 12px;
  color: #33414a;
  font-size: 12px;
}

input,
select,
button,
textarea,
.rich-editor {
  border: 1px solid #cbd8e1;
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
}

input,
select {
  min-height: 34px;
  padding: 6px 8px;
}

input[type="color"] {
  width: 100%;
  height: 38px;
  padding: 4px;
}

button {
  min-height: 36px;
  padding: 8px 12px;
  cursor: pointer;
}

button:hover {
  border-color: #7da9c8;
}

.two-col,
.button-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.wide-button {
  width: 100%;
  background: #e7f6f2;
}

.button-row + .wide-button {
  margin-top: 10px;
}

.level-counts,
.level-colors {
  display: grid;
  gap: 8px;
}

.level-row {
  display: grid;
  grid-template-columns: 76px 1fr;
  align-items: center;
  gap: 8px;
}

.workspace {
  grid-column: 2;
  grid-row: 2;
  display: grid;
  grid-template-rows: 58px minmax(0, 1fr);
  min-width: 0;
}

.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 12px 18px;
  background: #fbfdff;
  border-bottom: 1px solid var(--line);
}

.toolbar-left {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-shrink: 0;
}

.toolbar-search {
  position: relative;
  flex: 1;
  min-width: 0;
  max-width: 340px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.toolbar-search input[type="search"] {
  flex: 1;
  min-width: 0;
  min-height: 32px;
  padding: 4px 10px;
}

.search-count {
  flex-shrink: 0;
  color: var(--muted);
  font-size: 12px;
  min-width: 36px;
}

.search-results {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 30;
  margin: 0;
  padding: 4px;
  list-style: none;
  max-height: 320px;
  overflow-y: auto;
  background: #fff;
  border: 1px solid #cbd8e1;
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(20, 36, 48, 0.16);
  display: none;
}

.search-results.is-open {
  display: block;
}

.search-results li {
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
}

.search-results li:hover,
.search-results li.is-focused {
  background: #eaf3fb;
}

.search-results .result-label {
  font-weight: 600;
  color: var(--ink);
}

.search-results .result-path {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
}

.search-results .result-snippet {
  display: block;
  margin-top: 4px;
  color: #4a5860;
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.search-results mark {
  background: #fff3a3;
  color: inherit;
  padding: 0 2px;
  border-radius: 2px;
}

.search-results .no-result {
  padding: 12px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
  cursor: default;
}

.toolbar-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.mindmap-frame {
  position: relative;
  overflow: hidden;
  background: var(--canvas);
  cursor: grab;
  touch-action: none;
}

.mindmap-frame.is-panning {
  cursor: grabbing;
}

#mindmapSvg {
  width: 100%;
  height: 100%;
  display: block;
}

.branch-line {
  fill: none;
  stroke-linecap: round;
  stroke-width: 3;
}

.node-rect {
  stroke: rgba(32, 47, 57, 0.18);
  stroke-width: 1;
  filter: drop-shadow(0 8px 12px rgba(38, 60, 78, 0.08));
}

.node-text {
  dominant-baseline: middle;
  text-anchor: middle;
  pointer-events: none;
  user-select: none;
}

.node-group {
  cursor: pointer;
}

.toggle-button circle {
  stroke: rgba(32, 47, 57, 0.2);
  stroke-width: 1;
}

.toggle-button text {
  fill: #111;
  font-weight: 800;
  dominant-baseline: middle;
  text-anchor: middle;
  pointer-events: none;
  user-select: none;
}

.detail-page {
  display: none;
  min-height: 100vh;
  padding: 28px;
  background: #f5f8fb;
}

.detail-page.is-open {
  display: block;
}

.detail-page article {
  max-width: 920px;
  margin: 24px auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 32px;
}

.back-button {
  background: #dfefff;
}

.format-panel {
  display: grid;
  gap: 10px;
  margin: 14px 0 18px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fbfd;
}

.format-row {
  display: grid;
  grid-template-columns: 58px minmax(150px, 1fr) 72px 38px 38px 38px 48px 54px;
  gap: 8px;
  align-items: center;
}

.format-row span {
  color: var(--muted);
  font-size: 12px;
}

.format-row button {
  min-width: 0;
  padding: 6px;
  font-weight: 700;
}

.format-row button.is-active {
  background: #cdeee8;
  border-color: #72b9ad;
}

.detail-title-input {
  display: block;
  width: 100%;
  min-height: 52px;
  margin: 8px 0 18px;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  padding: 0 0 10px;
  font-size: 30px;
  font-weight: 700;
  outline: none;
}

.detail-title-input:focus {
  border-bottom-color: #7da9c8;
}

.hidden-file {
  display: none;
}

.rich-editor {
  width: 100%;
  min-height: 56vh;
  padding: 18px;
  line-height: 1.7;
  overflow-y: auto;
  outline: none;
  white-space: pre-wrap;
}

.rich-editor:focus {
  border-color: #7da9c8;
}

.detail-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 18px;
}

.detail-actions .wide-button {
  width: auto;
  min-width: 210px;
}

.image-frame {
  display: inline-block;
  position: relative;
  width: 60%;
  min-width: 96px;
  max-width: 100%;
  margin: 6px 4px;
  padding: 4px;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: move;
  user-select: none;
  vertical-align: middle;
}

.image-frame img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 8px;
  pointer-events: none;
}

.image-frame.image-selected {
  outline: 3px solid #2b88b8;
  outline-offset: 3px;
}

.image-resize-handle {
  display: none;
  position: absolute;
  right: -7px;
  bottom: -7px;
  width: 15px;
  height: 15px;
  border: 2px solid #ffffff;
  border-radius: 4px;
  background: #2b88b8;
  box-shadow: 0 1px 5px rgba(0, 0, 0, 0.25);
  cursor: nwse-resize;
}

.image-frame.image-selected .image-resize-handle {
  display: block;
}

body.detail-open .app-shell {
  display: none;
}

@media (max-width: 860px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: 66px auto minmax(0, 1fr);
  }

  .settings-panel {
    grid-column: 1;
    grid-row: 2;
    max-height: 42vh;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .workspace {
    grid-column: 1;
    grid-row: 3;
  }

  .toolbar {
    align-items: stretch;
    flex-direction: column;
    gap: 8px;
  }

  .toolbar-search {
    max-width: none;
  }

  .format-row {
    grid-template-columns: 1fr 1fr 72px 38px 38px 38px 48px 54px;
  }

  .format-row span {
    grid-column: 1 / -1;
  }
}

.autosave-toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 50;
  padding: 10px 16px;
  border-radius: 999px;
  background: rgba(23, 32, 38, 0.86);
  color: #fff;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.2px;
  box-shadow: 0 6px 18px rgba(20, 36, 48, 0.18);
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.autosave-toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.canvas-hint {
  position: absolute;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  padding: 6px 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  pointer-events: none;
  z-index: 4;
  opacity: 1;
  transition: opacity 0.3s ease;
}

.canvas-hint.is-hidden {
  opacity: 0;
}

.context-menu {
  position: fixed;
  z-index: 60;
  min-width: 220px;
  margin: 0;
  padding: 6px;
  list-style: none;
  background: #fff;
  border: 1px solid #cbd8e1;
  border-radius: 10px;
  box-shadow: 0 10px 28px rgba(20, 36, 48, 0.22);
  font-size: 13px;
  display: none;
}

.context-menu.is-open {
  display: block;
}

.context-menu li[role="menuitem"] {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  border-radius: 6px;
  cursor: pointer;
  color: var(--ink);
}

.context-menu li[role="menuitem"]:hover {
  background: #eaf3fb;
}

.context-menu li.danger {
  color: #b3261e;
}

.context-menu li.danger:hover {
  background: #fbe9e7;
}

.context-menu li[aria-disabled="true"] {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

.context-menu .context-divider {
  height: 1px;
  margin: 4px 2px;
  background: var(--line);
}

.context-menu kbd {
  display: inline-block;
  padding: 1px 6px;
  border: 1px solid #cbd8e1;
  border-radius: 4px;
  background: #f4f7fa;
  color: var(--muted);
  font-size: 11px;
  font-family: "Consolas", monospace;
}

.node-rect.is-active-target {
  stroke: #2b88b8;
  stroke-width: 2.5;
  filter: drop-shadow(0 6px 14px rgba(43, 136, 184, 0.35));
}

.node-rect.is-drop-target {
  stroke: #2aa269;
  stroke-width: 3;
  stroke-dasharray: 6 4;
  filter: drop-shadow(0 6px 14px rgba(42, 162, 105, 0.4));
}

.node-rect.is-drop-invalid {
  stroke: #c14242;
  stroke-width: 2.5;
  stroke-dasharray: 4 4;
}

.node-rect.is-dragging-source {
  opacity: 0.45;
}

.node-rect.is-search-match {
  stroke: #d18a00;
  stroke-width: 2.5;
  filter: drop-shadow(0 6px 14px rgba(209, 138, 0, 0.4));
}

.mindmap-frame.is-dragging-node {
  cursor: grabbing;
}

.drag-ghost {
  position: fixed;
  z-index: 70;
  pointer-events: none;
  padding: 6px 12px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid #2b88b8;
  box-shadow: 0 6px 16px rgba(20, 36, 48, 0.18);
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: none;
  transform: translate(8px, 8px);
}

.drag-ghost.is-visible {
  display: block;
}

.drag-ghost.is-invalid {
  border-color: #c14242;
  background: rgba(253, 235, 235, 0.95);
}

#undoBtn:disabled,
#redoBtn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

@media print {
  .settings-panel,
  .toolbar,
  .detail-page {
    display: none !important;
  }

  .app-shell {
    display: block;
  }

  .workspace {
    display: block;
  }

  .mindmap-frame {
    height: 100vh;
  }
}
