/* ==========================================================================
   The blueprint system.

   Governing idea: the page IS a drafting sheet. These are not decorations
   applied to a layout — the layout is the drawing.

   Four rules:
     1. Elements snap to a VISIBLE 12-column grid.
     2. Nothing floats. Panels are dimensioned — corner brackets, indices,
        spec callouts on leader lines.
     3. Two type registers: display (Vazirmatn, warm) and readout (mono,
        technical). The tension between them is the brief.
     4. Teal is a SIGNAL, never a fill. It marks energized state. If teal
        appears without meaning something, delete it.

   Restraint budget, enforced in review:
     - At most 3 teal elements visible in any one viewport.
     - At most one "hero" animation per section.
     - Roughly half of all sections carry no grid at all. That contrast is
       what makes the grid read as intentional rather than as wallpaper.
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. The sheet — blueprint grid overlay
   Opt-in per section with .bp-sheet. Vertical rules only; horizontals get
   noisy fast, so sections draw their own single top hairline instead.
   -------------------------------------------------------------------------- */

.bp-sheet {
  position: relative;
  isolation: isolate;
}

.bp-sheet::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background-image: repeating-linear-gradient(
    to right,
    var(--bp-line) 0 1px,
    transparent 1px calc(100% / var(--bp-cols))
  );
  background-size: calc(100% - 2 * var(--gutter)) 100%;
  background-position: var(--gutter) 0;
  background-repeat: no-repeat;
  /*
   * The mask is the restraint. Without it the grid tiles flatly down the whole
   * page and reads as a texture; with it the grid emerges mid-section and
   * dissolves at the seams, which reads as a drawing.
   */
  -webkit-mask-image: linear-gradient(
    to bottom, transparent, #000 7rem, #000 calc(100% - 7rem), transparent
  );
  mask-image: linear-gradient(
    to bottom, transparent, #000 7rem, #000 calc(100% - 7rem), transparent
  );
  opacity: 0;
  transition: opacity 900ms var(--ease-out);
}

.bp-sheet.is-in::before {
  opacity: 1;
}

/* --------------------------------------------------------------------------
   2. Corner brackets
   Two pseudo-elements draw four corners. Built from border-inline-* and
   inset-inline-*, so RTL mirrors for free with zero rtl.css.
   -------------------------------------------------------------------------- */

.brk {
  position: relative;
}

.brk::before,
.brk::after {
  content: "";
  position: absolute;
  inline-size: var(--bracket-size);
  block-size: var(--bracket-size);
  border: var(--bracket-w) solid var(--bracket-color);
  transition: border-color var(--dur-base) var(--ease-out);
  pointer-events: none;
}

.brk::before {
  inset-block-start: 0;
  inset-inline-start: 0;
  border-inline-end: 0;
  border-block-end: 0;
}

.brk::after {
  inset-block-end: 0;
  inset-inline-end: 0;
  border-inline-start: 0;
  border-block-start: 0;
}

/* Energized: hover, focus, or an explicit live state. */
.brk:hover::before,
.brk:hover::after,
.brk:focus-within::before,
.brk:focus-within::after,
.brk[data-live="true"]::before,
.brk[data-live="true"]::after {
  border-color: var(--bracket-color-live);
}

/* Certification context uses copper, never teal. */
.brk--cert:hover::before,
.brk--cert:hover::after {
  border-color: var(--tr-copper);
}

/* --------------------------------------------------------------------------
   3. Readout — the technical voice
   -------------------------------------------------------------------------- */

.readout {
  font-family: var(--font-mono);
  font-size: var(--readout-size);
  letter-spacing: var(--readout-track);
  text-transform: uppercase;
  color: var(--tr-gray);
  font-variant-numeric: tabular-nums;
  line-height: 1.4;
}

.readout--live { color: var(--color-accent-text); }
.readout--cert { color: var(--tr-copper); }

.is-dark .readout { color: rgba(255, 255, 255, 0.5); }
.is-dark .readout--live { color: var(--tr-teal); }

/*
 * Persian and Arabic readouts.
 *
 * text-transform: uppercase is a no-op in both scripts, and letter-spacing
 * actively BREAKS Arabic glyph joining — the connected letterforms come apart.
 * So translated readout text drops to Vazirmatn medium at normal tracking.
 *
 * Latin product nomenclature (IEC 61439, IP 54, 24 kV, ISO 9001) keeps the
 * mono treatment in EVERY language, because it is product naming rather than
 * translated text. Mark those with .readout--code.
 */
.lang-fa .readout,
.lang-ar .readout {
  font-family: var(--font-body);
  font-weight: var(--fw-medium);
  letter-spacing: normal;
  text-transform: none;
  font-size: 0.8125rem;
}

.lang-fa .readout--code,
.lang-ar .readout--code,
.readout--code {
  font-family: var(--font-mono);
  font-size: var(--readout-size);
  letter-spacing: var(--readout-track);
  text-transform: uppercase;
}

/* --------------------------------------------------------------------------
   4. Index badge
   Only used where the content is genuinely a sequence. A numbered marker on
   an unordered set is decoration pretending to be information.
   -------------------------------------------------------------------------- */

.idx {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-inline-size: 2.25rem;
  padding: 0.3rem 0.5rem;
  font-family: var(--font-mono);
  font-size: var(--readout-size);
  font-weight: var(--fw-medium);
  letter-spacing: 0.1em;
  color: var(--tr-gray);
  font-variant-numeric: tabular-nums;
}

/* --------------------------------------------------------------------------
   5. Spec line — label, leader rule, value
   The signature device: a value connected to its label by a hairline, the way
   a dimension is called out on a drawing.
   -------------------------------------------------------------------------- */

.specs {
  display: flex;
  flex-direction: column;
}

