/* ============================================================
   Studio Dagdak — Mind Map (v9, 2026-11-26)
   Cream canvas, espresso chrome, terracotta accent.
   ============================================================ */

:root {
  --ink: #170e09;
  --ink-2: #241610;
  --cream: #f6f0e6;
  --cream-2: #e6dbc9;
  --bg: #faf5ec;
  --bg-2: #f3ebdd;
  --sand: #dfc8aa;
  --terra: #b85d3b;
  --terra-2: #cf7a56;
  --muted: #b7a591;
  --muted-2: #8d7a66;
  --line: rgba(36, 22, 16, 0.12);
  --line-2: rgba(36, 22, 16, 0.22);
  --bar: 60px;
  --sans: "Pretendard", -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
}

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

[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
  overflow: hidden;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
a:focus-visible {
  outline: 2px solid var(--terra);
  outline-offset: 2px;
}

/* ============================== Top bar ============================== */

.bar {
  position: fixed;
  inset: 0 0 auto 0;
  z-index: 60;
  height: var(--bar);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  background: var(--ink);
  border-bottom: 1px solid rgba(223, 200, 170, 0.14);
  color: var(--cream);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--cream-2);
  text-decoration: none;
  flex: 0 0 auto;
}

.brand img {
  width: 30px;
  height: auto;
  display: block;
}

.brand span {
  font-size: 0.7rem;
  letter-spacing: 0.2em;
  font-weight: 600;
  white-space: nowrap;
}

.brand b {
  font-weight: 800;
  color: var(--cream);
}

.vsep {
  width: 1px;
  height: 22px;
  background: rgba(223, 200, 170, 0.18);
  flex: 0 0 auto;
}

.mapbtn {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  max-width: 320px;
  padding: 7px 13px;
  border-radius: 9px;
  border: 1px solid rgba(223, 200, 170, 0.22);
  color: var(--cream);
  transition: background 0.16s, border-color 0.16s;
}

.mapbtn:hover,
.mapbtn[aria-expanded="true"] {
  background: rgba(246, 240, 230, 0.08);
  border-color: rgba(223, 200, 170, 0.42);
}

.mapbtn b {
  font-size: 0.9rem;
  font-weight: 650;
  letter-spacing: -0.01em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 250px;
}

.chev {
  width: 6px;
  height: 6px;
  border-right: 1.5px solid var(--muted);
  border-bottom: 1.5px solid var(--muted);
  transform: translateY(-2px) rotate(45deg);
  flex: 0 0 auto;
}

.saved {
  font-size: 0.72rem;
  color: var(--muted);
  opacity: 0;
  transition: opacity 0.3s;
  white-space: nowrap;
}

.saved.on {
  opacity: 1;
}

.tools {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

.group {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 3px;
  border-radius: 10px;
  background: rgba(246, 240, 230, 0.05);
}

.tool {
  padding: 7px 12px;
  border-radius: 8px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--cream-2);
  white-space: nowrap;
  transition: background 0.15s, color 0.15s, opacity 0.15s;
}

.tool:hover {
  background: rgba(246, 240, 230, 0.1);
  color: #fff;
}

.tool.icon {
  padding: 7px 10px;
  font-size: 1rem;
  line-height: 1;
}

.tool[disabled] {
  opacity: 0.32;
  cursor: default;
}

.tool[disabled]:hover {
  background: none;
}

.tool.primary {
  background: var(--terra);
  color: #fff8ef;
}

.tool.primary:hover {
  background: var(--terra-2);
}

.lang {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 6px 10px;
  margin-left: 2px;
  border-radius: 999px;
  border: 1px solid rgba(223, 200, 170, 0.26);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  color: var(--muted);
}

.lang span[data-l] {
  padding: 2px 6px;
  border-radius: 999px;
  transition: background 0.16s, color 0.16s;
}

.lang span.is-on {
  background: rgba(246, 240, 230, 0.16);
  color: #fff;
}

.langsep {
  opacity: 0.4;
}

/* ============================== Stage ============================== */

.stage {
  position: fixed;
  inset: var(--bar) 0 0 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 1px 1px, rgba(36, 22, 16, 0.12) 1px, transparent 0) 0 0 / 26px 26px,
    var(--bg);
}

.canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: grab;
}

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

.node {
  cursor: pointer;
}

