/* Pine Script to MT4/MT5 conversion page: the "pine_conversion" layout (/pine).
 *
 * Built on services.css (hero, rotating words, editor, form) and
 * blockchain.css (pillars, cards, steps, FAQ); this file adds:
 *
 * 1. Code chips floating in the hero gutters: Pine Script on the left, the
 *    matching MQL on the right. Shown only where the gutters are wide enough
 *    (from 1200px), like the /ea coins, so they never cover the copy.
 * 2. A pipeline along the bottom of the hero: packets travel from
 *    "Pine Script" to "MT4 / MT5" (each packet is a full-width layer moved by
 *    translateX(0 → 100%), so the trip always spans the track).
 * 3. The conversion demo: a Pine Script editor, a converter and the MQL5
 *    editor. Side by side from 1024px, stacked (the converter turned to point
 *    down) below. The converter flashes at --handoff, the moment the Pine
 *    Script has finished typing (set by service-page.js).
 * 4. The "Pine Script → MQL" mapping list.
 *
 * Only transform and opacity are animated, everything moves only under
 * prefers-reduced-motion: no-preference and the hero pauses while it is off
 * screen (service-page.js). Without motion every part is shown still.
 */

.pine-body {
  --pine-blue: #6f9bff;
  --pine-blue-soft: rgba(111, 155, 255, 0.14);
  --pine-blue-line: rgba(111, 155, 255, 0.45);
  --pine-gold-line: rgba(235, 196, 42, 0.45);
  --pine-converter: clamp(4.75rem, 3.75rem + 2vw, 6rem);
}

/* ================================================================== Hero */

.pine-hero {
  padding-bottom: clamp(9.5rem, 7.5rem + 5vw, 13rem);
}

.pine-scene {
  position: absolute;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
}

/* A floating code chip. Hidden until the gutters are wide enough. */
.pine-token {
  --pine-token-color: var(--pine-blue);
  --pine-token-line: var(--pine-blue-line);
  position: absolute;
  display: none;
  padding: 0.45em 0.9em;
  border: 1px solid var(--pine-token-line);
  border-radius: 10px;
  background-color: rgba(10, 12, 16, 0.85);
  box-shadow: 0 12px 30px -16px var(--pine-token-line);
  color: var(--pine-token-color);
  font-family: var(--font-mono);
  font-size: calc(var(--svc-decor) * 0.32 * var(--k, 1));
  font-weight: var(--font-weight-bold);
  white-space: nowrap;
  opacity: 0.85;
}

.pine-token--mql {
  --pine-token-color: var(--auth-gold);
  --pine-token-line: var(--pine-gold-line);
}

/* In the gutters beside the copy, centred at a fraction (--x) of the gutter
   measured from the outer edge (translate centres any chip width). */
@media (min-width: 1200px) {
  .pine-token {
    display: inline-block;
  }

  .pine-token:nth-of-type(odd) {
    left: calc((100% - var(--svc-copy)) / 2 * var(--x));
    translate: -50% 0;
  }

  .pine-token:nth-of-type(even) {
    right: calc((100% - var(--svc-copy)) / 2 * var(--x));
    translate: 50% 0;
  }

  .pine-token:nth-of-type(1) { --k: 1.05; --x: 0.5; top: 12%; }
  .pine-token:nth-of-type(2) { --k: 1.05; --x: 0.5; top: 16%; }
  .pine-token:nth-of-type(3) { --k: 0.9; --x: 0.76; top: 34%; }
  .pine-token:nth-of-type(4) { --k: 0.9; --x: 0.76; top: 38%; }
  .pine-token:nth-of-type(5) { --k: 0.95; --x: 0.45; top: 56%; }
  .pine-token:nth-of-type(6) { --k: 0.95; --x: 0.45; top: 60%; }
}

