/* Diagrams inside posts, drawn as bricks (DESIGN.md: five colours, 3px keyline, square bricks, Rubik).
   The finished drawing is the default. Motion only adds: pieces settle once when a diagram scrolls in,
   and three diagrams move a yellow "now" marker on a slow loop that has a pause button. */

.dg { padding: clamp(18px, 3vw, 28px); border: var(--line); background: var(--sky); color: var(--ink); font-size: 17px; line-height: 1.35; }
.post .sheet-body .dg p, .post .sheet-body .dg ul, .post .sheet-body .dg ol { margin: 0; max-width: none; }
.post .sheet-body .dg li { padding-left: 0; }
.post .sheet-body .dg li + li { margin-top: 0; }
.post .sheet-body .dg li::before { content: none; }
.post .sheet-body .dg .dg-title { font-weight: 800; font-size: clamp(20px, 2.4vw, 24px); line-height: 1.15; letter-spacing: -.01em; }
.post .sheet-body .dg .dg-sub { margin-top: 6px; font-weight: 500; font-size: 16px; }
.dg-body { margin-top: 22px; }
.post .sheet-body .dg .dg-foot { margin-top: 18px; font-weight: 500; font-size: 16px; }

/* Bricks and pieces */
.b { position: relative; min-width: 0; padding: 14px 16px; border: var(--line); background: var(--white); font-weight: 700; transition: background-color .45s var(--out), color .45s var(--out); }
.b small, .b .note { display: block; margin-top: 4px; font-weight: 500; font-size: 15px; }
.b.y { background: var(--yellow); }
.b.r { background: var(--red); color: var(--white); }
.b.k { background: var(--ink); color: var(--white); }
.b.later { border-style: dashed; background: transparent; }
.b.c { text-align: center; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; padding: 0; list-style: none; }
.chips li, .chip { display: inline-block; padding: 4px 10px; border: 2px solid var(--ink); background: var(--white); color: var(--ink); font-weight: 500; font-size: 15px; transition: background-color .45s var(--out); }
.dg [data-on].on { background: var(--yellow); color: var(--ink); }
.split { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 4px 16px; }
.split .note { margin-top: 0; }

/* A row of pieces joined by arrows; it turns into a column on phones */
.flow { display: flex; align-items: stretch; }
.flow > .b, .flow > .col { flex: 1 1 0; }
.arr { position: relative; flex: 0 0 34px; align-self: center; height: 3px; background: var(--ink); }
.arr::after { content: ""; position: absolute; right: -2px; top: -6px; border-left: 11px solid var(--ink); border-top: 7.5px solid transparent; border-bottom: 7.5px solid transparent; }
.arr.dashed { background: repeating-linear-gradient(90deg, var(--ink) 0 8px, transparent 8px 13px); }

/* Pieces stacked on each other share one keyline */
.stack > .b + .b { border-top: 0; }
.stack .studs { max-width: 368px; }

/* 01 Three strands on one fabric */
.strands { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); }
.strands .b + .b { border-left: 0; }
.strands .b { min-height: 84px; display: flex; align-items: center; justify-content: center; text-align: center; }
.fabric { border-top: 0; text-align: center; }

/* 02 The engineering layer swaps out under a Ninja Harness that holds still */
.post .sheet-body .dg .swap { position: relative; min-height: 2.7em; margin-top: 10px; font-weight: 500; font-size: 15px; }
.post .sheet-body .dg .swap p + p { margin-top: 4px; }
.engine .eras li[data-on].on { background: var(--yellow); }
.post .sheet-body .dg .swap p.on { background: transparent; }

