/* ═══════════════════════════════════════════════════════════════════════════
   R18 — MOTION GRAPHICS PASS
   ───────────────────────────────────────────────────────────────────────────
   Four set pieces, no new palette, no new type. Everything here is drawn with
   the vocabulary the page already owns: 1px tactical-orange hairlines, mono
   micro-caps, registration brackets, tabular numerals.

     MG-1  HERO      caliper measures the name, leaves a dimension annotation
     MG-2  HEADERS   ghost index rolls in on an odometer; a gantry runs the rule
     MG-3  IDENTITY  the skill matrix plotted live on a phosphor scope
     MG-4  CONNECT   packets run the top edge of a control on hover

   Structure is injected by motion-fx.js; this file is geometry and timing.
   ═══════════════════════════════════════════════════════════════════════════ */

:root {
  --mg-hair: 0.9px;
}

/* ═══════════ MG-1 · HERO CALIPER ═══════════ */

.hero-name { position: relative; }

.mg-cal {
  position: absolute;
  left: 0;
  pointer-events: none;
  overflow: visible;
  z-index: 1;
  opacity: 0;
  transition: opacity 0.5s var(--ease-out);
}
.mg-cal.is-armed { opacity: 1; }

.mg-cal line,
.mg-cal path,
.mg-cal rect {
  fill: none;
  stroke: var(--orange);
  stroke-width: var(--mg-hair);
  vector-effect: non-scaling-stroke;
}
.mg-cal text {
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.16em;
  fill: var(--orange);
  text-transform: uppercase;
  stroke: none;
}
.mg-cal .mg-cal-sub { fill: var(--text-dim); letter-spacing: 0.2em; }

/* The measured furniture: datum, extension lines, leader, brackets. Each is
   a normalised path (pathLength="1") so one dashoffset rule draws them all. */
.mg-cal-draw path,
.mg-cal-draw line {
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
}
.mg-cal.is-measured .mg-cal-draw path,
.mg-cal.is-measured .mg-cal-draw line {
  stroke-dashoffset: 0;
  transition: stroke-dashoffset 0.52s var(--ease-snap);
}
.mg-cal.is-measured .mg-cal-draw .mg-lead { transition-delay: 0.2s; }

/* Registration brackets snap on from oversize — the same target-lock beat the
   section titles use, so the hero and the headers speak once language. */
.mg-cal-bracket {
  transform-box: fill-box;
  transform-origin: center;
  transform: scale(1.7);
  opacity: 0;
}
.mg-cal.is-measured .mg-cal-bracket {
  transform: scale(1);
  opacity: 0.85;
  transition: transform 0.42s var(--ease-snap), opacity 0.3s linear;
}
.mg-cal.is-measured .mg-cal-bracket:nth-of-type(2) { transition-delay: 0.05s; }
.mg-cal.is-measured .mg-cal-bracket:nth-of-type(3) { transition-delay: 0.1s; }
.mg-cal.is-measured .mg-cal-bracket:nth-of-type(4) { transition-delay: 0.15s; }

.mg-cal-tick {
  opacity: 0;
  transform-box: fill-box;
  transform-origin: bottom center;
  transform: scaleY(0.15);
  transition: opacity 0.14s linear, transform 0.22s var(--ease-snap);
}

.mg-cal-label { opacity: 0; }
.mg-cal.is-measured .mg-cal-label {
  opacity: 1;
  transition: opacity 0.34s linear 0.24s;
}

/* The jaw itself is the only bright thing on screen while it travels. */
.mg-cal-jaw line { stroke-width: 1.4px; }
.mg-cal-jaw { opacity: 0; transition: opacity 0.24s linear; }
.mg-cal.is-scanning .mg-cal-jaw { opacity: 1; transition: none; }

/* Afterlife: the annotation stays as a faint engineering mark, not a UI. */
.mg-cal.is-settled { opacity: 0.24; }
.mg-cal.is-settled .mg-cal-label { opacity: 0.9; }

/* Letters brighten as the jaw crosses them. The outline row has no fill, so
   it answers on its stroke instead. */
