:root {
  color-scheme: light dark;
  --mm-bg: #f6f5ef;
  --mm-surface: #fffefa;
  --mm-surface-soft: #efefe8;
  --mm-text: #1f2b24;
  --mm-muted: #6c756f;
  --mm-border: #dcdfd6;
  --mm-accent: #4b7255;
  --mm-accent-soft: #e4ede5;
  --mm-branch-0: #4f6f9a;
  --mm-branch-1: #4b7a5a;
  --mm-branch-2: #b0793d;
  --mm-branch-3: #7b6aa6;
  --mm-font: "Pretendard Variable", Pretendard, "Noto Sans KR", "Apple SD Gothic Neo", "Malgun Gothic", system-ui, sans-serif;
  --mm-radius: 14px;
  --mm-radius-sm: 10px;
  --mm-ease: cubic-bezier(.22, .8, .24, 1);
  --mm-shadow: 0 1px 2px rgb(24 36 28 / 6%), 0 4px 14px rgb(24 36 28 / 6%);
  --mm-grid: rgb(31 43 36 / 9%);
  --mm-bar-h: 52px;
  --mm-control: 40px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --mm-bg: #121614;
    --mm-surface: #1a201c;
    --mm-surface-soft: #232b26;
    --mm-text: #e3eae4;
    --mm-muted: #9aa69e;
    --mm-border: #313b35;
    --mm-accent: #8fbf9b;
    --mm-accent-soft: #24352a;
    --mm-branch-0: #86a3cc;
    --mm-branch-1: #85b893;
    --mm-branch-2: #d3a46f;
    --mm-branch-3: #b3a5d9;
    --mm-shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 6px 18px rgb(0 0 0 / 28%);
    --mm-grid: rgb(227 234 228 / 7%);
  }
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--mm-bg);
  color: var(--mm-text);
  font-family: var(--mm-font);
  -webkit-tap-highlight-color: transparent;
  word-break: keep-all;
}

button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

.mm-app { position: fixed; inset: 0; }
.mm-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* Top bar */
.mm-bar {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 6px;
  height: calc(var(--mm-bar-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) max(12px, env(safe-area-inset-right)) 0 max(10px, env(safe-area-inset-left));
  border-bottom: 1px solid color-mix(in srgb, var(--mm-border) 75%, transparent);
  background: var(--mm-bg);
  pointer-events: none;
}
.mm-bar > * { pointer-events: auto; }
.mm-back {
  display: grid;
  place-items: center;
  width: var(--mm-control);
  height: var(--mm-control);
  border-radius: 50%;
  color: var(--mm-muted);
  text-decoration: none;
  transition: background-color .16s ease, color .16s ease;
}
.mm-back:hover { background: var(--mm-surface-soft); color: var(--mm-text); }
.mm-title {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -.01em;
}
.mm-account { margin-left: auto; display: flex; align-items: center; }
.mm-account > [hidden] { display: none; }
.mm-account-link,
.mm-account-state {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 0 12px;
  border-radius: 999px;
  color: var(--mm-muted);
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
}
.mm-account-link:hover { background: var(--mm-surface-soft); color: var(--mm-text); }
.mm-account-state { color: var(--mm-accent); background: var(--mm-accent-soft); }
.mm-import {
  margin-right: 6px;
  border: 1px solid var(--mm-border);
  background: transparent;
  cursor: pointer;
}
.mm-import:disabled { cursor: progress; opacity: .6; }
.mm-account-state::before {
  content: "";
  width: 6px; height: 6px;
  margin-right: 7px;
  border-radius: 50%;
  background: currentColor;
}

/* Canvas */
.mm-viewport {
  position: absolute;
  inset: 0;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  cursor: grab;
  background-color: var(--mm-bg);
  background-image: radial-gradient(circle, var(--mm-grid) 1px, transparent 1.2px);
  background-size: 24px 24px;
  outline: none;
}
.mm-viewport.is-panning { cursor: grabbing; }
.mm-world {
  position: absolute;
  left: 0; top: 0;
  width: 0; height: 0;
  transform-origin: 0 0;
}
.mm-edges {
  position: absolute;
  left: 0; top: 0;
  width: 1px; height: 1px;
  overflow: visible;
  pointer-events: none;
}
.mm-edge {
  fill: none;
  stroke: var(--c, var(--mm-border));
  stroke-linecap: round;
  stroke-opacity: .55;
  stroke-width: 1.5;
}
.mm-edge[data-depth="1"] { stroke-width: 3; stroke-opacity: .7; }
.mm-edge[data-depth="2"] { stroke-width: 2.2; }
.mm-edge[data-depth="3"] { stroke-width: 1.8; }

.mm-nodes { position: absolute; left: 0; top: 0; }

[data-branch="0"] { --c: var(--mm-branch-0); }
[data-branch="1"] { --c: var(--mm-branch-1); }
[data-branch="2"] { --c: var(--mm-branch-2); }
[data-branch="3"] { --c: var(--mm-branch-3); }
[data-branch="-1"] { --c: var(--mm-text); }

.mm-node {
  position: absolute;
  left: 0; top: 0;
  display: block;
  width: max-content;
  max-width: 210px;
  margin: 0;
  padding: 7px 14px;
  border: 1px solid var(--mm-border);
  border-radius: 999px;
  background: var(--mm-surface);
  color: var(--mm-text);
  font-size: 14px;
  font-weight: 500;
  line-height: 1.35;
  letter-spacing: -.01em;
  text-align: center;
  white-space: normal;
  overflow-wrap: anywhere;
  cursor: pointer;
  touch-action: none;
  transition: box-shadow .18s ease, border-color .18s ease, background-color .18s ease, opacity .2s ease;
  outline: none;
}
.mm-node-label {
  display: -webkit-box;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}
.mm-node:hover { border-color: color-mix(in srgb, var(--c) 55%, var(--mm-border)); }
.mm-node[data-depth="0"] {
  max-width: 240px;
  padding: 14px 28px;
  border: 0;
  background: var(--mm-text);
  color: var(--mm-bg);
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -.02em;
}
.mm-node[data-depth="1"] {
  max-width: 220px;
  padding: 10px 20px;
  border: 1.5px solid color-mix(in srgb, var(--c) 50%, transparent);
  background: color-mix(in srgb, var(--c) 12%, var(--mm-surface));
  font-size: 16px;
  font-weight: 600;
}
.mm-node[data-depth="2"] { font-size: 14.5px; }
.mm-node[aria-current="true"] {
  border-color: var(--c);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--c) 22%, transparent);
}
.mm-node[data-depth="0"][aria-current="true"] { box-shadow: 0 0 0 5px color-mix(in srgb, var(--mm-text) 18%, transparent); }
.mm-node:focus-visible { box-shadow: 0 0 0 3px var(--mm-bg), 0 0 0 5px var(--mm-accent); }
.mm-node.is-entering, .mm-node.is-leaving { opacity: 0; }
.mm-node.is-leaving { pointer-events: none; }
.mm-node.is-dragging { opacity: .35; }
.mm-node.is-drop-target {
  border-color: var(--c);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--c) 32%, transparent);
}
.mm-node.is-drop-invalid { opacity: .45; cursor: not-allowed; }
.mm-viewport.is-moving-node .mm-node { cursor: crosshair; }
.mm-node.has-body .mm-node-label::after {
  content: "";
  display: inline-block;
  width: 5px; height: 5px;
  margin-left: 6px;
  vertical-align: middle;
  border-radius: 50%;
  background: var(--c);
  opacity: .7;
}
.mm-node[data-depth="0"].has-body .mm-node-label::after { background: var(--mm-bg); }