/* 03 Agents with and without a discipline */
.pair { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
.panel { position: relative; height: 270px; border: var(--line); background: var(--white); overflow: hidden; }
.panel svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.panel .chip { position: absolute; white-space: nowrap; font-size: 15px; }
.panel-label { margin-top: 10px; font-weight: 700; text-align: center; }
.lanes { position: absolute; inset: 0; display: grid; grid-template-columns: minmax(0, 1fr) 70px 26px 76px; align-items: center; padding: 22px 16px; }
.lanes .ln { display: grid; gap: 30px; }
.lanes .ln div { font-weight: 500; font-size: 15px; }
.lanes .ln div::after { content: ""; display: block; height: 3px; margin-top: 6px; background: var(--ink); }
.cutoff { height: 100%; display: flex; align-items: center; justify-content: center; padding: 8px; border: var(--line); background: var(--ink); color: var(--white); font-weight: 700; font-size: 15px; text-align: center; }
.lanes .arr { flex: none; width: 100%; }
.ship { padding: 10px 8px; text-align: center; }

/* 04 Where the hard part went */
.bn { display: grid; gap: 22px; }
.bn-row { display: grid; grid-template-columns: 170px 1fr; gap: 16px; align-items: center; }
.bn-label { font-weight: 700; }
.bn-label small { display: block; font-weight: 500; font-size: 15px; }
.bn-bar { display: flex; min-height: 64px; }
.bn-bar > .b { flex: var(--g) 1 0; display: flex; align-items: center; justify-content: center; text-align: center; transition: flex-grow 1.3s var(--out) .45s, background-color .5s var(--out) 1.5s; }
.bn-bar > .b + .b { border-left: 0; }

/* 05 Learn, adapt, discipline */
.offroad { max-width: 360px; margin-bottom: 18px; }
.loop { margin-top: 18px; }
.loop .b { border-radius: 0; }
.loop-back { height: 22px; margin: 0 34px; border: 3px dashed var(--ink); border-top: 0; }
.post .sheet-body .dg .loop-note { margin-top: 8px; font-weight: 500; font-size: 15px; text-align: center; }

/* 06 The two-week sprint, at rest */
.rest { display: grid; grid-template-columns: 1fr auto 1fr; align-items: end; }
.tomb { grid-column: 2; width: 300px; padding: 54px 24px 28px; border: var(--line); border-bottom: 0; border-radius: 150px 150px 0 0; background: var(--white); text-align: center; font-weight: 500; }
.post .sheet-body .dg .tomb p + p { margin-top: 12px; }
.tomb .name { font-weight: 800; font-size: 22px; line-height: 1.15; }
.tomb .rip { font-weight: 800; font-size: 22px; }
.cause { grid-column: 3; align-self: center; margin-left: 28px; max-width: 250px; }
.cause::before { content: ""; position: absolute; right: 100%; top: 50%; width: 28px; border-top: 3px dashed var(--ink); }
.ground { grid-column: 1 / -1; height: 10px; background: var(--ink); }

/* 07 Tools change, the Kata stays */
.tools { gap: 0; }
.ties { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); height: 30px; }
.ties span { justify-self: center; width: 0; border-left: 3px dashed var(--ink); }
.kata-strip { text-align: center; }

/* 08 Belts climb */
.belts { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); align-items: end; gap: 12px; }
.belt { display: flex; flex-direction: column; justify-content: space-between; min-height: calc(70px + var(--h) * 36px); text-align: center; transform-origin: bottom; }
.belt i { display: block; height: 14px; margin-top: 12px; border: 2px solid var(--ink); background: var(--c); }
.belt-say { margin-top: 8px; font-weight: 500; font-size: 15px; text-align: center; }

/* 09 Inject, build, deploy */
.target { text-align: center; }
.drops { display: grid; grid-template-columns: 1fr 1.6fr 1fr; height: 28px; margin: 0 0; }
.drops span { justify-self: center; width: 0; border-left: 3px dashed var(--ink); }
.ibd { display: grid; grid-template-columns: 1fr 34px 1.6fr 34px 1fr; align-items: stretch; }
.ibd .b { text-align: center; }
.katas { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 8px; margin-top: 12px; }
.katas .chip { font-weight: 700; }

/* 10 One Kata week */
.week { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0 34px; row-gap: 26px; position: relative; }
.week .b { text-align: center; }
.week .q { background: var(--white); }
.week .tie { position: relative; }
.week .tie::before { content: ""; position: absolute; left: 50%; bottom: 100%; height: 26px; border-left: 3px dashed var(--ink); }
.week .h-arr { position: relative; }
.week .h-arr::after { content: ""; position: absolute; left: 100%; top: 50%; width: 34px; height: 3px; background: var(--ink); }
.week .yes { position: absolute; left: 100%; top: 50%; transform: translate(4px, -26px); font-weight: 500; font-size: 15px; }
.post .sheet-body .dg .week-back { margin-top: 14px; padding: 8px 0 0; border-top: 3px dashed var(--ink); font-weight: 500; font-size: 15px; }

/* 11 and 12: three pieces in a row */
.big { display: block; margin: 10px 0 4px; font-weight: 800; font-size: 36px; line-height: 1; }
.steps-list { margin-top: 8px; padding-left: 22px; font-weight: 500; text-align: left; }
.post .sheet-body .dg .steps-list li + li { margin-top: 4px; }
.post .sheet-body .dg .steps-list { padding-left: 22px; list-style: decimal; }
.road .b { text-align: left; }
.road .tag { display: block; margin-bottom: 6px; font-weight: 800; font-size: 15px; }