/* The pipeline: "Pine Script" ──●──●──●──▶ "MT4 / MT5". */
.pine-flow {
  position: absolute;
  bottom: clamp(3.75rem, 2.75rem + 2.5vw, 5.75rem);
  left: 50%;
  display: flex;
  align-items: center;
  gap: clamp(0.5rem, 0.3rem + 0.6vw, 0.9rem);
  width: min(44rem, calc(100% - 2rem));
  translate: -50% 0;
}

.pine-flow__end {
  flex: 0 0 auto;
  padding: 0.4em 0.85em;
  border: 1px solid var(--pine-blue-line);
  border-radius: var(--radius-pill);
  background-color: rgba(10, 12, 16, 0.85);
  color: var(--pine-blue);
  font-family: var(--font-mono);
  font-size: clamp(0.7rem, 0.64rem + 0.25vw, 0.85rem);
  font-weight: var(--font-weight-bold);
  white-space: nowrap;
}

.pine-flow__end--to {
  border-color: var(--pine-gold-line);
  color: var(--auth-gold);
}

.pine-flow__track {
  position: relative;
  flex: 1 1 auto;
  min-width: 2rem;
  height: 2px;
  border-radius: 2px;
  background: linear-gradient(90deg, var(--pine-blue-line), var(--pine-gold-line));
}

/* A packet: a full-width layer with its dot at the left edge. Still, the
   packets are spread along the track (--i); moving, they travel its length. */
.pine-flow__packet {
  position: absolute;
  inset: 0;
  transform: translateX(calc(var(--i, 0) * 20%));
}

.pine-flow__packet::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 0;
  width: 0.5rem;
  height: 0.5rem;
  margin: -0.25rem 0 0 -0.25rem;
  border-radius: 50%;
  background-color: #ffffff;
  box-shadow: 0 0 10px 2px var(--auth-gold-glow);
}

.pine-flow__packet:nth-child(1) { --i: 0.5; }
.pine-flow__packet:nth-child(2) { --i: 1.5; }
.pine-flow__packet:nth-child(3) { --i: 2.5; }
.pine-flow__packet:nth-child(4) { --i: 3.5; }
.pine-flow__packet:nth-child(5) { --i: 4.5; }

/* ========================================================= Conversion demo */

.pine-demo {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-items: center;
  gap: clamp(0.5rem, 0.3rem + 0.6vw, 1rem);
}

@media (min-width: 1024px) {
  .pine-demo {
    grid-template-columns: minmax(0, 1fr) calc(var(--pine-converter) + 2rem) minmax(0, 1.15fr);
  }
}

.pine-editor--pine .svc-editor__lang {
  background-color: var(--pine-blue-soft);
  color: var(--pine-blue);
}

/* The converter: a gold core inside two rings, on a beam that carries pulses
   from the Pine Script editor to the MQL one (top to bottom when stacked,
   left to right side by side). */
.pine-converter {
  position: relative;
  display: grid;
  place-items: center;
  height: calc(var(--pine-converter) + 2.5rem);
}

.pine-converter__beam {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 2px;
  translate: -50% 0;
  background: linear-gradient(180deg, var(--pine-blue-line), var(--pine-gold-line));
}

.pine-converter__pulse {
  position: absolute;
  inset: 0;
  opacity: 0;
}

.pine-converter__pulse::before {
  content: "";
  position: absolute;
  top: 0;
  left: 50%;
  width: 0.45rem;
  height: 0.45rem;
  margin: -0.225rem 0 0 -0.225rem;
  border-radius: 50%;
  background-color: #ffffff;
  box-shadow: 0 0 10px 2px var(--auth-gold-glow);
}

.pine-converter__ring {
  position: absolute;
  width: calc(var(--pine-converter) * 0.82);
  aspect-ratio: 1;
  border: 1px dashed var(--pine-gold-line);
  border-radius: 50%;
}

.pine-converter__ring--outer {
  width: var(--pine-converter);
  border-style: solid;
  border-color: var(--pine-blue-line);
  border-right-color: transparent;
  border-left-color: transparent;
}

