:root {
  color-scheme: light;
  --ink: #26243a;
  --muted: #77748c;
  --surface: rgba(255, 255, 255, 0.88);
  --line: #e8e5f2;
  --purple: #7057da;
  --purple-dark: #5941bf;
  --purple-soft: #eeeaff;
  --danger: #c64f60;
  --shadow: 0 18px 50px rgba(61, 47, 110, 0.12);
  --node-width: 200px;
  --node-height: 76px;
  font-family: Inter, ui-rounded, "SF Pro Rounded", "Segoe UI", system-ui, -apple-system, sans-serif;
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

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

body {
  color: var(--ink);
  background:
    radial-gradient(circle at 9% 12%, rgba(215, 233, 255, 0.82), transparent 27%),
    radial-gradient(circle at 89% 8%, rgba(237, 224, 255, 0.8), transparent 25%),
    #f8f8fc;
}

button,
input {
  font: inherit;
}

button {
  color: inherit;
}

button:focus-visible,
input:focus-visible,
.stage:focus-visible {
  outline: 3px solid rgba(112, 87, 218, 0.3);
  outline-offset: 3px;
}

.app-shell {
  display: grid;
  grid-template-rows: auto 1fr;
  width: 100%;
  height: 100%;
  min-height: 0;
}

.app-header {
  position: relative;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 92px;
  padding: 18px clamp(20px, 4vw, 52px);
  border-bottom: 1px solid rgba(225, 222, 236, 0.9);
  background: rgba(251, 251, 254, 0.75);
  backdrop-filter: blur(20px);
}

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

.brand-mark {
  position: relative;
  width: 48px;
  height: 48px;
  border-radius: 15px;
  background: linear-gradient(145deg, #826ce9, #5f47c8);
  box-shadow: 0 10px 25px rgba(101, 76, 203, 0.28);
}

.brand-mark::before,
.brand-mark span {
  position: absolute;
  display: block;
  border-radius: 50%;
  background: white;
  content: "";
}

.brand-mark::before {
  top: 20px;
  left: 20px;
  width: 8px;
  height: 8px;
}

.brand-mark span {
  width: 6px;
  height: 6px;
}

.brand-mark span:nth-child(1) { top: 9px; left: 9px; }
.brand-mark span:nth-child(2) { top: 9px; right: 9px; }
.brand-mark span:nth-child(3) { right: 9px; bottom: 9px; }

.brand-mark::after {
  position: absolute;
  inset: 11px;
  border: 2px solid rgba(255, 255, 255, 0.72);
  border-left-color: transparent;
  border-bottom-color: transparent;
  border-radius: 8px;
  content: "";
  transform: rotate(45deg);
}

.eyebrow {
  margin: 0 0 3px;
  color: #858197;
  font-size: 0.69rem;
  font-weight: 700;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(1.45rem, 3vw, 1.85rem);
  line-height: 1;
  letter-spacing: -0.045em;
}

h1 span {
  color: var(--purple);
}

.header-meta,
.save-status {
  display: flex;
  align-items: center;
}

.header-meta {
  gap: 20px;
}

.save-status {
  gap: 7px;
  color: #6e6a7e;
  font-size: 0.82rem;
  font-weight: 650;
}

.save-status svg {
  width: 18px;
  height: 18px;
  padding: 3px;
  border-radius: 50%;
  color: #4e9f79;
  background: #e3f5eb;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2.2;
}

.text-button {
  padding: 7px 2px;
  border: 0;
  border-bottom: 1px solid transparent;
  background: transparent;
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 700;
}

.danger-text {
  color: var(--danger);
}

.text-button:hover {
  border-bottom-color: currentColor;
}

.workspace {
  position: relative;
  min-height: 0;
  overflow: hidden;
}

.stage {
  position: absolute;
  inset: 0;
  overflow: hidden;
  cursor: grab;
  touch-action: none;
  user-select: none;
  background-image: radial-gradient(circle, rgba(125, 116, 157, 0.2) 1.1px, transparent 1.1px);
  background-position: 0 0;
  background-size: 27px 27px;
}

.stage.is-dragging {
  cursor: grabbing;
}

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

.world,
.connectors,
.node-layer {
  position: absolute;
  top: 0;
  left: 0;
}

.connectors {
  overflow: visible;
  pointer-events: none;
}

.connector {
  fill: none;
  stroke: #c9c1e7;
  stroke-linecap: round;
  stroke-width: 3;
  vector-effect: non-scaling-stroke;
}

.connector.depth-1 { stroke: #b9b0e5; }
.connector.depth-2 { stroke: #a9cde1; }
.connector.depth-3 { stroke: #c8bfdc; }
.connector.depth-4 { stroke: #add4ca; }

.node-layer {
  pointer-events: none;
}

.mind-node {
  --node-accent: #7057da;
  --node-tint: #f0edff;
  --node-rotation: 0rad;
  position: absolute;
  display: grid;
  grid-template-columns: 10px 1fr 24px;
  align-items: center;
  gap: 10px;
  width: var(--node-width);
  height: var(--node-height);
  padding: 12px 14px;
  overflow: hidden;
  border: 1px solid rgba(220, 216, 234, 0.92);
  border-radius: 20px;
  color: #373348;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 9px 24px rgba(72, 61, 110, 0.11), 0 2px 5px rgba(72, 61, 110, 0.05);
  cursor: pointer;
  pointer-events: auto;
  text-align: left;
  transform: rotate(var(--node-rotation));
  transform-origin: center;
  transition: border-color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}

.mind-node::after {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(120deg, transparent 48%, var(--node-tint));
  content: "";
  opacity: 0.5;
  pointer-events: none;
}

.mind-node:hover,
.mind-node:focus-visible {
  z-index: 2;
  border-color: color-mix(in srgb, var(--node-accent), white 45%);
  box-shadow: 0 13px 28px rgba(72, 61, 110, 0.16), 0 0 0 4px var(--node-tint);
  transform: rotate(var(--node-rotation)) translateY(-2px);
}

.mind-node.root-node {
  --node-accent: #7057da;
  --node-tint: #e9e4ff;
  border: 0;
  color: white;
  background: linear-gradient(145deg, #7c65e5, #5d45c7);
  box-shadow: 0 14px 32px rgba(93, 69, 199, 0.3);
}

.mind-node.root-node::after {
  background: radial-gradient(circle at 88% 15%, rgba(255, 255, 255, 0.24), transparent 36%);
}

.node-dot {
  position: relative;
  z-index: 1;
  width: 9px;
  height: 9px;
  border: 2px solid var(--node-accent);
  border-radius: 50%;
  background: var(--node-tint);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--node-tint), transparent 30%);
}

.root-node .node-dot {
  border-color: white;
  background: white;
  box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.18);
}

.node-label {
  position: relative;
  z-index: 1;
  display: -webkit-box;
  overflow: hidden;
  font-size: 0.92rem;
  font-weight: 750;
  line-height: 1.25;
  overflow-wrap: anywhere;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.node-add {
  position: relative;
  z-index: 1;
  display: grid;
  width: 24px;
  height: 24px;
  place-items: center;
  border-radius: 8px;
  color: var(--node-accent);
  background: var(--node-tint);
  font-size: 1rem;
  font-weight: 700;
  transition: transform 160ms ease;
}

.mind-node:hover .node-add {
  transform: rotate(90deg);
}

.root-node .node-add {
  color: white;
  background: rgba(255, 255, 255, 0.18);
}

.mind-node.theme-1 { --node-accent: #4b93bd; --node-tint: #e8f5fb; }
.mind-node.theme-2 { --node-accent: #9a65b3; --node-tint: #f5ebf9; }
.mind-node.theme-3 { --node-accent: #3f9a83; --node-tint: #e5f5f0; }
.mind-node.theme-4 { --node-accent: #d18259; --node-tint: #fbefe7; }
.mind-node.theme-5 { --node-accent: #7a7ebc; --node-tint: #eeeffa; }

.tip,
.canvas-hint,
.canvas-controls {
  position: absolute;
  z-index: 5;
}

.tip {
  top: 22px;
  left: 50%;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 14px;
  border: 1px solid rgba(225, 221, 239, 0.9);
  border-radius: 999px;
  color: #6f6b7d;
  background: rgba(255, 255, 255, 0.78);
  box-shadow: 0 7px 22px rgba(66, 54, 105, 0.08);
  backdrop-filter: blur(12px);
  font-size: 0.78rem;
  font-weight: 650;
  pointer-events: none;
  transform: translateX(-50%);
}

.tip-icon {
  display: grid;
  width: 19px;
  height: 19px;
  place-items: center;
  border-radius: 6px;
  color: white;
  background: var(--purple);
  font-size: 0.9rem;
}

.canvas-controls {
  right: 24px;
  bottom: 24px;
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 7px;
  border: 1px solid rgba(220, 216, 234, 0.9);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

.control-button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: transparent;
  cursor: pointer;
}

.control-button:hover {
  color: var(--purple);
  background: var(--purple-soft);
}

.control-button svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.zoom-value {
  min-width: 50px;
  color: #6f6b7d;
  font-size: 0.76rem;
  font-weight: 750;
  text-align: center;
}

.control-divider {
  width: 1px;
  height: 24px;
  margin: 0 3px;
  background: var(--line);
}

.fit-button {
  width: auto;
  padding: 0 9px;
  gap: 6px;
  font-size: 0.76rem;
  font-weight: 750;
}

.canvas-hint {
  bottom: 29px;
  left: 28px;
  margin: 0;
  color: #9290a1;
  font-size: 0.72rem;
  font-weight: 600;
  pointer-events: none;
}

.node-dialog {
  width: min(440px, calc(100vw - 28px));
  max-height: calc(100vh - 28px);
  padding: 0;
  overflow: auto;
  border: 1px solid rgba(219, 214, 235, 0.95);
  border-radius: 24px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.98);
  box-shadow: 0 30px 90px rgba(42, 31, 87, 0.25);
}

.node-dialog::backdrop {
  background: rgba(39, 31, 63, 0.32);
  backdrop-filter: blur(5px);
}

.node-dialog[open] {
  animation: dialog-in 180ms ease-out;
}

.node-dialog form {
  padding: 24px;
}

.dialog-topline {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.dialog-kicker {
  color: var(--purple);
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.close-button {
  display: grid;
  width: 34px;
  height: 34px;
  padding: 0;
  place-items: center;
  border: 0;
  border-radius: 10px;
  color: #858195;
  background: #f5f3f9;
  cursor: pointer;
}

.close-button:hover {
  color: var(--ink);
  background: #eeebf5;
}

.close-button svg,
.utility-button svg,
.primary-button svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.node-dialog h2 {
  margin: 17px 0 6px;
  font-size: 1.55rem;
  letter-spacing: -0.035em;
}

.dialog-context {
  margin: 0 0 22px;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.5;
}

.dialog-context strong {
  color: #555164;
}

.field-label {
  display: block;
  margin: 0 0 8px;
  color: #5e5a6d;
  font-size: 0.78rem;
  font-weight: 750;
}

.input-wrap {
  position: relative;
}

.input-wrap input {
  width: 100%;
  height: 52px;
  padding: 0 62px 0 14px;
  border: 1px solid #dcd8e9;
  border-radius: 14px;
  color: var(--ink);
  background: #fbfaff;
  font-size: 0.95rem;
  transition: border-color 150ms ease, box-shadow 150ms ease;
}

.input-wrap input:focus {
  border-color: var(--purple);
  outline: 0;
  box-shadow: 0 0 0 4px rgba(112, 87, 218, 0.12);
}

.input-wrap input[aria-invalid="true"] {
  border-color: var(--danger);
}

.character-count {
  position: absolute;
  top: 50%;
  right: 13px;
  color: #9995a6;
  font-size: 0.7rem;
  font-weight: 700;
  transform: translateY(-50%);
}

.field-error {
  min-height: 18px;
  margin: 6px 2px 2px;
  color: var(--danger);
  font-size: 0.75rem;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 11px;
}

.button {
  min-height: 43px;
  padding: 0 17px;
  border-radius: 12px;
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 750;
}

.secondary-button {
  border: 1px solid #dfdbea;
  background: white;
}

.secondary-button:hover {
  background: #f7f5fb;
}

.primary-button {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 0;
  color: white;
  background: linear-gradient(135deg, #7860df, #5e46c6);
  box-shadow: 0 8px 18px rgba(94, 70, 198, 0.24);
}

.primary-button:hover {
  background: linear-gradient(135deg, #6f56d5, #563dbd);
}

.node-tools {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 22px;
  padding-top: 17px;
  border-top: 1px solid #ece9f3;
}

.node-tools > span {
  color: #9793a3;
  font-size: 0.71rem;
  font-weight: 700;
}

.node-tools > div {
  display: flex;
  gap: 6px;
}

.utility-button {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 7px 9px;
  border: 0;
  border-radius: 9px;
  color: #6b677a;
  background: transparent;
  cursor: pointer;
  font-size: 0.75rem;
  font-weight: 700;
}

.utility-button:hover {
  color: var(--purple-dark);
  background: var(--purple-soft);
}

.utility-button.delete-button {
  color: var(--danger);
}

.utility-button.delete-button:hover {
  background: #fff0f2;
}

.utility-button[hidden] {
  display: none;
}

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

@media (max-width: 680px) {
  .app-header {
    min-height: 78px;
    padding: 13px 16px;
  }

  .brand-mark {
    width: 42px;
    height: 42px;
    border-radius: 13px;
    transform: scale(0.88);
    transform-origin: left center;
  }

  .brand {
    gap: 7px;
  }

  .eyebrow,
  .save-status span,
  .canvas-hint {
    display: none;
  }

  .header-meta {
    gap: 10px;
  }

  .tip {
    top: 14px;
    width: max-content;
    max-width: calc(100% - 28px);
  }

  .canvas-controls {
    right: 50%;
    bottom: 16px;
    transform: translateX(50%);
  }

  .node-dialog form {
    padding: 21px;
  }

  .node-tools {
    align-items: flex-start;
    flex-direction: column;
  }
}

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