/* Pause control for the looping diagrams */
.dg-controls { margin-top: 16px; }
.dg-pause { display: inline-flex; align-items: center; min-height: 44px; padding: 0 18px; border: var(--line); border-radius: 8px; background: var(--white); color: var(--ink); font: inherit; font-weight: 700; font-size: 16px; cursor: pointer; transition: transform .12s var(--out), box-shadow .12s var(--out); }
.dg-pause:hover { transform: translateY(-2px); box-shadow: 0 6px 12px rgba(17, 17, 17, .22); }
.dg-pause:active { transform: translateY(1px); box-shadow: none; }
.dg-pause:focus-visible { outline: 3px solid var(--ink); outline-offset: 3px; }

/* Motion. Hidden-before-entrance applies only when script runs and motion is allowed. */
@media (prefers-reduced-motion: no-preference) {
  .js .dg[data-anim]:not(.in) .piece { opacity: 0; }
  .js .dg.in .piece { animation: dg-settle .7s var(--out) both; animation-delay: calc(var(--i, 0) * 120ms); }
  .js .dg.in .belt.piece { animation-name: dg-rise; }
  .js .dg .swap p { display: none; }
  .js .dg .swap p.on { display: block; animation: dg-swap-in .6s var(--out) both; }
  .js .dg.in .engine.jolt { animation: dg-jolt .5s var(--out); }
  .js .dg[data-anim]:not(.in) .bn-bar > .b { flex-grow: var(--g0, var(--g)); }
  .js .dg[data-anim]:not(.in) .bn-bar > .b.y { background: var(--white); }
}
@keyframes dg-settle { 0% { opacity: 0; transform: translateY(-26px); } 70% { opacity: 1; transform: translateY(3px); } 100% { opacity: 1; transform: none; } }
@keyframes dg-rise { 0% { opacity: 0; transform: scaleY(.2); } 70% { opacity: 1; transform: scaleY(1.03); } 100% { opacity: 1; transform: none; } }