/* Show the start of the description under the title; the panel holds the full text. */
.mm-node-summary { display: none; }
.mm-node.has-summary {
  max-width: 236px;
  border-radius: var(--mm-radius);
  padding-block: 8px 9px;
}
.mm-node.has-summary .mm-node-summary {
  display: block;
  margin-top: 2px;
  color: var(--mm-muted);
  font-size: 11.5px;
  font-weight: 400;
  line-height: 1.4;
  letter-spacing: 0;
}
.mm-node-summary-text {
  display: -webkit-box;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}
.mm-node[data-depth="0"].has-summary { max-width: 280px; border-radius: 20px; }
.mm-node[data-depth="0"].has-summary .mm-node-summary {
  color: color-mix(in srgb, var(--mm-bg) 72%, transparent);
  font-size: 12.5px;
}
.mm-node[data-depth="1"].has-summary { max-width: 250px; }
.mm-node[data-depth="1"].has-summary .mm-node-summary {
  color: color-mix(in srgb, var(--mm-text) 74%, transparent);
  font-size: 12px;
}

.mm-fold {
  position: absolute;
  left: 0; top: 0;
  display: grid;
  place-items: center;
  min-width: 20px;
  height: 20px;
  margin: 0;
  padding: 0 5px;
  border: 1.5px solid color-mix(in srgb, var(--c) 55%, var(--mm-border));
  border-radius: 999px;
  background: var(--mm-surface);
  color: var(--c);
  font-size: 11px;
  font-weight: 600;
  line-height: 1;
  opacity: 0;
  pointer-events: none;
  transition: opacity .16s ease, background-color .16s ease;
  touch-action: none;
}
.mm-fold::before {
  content: "";
  position: absolute;
  inset: -12px;
}
.mm-fold.is-collapsed,
.mm-fold.is-near { opacity: 1; pointer-events: auto; }
.mm-fold.is-collapsed { background: var(--c); color: var(--mm-surface); border-color: var(--c); }
.mm-fold-minus { display: block; width: 8px; height: 1.5px; border-radius: 2px; background: currentColor; }
.mm-fold.is-leaving { opacity: 0 !important; pointer-events: none; }