.hero-name .name-line > span {
  transition: text-shadow 0.36s var(--ease-out), -webkit-text-stroke-color 0.36s var(--ease-out);
}
.hero-name .name-line > span.mg-lit {
  text-shadow: 0 0 22px var(--orange-glow), 0 0 4px var(--orange-dim);
  transition-duration: 0.1s;
}
.hero-name .outline-text > span.mg-lit {
  -webkit-text-stroke-color: var(--orange);
}

/* ═══════════ MG-2 · SECTION HEADER ODOMETER + GANTRY ═══════════ */

/* Our numeral replaces the static ghost the moment JS has drawn one. */
html.mg-fx section > .section-header[data-num]::before { opacity: 0 !important; }

.mg-odo {
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-54%);
  display: flex;
  pointer-events: none;
  user-select: none;
  z-index: 0;
  opacity: 0;
  font-family: var(--font-head);
  font-size: 6rem;
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  color: transparent;
  -webkit-text-stroke: 1px var(--border-light);
  transition: opacity 0.5s var(--ease-out);
}
.section-header.mg-rolled .mg-odo { opacity: 0.45; }

.mg-digit {
  display: block;
  height: 1em;
  overflow: hidden;
}
.mg-digit b {
  display: block;
  font-weight: inherit;
  transform: translateY(0);
  transition: transform 0.94s var(--ease-snap), filter 0.34s linear;
}
.mg-digit b i {
  display: block;
  height: 1em;
  font-style: normal;
}

/* The rule is a track; a carriage runs it once and hands the section over. */
.mg-trail,
.mg-carriage {
  position: absolute;
  pointer-events: none;
  opacity: 0;
}
.mg-trail {
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  transform: scaleX(0);
  transform-origin: left center;
  background: linear-gradient(90deg, transparent, var(--orange));
}
.mg-carriage {
  left: 0;
  top: -7px;
  width: 2px;
  height: 16px;
  margin-left: -1px;
  background: var(--orange);
}
.mg-carriage::before,
.mg-carriage::after {
  content: '';
  position: absolute;
  left: -4px;
  width: 10px;
  height: 1px;
  background: var(--orange);
}
.mg-carriage::before { top: 0; }
.mg-carriage::after { bottom: 0; }

.section-line.mg-run .mg-trail { animation: mg-trail-run 0.72s var(--ease-snap) forwards; }
.section-line.mg-run .mg-carriage { animation: mg-carriage-run 0.72s var(--ease-snap) forwards; }
@keyframes mg-trail-run {
  0%   { transform: scaleX(0); opacity: 0.85; }
  72%  { opacity: 0.85; }
  100% { transform: scaleX(1); opacity: 0; }
}
@keyframes mg-carriage-run {
  0%   { left: 0; opacity: 0; }
  9%   { opacity: 1; }
  88%  { opacity: 1; }
  100% { left: 100%; opacity: 0; }
}

@media (max-width: 600px) {
  .mg-odo { font-size: 3.4rem; }
  .section-header.mg-rolled .mg-odo { opacity: 0.35; }
}

/* ═══════════ MG-5 · EDUCATION READ HEAD ═══════════ */

/* The spine fills as you read down it and a head rides the fill; each node
   latches as the head reaches it. Scroll-linked, so the section is never
   playing an animation the visitor did not ask for. */
.mg-eduspine {
  position: absolute;
  left: 12px;
  top: 0;
  width: 2px;
  height: 0;
  background: var(--orange);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s var(--ease-out);
}
.mg-eduhead {
  position: absolute;
  left: 13px;
  top: 0;
  width: 0;
  height: 0;
  z-index: 3;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s var(--ease-out);
}
.edu-timeline.mg-live .mg-eduspine { opacity: 0.5; }
.edu-timeline.mg-live .mg-eduhead { opacity: 1; }
.mg-eduhead::before {
  content: '';
  position: absolute;
  left: -3px;
  top: -13px;
  width: 6px;
  height: 26px;
  background: var(--orange);
  box-shadow: 0 0 12px var(--orange-glow);
}
.mg-eduhead::after {
  content: '';
  position: absolute;
  left: -13px;
  top: 0;
  width: 26px;
  height: 1px;
  background: var(--orange);
  opacity: 0.55;
}

