/* Map of Concepts (/courses/concept-map). Drawn by scripts/concept_map.js. */

.cmap-page {
    --cmap-node-line: #b6bcc6;
    --cmap-edge:      #c5cad3;
    --cmap-pre:       #2563eb;
    --cmap-pre-bg:    #e7effc;
    --cmap-post:      #7c3aed;
    --cmap-post-bg:   #f0e9fd;
    --cmap-gap:       #b45309;
    --cmap-gap-bg:    #fdf3e3;
    /* the drawing board: the same tint, dot grid and border as a lesson's
       .fn-stage--model figure (electricity-introduction/lesson.html, top of
       {% block sections %}); keep the two in step */
    --cmap-board-bg:   #f6f6fe;
    --cmap-board-grid: #e1e4fc;
    --cmap-board-bd:   #c7d2fe;
    /* the site caps content at 1200px; this page takes the whole window instead.
       --cmap-sbw is the scrollbar width, set by the script, so 100vw does not overflow */
    margin-left: calc(50% - (100vw - var(--cmap-sbw, 0px)) / 2);
    margin-right: calc(50% - (100vw - var(--cmap-sbw, 0px)) / 2);
    padding: 20px 24px 24px;
    box-sizing: border-box;
}
[data-theme="dark"] .cmap-page {
    --cmap-node-line: #5b6474;
    --cmap-edge:      #4f5866;
    --cmap-pre:       #60a5fa;
    --cmap-pre-bg:    #1e2f4d;
    --cmap-post:      #c4b5fd;
    --cmap-post-bg:   #33294f;
    --cmap-gap:       #fbbf24;
    --cmap-gap-bg:    #3d3017;
    --cmap-board-bg:   #211d38;
    --cmap-board-grid: #332c56;
    --cmap-board-bd:   #4c3f78;
}

.cmap-header {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    justify-content: space-between;
    gap: 10px 24px;
    margin-bottom: 14px;
}
.cmap-title { font-size: 1.8rem; font-weight: 700; margin: 0 0 4px; letter-spacing: -0.01em; }
.cmap-sub   { margin: 0; color: var(--color-text-muted); max-width: 70ch; }
.cmap-search input {
    font: inherit;
    font-size: 0.95rem;
    width: 260px;
    max-width: 100%;
    padding: 8px 12px;
    border-radius: var(--radius-lg);
    border: 1px solid var(--color-border);
    background: var(--color-surface);
    color: var(--color-text-dark);
}

.cmap-stage {
    position: relative;
    height: calc(100vh - 220px);
    height: calc(100dvh - 220px);
    min-height: 460px;
    overflow: hidden;
    border: 1px solid var(--cmap-board-bd);
    border-radius: var(--radius-lg);
    background-color: var(--cmap-board-bg);
    /* size and position follow the view (set by the script), so the dots
       travel with the map instead of the map sliding over them */
    background-image: radial-gradient(var(--cmap-board-grid) 1.1px, transparent 1.1px);
    background-size: 15px 15px;
    touch-action: none;           /* pan and pinch are ours, not the page's */
    cursor: grab;
    outline: none;
    user-select: none;
    -webkit-user-select: none;
}
.cmap-stage:focus-visible { box-shadow: 0 0 0 3px var(--cmap-pre); }
.cmap-stage.cmap-dragging  { cursor: grabbing; }
.cmap-svg { display: block; width: 100%; height: 100%; }

