/* ==========================================================================
   Product sims — simulated, animated app screenshots for marketing pages.
   A .psim is a window frame; a variant block inside provides the scene.
   Animations run when .is-live is set (marketing/productsims.js adds it via
   IntersectionObserver and removes it when scrolled away, so scenes replay).
   ========================================================================== */

.psim {
  --psim-ink: #111827;
  --psim-muted: #52525e;
  --psim-dim: #8b8b96;
  --psim-border: #e5e7eb;
  --psim-accent: #6663fd;
  position: relative;
  border-radius: 16px;
  overflow: hidden;
  border: 1px solid var(--psim-border);
  background: #fff;
  box-shadow:
    0 24px 60px -28px rgba(16, 17, 20, 0.22),
    0 4px 20px rgba(102, 99, 253, 0.12);
  font-family: "Aspekta", "Inter", sans-serif;
  color: var(--psim-ink);
  text-align: left;
}
.psim__bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 13px;
  background: #1c1c22;
}
.psim__bar i {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}
.psim__bar i:nth-child(1) { background: #ff5f57; }
.psim__bar i:nth-child(2) { background: #febc2e; }
.psim__bar i:nth-child(3) { background: #28c840; }
.psim__bar span {
  margin-left: 8px;
  font-size: 0.72rem;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.66);
}
.psim__body {
  padding: 18px 18px 20px;
  background: #fafafd;
}

/* ---- shared atoms ---- */

.psim-q {
  display: inline-block;
  background: #eeeeee;
  color: var(--psim-ink);
  border-radius: 12px;
  padding: 9px 13px;
  font-size: 0.88rem;
  line-height: 1.45;
  max-width: 92%;
  opacity: 0;
  transform: translateY(6px);
}
.is-live .psim-q {
  animation: psim-up 0.45s ease forwards;
}
.psim-think {
  display: flex;
  gap: 5px;
  margin: 12px 0 0 4px;
  opacity: 0;
}
.is-live .psim-think {
  animation: psim-think-cycle 1.4s ease 0.45s forwards;
}
.psim-think i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: rgba(102, 99, 253, 0.55);
  animation: psim-blink 0.9s ease infinite;
}
.psim-think i:nth-child(2) { animation-delay: 0.15s; }
.psim-think i:nth-child(3) { animation-delay: 0.3s; }
.psim-a {
  margin-top: 12px;
  opacity: 0;
  transform: translateY(8px);
}
.is-live .psim-a {
  animation: psim-up 0.5s ease 1.7s forwards;
}
.psim-a p {
  margin: 0 0 12px;
  font-size: 0.9rem;
  line-height: 1.55;
  color: var(--psim-muted);
}
.psim-a p b, .psim-a p strong {
  color: var(--psim-ink);
  font-weight: 600;
}
.psim-src {
  margin-top: 10px;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.64rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--psim-dim);
}

