:root {
  --bg0: #07020f;
  --bg1: #100924;
  --bg2: #1c1038;
  --panel: rgba(25, 14, 48, 0.72);
  --panel-strong: rgba(35, 22, 66, 0.92);
  --line: rgba(168, 130, 255, 0.38);
  --line-soft: rgba(255, 255, 255, 0.11);
  --text: #f4efff;
  --muted: #bdb1df;
  --dim: #81739c;
  --gold: #ffd98a;
  --violet: #a777ff;
  --cyan: #82f4ff;
  --pink: #ff87dc;
  --green: #90ffbd;
  --red: #ff6f9a;
  --shadow: 0 18px 52px rgba(0, 0, 0, 0.42);
  --radius: 22px;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", Meiryo, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; background: var(--bg0); color: var(--text); }
body {
  background:
    radial-gradient(circle at 20% 10%, rgba(137, 77, 255, 0.26), transparent 32%),
    radial-gradient(circle at 85% 20%, rgba(55, 237, 255, 0.14), transparent 34%),
    radial-gradient(circle at 45% 86%, rgba(255, 121, 218, 0.12), transparent 38%),
    linear-gradient(160deg, var(--bg0), var(--bg1) 48%, #070412);
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }

.app-shell { position: relative; width: 100%; height: 100dvh; overflow: hidden; isolation: isolate; }
.app-shell::before {
  content: "";
  position: absolute; inset: 0;
  background-image:
    radial-gradient(circle, rgba(255,255,255,0.4) 0 1px, transparent 1.6px),
    radial-gradient(circle, rgba(130,244,255,0.25) 0 1px, transparent 1.8px);
  background-size: 74px 74px, 119px 119px;
  opacity: 0.18;
  pointer-events: none;
}

.glass-panel {
  background: linear-gradient(145deg, rgba(34, 19, 66, 0.78), rgba(13, 7, 28, 0.68));
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255,255,255,0.08);
  backdrop-filter: blur(18px);
}

.topbar {
  position: absolute; z-index: 40; left: max(12px, env(safe-area-inset-left)); right: max(12px, env(safe-area-inset-right)); top: max(10px, env(safe-area-inset-top));
  height: 66px; border-radius: 24px; display: flex; align-items: center; justify-content: space-between; padding: 10px 12px 10px 14px;
}
.brand-block { display: flex; align-items: center; min-width: 0; gap: 10px; }
.brand-mark {
  width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center;
  color: var(--gold); font-size: 21px;
  background: radial-gradient(circle at 35% 30%, rgba(255,255,255,0.26), rgba(167,119,255,0.22) 45%, rgba(4,2,15,0.9) 100%);
  box-shadow: 0 0 24px rgba(167,119,255,0.55), inset 0 0 14px rgba(255,255,255,0.12);
  border: 1px solid rgba(255,255,255,0.19);
}
h1 { margin: 0; font-size: 17px; letter-spacing: 0.06em; line-height: 1.1; }
#statusLine { margin: 4px 0 0; color: var(--muted); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 66vw; }
.icon-btn {
  width: 42px; height: 42px; border-radius: 15px; border: 1px solid rgba(255,255,255,0.13); background: rgba(255,255,255,0.06);
  display: grid; place-items: center; box-shadow: inset 0 1px 0 rgba(255,255,255,0.08);
}
.icon-btn.small { width: 34px; height: 34px; border-radius: 12px; }
.icon-btn:active, button:active { transform: translateY(1px) scale(0.99); }

.stage-strip {
  position: absolute; z-index: 38; top: calc(max(10px, env(safe-area-inset-top)) + 76px); left: max(12px, env(safe-area-inset-left)); right: max(12px, env(safe-area-inset-right));
  height: 48px; border-radius: 18px; display: flex; align-items: center; gap: 8px; padding: 7px;
}
.stage-chips { flex: 1; display: flex; gap: 7px; overflow-x: auto; scrollbar-width: none; }
.stage-chips::-webkit-scrollbar { display: none; }
.stage-chip, .stage-add {
  border: 1px solid rgba(255,255,255,0.13); background: rgba(255,255,255,0.06); color: var(--muted); border-radius: 999px; min-height: 34px;
  padding: 0 13px; white-space: nowrap; display: inline-flex; align-items: center; gap: 6px;
}
.stage-chip.active { color: var(--text); background: linear-gradient(135deg, rgba(167,119,255,0.34), rgba(130,244,255,0.12)); box-shadow: 0 0 22px rgba(167,119,255,0.23); border-color: rgba(255,255,255,0.24); }
.stage-add { width: 36px; padding: 0; justify-content: center; color: var(--gold); }

.canvas-viewport { position: absolute; inset: 0; overflow: hidden; touch-action: none; cursor: grab; }
.canvas-viewport:active { cursor: grabbing; }
.background-orbits {
  position: absolute; inset: 102px -80px 120px -80px; opacity: 0.18; pointer-events: none;
  background:
    radial-gradient(ellipse at center, transparent 0 32%, rgba(255,255,255,0.15) 32.2% 32.6%, transparent 32.8%),
    radial-gradient(ellipse at center, transparent 0 46%, rgba(130,244,255,0.12) 46.2% 46.5%, transparent 46.8%),
    radial-gradient(ellipse at center, transparent 0 61%, rgba(255,217,138,0.10) 61.2% 61.5%, transparent 61.8%);
  transform: rotate(-16deg);
}
.world { position: absolute; left: 0; top: 0; width: 5000px; height: 5000px; transform-origin: 0 0; will-change: transform; }
.link-layer { position: absolute; inset: 0; width: 5000px; height: 5000px; overflow: visible; pointer-events: none; }
.node-layer { position: absolute; inset: 0; width: 5000px; height: 5000px; }

.link-path { fill: none; stroke-width: 4; stroke-linecap: round; filter: drop-shadow(0 0 6px rgba(167,119,255,0.35)); opacity: 0.94; }
.link-path.required { stroke: rgba(255,217,138,0.72); stroke-width: 5; }
.link-path.recommended { stroke: rgba(130,244,255,0.48); stroke-dasharray: 12 10; }
.link-path.unlocks { stroke: rgba(144,255,189,0.62); stroke-width: 4.5; }
.link-path.supports { stroke: rgba(167,119,255,0.48); stroke-dasharray: 3 10; }
.link-path.conflicts { stroke: rgba(255,111,154,0.68); stroke-dasharray: 10 8 2 8; }
.link-path.dimmed { opacity: 0.24; }
.link-glow { fill: none; stroke: rgba(255,255,255,0.14); stroke-width: 13; stroke-linecap: round; opacity: 0.45; }
.link-arrow { fill: rgba(255,255,255,0.58); }

.node {
  position: absolute; width: 104px; height: 104px; left: 0; top: 0; border-radius: 50%; transform: translate(-52px, -52px);
  display: grid; place-items: center; text-align: center; padding: 10px; user-select: none; touch-action: none;
  background:
    radial-gradient(circle at 32% 24%, rgba(255,255,255,0.28), transparent 17%),
    radial-gradient(circle at 50% 58%, rgba(10, 5, 30, 0.38), rgba(10, 5, 28, 0.94) 62%),
    conic-gradient(from 18deg, rgba(167,119,255,0.82), rgba(130,244,255,0.35), rgba(255,217,138,0.64), rgba(167,119,255,0.82));
  border: 1px solid rgba(255,255,255,0.22);
  box-shadow: 0 0 28px rgba(167,119,255,0.28), inset 0 0 18px rgba(255,255,255,0.08), 0 10px 34px rgba(0,0,0,0.45);
}
.node::before {
  content: ""; position: absolute; inset: 5px; border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.14);
  background: radial-gradient(circle at 50% 30%, rgba(255,255,255,0.08), transparent 45%);
}
.node::after {
  content: ""; position: absolute; inset: -8px; border-radius: 50%;
  border: 1px solid rgba(167,119,255,0.18); opacity: 0.8;
}
.node .node-title { position: relative; z-index: 2; font-weight: 750; font-size: 12px; line-height: 1.25; letter-spacing: 0.01em; text-shadow: 0 1px 8px rgba(0,0,0,0.7); max-width: 76px; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; }
.node .node-type { position: absolute; z-index: 2; bottom: 8px; font-size: 9px; color: var(--muted); max-width: 76px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.node .node-handle { position: absolute; right: -5px; top: 41px; z-index: 5; width: 25px; height: 25px; border-radius: 50%; border: 1px solid rgba(255,255,255,0.3); background: rgba(130,244,255,0.22); box-shadow: 0 0 14px rgba(130,244,255,0.5); display: grid; place-items: center; font-size: 12px; }
.node.selected { outline: 2px solid rgba(255,217,138,0.72); box-shadow: 0 0 34px rgba(255,217,138,0.38), inset 0 0 18px rgba(255,255,255,0.08), 0 10px 34px rgba(0,0,0,0.45); }
.node.ready { animation: pulseReady 2.1s ease-in-out infinite; }
.node.blocked { filter: saturate(0.65); }
.node.blocked::after { border-color: rgba(255,111,154,0.34); }
.node.done { background:
    radial-gradient(circle at 32% 24%, rgba(255,255,255,0.34), transparent 17%),
    radial-gradient(circle at 50% 58%, rgba(4, 40, 26, 0.35), rgba(4, 20, 24, 0.96) 62%),
    conic-gradient(from 18deg, rgba(144,255,189,0.9), rgba(130,244,255,0.42), rgba(255,217,138,0.72), rgba(144,255,189,0.9));
}
.node.progress::before { animation: slowSpin 6s linear infinite; border-color: rgba(130,244,255,0.34); }
.node.hold { opacity: 0.68; filter: grayscale(0.25); }
.node.locked .node-handle { display: none; }
.node.link-target { outline: 2px dashed rgba(130,244,255,0.82); }
.node.search-hit { box-shadow: 0 0 36px rgba(255,135,220,0.62), inset 0 0 18px rgba(255,255,255,0.08), 0 10px 34px rgba(0,0,0,0.45); }

@keyframes pulseReady { 0%,100% { box-shadow: 0 0 24px rgba(255,217,138,0.26), inset 0 0 18px rgba(255,255,255,0.08), 0 10px 34px rgba(0,0,0,0.45); } 50% { box-shadow: 0 0 44px rgba(255,217,138,0.58), inset 0 0 18px rgba(255,255,255,0.08), 0 10px 34px rgba(0,0,0,0.45); } }
@keyframes slowSpin { to { transform: rotate(360deg); } }

.empty-hint { position: absolute; z-index: 20; left: 50%; top: 45%; transform: translate(-50%, -50%); width: min(82vw, 320px); border-radius: 24px; padding: 22px; text-align: center; color: var(--muted); display: grid; gap: 8px; }
.empty-hint strong { color: var(--text); }
.hint-icon { font-size: 32px; color: var(--gold); }
.hidden { display: none !important; }

.insight-panel { position: absolute; z-index: 30; left: max(12px, env(safe-area-inset-left)); right: max(12px, env(safe-area-inset-right)); bottom: calc(172px + env(safe-area-inset-bottom)); border-radius: 20px; padding: 8px; }
.insight-grid { display: grid; grid-template-columns: 1fr 1fr 1.25fr; gap: 8px; }
.insight-card { min-width: 0; border: 1px solid rgba(255,255,255,0.1); background: rgba(255,255,255,0.055); border-radius: 16px; padding: 8px 8px; text-align: left; display: grid; gap: 2px; }
.insight-card span { color: var(--muted); font-size: 10px; }
.insight-card strong { font-size: 17px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.floating-actions { position: absolute; z-index: 36; right: max(14px, env(safe-area-inset-right)); bottom: calc(188px + env(safe-area-inset-bottom)); display: grid; gap: 10px; }
.round-action { width: 56px; height: 56px; border-radius: 50%; border: 1px solid rgba(255,255,255,0.22); display: grid; place-items: center; font-size: 26px; box-shadow: var(--shadow); }
.round-action.primary { background: radial-gradient(circle at 30% 22%, rgba(255,255,255,0.28), rgba(255,217,138,0.38) 38%, rgba(167,119,255,0.72)); color: #fff9e7; }
.round-action.ghost { background: rgba(15, 8, 31, 0.72); color: var(--cyan); font-size: 22px; }

.detail-sheet {
  position: absolute; z-index: 50; left: 0; right: 0; bottom: 0; min-height: 146px; max-height: min(70dvh, 560px);
  border-radius: 28px 28px 0 0; padding: 8px 14px calc(12px + env(safe-area-inset-bottom)); overflow: auto; transform: translateY(0); transition: transform 180ms ease;
}
.sheet-grip { width: 48px; height: 5px; border-radius: 999px; background: rgba(255,255,255,0.22); margin: 2px auto 10px; }
.sheet-empty { min-height: 100px; display: grid; align-content: center; gap: 6px; color: var(--muted); text-align: center; }
.sheet-empty strong { color: var(--text); }
.sheet-content { display: grid; gap: 10px; }
.sheet-head { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: start; }
.tiny-label { display: block; font-size: 10px; letter-spacing: 0.16em; color: var(--dim); margin-bottom: 5px; }
.title-input, .desc-input, .text-input, .pill-select {
  width: 100%; border: 1px solid rgba(255,255,255,0.13); background: rgba(255,255,255,0.065); color: var(--text); border-radius: 15px; outline: none;
}
.title-input { font-size: 18px; font-weight: 760; padding: 10px 12px; }
.desc-input { resize: vertical; min-height: 76px; padding: 12px; line-height: 1.45; }
.text-input { padding: 12px; }
.pill-row { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; }
.pill-row::-webkit-scrollbar { display:none; }
.pill-select { min-width: 112px; padding: 9px 10px; border-radius: 999px; background-color: rgba(26, 16, 50, 0.96); }
.pill-select.compact { min-width: 120px; width: 132px; }
.pill-button, .sheet-actions button, .drawer-section button, .danger-btn {
  border: 1px solid rgba(255,255,255,0.13); background: rgba(255,255,255,0.065); color: var(--text); border-radius: 15px; padding: 10px 12px;
}
.pill-button { border-radius: 999px; white-space: nowrap; }
.pill-button.active { color: var(--gold); border-color: rgba(255,217,138,0.34); background: rgba(255,217,138,0.10); }
.derived-box { border: 1px solid rgba(255,255,255,0.1); background: rgba(255,255,255,0.045); border-radius: 18px; padding: 10px 11px; color: var(--muted); display: grid; gap: 6px; font-size: 12px; }
.derived-box strong { color: var(--text); }
.status-ready { color: var(--gold); }
.status-blocked { color: var(--red); }
.status-done { color: var(--green); }
.sheet-actions { display: grid; grid-template-columns: 1fr 1fr 1.35fr; gap: 8px; }
.sheet-actions button { min-height: 42px; }
#markDoneBtn { background: rgba(144,255,189,0.11); border-color: rgba(144,255,189,0.22); }
#connectFromBtn.active { color: var(--cyan); border-color: rgba(130,244,255,0.36); box-shadow: 0 0 20px rgba(130,244,255,0.16); }
.section-title { font-size: 12px; letter-spacing: 0.12em; color: var(--muted); margin: 2px 0 7px; }
.relation-row { display: flex; align-items: center; gap: 8px; color: var(--dim); font-size: 11px; }
.link-list { display: grid; gap: 7px; margin-top: 9px; }
.link-item { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; border: 1px solid rgba(255,255,255,0.1); background: rgba(255,255,255,0.045); border-radius: 14px; padding: 8px 9px; font-size: 12px; }
.link-item small { color: var(--dim); display: block; margin-top: 2px; }
.link-item button { border: none; background: rgba(255,111,154,0.12); color: var(--red); border-radius: 10px; padding: 7px 9px; }
.danger-row { display: flex; justify-content: flex-end; }
.danger-btn, .danger-lite { color: #ffc4d5 !important; border-color: rgba(255,111,154,0.22) !important; background: rgba(255,111,154,0.09) !important; }

.menu-drawer {
  position: absolute; z-index: 80; top: max(10px, env(safe-area-inset-top)); right: max(10px, env(safe-area-inset-right)); width: min(380px, calc(100vw - 20px)); max-height: calc(100dvh - 20px - env(safe-area-inset-top)); overflow: auto; border-radius: 26px; padding: 14px;
}
.drawer-head { display: flex; justify-content: space-between; align-items: start; margin-bottom: 12px; }
.drawer-head h2 { margin: 0; font-size: 19px; }
.drawer-section { display: grid; gap: 8px; margin: 12px 0; }
.drawer-section.two-col { grid-template-columns: 1fr 1fr; }
.drawer-note { color: var(--muted); font-size: 12px; line-height: 1.5; border-top: 1px solid rgba(255,255,255,0.09); padding-top: 12px; }
.toast { position: absolute; z-index: 100; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: rgba(16,9,36,0.94); border: 1px solid rgba(255,255,255,0.16); border-radius: 999px; padding: 10px 15px; color: var(--text); box-shadow: var(--shadow); max-width: 82vw; text-align: center; }

@media (min-width: 760px) {
  .detail-sheet { left: 50%; right: auto; width: min(680px, calc(100vw - 32px)); transform: translateX(-50%); border-radius: 28px 28px 0 0; }
  .insight-panel { left: 50%; right: auto; width: min(680px, calc(100vw - 32px)); transform: translateX(-50%); }
  .floating-actions { right: calc(50% - min(340px, calc((100vw - 32px) / 2)) - 72px); }
}

@media (max-height: 680px) {
  .insight-panel { bottom: calc(128px + env(safe-area-inset-bottom)); }
  .floating-actions { bottom: calc(142px + env(safe-area-inset-bottom)); }
  .detail-sheet { min-height: 108px; }
}