.node rect.nbg {
  transition: filter 0.15s;
}

.node:hover rect.nbg {
  filter: brightness(1.04);
}

.node text {
  pointer-events: none;
  user-select: none;
}

.node .badge {
  cursor: pointer;
}

.ngroup.is-selected rect.selring {
  display: block;
}

/* ============================== Zoom ============================== */

.zoom,
.outtoggle {
  position: absolute;
  bottom: 20px;
  z-index: 20;
  display: inline-flex;
  align-items: center;
  gap: 2px;
  height: 40px;
  padding: 0 6px;
  background: #fffdf8;
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 12px 28px -18px rgba(36, 22, 16, 0.5);
}

.zoom {
  left: 20px;
}

.zoom button {
  min-width: 30px;
  height: 30px;
  padding: 0 7px;
  border-radius: 7px;
  font-size: 0.88rem;
  font-weight: 600;
  color: #5b4636;
  transition: background 0.14s, color 0.14s;
}

.zoom button:hover {
  background: var(--bg-2);
  color: var(--ink);
}

#zoomLabel {
  min-width: 50px;
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
}

.zoomsep {
  width: 1px;
  height: 18px;
  background: var(--line);
  margin: 0 3px;
}

.outtoggle {
  right: 20px;
  gap: 8px;
  padding: 0 14px;
  font-size: 0.82rem;
  font-weight: 650;
  color: #5b4636;
  transition: background 0.16s, color 0.16s, border-color 0.16s;
}

.outtoggle:hover {
  background: var(--bg-2);
  color: var(--ink);
}

.outtoggle[aria-expanded="true"] {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--cream);
}

.outicon {
  font-size: 0.9rem;
  line-height: 1;
}

.hint {
  position: absolute;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  z-index: 15;
  max-width: min(620px, calc(100vw - 380px));
  padding: 8px 16px;
  border-radius: 999px;
  background: rgba(255, 253, 248, 0.86);
  border: 1px solid var(--line);
  font-size: 0.74rem;
  color: var(--muted-2);
  text-align: center;
  backdrop-filter: blur(6px);
  pointer-events: none;
  transition: opacity 0.4s;
}

.hint.is-faded {
  opacity: 0;
}

.empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 0.9rem;
  color: var(--muted-2);
  pointer-events: none;
}

/* ============================== Node toolbar ============================== */

.ntools {
  position: absolute;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 5px 6px;
  background: #fffdf8;
  border: 1px solid rgba(36, 22, 16, 0.14);
  border-radius: 12px;
  box-shadow: 0 18px 36px -20px rgba(36, 22, 16, 0.55);
  transform: translate(-50%, -100%);
  white-space: nowrap;
}

.ntools > button {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  font-size: 0.86rem;
  color: #5b4636;
  transition: background 0.14s, color 0.14s;
}

.ntools > button:hover {
  background: var(--bg-2);
  color: var(--ink);
}

.ntools > button i {
  font-style: normal;
  font-size: 0.62rem;
  margin-left: -1px;
}

.ntools > button[data-act="delete"]:hover {
  background: rgba(184, 93, 59, 0.14);
  color: var(--terra);
}

