:root {
  --paper: #14120e;
  --paper-2: #1c1914;
  --cream: #f6f1e7;
  --cream-dim: #d9d0c2;
  --brass: #e0a15a;
  --ink: #221c16;
  --line: rgba(243, 234, 215, 0.16);
  --danger: #e7b2a4;
  --shadow: 0 16px 40px rgba(0, 0, 0, 0.28);
  --header: 72px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--paper);
  color: var(--cream);
  font-family: Figtree, "Segoe UI", sans-serif;
}

body {
  min-height: 100%;
  background:
    radial-gradient(ellipse 70% 50% at 50% 38%, rgba(224, 161, 90, 0.16), transparent 60%),
    radial-gradient(ellipse 40% 30% at 80% 80%, rgba(126, 176, 196, 0.08), transparent 70%),
    var(--paper);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image: radial-gradient(rgba(246, 241, 231, 0.09) 0.7px, transparent 0.7px);
  background-size: 22px 22px;
  mask-image: radial-gradient(ellipse at center, black 20%, transparent 75%);
}

button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, a:focus-visible {
  outline: 2px solid var(--brass);
  outline-offset: 3px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

header {
  position: fixed;
  z-index: 5;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 22px;
  pointer-events: none;
}

header > * { pointer-events: auto; }

.brand {
  text-decoration: none;
  font-family: Fraunces, Georgia, serif;
  font-weight: 620;
  font-size: 22px;
  letter-spacing: -0.03em;
  color: var(--cream);
}

#topic-label {
  margin: 0;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--cream-dim);
  font-size: 14px;
}

.header-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 12px;
}

.model-line {
  margin: 0;
  color: rgba(217, 208, 194, 0.72);
  font-size: 12px;
  letter-spacing: 0.01em;
}

#new-map, .seeds button, #zoom button, .dock-remove, .action {
  border: 1px solid rgba(246, 241, 231, 0.16);
  background: rgba(20, 18, 14, 0.72);
  color: var(--cream);
  border-radius: 999px;
}

#new-map {
  padding: 8px 14px;
  backdrop-filter: blur(8px);
}

#new-map.is-armed {
  background: var(--cream);
  color: var(--ink);
  border-color: transparent;
}

#hero {
  position: fixed;
  inset: 0;
  z-index: 4;
  display: grid;
  place-items: center;
  padding: 88px 22px 32px;
}

#hero[hidden] { display: none; }

.hero-card { width: min(680px, 100%); }

.eyebrow {
  margin: 0;
  color: var(--brass);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  font-size: 12px;
  font-weight: 600;
}

h1 {
  margin: 12px 0 14px;
  font-family: Fraunces, Georgia, serif;
  font-weight: 520;
  font-size: clamp(46px, 7vw, 76px);
  line-height: 0.98;
  letter-spacing: -0.035em;
}

h1 em {
  font-style: italic;
  font-weight: 500;
  color: #f0d3ae;
}

.lede {
  margin: 0;
  max-width: 48ch;
  color: var(--cream-dim);
  font-size: 17px;
  line-height: 1.45;
}

#composer {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 28px;
  padding-bottom: 8px;
  border-bottom: 1px solid rgba(224, 161, 90, 0.55);
}

#topic {
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  font-family: Fraunces, Georgia, serif;
  font-size: clamp(20px, 3vw, 28px);
  padding: 8px 0;
}

#topic::placeholder { color: rgba(246, 241, 231, 0.35); }

#map-it {
  border: 0;
  background: var(--cream);
  color: var(--ink);
  border-radius: 999px;
  padding: 12px 18px;
  font-weight: 700;
}

#map-it:disabled { opacity: 0.55; cursor: wait; }

.warning {
  margin: 14px 0 0;
  color: var(--danger);
  font-size: 14px;
  line-height: 1.4;
}

.warning code {
  font-size: 0.92em;
}

.seeds {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 22px;
}

.seeds button {
  padding: 8px 12px;
  color: var(--cream-dim);
  background: transparent;
}

.seeds button:hover { color: var(--cream); border-color: rgba(224, 161, 90, 0.6); }

#stage {
  position: fixed;
  inset: 0;
  overflow: hidden;
  touch-action: none;
  cursor: grab;
}

#stage[hidden] { display: none; }
#stage.is-panning { cursor: grabbing; }

#camera {
  position: absolute;
  inset: 0;
  transform-origin: 0 0;
}

#edges {
  position: absolute;
  left: 0;
  top: 0;
  width: 1px;
  height: 1px;
  overflow: visible;
  pointer-events: none;
}

.edge {
  fill: none;
  stroke: var(--edge, rgba(224, 161, 90, 0.45));
  stroke-width: 1.5;
  vector-effect: non-scaling-stroke;
}

#world { position: absolute; inset: 0; }

.node {
  position: absolute;
  left: 0;
  top: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0;
  margin: 0;
  padding: 0;
  text-align: center;
  background: #1b1814;
  color: var(--cream);
  border: 1.5px solid var(--rim, var(--brass));
  box-shadow: var(--shadow);
  transform: translate(-50%, -50%);
  transition: left 460ms cubic-bezier(0.2, 0.8, 0.2, 1), top 460ms cubic-bezier(0.2, 0.8, 0.2, 1), border-color 160ms ease, background 160ms ease;
  z-index: 1;
}

