:root{
  --bg:#0b0f14;
  --panel:#0f1620;
  --surface:#121b27;
  --card:#0f1a2b;
  --accent:#56b3ff;
  --accent-2:#7cffa8;
  --accent-3:#ffb457;
  --line:#2a3a52;
  --text:#e6eef9;
  --muted:#a4b2c6;
  --diag:#ff8e53;            /* diagonal 5→2 color */
  --shadow: 0 10px 30px rgba(0,0,0,.35), inset 0 1px 0 rgba(255,255,255,.02);
}

*{box-sizing:border-box}
html,body{height:100%}
body{
  margin:0;
  font-family:Inter, system-ui, -apple-system, Segoe UI, Roboto, Arial, "Noto Sans", sans-serif;
  background: radial-gradient(1200px 800px at 60% 20%, #0e1622 0%, var(--bg) 60%);
  color:var(--text);
}

.app{
  min-height:100svh;
  display:grid;
  grid-template-columns: 280px 1fr;
  gap:16px;
  padding:20px;
}

/* Toolbar */
.toolbar{
  display:flex; flex-direction:column; gap:14px;
  background:linear-gradient(180deg, var(--panel), #0b1420);
  border:1px solid #192233; border-radius:16px;
  padding:12px 12px 10px; box-shadow:var(--shadow);
  position:sticky; top:20px; align-self:start;
}
.btn{
  display:grid; grid-template-columns:36px 1fr auto;
  align-items:center; gap:10px;
  background:var(--surface); border:1px solid #1c2a3d; border-radius:12px;
  padding:10px 12px; cursor:pointer; box-shadow:var(--shadow);
  transition: transform .12s ease, border-color .2s ease, box-shadow .2s ease;
}
.btn:hover{ transform: translateY(-2px); border-color:#2b3d57; }
.btn:active{ transform: translateY(0); }
.btn .icon{ font-size:18px; filter: drop-shadow(0 0 6px rgba(255,255,255,.05));}
.btn .btn-text{ font-weight:800; letter-spacing:.2px;}
.btn .state-indicator{ inline-size:10px; block-size:10px; border-radius:50%; border:2px solid #24334a; background:#0a121c; }
.btn-title{ padding:14px 14px; border-radius:14px; background:linear-gradient(180deg,#142033,#0e1826); border:1px solid #22324a; box-shadow: 0 8px 24px rgba(31,73,125,.28), inset 0 1px 0 rgba(255,255,255,.03); }
.buttons{ display:flex; flex-direction:column; gap:10px; }
.btn.sub{ margin-left:24px; }   /* visual sub-button */

#toggle-cycle:checked ~ .app .toolbar label[for="toggle-cycle"] .state-indicator{ background: radial-gradient(circle at 40% 40%, #8de0ff, #1170ff); box-shadow: 0 0 12px #2f9bff; }
#toggle-power:checked ~ .app .toolbar label[for="toggle-power"] .state-indicator{ background: radial-gradient(circle at 40% 40%, #c3ffa9, #18ce7a); box-shadow: 0 0 12px #24f39d; }
#toggle-confluence:checked ~ .app .toolbar label[for="toggle-confluence"] .state-indicator{ background: radial-gradient(circle at 40% 40%, #ffd48a, #ff9f1a); box-shadow: 0 0 12px rgba(255,191,73,.85); }
#toggle-list:checked  ~ .app .toolbar label[for="toggle-list"]{ outline:2px solid var(--accent-2); }
#toggle-effects:checked ~ .app .toolbar .btn-title .state-indicator{ background: radial-gradient(circle at 40% 40%, #ffc7a1, #ff6f3d); box-shadow: 0 0 12px rgba(255,153,102,.75); }

/* List (titles only) */
.linear-list{
  background:linear-gradient(180deg, var(--panel), #0b1420); border:1px solid #192233;
  border-radius:14px; padding:10px; box-shadow:var(--shadow);
  max-block-size: 40svh; overflow:auto; display:none;
}
.linear-list ol{ margin:0; padding-left:1.1rem; display:grid; gap:.45rem; }
.linear-list li{
  background:#0f1a2b; border:1px solid #1a2b43; border-radius:10px; padding:.55rem .6rem; box-shadow:var(--shadow); font-size:14px; transform-origin:left center;
}
.linear-list .rank{
  display:inline-grid; place-items:center; inline-size:20px; block-size:20px; border-radius:6px; margin-right:.45rem; font-weight:800; color:#9dd1ff; background:#162a45; border:1px solid #27415f;
}
#toggle-list:checked ~ .app .toolbar .linear-list{ display:block; }

/* Confluence scaling when enabled */
#toggle-confluence:checked ~ .app .toolbar .linear-list ol li:nth-child(1),
#toggle-confluence:checked ~ .app .toolbar .linear-list ol li:nth-child(5){
  transform: scale(1);
}
#toggle-confluence:checked ~ .app .toolbar .linear-list ol li:nth-child(2),
#toggle-confluence:checked ~ .app .toolbar .linear-list ol li:nth-child(4){
  transform: scale(2);
}
#toggle-confluence:checked ~ .app .toolbar .linear-list ol li:nth-child(3){
  transform: scale(3);
}

/* Stage */
.stage{ display:block; }

/* Square — HALF SIZE now */
.square{
  position:relative;
  aspect-ratio:1/1;
  min-height:260px; /* half of 520px */
  background: radial-gradient(100% 100% at 50% 50%, #0e1928 0%, #0b1019 70%);
  border:1px solid #1a2636; border-radius:22px; box-shadow:var(--shadow);
  overflow:hidden;
}

/* Edges */
.edges{ position:absolute; inset:0; }
.edges .edge{
  stroke:#5da0ff; stroke-width:6; opacity:0;
  marker-end:url(#arrow); filter: drop-shadow(0 0 6px rgba(86,179,255,.35)); stroke-linecap:round;
}
.edges #arrow path{ fill:#5da0ff; }
.edges .diag{ stroke: var(--diag); filter: drop-shadow(0 0 6px rgba(255,142,83,.5)); }
.edges .diag + marker #arrow path { fill: var(--diag); } /* safe guard */

/* Nodes with dropdowns and adders — smaller to fit compact square */
.node{
  position:absolute; inline-size:150px;
  background:linear-gradient(180deg, var(--card), #0c1524);
  border:1px solid #1b2a40; border-radius:14px; box-shadow:var(--shadow); overflow:hidden;
}
.node[open]{ box-shadow: 0 14px 30px rgba(0,0,0,.45), inset 0 1px 0 rgba(255,255,255,.03); }
.node summary{ list-style:none; cursor:pointer; user-select:none; outline:none; display:flex; align-items:center; gap:8px; padding:10px 12px; }
.node summary::-webkit-details-marker{ display:none; }
.node .badge{ display:inline-grid; place-items:center; inline-size:24px; block-size:24px; border-radius:8px; background:linear-gradient(180deg, #1b2f4a, #13243a); border:1px solid #27415f; font-weight:800; color:#9dd1ff; font-size:12px;}
.node h3.title{ margin:0; font-size:14px; letter-spacing:.2px; }

.node .dropdown{
  position:absolute; inset-inline:10px; top:46px;
  display:none; z-index:3;
  background:#0e192a; border:1px solid #20324a; border-radius:10px; box-shadow:0 12px 24px rgba(0,0,0,.4);
  padding:6px; max-height:140px; overflow:auto;
}
.node:hover .dropdown{ display:grid; gap:6px; }
.dropdown .opt{
  background:#0f1a2b; border:1px solid #1a2b43; color:#cfe6ff;
  text-align:left; padding:.45rem .55rem; border-radius:8px; cursor:pointer; font-size:13px;
}
.dropdown .opt:hover{ border-color:#2a3e5a; transform: translateY(-1px); }

.node .content{ padding:0 12px 10px; }
.node .meta{ margin:.2rem 0 .45rem; color:var(--muted); font-size:12px; }
.node .tags{ margin:0; padding:0; list-style:none; display:flex; gap:6px; flex-wrap:wrap;}
.node .tags li{ font-size:10px; padding:.25rem .45rem; border-radius:999px; background:#0f2136; border:1px solid #213652; color:#b8d9ff; }

.node .adder{ display:flex; gap:6px; margin-top:.5rem; }
.node .adder input{
  flex:1; background:#0f1a2b; border:1px solid #1a2b43; color:#cfe6ff;
  border-radius:8px; padding:.45rem .5rem; font-size:12px;
}
.node .adder .add{
  background:#17325a; color:#d8ecff; border:1px solid #295189; border-radius:8px;
  padding:.45rem .6rem; cursor:pointer; font-size:12px;
}
.node .adder .add:hover{ background:#1c3a69; }

/* Positions (tight to corners) */
.center{ left:50%; top:50%; transform:translate(-50%,-50%); }
.top-left{ left:10px; top:10px; }
.top-right{ right:10px; top:10px; }
.bottom-left{ left:10px; bottom:10px;}
.bottom-right{ right:10px; bottom:10px;}

/* --- EFFECTS --- */

/* Cycle animation — slower (more time) */
@keyframes dash-flow {
  0%{ opacity:0; stroke-dasharray: 0 800; }
  12%{ opacity:1; stroke-dasharray: 300 800; }
  40%{ opacity:1; stroke-dasharray: 700 800; }
  75%{ opacity:1; stroke-dasharray: 900 800; }
  100%{ opacity:0; stroke-dasharray: 900 800; }
}
#toggle-cycle:checked ~ .app .square .edges .cycle{
  animation: dash-flow 4s ease-in-out infinite;
}
#toggle-cycle:checked ~ .app .square .edges #e12{ animation-delay: 0s; }
#toggle-cycle:checked ~ .app .square .edges #e23{ animation-delay: .8s; }
#toggle-cycle:checked ~ .app .square .edges #e34{ animation-delay: 1.6s; }
#toggle-cycle:checked ~ .app .square .edges #e45{ animation-delay: 2.4s; }
#toggle-cycle:checked ~ .app .square .edges #e51{ animation-delay: 3.2s; }

/* Powering — longer alternation:
   Phase A: (2→3 & 4→5)
   Phase B: (3→4 & 5→2  [diagonal colored])
*/
@keyframes blinkA { 0%, 49%{ opacity:1; } 50%, 100%{ opacity:0; } }
@keyframes blinkB { 0%, 49%{ opacity:0; } 50%, 100%{ opacity:1; } }
#toggle-power:checked ~ .app .square .edges .powerA{
  animation: blinkA 3.6s steps(1,end) infinite;
}
#toggle-power:checked ~ .app .square .edges .powerB{
  animation: blinkB 3.6s steps(1,end) infinite;
}

/* Master switch: when checked, STOP all animations and show faint wiring */
#toggle-effects:checked ~ .app .square .edges .edge{
  animation: none !important; opacity:.12; filter:none;
}

/* Responsive */
@media (max-width: 1080px){
  .app{ grid-template-columns: 240px 1fr; }
}
@media (max-width: 860px){
  .app{ grid-template-columns: 1fr; }
  .toolbar{ position:static; }
}

