:root {
  --bg: #0e1016;
  --bg-2: #141824;
  --panel: rgba(20, 24, 36, 0.86);
  --panel-border: rgba(255, 255, 255, 0.08);
  --text: #e6e9f2;
  --muted: #8b93a7;
  --blue: #3f70fa;
  --blue-2: #59a1fc;
  --green: #00dc69;
  --orange: #f2a541;
  --red: #ff5c72;
  --purple: #b98cff;
  --grey: #6b7280;
  --radius: 12px;
  --font: 'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Inter, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: var(--font); font-size: 14px; overflow: hidden; }
button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
a { color: var(--blue-2); }
canvas#graph { position: fixed; inset: 0; display: block; cursor: grab; }
canvas#graph.dragging { cursor: grabbing; }
canvas#graph.pointer { cursor: pointer; }

/* ---------- generic panel bits */
.panel { position: fixed; background: var(--panel); border: 1px solid var(--panel-border); border-radius: var(--radius); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); box-shadow: 0 10px 40px rgba(0,0,0,.45); }
.btn { border: 1px solid var(--panel-border); background: rgba(255,255,255,.05); color: var(--text); padding: 7px 12px; border-radius: 9px; cursor: pointer; transition: background .15s, transform .1s; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.btn:hover { background: rgba(255,255,255,.1); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--blue); border-color: transparent; color: #fff; }
.btn.primary:hover { background: #5583ff; }
.btn.danger { color: var(--red); }
.btn.small { padding: 4px 8px; font-size: 12px; border-radius: 7px; }
.btn.icon { padding: 7px; width: 34px; height: 34px; justify-content: center; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.field label { font-size: 12px; color: var(--muted); }
.field input, .field select, .field textarea { background: rgba(0,0,0,.3); border: 1px solid var(--panel-border); border-radius: 8px; padding: 7px 9px; outline: none; width: 100%; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--blue); }
.field textarea { min-height: 120px; resize: vertical; line-height: 1.45; }
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.chip { display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; border-radius: 999px; font-size: 11px; background: rgba(255,255,255,.07); color: var(--muted); border: 1px solid transparent; }
.chip .dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.muted { color: var(--muted); }
hr.sep { border: 0; border-top: 1px solid var(--panel-border); margin: 12px 0; }
.hidden { display: none !important; }

/* ---------- top bar */
#topbar { top: 14px; left: 14px; padding: 8px 10px 8px 14px; display: flex; align-items: center; gap: 12px; z-index: 5; }
#topbar .brand { display: flex; align-items: center; gap: 8px; font-weight: 700; letter-spacing: .3px; }
#topbar .brand .logo { width: 22px; height: 22px; border-radius: 6px; background: radial-gradient(circle at 30% 30%, #7fa7ff, var(--blue) 60%, #1c1463); box-shadow: 0 0 14px rgba(63,112,250,.7); }
#topbar .brand small { color: var(--muted); font-weight: 400; }
#search { background: rgba(0,0,0,.3); border: 1px solid var(--panel-border); border-radius: 9px; padding: 7px 10px; width: 260px; outline: none; }
#search:focus { border-color: var(--blue); }
#stats { color: var(--muted); font-size: 12px; white-space: nowrap; }

/* ---------- left panel (Obsidian-like settings) */
#left { top: 70px; left: 14px; width: 250px; max-height: calc(100vh - 160px); overflow: auto; z-index: 4; padding: 6px 0; }
#left details { border-bottom: 1px solid var(--panel-border); }
#left details:last-child { border-bottom: 0; }
#left summary { cursor: pointer; padding: 9px 14px; font-weight: 600; font-size: 13px; list-style: none; display: flex; align-items: center; }
#left summary::after { content: '›'; margin-left: auto; color: var(--muted); transition: transform .15s; }
#left details[open] summary::after { transform: rotate(90deg); }
#left .body { padding: 2px 14px 12px; }
.check { display: flex; align-items: center; gap: 8px; padding: 3px 0; cursor: pointer; font-size: 13px; }
.check input { accent-color: var(--blue); }
.check .dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.check .cnt { margin-left: auto; color: var(--muted); font-size: 11px; }
.slider { display: grid; grid-template-columns: 1fr 44px; gap: 8px; align-items: center; font-size: 12px; color: var(--muted); margin: 6px 0; }
.slider span:first-child { grid-column: 1 / -1; }
.slider input[type=range] { width: 100%; accent-color: var(--blue); }
.toggle { display: flex; align-items: center; justify-content: space-between; font-size: 13px; padding: 4px 0; }

/* ---------- right panel: node detail */
#right { top: 14px; right: 14px; width: 360px; max-height: calc(100vh - 28px); overflow: auto; z-index: 6; padding: 16px 18px 18px; }
#right h2 { margin: 0 0 6px; font-size: 20px; line-height: 1.2; padding-right: 30px; }
#right .close { position: absolute; top: 10px; right: 10px; }
#right .desc { line-height: 1.5; margin: 12px 0; font-size: 13.5px; }
#right .desc p { margin: 0 0 8px; }
#right .desc code { background: rgba(255,255,255,.08); padding: 1px 5px; border-radius: 4px; font-size: 12px; }
#right .desc ul { padding-left: 18px; margin: 0 0 8px; }
.conn { display: flex; align-items: center; gap: 8px; padding: 5px 6px; border-radius: 8px; cursor: pointer; font-size: 13px; }
.conn:hover { background: rgba(255,255,255,.06); }
.conn .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.conn .kind { color: var(--muted); font-size: 11px; }
.conn .del { margin-left: auto; opacity: 0; color: var(--muted); background: none; border: 0; cursor: pointer; font-size: 14px; }
.conn:hover .del { opacity: 1; }
.conn .del:hover { color: var(--red); }
h4.sub { margin: 14px 0 6px; font-size: 12px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); }

/* ---------- bottom bars */
#legend { bottom: 14px; left: 14px; padding: 10px 14px; z-index: 4; display: flex; flex-direction: column; gap: 4px; font-size: 12px; }
#legend .item { display: flex; align-items: center; gap: 8px; }
#legend .dot { width: 10px; height: 10px; border-radius: 50%; }
#legend .line { width: 22px; height: 0; border-top: 2px solid; }
#legend .line.dashed { border-top-style: dashed; }
#actions { bottom: 14px; right: 14px; padding: 8px; display: flex; gap: 6px; z-index: 5; }
#hint { position: fixed; bottom: 68px; right: 14px; color: var(--muted); font-size: 11px; z-index: 4; text-align: right; opacity: .8; }

/* ---------- context menu */
#ctx { position: fixed; z-index: 20; min-width: 190px; padding: 6px; }
#ctx button { display: block; width: 100%; text-align: left; background: none; border: 0; padding: 8px 10px; border-radius: 7px; cursor: pointer; color: var(--text); }
#ctx button:hover { background: rgba(255,255,255,.08); }
#ctx button.danger { color: var(--red); }

/* ---------- presentation */
body.presenting #topbar, body.presenting #left, body.presenting #legend, body.presenting #actions, body.presenting #hint, body.presenting #right { display: none; }
#caption { left: 40px; bottom: 40px; max-width: 560px; padding: 22px 26px; z-index: 8; transition: opacity .35s, transform .35s; opacity: 0; transform: translateY(12px); pointer-events: none; }
#caption.show { opacity: 1; transform: translateY(0); pointer-events: auto; }
#caption h1 { margin: 0 0 8px; font-size: 26px; line-height: 1.15; }
#caption .note { color: #c5cbd9; line-height: 1.55; font-size: 15px; }
#caption .note p { margin: 0 0 6px; }
#caption .progress { display: flex; gap: 5px; margin-top: 14px; }
#caption .progress i { width: 18px; height: 3px; border-radius: 2px; background: rgba(255,255,255,.15); }
#caption .progress i.on { background: var(--blue-2); box-shadow: 0 0 8px var(--blue-2); }
#present-nav { right: 24px; bottom: 24px; padding: 6px; display: none; gap: 4px; z-index: 9; }
body.presenting #present-nav { display: flex; }

/* ---------- modal */
.modal-bg { position: fixed; inset: 0; background: rgba(5,7,12,.6); backdrop-filter: blur(6px); z-index: 30; display: flex; align-items: center; justify-content: center; }
.modal { width: min(760px, 94vw); max-height: 88vh; overflow: auto; padding: 22px 24px; position: relative; }
.modal h2 { margin: 0 0 12px; font-size: 18px; }
.slide-row { border: 1px solid var(--panel-border); border-radius: 10px; padding: 10px 12px; margin-bottom: 8px; background: rgba(0,0,0,.2); }
.slide-row .head { display: flex; align-items: center; gap: 8px; }
.slide-row .head .n { color: var(--muted); font-size: 12px; width: 22px; }
.slide-row .head input { flex: 1; }
.slide-row .grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }
.slide-row textarea { min-height: 60px; }
.slide-row select[multiple] { min-height: 90px; }

