/* ============================================================
   CardCatalog — "data journey" scrollytelling engine
   ============================================================ */

.journey { position: relative; }
.journey-sticky {
  position: sticky; top: 0; height: 100vh; min-height: 640px;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.jn-stage {
  width: min(1120px, 92vw);
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: clamp(14px, 2.4vh, 28px);
  height: min(86vh, 760px);
}

/* ---- progress rail ---- */
.jn-rail { display: flex; align-items: center; gap: 0; position: relative; padding: 0 6px; }
.jn-rail .rail-track { position: absolute; left: 18px; right: 18px; top: 11px; height: 2px; background: rgba(120,150,200,0.16); border-radius: 2px; }
.jn-rail .rail-fill { position: absolute; left: 18px; top: 11px; height: 2px; background: linear-gradient(90deg, var(--blue), var(--cyan), var(--green)); border-radius: 2px; width: 0; transition: width .35s cubic-bezier(.4,0,.2,1); box-shadow: 0 0 10px var(--cyan-g); }
.jn-step-dot { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 9px; position: relative; z-index: 2; cursor: pointer; }
.jn-step-dot .dot { width: 22px; height: 22px; border-radius: 50%; border: 2px solid rgba(120,150,200,0.3); background: var(--bg-2); display: grid; place-items: center; font-family: var(--f-mono); font-size: 10px; color: var(--ink-mute); transition: all .35s; }
.jn-step-dot .lbl { font-family: var(--f-mono); font-size: 11px; color: var(--ink-mute); letter-spacing: 0.02em; transition: color .35s; text-align: center; white-space: nowrap; }
.jn-step-dot.done .dot { border-color: var(--cyan); color: var(--cyan); }
.jn-step-dot.active .dot { border-color: var(--cyan); background: var(--cyan); color: #04121f; box-shadow: 0 0 16px var(--cyan-g); transform: scale(1.15); }
.jn-step-dot.active .lbl { color: var(--ink); }
@media (max-width: 720px){ .jn-step-dot .lbl { display: none; } }

/* ---- canvas (scenes stacked) ---- */
.jn-canvas { position: relative; border-radius: var(--radius-lg); overflow: hidden; }
.jn-scene {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  padding: clamp(16px, 3vw, 40px);
  opacity: 0; transform: translateY(24px) scale(.98);
  transition: opacity .55s cubic-bezier(.2,.7,.2,1), transform .55s cubic-bezier(.2,.7,.2,1);
  pointer-events: none;
}
.jn-scene.active { opacity: 1; transform: none; pointer-events: auto; }

/* ---- caption ---- */
.jn-caption { display: grid; grid-template-columns: 1fr auto; gap: 20px; align-items: end; }
.jn-cap-text { max-width: 720px; }
.jn-cap-kicker { font-family: var(--f-mono); font-size: 12px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--cyan); }
.jn-cap-title { font-family: var(--f-display); font-size: clamp(22px, 3.2vw, 34px); font-weight: 600; letter-spacing: -0.02em; margin: 8px 0 6px; line-height: 1.05; }
.jn-cap-desc { color: var(--ink-soft); font-size: clamp(14px, 1.7vw, 16.5px); margin: 0; text-wrap: pretty; }
.jn-cap-desc code { font-family: var(--f-mono); font-size: 0.9em; color: var(--cyan); }
.jn-metric {
  flex: none; text-align: right; padding: 14px 20px; border-radius: 14px;
  border: 1px solid var(--line-2); background: var(--panel-2);
  min-width: 150px; transition: border-color .4s, box-shadow .4s;
}
.jn-metric .v { font-family: var(--f-mono); font-size: clamp(22px, 3vw, 30px); font-weight: 600; letter-spacing: -0.02em; color: var(--ink); white-space: nowrap; }
.jn-metric .l { font-family: var(--f-mono); font-size: 10.5px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-mute); margin-top: 4px; }
.jn-metric.flash { border-color: var(--cyan); box-shadow: 0 0 0 1px var(--cyan-g), 0 14px 40px -18px var(--cyan-g); }
@media (max-width: 640px){ .jn-caption { grid-template-columns: 1fr; } .jn-metric { text-align: left; } }

