/* ==========================================================================
   Interactive Horizontal Knowledge Graph
   Replaces the old vertical accordion tree with a pannable/zoomable node
   map: root in the center, children fan out to the right, connected by
   soft curved SVG paths. See js/graphRenderer.js for the layout engine.
   ========================================================================== */

.graph-viewport {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  cursor: grab;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  background: transparent;
}
.graph-viewport.is-panning { cursor: grabbing; }

.graph-world {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
  will-change: transform;
}
.graph-world.is-animating { transition: transform 320ms var(--ease-out); }

.graph-svg {
  position: absolute;
  top: 0;
  left: 0;
  overflow: visible;
  pointer-events: none;
}

.graph-link {
  fill: none;
  stroke: var(--ink-600);
  stroke-width: 1.5px;
  transition: stroke var(--dur-fast) var(--ease-out);
}
.graph-link.is-dim { stroke: var(--ink-700); opacity: 0.5; }
.graph-link.is-active-path { stroke: var(--brass-soft-strong); stroke-width: 2px; }

/* ---------- Node ---------- */
.graph-node {
  position: absolute;
  top: 0;
  left: 0;
  will-change: transform, opacity;
  transform-origin: 0 50%;
}

.graph-node__body {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 52px;
  padding: 0 14px;
  border-radius: 14px;
  background: var(--glass-bg);
  backdrop-filter: blur(14px) saturate(160%);
  -webkit-backdrop-filter: blur(14px) saturate(160%);
  border: 1px solid var(--glass-border);
  box-shadow: var(--glass-shadow);
  cursor: pointer;
  transition: border-color var(--dur-fast) var(--ease-out), box-shadow var(--dur-fast) var(--ease-out),
    transform var(--dur-fast) var(--ease-out), background var(--dur-fast) var(--ease-out);
}
.graph-node__body:hover {
  border-color: var(--brass-soft-strong);
  transform: translateY(-2px);
  box-shadow: var(--glass-shadow-lg), 0 0 0 1px var(--brass-soft);
}
.graph-node__body:active { transform: translateY(0); }

.graph-node.type-branch .graph-node__body { background: var(--glass-bg); }
.graph-node.type-lesson .graph-node__body,
.graph-node.type-sop .graph-node__body { background: linear-gradient(180deg, var(--brass-soft), var(--glass-bg)); }
.graph-node.type-quiz .graph-node__body { background: linear-gradient(180deg, var(--coral-soft), var(--glass-bg)); }
.graph-node.type-summary .graph-node__body { background: linear-gradient(180deg, var(--green-soft), var(--glass-bg)); }

.graph-node__body.is-active {
  border-color: var(--brass);
  box-shadow: 0 0 0 3px var(--brass-soft), var(--glass-shadow-lg);
  background: linear-gradient(180deg, var(--brass-soft-strong), var(--glass-bg));
}

.graph-node--root .graph-node__body {
  height: 58px;
  padding: 0 18px;
  border-color: var(--brass-soft-strong);
  background: linear-gradient(155deg, var(--brass-soft-strong), var(--glass-bg-strong));
  box-shadow: var(--glass-shadow-lg), 0 0 0 1px var(--brass-soft);
}
.graph-node--root .graph-node__title { font-family: var(--font-display); font-weight: 700; font-size: var(--fs-md); }

.graph-node__icon {
  width: 18px; height: 18px;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  color: var(--slate-500);
}
.graph-node.type-lesson .graph-node__icon,
.graph-node.type-sop .graph-node__icon { color: var(--teal-bright); }
.graph-node.type-quiz .graph-node__icon { color: var(--coral); }
.graph-node.type-summary .graph-node__icon { color: var(--green); }
.graph-node--root .graph-node__icon { color: var(--brass-bright); }
.graph-node__body.is-active .graph-node__icon { color: var(--brass-bright); }

.graph-node__title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--parchment-dim);
  font-size: var(--fs-sm);
}
.graph-node__body.is-active .graph-node__title,
.graph-node__body:hover .graph-node__title { color: var(--parchment); }

.graph-node__meta {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.graph-node__count {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--slate-600);
  background: var(--ink-900);
  border-radius: 10px;
  padding: 1px 6px;
}
.graph-node__meta .progress-badge__track { width: 20px; }
.graph-node__meta .progress-badge__pct { font-size: 9px; }

.graph-node__body.is-on-path {
  border-color: var(--brass-soft-strong);
  box-shadow: 0 0 0 1px var(--brass-soft), 0 6px 16px rgba(4, 7, 10, 0.35);
}

