:root {
  --bg: #0f172a;
  --panel: #111827;
  --panel-2: #1f2937;
  --line: #334155;
  --text: #e5e7eb;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --warn: #facc15;
  --bad: #fb7185;
}

* { box-sizing: border-box; }
body { margin: 0; font-family: Inter, system-ui, sans-serif; background: var(--bg); color: var(--text); }

.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 280px;
  background: #020617;
  border-right: 1px solid var(--line);
  padding: 1rem;
  transition: width 0.2s ease;
  overflow: hidden;
}
.sidebar.collapsed { width: 70px; }
.sidebar h2 { margin-top: 0.5rem; font-size: 1rem; color: var(--muted); }
.sidebar-toggle {
  width: 100%; border: 1px solid var(--line); border-radius: 8px; background: #0b1220; color: var(--text); padding: 0.45rem;
}
.quiz-link {
  width: 100%; margin-top: 0.6rem; text-align: left; border: 1px solid var(--line); background: #0b1220; color: var(--text);
  border-radius: 8px; padding: 0.6rem;
}
.quiz-link.active { border-color: var(--accent); }
.sidebar.collapsed h2,
.sidebar.collapsed .quiz-link { display: none; }

.content { flex: 1; padding: 1.2rem; }
.quiz-panel { display: none; }
.quiz-panel.active { display: block; }
.subtitle { color: var(--muted); }
.controls { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; margin: 0.8rem 0; }
.controls.compact { margin: 0.3rem 0; }
input, select, button {
  background: #0b1220; color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 0.45rem 0.65rem;
}


.graph-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(340px, 0.95fr);
  gap: 0.9rem;
  align-items: start;
}
.graph-side { display: grid; gap: 0.45rem; }
.current-loop {
  color: #cbd5e1;
  font-weight: 700;
  background: #0b1220;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.35rem 0.6rem;
}
@media (max-width: 1100px) {
  .graph-layout { grid-template-columns: 1fr; }
}

.tree-wrap, .graph-wrap {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 0.7rem;
}
#treeSvg, #graphSvg { width: 100%; height: auto; display: block; }