.jn-hint { position: absolute; bottom: 18px; left: 50%; transform: translateX(-50%); font-family: var(--f-mono); font-size: 12px; color: var(--ink-mute); display: flex; align-items: center; gap: 8px; opacity: .8; }
.jn-hint .m { animation: hintBob 1.8s ease-in-out infinite; }
@keyframes hintBob { 0%,100%{ transform: translateY(0);} 50%{ transform: translateY(4px);} }

/* ============================================================
   SHARED VISUAL PRIMITIVES
   ============================================================ */
.bit {
  width: var(--bs, 16px); height: var(--bs, 16px); border-radius: 3px;
  background: rgba(120,150,200,0.12);
  display: inline-grid; place-items: center;
  font-family: var(--f-mono); font-size: calc(var(--bs,16px) * 0.56); color: var(--ink-mute);
  transition: background .3s, box-shadow .3s, color .3s, transform .3s;
}
.bit.on { background: var(--bc, var(--cyan)); color: #04121f; box-shadow: 0 0 9px var(--bc, var(--cyan-g)); font-weight: 600; }
.bit.pop { transform: scale(1.28); }
.byte-row { display: flex; gap: 4px; }
.byte-row.grouped { gap: 4px; }
.byte-row .gap { width: 6px; }

/* scene 1 — parse */
.sc-parse { display: flex; flex-direction: column; gap: 22px; align-items: center; width: 100%; }
.raw-line { font-family: var(--f-mono); font-size: clamp(15px, 2.2vw, 24px); display: flex; flex-wrap: wrap; gap: 0; justify-content: center; line-height: 1.8; }
.raw-line .tok { padding: 4px 9px; border-radius: 7px; transition: all .45s; border: 1px solid transparent; position: relative; }
.raw-line .comma { color: var(--ink-mute); padding: 4px 1px; }
.raw-line .tok.hl { color: var(--ink); }
.raw-line .tok[data-f="year"].hl { background: rgba(169,139,255,0.16); border-color: var(--purple); color: var(--purple); }
.raw-line .tok[data-f="category"].hl { background: rgba(70,227,154,0.14); border-color: var(--green); color: var(--green); }
.raw-line .tok[data-f="author"].hl { background: rgba(77,141,255,0.14); border-color: var(--blue); color: var(--blue); }
.raw-line .tok[data-f="title"].hl { background: rgba(47,224,224,0.13); border-color: var(--cyan); color: var(--cyan); }
.raw-line .tok .ftag { position: absolute; top: -20px; left: 50%; transform: translateX(-50%); font-size: 9.5px; letter-spacing: 0.08em; text-transform: uppercase; opacity: 0; transition: opacity .4s; white-space: nowrap; }
.raw-line .tok.hl .ftag { opacity: .9; }
.parse-note { font-family: var(--f-mono); font-size: 13px; color: var(--ink-mute); display: flex; align-items: center; gap: 10px; opacity: 0; transition: opacity .5s; }
.parse-note.show { opacity: 1; }
.parse-arrow { color: var(--cyan); }

/* scene 2 — dictionary encoding */
.sc-dict { display: grid; grid-template-columns: 1fr auto 1.1fr auto 1fr; gap: clamp(10px,2vw,26px); align-items: center; width: 100%; }
@media (max-width: 820px){ .sc-dict { grid-template-columns: 1fr; gap: 18px; } .sc-dict .flowarrow { transform: rotate(90deg); justify-self: center; } }
.dict-word { display: flex; gap: 5px; justify-content: center; flex-wrap: wrap; }
.dict-word .ch {
  font-family: var(--f-mono); font-size: clamp(18px,2.6vw,30px); font-weight: 600;
  color: var(--ink); padding: 6px 9px; border-radius: 8px; background: var(--panel-2); border: 1px solid var(--line);
  transition: all .5s; 
}
.dict-word .ch.fly { transform: translateY(-8px) scale(.7); opacity: 0; }
.col-cap { font-family: var(--f-mono); font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-mute); text-align: center; margin-bottom: 12px; }
.dict-table { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--panel-2); }
.dict-table .drow { display: flex; justify-content: space-between; gap: 18px; padding: 8px 14px; font-family: var(--f-mono); font-size: 13px; color: var(--ink-soft); border-bottom: 1px solid var(--line); transition: background .35s, color .35s; }
.dict-table .drow:last-child { border-bottom: none; }
.dict-table .drow .code { color: var(--ink-mute); }
.dict-table .drow.scan { background: rgba(47,224,224,0.12); color: var(--cyan); }
.dict-table .drow.hit { background: rgba(70,227,154,0.14); color: var(--green); }
.dict-table .drow.hit .code { color: var(--green); font-weight: 600; }
.flowarrow { font-family: var(--f-mono); color: var(--cyan); font-size: 22px; text-align: center; }
.code-out { display: flex; flex-direction: column; align-items: center; gap: 14px; }
.code-num { font-family: var(--f-mono); font-size: clamp(34px,5vw,52px); font-weight: 600; color: var(--green); opacity: 0; transform: scale(.6); transition: all .5s; }
.code-num.show { opacity: 1; transform: none; }
.code-bits { --bs: clamp(20px,3.4vw,30px); }