/* 삭제 버튼 — 아이콘만이 아니라 라벨까지 보이는 명시적 버튼 */
.ntools > .ntdel {
  width: auto;
  min-width: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0 11px 0 9px;
  color: var(--terra);
  background: rgba(184, 93, 59, 0.1);
  border: 1px solid rgba(184, 93, 59, 0.28);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.ntools > .ntdel:hover {
  background: var(--terra);
  border-color: var(--terra);
  color: #fff8ef;
}

.ntdel-ic {
  font-size: 1rem;
  font-weight: 600;
  line-height: 1;
  margin-top: -1px;
}

.ntdel-lbl {
  line-height: 1;
  white-space: nowrap;
}

.ntools > .ntdel.is-disabled {
  color: var(--muted);
  background: transparent;
  border-color: var(--line);
  cursor: not-allowed;
}

.ntools > .ntdel.is-disabled:hover {
  background: transparent;
  border-color: var(--line);
  color: var(--muted);
}

.ntsep {
  width: 1px;
  height: 18px;
  background: var(--line);
  margin: 0 4px;
}

.swatches {
  display: flex;
  align-items: center;
  gap: 4px;
}

.sw {
  width: 17px;
  height: 17px;
  border-radius: 50%;
  border: 1px solid rgba(36, 22, 16, 0.18);
  transition: transform 0.14s, box-shadow 0.14s;
}

.sw:hover {
  transform: scale(1.18);
}

.sw.is-on {
  box-shadow: 0 0 0 2px #fffdf8, 0 0 0 3.5px var(--ink);
}

/* ============================== Node editor ============================== */

.node-edit {
  position: absolute;
  z-index: 40;
  min-width: 120px;
  padding: 8px 12px;
  font-family: var(--sans);
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  background: #fffdf8;
  border: 2px solid var(--terra);
  border-radius: 9px;
  box-shadow: 0 10px 24px -14px rgba(36, 22, 16, 0.6);
  outline: none;
}

/* ============================== Outliner ============================== */

.outliner {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 35;
  width: 340px;
  max-width: 86vw;
  display: flex;
  flex-direction: column;
  background: #fffdf8;
  border-left: 1px solid var(--line);
  box-shadow: -18px 0 44px -30px rgba(36, 22, 16, 0.5);
  animation: slideIn 0.24s var(--ease);
}

@keyframes slideIn {
  from {
    transform: translateX(18px);
    opacity: 0;
  }
  to {
    transform: none;
    opacity: 1;
  }
}

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

.out-head h2 {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--muted-2);
}

.out-head button {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  color: var(--muted-2);
  font-size: 0.8rem;
}

.out-head button:hover {
  background: var(--bg-2);
  color: var(--ink);
}

.out-body {
  flex: 1;
  overflow: auto;
  padding: 10px 8px 40px;
}

.out-row {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 4px 6px;
  border-radius: 8px;
  position: relative;
}

.out-row:hover {
  background: rgba(223, 200, 170, 0.22);
}

.out-row.is-sel {
  background: rgba(184, 93, 59, 0.1);
}

.out-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex: 0 0 auto;
  border: 1px solid rgba(36, 22, 16, 0.16);
}

.out-row input {
  flex: 1;
  min-width: 0;
  padding: 5px 6px;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--ink);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
}

.out-row input:hover {
  border-color: var(--line);
}

.out-row input:focus {
  outline: none;
  background: #fff;
  border-color: var(--terra);
}

.out-row .oadd {
  width: 20px;
  height: 20px;
  border-radius: 5px;
  font-size: 0.8rem;
  color: var(--muted-2);
  opacity: 0;
  flex: 0 0 auto;
}

.out-row:hover .oadd {
  opacity: 1;
}

.out-row .oadd:hover {
  background: var(--bg-2);
  color: var(--ink);
}

.out-row .odel {
  width: 20px;
  height: 20px;
  border-radius: 5px;
  font-size: 0.68rem;
  color: var(--muted-2);
  opacity: 0;
  flex: 0 0 auto;
}

.out-row:hover .odel,
.out-row.is-sel .odel {
  opacity: 1;
}

.out-row .odel:hover {
  background: rgba(184, 93, 59, 0.16);
  color: var(--terra);
}

.out-row.depth-0 input {
  font-weight: 700;
}

.out-foot {
  padding: 10px 16px;
  border-top: 1px solid var(--line);
  font-size: 0.7rem;
  color: var(--muted-2);
}

/* ============================== Maps drawer ============================== */

.drawer {
  position: absolute;
  inset: 0;
  z-index: 50;
  background: rgba(23, 14, 9, 0.28);
  backdrop-filter: blur(2px);
}

.drawer-panel {
  width: min(400px, 92vw);
  height: 100%;
  padding: 20px 20px 30px;
  overflow: auto;
  background: var(--bg);
  border-right: 1px solid var(--line);
  box-shadow: 24px 0 60px -30px rgba(23, 14, 9, 0.6);
  animation: drawerIn 0.22s var(--ease);
}

@keyframes drawerIn {
  from {
    transform: translateX(-16px);
    opacity: 0;
  }
  to {
    transform: none;
    opacity: 1;
  }
}

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.drawer-head h2 {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted-2);
}