.edge { stroke: #64748b; stroke-width: 2; }
.node circle, .g-node circle { stroke: #f8fafc; stroke-width: 2; }
.node text { fill: #fff; font-size: 13px; font-weight: 700; text-anchor: middle; dominant-baseline: central; }
.g-node text { font-size: 13px; font-weight: 700; text-anchor: middle; dominant-baseline: central; pointer-events: none; }
.node-unlabeled circle { fill: #334155; stroke-dasharray: 4; }
.node-red circle { fill: #dc2626; }
.node-black circle { fill: #020617; }
.node-wrong circle { stroke: var(--warn); stroke-width: 4; filter: drop-shadow(0 0 4px rgba(250,204,21,.9)); }

.g-edge { stroke: #64748b; stroke-width: 2; cursor: pointer; }
.g-edge.active-edge { stroke: #f59e0b; stroke-width: 2; }
.g-edge.parent-edge { stroke: #22c55e; stroke-width: 2; }
.g-edge.wrong-edge { stroke: #ef4444; stroke-width: 3; filter: drop-shadow(0 0 3px rgba(239,68,68,.85)); }
.g-weight { fill: #f8fafc; font-size: 12px; pointer-events: none; }
.g-edge-type { fill: #ffffff; font-size: 11px; font-weight: 700; pointer-events: none; }
.g-node { cursor: pointer; }
.g-node-source circle { stroke: #22c55e; stroke-width: 4; }
.g-node.selected-helper-node circle { stroke: #38bdf8; stroke-width: 4; }
.g-node.g-node-unset circle { fill: transparent; stroke-dasharray: 4 4; }

.graph-helper {
  position: fixed;
  left: 60px;
  top: 130px;
  z-index: 40;
  width: 420px;
  background: #0b1220;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.65rem;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.35);
}
.graph-helper.hidden { display: none; }
.graph-helper.dragging { opacity: 0.92; }
.graph-helper-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  cursor: grab;
  user-select: none;
}
.graph-helper h3 { margin: 0; font-size: 1rem; flex: 1; }
.helper-close { padding: 0.2rem 0.45rem; cursor: pointer; }
.helper-hint { margin: 0.2rem 0 0; color: #cbd5e1; font-size: 0.95rem; white-space: pre-line; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

.state-container { margin-top: 0; display: grid; gap: 0.7rem; }
.iteration-card {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 0.7rem;
}
.iteration-title { margin-bottom: 0.4rem; font-weight: 700; color: #cbd5e1; }
.state-grid { width: 100%; border-collapse: collapse; }
.state-grid th, .state-grid td { border: 1px solid #475569; padding: 0.3rem; font-size: 0.9rem; }
.state-grid input, .state-grid select { width: 100%; padding: 0.3rem; border-radius: 6px; }
.wrong-field { border-color: var(--bad) !important; box-shadow: 0 0 0 1px var(--bad); }
.result { margin-top: 0.8rem; min-height: 1.3rem; }

.g-node-distance { font-size: 13px; font-weight: 700; }
.g-node-index { font-size: 10px; font-weight: 600; opacity: 0.95; }

.helper-value { font-weight: 700; cursor: pointer; text-decoration: underline dotted; }

.edge-type-grid { margin-top: 0.5rem; }

.g-node-increment { pointer-events: auto !important; cursor: pointer; user-select: none; }
.g-node-discovery { text-anchor: end; }
.g-node-finish { text-anchor: start; }

#newGraphButton, #submitGraphButton { cursor: pointer; }
.current-loop-score { margin-top: 0.2rem; color: #e2e8f0; font-weight: 600; }


.rbops-node circle { stroke: #e2e8f0; stroke-width: 2; }
.rbops-node text { fill: #fff; font-size: 12px; font-weight: 700; text-anchor: middle; dominant-baseline: central; pointer-events: none; user-select: none; -webkit-user-select: none; }
.rbops-node.red circle { fill: #b91c1c; }
.rbops-node.black circle { fill: #0f172a; }
.rbops-node.selected circle { stroke: #38bdf8; stroke-width: 4; }
.rbops-edge { stroke: #64748b; stroke-width: 2; cursor: pointer; }
.rbops-edge.selected { stroke: #f59e0b; }
.action-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 0.3rem; }
.action-list li { background: #1f2937; border: 1px solid #334155; border-radius: 6px; padding: 0.35rem 0.5rem; font-size: 0.9rem; }
.action-list li.wrong-action { border-color: #ef4444; color: #fecaca; }

.rbops-layout { display: grid; grid-template-columns: minmax(0,1.3fr) minmax(280px,0.7fr); gap: 0.8rem; align-items: start; }
@media (max-width: 1100px) { .rbops-layout { grid-template-columns: 1fr; } }

.rbops-child-dot { fill: #94a3b8; stroke: #e2e8f0; stroke-width: 1.2; cursor: pointer; }
.rbops-child-dot.active { fill: #38bdf8; }
#rbOpsInitialNodesValue { min-width: 1.6rem; display: inline-block; text-align: center; color: #cbd5e1; }


.rbops-side { display: grid; grid-template-columns: minmax(240px,1fr) minmax(240px,1fr); gap: 0.7rem; align-items: start; }
@media (max-width: 1400px) { .rbops-side { grid-template-columns: 1fr; } }
.hidden-solution { display: none; }
.solution-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 0.3rem; }
.solution-list li { background: #0f1b33; border: 1px solid #334155; border-radius: 6px; padding: 0.35rem 0.5rem; font-size: 0.9rem; }

.rbops-node.arc-target circle { stroke: #38bdf8; stroke-width: 3; }

.solution-subheading { font-size: 0.78rem; color: #94a3b8; margin: 0.15rem 0 0.1rem; }



.rbops-confetti-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9999;
  overflow: hidden;
}
.rbops-confetti {
  position: fixed;
  width: 8px;
  height: 14px;
  border-radius: 2px;
  opacity: 0.95;
  will-change: transform;
}


.ode-wrap { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 0.75rem; margin-top: 0.6rem; }
.ode-math { font-size: 1.02rem; line-height: 1.5; }
.ode-work { width: 100%; background: #0b1220; color: var(--text); border: 1px solid #334155; border-radius: 8px; padding: 0.5rem; margin-top: 0.45rem; }
.ode-render { margin-top: 0.45rem; min-height: 1.4rem; background: #0f1b33; border: 1px solid #334155; border-radius: 8px; padding: 0.45rem; }
.ode-hint { display: none; margin-bottom: 0.45rem; }
#odeHelpPanel.show-hints .ode-hint { display: block; }

.ode-snippet-table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
.ode-snippet-table th, .ode-snippet-table td { border: 1px solid #334155; padding: 0.35rem 0.5rem; text-align: left; }
.ode-snippet-table th { color: #cbd5e1; }
.ode-snippet-table td code { color: #93c5fd; }

.mv-layout { display: grid; grid-template-columns: 1.2fr 1fr; gap: 0.8rem; margin-top: 0.7rem; }
.mv-vector { display: grid; gap: 0.4rem; margin-bottom: 0.7rem; }
.mv-input-line { display: grid; grid-template-columns: 70px 1fr; gap: 0.45rem; align-items: center; }
.mv-input-line input, .mv-matrix input { width: 100%; }
.mv-matrix { display: grid; gap: 0.35rem; }
.mv-step { margin-bottom: 0.45rem; padding: 0.35rem 0.45rem; border: 1px solid #334155; border-radius: 8px; background: #0f1b33; }
@media (max-width: 980px) { .mv-layout { grid-template-columns: 1fr; } }

.mv-point-card { border: 1px solid #334155; border-radius: 10px; padding: 0.55rem; margin-bottom: 0.6rem; background: #0b1220; }