/* scene 3 — columnar store */
.sc-cols { display: flex; gap: clamp(12px,3vw,40px); align-items: flex-end; justify-content: center; width: 100%; }
.col-stack { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.col-stack .cells { display: flex; flex-direction: column; gap: 3px; padding: 6px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel-2); }
.col-stack .cell { width: clamp(54px,8vw,78px); height: 26px; border-radius: 5px; background: rgba(120,150,200,0.08); display: grid; place-items: center; font-family: var(--f-mono); font-size: 12px; color: var(--ink-soft); transition: all .4s; opacity: .35; }
.col-stack .cell.fill { opacity: 1; background: color-mix(in oklab, var(--cc) 18%, transparent); color: var(--ink); }
.col-stack .cell.target { background: var(--cc); color: #04121f; font-weight: 600; box-shadow: 0 0 12px var(--cc); transform: scale(1.06); }
.col-stack .cname { font-family: var(--f-mono); font-size: 11px; color: var(--ink-mute); }
.col-stack .ctype { font-family: var(--f-mono); font-size: 10px; color: var(--ink-mute); opacity: .7; }
.col-implicit { align-self: center; text-align: center; font-family: var(--f-mono); font-size: 12px; color: var(--purple); border: 1px dashed var(--purple); border-radius: 10px; padding: 14px 16px; max-width: 150px; }

/* scene 4 — bitmap construction (matrix) */
.sc-matrix { display: flex; flex-direction: column; gap: 14px; width: 100%; align-items: center; }
.matrix-wrap { display: grid; grid-template-columns: auto 1fr; gap: 10px 12px; align-items: center; }
.matrix-rowlabel { font-family: var(--f-mono); font-size: 12px; color: var(--ink-soft); text-align: right; white-space: nowrap; transition: color .3s; }
.matrix-rowlabel.hot { color: var(--green); font-weight: 600; }
.matrix-bits { display: flex; gap: 3px; }
.matrix-head { font-family: var(--f-mono); font-size: 10px; color: var(--ink-mute); display: flex; gap: 12px; justify-content: center; }
.matrix-cursor { font-family: var(--f-mono); font-size: 12px; color: var(--cyan); height: 16px; transition: opacity .3s; }

/* scene 5 — AND / AND-NOT */
.sc-and { display: flex; flex-direction: column; gap: 16px; width: 100%; align-items: center; }
.and-row { display: grid; grid-template-columns: 210px 1fr; gap: 14px; align-items: center; width: 100%; max-width: 760px; }
.and-row .rl { font-family: var(--f-mono); font-size: 13px; color: var(--ink-soft); }
.and-row .rl .op { color: var(--ink-mute); font-size: 11px; display: block; }
.and-bits { display: flex; gap: 4px; flex-wrap: wrap; }
.and-op-sym { font-family: var(--f-mono); font-size: 15px; color: var(--cyan); text-align: center; padding: 2px 0; letter-spacing: 0.1em; }
.and-divider { width: 100%; max-width: 760px; height: 1px; background: var(--line-2); }
.and-row.result .rl { color: var(--green); font-weight: 600; }

/* scene 6 — decode output */
.sc-decode { display: grid; grid-template-columns: auto 1fr; gap: clamp(16px,4vw,46px); align-items: center; width: 100%; }
@media (max-width: 760px){ .sc-decode { grid-template-columns: 1fr; } }
.decode-bits { display: flex; flex-direction: column; gap: 4px; }
.decode-bits .drowi { display: flex; align-items: center; gap: 10px; font-family: var(--f-mono); font-size: 12px; color: var(--ink-mute); }
.decode-out { display: flex; flex-direction: column; gap: 8px; }
.out-rec {
  font-family: var(--f-mono); font-size: clamp(12px,1.6vw,14px); color: var(--ink);
  padding: 10px 14px; border-radius: 9px; border: 1px solid var(--line);
  background: var(--panel-2);
  opacity: 0; transform: translateX(18px);
  transition: opacity .45s, transform .45s;
  display: flex; gap: 10px; align-items: baseline;
}
.out-rec.show { opacity: 1; transform: none; }
.out-rec .oid { color: var(--green); }
.out-rec .ot { color: var(--cyan); }
.out-rec .oa { color: var(--blue); }
.out-rec .oc { color: var(--ink-soft); }
.decode-count { font-family: var(--f-mono); font-size: 13px; color: var(--ink-soft); margin-top: 6px; }
.decode-count b { color: var(--green); }

@media (prefers-reduced-motion: reduce){
  .jn-scene { transition: opacity .2s; transform: none; }
}

/* ============================================================
   v2 — scrubbed engine additions
   ============================================================ */

/* fixed top progress bar (only over journey) */
.jn-topbar { position: fixed; top: 0; left: 0; height: 3px; width: 0; z-index: 60; background: linear-gradient(90deg, var(--blue), var(--cyan), var(--green)); box-shadow: 0 0 12px var(--cyan-g); opacity: 0; transition: opacity .4s; pointer-events: none; }
.jn-topbar.show { opacity: 1; }

/* generic 16x16 bitmap grid */
.grid16 { --c16: clamp(9px, 1.9vw, 16px); display: grid; grid-template-columns: repeat(16, var(--c16)); grid-auto-rows: var(--c16); gap: 2px; }
.grid16 .b { width: var(--c16); height: var(--c16); border-radius: 2px; background: rgba(120,150,200,0.08); transition: background .22s ease, box-shadow .22s ease, opacity .22s ease, transform .22s ease; }
.grid16 .b.on { background: var(--bc, var(--cyan)); box-shadow: 0 0 6px var(--bc, var(--cyan)); }
.grid16 .b.hot { box-shadow: 0 0 12px 2px var(--bc, var(--cyan)); transform: scale(1.18); z-index: 2; }
.grid16 .b.tomb { background: var(--purple) !important; box-shadow: 0 0 9px var(--purple-g) !important; }
.grid16-cap { font-family: var(--f-mono); font-size: 11px; color: var(--ink-mute); text-align: center; margin-bottom: 9px; letter-spacing: 0.04em; transition: color .3s; }
.grid16-frame { padding: 8px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel-2); }