.edu-timeline .edu-item.mg-latched::before {
  animation: mg-latch 0.66s var(--ease-out);
}
@keyframes mg-latch {
  0%   { box-shadow: 0 0 0 0 var(--orange-glow); transform: scale(1); }
  28%  { box-shadow: 0 0 16px 2px var(--orange-glow); transform: scale(1.32); }
  100% { box-shadow: 0 0 0 0 rgba(232, 118, 43, 0); transform: scale(1); }
}

/* ═══════════ MG-6 · ARCHIVE COUNTER DRUM ═══════════ */

.mg-drum {
  display: inline-flex;
  line-height: 1;
  vertical-align: baseline;
  font-variant-numeric: tabular-nums;
}
.mg-drum .mg-digit b { transition-duration: 0.62s; }
.mg-count-src {
  position: absolute !important;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ═══════════ MG-4 · CONNECT TRANSMISSION ═══════════ */

.mg-tx {
  position: absolute;
  left: 12px;
  right: 12px;
  top: 9px;
  height: 1px;
  z-index: 2;
  pointer-events: none;
  color: inherit;
}
.mg-tx::before {
  content: '';
  position: absolute;
  inset: 0;
  background: currentColor;
  opacity: 0.16;
  transform: scaleX(0);
  transform-origin: left center;
  transition: transform 0.34s var(--ease-out);
}
.connect-btn:hover .mg-tx::before,
.connect-btn:focus-visible .mg-tx::before { transform: scaleX(1); }

.mg-tx i {
  position: absolute;
  top: -1px;
  left: 0;
  width: 3px;
  height: 3px;
  margin-left: -3px;
  background: currentColor;
  opacity: 0;
}
@media (hover: hover) and (pointer: fine) {
  .connect-btn:hover .mg-tx i { animation: mg-packet 1.1s var(--ease-out) infinite; }
  .connect-btn:hover .mg-tx i:nth-child(2) { animation-delay: 0.17s; }
  .connect-btn:hover .mg-tx i:nth-child(3) { animation-delay: 0.36s; }
}
@keyframes mg-packet {
  0%   { left: 0; opacity: 0; }
  12%  { opacity: 1; }
  86%  { opacity: 1; }
  100% { left: 100%; opacity: 0; }
}

/* ═══════════ MG-7 · HIVE MIND PANEL ═══════════ */

.mg-glyphfield {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
}
/* Everything the visitor reads sits above the field. */
#chat-modal > .chat-header,
#chat-modal > .chat-body,
#chat-modal > .typing-indicator,
#chat-modal > .chat-input-area {
  position: relative;
  z-index: 2;
}

/* ── Opening: a hot scanline strikes, the frame unfolds from it, then the
   three rows arrive in order. Same CRT idea that was here before, but the
   beat is separated — strike, unfold, populate — instead of all at once. */
@keyframes modalPop {
  0% {
    opacity: 0;
    clip-path: polygon(0% 49.6%, 100% 49.6%, 100% 50.4%, 90% 50.4%, 0% 50.4%);
    filter: brightness(2.6);
  }
  14% {
    opacity: 1;
    clip-path: polygon(0% 49.6%, 100% 49.6%, 100% 50.4%, 90% 50.4%, 0% 50.4%);
    filter: brightness(2.6);
  }
  62% {
    opacity: 1;
    clip-path: polygon(0% 0%, 100% 0%, 100% 90%, 90% 100%, 0% 100%);
    filter: brightness(1.28);
  }
  100% {
    opacity: 1;
    clip-path: polygon(0% 0%, 100% 0%, 100% 90%, 90% 100%, 0% 100%);
    filter: brightness(1);
  }
}
#chat-modal {
  animation: modalPop 0.52s cubic-bezier(0.16, 0.84, 0.44, 1) forwards;
}

/* One pass of the beam down the freshly-opened panel. */
#chat-modal::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 2px;
  z-index: 3;
  pointer-events: none;
  background: linear-gradient(90deg, transparent, var(--orange), transparent);
  animation: mg-chat-beam 0.66s cubic-bezier(0.16, 0.84, 0.44, 1) 0.16s both;
}
@keyframes mg-chat-beam {
  0%   { top: 0; opacity: 0; }
  12%  { opacity: 0.9; }
  100% { top: 100%; opacity: 0; }
}

