/* Perancang Alur Cabang — The Judge. Palet ungu saja, tanpa warna hangat. */
:root {
  --bg: #0B0720;
  --panel: #25134D;
  --panel-2: #1B0E3A;
  --accent: #6A2FC8;
  --soft: #9D71E8;
  --line: #D1B8FF;
  --text: #F2E9FF;
  --muted: #B9A3E8;
  --white: #FFFFFF;
  --black: #111111;
  --danger: #FF5C5C;
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
}

#app {
  max-width: 640px;
  margin: 0 auto;
  min-height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* ---------- bilah atas ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  background: var(--bg);
  border-bottom: 1px solid var(--panel);
}

.topbar h1 {
  flex: 1;
  font-size: 1.15rem;
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

main { padding: 14px; }

/* ---------- tombol & input ---------- */

.btn {
  appearance: none;
  border: 1px solid var(--soft);
  background: var(--panel);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 0.95rem;
  min-height: 44px;
  cursor: pointer;
}

.btn.primary { background: var(--accent); border-color: var(--accent); }
.btn.danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.small { min-height: 38px; padding: 7px 10px; font-size: 0.88rem; }
.btn:disabled { opacity: 0.45; cursor: default; }

.icon-btn {
  appearance: none;
  border: 1px solid transparent;
  background: var(--panel);
  color: var(--text);
  border-radius: 50%;
  width: 44px;
  height: 44px;
  font-size: 1.15rem;
  cursor: pointer;
  position: relative;
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

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

.input {
  width: 100%;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--soft);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 1rem;
  font-family: inherit;
  min-height: 44px;
}

.input.num { width: 90px; }
textarea.input { resize: vertical; min-height: 88px; }
.input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.row { display: flex; align-items: center; }
.row.gap { gap: 8px; flex-wrap: wrap; }
.row.between { justify-content: space-between; margin-top: 14px; }
.hint { color: var(--muted); font-size: 0.88rem; margin: 0 0 12px; }
.empty { color: var(--muted); text-align: center; padding: 32px 0; }
.small { font-size: 0.88rem; }
.ok-text { color: var(--text); }

/* ---------- daftar jiwa ---------- */

.list-head { margin-bottom: 14px; }

.soul-card {
  display: flex;
  gap: 8px;
  align-items: stretch;
  background: var(--panel);
  border: 1px solid var(--soft);
  border-radius: var(--radius);
  margin-bottom: 10px;
  overflow: hidden;
}

.soul-main {
  flex: 1;
  appearance: none;
  background: none;
  border: 0;
  color: var(--text);
  text-align: left;
  padding: 14px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.soul-name { font-size: 1.05rem; font-weight: 700; }
.soul-meta { color: var(--line); font-size: 0.9rem; }
.soul-deeds { color: var(--muted); font-size: 0.85rem; }
.list-foot { margin-top: 18px; text-align: center; }

.warn-count { color: var(--danger); font-weight: 700; }
.warn-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  background: var(--danger);
  color: #fff;
  font-size: 0.68rem;
  font-weight: 700;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
}

/* ---------- grafik simpul ---------- */

.graph {
  position: relative;
  padding: 18px 0 26px;
}

#edges {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
  z-index: 0;
  overflow: visible;
}

#edges .edge {
  fill: none;
  stroke: var(--soft);
  stroke-width: 2;
  opacity: 0.75;
}

#edges .edge-active {
  stroke: var(--text);
  stroke-width: 2.5;
  opacity: 1;
}

.node-row {
  position: relative;
  z-index: 1;
  display: flex;
  justify-content: center;
  padding: 14px 0;
}

