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

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  font-family: "Nunito", system-ui, -apple-system, 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; }

.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;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}

.toolbar button:hover { background: #f6eadb; }
.toolbar button:active { transform: translateY(1px); }
.toolbar button.on { background: #fde6c8; border-color: var(--orange); }
.cards-toggle { display: none; }
#btn-connect { background: #fde6c8; border-color: #f0c9a0; }

.tabs {
  height: var(--tabs-h);
  display: flex;
  align-items: flex-end;
  gap: 4px;
  padding: 0 12px;
  background: #f6efe4;
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
}

.tabs button.tab,
.tabs button.tab-add {
  border: 0;
  background: transparent;
  border-radius: 10px 10px 0 0;
  padding: 8px 12px;
  font-size: 0.84rem;
  font-weight: 700;
  cursor: pointer;
  color: var(--ink-soft);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}

.tabs button.tab.on {
  background: var(--paper);
  color: var(--ink);
}

.tabs button.tab .x {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.95rem;
  line-height: 1;
}

.tabs button.tab .x:hover { background: #fde6c8; color: var(--ink); }
.tabs button.tab-add { font-size: 1.15rem; padding: 6px 12px; }
.tabs button.tab-add:hover,
.tabs button.tab:hover { background: rgba(255, 253, 249, 0.7); }

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

#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; }

.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,
.legend .key {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 0;
  background: transparent;
  padding: 3px 6px;
  border-radius: 8px;
  text-align: left;
  font-size: 0.8rem;
  color: inherit;
}

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

.legend .key {
  padding-left: 22px;
  color: var(--ink-soft);
  font-size: 0.75rem;
}

.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.25rem;
  margin: 0 0 4px;
  line-height: 1.25;
}

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

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

.desc {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  margin: 0 0 16px;
}

.desc-icon {
  width: 54px;
  height: 54px;
  border-radius: 16px;
  flex: none;
  display: grid;
  place-items: center;
}

.desc-icon svg {
  width: 28px;
  height: 28px;
  display: block;
}

.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;
}

.flag {
  display: inline-block;
  background: #fde6c8;
  color: var(--orange-dark);
  font-size: 0.75rem;
  font-weight: 700;
  border-radius: 999px;
  padding: 3px 8px;
  margin: 0 0 12px;
}

.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);
}

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;
}

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

.sheet {
  position: fixed;
  inset: 0;
  z-index: 6;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(58, 42, 34, 0.38);
}

.sheet[hidden] { display: none; }

.sheet-card {
  width: min(480px, 100%);
  max-height: min(88vh, 760px);
  overflow: auto;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 18px;
  box-shadow: 0 18px 50px rgba(58, 42, 34, 0.2);
}

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.sheet-head h2 { margin: 0; font-family: "Fredoka", sans-serif; font-size: 1.45rem; }
.sheet-card .sub { margin: 8px 0 14px; }

#sheet-close {
  border: 0;
  background: var(--cream);
  width: 32px;
  height: 32px;
  border-radius: 10px;
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
}

.pictures-label {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 16px 0 8px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
.optional {
  letter-spacing: 0;
  text-transform: none;
  font-weight: 700;
  background: var(--cream);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 8px;
}

.file-btn {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  background: var(--cream);
  border-radius: 10px;
  padding: 7px 12px;
  font-size: 0.86rem;
  font-weight: 700;
  cursor: pointer;
}

.file-btn:hover { background: #f6eadb; }
.file-btn input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.thumbs { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0 4px; }
.thumbs:empty { display: none; }
.thumbs figure {
  position: relative;
  margin: 0;
  width: 72px;
  height: 72px;
}
.thumbs img {
  width: 72px;
  height: 72px;
  object-fit: cover;
  border-radius: 12px;
  border: 1px solid var(--line);
  display: block;
}
.thumbs button {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 22px;
  height: 22px;
  border: 0;
  border-radius: 50%;
  background: var(--ink);
  color: #fff;
  cursor: pointer;
  line-height: 1;
}

.field { display: grid; gap: 6px; margin-top: 12px; }
.field span {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
.field textarea,
.field input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--cream);
  padding: 10px 12px;
  resize: vertical;
}
.field textarea:focus,
.field input:focus { outline: none; border-color: var(--orange); background: #fff; }

.sheet-note { color: var(--ink-soft); font-size: 0.8rem; margin: 10px 0 14px; }

#sheet-go {
  border: 0;
  background: var(--orange);
  color: #fff;
  border-radius: 12px;
  padding: 10px 16px;
  font-weight: 700;
  cursor: pointer;
}
#sheet-go:disabled { opacity: 0.6; cursor: wait; }

.sheet-status { min-height: 1.3em; margin: 10px 0 0; font-size: 0.86rem; }
.sheet-status.error { color: var(--red); }

@media (max-width: 820px) {
  .cards-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;
    box-shadow: none;
  }
  .panel.open {
    transform: none;
    box-shadow: -8px 0 24px rgba(58, 42, 34, 0.12);
  }
  .legend { max-height: 42vh; overflow: auto; }
  #search { width: 140px; }
}
