/* Interactive story figures: live 3D stages with a step bar, in-stage labels and controls. */
[hidden] { display: none !important; }
.story .section-head .kicker { display: block; margin-bottom: 6px; color: var(--accent); font-weight: 700; font-size: 0.85rem; letter-spacing: 0.04em; }

.story-bottom { position: absolute; left: 0; right: 0; bottom: 0; z-index: 3; }
.story-synopsis {
  padding: 10px 16px; border-top: 1px solid var(--line); background: #fff;
  color: var(--text); font-size: 0.92rem; line-height: 1.4; text-align: center;
}
.story-synopsis:empty { display: none; }
.steps { display: flex; height: 40px; border-top: 1px solid var(--line); background: #fff; }
.steps-track { display: flex; flex: 1; min-width: 0; cursor: ew-resize; touch-action: none; user-select: none; }
.steps .step {
  position: relative; display: grid; place-items: center; flex: 1; min-width: 0; padding: 0 8px; overflow: hidden;
  color: var(--muted); font-size: 0.88rem; font-weight: 600; white-space: nowrap;
}
.steps .step + .step { border-left: 1px solid var(--line); }
.steps .step i {
  position: absolute; inset: 0; border-bottom: 4px solid var(--accent); background: var(--accent-soft);
  transform: scaleX(0); transform-origin: left; pointer-events: none;
}
.steps .step span { position: relative; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.steps .step[aria-current="true"] { color: var(--text); }
.steps-play { position: relative; flex: none; width: 44px; border: 0; border-right: 1px solid var(--line); background: none; cursor: pointer; }
.steps-play::before, .steps-play::after { content: ""; position: absolute; top: 13px; width: 4px; height: 14px; background: var(--text); border-radius: 1px; }
.steps-play::before { left: 15px; } .steps-play::after { left: 23px; }
.steps-play.paused::before { left: 17px; width: 0; height: 0; background: none; border-left: 12px solid var(--text); border-top: 7px solid transparent; border-bottom: 7px solid transparent; border-radius: 0; }
.steps-play.paused::after { display: none; }
.has-steps .story-legend, .has-steps .story-hint { bottom: calc(var(--bottom-h, 80px) + 10px); }
.has-steps .inset { bottom: calc(var(--bottom-h, 80px) + 10px); }
.story-tag { position: absolute; left: 0; top: 0; z-index: 2; white-space: nowrap; pointer-events: none; }
.story-tag.callout::after { content: ""; position: absolute; left: 50%; top: 100%; width: 1.5px; height: var(--lift); background: var(--text); opacity: 0.6; }
.story-tag.part { padding: 2px 8px; font-size: 0.74rem; font-weight: 600; color: #075b76; }
.story-select {
  pointer-events: auto; max-width: 100%; padding: 5px 30px 5px 12px; border: 1px solid var(--line); border-radius: 999px;
  background: rgba(255, 255, 255, 0.92) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%2316181d' stroke-width='1.5'/%3E%3C/svg%3E") no-repeat right 12px center;
  color: var(--text); font: inherit; font-size: 0.84rem; font-weight: 600; appearance: none; cursor: pointer; backdrop-filter: blur(6px);
}
.story-select:hover { border-color: #c9cfd8; }
.story-select { max-height: 40px; overflow: hidden; transition: width .28s ease, opacity .3s ease, max-height .35s ease, padding .35s ease, border-width .35s ease, margin .35s ease; }
.story-select.gone { opacity: 0; max-height: 0; padding-top: 0; padding-bottom: 0; border-width: 0; margin-bottom: -6px; pointer-events: none; }
.story-picks { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; }
.goal-count { transform-origin: left center; }
.goal-count.pop { animation: goal-pop .55s ease-out; }
@keyframes goal-pop { 0% { transform: scale(1); } 30% { transform: scale(1.16); box-shadow: 0 0 0 3px var(--accent-soft); } 100% { transform: scale(1); } }

.story-stage {
  position: relative; width: 100%; overflow: hidden; border: 1px solid var(--line); border-radius: var(--radius);
  background: radial-gradient(ellipse at 50% 35%, #ffffff 0%, #f7f9fb 70%, #eef2f6 100%);
  touch-action: pan-y; cursor: grab;
}
.story-stage.orbiting { cursor: grabbing; }
.story-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.story-stage.busy .story-canvas { opacity: 0.6; transition: opacity .2s; }
.story-hud { position: absolute; top: 12px; left: 12px; right: 120px; display: flex; flex-wrap: wrap; gap: 8px; pointer-events: none; }
.pill {
  padding: 4px 11px; border-radius: 999px; background: rgba(255, 255, 255, 0.88); border: 1px solid var(--line);
  color: var(--text); font-size: 0.82rem; font-weight: 600; font-variant-numeric: tabular-nums; backdrop-filter: blur(6px);
}
.pill.quiet { color: var(--muted); font-weight: 500; }
.pill.accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.pill.fail { background: #d64545; border-color: #d64545; color: #fff; }
.pill .sw { display: inline-block; width: 9px; height: 9px; margin-right: 6px; border-radius: 50%; vertical-align: 0; }
.story-reset {
  position: absolute; top: 12px; right: 12px; padding: 5px 12px; border: 1px solid var(--line); border-radius: 999px;
  background: rgba(255, 255, 255, 0.9); color: var(--muted); font: inherit; font-size: 0.8rem; cursor: pointer;
}
.story-reset:hover { color: var(--text); }
.story-loading { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-size: 0.9rem; background: #fff; }
.story-loading .spinner {
  display: inline-block; width: 16px; height: 16px; margin-right: 8px; border: 2px solid var(--line);
  border-top-color: var(--accent); border-radius: 50%; animation: story-spin 0.9s linear infinite; vertical-align: -3px;
}
@keyframes story-spin { to { transform: rotate(360deg); } }
.story-caption { min-height: 3.3em; margin: 12px 0 4px; color: var(--muted); font-size: 0.95rem; max-width: var(--narrow); }

.story-under { display: flex; flex-direction: column; gap: 10px; margin-top: 6px; }
.under-row { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.under-label { color: var(--muted); font-size: 0.8rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; }

.combo { display: flex; flex-wrap: wrap; gap: 10px 18px; }
.combo-group { display: inline-flex; align-items: center; gap: 4px; }
.combo-label { margin-right: 4px; color: var(--text); font-size: 0.85rem; font-weight: 600; }
.combo button, .seg button {
  padding: 5px 12px; border: 1px solid var(--line); border-radius: 999px; background: #fff;
  color: var(--muted); font: inherit; font-size: 0.84rem; cursor: pointer;
}
.combo button:hover, .seg button:hover { color: var(--text); border-color: #c9cfd8; }
.combo button[aria-pressed="true"], .seg button[aria-pressed="true"], .seg button[aria-selected="true"] { background: var(--text); border-color: var(--text); color: #fff; }
.seg { display: inline-flex; flex-wrap: wrap; gap: 4px; }
.seg button:disabled { opacity: 0.4; cursor: default; }

.band { position: relative; width: 100%; cursor: ew-resize; user-select: none; touch-action: none; }
.band svg { display: block; width: 100%; height: 100%; overflow: visible; }
.band .axis { stroke: var(--line); stroke-width: 1; }
.band .curve { fill: none; stroke-width: 2; stroke-linejoin: round; }
.band .curve.faint { stroke-width: 1.5; opacity: 0.45; }
.band .ci { opacity: 0.16; stroke: none; }
.band .span rect { fill: var(--bg-soft); stroke: var(--line); }
.band .span.shake rect { fill: #fdf3dc; stroke: #f1d79a; }
.band .span text { fill: var(--muted); font-size: 10.5px; font-weight: 600; }
.band .mark { stroke: #c9cfd8; stroke-dasharray: 3 3; }
.band .mark.event { stroke: #e0a21b; stroke-dasharray: none; }
.band .tick { fill: var(--muted); font-size: 10.5px; font-variant-numeric: tabular-nums; }
.band .head { stroke: var(--text); stroke-width: 1.5; }
.band .knob { fill: #fff; stroke: var(--text); stroke-width: 2; }
.band-tag {
  position: absolute; top: -6px; transform: translateX(-50%); padding: 1px 8px; border-radius: 999px;
  background: var(--text); color: #fff; font-size: 0.74rem; font-weight: 600; white-space: nowrap;
  font-variant-numeric: tabular-nums; pointer-events: none;
}
.band-tag:empty { display: none; }

.legend { display: flex; flex-wrap: wrap; gap: 14px; color: var(--muted); font-size: 0.82rem; }
.legend span::before { content: ""; display: inline-block; width: 10px; height: 10px; margin-right: 6px; border-radius: 50%; background: var(--c); vertical-align: -1px; }

@media (max-width: 760px) {
  .steps .step { padding: 0 4px; font-size: 0.72rem; }
  .story-synopsis { font-size: 0.8rem; padding: 7px 10px; }
  .has-steps .story-hud { bottom: calc(var(--bottom-h, 80px) + 8px); }
  .story-stage { min-height: 360px !important; aspect-ratio: 4 / 5 !important; }
  .story-hud { right: 12px; top: auto; bottom: 12px; }
}
@media (prefers-reduced-motion: reduce) { .story-loading .spinner { animation: none; } }

.ctx-bars { display: inline-flex; align-items: stretch; align-self: stretch; gap: 3px; box-sizing: border-box; padding: 6px 12px; border: 1px solid var(--line); border-radius: 999px; background: rgba(255, 255, 255, 0.92); backdrop-filter: blur(6px); }
.ctx-bar { position: relative; width: 7px; border-radius: 2px; background: var(--bg-soft); overflow: hidden; }
.ctx-bar i { position: absolute; inset: 0; background: #9aa3b2; transform-origin: bottom; transition: transform .5s ease; }
.ctx-label { align-self: center; margin-right: 4px; color: var(--muted); font-size: 0.72rem; font-weight: 600; }

/* Paired refinement viewer */
.refine-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 12px; }
.refine-grid .story-stage.ours { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.refine-grid .story-stage.ended .story-canvas { opacity: 0.55; transition: opacity .4s; }
.refine-grid .story-hud { right: 12px; }
.transport { flex-wrap: nowrap; }
.transport-band { flex: 1; min-width: 0; }
.round-btn { flex: none; width: 36px; height: 36px; border: 1px solid var(--line); border-radius: 50%; background: #fff; cursor: pointer; position: relative; }
.round-btn::before, .round-btn::after { content: ""; position: absolute; top: 11px; width: 4px; height: 14px; background: var(--text); border-radius: 1px; }
.round-btn::before { left: 12px; } .round-btn::after { left: 19px; }
.round-btn.paused::before { left: 13px; width: 0; height: 0; background: none; border-left: 12px solid var(--text); border-top: 7px solid transparent; border-bottom: 7px solid transparent; border-radius: 0; }
.round-btn.paused::after { display: none; }
.band .span.noisy rect { fill: #fbeaea; stroke: #f0c4c4; }
.band .span.ours rect { fill: var(--accent-soft); stroke: #b9e1ef; opacity: 0.7; }
.band .mark.noisy { stroke: #e06a6a; stroke-dasharray: none; }
.band .mark.ours { stroke: var(--accent); stroke-dasharray: none; }
@media (max-width: 760px) {
  .refine-grid { gap: 6px; }
  .refine-grid .story-stage { min-height: 280px !important; aspect-ratio: 3 / 5 !important; }
  .refine-grid .pill { font-size: 0.7rem; padding: 2px 7px; }
  .refine-grid .story-hud { top: 8px; left: 8px; right: 8px; bottom: auto; gap: 4px; }
}

/* Real-world results */
#real-world .real-part { margin-top: 40px; }
#real-world .real-part .subhead { margin: 0 0 8px; }
#real-world .real-part .subhead + .muted { margin-top: 0; margin-bottom: 16px; font-size: 0.95rem; }
.real-view.story-mount:empty { min-height: 0; aspect-ratio: 16 / 9; }
.real-view[data-real="onbody"].story-mount:empty { aspect-ratio: 27 / 16; }
.real-view[data-real="teleop"] { max-width: 820px; margin: 0 auto; }
.real-top { justify-content: center; margin-bottom: 10px; }
.real-cards { display: grid; gap: 14px; }
.real-cards.portrait { grid-template-columns: repeat(3, 1fr); }
.real-cards.pair { grid-template-columns: 1fr 1fr; }
.real-card, .real-solo { margin: 0; }
.real-media { position: relative; overflow: hidden; border-radius: var(--radius); border: 1px solid var(--line); background: #0d0f12; }
.real-card.ours .real-media, .real-media.ours { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent); }
.real-media video { width: 100%; display: block; }
.real-cards.portrait video { aspect-ratio: 9 / 16; object-fit: cover; }
.real-cards.pair video { aspect-ratio: 8 / 9; object-fit: cover; }
.real-solo video { aspect-ratio: 16 / 9; object-fit: cover; }
.real-media .pill { position: absolute; top: 10px; left: 10px; }
.real-solo .pill { top: 14px; left: 14px; padding: 6px 14px; font-size: 0.95rem; }
.real-done { position: absolute; right: 10px; bottom: 10px; padding: 3px 9px; border-radius: 999px; background: rgba(13, 15, 18, 0.75); color: #fff; font-size: 0.75rem; }
.real-transport { margin-top: 10px; flex-wrap: nowrap; }
.real-scrub { flex: 1; min-width: 0; accent-color: var(--text); }
.real-clock { min-width: 84px; color: var(--muted); font-size: 0.85rem; font-variant-numeric: tabular-nums; text-align: right; }
.real-caption { margin: 8px auto 0; max-width: 760px; color: var(--muted); font-size: 0.9rem; text-align: center; }
.real-seq { flex: 1; flex-wrap: nowrap; gap: 6px; }
.real-seq button { position: relative; flex: 1; overflow: hidden; padding: 6px 10px; font-weight: 600; }
.real-seq button span { position: relative; }
.real-seq button i { position: absolute; left: 0; right: 0; bottom: 0; height: 3px; background: var(--accent); transform: scaleX(0); transform-origin: left; }
.real-seq button.ours { border-color: var(--accent); color: var(--accent); }
.real-seq button.ours[aria-selected="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
.real-seq button.ours i { background: #fff; }
#real-world .real-table { margin-top: 14px; }
#real-world .real-table table { font-size: 0.88rem; }
#real-world .real-table caption { margin-bottom: 4px; font-size: 0.9rem; }
#real-world .real-table th, #real-world .real-table td { padding: 4px 8px; }
#real-world .real-table td { white-space: nowrap; }
#real-world .real-table td[rowspan] { white-space: normal; }
.real-tables { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0 20px; }
#real-world .real-part > .note { margin-top: 8px; font-size: 0.85rem; }
@media (max-width: 900px) { .real-tables { grid-template-columns: 1fr; } }
@media (max-width: 760px) {
  .real-cards.portrait, .real-cards.pair { gap: 6px; }
  .real-cards .pill { top: 6px; left: 6px; padding: 2px 7px; font-size: 0.7rem; }
  .real-done { right: 6px; bottom: 6px; font-size: 0.68rem; }
  .real-seq button { padding: 5px 6px; font-size: 0.78rem; }
  .real-clock { display: none; }
  #real-world .real-table table { font-size: 0.78rem; }
  #real-world .real-table th, #real-world .real-table td { padding: 3px 4px; }
}
[data-story] .story-mount:empty { min-height: min(70vw, 820px); border-radius: var(--radius); background: var(--bg-soft); }
.highlight-grid { display: grid; grid-template-columns: repeat(var(--n, 3), 1fr); gap: 14px; }
.highlight { margin: 0; }
.highlight video { width: 100%; border-radius: var(--radius); background: #0d0f12; }
.highlight figcaption { margin-top: 8px; color: var(--muted); font-size: 0.9rem; }
@media (max-width: 760px) { .highlight-grid { grid-template-columns: 1fr; } }
.story-hint {
  position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%); padding: 7px 14px; border-radius: 999px;
  background: var(--text); color: #fff; font-size: 0.85rem; font-weight: 600; white-space: nowrap; pointer-events: none;
  box-shadow: 0 4px 14px rgba(22, 24, 29, 0.18); animation: story-hint 1.6s ease-in-out infinite;
}
@keyframes story-hint { 50% { transform: translateX(-50%) translateY(-3px); } }
@media (prefers-reduced-motion: reduce) { .story-hint { animation: none; } }

.story-legend { position: absolute; left: 12px; bottom: 12px; z-index: 2; display: flex; gap: 12px; padding: 6px 10px; border-radius: 999px; background: rgba(255,255,255,0.86); border: 1px solid var(--line); font-size: 0.78rem; font-weight: 600; color: var(--text); pointer-events: none; }
.story-legend span::before { content: ""; display: inline-block; width: 10px; height: 10px; margin-right: 6px; border-radius: 2px; background: var(--c); vertical-align: -1px; }
.randomize { display: inline-flex; align-items: center; gap: 8px; padding: 7px 14px; border: 1px solid var(--text); border-radius: 999px; background: var(--text); color: #fff; font: inherit; font-size: 0.86rem; font-weight: 600; cursor: pointer; }
.randomize span { font-size: 1.05rem; line-height: 1; }
.randomize:hover { background: var(--accent); border-color: var(--accent); }
.under-note { color: var(--muted); font-size: 0.85rem; }
.inset { position: absolute; right: 12px; bottom: 12px; z-index: 2; width: 330px; padding: 8px 10px 6px; border: 1px solid var(--line); border-radius: 10px; background: rgba(255, 255, 255, 0.92); pointer-events: none; }
.inset-title { font-size: 0.8rem; font-weight: 600; color: var(--text); margin-bottom: 2px; }
.inset svg { display: block; width: 100%; height: auto; overflow: visible; }
.inset .axis { stroke: var(--line); stroke-width: 1; }
.inset .tick { fill: var(--muted); font-size: 11px; }
.inset .curve { fill: none; stroke-width: 2.8; stroke-linejoin: round; stroke-linecap: round; }
.inset .goal { fill: #fff; stroke-width: 1.8; }
.inset .fail { fill: none; stroke-width: 2.6; stroke-linecap: round; }
.inset .curve.dashed { stroke-dasharray: 4 3; stroke-width: 1.5; }
.inset-legend { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 0.76rem; color: var(--muted); }
.inset-legend span::before { content: ""; display: inline-block; width: 9px; height: 9px; margin-right: 4px; border-radius: 50%; background: var(--c); }
.inset-legend .fail-key::before { content: "×"; width: auto; height: auto; background: none; color: var(--muted); font-weight: 700; }
.inset-legend .goal-key::before { background: #fff; border: 1.8px solid var(--muted); box-sizing: border-box; }
@media (max-width: 760px) {
  .inset { width: 150px; right: 8px; padding: 5px 7px 4px; }
  #training .inset { display: none; }
  .inset-title { font-size: 0.66rem; line-height: 1.3; }
  .inset-legend { font-size: 0.6rem; gap: 0 6px; }
}

/* Refinement viewer: shared progress inset and goal counters */
.refine-view { position: relative; }
.refine-view .inset { left: 50%; right: auto; bottom: 14px; width: 330px; transform: translateX(-50%); }
@media (max-width: 760px) {
  .refine-view .inset { position: relative; left: auto; right: auto; bottom: auto; width: auto; max-width: 360px; margin: 8px auto 0; transform: none; }
}
@media (max-width: 760px) {
  .story-legend, .has-steps .story-legend { top: 12px; bottom: auto; left: 12px; max-width: calc(100% - 118px); flex-wrap: wrap; gap: 2px 8px; border-radius: 12px; font-size: 0.7rem; }
  #distillation .story-legend { top: auto; bottom: calc(var(--bottom-h, 80px) + 10px); max-width: calc(100% - 24px); }
  #distillation .story-hud { top: 12px; bottom: auto; right: auto; flex-direction: column; align-items: flex-start; gap: 6px; }
  #distillation .ctx-bars { align-self: flex-start; }
}

/* Hand-to-body morph: the two phase pills share one slot and crossfade. */
.morph-pills { display: grid; justify-items: start; align-items: start; }
@media (max-width: 760px) { .morph-pills .pill { padding: 3px 9px; border-radius: 12px; font-size: 0.7rem; } }
.morph-pills > .pill { grid-area: 1 / 1; }