.cmap-zoom {
    position: absolute;
    top: 12px;
    left: 12px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.cmap-zoom-btn {
    width: 36px;
    height: 36px;
    border-radius: var(--radius);
    border: 1px solid var(--color-border);
    background: var(--color-surface);
    color: var(--color-text-dark);
    font-size: 1.25rem;
    line-height: 1;
    cursor: pointer;
    box-shadow: var(--shadow-sm);
}
.cmap-zoom-btn:hover { background: var(--color-hover-gray); }
.cmap-zoom-btn--fit { font-size: 1rem; }

.cmap-legend {
    position: absolute;
    left: 12px;
    bottom: 10px;
    display: flex;
    flex-wrap: wrap;
    gap: 6px 14px;
    padding: 4px 10px;
    border-radius: var(--radius);
    background: var(--color-surface);
    font-size: 0.8rem;
    color: var(--color-text-muted);
    pointer-events: none;
}
.cmap-legend span { display: inline-flex; align-items: center; gap: 6px; }
.cmap-sw { width: 13px; height: 13px; border-radius: 4px; border: 2px solid; display: inline-block; }
.cmap-sw--pre  { border-color: var(--cmap-pre);  background: var(--cmap-pre-bg); }
.cmap-sw--post { border-color: var(--cmap-post); background: var(--cmap-post-bg); }
.cmap-sw--gap  { border-color: var(--cmap-node-line); background: transparent; border-style: dashed; }

/* ── the graph (map units; the view scales them) ────────────────── */

.cmap-node { cursor: pointer; outline: none; }
.cmap-node .cmap-node-shape { fill: var(--color-surface); stroke: var(--cmap-node-line); stroke-width: 1.5; transition: opacity .15s; }
.cmap-node text { fill: var(--color-text-dark); font-size: 13.5px; font-weight: 500; pointer-events: none; }
.cmap-node text.cmap-node-sub { fill: var(--color-text-muted); font-size: 11px; font-weight: 400; }
.cmap-node text.cmap-node-mono { font-size: 15px; font-weight: 800; }
.cmap-node-icon { pointer-events: none; color: var(--color-text-dark); }
/* Nothing teaches it yet: the quietest thing on the map, because it is the one
   thing a student cannot learn. Marked by dashes and muted ink rather than a
   colour, which keeps green/yellow/red free for the student's own state and
   matches what dashes mean inside the lessons ("not built yet"). */
.cmap-node--gap { opacity: 0.8; }
.cmap-node--gap .cmap-node-shape { fill: transparent; stroke: var(--cmap-node-line); stroke-dasharray: 5 4; }
.cmap-node--gap text, .cmap-node--gap .cmap-node-icon { fill: var(--color-text-muted); color: var(--color-text-muted); }
.cmap-node:hover .cmap-node-shape, .cmap-node:focus-visible .cmap-node-shape { stroke: var(--color-text-dark); stroke-width: 2.5; }
.cmap-node--match .cmap-node-shape { stroke: var(--cmap-pre); stroke-width: 3.5; }

.cmap-edge { fill: none; stroke: var(--cmap-edge); stroke-width: 1.4; transition: opacity .15s; }
.cmap-arrow { fill: var(--cmap-edge); }
.cmap-arrow--pre  { fill: var(--cmap-pre); }
.cmap-arrow--post { fill: var(--cmap-post); }

.cmap-focus .cmap-node, .cmap-focus .cmap-edge { opacity: 0.16; }
.cmap-focus .cmap-node--on, .cmap-focus .cmap-edge--on { opacity: 1; }
.cmap-node--sel .cmap-node-shape  { stroke: var(--color-text-dark); stroke-width: 3; stroke-dasharray: none; }
.cmap-node--pre .cmap-node-shape  { fill: var(--cmap-pre-bg);  stroke: var(--cmap-pre);  stroke-width: 2; }
.cmap-node--post .cmap-node-shape { fill: var(--cmap-post-bg); stroke: var(--cmap-post); stroke-width: 2; }
.cmap-edge--pre  { stroke: var(--cmap-pre);  stroke-width: 2; }
.cmap-edge--post { stroke: var(--cmap-post); stroke-width: 2; }

/* Level of detail. Close up: a box with the name and its topic. Further out,
   where the name would be unreadable, the box becomes a circle with the
   concept's icon (or its initials until one is drawn). */
.cmap-lod-near .cmap-node-circle,
.cmap-lod-near .cmap-node-icon,
.cmap-lod-near .cmap-node-mono { display: none; }
.cmap-lod-far .cmap-node rect,
.cmap-lod-far .cmap-node text.cmap-node-sub,
.cmap-lod-far .cmap-node text:not(.cmap-node-mono),
.cmap-lod-mid .cmap-node rect,
.cmap-lod-mid .cmap-node text.cmap-node-sub,
.cmap-lod-mid .cmap-node text:not(.cmap-node-mono) { display: none; }
/* the initials are only legible from about half zoom */
.cmap-lod-far .cmap-node-mono { display: none; }

/* ── the panel: a drawer over the map, a sheet on a phone ─────────── */

.cmap-panel {
    position: absolute;
    top: 12px;
    right: 12px;
    bottom: 12px;
    width: 340px;
    max-width: calc(100% - 24px);
    overflow-y: auto;
    padding: 16px 18px;
    box-sizing: border-box;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    background: var(--color-surface);
    box-shadow: var(--shadow-md);
    font-size: 0.93rem;
    cursor: auto;
    user-select: text;
    -webkit-user-select: text;
    touch-action: pan-y;
    animation: cmapPanelIn 0.2s ease;
}
.cmap-panel[hidden] { display: none; }
@keyframes cmapPanelIn {
    from { opacity: 0; transform: translateX(16px); }
    to   { opacity: 1; transform: translateX(0); }
}
.cmap-panel-close {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 32px;
    height: 32px;
    border: none;
    border-radius: var(--radius);
    background: transparent;
    color: var(--color-text-muted);
    font-size: 1.4rem;
    line-height: 1;
    cursor: pointer;
}
.cmap-panel-close:hover { background: var(--color-hover-gray); color: var(--color-text-dark); }
.cmap-panel h2 { font-size: 1.2rem; margin: 0 36px 2px 0; }
.cmap-panel h3 {
    font-size: 0.74rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--color-text-muted);
    margin: 16px 0 6px;
}
.cmap-panel p  { margin: 0 0 6px; }
.cmap-panel ul { margin: 0; padding-left: 18px; }
.cmap-panel li { margin-bottom: 4px; }
.cmap-panel-topic { color: var(--color-text-muted); margin: 0; }
.cmap-panel-topic a { color: var(--cmap-pre); }
.cmap-panel-note {
    padding: 8px 10px;
    border-radius: var(--radius);
    border: 1px dashed var(--cmap-gap);
    background: var(--cmap-gap-bg);
}
.cmap-muted { color: var(--color-text-muted); }
.cmap-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.cmap-chip {
    font: inherit;
    font-size: 0.84rem;
    padding: 2px 10px;
    border-radius: var(--radius-full);
    border: 1px solid;
    color: var(--color-text-dark);
    cursor: pointer;
}
.cmap-chip--pre  { border-color: var(--cmap-pre);  background: var(--cmap-pre-bg); }
.cmap-chip--post { border-color: var(--cmap-post); background: var(--cmap-post-bg); }

@media (max-width: 640px) {
    .cmap-page { padding: 16px 16px 20px; }
    .cmap-title { font-size: 1.5rem; }
    .cmap-search, .cmap-search input { width: 100%; }
    .cmap-stage { height: calc(100dvh - 250px); min-height: 420px; }
    .cmap-legend { font-size: 0.72rem; right: 12px; }
    .cmap-panel {
        top: auto;
        left: 8px;
        right: 8px;
        bottom: 8px;
        width: auto;
        max-width: none;
        max-height: 58%;
        animation-name: cmapSheetIn;
    }
    @keyframes cmapSheetIn {
        from { opacity: 0; transform: translateY(16px); }
        to   { opacity: 1; transform: translateY(0); }
    }
}