.symbol {
  appearance: none;
  position: relative;
  width: 64px;
  height: 64px;
  border-radius: 16px;
  border: 2px solid var(--line);
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
  padding: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.symbol svg { width: 100%; height: 100%; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.symbol svg text { font-family: inherit; font-weight: 700; }

.symbol:active { background: var(--accent); }

.node-row.sim-current .symbol {
  border-color: var(--text);
  background: var(--accent);
  box-shadow: 0 0 0 4px rgba(157, 113, 232, 0.45);
}

.node-row.sim-target .symbol {
  border-color: var(--soft);
  animation: pulse 1.4s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(157, 113, 232, 0.55); }
  50% { box-shadow: 0 0 0 7px rgba(157, 113, 232, 0.12); }
}

.pips {
  position: absolute;
  right: -8px;
  bottom: -8px;
  display: flex;
  gap: 3px;
}

.pip {
  font-size: 0.62rem;
  font-weight: 700;
  line-height: 1;
  border-radius: 8px;
  padding: 3px 5px;
  white-space: nowrap;
}

.pip-dharma { background: var(--white); color: var(--black); }
.pip-karma { background: var(--black); color: var(--white); outline: 1px solid var(--line); }

.nonext-mark {
  position: absolute;
  right: 6px;
  bottom: 6px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  border: 2px solid var(--soft);
  background: transparent;
}

.warn-mark {
  position: absolute;
  top: -9px;
  right: -9px;
  color: var(--danger);
  font-size: 1.05rem;
  line-height: 1;
  text-shadow: 0 0 4px var(--bg);
}

.warn-mark.static { position: static; text-shadow: none; }

/* ---------- simulasi ---------- */

.card {
  background: var(--panel);
  border: 1px solid var(--soft);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 12px;
}

.scales {
  display: flex;
  height: 12px;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid var(--line);
}

.scales-dharma { background: var(--white); }
.scales-karma { background: var(--black); }
.sim-totals { margin-top: 8px; font-size: 0.95rem; }
.sim-speaker { font-weight: 700; margin: 0 0 4px; color: var(--line); }
.sim-text { margin: 0 0 12px; white-space: pre-wrap; }
.sim-done { font-weight: 700; color: var(--soft); margin: 0 0 8px; }
.sim-choices { display: flex; flex-direction: column; gap: 8px; }
.sim-choice { width: 100%; text-align: left; }

/* ---------- lembar & modal ---------- */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(5, 2, 16, 0.72);
  z-index: 80;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.sheet, .picker-sheet {
  width: 100%;
  max-width: 640px;
  max-height: 88dvh;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--soft);
  border-bottom: 0;
  border-radius: 18px 18px 0 0;
  padding: 14px 16px calc(18px + env(safe-area-inset-bottom));
}

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

.sheet-head h2 { font-size: 1.05rem; margin: 0; }

.field { margin-bottom: 14px; }
.field > label { display: block; font-size: 0.88rem; color: var(--line); margin-bottom: 6px; }
.static-value { padding: 10px 12px; background: var(--panel-2); border-radius: 10px; }
.picker-btn { width: 100%; text-align: left; justify-content: space-between; display: flex; }
.mini { font-size: 0.88rem; color: var(--line); display: flex; align-items: center; gap: 6px; }

.choice-row, .deed-row {
  display: flex;
  gap: 6px;
  align-items: center;
  margin-bottom: 8px;
}

.choice-row .input { flex: 1; min-width: 0; }
.deed-row .input:first-child { flex: 1; min-width: 0; }

.picker-list { display: flex; flex-direction: column; }
.picker-option {
  appearance: none;
  background: none;
  border: 0;
  border-bottom: 1px solid var(--panel-2);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 4px;
  font-size: 1rem;
  min-height: 52px;
  cursor: pointer;
  text-align: left;
}

.picker-option:last-child { border-bottom: 0; }
.picker-radio {
  flex: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid var(--line);
}
.picker-option.selected .picker-radio { border-color: var(--text); background: var(--accent); box-shadow: inset 0 0 0 3px var(--panel); }

.confirm-text { margin: 0 0 16px; }
.confirm-actions { display: flex; justify-content: flex-end; gap: 8px; }
.issues-list { list-style: none; margin: 0; padding: 0; }
.issues-list li { padding: 10px 0; border-bottom: 1px solid var(--panel-2); }
.issues-list li:last-child { border-bottom: 0; }
.txt-view { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 0.82rem; }

/* ---------- toast ---------- */

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(8px);
  background: var(--panel);
  border: 1px solid var(--soft);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 0.92rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
  z-index: 120;
  max-width: 90vw;
  text-align: center;
}

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

@media (prefers-reduced-motion: reduce) {
  .node-row.sim-target .symbol { animation: none; }
  #toast { transition: none; }
}
