/* ==========================================================================
   Rules Studio · 4 — From policy idea to live decision
   "Time race": both paths on one shared time axis (30 units), like a Gantt
   chart:
       Time →
       The usual way
       [Policy idea][Ticket to IT][╱╱╱ Waiting in the queue ╱╱╱][Built by a developer][Live] ● Effect seen only now
       With Decision Rules Studio                              ┊
       [Policy idea][Draft][● Tested: effect seen first][Live ✓]┊
   Steps sit on a 30-column grid placed by --a / --b (the same lines on
   both tracks), so lengths compare honestly. The guide marks where the
   Studio path is live: the usual way has only just left the queue.
   Arrival (js/rules/race.js adds .is-go once): both tracks build at the
   same pace, each step snapping in as time reaches it; the effect dots
   and the guide land on cue; the queue's stripes drift slowly. On phones time runs down, the tracks side by
   side. Prefixed .rv- and scoped to .rv.
   ========================================================================== */

.rv {
  --rv-frame: #FFFFFF;
  --rv-dur: 3s;
  --rv-seg: 44px;
  position: relative;
  padding: clamp(72px, 9vw, 120px) var(--page-px);
  background: var(--surface-raised);
  border-top: 1px solid var(--border);
}
:root[data-theme="dark"] .rv { --rv-frame: #0B1F42; }

.rv-inner { max-width: var(--container); margin: 0 auto; }
.rv-head { display: flex; flex-direction: column; gap: 14px; margin-bottom: clamp(36px, 4.5vw, 56px); }
.rv-title { max-width: 820px; font-size: var(--fs-section-title); font-weight: 600; line-height: 1.12; letter-spacing: -0.03em; text-wrap: balance; }
.rv-title em { font-style: normal; color: var(--accent); }
.rv-sub { max-width: 680px; font-size: var(--fs-section-sub); line-height: 1.6; color: var(--text-secondary); }

/* ─── The chart ───────────────────────────────────────────────────────── */
.rv-frame {
  padding: clamp(20px, 2.6vw, 32px) clamp(16px, 2.6vw, 32px) clamp(24px, 3vw, 36px);
  background: var(--rv-frame);
  border: 1px solid var(--border);
  border-radius: 14px;
}
.rv-axis {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 14px;
  padding-bottom: 10px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}
.rv-axis .ti { font-size: 14px; }

.rv-stage { position: relative; }
.rv-plot {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 26px;
}
.rv-lane-t { margin-bottom: 10px; font-family: var(--font-display); font-size: 15px; font-weight: 600; letter-spacing: -0.01em; color: var(--text-primary); }
.rv-lane--studio .rv-lane-t { color: var(--accent-text); }

.rv-track {
  display: grid;
  grid-template-columns: repeat(30, minmax(0, 1fr));
  margin: 0; padding: 0;
  list-style: none;
  /* faint time gridlines, every 2 units, behind the steps only */
  background-image: linear-gradient(90deg, var(--border) 1px, transparent 1px);
  background-size: calc(100% / 15) 100%;
}
.rv-seg {
  grid-column: var(--a) / var(--b);
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
  height: var(--rv-seg);
  margin-right: 4px;
  padding: 0 12px;
  font-size: 13.5px;
  font-weight: 500;
  line-height: 1.25;
  color: var(--text-secondary);
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.rv-seg span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rv-seg .ti { flex: none; font-size: 16px; }

/* the usual way: the queue is the long hatched stretch; the effect arrives last */
.rv-seg--wait {
  color: var(--warn);
  /* a seamless 17px tile (two stripes), so the drift loops without a jump */
  background:
    linear-gradient(135deg, var(--warn-soft) 25%, transparent 25% 50%, var(--warn-soft) 50% 75%, transparent 75%) 0 0 / 17px 17px,
    var(--rv-frame);
  border: 1px dashed color-mix(in srgb, var(--warn) 50%, transparent);
}
.rv-seg--late { color: var(--warn); background: transparent; border-color: transparent; padding-left: 8px; }
.rv-dot { flex: none; width: 9px; height: 9px; border-radius: 50%; background: currentColor; box-shadow: 0 0 0 4px color-mix(in srgb, currentColor 18%, transparent); }

/* Studio: blue steps, the effect seen at Tested, then Live */
.rv-lane--studio .rv-seg { color: var(--accent-text); background: var(--accent-soft); border-color: var(--accent-line); }
.rv-lane--studio .rv-seg--tested { color: var(--good); background: var(--good-soft); border-color: color-mix(in srgb, var(--good) 35%, transparent); }
.rv-lane--studio .rv-seg--golive { color: #FFFFFF; background: var(--accent); border-color: transparent; font-weight: 600; }
:root[data-theme="dark"] .rv-lane--studio .rv-seg--golive { color: #0B1F42; }

/* where Studio is live: the usual way has only just left the queue */
.rv-guide {
  position: absolute;
  top: -6px; bottom: -10px;
  left: calc(100% * 16 / 30 - 2px);
  border-left: 1.5px dashed var(--accent);
  pointer-events: none;
}

/* ─── Arrival: crisp, step by step ───────────────────────────────────────
   Both tracks build at the same pace of time: each step snaps in when
   time reaches its start (--a), a fast scale from its left edge, then its
   label; the effect dots and Studio's check pop with a ring; the guide
   draws down when Studio goes live. The queue's stripes keep drifting,
   slowly: it is still waiting. */
.rv { --rv-ease: cubic-bezier(0.2, 0.9, 0.1, 1); }
html.has-js .rv-plot:not(.is-go) .rv-seg,
html.has-js .rv-plot:not(.is-go) .rv-guide { opacity: 0; }
.rv-seg { transform-origin: left center; }
.rv-plot.is-go .rv-seg {
  animation: rv-snap 0.34s var(--rv-ease) calc(var(--rv-dur) * (var(--a) - 1) / 30) both;
}
.rv-plot.is-go .rv-seg > * {
  animation: rv-label 0.22s ease-out calc(var(--rv-dur) * (var(--a) - 1) / 30 + 0.12s) both;
}
@keyframes rv-snap  { 0% { opacity: 0; transform: scaleX(0.35); } 60% { opacity: 1; } 100% { opacity: 1; transform: none; } }
@keyframes rv-label { from { opacity: 0; transform: translateX(-4px); } to { opacity: 1; transform: none; } }

/* the queue: its stripes drift, slowly and for good */
.rv-plot.is-go .rv-seg--wait {
  animation:
    rv-snap 0.34s var(--rv-ease) calc(var(--rv-dur) * 8 / 30) both,
    rv-crawl 1s linear calc(var(--rv-dur) * 8 / 30) infinite;
}
@keyframes rv-crawl { from { background-position: 0 0, 0 0; } to { background-position: 17px 0, 0 0; } }

/* the moments that matter pop, with a ring */
.rv-plot.is-go .rv-seg--tested .rv-dot { animation: rv-pop 0.45s var(--rv-ease) calc(var(--rv-dur) * 7 / 30 + 0.2s) both; }
.rv-plot.is-go .rv-seg--golive .ti     { animation: rv-pop-i 0.45s var(--rv-ease) calc(var(--rv-dur) * 13 / 30 + 0.2s) both; }
.rv-plot.is-go .rv-seg--late .rv-dot   { animation: rv-pop 0.45s var(--rv-ease) calc(var(--rv-dur) * 25 / 30 + 0.2s) both; }
@keyframes rv-pop {
  0%   { opacity: 0; transform: scale(0.2); }
  55%  { opacity: 1; transform: scale(1.25); box-shadow: 0 0 0 7px color-mix(in srgb, currentColor 22%, transparent); }
  100% { opacity: 1; transform: none; }
}
@keyframes rv-pop-i { 0% { opacity: 0; transform: scale(0.2) rotate(-20deg); } 55% { opacity: 1; transform: scale(1.3); } 100% { opacity: 1; transform: none; } }
.rv-guide { transform-origin: top; }
.rv-plot.is-go .rv-guide { animation: rv-draw 0.3s var(--rv-ease) calc(var(--rv-dur) * 16 / 30) both; }
@keyframes rv-draw { from { opacity: 1; transform: scaleY(0); } to { opacity: 1; transform: none; } }

/* ─── Phones: time runs down, the tracks side by side ─────────────────── */
@media (max-width: 760px) {
  .rv { --rv-unit: 22px; }
  .rv-axis .ti { transform: rotate(90deg); }
  .rv-plot { flex-direction: row; gap: 12px; }
  .rv-lane { flex: 1; min-width: 0; }
  .rv-lane-t { min-height: 36px; margin-bottom: 10px; font-size: 13.5px; line-height: 1.3; }  /* two lines, so both tracks start level */
  .rv-track { grid-template-columns: minmax(0, 1fr); grid-template-rows: repeat(30, var(--rv-unit)); background-image: linear-gradient(180deg, var(--border) 1px, transparent 1px); background-size: 100% calc(var(--rv-unit) * 2); }
  .rv-seg { grid-column: 1; grid-row: var(--a) / var(--b); height: auto; margin: 0 0 3px; padding: 6px 10px; align-items: flex-start; font-size: 13px; }
  .rv-seg span { white-space: normal; }
  .rv-guide { top: calc(46px + var(--rv-unit) * 16 - 2px); bottom: auto; left: -4px; right: -4px; border-left: 0; border-top: 1.5px dashed var(--accent); }
  .rv-seg { transform-origin: center top; }
  @keyframes rv-snap { 0% { opacity: 0; transform: scaleY(0.35); } 60% { opacity: 1; } 100% { opacity: 1; transform: none; } }
}

@media (prefers-reduced-motion: reduce) {
  .rv-plot.is-go .rv-seg, .rv-plot.is-go .rv-seg > *,
  .rv-plot.is-go .rv-dot, .rv-plot.is-go .rv-seg--golive .ti, .rv-plot.is-go .rv-guide { animation: none; }
}
