:root {
      --bg: #f6f8fb;
      --card: #ffffff;
      --ink: #1f2937;
      --muted: #6b7280;
      --accent: #2563eb;
      --accent-soft: #dbeafe;
      --ok: #047857;
      --warn: #b45309;
      --border: #d1d5db;
      --code: #111827;
    }
    * { box-sizing: border-box; }
    body {
      margin: 0;
      font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
      background: var(--bg);
      color: var(--ink);
      line-height: 1.55;
      overflow-x: hidden;
    }
    header {
      background: linear-gradient(135deg, #1d4ed8, #0f172a);
      color: white;
      padding: 48px 24px;
    }
    header .wrap, main, .section-nav {
      width: min(100%, 1600px);
      margin: 0 auto;
    }
    h1 { margin: 0 0 12px; font-size: clamp(2rem, 4vw, 3rem); }
    h2 { margin-top: 0; border-bottom: 2px solid var(--accent-soft); padding-bottom: 8px; }
    h3 { margin-bottom: 8px; }
    .subtitle { font-size: 1.2rem; opacity: .92; max-width: 1100px; }
    main { padding: 28px clamp(12px, 2vw, 28px) 64px; }
    section, .card {
      background: var(--card);
      border: 1px solid var(--border);
      border-radius: 16px;
      padding: 24px;
      margin: 18px 0;
      box-shadow: 0 6px 18px rgba(15, 23, 42, .05);
    }
    .grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; }
    .mission {
      background: var(--accent-soft);
      border-left: 6px solid var(--accent);
    }
    .mentor {
      background: #fff7ed;
      border-left: 6px solid var(--warn);
    }
    .success {
      background: #ecfdf5;
      border-left: 6px solid var(--ok);
    }
    code, pre {
      font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
    }
    pre {
      background: var(--code);
      color: #e5e7eb;
      padding: 14px 16px;
      border-radius: 12px;
      overflow-x: auto;
      font-size: .95rem;
    }
    .cmd::before { content: "$ "; color: #93c5fd; }
    table {
      width: 100%;
      border-collapse: collapse;
      margin: 12px 0 20px;
      background: white;
    }
    th, td {
      border: 1px solid var(--border);
      padding: 10px;
      text-align: left;
      vertical-align: top;
    }
    th { background: #f3f4f6; }
    .answer {
      min-height: 42px;
      border-bottom: 1px dashed #9ca3af;
      margin: 8px 0 14px;
    }
    .big-answer { min-height: 100px; }
    .answer-field,
    .answer-select {
      width: 100%;
      border: 1px solid var(--border);
      border-radius: 8px;
      padding: 9px 10px;
      font: inherit;
      color: var(--ink);
      background: #f9fafb;
    }
    .answer-field:focus,
    .answer-select:focus {
      outline: 3px solid var(--accent-soft);
      border-color: var(--accent);
      background: white;
    }
    textarea.answer-field {
      min-height: 72px;
      resize: vertical;
    }
    .big-answer textarea.answer-field { min-height: 120px; }
    td .answer-field { min-width: 160px; }
    .tag {
      display: inline-block;
      background: #eef2ff;
      color: #3730a3;
      border-radius: 999px;
      padding: 4px 10px;
      font-size: .85rem;
      margin: 2px 4px 2px 0;
    }
    .steps li { margin-bottom: 10px; }
    .checklist label { display: block; margin: 7px 0; }
    .small { color: var(--muted); font-size: .94rem; }
    .diagram {
      font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
      background: #f9fafb;
      padding: 16px;
      border: 1px dashed #9ca3af;
      border-radius: 12px;
      white-space: pre-wrap;
    }
    .mermaid-editor {
      border: 1px solid var(--border);
      border-radius: 12px;
      background: #ffffff;
      padding: 16px;
      margin: 14px 0 24px;
    }
    .mermaid-editor-toolbar,
    .graph-link-tools,
    .graph-delete-tools {
      display: grid;
      grid-template-columns: minmax(180px, 1fr) minmax(180px, 1fr) auto auto;
      gap: 10px;
      align-items: end;
      margin-bottom: 12px;
    }
    .mermaid-editor label,
    .mermaid-output-label {
      display: grid;
      gap: 5px;
      color: #374151;
      font-size: .92rem;
      font-weight: 700;
    }
    .mermaid-editor select,
    .mermaid-editor input {
      min-height: 40px;
      border: 1px solid var(--border);
      border-radius: 8px;
      padding: 8px 10px;
      font: inherit;
      background: #f9fafb;
      color: var(--ink);
    }
    .mermaid-editor button {
      min-height: 40px;
      border: 1px solid #1d4ed8;
      border-radius: 8px;
      padding: 8px 12px;
      font: inherit;
      font-weight: 700;
      background: #2563eb;
      color: white;
      cursor: pointer;
    }
    .mermaid-editor button:hover,
    .mermaid-editor button:focus {
      outline: 3px solid var(--accent-soft);
      background: #1d4ed8;
    }
    .mermaid-editor button:disabled {
      border-color: #cbd5e1;
      background: #e5e7eb;
      color: #64748b;
      cursor: not-allowed;
    }
    .graph-stage {
      position: relative;
      min-height: 320px;
      border: 1px solid #cbd5e1;
      border-radius: 12px;
      overflow: hidden;
      background:
        linear-gradient(rgba(148, 163, 184, .18) 1px, transparent 1px),
        linear-gradient(90deg, rgba(148, 163, 184, .18) 1px, transparent 1px),
        #f8fafc;
      background-size: 28px 28px;
      margin: 12px 0 16px;
    }
    .graph-stage svg {
      display: block;
      width: 100%;
      min-height: 320px;
      touch-action: none;
    }
    .graph-empty {
      position: absolute;
      inset: 0;
      display: grid;
      place-items: center;
      margin: 0;
      color: var(--muted);
      font-weight: 700;
      pointer-events: none;
    }
    .graph-edge {
      stroke: #475569;
      stroke-width: 3;
      stroke-linecap: round;
    }
    .graph-node {
      cursor: grab;
      outline: none;
    }
    .graph-node.is-dragging {
      cursor: grabbing;
    }
    .graph-node rect {
      fill: #ffffff;
      stroke: #2563eb;
      stroke-width: 2;
      filter: drop-shadow(0 5px 10px rgba(15, 23, 42, .12));
    }
    .graph-node text {
      fill: var(--ink);
      font: 700 15px system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
      text-anchor: middle;
      pointer-events: none;
    }
    .graph-node:focus rect,
    .graph-node:hover rect {
      fill: #eff6ff;
      stroke: #1d4ed8;
    }
    .mermaid-output {
      margin-top: 8px;
      font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
      min-height: 150px;
    }
    .mermaid-output[readonly] {
      color: #0f172a;
      background: #f8fafc;
    }
    .mermaid-code-actions {
      display: flex;
      align-items: center;
      flex-wrap: wrap;
      gap: 10px 14px;
      margin-top: 10px;
    }
    .mermaid-code-actions a {
      color: var(--accent);
      font-weight: 700;
      text-decoration: none;
    }
    .mermaid-code-actions a:hover,
    .mermaid-code-actions a:focus {
      text-decoration: underline;
      outline: none;
    }
    #mermaidParseStatus {
      color: var(--muted);
      font-size: .92rem;
      font-weight: 700;
    }
    #mermaidParseStatus.is-error {
      color: #b91c1c;
    }
    .graph-state-field {
      display: none;
    }
    .toc-toggle {
      position: fixed;
      top: 14px;
      left: 14px;
      z-index: 30;
      border: 1px solid rgba(255, 255, 255, .45);
      background: linear-gradient(135deg, rgba(15, 23, 42, .96), rgba(37, 99, 235, .92));
      color: white;
      border-radius: 10px;
      padding: 10px 14px;
      font: inherit;
      font-weight: 700;
      cursor: pointer;
      box-shadow: 0 10px 26px rgba(15, 23, 42, .28);
    }
    .toc-toggle::before {
      content: "☰";
      display: inline-block;
      margin-right: 8px;
      font-weight: 800;
    }
    .toc-toggle:hover,
    .toc-toggle:focus {
      outline: 3px solid rgba(219, 234, 254, .9);
      transform: translateY(-1px);
    }
    .toc-drawer {
      position: fixed;
      inset: 0 auto 0 0;
      width: min(410px, 90vw);
      z-index: 40;
      background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
      border-right: 1px solid var(--border);
      box-shadow: 22px 0 46px rgba(15, 23, 42, .24);
      transform: translateX(-105%);
      transition: transform .24s ease;
      display: flex;
      flex-direction: column;
    }
    body.toc-open .toc-drawer { transform: translateX(0); }
    .toc-header {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 12px;
      padding: 20px 22px;
      border-bottom: 1px solid var(--border);
      background: #0f172a;
      color: white;
    }
    .toc-header h2 {
      border: 0;
      padding: 0;
      margin: 0;
      font-size: 1.18rem;
    }
    .toc-close {
      border: 1px solid rgba(255, 255, 255, .28);
      background: rgba(255, 255, 255, .08);
      color: white;
      border-radius: 8px;
      padding: 7px 10px;
      font: inherit;
      cursor: pointer;
    }
    .toc-close:hover,
    .toc-close:focus {
      background: rgba(255, 255, 255, .16);
      outline: 3px solid rgba(219, 234, 254, .28);
    }
    .toc-nav {
      overflow: auto;
      padding: 18px 18px 28px;
    }
    .toc-nav h3 {
      color: #475569;
      font-size: .78rem;
      text-transform: uppercase;
      letter-spacing: .08em;
      margin: 4px 0 12px;
      padding: 0 8px;
    }
    .toc-nav a {
      position: relative;
      display: flex;
      align-items: center;
      gap: 10px;
      color: var(--ink);
      text-decoration: none;
      padding: 10px 12px;
      border: 1px solid transparent;
      border-radius: 10px;
      margin: 4px 0;
      background: transparent;
      transition: background .16s ease, border-color .16s ease, color .16s ease, transform .16s ease;
    }
    .toc-nav a::before {
      content: "";
      width: 8px;
      height: 8px;
      border-radius: 999px;
      background: #cbd5e1;
      flex: 0 0 auto;
    }
    .toc-nav a:hover,
    .toc-nav a:focus {
      background: #eef6ff;
      border-color: #bfdbfe;
      color: var(--accent);
      outline: none;
      transform: translateX(2px);
    }
    .toc-nav a[aria-current="page"] {
      background: var(--accent-soft);
      border-color: #93c5fd;
      color: #1d4ed8;
      font-weight: 700;
      box-shadow: inset 4px 0 0 var(--accent);
    }
    .toc-nav a[aria-current="page"]::before {
      background: var(--accent);
    }
    .toc-backdrop {
      position: fixed;
      inset: 0;
      z-index: 35;
      background: rgba(15, 23, 42, .36);
      opacity: 0;
      pointer-events: none;
      transition: opacity .2s ease;
    }
    body.toc-open .toc-backdrop {
      opacity: 1;
      pointer-events: auto;
    }
    .section-nav {
      padding: 0 clamp(12px, 2vw, 28px) 64px;
      display: flex;
      justify-content: space-between;
      gap: 12px;
      flex-wrap: wrap;
    }
    .nav-button {
      display: inline-flex;
      align-items: center;
      justify-content: center;
      min-height: 42px;
      border: 1px solid var(--border);
      background: white;
      color: var(--ink);
      border-radius: 8px;
      padding: 9px 14px;
      text-decoration: none;
      box-shadow: 0 4px 12px rgba(15, 23, 42, .05);
    }
    .nav-button:hover,
    .nav-button:focus {
      border-color: var(--accent);
      color: var(--accent);
      outline: 3px solid var(--accent-soft);
    }
    .nav-spacer { min-width: 1px; }
    .print-note { display: none; }
    @media print {
      body { background: white; }
      header { padding: 26px 18px; }
      .toc-toggle, .toc-drawer, .toc-backdrop, .section-nav { display: none; }
      section, .card { box-shadow: none; break-inside: avoid; }
      pre { white-space: pre-wrap; }
      .answer-field,
      .answer-select {
        border: 0;
        border-bottom: 1px dashed #9ca3af;
        border-radius: 0;
        background: white;
        padding-left: 0;
      }
      .print-note { display: block; }
    }
    @media (max-width: 760px) {
      table {
        display: block;
        overflow-x: auto;
      }
      .mermaid-editor-toolbar,
      .graph-link-tools,
      .graph-delete-tools {
        grid-template-columns: 1fr;
      }
      .graph-stage,
      .graph-stage svg {
        min-height: 280px;
      }
    }
