/* ==========================================================================
   Rules Studio · 6 — Use it your way
   "Product vignettes": each card's well is a cropped scene of real UI, in
   the language of sections 2 and 3 (hairline windows, mono values, the
   green answer chip, Studio's tree mark), and hovering a card plays out
   the sentence under it once. At rest every scene is resolved.
       Inside Finflow   ┌ ◈ Loan application ┐  ┌ Offline ┐
                        │ Risk rating  Low ⌥ │  │ Low ⌥   │   ← both resolve
       On top of …      ┌ ••• Your loan system ┐ ═══ [⌥ Studio]
                        │ Decision  [Approve]  │ ←─         ← asks, answer lands
       Beyond lending   [Any system]  Insurance claim 1,800   [Fast-track]
                        [Any process] Supplier invoice …       [Flag]
                        [Any team]    Leave request 2 days     [Approve]
   A resolving value (.rw-res) holds a pending mark (skeleton or caret)
   and its outcome; on hover the pending mark shows until --d, then the
   outcome pops in. Prefixed .rw- and scoped to .rw.
   ========================================================================== */

.rw {
  --rw-frame: #FFFFFF;
  --rw-dot:   rgba(10,47,107,0.13);
  --rw-pop:   cubic-bezier(0.34, 1.56, 0.64, 1);
  position: relative;
  padding: clamp(72px, 9vw, 120px) var(--page-px);
  background: var(--surface);
}
:root[data-theme="dark"] .rw { --rw-frame: #0B1F42; --rw-dot: rgba(147,190,240,0.12); }

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

.rw-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; margin: 0; padding: 0; list-style: none; }
.rw-card {
  display: flex;
  flex-direction: column;
  padding: 10px 10px 24px;
  background: var(--rw-frame);
  border: 1px solid var(--border);
  border-radius: 16px;
}
.has-js .rw-card.anim-el { transition: opacity 0.65s var(--ease-out), transform 0.65s var(--ease-out), border-color 0.25s ease-out; }
.rw-card:hover { border-color: var(--border-strong); }
.rw-card-t { margin: 20px 12px 0; font-family: var(--font-display); font-size: 18px; font-weight: 600; letter-spacing: -0.02em; color: var(--text-primary); }
.rw-card-p { margin: 8px 12px 0; font-size: 14px; line-height: 1.6; color: var(--text-secondary); }

