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

:root {
  --bg: #111;
  --surface: #1c1c1c;
  --border: #2e2e2e;
  --accent: #7c6af7;
  --accent-bg: rgba(124,106,247,0.10);
  --accent-border: rgba(124,106,247,0.35);
  --text: #ddd;
  --text-dim: #555;
  --text-mid: #888;
  --match: #f0c040;
  --radius: 6px;
  --indent: 20px;
  --font: system-ui, -apple-system, sans-serif;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  min-height: 100vh;
}

#root {
  max-width: 680px;
  margin: 0 auto;
  padding: 0 20px 80px;
}

/* ── Search bar ── */
.search-wrap {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
  padding: 18px 0 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.search-row {
  display: flex;
  align-items: center;
  gap: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color 0.15s;
  overflow: hidden;
}

.search-row:focus-within {
  border-color: var(--accent);
}

.search-icon {
  padding: 0 10px;
  color: var(--text-dim);
  font-size: 15px;
  flex-shrink: 0;
  pointer-events: none;
  line-height: 1;
}

.search-input {
  flex: 1;
  background: none;
  border: none;
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  outline: none;
  padding: 10px 0;
  min-width: 0;
}

.search-input::placeholder { color: var(--text-dim); }

.search-clear {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 16px;
  padding: 0 12px;
  line-height: 1;
  transition: color 0.15s;
  display: none;
}
.search-clear.visible { display: block; }
.search-clear:hover { color: var(--text); }

/* Add-new prompt that appears when search has no match */
.search-add-prompt {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.search-add-prompt:hover {
  border-color: var(--accent);
  background: var(--accent-bg);
}
.search-add-label {
  color: var(--text-mid);
  font-size: 13px;
}
.search-add-label strong {
  color: var(--text);
  font-weight: 600;
}
.search-add-icon {
  color: var(--accent);
  font-size: 16px;
  font-weight: 300;
  line-height: 1;
  flex-shrink: 0;
}

/* ── App title (small, inline with search) ── */
.app-title {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
  padding-bottom: 2px;
}

/* ── Tree ── */
.tree-root {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.node { display: flex; flex-direction: column; }

.node-row {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 4px 5px;
  border-radius: var(--radius);
  transition: background 0.1s;
  min-height: 30px;
}

.node-row:hover { background: var(--surface); }
.node-row:hover .node-actions { opacity: 1; }

/* dim non-matching nodes during search */
.node-row.search-dim { opacity: 0.22; }
.node-row.search-match .node-label mark {
  background: none;
  color: var(--match);
  font-weight: 700;
}

.node-toggle {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 9px;
  width: 14px;
  flex-shrink: 0;
  padding: 0;
  line-height: 1;
  user-select: none;
  transition: color 0.1s;
}
.node-toggle:hover { color: var(--text); }
.node-toggle.leaf { cursor: default; visibility: hidden; }

.node-bullet {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--text-dim);
  flex-shrink: 0;
  transition: background 0.1s;
}
.node-row:hover .node-bullet,
.node-row.search-match .node-bullet { background: var(--accent); }

.node-label {
  flex: 1;
  line-height: 1.4;
  cursor: text;
  outline: none;
  border-radius: 3px;
  padding: 1px 3px;
  margin: -1px -3px;
  white-space: pre-wrap;
  word-break: break-word;
}
.node-label:focus { background: var(--accent-bg); caret-color: var(--accent); }

.node-actions {
  display: flex;
  gap: 3px;
  opacity: 0;
  transition: opacity 0.1s;
  flex-shrink: 0;
}

.action-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 11px;
  padding: 2px 7px;
  transition: border-color 0.12s, color 0.12s;
  white-space: nowrap;
  font-family: var(--font);
}
.action-btn:hover { border-color: var(--accent); color: var(--accent); }
.action-btn.del:hover { border-color: #b33; color: #c44; }

.node-children {
  margin-left: calc(var(--indent) + 5px);
  border-left: 1px solid var(--border);
  padding-left: 10px;
  display: flex;
  flex-direction: column;
  gap: 1px;
  margin-top: 1px;
  margin-bottom: 1px;
}
.node-children.collapsed { display: none; }

/* Loading */
.loading-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 6px;
  color: var(--text-dim);
  font-size: 12px;
}
.spinner {
  width: 11px; height: 11px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty-tree {
  color: var(--text-dim);
  font-size: 13px;
  padding: 6px 2px;
}

/* ── Question ── */
.question-box {
  padding: 9px 11px;
  border: 1px solid var(--accent-border);
  border-radius: var(--radius);
  background: var(--accent-bg);
  display: flex;
  flex-direction: column;
  gap: 7px;
  margin: 2px 0;
}

/* ── Options ── */
.options-box {
  padding: 9px 11px;
  border: 1px solid rgba(167, 139, 250, 0.35);
  border-radius: var(--radius);
  background: rgba(167, 139, 250, 0.08);
  display: flex;
  flex-direction: column;
  gap: 7px;
  margin: 2px 0;
}
.options-header {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-dim);
}
.options-list {
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.option-btn {
  background: none;
  border: 1px solid rgba(167, 139, 250, 0.3);
  border-radius: 4px;
  color: #c4b5fd;
  cursor: pointer;
  font-family: var(--font);
  font-size: 13px;
  padding: 5px 10px;
  text-align: left;
  transition: all 0.12s;
  width: 100%;
}
.option-btn:hover {
  background: rgba(167, 139, 250, 0.2);
  border-color: rgba(167, 139, 250, 0.5);
  color: #e9d5ff;
}
.option-label { font-weight: 500; }
.option-desc { font-size: 12px; opacity: 0.75; margin-top: 2px; }
.question-text {
  font-size: 13px;
  color: var(--text);
  line-height: 1.45;
}
.question-text::before { content: '? '; color: var(--accent); font-weight: 700; }

.question-choices {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  align-items: center;
}
.choice-btn {
  background: none;
  border: 1px solid var(--accent-border);
  border-radius: 4px;
  color: var(--accent);
  cursor: pointer;
  font-family: var(--font);
  font-size: 12px;
  padding: 3px 9px;
  transition: background 0.12s;
}
.choice-btn:hover { background: rgba(124,106,247,0.18); }

.answer-form { display: flex; gap: 5px; }
.answer-input {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  padding: 4px 8px;
  outline: none;
  min-width: 0;
  transition: border-color 0.12s;
}
.answer-input:focus { border-color: var(--accent); }
.answer-input::placeholder { color: var(--text-dim); }
.answer-btn {
  background: var(--accent-bg);
  border: 1px solid var(--accent-border);
  border-radius: 4px;
  color: var(--accent);
  cursor: pointer;
  font-family: var(--font);
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  transition: background 0.12s;
  white-space: nowrap;
}
.answer-btn:hover { background: rgba(124,106,247,0.25); }

/* ── Answer records ── */
.answers-wrap {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-bottom: 4px;
}
.answer-record {
  display: flex;
  align-items: baseline;
  gap: 6px;
  padding: 3px 6px;
  border-radius: 4px;
  font-size: 12px;
  line-height: 1.4;
}
.answer-record-q {
  color: var(--text-dim);
  font-style: italic;
  flex-shrink: 0;
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.answer-record-arrow {
  color: var(--text-dim);
  flex-shrink: 0;
}
.answer-record-a {
  color: var(--text-mid);
  font-weight: 500;
}

/* ── Options ── */
.options-box {
  padding: 9px 11px;
  border: 1px solid rgba(167, 139, 250, 0.35);
  border-radius: var(--radius);
  background: rgba(167, 139, 250, 0.08);
  display: flex;
  flex-direction: column;
  gap: 7px;
  margin: 2px 0;
}
.options-header {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-dim);
}
.options-list {
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.option-btn {
  background: none;
  border: 1px solid rgba(167, 139, 250, 0.3);
  border-radius: 4px;
  color: #c4b5fd;
  cursor: pointer;
  font-family: var(--font);
  font-size: 13px;
  padding: 5px 10px;
  text-align: left;
  transition: all 0.12s;
  width: 100%;
}
.option-btn:hover {
  background: rgba(167, 139, 250, 0.2);
  border-color: rgba(167, 139, 250, 0.5);
  color: #e9d5ff;
}
