/* ==========================================================================
   Engineering chapters: the dark half of the case study.
   ========================================================================== */

.dark { background: var(--ink); color: #fff; padding-bottom: clamp(90px, 11vw, 150px); margin-top: clamp(90px, 11vw, 150px); }
.dark .kicker { color: rgba(255, 255, 255, 0.55); }
.dark .code { background: var(--yellow); color: var(--ink); }
.dark .ch-lede, .dark .prose p { color: rgba(255, 255, 255, 0.74); }
.dark code { background: rgba(255, 255, 255, 0.1); color: #fff; }
.dark .sub-title { color: #fff; }
.dark .btn-ch:hover { box-shadow: 0 6px 0 #fff; }

/* ---------- System design diagram ---------- */
.arch-flows { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 18px; }
.arch-flows button { padding: 9px 16px; font-size: 13.5px; font-weight: 700; color: rgba(255, 255, 255, 0.7); box-shadow: inset 0 0 0 1.5px rgba(255, 255, 255, 0.2); transition: background 0.3s, color 0.3s, box-shadow 0.3s; }
.arch-flows button:hover { color: #fff; box-shadow: inset 0 0 0 1.5px rgba(255, 255, 255, 0.5); }
.arch-flows button[aria-selected="true"] { background: var(--yellow); color: var(--ink); box-shadow: none; }
.arch-canvas { position: relative; background:
    radial-gradient(circle at 1px 1px, rgba(255, 255, 255, 0.09) 1px, transparent 0) 0 0 / 22px 22px, #121212; border: 1px solid rgba(255, 255, 255, 0.08); padding: clamp(8px, 1.5vw, 18px); }
.arch-canvas svg { width: 100%; height: auto; overflow: visible; }
.a-node rect { fill: #1b1b1b; stroke: rgba(255, 255, 255, 0.22); stroke-width: 1.5; transition: fill 0.3s, stroke 0.3s; }
.a-node .a-t { fill: #fff; font: 700 15px var(--font); }
.a-node .a-s { fill: rgba(255, 255, 255, 0.55); font: 500 11.5px var(--mono); }
.a-node .a-dot { fill: var(--c, #fff); }
.a-node.is-on rect { stroke: var(--yellow); fill: #232016; }
.a-node.is-dim { opacity: 0.35; }
.a-node { cursor: default; transition: opacity 0.3s; }
.a-group { fill: none; stroke: rgba(255, 255, 255, 0.12); stroke-dasharray: 4 6; }
.a-glabel { fill: rgba(255, 255, 255, 0.4); font: 700 10.5px var(--font); letter-spacing: 0.14em; text-transform: uppercase; }
.a-edge { fill: none; stroke: rgba(255, 255, 255, 0.18); stroke-width: 1.5; transition: stroke 0.3s, opacity 0.3s; }
.a-edge.is-on { stroke: var(--yellow); stroke-width: 2.2; stroke-dasharray: 6 6; animation: flow 0.8s linear infinite; }
.a-edge.is-dim { opacity: 0.35; }
@keyframes flow { to { stroke-dashoffset: -12; } }
.a-packet { fill: var(--yellow); filter: drop-shadow(0 0 6px rgba(254, 207, 111, 0.9)); }
.a-tip { pointer-events: none; }
.arch-steps { counter-reset: s; display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 10px; margin-top: 16px; }
.arch-steps li { counter-increment: s; position: relative; padding: 12px 14px 12px 44px; background: #161616; border: 1px solid rgba(255, 255, 255, 0.08); font-size: 14px; color: rgba(255, 255, 255, 0.72); transition: border-color 0.3s, background 0.3s, color 0.3s; cursor: pointer; }
.arch-steps li::before { content: counter(s); position: absolute; left: 14px; top: 12px; width: 20px; height: 20px; display: grid; place-items: center; font: 700 11px var(--mono); background: rgba(255, 255, 255, 0.12); color: #fff; }
.arch-steps li.is-on { border-color: var(--yellow); background: #1f1c13; color: #fff; }
.arch-steps li.is-on::before { background: var(--yellow); color: var(--ink); }
.arch-steps b { color: #fff; font-weight: 700; }

/* ---------- Tech stack ---------- */
.stack { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1px; background: rgba(255, 255, 255, 0.1); border: 1px solid rgba(255, 255, 255, 0.1); overflow: hidden; }
.st { padding: clamp(18px, 2.2vw, 26px); background: var(--ink); transition: background 0.3s; }
.st:hover { background: #151515; }
.st-k { font-family: var(--mono); font-size: 11.5px; color: var(--yellow); margin-bottom: 10px; }
.st h3 { font-size: 19px; font-weight: 800; letter-spacing: -0.015em; line-height: 1.2; margin-bottom: 10px; }
.st p { font-size: 14.5px; color: rgba(255, 255, 255, 0.66); line-height: 1.55; }

/* ---------- ER cards ---------- */
.er { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.ent { background: #151515; border: 1px solid rgba(255, 255, 255, 0.1); overflow: hidden; transition: border-color 0.3s, transform 0.4s var(--ease), opacity 0.3s; }
.ent h3 { display: flex; align-items: center; gap: 10px; padding: 12px 16px; font-size: 16px; font-weight: 800; background: #1d1d1d; border-bottom: 1px solid rgba(255, 255, 255, 0.08); }
.ent h3::before { content: ""; width: 10px; height: 10px; background: var(--c, var(--lav)); }
.ent[data-ent="Course"] { --c: var(--lav); } .ent[data-ent="Folder"] { --c: var(--yellow); } .ent[data-ent="File"] { --c: var(--blue); }
.ent[data-ent="User"] { --c: var(--pink); } .ent[data-ent="Contribution"] { --c: var(--lime); }
.ent[data-ent="CourseAllotment"], .ent[data-ent="BR"] { --c: #888; }
.ent ul { padding: 8px 0; }
.ent li { display: flex; justify-content: space-between; gap: 12px; padding: 6px 16px; font-size: 12.5px; }
.ent li b { font-family: var(--mono); font-weight: 500; color: #fff; }
.ent li span { color: rgba(255, 255, 255, 0.5); text-align: right; font-family: var(--mono); font-size: 11.5px; }
.ent .ref { color: var(--yellow); cursor: help; }
.ent-key { border-color: rgba(254, 207, 111, 0.5); }
.er.has-focus .ent { opacity: 0.4; }
.er.has-focus .ent.is-target, .er.has-focus .ent.is-source { opacity: 1; border-color: var(--yellow); transform: translateY(-3px); }

.tree-demo { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: clamp(24px, 4vw, 56px); align-items: center; margin-top: clamp(50px, 7vw, 90px); }
.td-tree { margin: 0; padding: 22px 24px; background: #151515; border: 1px solid rgba(255, 255, 255, 0.1); overflow-x: auto; font: 13.5px/1.75 var(--mono); color: rgba(255, 255, 255, 0.5); }
.td-tree code { background: none; padding: 0; color: inherit; font-size: inherit; }
.t-c { color: var(--lav); font-weight: 600; } .t-f { color: var(--yellow); } .t-l { color: #fff; } .t-m { color: rgba(255, 255, 255, 0.35); }

.link-demo { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: clamp(24px, 4vw, 56px); align-items: center; margin-top: clamp(50px, 7vw, 90px); }
.ld-copy .btn-ch { margin-top: 20px; }
.ld-viz { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; padding: 18px; background: #151515; border: 1px solid rgba(255, 255, 255, 0.1); }
.ld-course { display: flex; align-items: center; gap: 8px; font-size: 12px; color: rgba(255, 255, 255, 0.5); margin-bottom: 12px; }
.ld-course .cc-code { background: var(--yellow); color: var(--ink); font-size: 12px; }
.ld-col ul { display: grid; gap: 8px; }
.ld-f, .ld-ghost { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 10px 12px; font-weight: 700; font-size: 14px; min-height: 42px; }
.ld-f { background: #222; border: 1px solid rgba(255, 255, 255, 0.12); }
.ld-f code { font-size: 10.5px; color: rgba(255, 255, 255, 0.6); background: none; padding: 0; transition: color 0.4s; }
.ld-f.is-shared { border-color: var(--yellow); }
.ld-f.is-shared code { color: var(--yellow); }
.ld-own { background: #1c1c1c; }
.ld-ghost { border: 1.5px dashed rgba(255, 255, 255, 0.14); color: rgba(255, 255, 255, 0.2); transition: all 0.5s var(--ease); }
.ld-ghost.is-shared { border: 1px solid var(--yellow); background: #262113; color: #fff; }
.ld-ghost.is-shared::after { content: "shared"; font: 600 10px var(--mono); color: var(--ink); background: var(--yellow); padding: 1px 6px; }

/* ---------- Upload pipeline ---------- */
.pipe { position: relative; display: grid; grid-template-columns: 4px minmax(0, 1fr); gap: 0 28px; }
.pipe-rail { position: relative; background: rgba(255, 255, 255, 0.1); }
.pipe-rail i { position: absolute; left: 0; top: 0; width: 100%; height: 100%; background: var(--yellow); transform-origin: 50% 0; transform: scaleY(0); }
.pipe ol { counter-reset: p; display: grid; gap: 0; }
.pipe li { counter-increment: p; position: relative; display: grid; grid-template-columns: minmax(150px, 0.32fr) minmax(0, 1fr); gap: 20px; padding: 20px 0; border-top: 1px solid rgba(255, 255, 255, 0.1); }
.pipe li:first-child { border-top: 0; }
.pipe li::before { content: counter(p, decimal-leading-zero); position: absolute; left: -46px; top: 18px; width: 32px; height: 26px; display: grid; place-items: center; font: 600 11px var(--mono); background: var(--ink); color: rgba(255, 255, 255, 0.5); border: 1px solid rgba(255, 255, 255, 0.15); transition: all 0.4s; }
.pipe li.is-on::before { background: var(--yellow); color: var(--ink); border-color: var(--yellow); }
.pipe b { font-size: 18px; font-weight: 800; letter-spacing: -0.01em; }
.pipe li span { font-size: 15.5px; color: rgba(255, 255, 255, 0.7); }
.pipe li:last-child b::after { content: "background"; margin-left: 10px; font: 600 10.5px var(--mono); color: var(--ink); background: var(--lime); padding: 2px 7px; vertical-align: 3px; }

/* ---------- Auth sequence ---------- */
.seq { position: relative; padding: 16px 0 6px; }
.seq-lanes { display: grid; grid-template-columns: repeat(5, 1fr); position: sticky; top: var(--bar); z-index: 2; margin-bottom: 0; padding: 10px 0 18px; background: linear-gradient(var(--ink) 75%, rgba(11, 11, 11, 0)); }
.seq-lanes span { justify-self: center; padding: 7px 12px; background: #1b1b1b; border: 1px solid rgba(255, 255, 255, 0.16); font-size: 12.5px; font-weight: 700; text-align: center; }
.seq-lanes span:nth-child(3) { border-color: rgba(0, 164, 239, 0.6); }
.seq-msgs { position: relative; display: grid; gap: 4px; }
.seq-msgs::before { content: ""; position: absolute; inset: -8px 0 0; background: repeating-linear-gradient(90deg, transparent 0 calc(10% - 0.75px), rgba(255, 255, 255, 0.14) calc(10% - 0.75px) calc(10% + 0.75px), transparent calc(10% + 0.75px) 20%); pointer-events: none; }
.seq-msgs li { position: relative; margin-left: calc((var(--a) - 0.5) * 20%); width: calc((var(--b) - var(--a)) * 20%); padding: 10px 6px 18px; text-align: center; }
.seq-msgs li::after { content: ""; position: absolute; left: 0; right: 0; bottom: 8px; height: 2px; background: rgba(255, 255, 255, 0.35); transform-origin: var(--o, 0%) 50%; transform: scaleX(var(--k, 1)); transition: transform 0.7s var(--ease), background 0.4s; }
.seq-msgs li::before { content: ""; position: absolute; bottom: 4px; width: 0; height: 0; border-top: 5px solid transparent; border-bottom: 5px solid transparent; transition: border-color 0.4s; }
.seq-msgs li[data-dir="r"]::before { right: -1px; border-left: 8px solid rgba(255, 255, 255, 0.35); }
.seq-msgs li[data-dir="l"] { --o: 100%; }
.seq-msgs li[data-dir="l"]::before { left: -1px; border-right: 8px solid rgba(255, 255, 255, 0.35); }
.seq-msgs li.is-on::after { background: var(--yellow); }
.seq-msgs li.is-on[data-dir="r"]::before { border-left-color: var(--yellow); }
.seq-msgs li.is-on[data-dir="l"]::before { border-right-color: var(--yellow); }
.seq-msgs b { display: block; font-size: 14px; font-weight: 700; }
.seq-msgs li > span { display: block; font-size: 12.5px; color: rgba(255, 255, 255, 0.6); line-height: 1.45; max-width: 34ch; margin: 2px auto 0; }
.seq-who { display: none; }
.auth-notes { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; margin-top: clamp(36px, 5vw, 60px); }
.auth-notes article { padding: 20px; background: #151515; border: 1px solid rgba(255, 255, 255, 0.1); }
.auth-notes h3 { font-size: 17px; font-weight: 800; margin-bottom: 8px; }
.auth-notes p { font-size: 14.5px; color: rgba(255, 255, 255, 0.66); }

/* ---------- Caching layers ---------- */
.layers { display: grid; gap: 8px; }
.layers li { display: grid; grid-template-columns: 190px 200px minmax(0, 1fr); align-items: center; gap: 20px; padding: 16px 20px; background: #151515; border: 1px solid rgba(255, 255, 255, 0.08); transition: transform 0.4s var(--ease), border-color 0.3s; }
.layers li:hover { transform: translateX(6px); border-color: rgba(254, 207, 111, 0.6); }
.ly-where { font: 600 11.5px var(--mono); color: var(--yellow); }
.layers b { font-size: 17px; font-weight: 800; }
.ly-what { font-size: 14.5px; color: rgba(255, 255, 255, 0.66); }
.layers li:nth-child(-n + 2) .ly-where { color: var(--lav); }
.layers li:nth-child(3) .ly-where { color: var(--pink); }
.layers li:nth-child(n + 4) .ly-where { color: var(--lime); }

/* ---------- Shipping ---------- */
.ship { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: clamp(24px, 4vw, 56px); align-items: start; }
.ship-flow { display: grid; gap: 10px; }
.ship-flow li { position: relative; display: grid; gap: 4px; padding: 16px 18px; border: 1px solid rgba(255, 255, 255, 0.12); }
.ship-flow li + li::before { content: ""; position: absolute; left: 30px; top: -11px; width: 1.5px; height: 10px; background: var(--yellow); }
.ship-flow b { font-family: var(--mono); font-size: 14px; font-weight: 600; color: var(--yellow); }
.ship-flow span { font-size: 14.5px; color: rgba(255, 255, 255, 0.7); }

@media (max-width: 900px) {
    .stack, .er, .auth-notes { grid-template-columns: minmax(0, 1fr); }
    .tree-demo, .link-demo, .ship { grid-template-columns: minmax(0, 1fr); }
    .td-tree { font-size: 11.5px; padding: 16px; }
    .ld-viz { padding: 12px; gap: 10px; }
    .ld-f, .ld-ghost { font-size: 13px; padding: 8px 10px; flex-wrap: wrap; }
    .pipe { gap: 0 18px; padding-left: 40px; }
    .pipe li { grid-template-columns: minmax(0, 1fr); gap: 4px; }
    .pipe li::before { left: -78px; }
    .layers li { grid-template-columns: minmax(0, 1fr); gap: 4px; }
    /* The sequence becomes a numbered list with who-to-whom chips */
    .seq-lanes { display: none; }
    .seq-msgs { counter-reset: q; gap: 10px; }
    .seq-msgs::before { display: none; }
    .seq-msgs li { counter-increment: q; margin: 0; width: auto; text-align: left; padding: 12px 14px 12px 46px; background: #151515; border: 1px solid rgba(255, 255, 255, 0.1); }
    .seq-msgs li::after { display: none; }
    .seq-msgs li::before { content: counter(q); left: 14px !important; top: 13px; bottom: auto; width: 20px; height: 20px; border: 0 !important; display: grid; place-items: center; font: 700 11px var(--mono); background: rgba(255, 255, 255, 0.12); color: #fff; }
    .seq-msgs li.is-on::before { background: var(--yellow); color: var(--ink); }
    .seq-msgs li > span { margin: 2px 0 0; max-width: none; }
    .seq-who { display: inline-block; font: 600 10.5px var(--mono); color: var(--ink); background: var(--yellow); padding: 1px 6px; margin-bottom: 6px; }
}