/* bar chart: <div class="psim-chart"><figure style="--h:92%"><figcaption>West</figcaption></figure>…</div> */
.psim-chart {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  height: 110px;
  padding: 12px 14px 8px;
  background: #fff;
  border: 1px solid var(--psim-border);
  border-radius: 10px;
}
.psim-chart figure {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: stretch;
  gap: 6px;
  height: 100%;
  margin: 0;
}
.psim-chart figure::before {
  content: "";
  display: block;
  height: var(--h, 50%);
  border-radius: 3px 3px 0 0;
  background: linear-gradient(180deg, #8b88ff, #6663fd);
  transform: scaleY(0);
  transform-origin: bottom;
}
.is-live .psim-chart figure::before {
  animation: psim-grow 0.7s cubic-bezier(0.2, 0.7, 0.2, 1) forwards;
}
.is-live .psim-chart figure:nth-child(2)::before { animation-delay: 0.1s; }
.is-live .psim-chart figure:nth-child(3)::before { animation-delay: 0.2s; }
.is-live .psim-chart figure:nth-child(4)::before { animation-delay: 0.3s; }
.is-live .psim-chart figure:nth-child(5)::before { animation-delay: 0.4s; }
.psim--chat .psim-chart { opacity: 0; }
.is-live.psim--chat .psim-chart,
.psim--chat.is-live .psim-chart {
  animation: psim-fade 0.4s ease 2s forwards;
}
.psim--chat .psim-chart figure::before { animation-delay: 2.2s !important; }
.psim-chart figcaption {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.58rem;
  color: var(--psim-dim);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* KPI row: <div class="psim-kpis"><div class="psim-kpi"><small>Label</small><b>$2.04B</b><em>+2.9%</em></div>…</div> */
.psim-kpis {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 12px;
}
.psim-kpi {
  background: #fff;
  border: 1px solid var(--psim-border);
  border-radius: 10px;
  padding: 10px 12px;
  opacity: 0;
  transform: translateY(6px);
}
.is-live .psim-kpi { animation: psim-up 0.45s ease forwards; }
.is-live .psim-kpi:nth-child(2) { animation-delay: 0.12s; }
.is-live .psim-kpi:nth-child(3) { animation-delay: 0.24s; }
.psim-kpi small {
  display: block;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.56rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--psim-dim);
}
.psim-kpi b {
  display: block;
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin-top: 2px;
}
.psim-kpi em {
  font-style: normal;
  font-size: 0.7rem;
  font-weight: 600;
  color: #178a51;
}
.psim-kpi em.is-down { color: #b91c1c; }

/* line chart: <svg class="psim-line" viewBox="0 0 300 90"><path d="…"/></svg> */
.psim-line {
  width: 100%;
  height: auto;
  display: block;
  background: #fff;
  border: 1px solid var(--psim-border);
  border-radius: 10px;
  padding: 8px;
}
.psim-line path {
  fill: none;
  stroke: var(--psim-accent);
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-dasharray: 620;
  stroke-dashoffset: 620;
}
.is-live .psim-line path {
  animation: psim-draw 1.4s ease 0.35s forwards;
}
.psim-line path.psim-line__area {
  fill: rgba(102, 99, 253, 0.08);
  stroke: none;
  opacity: 0;
}
.is-live .psim-line path.psim-line__area {
  animation: psim-fade 0.8s ease 1.3s forwards;
}
.psim-line path.psim-line__dash {
  stroke: rgba(102, 99, 253, 0.45);
  stroke-width: 2;
  stroke-dasharray: 5 7;
  stroke-dashoffset: 0;
  opacity: 0;
}
.is-live .psim-line path.psim-line__dash {
  animation: psim-fade 0.6s ease 1.5s forwards;
}

/* table: <div class="psim-table"><div class="psim-tr psim-tr--head">…</div><div class="psim-tr">…</div></div>
   each .psim-tr contains spans; give the row a badge with <i class="psim-badge is-risk|is-prog|is-done">…</i> */
.psim-table {
  background: #fff;
  border: 1px solid var(--psim-border);
  border-radius: 10px;
  overflow: hidden;
}
.psim-tr {
  display: grid;
  grid-template-columns: 1.4fr 1fr 0.9fr 0.8fr;
  gap: 8px;
  align-items: center;
  padding: 8px 12px;
  font-size: 0.78rem;
  border-top: 1px solid #f1f1f4;
  opacity: 0;
}
.is-live .psim-tr { animation: psim-fade 0.35s ease forwards; }
.is-live .psim-tr:nth-child(2) { animation-delay: 0.1s; }
.is-live .psim-tr:nth-child(3) { animation-delay: 0.2s; }
.is-live .psim-tr:nth-child(4) { animation-delay: 0.3s; }
.is-live .psim-tr:nth-child(5) { animation-delay: 0.4s; }
.is-live .psim-tr:nth-child(6) { animation-delay: 0.5s; }
.is-live .psim-tr:nth-child(7) { animation-delay: 0.6s; }
.psim-tr--head {
  border-top: 0;
  background: #fafafb;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.58rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--psim-dim);
}
.psim-tr span:first-child { font-weight: 500; }
.psim-tr .psim-num {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.72rem;
  color: var(--psim-muted);
}
.psim-badge {
  justify-self: start;
  font-style: normal;
  font-size: 0.62rem;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 20px;
}
.psim-badge.is-risk { background: rgba(217, 106, 106, 0.14); color: #b91c1c; }
.psim-badge.is-prog { background: rgba(224, 148, 47, 0.16); color: #92610c; }
.psim-badge.is-done { background: rgba(63, 178, 127, 0.16); color: #178a51; }

/* workflow graph: <div class="psim-flow"> nodes absolutely placed via --x/--y, edges as svg */
.psim-flow {
  position: relative;
  background: #fff;
  border: 1px solid var(--psim-border);
  border-radius: 10px;
  height: 240px;
  overflow: hidden;
  background-image: radial-gradient(rgba(17, 24, 39, 0.06) 1px, transparent 1px);
  background-size: 16px 16px;
}
.psim-flow svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
.psim-flow svg path {
  fill: none;
  stroke: rgba(102, 99, 253, 0.45);
  stroke-width: 1.75;
  stroke-dasharray: 340;
  stroke-dashoffset: 340;
}
.is-live .psim-flow svg path { animation: psim-draw 0.9s ease forwards; }
.is-live .psim-flow svg path:nth-of-type(2) { animation-delay: 0.35s; }
.is-live .psim-flow svg path:nth-of-type(3) { animation-delay: 0.7s; }
.is-live .psim-flow svg path:nth-of-type(4) { animation-delay: 1.05s; }
.is-live .psim-flow svg path:nth-of-type(5) { animation-delay: 1.4s; }
.psim-node {
  position: absolute;
  left: var(--x);
  top: var(--y);
  min-width: 104px;
  max-width: min(168px, 27%);
  background: #fff;
  border: 1px solid var(--psim-border);
  border-left: 3px solid var(--psim-accent);
  border-radius: 9px;
  padding: 7px 10px;
  font-size: 0.7rem;
  line-height: 1.3;
  box-shadow: 0 4px 12px -6px rgba(16, 17, 20, 0.18);
  opacity: 0;
  transform: scale(0.92);
}
.is-live .psim-node { animation: psim-pop 0.4s cubic-bezier(0.2, 0.9, 0.3, 1.3) forwards; }
.is-live .psim-node:nth-of-type(2) { animation-delay: 0.35s; }
.is-live .psim-node:nth-of-type(3) { animation-delay: 0.7s; }
.is-live .psim-node:nth-of-type(4) { animation-delay: 1.05s; }
.is-live .psim-node:nth-of-type(5) { animation-delay: 1.4s; }
.is-live .psim-node:nth-of-type(6) { animation-delay: 1.75s; }
.psim-node b {
  display: block;
  font-weight: 600;
  font-size: 0.72rem;
}
.psim-node small {
  color: var(--psim-dim);
  font-size: 0.62rem;
}
.psim-node.is-if { border-left-color: #e0942f; }
.psim-node.is-end { border-left-color: #178a51; }

/* notebook: <div class="psim-nb"><pre>…<span class="tok-kw">from</span>…</pre></div> lines revealed in order */
.psim-nb {
  background: #16161d;
  border-radius: 10px;
  padding: 14px 16px;
  overflow: hidden;
}
.psim-nb code {
  display: block;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.72rem;
  line-height: 1.7;
  color: #d6d6df;
  white-space: pre;
  opacity: 0;
  transform: translateX(-4px);
}
.is-live .psim-nb code { animation: psim-code 0.3s ease forwards; }
.is-live .psim-nb code:nth-child(2) { animation-delay: 0.15s; }
.is-live .psim-nb code:nth-child(3) { animation-delay: 0.3s; }
.is-live .psim-nb code:nth-child(4) { animation-delay: 0.45s; }
.is-live .psim-nb code:nth-child(5) { animation-delay: 0.6s; }
.is-live .psim-nb code:nth-child(6) { animation-delay: 0.75s; }
.is-live .psim-nb code:nth-child(7) { animation-delay: 0.9s; }
.is-live .psim-nb code:nth-child(8) { animation-delay: 1.05s; }
.psim-nb .tok-kw { color: #c792ea; }
.psim-nb .tok-fn { color: #82aaff; }
.psim-nb .tok-str { color: #c3e88d; }
.psim-nb .tok-com { color: #9aa0a6; }
.psim-nb .tok-num { color: #f78c6c; }

/* generic caption under a sim */
.psim-caption {
  margin-top: 12px;
  text-align: center;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.66rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--psim-dim);
}

@keyframes psim-up {
  to { opacity: 1; transform: translateY(0); }
}
@keyframes psim-fade {
  to { opacity: 1; }
}
@keyframes psim-grow {
  to { transform: scaleY(1); }
}
@keyframes psim-draw {
  to { stroke-dashoffset: 0; }
}
@keyframes psim-pop {
  to { opacity: 1; transform: scale(1); }
}
@keyframes psim-code {
  to { opacity: 1; transform: translateX(0); }
}
@keyframes psim-blink {
  0%, 100% { opacity: 0.35; }
  50% { opacity: 1; }
}
/* the thinking dots appear, cycle, then hide as the answer lands */
@keyframes psim-think-cycle {
  0% { opacity: 0; }
  12% { opacity: 1; }
  82% { opacity: 1; }
  100% { opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .psim *, .psim *::before {
    animation-duration: 0.01ms !important;
    animation-delay: 0s !important;
  }
}

/* Mobile: sims never force the page wider than the viewport; wide inner
   content (code, tables) scrolls inside its own box. */
@media (max-width: 760px) {
  .psim { max-width: 100%; }
  .psim-nb, .psim-table, .psheet { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .psim-flow { overflow: hidden; }
}