.node.bubble, .node.root.is-round { border-radius: 999px; }
.node.box, .node.root.is-pill {
  border-radius: 18px;
  align-items: stretch;
  text-align: left;
}

.node .face {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  width: 100%;
  height: 100%;
  min-width: 0;
  padding: 16px;
  overflow: hidden;
  border-radius: inherit;
  text-align: center;
}

.node.box .face, .node.root.is-pill .face {
  align-items: flex-start;
  text-align: left;
  padding: 12px 14px 12px 16px;
}

.node.root {
  background: var(--cream);
  color: var(--ink);
  border-color: transparent;
  z-index: 2;
}

.node.root .label {
  font-family: Fraunces, Georgia, serif;
  font-size: 22px;
  font-weight: 560;
  letter-spacing: -0.03em;
  line-height: 1.15;
}

.node.root.is-long .label { font-size: 16px; }

.node .label {
  font-size: 14.5px;
  font-weight: 650;
  line-height: 1.25;
  letter-spacing: -0.01em;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.node.box .label { -webkit-line-clamp: 2; font-size: 14px; }

.node .hint {
  color: var(--cream-dim);
  font-size: 12px;
  line-height: 1.3;
  font-weight: 500;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.node .kicker {
  position: absolute;
  top: -18px;
  left: 14px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--rim, var(--brass));
  white-space: nowrap;
}

.node.bubble .kicker, .node.root .kicker {
  left: 50%;
  transform: translateX(-50%);
}

.node.root .kicker, .node.root .badge { color: #8a5a28; }

.node.bubble:not(.has-kids)::after {
  content: "";
  position: absolute;
  inset: -8px;
  border-radius: inherit;
  border: 1px dashed var(--rim, var(--brass));
  opacity: 0.75;
  pointer-events: none;
}

.node.is-selected {
  z-index: 3;
  background: #262119;
  box-shadow: 0 0 0 5px var(--wash, rgba(224, 161, 90, 0.18)), var(--shadow);
}

.node.root.is-selected { background: #fffaf2; }

.node.is-loading::before {
  content: "";
  position: absolute;
  inset: -7px;
  border-radius: inherit;
  padding: 2px;
  background: conic-gradient(from 40deg, transparent 0 30%, var(--rim, var(--brass)) 85% 100%);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  mask-composite: exclude;
  animation: spin 0.9s linear infinite;
  pointer-events: none;
}

.node.box {
  box-shadow: inset 3px 0 0 var(--rim, var(--brass)), var(--shadow);
}

@keyframes spin { to { transform: rotate(1turn); } }

#zoom {
  position: fixed;
  z-index: 5;
  top: 78px;
  right: 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

#zoom[hidden] { display: none; }

#zoom button {
  width: 36px;
  height: 36px;
  backdrop-filter: blur(8px);
}

#dock {
  position: fixed;
  z-index: 6;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  width: min(860px, calc(100vw - 20px));
  padding: 14px 14px 12px;
  border: 1px solid rgba(246, 241, 231, 0.12);
  border-radius: 22px;
  background: rgba(22, 19, 15, 0.92);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

#dock[hidden] { display: none; }

.dock-top {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.dock-copy { min-width: 0; flex: 1; }

.dock-kicker {
  margin: 0;
  color: var(--brass);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.dock-title {
  margin: 2px 0 0;
  font-family: Fraunces, Georgia, serif;
  font-size: 22px;
  font-weight: 560;
  letter-spacing: -0.03em;
  line-height: 1.15;
}

.dock-hint, .dock-status {
  margin: 4px 0 0;
  color: var(--cream-dim);
  font-size: 13.5px;
  line-height: 1.35;
}

.dock-remove {
  flex: none;
  padding: 7px 10px;
  color: var(--danger);
}

.actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: thin;
}

.action {
  flex: none;
  padding: 8px 12px;
  color: var(--cream-dim);
  background: transparent;
}

.action strong {
  display: block;
  font-weight: 650;
  color: var(--cream);
  font-size: 13px;
}

.action small {
  display: block;
  margin-top: 1px;
  font-size: 11px;
  color: rgba(217, 208, 194, 0.7);
}

.action.primary {
  background: var(--cream);
  color: var(--ink);
  border-color: transparent;
}

.action.primary strong, .action.primary small { color: var(--ink); }
.action.primary small { opacity: 0.7; }

.action.done { border-color: rgba(224, 161, 90, 0.7); }

.action:disabled { opacity: 0.45; cursor: wait; }

#toast {
  position: fixed;
  z-index: 7;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%) translateY(12px);
  max-width: min(520px, calc(100vw - 24px));
  padding: 12px 14px;
  border-radius: 14px;
  background: #3a2a24;
  color: #f8e7e1;
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
}

#toast.is-on {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

body.has-dock #toast.is-on { bottom: 168px; }

@media (max-width: 720px) {
  header { padding: 0 14px; }
  .model-line { display: none; }
  h1 { font-size: 42px; }
  #composer { flex-wrap: wrap; }
  #map-it { width: 100%; }
  .dock-title { font-size: 18px; }
  .action small { display: none; }
  #dock { bottom: max(10px, env(safe-area-inset-bottom)); }
}

@media (prefers-reduced-motion: reduce) {
  .node, #toast { transition: none; }
  .node.is-loading::before { animation: none; }
}