.mm-ghost {
  position: absolute;
  z-index: 15;
  left: 0; top: 0;
  max-width: 210px;
  padding: 7px 14px;
  border: 1px solid var(--c, var(--mm-accent));
  border-radius: 999px;
  background: var(--mm-surface);
  color: var(--mm-text);
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
  box-shadow: var(--mm-shadow);
}

.mm-rename {
  position: absolute;
  left: 0; top: 0;
  z-index: 11;
  min-width: 120px;
  max-width: 260px;
  padding: 7px 14px;
  border: 1.5px solid var(--mm-accent);
  border-radius: 999px;
  background: var(--mm-surface);
  color: var(--mm-text);
  font-size: 14px;
  font-weight: 500;
  text-align: center;
  outline: none;
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--mm-accent) 18%, transparent);
  user-select: text;
  -webkit-user-select: text;
}

/* Node tools (admin) */
.mm-tools {
  position: absolute;
  left: 0; top: 0;
  z-index: 10;
  display: flex;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--mm-border);
  border-radius: 12px;
  background: var(--mm-surface);
  box-shadow: var(--mm-shadow);
  transform: translate(-50%, -100%);
  transition: opacity .14s ease;
}
.mm-tools[hidden] { display: none; }
.mm-tool {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--mm-muted);
}
.mm-tool:hover { background: var(--mm-surface-soft); color: var(--mm-text); }
.mm-tool[aria-pressed="true"] { background: var(--mm-accent-soft); color: var(--mm-accent); }
.mm-tool-danger:hover { color: #b74444; background: color-mix(in srgb, #b74444 10%, transparent); }
.mm-tool:disabled { opacity: .35; cursor: default; background: transparent; }

.mm-move-hint {
  position: absolute;
  z-index: 12;
  top: calc(var(--mm-bar-h) + env(safe-area-inset-top) + 8px);
  left: 50%;
  padding: 8px 14px;
  transform: translateX(-50%);
  border: 1px solid var(--mm-border);
  border-radius: 999px;
  background: var(--mm-surface);
  color: var(--mm-text);
  font-size: 13px;
  white-space: nowrap;
  pointer-events: none;
}

/* Zoom controls */
.mm-controls {
  position: fixed;
  right: max(14px, env(safe-area-inset-right));
  bottom: max(14px, env(safe-area-inset-bottom));
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--mm-border);
  border-radius: 14px;
  background: color-mix(in srgb, var(--mm-surface) 88%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.mm-control {
  display: grid;
  place-items: center;
  min-width: var(--mm-control);
  height: var(--mm-control);
  padding: 0;
  border: 0;
  border-radius: 11px;
  background: transparent;
  color: var(--mm-muted);
  transition: background-color .14s ease, color .14s ease;
}
.mm-control:hover { background: var(--mm-surface-soft); color: var(--mm-text); }
.mm-zoom-label {
  min-width: 52px;
  font-size: 12.5px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.mm-control-sep { width: 1px; height: 20px; margin: 0 2px; background: var(--mm-border); }

button:focus-visible, a:focus-visible { outline: 2px solid var(--mm-accent); outline-offset: 2px; }

/* Loading / error */
.mm-state {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 14px;
  pointer-events: none;
}
.mm-state[hidden] { display: none; }
.mm-state-text { margin: 0; color: var(--mm-muted); font-size: 15px; }
.mm-state-retry {
  pointer-events: auto;
  min-height: 40px;
  padding: 0 18px;
  border: 1px solid var(--mm-border);
  border-radius: 999px;
  background: var(--mm-surface);
  font-size: 14px;
  font-weight: 600;
}
.mm-state-retry[hidden] { display: none; }

/* Toast */
.mm-toast {
  position: fixed;
  left: 50%;
  bottom: calc(max(14px, env(safe-area-inset-bottom)) + 62px);
  z-index: 40;
  max-width: min(88vw, 420px);
  padding: 11px 16px;
  border-radius: 12px;
  background: var(--mm-text);
  color: var(--mm-bg);
  font-size: 14px;
  font-weight: 500;
  line-height: 1.45;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 8px);
  transition: opacity .18s ease, transform .18s var(--mm-ease);
}
.mm-toast.is-visible { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 767px) {
  :root { --mm-control: 44px; --mm-bar-h: 56px; }
  .mm-title { font-size: 16px; }
  .mm-account-link { min-height: 44px; }
  .mm-zoom-label { min-width: 54px; }
  .mm-tool { width: 44px; height: 44px; }
  .mm-node { max-width: 170px; }
  .mm-node[data-depth="1"] { max-width: 190px; min-height: 47px; padding-inline: 16px; font-size: 17px; }
  .mm-node.has-summary { max-width: 170px; }
  .mm-node[data-depth="0"].has-summary { max-width: clamp(136px, 36vw, 184px); }
  .mm-node[data-depth="1"].has-summary { max-width: clamp(125px, 39vw, 190px); }
  .mm-fold { min-width: 22px; height: 22px; }
  .mm-rename { font-size: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0s !important; animation-duration: 0s !important; }
}