.drawer-head.sub {
  margin-top: 26px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.mini {
  padding: 7px 12px;
  border-radius: 8px;
  background: var(--ink);
  color: var(--cream);
  font-size: 0.76rem;
  font-weight: 650;
}

.mini:hover {
  background: #2b1a11;
}

.maplist {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.maplist li {
  display: flex;
  align-items: center;
  gap: 8px;
  border-radius: 10px;
}

.maplist li:hover {
  background: rgba(223, 200, 170, 0.28);
}

.maplist li.is-current {
  background: rgba(184, 93, 59, 0.12);
}

.mapopen {
  flex: 1;
  min-width: 0;
  text-align: left;
  padding: 10px 12px;
}

.mapopen b {
  display: block;
  font-size: 0.9rem;
  font-weight: 650;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mapopen span {
  display: block;
  font-size: 0.72rem;
  color: var(--muted-2);
  margin-top: 1px;
}

.mapdel {
  width: 30px;
  height: 30px;
  margin-right: 6px;
  border-radius: 7px;
  color: var(--muted-2);
  font-size: 0.76rem;
  opacity: 0;
}

.maplist li:hover .mapdel {
  opacity: 1;
}

.mapdel:hover {
  background: rgba(184, 93, 59, 0.15);
  color: var(--terra);
}

.drawer-note {
  margin-top: 26px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  font-size: 0.74rem;
  line-height: 1.6;
  color: var(--muted-2);
}

/* ============================== Toast ============================== */

.toast {
  position: absolute;
  top: 18px;
  left: 50%;
  z-index: 70;
  transform: translate(-50%, -12px);
  padding: 11px 20px;
  background: var(--ink);
  color: var(--cream);
  border-radius: 10px;
  font-size: 0.82rem;
  font-weight: 500;
  box-shadow: 0 18px 40px -22px rgba(23, 14, 9, 0.8);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s, transform 0.22s var(--ease);
  max-width: min(560px, 88vw);
  text-align: center;
}

.toast.on {
  opacity: 1;
  transform: translate(-50%, 0);
  pointer-events: auto;
}

.toast button {
  margin-left: 10px;
  text-decoration: underline;
  font-weight: 700;
  color: var(--sand);
}

/* ============================== Responsive ============================== */

@media (max-width: 900px) {
  :root {
    --bar: auto;
  }

  .bar {
    height: auto;
    flex-wrap: wrap;
    padding: 8px 12px;
    gap: 8px;
    row-gap: 8px;
  }

  .brand span {
    display: none;
  }

  .mapbtn {
    max-width: 42vw;
    padding: 6px 10px;
  }

  .mapbtn b {
    font-size: 0.84rem;
    max-width: 30vw;
  }

  .saved {
    display: none;
  }

  .lang {
    order: 3;
    margin-left: auto;
  }

  .tools {
    order: 4;
    width: 100%;
    overflow-x: auto;
    gap: 6px;
    padding-bottom: 2px;
    scrollbar-width: none;
  }

  .tools::-webkit-scrollbar {
    display: none;
  }

  .tool {
    padding: 6px 10px;
    font-size: 0.76rem;
  }

  .group {
    flex: 0 0 auto;
  }

  .lang {
    flex: 0 0 auto;
  }

  .stage {
    inset: 96px 0 0 0;
  }

  .hint {
    display: none;
  }

  .zoom {
    left: 12px;
    bottom: 12px;
  }

  .outtoggle {
    right: 12px;
    bottom: 12px;
  }

  .outliner {
    width: 100%;
    max-width: none;
    top: 0;
  }

  /* 좁은 화면: 삭제 버튼은 첫 줄에 남고 색상 스와치는 아랫줄로 내려갑니다 */
  .ntools {
    max-width: calc(100vw - 20px);
    flex-wrap: wrap;
    justify-content: center;
    row-gap: 4px;
  }

  .ntools > .ntsep {
    display: none;
  }

  .ntools > .ntdel {
    order: 2;
    padding: 0 10px 0 8px;
  }

  .ntools > .swatches {
    order: 3;
    flex: 1 0 100%;
    justify-content: center;
    gap: 6px;
    padding-bottom: 2px;
  }

  .out-row .oadd,
  .out-row .odel {
    opacity: 0.55;
  }
}

/* 터치 기기에서는 호버가 없으므로 아웃라이너 버튼을 항상 보이게 */
@media (hover: none) {
  .out-row .oadd,
  .out-row .odel {
    opacity: 0.6;
  }
}