.specline {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding-block: 0.7rem;
  border-block-start: 1px solid var(--bp-line);
}

.specline__dot {
  inline-size: 5px;
  block-size: 5px;
  border-radius: 50%;
  background: var(--tr-light-gray);
  flex-shrink: 0;
  transition: background var(--dur-base) var(--ease-out);
}

.specline__k {
  font-size: var(--fs-small);
  color: var(--color-text);
  flex-shrink: 0;
}

.specline__rule {
  flex: 1 1 auto;
  block-size: 1px;
  background: var(--bp-line-strong);
  transform: scaleX(0);
  transform-origin: inline-start;
  transition: transform var(--dur-slow) var(--ease-out);
  transition-delay: calc(var(--i, 0) * 90ms + 300ms);
}

.specline__v {
  font-family: var(--font-mono);
  font-size: var(--fs-micro);
  letter-spacing: 0.06em;
  color: var(--color-heading);
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}

.is-in .specline__rule { transform: scaleX(1); }
.is-in .specline__dot {
  background: var(--tr-teal);
}

/* --------------------------------------------------------------------------
   6. Busbar — a divider that means something
   Section separators energize left-to-right as they come into view. One idea,
   recurring sitewide, costing almost nothing.
   -------------------------------------------------------------------------- */

.busbar {
  block-size: 2px;
  background: var(--tr-charcoal);
  opacity: 0.85;
  position: relative;
  overflow: hidden;
}

.is-dark .busbar { background: rgba(255, 255, 255, 0.22); }

.busbar::after {
  content: "";
  position: absolute;
  inset-block: 0;
  inset-inline-start: 0;
  inline-size: 0;
  background: var(--tr-teal);
  transition: inline-size 1400ms var(--ease-out);
}

.busbar.is-in::after { inline-size: 100%; }

/* --------------------------------------------------------------------------
   7. Terminal marker
   -------------------------------------------------------------------------- */

.terminal {
  inline-size: calc(var(--terminal-r) * 2);
  block-size: calc(var(--terminal-r) * 2);
  border: 1px solid var(--sld-dim);
  border-radius: 50%;
  background: var(--color-bg);
  flex-shrink: 0;
}

.terminal--live {
  border-color: var(--tr-teal);
  background: var(--tr-teal);
}

/* --------------------------------------------------------------------------
   8. Single-line diagrams
   Real IEC grammar: supply -> disconnector -> breaker -> transformer -> busbar
   -> outgoing ways. Every stroke carries pathLength="1" so the draw-on timing
   is independent of the path's actual length.
   -------------------------------------------------------------------------- */

.sld {
  display: block;
  inline-size: 100%;
  block-size: auto;
}

.sld [data-draw] {
  stroke: var(--sld-color);
  stroke-width: var(--sld-stroke);
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
}

.sld.is-drawn [data-draw] {
  animation: tr-sld-draw var(--dur-draw) var(--ease-out) forwards;
}

@keyframes tr-sld-draw {
  to { stroke-dashoffset: 0; }
}

.sld__node {
  fill: var(--sld-color);
  opacity: 0;
  transition: opacity 500ms var(--ease-out) 1200ms;
}

.sld__label {
  font-family: var(--font-mono);
  font-size: 8px;
  letter-spacing: 0.06em;
  fill: var(--sld-dim);
  opacity: 0;
  transition: opacity 500ms var(--ease-out) 1400ms;
}

.sld.is-drawn .sld__node,
.sld.is-drawn .sld__label { opacity: 1; }

/*
 * The current pulse — the one genuinely delightful moment in the design.
 * A short teal dash travels the energized path exactly once.
 */
.sld__current {
  stroke: var(--tr-teal);
  stroke-width: 2.6;
  fill: none;
  stroke-linecap: round;
  stroke-dasharray: 0.07 0.93;
  stroke-dashoffset: 1;
}

.sld.is-drawn .sld__current {
  animation: tr-current-flow 2400ms var(--ease-in-out) 1100ms 1 forwards;
}

@keyframes tr-current-flow {
  to { stroke-dashoffset: 0; }
}

/*
 * Where the browser supports scroll-driven animation, drive the pulse from
 * scroll position instead of a timer — it runs off the main thread entirely.
 * Chromium gets this; Safari and Firefox keep the IntersectionObserver path.
 * Both are correct; neither is a degraded-looking fallback.
 */
@supports (animation-timeline: view()) {
  @media (prefers-reduced-motion: no-preference) {
    .sld--scroll .sld__current {
      animation: tr-current-flow linear both;
      animation-timeline: view();
      animation-range: entry 20% cover 60%;
    }
  }
}

/* --------------------------------------------------------------------------
   9. Reveal
   -------------------------------------------------------------------------- */

.rv {
  opacity: 0;
  transform: translateY(18px);
  transition: opacity 620ms var(--ease-out), transform 620ms var(--ease-out);
  transition-delay: calc(var(--i, 0) * 80ms);
}

.rv.is-in {
  opacity: 1;
  transform: none;
}

/* --------------------------------------------------------------------------
   10. Reduced motion
   Every primitive lands on its COMPLETED state. The classic bug in this kind
   of system is a reveal that starts at opacity:0 and never fires, leaving the
   page blank for exactly the users who opted out of motion.
   -------------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  .rv { opacity: 1; transform: none; }
  .bp-sheet::before { opacity: 1; }
  .busbar::after { inline-size: 100%; }
  .specline__rule { transform: scaleX(1); }
  .specline__dot { background: var(--tr-teal); }
  .sld [data-draw] { stroke-dashoffset: 0; }
  .sld__node,
  .sld__label { opacity: 1; }
  .sld__current { stroke-dashoffset: 0; }
}
