/**
 * HostCraft — Animated Infrastructure Grid (shared)
 * Markup: includes/shared/visual_grid.php. Used by auth/ and admin-dsahboard/.
 *
 * Geometry: 5 equal columns × 12 equal rows inside a 1px frame. Every cell draws
 * a dashed line on its right and bottom edge. Tiles are one row tall and sit in
 * their cells with one gutter (--g) on all four sides, measured from the lines,
 * so every gap between two tiles has its line exactly in the middle.
 *
 * Motion has two levels:
 *   full  — reveal, drifting light, breathing tiles, edge traces, travelling pulses, scan line
 *   calm  — (prefers-reduced-motion) nothing travels; fades, breathing and in-tile light drift remain
 * Only transform and opacity are animated.
 */

.hc-visual {
  --cols: 5; --rows: 12;
  --hc-line: rgba(255, 255, 255, 0.09);
  --hc-frame: rgba(255, 255, 255, 0.08);
  --hc-corner-bg: #070707;
  --hc-ease: cubic-bezier(.2, .7, .2, 1);
  --hc-step: 50ms;
  --d: 0; --t: 0s;
  position: absolute; inset: 22px; z-index: 1; pointer-events: none;
  border: 1px solid var(--hc-frame);
  container-type: inline-size; container-name: hc-grid;
}
.hc-cells, .hc-layer {
  position: absolute; inset: 0; display: grid;
  grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
  grid-template-rows: repeat(var(--rows), minmax(0, 1fr));
}
/* Gutter: 2% of the panel width (10% of a cell), whole pixels where supported. */
.hc-layer { --g: max(6px, 2cqw); }
@supports (width: round(1px, 1px)) {
  .hc-layer { --g: round(max(6px, 2cqw), 1px); }
}

/* ---- Placement & timing utilities (no inline styles, CSP-safe) ---------- */
.hc-c1 { grid-column-start: 1; } .hc-c2 { grid-column-start: 2; } .hc-c3 { grid-column-start: 3; }
.hc-c4 { grid-column-start: 4; } .hc-c5 { grid-column-start: 5; } .hc-c6 { grid-column-start: 6; }
.hc-c7 { grid-column-start: 7; } .hc-c8 { grid-column-start: 8; } .hc-c9 { grid-column-start: 9; }
.hc-c10 { grid-column-start: 10; }
.hc-cs1 { grid-column-end: span 1; } .hc-cs2 { grid-column-end: span 2; }
.hc-cs3 { grid-column-end: span 3; } .hc-cs4 { grid-column-end: span 4; } .hc-cs5 { grid-column-end: span 5; }
.hc-cols-10 { --cols: 10; } .hc-rows-8 { --rows: 8; }
.hc-r1 { grid-row-start: 1; } .hc-r2 { grid-row-start: 2; } .hc-r3 { grid-row-start: 3; } .hc-r4 { grid-row-start: 4; }
.hc-r5 { grid-row-start: 5; } .hc-r6 { grid-row-start: 6; } .hc-r7 { grid-row-start: 7; } .hc-r8 { grid-row-start: 8; }
.hc-r9 { grid-row-start: 9; } .hc-r10 { grid-row-start: 10; } .hc-r11 { grid-row-start: 11; } .hc-r12 { grid-row-start: 12; }
.hc-rs1 { grid-row-end: span 1; } .hc-rs2 { grid-row-end: span 2; } .hc-rs6 { grid-row-end: span 6; }
.hc-rs7 { grid-row-end: span 7; }
.hc-d0{--d:0}.hc-d1{--d:1}.hc-d2{--d:2}.hc-d3{--d:3}.hc-d4{--d:4}.hc-d5{--d:5}.hc-d6{--d:6}.hc-d7{--d:7}.hc-d8{--d:8}
.hc-d9{--d:9}.hc-d10{--d:10}.hc-d11{--d:11}.hc-d12{--d:12}.hc-d13{--d:13}.hc-d14{--d:14}.hc-d15{--d:15}.hc-d16{--d:16}
.hc-t0{--t:0s}.hc-t1{--t:1.3s}.hc-t2{--t:2.6s}.hc-t3{--t:3.9s}.hc-t4{--t:5.2s}.hc-t5{--t:6.5s}.hc-t6{--t:7.8s}.hc-t7{--t:9.1s}
.hc-t8{--t:10.4s}.hc-t9{--t:11.7s}.hc-t10{--t:13s}.hc-t11{--t:14.3s}.hc-t12{--t:15.6s}.hc-t13{--t:16.9s}.hc-t14{--t:18.2s}.hc-t15{--t:19.5s}