.pine-converter__core {
  position: relative;
  z-index: 1;
  display: grid;
  place-items: center;
  width: calc(var(--pine-converter) * 0.56);
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle at 32% 28%, var(--svc-coin-light), var(--auth-gold) 50%, var(--svc-coin-dark));
  box-shadow: 0 0 0 6px var(--auth-gold-soft), 0 14px 34px -10px var(--auth-gold-glow);
  color: #1d1600;
}

/* Stacked: the arrows point down, towards the MQL editor. */
.pine-converter__core svg {
  width: 45%;
  height: 45%;
  transform: rotate(90deg);
}

@media (min-width: 1024px) {
  .pine-converter {
    height: auto;
    min-height: var(--pine-converter);
  }

  .pine-converter__beam {
    top: 50%;
    right: 0;
    bottom: auto;
    left: 0;
    width: auto;
    height: 2px;
    translate: 0 -50%;
    background: linear-gradient(90deg, var(--pine-blue-line), var(--pine-gold-line));
  }

  .pine-converter__pulse::before {
    top: 50%;
    left: 0;
  }

  .pine-converter__core svg {
    transform: none;
  }
}

/* ============================================================ Mapping list */

.pine-map__title {
  margin: clamp(2.25rem, 1.75rem + 2vw, 3.5rem) 0 clamp(1rem, 0.8rem + 0.6vw, 1.5rem);
  font-family: var(--font-brand);
  font-size: var(--mql-fs-h3);
  font-weight: var(--font-weight-bold);
  text-align: center;
}

.pine-map {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: clamp(0.65rem, 0.5rem + 0.5vw, 1rem);
  margin: 0;
  padding: 0;
  list-style: none;
}