#chat-modal > .chat-header { animation: mg-chat-row 0.3s var(--ease-out) 0.26s both; }
#chat-modal > .chat-body { animation: mg-chat-row 0.36s var(--ease-out) 0.34s both; }
#chat-modal > .chat-input-area { animation: mg-chat-row 0.32s var(--ease-out) 0.42s both; }
@keyframes mg-chat-row {
  from { opacity: 0; transform: translateY(-5px); }
  to   { opacity: 1; transform: none; }
}

/* ── The panel itself: an instrument, not a bubble sheet.
   A hairline inside the 2px frame, registration brackets on the two square
   corners, and an input row that reads as a console line. */
#chat-modal {
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.8), inset 0 0 0 1px rgba(232, 118, 43, 0.14);
}
[data-theme="light"] #chat-modal {
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.34), inset 0 0 0 1px rgba(7, 110, 174, 0.16);
}
#chat-modal > .chat-header::before,
#chat-modal > .chat-header::after {
  content: '';
  position: absolute;
  width: 9px;
  height: 9px;
  border: 1px solid var(--orange);
  opacity: 0.55;
  pointer-events: none;
}
#chat-modal > .chat-header { position: relative; }
#chat-modal > .chat-header::before { top: 5px; left: 5px; border-right: none; border-bottom: none; }
#chat-modal > .chat-header::after { top: 5px; right: 5px; border-left: none; border-bottom: none; }

.chat-input-area { position: relative; }
.chat-input-area::before {
  content: '>';
  position: absolute;
  left: 24px;
  top: 50%;
  transform: translateY(-50%);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--orange);
  opacity: 0.5;
  pointer-events: none;
  z-index: 3;
}
.chat-input {
  padding-left: 26px !important;
  transition: border-color 0.18s var(--ease-out), box-shadow 0.18s var(--ease-out);
}
.chat-input:focus {
  box-shadow: 0 0 0 1px var(--orange-dim);
}

html.hive-motion-off .mg-glyphfield { display: none; }
html.hive-motion-off #chat-modal::after,
html.hive-motion-off #chat-modal > .chat-header,
html.hive-motion-off #chat-modal > .chat-body,
html.hive-motion-off #chat-modal > .chat-input-area { animation: none !important; }

@media (prefers-reduced-motion: reduce) {
  html:not(.force-motion) .mg-glyphfield { display: none; }
  html:not(.force-motion) #chat-modal::after,
  html:not(.force-motion) #chat-modal > .chat-header,
  html:not(.force-motion) #chat-modal > .chat-body,
  html:not(.force-motion) #chat-modal > .chat-input-area { animation: none !important; }
}

.mg-runewake {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 4997;
  pointer-events: none;
}
html.hive-motion-off .mg-runewake { display: none; }
@media (prefers-reduced-motion: reduce) {
  html:not(.force-motion) .mg-runewake { display: none; }
}

/* ═══════════ MOTION GUARDS ═══════════ */

html.hive-motion-off .mg-digit b,
html.hive-motion-off .mg-cal *,
html.hive-motion-off .edu-item.mg-latched::before,
html.hive-motion-off .mg-tx::before,
html.hive-motion-off .mg-tx i {
  animation: none !important;
  transition: none !important;
}
html.hive-motion-off .section-line.mg-run .mg-trail,
html.hive-motion-off .section-line.mg-run .mg-carriage { animation: none !important; opacity: 0 !important; }

@media (prefers-reduced-motion: reduce) {
  html:not(.force-motion) .mg-digit b,
  html:not(.force-motion) .mg-cal *,
  html:not(.force-motion) .edu-item.mg-latched::before,
  html:not(.force-motion) .mg-tx::before,
  html:not(.force-motion) .mg-tx i {
    animation: none !important;
    transition: none !important;
  }
  html:not(.force-motion) .section-line.mg-run .mg-trail,
  html:not(.force-motion) .section-line.mg-run .mg-carriage { animation: none !important; opacity: 0 !important; }
}