.graph-node__status { width: 14px; height: 14px; display: grid; place-items: center; color: var(--slate-600); }
.graph-node__status.is-done { color: var(--green); }
.graph-node__status svg { width: 14px; height: 14px; }
.graph-node__bookmark { width: 12px; height: 12px; display: grid; place-items: center; color: var(--brass); }
.graph-node__bookmark svg { width: 11px; height: 11px; }
.graph-node__flag { width: 12px; height: 12px; display: grid; place-items: center; color: var(--coral); }
.graph-node__flag svg { width: 11px; height: 11px; }
.graph-node__offline { width: 12px; height: 12px; display: grid; place-items: center; color: var(--teal-bright); }
.graph-node__offline svg { width: 11px; height: 11px; }

/* Expand / collapse pill, sitting on the node's right edge like the
   reference design's "<"/">" toggle. */
.graph-node__arrow {
  position: absolute;
  top: 50%;
  right: -13px;
  width: 26px;
  height: 26px;
  transform: translateY(-50%);
  border-radius: 50%;
  background: var(--glass-bg-strong);
  backdrop-filter: blur(10px) saturate(160%);
  -webkit-backdrop-filter: blur(10px) saturate(160%);
  border: 1px solid var(--glass-border-strong);
  color: var(--parchment-dim);
  display: grid;
  place-items: center;
  box-shadow: var(--glass-shadow);
  transition: background var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out),
    border-color var(--dur-fast) var(--ease-out);
}
.graph-node__arrow:hover { background: var(--brass-soft-strong); color: var(--parchment); border-color: var(--brass); }
.graph-node__arrow svg { width: 11px; height: 11px; transition: transform 360ms cubic-bezier(0.34, 1.56, 0.64, 1); }
.graph-node__arrow.is-expanded svg { transform: rotate(180deg); }

/* Search highlight (shared with the old tree, kept here so removing
   tree.css doesn't lose it). */
mark.hl {
  background: var(--brass-soft-strong);
  color: var(--parchment);
  border-radius: 2px;
  padding: 0 1px;
}

/* ---------- Floating controls ---------- */
.graph-controls {
  position: absolute;
  right: var(--sp-3);
  bottom: var(--sp-3);
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 5;
}
.graph-controls button {
  width: 32px; height: 32px;
  border-radius: 10px;
  background: var(--glass-bg-strong);
  backdrop-filter: blur(14px) saturate(160%);
  -webkit-backdrop-filter: blur(14px) saturate(160%);
  border: 1px solid var(--glass-border-strong);
  color: var(--slate-400);
  font-size: var(--fs-md);
  line-height: 1;
  display: grid;
  place-items: center;
  box-shadow: var(--glass-shadow);
  transition: color var(--dur-fast), border-color var(--dur-fast);
}
.graph-controls button:hover { color: var(--brass-bright); border-color: var(--brass-soft-strong); }

.graph-hint {
  position: absolute;
  left: var(--sp-3);
  bottom: var(--sp-3);
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--slate-600);
  pointer-events: none;
  z-index: 5;
}

/* ---------- Mini-map ---------- */
.graph-minimap {
  position: absolute;
  top: var(--sp-3);
  right: var(--sp-3);
  width: 168px;
  height: 118px;
  border-radius: var(--radius-md);
  background: var(--glass-bg-strong);
  backdrop-filter: blur(18px) saturate(160%);
  -webkit-backdrop-filter: blur(18px) saturate(160%);
  border: 1px solid var(--glass-border-strong);
  box-shadow: var(--glass-shadow);
  overflow: hidden;
  cursor: pointer;
  z-index: 6;
  touch-action: none;
}
.graph-minimap__svg { display: block; }
.graph-minimap__dot { fill: var(--slate-600); }
.graph-minimap__dot.is-done { fill: var(--green); }
.graph-minimap__dot.is-active { fill: var(--brass-bright); }
.graph-minimap__viewport {
  fill: var(--brass-soft);
  stroke: var(--brass-bright);
  stroke-width: 1;
  pointer-events: none;
}
@media (max-width: 900px) {
  .graph-minimap { width: 118px; height: 84px; }
}

.graph-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: var(--sp-5);
  text-align: center;
  color: var(--slate-600);
  font-size: var(--fs-xs);
}

/* ---------- "Wide" mode: give the graph more room to breathe ---------- */
#app.graph-wide { grid-template-columns: minmax(340px, 74%) 1fr; }
@media (max-width: 900px) {
  #app.graph-wide { grid-template-columns: 1fr; }
}

/* ---------- "Article-wide" mode: shrink the tree panel so lesson content
   (the article side) gets almost all the room. Mirrors .graph-wide above,
   toggled via the Alt+A keyboard shortcut. ---------- */
#app.article-wide { grid-template-columns: minmax(260px, 26%) 1fr; }
@media (max-width: 900px) {
  #app.article-wide { grid-template-columns: 1fr; }
}

