:root {
  --cream: #fbf5ec;
  --paper: #fffdf9;
  --ink: #3a2a22;
  --ink-soft: #6e5a4e;
  --line: #eadfce;
  --orange: #e8894f;
  --orange-dark: #c96a33;
  --toolbar-h: 58px;
  --chrome: var(--toolbar-h);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  font-family: "Nunito", system-ui, sans-serif;
  color: var(--ink);
  background: var(--cream);
}

button, input { font: inherit; color: inherit; }

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

.toolbar {
  height: var(--toolbar-h);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 16px;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 2px 10px rgba(58, 42, 34, 0.05);
  position: relative;
  z-index: 2;
  white-space: nowrap;
  overflow-x: auto;
}

.brand {
  font-family: "Fredoka", sans-serif;
  font-weight: 600;
  font-size: 1.15rem;
  color: var(--ink);
  text-decoration: none;
  margin-right: 6px;
}

.brand span {
  font-family: "Nunito", sans-serif;
  font-weight: 700;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--orange-dark);
  margin-left: 6px;
}

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

.space {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-right: 6px;
  color: var(--ink-soft);
  font-size: 0.8rem;
  font-weight: 700;
}

.space input[type="range"] {
  width: 112px;
  accent-color: var(--orange);
  cursor: pointer;
}

.toolbar button {
  border: 1px solid var(--line);
  background: var(--cream);
  border-radius: 10px;
  padding: 6px 12px;
  font-size: 0.86rem;
  font-weight: 700;
  cursor: pointer;
}

.toolbar button:hover { background: #f6eadb; }
.toolbar button.on { background: #fde6c8; border-color: var(--orange); }
.notes-toggle { display: none; }

#search {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 6px 12px;
  width: 200px;
  background: var(--cream);
  outline: none;
}

#search:focus { border-color: var(--orange); background: #fff; }

.workspace { display: flex; height: calc(100% - var(--chrome)); }

.stage { position: relative; flex: 1; min-width: 0; }

#map {
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
  touch-action: none;
}

#map.panning { cursor: grabbing; }
#map.over-node { cursor: pointer; }

.legend {
  position: absolute;
  left: 16px;
  bottom: 16px;
  background: rgba(255, 253, 249, 0.94);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px 12px;
  font-size: 0.8rem;
  display: grid;
  gap: 2px;
  box-shadow: 0 4px 16px rgba(58, 42, 34, 0.08);
  max-width: min(280px, calc(100% - 32px));
}

.legend-title {
  font-weight: 700;
  color: var(--ink-soft);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 4px;
}

.legend button {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 0;
  background: transparent;
  padding: 3px 6px;
  border-radius: 8px;
  text-align: left;
  font-size: 0.8rem;
  cursor: pointer;
  color: inherit;
}

.legend button:hover { background: var(--cream); }
.legend button.on { background: #fde6c8; font-weight: 700; }

.legend .count {
  margin-left: auto;
  padding-left: 10px;
  color: var(--ink-soft);
  font-size: 0.72rem;
}

.swatch {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  display: inline-block;
  flex: none;
}

.hint {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(58, 42, 34, 0.82);
  color: #fff;
  padding: 7px 16px;
  border-radius: 999px;
  font-size: 0.8rem;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.25s;
  white-space: nowrap;
  max-width: calc(100% - 32px);
  overflow: hidden;
  text-overflow: ellipsis;
}

.hint.show { opacity: 1; }

.panel {
  width: 340px;
  flex: none;
  background: var(--paper);
  border-left: 1px solid var(--line);
  padding: 20px;
  overflow-y: auto;
}

.panel h2 {
  font-family: "Fredoka", sans-serif;
  font-weight: 600;
  font-size: 1.35rem;
  margin: 0 0 8px;
  line-height: 1.2;
}

.panel .sub {
  color: var(--ink-soft);
  font-size: 0.82rem;
  margin: 0 0 14px;
}

.panel .prose {
  font-size: 0.92rem;
  line-height: 1.55;
  margin: 0 0 12px;
}

.kicker {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin: 0 0 8px;
}

.stats { display: flex; gap: 10px; margin: 4px 0 16px; }
.stats div {
  flex: 1;
  background: var(--cream);
  border-radius: 12px;
  padding: 10px;
  text-align: center;
}
.stats b {
  display: block;
  font-family: "Fredoka", sans-serif;
  font-size: 1.4rem;
}
.stats small { color: var(--ink-soft); font-size: 0.75rem; }

.section-label {
  margin: 16px 0 8px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  background: var(--cream);
  border-radius: 10px;
  padding: 4px 10px;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  text-align: left;
}
.chips button:hover { background: #f6eadb; }
.chips button .mini {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex: none;
}

.tips { font-size: 0.86rem; line-height: 1.55; padding-left: 0; list-style: none; margin: 0; }
.tips li { margin: 8px 0; padding-left: 14px; position: relative; }
.tips li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0.6em;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--orange);
}

.wire-note {
  background: var(--cream);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 0.86rem;
  line-height: 1.5;
  margin-top: 8px;
}

kbd {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.75rem;
  background: var(--cream);
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 5px;
  padding: 0 5px;
}

@media (max-width: 820px) {
  .notes-toggle { display: inline-block; }
  .panel {
    position: absolute;
    right: 0;
    bottom: 0;
    top: var(--chrome);
    width: min(320px, 88vw);
    transform: translateX(105%);
    transition: transform 0.2s ease;
    z-index: 3;
  }
  .panel.open {
    transform: none;
    box-shadow: -8px 0 24px rgba(58, 42, 34, 0.12);
  }
  .legend { max-height: 42vh; overflow: auto; }
  #search { width: 140px; }
}