/* scene: index (single 16x16) */
.sc-index { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.sc-index .idx-cursor { font-family: var(--f-mono); font-size: 12.5px; color: var(--cyan); height: 18px; text-align: center; }

/* scene: query — overlay stack of three 16x16 grids */
.sc-q { display: flex; flex-direction: column; align-items: center; gap: 16px; width: 100%; }
.q-stage { position: relative; margin: 0 auto; }
.q-layer { position: absolute; top: 0; left: 50%; will-change: transform, opacity; }
.q-layer .grid16-cap { white-space: nowrap; }
.q-foot { font-family: var(--f-mono); font-size: 13.5px; color: var(--ink-soft); text-align: center; min-height: 20px; }
.q-foot b { color: var(--green); }
.q-foot .opname { color: var(--cyan); }

/* scene: parse scanline */
.sc-parse { position: relative; }
.scanline { position: absolute; top: 0; bottom: 0; width: 2px; background: linear-gradient(to bottom, transparent, var(--cyan), transparent); box-shadow: 0 0 14px 2px var(--cyan-g); opacity: 0; transition: opacity .3s; pointer-events: none; }
.scanline.show { opacity: .9; }

/* scene: decode (16x16 result -> records) */
.sc-decode2 { display: grid; grid-template-columns: auto 1fr; gap: clamp(18px,4vw,48px); align-items: center; width: 100%; }
@media (max-width: 760px){ .sc-decode2 { grid-template-columns: 1fr; justify-items: center; } }