@media (max-width: 900px) {
  .graph-node__body { height: 48px; }
  .graph-controls { bottom: calc(var(--sp-3) + env(safe-area-inset-bottom, 0px)); }
}

/* ---------- Floating Graph ⇄ Lesson mode toggle (mobile only) ---------- */
.mode-toggle {
  display: none;
  position: fixed;
  left: 50%;
  bottom: calc(var(--sp-5) + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  z-index: 60;
  align-items: center;
  gap: 8px;
  padding: 12px 22px;
  border-radius: 999px;
  background: linear-gradient(180deg, var(--brass-bright), var(--brass));
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  color: var(--on-accent);
  font-family: var(--font-mono);
  font-size: var(--fs-sm);
  font-weight: 700;
  letter-spacing: 0.02em;
  border: 1px solid rgba(255,255,255,0.25);
  box-shadow: var(--glass-shadow-lg), 0 0 24px var(--brass-soft-strong);
  transition: transform var(--dur-fast) var(--ease-out), background var(--dur-fast) var(--ease-out);
}
.mode-toggle svg { width: 16px; height: 16px; }
.mode-toggle:active { transform: translateX(-50%) scale(0.96); }
.mode-toggle.is-lesson-mode {
  background: var(--glass-bg-strong);
  color: var(--parchment);
  border: 1px solid var(--glass-border-strong);
}

@media (max-width: 900px) {
  .mode-toggle.is-visible { display: flex; }
}

/* ---------- Draggable divider between the graph and lesson panels ---------- */
.resize-handle {
  display: none;
  position: fixed;
  top: var(--topbar-h);
  bottom: 0;
  width: 13px;
  transform: translateX(-6.5px);
  cursor: col-resize;
  z-index: 45;
  touch-action: none;
}
.resize-handle::after {
  content: "";
  position: absolute;
  left: 6px;
  top: 0;
  bottom: 0;
  width: 1px;
  background: var(--glass-border);
  transition: background var(--dur-fast) var(--ease-out), width var(--dur-fast) var(--ease-out);
}
.resize-handle:hover::after,
.resize-handle.is-dragging::after {
  background: var(--brass-soft-strong);
  width: 2px;
}

/* Glass-pill grabber, VisionOS/iPadOS-style: sits centered on the divider
   line and grows taller + brighter on hover/drag. */
.resize-handle::before {
  content: "";
  position: absolute;
  left: 6px;
  top: 50%;
  width: 5px;
  height: 44px;
  transform: translate(-50%, -50%);
  border-radius: 999px;
  /* Explicit, theme-aware colors (not tied to --glass-bg-strong) so the
     grabber stays clearly visible against the mesh background in both
     modes: dark handle on light mode, bright white handle on dark mode. */
  background: rgba(255, 255, 255, 0.55);
  backdrop-filter: blur(10px) saturate(160%);
  -webkit-backdrop-filter: blur(10px) saturate(160%);
  border: 1px solid rgba(255, 255, 255, 0.75);
  box-shadow: var(--glass-shadow), 0 0 10px rgba(255, 255, 255, 0.15);
  transition: height var(--dur-med) var(--ease-out), background var(--dur-fast) var(--ease-out),
    border-color var(--dur-fast) var(--ease-out), box-shadow var(--dur-fast) var(--ease-out);
}
[data-theme="light"] .resize-handle::before {
  background: rgba(16, 24, 40, 0.32);
  border: 1px solid rgba(16, 24, 40, 0.55);
  box-shadow: var(--glass-shadow);
}
.resize-handle:hover::before,
.resize-handle.is-dragging::before {
  height: 68px;
  background: var(--brass-soft-strong);
  border-color: var(--brass);
  box-shadow: var(--glass-shadow-lg), 0 0 18px var(--brass-soft-strong);
}
.resize-handle.is-dragging::before { height: 84px; }
.resize-handle.is-dragging { cursor: col-resize; }
body.is-resizing { cursor: col-resize !important; user-select: none; }
body.is-resizing .graph-viewport { pointer-events: none; }

@media (min-width: 901px) {
  .resize-handle { display: block; }
}

@media (prefers-reduced-motion: reduce) {
  .graph-world.is-animating { transition: none; }
}

/* ---------- Mouse-tracked specular shine on graph nodes ---------- */
.graph-node__body {
  position: relative;
  overflow: hidden;
}
.graph-node__body::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: radial-gradient(circle at var(--mx, 50%) var(--my, 50%), var(--glass-shine), transparent 45%);
  opacity: 0;
  transition: opacity var(--dur-fast) var(--ease-out);
  pointer-events: none;
  mix-blend-mode: soft-light;
}
.graph-node__body:hover::after { opacity: 1; }