/* ---- Cells: dashed lines on the right and bottom edge ---------------------- */
.hc-cell {
  border-right: 1px dashed var(--hc-line); border-bottom: 1px dashed var(--hc-line);
  animation: hcFadeIn .6s var(--hc-ease) both; animation-delay: calc(var(--d) * var(--hc-step));
}
.hc-cell.hc-last-col { border-right: 0; }    /* the frame draws the outer edge */
.hc-cell.hc-last-row { border-bottom: 0; }
.hc-cell.hc-void { border-color: transparent; }
.hc-cell.hc-join { border-right-color: transparent; }   /* covered by a wider tile in this row */
.hc-cell.hc-sr { border-right: 1px solid var(--hc-frame); }    /* stepped zone outline */
.hc-cell.hc-sb { border-bottom: 1px solid var(--hc-frame); }

/* ---- Solid outlines: the copy zone and single outlined cells ------------------
   Pulled 1px up-left so their left/top edge lands on the neighbouring cell's line. */
.hc-zone, .hc-frame {
  position: relative; overflow: hidden; margin: -1px 0 0 -1px; border: 1px solid var(--hc-frame);
  animation: hcFadeIn .8s var(--hc-ease) both; animation-delay: calc(var(--d) * var(--hc-step) + 250ms);
}
.hc-zone::after, .hc-frame::after {   /* a light running along the top edge now and then */
  content: ""; position: absolute; top: -1px; left: 0; width: 45%; height: 1px;
  background: linear-gradient(90deg, transparent, #ff7a28, transparent);
  transform: translateX(-110%);
  animation: hcTrace 6.5s cubic-bezier(.45, 0, .2, 1) infinite; animation-delay: calc(1.6s + var(--t));
}
.hc-zone::after { width: 30%; animation-duration: 9s; }
.hc-zone--ghost { border-color: transparent; }   /* stepped zones: the cells draw the outline */

/* ---- Tiles ---------------------------------------------------------------------
   Equal gap to the line on every side: the left/top line sits outside the cell,
   the right/bottom line inside it, hence +1px on those sides. At the outer frame
   the line is outside the cell again, so the extra pixel goes away. */
.hc-tile {
  position: relative;
  margin: var(--g) calc(var(--g) + 1px) calc(var(--g) + 1px) var(--g);
  animation: hcRise .9s var(--hc-ease) both; animation-delay: calc(var(--d) * var(--hc-step) + 400ms);
}
.hc-tile.hc-at-right { margin-right: var(--g); }
.hc-tile.hc-at-bottom { margin-bottom: var(--g); }
/* Tile surface, three layers (matched against the reference crop):
     1. light  — one broad, soft glow: dark at both ends, never clipping to flat colour
     2. grain  — a 1px, high-contrast dither blended in overlay, so every pixel varies
                 (dark specks in the light, faint sparks in the shadow)
     3. rim    — a soft dark edge inside the tile
   The glow is one smooth hump across the whole tile, however many columns it spans. */
.hc-fill { position: absolute; inset: 0; overflow: hidden; background: #050100; isolation: isolate; }
.hc-fill::before {          /* 1. light — 120% wide so the drift can move the glow inside the tile */
  content: ""; position: absolute; top: 0; bottom: 0; left: 0; width: 120%;
  background: var(--hc-tone);
  transform: translateX(var(--hc-x0, 0%));
}
.hc-fill::after {           /* 2. grain — rendered 1:1 (180px tile of 180 units) */
  content: ""; position: absolute; inset: 0; mix-blend-mode: overlay; opacity: .85;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180' viewBox='0 0 180 180'%3E%3Cfilter id='n' x='0' y='0'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='1.35' numOctaves='1' seed='7' stitchTiles='stitch'/%3E%3CfeColorMatrix values='2.8 0 0 0 -0.9 2.8 0 0 0 -0.9 2.8 0 0 0 -0.9 0 0 0 0 1'/%3E%3C/filter%3E%3Crect width='180' height='180' filter='url(%23n)'/%3E%3C/svg%3E");
  background-size: 180px 180px;
}
.hc-tile::after {           /* 3. rim */
  content: ""; position: absolute; inset: 0; pointer-events: none;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.45), inset 0 0 5px rgba(0, 0, 0, 0.5);   /* keeps the tile a crisp rectangle */
}

/* Tones. Stops are positions on the 120% layer; the tile shows 83% of it.
   --hc-x0 is the rest position, --hc-dx the far end of the drift. */
.hc-ember {   /* glow right of centre (~74% at rest, ~55% at the far end of the drift) */
  --hc-tone: linear-gradient(90deg, #030100 0%, #0f0400 12%, #2e0d00 26%, #6a2100 40%, #b43b00 52%, #e04a06 62%, #c23f02 70%, #7a2600 80%, #351000 91%, #140600 100%);
  --hc-x0: 0%; --hc-dx: -16%;
}
.hc-flare {   /* mirror: glow left of centre (~26% at rest, ~46% at the far end) */
  --hc-tone: linear-gradient(270deg, #030100 0%, #0f0400 12%, #2e0d00 26%, #6a2100 40%, #b43b00 52%, #e04a06 62%, #c23f02 70%, #7a2600 80%, #351000 91%, #140600 100%);
  --hc-x0: -16%; --hc-dx: 0%;
}
.hc-core {    /* single-column accent: glow centred, a touch brighter */
  --hc-tone: linear-gradient(90deg, #070200 0%, #2a0c00 18%, #7a2600 32%, #c84100 42%, #f05408 50%, #c84100 58%, #7a2600 68%, #2a0c00 82%, #070200 100%);
  --hc-x0: -4%; --hc-dx: -12%;
}
.hc-dim {     /* low light, same shape as ember */
  --hc-tone: linear-gradient(90deg, #020100 0%, #0a0300 14%, #1c0800 30%, #3a1100 48%, #5a1b00 62%, #3e1300 76%, #1c0800 90%, #0c0300 100%);
  --hc-x0: 0%; --hc-dx: -16%;
}

/* Ambient life: every tile breathes a little; "glow" tiles breathe more; "drift" tiles slide their light. */
.hc-fill::before { animation: hcBreathe 6s ease-in-out infinite alternate; animation-delay: calc(var(--t) * -1); }
.hc-fx-glow .hc-fill::before { animation-name: hcBreatheStrong; animation-duration: 4.5s; }
.hc-fx-drift .hc-fill::before {
  animation: hcDrift 10s ease-in-out infinite alternate, hcBreathe 6s ease-in-out infinite alternate;
  animation-delay: calc(var(--t) * -1), calc(var(--t) * -1);
}

/* A short pulse travelling along a grid line */
.hc-lane { position: absolute; left: 0; right: 0; height: 1px; container-type: inline-size; }
.hc-l1 { top: calc(100% / 12 * 1); }  .hc-l2 { top: calc(100% / 12 * 2); }  .hc-l3 { top: calc(100% / 12 * 3); }
.hc-l10 { top: calc(100% / 12 * 10); } .hc-l11 { top: calc(100% / 12 * 11); }
.hc-lane { margin-top: -1px; }   /* sit on the dashed line, which is the last pixel of the row above */
.hc-packet {
  position: absolute; top: -1px; left: 0; width: 64px; height: 3px;
  background: linear-gradient(90deg, transparent, var(--silver));
  box-shadow: 0 0 10px var(--silver-bd);
  opacity: 0; transform: translateX(-70px);
  animation: hcPacket 7s cubic-bezier(.5, 0, .3, 1) infinite; animation-delay: calc(1.5s + var(--t));
}

/* A soft scan line moving down the panel */
.hc-scan {
  position: absolute; left: 0; right: 0; top: 0; height: 18%;
  background: linear-gradient(180deg, transparent, rgba(255, 90, 0, 0.04) 60%, rgba(255, 120, 40, 0.08) 98%, transparent);
  transform: translateY(-100%); animation: hcScan 12s linear infinite; animation-delay: 1.5s;
}

/* Corner markers, centred on the frame corners */
.hc-corner { position: absolute; width: 13px; height: 13px; background: var(--hc-corner-bg); border: 1px solid var(--hc-frame); }
.hc-tl { top: -7px; left: -7px; }  .hc-tr { top: -7px; right: -7px; }
.hc-bl { bottom: -7px; left: -7px; } .hc-br { bottom: -7px; right: -7px; }

/* Already seen this visit: skip the build-up, keep the ambient motion. */
.hc-visual-seen .hc-cell, .hc-visual-seen .hc-zone, .hc-visual-seen .hc-frame, .hc-visual-seen .hc-tile { animation: none; }

/* Narrow panel: the copy is wider than four columns, so the zone takes the full
   width and the tiles beside it step aside — text never crosses a tile or line. */
@container hc-grid (max-width: 560px) {
  .hc-zone { grid-column: 1 / -1; }
  .hc-cell.hc-beside-zone { border-color: transparent; }
  .hc-behind-copy { display: none; }
  .hc-scan { display: none; }
}

/* Compact band (5 × 2) above the form on small screens; lines follow the host theme. */
.hc-visual--compact {
  --rows: 2;
  position: relative; inset: auto; height: 96px; overflow: hidden;
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 14%, #000 86%, transparent);
          mask-image: linear-gradient(90deg, transparent, #000 14%, #000 86%, transparent);
}
.hc-visual--compact .hc-layer { --g: 7px; }

@keyframes hcFadeIn  { from { opacity: 0; } }
@keyframes hcRise    { from { opacity: 0; transform: translateY(10px); } }
@keyframes hcDrift   { to { transform: translateX(var(--hc-dx, 0%)); } }
@keyframes hcBreathe { from { opacity: .8; } to { opacity: 1; } }
@keyframes hcBreatheStrong { from { opacity: .5; } to { opacity: 1; } }
@keyframes hcEdge    { 50% { opacity: .9; } }
@keyframes hcTrace   { 0%, 45% { transform: translateX(-110%); } 85%, 100% { transform: translateX(340%); } }
@keyframes hcScan    { to { transform: translateY(560%); } }
@keyframes hcPacket {
  0% { opacity: 0; transform: translateX(-70px); }
  6% { opacity: 1; }
  45% { opacity: 1; transform: translateX(100cqw); }
  46%, 100% { opacity: 0; transform: translateX(100cqw); }
}

/* ---- Calm motion (prefers-reduced-motion) -----------------------------------
   Nothing travels across the panel; the grid fades in and the tiles still breathe
   and drift their light inside their own bounds. !important wins over host pages
   that switch every animation off for this preference. */
@media (prefers-reduced-motion: reduce) {
  .hc-visual .hc-packet, .hc-visual .hc-scan { display: none !important; }
  .hc-visual .hc-cell { animation: hcFadeIn 1s ease-out both !important; animation-delay: calc(var(--d) * 60ms) !important; }
  .hc-visual .hc-zone, .hc-visual .hc-frame { animation: hcFadeIn 1.2s ease-out both !important; animation-delay: calc(var(--d) * 60ms + 250ms) !important; }
  .hc-visual .hc-tile { animation: hcFadeIn 1.3s ease-out both !important; animation-delay: calc(var(--d) * 60ms + 400ms) !important; }
  .hc-visual-seen .hc-visual .hc-cell, .hc-visual-seen .hc-visual .hc-zone,
  .hc-visual-seen .hc-visual .hc-frame, .hc-visual-seen .hc-visual .hc-tile { animation: none !important; }
  .hc-visual .hc-fill::before { animation: hcBreathe 6s ease-in-out infinite alternate !important; animation-delay: calc(var(--t) * -1) !important; }
  .hc-visual .hc-fx-glow .hc-fill::before { animation: hcBreatheStrong 5s ease-in-out infinite alternate !important; animation-delay: calc(var(--t) * -1) !important; }
  .hc-visual .hc-fx-drift .hc-fill::before {
    animation: hcDrift 14s ease-in-out infinite alternate, hcBreathe 6s ease-in-out infinite alternate !important;
    animation-delay: calc(var(--t) * -1), calc(var(--t) * -1) !important;
  }
  .hc-visual .hc-zone::after, .hc-visual .hc-frame::after {
    width: 100%; transform: none; opacity: .12; animation: hcEdge 6s ease-in-out infinite !important; animation-delay: var(--t) !important;
  }
}