@media (min-width: 768px) {
  .pine-map {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (min-width: 1280px) {
  .pine-map {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

/* Pine chip, then "→ MQL chip" (one unit, so a narrow card wraps it as a
   whole onto the next line), then the note on its own line. */
.pine-map__row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.55rem 0.6rem;
  min-width: 0;
  padding: clamp(0.9rem, 0.8rem + 0.4vw, 1.2rem) clamp(1rem, 0.85rem + 0.5vw, 1.35rem);
  border: 1px solid var(--auth-line);
  border-radius: var(--auth-radius-sm);
  background-color: var(--mql-surface);
  transition: border-color var(--transition-normal), transform var(--transition-normal);
}

.pine-map__row:hover {
  border-color: var(--auth-line-strong);
}

.pine-map__code {
  max-width: 100%;
  padding: 0.25em 0.6em;
  border: 1px solid var(--pine-blue-line);
  border-radius: 8px;
  background-color: var(--pine-blue-soft);
  color: var(--pine-blue);
  font-family: var(--font-mono);
  font-size: var(--font-size-sm);
  overflow-wrap: anywhere;
}

/* Wide enough cards keep each call on one line. */
@media (min-width: 400px) {
  .pine-map__code {
    white-space: nowrap;
  }
}

.pine-map__code--mql {
  border-color: var(--pine-gold-line);
  background-color: var(--auth-gold-soft);
  color: var(--auth-gold);
}

.pine-map__arrow {
  display: inline-grid;
  place-items: center;
  color: var(--auth-subtle);
}

.pine-map__arrow svg {
  width: 1rem;
  height: 1rem;
}

.pine-map__to {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  max-width: 100%;
}

.pine-map__text {
  flex-basis: 100%;
  color: var(--auth-muted);
  font-size: var(--auth-fs-small);
  line-height: 1.55;
}

/* ================================================================ Motion */

@media (prefers-reduced-motion: no-preference) {
  .pine-token {
    animation: pine-token-float 7s ease-in-out infinite alternate;
  }

  .pine-token:nth-of-type(2) { animation-duration: 8s; animation-delay: -3s; }
  .pine-token:nth-of-type(3) { animation-duration: 6s; animation-delay: -1.5s; }
  .pine-token:nth-of-type(4) { animation-duration: 9s; animation-delay: -5s; }
  .pine-token:nth-of-type(5) { animation-duration: 6.5s; animation-delay: -2s; }
  .pine-token:nth-of-type(6) { animation-duration: 7.5s; animation-delay: -4s; }

  .pine-flow__packet {
    animation: pine-packet 3.5s linear infinite;
  }

  .pine-flow__packet:nth-child(2) { animation-delay: -0.7s; }
  .pine-flow__packet:nth-child(3) { animation-delay: -1.4s; }
  .pine-flow__packet:nth-child(4) { animation-delay: -2.1s; }
  .pine-flow__packet:nth-child(5) { animation-delay: -2.8s; }

  .svc-hero.is-offscreen .pine-scene * {
    animation-play-state: paused;
  }

  .pine-converter__pulse {
    animation: pine-pulse-down 1.8s linear infinite;
  }

  .pine-converter__pulse:nth-child(2) { animation-delay: -0.6s; }
  .pine-converter__pulse:nth-child(3) { animation-delay: -1.2s; }

  .pine-converter__ring {
    animation: pine-spin 14s linear infinite;
  }

  .pine-converter__ring--outer {
    animation-duration: 9s;
    animation-direction: reverse;
  }

  /* The hand-off: the core pops once the Pine Script has been typed. */
  .pine-demo.is-typing .pine-converter__core {
    animation: pine-core-pop 900ms var(--auth-ease) var(--handoff, 0ms) both;
  }

  .pine-map__row:hover {
    transform: translateY(-2px);
  }

  .pine-map__row:hover .pine-map__arrow {
    animation: pine-nudge 700ms var(--auth-ease);
  }
}

/* Side by side the pulses travel left to right. */
@media (prefers-reduced-motion: no-preference) and (min-width: 1024px) {
  .pine-converter__pulse {
    animation-name: pine-pulse-right;
  }
}

/* Without motion, one pulse rests in the middle of the beam. */
@media (prefers-reduced-motion: reduce) {
  .pine-converter__pulse:first-child {
    opacity: 1;
    transform: translateY(25%);
  }
}

@media (prefers-reduced-motion: reduce) and (min-width: 1024px) {
  .pine-converter__pulse:first-child {
    transform: translateX(25%);
  }
}

@keyframes pine-token-float {
  from { transform: translateY(0); }
  to { transform: translateY(-14px); }
}

@keyframes pine-packet {
  0% { opacity: 0; transform: translateX(0); }
  12%, 88% { opacity: 1; }
  100% { opacity: 0; transform: translateX(100%); }
}

@keyframes pine-pulse-down {
  0% { opacity: 0; transform: translateY(0); }
  15%, 85% { opacity: 1; }
  100% { opacity: 0; transform: translateY(100%); }
}

@keyframes pine-pulse-right {
  0% { opacity: 0; transform: translateX(0); }
  15%, 85% { opacity: 1; }
  100% { opacity: 0; transform: translateX(100%); }
}

@keyframes pine-spin {
  to { transform: rotate(360deg); }
}

@keyframes pine-core-pop {
  0% { transform: scale(1); }
  40% { transform: scale(1.18); }
  100% { transform: scale(1); }
}

@keyframes pine-nudge {
  0%, 100% { transform: translateX(0); }
  50% { transform: translateX(4px); }
}

/* ========================================================= Short screens */

@media (max-height: 560px) and (orientation: landscape) {
  .pine-hero {
    padding-bottom: 7.5rem;
  }

  .pine-flow {
    bottom: 3rem;
  }
}

/* ================================================================ Phones */

@media (max-width: 479.98px) {
  .pine-flow__end {
    padding-inline: 0.65em;
  }
}