/* ---------- login */
#login { position: fixed; inset: 0; z-index: 40; display: flex; align-items: center; justify-content: center; background: radial-gradient(ellipse at 50% 40%, #182038 0%, var(--bg) 65%); }
#login form { width: 340px; padding: 28px; text-align: center; }
#login .logo { width: 56px; height: 56px; border-radius: 16px; margin: 0 auto 14px; background: radial-gradient(circle at 30% 30%, #7fa7ff, var(--blue) 60%, #1c1463); box-shadow: 0 0 40px rgba(63,112,250,.6); animation: pulse 3s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 30px rgba(63,112,250,.5); } 50% { box-shadow: 0 0 60px rgba(63,112,250,.9); } }
#login h1 { font-size: 20px; margin: 0 0 4px; }
#login p { color: var(--muted); margin: 0 0 18px; font-size: 13px; }
#login input { width: 100%; padding: 10px 12px; border-radius: 9px; border: 1px solid var(--panel-border); background: rgba(0,0,0,.35); outline: none; margin-bottom: 10px; text-align: center; letter-spacing: 2px; }
#login .err { color: var(--red); font-size: 12px; min-height: 16px; margin-top: 8px; }

/* ---------- toast */
#toasts { position: fixed; top: 14px; left: 50%; transform: translateX(-50%); z-index: 50; display: flex; flex-direction: column; gap: 6px; pointer-events: none; }
.toast { padding: 8px 14px; border-radius: 9px; background: rgba(20,24,36,.95); border: 1px solid var(--panel-border); font-size: 13px; box-shadow: 0 6px 24px rgba(0,0,0,.4); animation: toastIn .2s ease-out; }
.toast.err { border-color: rgba(255,92,114,.5); color: #ffb3bd; }
@keyframes toastIn { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }

@media (max-width: 900px) {
  #left { display: none; }
  #right { width: min(360px, calc(100vw - 28px)); }
  #search { width: 160px; }
  #stats { display: none; }
}