@media (max-width: 760px) {
  .chips { gap: 6px; }
  .chips li, .chip { padding: 3px 7px; }
  .dg { font-size: 16px; }
  .flow { flex-direction: column; }
  .flow > .arr { flex-basis: 28px; width: 3px; height: auto; }
  .flow > .arr::after { right: auto; left: -6px; top: auto; bottom: -2px; border-top: 11px solid var(--ink); border-left: 7.5px solid transparent; border-right: 7.5px solid transparent; border-bottom: 0; }
  .flow > .arr.dashed { background: repeating-linear-gradient(180deg, var(--ink) 0 8px, transparent 8px 13px); }
  .strands { grid-template-columns: 1fr; }
  .strands .b + .b { border-left: var(--line); border-top: 0; }
  .strands .b { min-height: 60px; }
  .pair { grid-template-columns: 1fr; }
  .panel { height: 300px; }
  .panel .chip { white-space: normal; max-width: 82%; }
  .lanes { grid-template-columns: minmax(0, 1fr) 60px 20px 64px; padding: 18px 12px; }
  .lanes .ln div { padding-right: 10px; }
  .bn-row { grid-template-columns: 1fr; gap: 8px; }
  .bn-bar { flex-direction: column; height: 250px; }
  .bn-bar > .b + .b { border-left: var(--line); border-top: 0; }
  .rest { grid-template-columns: 1fr; justify-items: center; }
  .tomb { grid-column: 1; width: 240px; padding-top: 44px; }
  .cause { grid-column: 1; grid-row: 3; margin: 16px 0 0; max-width: none; }
  .cause::before { display: none; }
  .ground { grid-row: 2; width: 100%; }
  .ties { display: none; }
  .tools > .kata-strip { margin-top: 18px; }
  .belts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .drops { display: none; }
  .ibd { grid-template-columns: 1fr; grid-template-rows: auto 28px auto 28px auto; }
  .ibd .arr { justify-self: center; }
  .target { margin-bottom: 18px; }
  .week { grid-template-columns: 1fr; row-gap: 0; }
  .week .tie::before, .week .h-arr::after, .week .yes { display: none; }
  .week > div:empty { display: none; }
  .week > .b { margin-top: -3px; }
  .week > :nth-child(1) { order: 1; margin-top: 0; } .week > :nth-child(2) { order: 2; } .week > :nth-child(6) { order: 3; }
  .week > :nth-child(3) { order: 4; } .week > :nth-child(7) { order: 5; } .week > :nth-child(4) { order: 6; } .week > :nth-child(8) { order: 7; }
  .loop-back { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .dg-pause { display: none; }
}
@keyframes dg-swap-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes dg-jolt { 0%, 100% { transform: none; } 25% { transform: translateX(-5px); } 50% { transform: translateX(4px); } 75% { transform: translateX(-2px); } }

/* Post hero: one quiet drawing. The engineering line changes shape; the harness and delivery hold still */
.dg.hero { margin: 0 0 36px; padding: 0; border: 0; background: transparent; }
.hero-grid { display: grid; grid-template-columns: 132px minmax(0, 1fr) 190px; align-items: center; gap: 18px 20px; padding: 26px 0; border-top: 2px solid var(--ink); border-bottom: 2px solid var(--ink); }
.post .sheet-body .dg.hero .hero-label { margin: 0; font-weight: 700; font-size: 16px; }
.post .sheet-body .dg.hero .hero-note { margin: 0; font-weight: 500; font-size: 15px; }
.hero-track { position: relative; height: 40px; }
.hero-track svg { display: block; width: 100%; height: 100%; overflow: visible; }
.hero-track path { fill: none; stroke: var(--ink); stroke-width: 3; opacity: 0; transition: opacity .7s var(--out); }
.hero-track path.on { opacity: 1; }
.hero-steady::before { content: ""; position: absolute; left: 0; right: 0; top: 50%; height: 3px; margin-top: -1.5px; background: var(--ink); }
.hero-steady::after { content: ""; position: absolute; left: 0; right: 0; top: 50%; height: 13px; margin-top: -6.5px; background: repeating-linear-gradient(90deg, transparent 0 calc(20% - 3px), var(--ink) calc(20% - 3px) 20%); }
.hero-dot { position: absolute; top: 50%; left: 62%; width: 16px; height: 16px; margin: -8px 0 0 -8px; border: 3px solid var(--ink); background: var(--yellow); z-index: 1; }
.hero-band { padding: 10px 14px; border: var(--line); background: var(--yellow); font-weight: 700; font-size: 15px; }
.hero-swap { position: relative; min-height: 1.4em; }
.hero-swap span { display: none; }
.post .sheet-body .dg.hero .hero-swap span.on { display: inline; background: transparent; }
.post .dg.hero figcaption { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; margin-top: 10px; }
.dg.hero .dg-pause { min-height: 44px; padding: 0; border: 0; background: none; font-weight: 500; font-size: 15px; text-decoration: underline; text-underline-offset: 3px; }
.dg.hero .dg-pause:hover { transform: none; box-shadow: none; }
@media (prefers-reduced-motion: no-preference) {
  .js .dg.hero.in .hero-dot { animation: hero-glide 9s linear infinite; }
  .js .dg.hero .hero-swap span.on { animation: dg-swap-in .6s var(--out) both; }
  .motion-paused .dg.hero .hero-dot { animation-play-state: paused; }
}
@keyframes hero-glide { from { left: 0; } to { left: 100%; } }
@media (max-width: 760px) {
  .hero-grid { grid-template-columns: minmax(0, 1fr) auto; grid-auto-flow: row dense; gap: 6px 12px; padding: 20px 0; }
  .hero-grid .hero-label { grid-column: 1; }
  .hero-grid .hero-note { grid-column: 2; text-align: right; }
  .hero-grid .hero-track, .hero-grid .hero-band { grid-column: 1 / -1; margin-bottom: 14px; }
}

/* The belt check: tick-boxes in the brick look */
.post .sheet-body .check { margin-top: 18px; max-width: 70ch; display: grid; gap: 10px; }
.check label { display: flex; gap: 14px; align-items: flex-start; padding: 12px 16px; background: var(--white); border: var(--line); cursor: pointer; transition: background .15s, transform .15s; }
.check label:hover { transform: translate(-2px, -2px); box-shadow: 4px 4px 0 var(--ink); }
.check label:has(input:checked) { background: var(--yellow); }
.check input { appearance: none; -webkit-appearance: none; flex: none; width: 24px; height: 24px; margin: 3px 0 0; border: 3px solid var(--ink); background: var(--white); cursor: pointer; display: grid; place-content: center; }
.check input:checked { background: var(--red); }
.check input:checked::after { content: ""; width: 6px; height: 12px; margin-top: -3px; border: solid var(--white); border-width: 0 3px 3px 0; transform: rotate(45deg); }
.check input:focus-visible { outline: 3px solid var(--ink); outline-offset: 3px; }
.post .sheet-body .check-result { margin: 4px 0 0; font-weight: 700; }
@media (prefers-reduced-motion: reduce) { .check label, .check label:hover { transition: none; transform: none; } }