/* ─── The well: a quiet stage with a soft dot grid ────────────────────── */
.rw-well {
  position: relative;
  isolation: isolate;
  height: 212px;
  background: color-mix(in srgb, var(--surface-raised) 60%, var(--rw-frame));
  border-radius: 10px;
  overflow: hidden;
}
.rw-well::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: -1;
  background-image: radial-gradient(circle, var(--rw-dot) 0.9px, transparent 1.3px);
  background-size: 14px 14px;
  background-position: 7px 7px;
  -webkit-mask-image: radial-gradient(ellipse 80% 75% at 50% 50%, #000 30%, transparent 90%);
          mask-image: radial-gradient(ellipse 80% 75% at 50% 50%, #000 30%, transparent 90%);
}

/* ─── Shared mini UI ──────────────────────────────────────────────────── */
.rw-win {
  position: absolute;
  background: var(--rw-frame);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  box-shadow: 0 14px 28px -20px rgba(10,47,107,0.35);
  overflow: hidden;
}
.rw-bar { display: flex; align-items: center; gap: 7px; height: 28px; padding: 0 11px; border-bottom: 1px solid var(--border); }
.rw-bar b { font-size: 11.5px; font-weight: 600; color: var(--text-primary); white-space: nowrap; }
.rw-bar img { display: block; }
.rw-rows { margin: 0; padding: 4px 0; }
.rw-rows > div { display: flex; align-items: center; justify-content: space-between; gap: 10px; height: 28px; padding: 0 11px; }
.rw-rows dt { font-size: 11.5px; color: var(--text-muted); white-space: nowrap; }
.rw-rows dd { display: flex; align-items: center; gap: 6px; margin: 0; font-size: 11.5px; font-weight: 500; color: var(--text-primary); white-space: nowrap; }
.rw-rows > .is-hot { background: color-mix(in srgb, var(--accent) 5%, transparent); }
.rw-mono { font-family: var(--font-mono); font-size: 11px !important; }

/* Studio's mark, wherever it decided something */
.rw-badge { display: grid; place-items: center; width: 18px; height: 18px; color: var(--accent); background: var(--accent-soft); border-radius: 5px; }
.rw-badge .ti { font-size: 12px; }

/* a resolving value: pending mark, then the outcome */
.rw-res { position: relative; display: inline-grid; align-items: center; justify-items: start; }
.rw-res > * { grid-area: 1 / 1; }
.rw-out { padding: 2px 7px; font-size: 11px; font-weight: 600; color: var(--good); background: var(--good-soft); border-radius: 5px; white-space: nowrap; }
.rw-pend { width: 34px; height: 9px; border-radius: 3px; opacity: 0; background: linear-gradient(90deg, var(--border) 25%, var(--border-strong) 50%, var(--border) 75%) 0 0 / 200% 100%; }
.rw-res--caret .rw-pend { width: 1.5px; height: 12px; margin-left: 2px; background: var(--accent); border-radius: 1px; }

/* ─── 1 · Inside Finflow ──────────────────────────────────────────────── */
.rw-win--ff { top: 20px; left: 16px; width: calc(100% - 132px); max-width: 220px; }
.rw-phone {
  position: absolute;
  top: 46px; right: 16px;
  width: 104px; height: 200px;
  padding: 8px 7px;
  background: var(--rw-frame);
  border: 1px solid var(--border-strong);
  border-radius: 18px;
  box-shadow: 0 18px 30px -18px rgba(10,47,107,0.45);
}
.rw-phone-top { display: flex; justify-content: center; margin-bottom: 8px; }
.rw-offline { display: inline-flex; align-items: center; gap: 3px; padding: 2px 6px; font-size: 9.5px; font-weight: 600; color: var(--text-secondary); background: var(--surface-raised); border-radius: 99px; }
.rw-offline .ti { font-size: 10px; }
.rw-phone-card { display: grid; gap: 4px; padding: 7px; background: color-mix(in srgb, var(--accent) 5%, var(--rw-frame)); border: 1px solid var(--border); border-radius: 8px; }
.rw-phone-card small { font-size: 9.5px; color: var(--text-muted); }
.rw-phone-val { display: flex; align-items: center; gap: 4px; }
.rw-phone-val .rw-out { font-size: 10px; padding: 1px 6px; }
.rw-phone-val .rw-badge { width: 15px; height: 15px; }
.rw-phone-val .rw-badge .ti { font-size: 10px; }
.rw-phone-line { height: 6px; margin: 9px 3px 0; background: var(--border); border-radius: 3px; }
.rw-phone-line--s { width: 60%; margin-top: 6px; }

/* ─── 2 · On top of your current system ───────────────────────────────── */
/* deliberately plain: a foreign system, not ours */
.rw-win--legacy { top: 34px; left: 16px; width: calc(100% - 137px); border-radius: 6px; box-shadow: none; }
.rw-win--legacy .rw-bar { background: var(--surface-raised); }
.rw-win--legacy .rw-bar b { font-family: var(--font-mono); font-weight: 500; font-size: 11px; color: var(--text-secondary); }
.rw-dots { display: flex; gap: 3px; }
.rw-dots i { width: 6px; height: 6px; border-radius: 50%; }
.rw-dots i:nth-child(1) { background: #FF5F57; }
.rw-dots i:nth-child(2) { background: #FEBC2E; }
.rw-dots i:nth-child(3) { background: #28C840; }
.rw-win--legacy dt { font-family: var(--font-mono); font-size: 10.5px; }
.rw-field { width: 76px; height: 24px; padding: 0; border: 1px solid var(--border-strong); border-radius: 4px; background: var(--rw-frame); overflow: hidden; }
/* the answer fills the field edge to edge, as an entered value would */
.rw-field .rw-res { width: 100%; height: 100%; }
.rw-field .rw-out { display: grid; place-items: center; width: 100%; height: 100%; padding: 0; font-size: 10.5px; border-radius: 0; }
.rw-field .rw-pend { margin-left: 6px; }
/* its Decision row's centre sits at 34 + 28 + 4 + 2 × 28 + 14 = 136px: the wire and
   Studio line up with it; the window ends where the wire starts (Studio ≈ 81px
   wide, 16px in, so the wire spans the last 97–121px of the well) */
.rw-wire { position: absolute; top: 128px; right: 97px; width: 24px; height: 16px; }
.rw-wire::before, .rw-wire::after { content: ''; position: absolute; left: 0; right: 0; border-top: 1.5px dashed var(--border-strong); }
.rw-wire::before { top: 3px; }
.rw-wire::after { bottom: 3px; }
.rw-tok { position: absolute; width: 7px; height: 7px; margin-left: -3.5px; border-radius: 50%; opacity: 0; }
.rw-tok--ask { top: 0.5px; left: 0; background: var(--accent); }
.rw-tok--ans { bottom: 0.5px; left: 100%; background: var(--good); }
.rw-studio {
  position: absolute;
  top: 119px; right: 16px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 34px;
  padding: 0 11px;
  font-size: 12.5px;
  font-weight: 600;
  color: #FFFFFF;
  background: var(--accent);
  border-radius: 9px;
  box-shadow: 0 8px 18px -10px color-mix(in srgb, var(--accent) 70%, transparent);
}
.rw-studio .ti { font-size: 15px; }
:root[data-theme="dark"] .rw-studio { color: #0B1F42; }

/* ─── 3 · Beyond lending ──────────────────────────────────────────────── */
.rw-recs { position: absolute; inset: 0; display: flex; flex-direction: column; justify-content: center; gap: 8px; margin: 0; padding: 0 14px; list-style: none; }
.rw-recs li {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  height: 42px;
  padding: 0 10px;
  background: var(--rw-frame);
  border: 1px solid var(--border-strong);
  border-radius: 9px;
  box-shadow: 0 10px 20px -18px rgba(10,47,107,0.35);
}
.rw-recs li:nth-child(2) { margin-left: 10px; margin-right: -4px; }
.rw-tag { padding: 2px 6px; font-size: 10px; font-weight: 600; color: var(--text-secondary); white-space: nowrap; border: 1px dashed var(--border-strong); border-radius: 5px; }
.rw-rec { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 11.5px; font-weight: 500; color: var(--text-primary); }
.rw-rec em { margin-left: 4px; font-style: normal; font-family: var(--font-mono); font-size: 10.5px; color: var(--text-muted); }
.rw-res--chip { justify-items: end; }
.rw-res--chip .rw-out::before { content: '\f5d3'; margin-right: 4px; font-family: 'tabler-icons'; font-weight: normal; font-size: 11px; vertical-align: -1px; }
.rw-res--warn .rw-out { color: var(--warn); background: var(--warn-soft); }

/* ─── Hover: the sentence plays out once ──────────────────────────────── */
.rw-card:is(:hover, :focus-within) .rw-pend { animation: rw-wait var(--d) linear both, rw-shimmer 0.9s linear infinite; }
.rw-card:is(:hover, :focus-within) .rw-res--caret .rw-pend { animation: rw-wait var(--d) linear both, rw-blink 0.6s steps(1) infinite; }
.rw-card:is(:hover, :focus-within) .rw-out { animation: rw-land 0.4s var(--rw-pop) var(--d) both; }
.rw-card:is(:hover, :focus-within) .rw-badge { animation: rw-mark 0.5s ease-out var(--d); }
.rw-card:is(:hover, :focus-within) .rw-tok--ask { animation: rw-ask 0.4s cubic-bezier(0.45, 0, 0.25, 1) 0.2s both; }
.rw-card:is(:hover, :focus-within) .rw-studio { animation: rw-tick 0.3s ease-out 0.58s; }
.rw-card:is(:hover, :focus-within) .rw-tok--ans { animation: rw-ans 0.32s cubic-bezier(0.45, 0, 0.25, 1) 0.72s both; }

@keyframes rw-wait    { 0%, 99% { opacity: 1; } 100% { opacity: 0; } }
@keyframes rw-shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }
@keyframes rw-blink   { 50% { visibility: hidden; } }
@keyframes rw-land    { from { opacity: 0; transform: scale(0.7); } }
@keyframes rw-mark    { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 45%, transparent); } 100% { box-shadow: 0 0 0 6px transparent; } }
@keyframes rw-ask     { 0% { left: 0; opacity: 0; } 20%, 80% { opacity: 1; } 100% { left: 100%; opacity: 0; } }
@keyframes rw-ans     { 0% { left: 100%; opacity: 0; } 20%, 80% { opacity: 1; } 100% { left: 0; opacity: 0; } }
@keyframes rw-tick    { 50% { transform: scale(1.06); } }

@media (max-width: 960px) {
  .rw-grid { grid-template-columns: minmax(0, 1fr); max-width: 560px; }
}
@media (max-width: 420px) {
  .rw-rec em { display: none; }   /* keep the record's name whole on phones */
  .rw-recs li:nth-child(2) { margin-left: 6px; margin-right: -2px; }
}
@media (prefers-reduced-motion: reduce) {
  .rw-card:is(:hover, :focus-within) * { animation: none !important; }
}
