/* =====================================================================
   AGGREGATOR HOOKS (#/aggregator). The whole page sits on the dark royal
   ground: the plate under a live field in the hero, then glass cards on the
   same ground with the grain over everything. Scoped to the view, so no
   other page changes. Phone first; the desktop rules come after.
   ===================================================================== */

#view-aggregator {
  --agh-ink: #ffffff;
  --agh-dim: #cfdcf1;
  --agh-faint: #9fb3d6;
  --agh-line: rgba(185, 200, 228, 0.16);
  --agh-glass: rgba(10, 30, 84, 0.46);
  --agh-glass-hi: rgba(20, 48, 116, 0.5);
  --agh-good: #9fd8c4;
  background:
    radial-gradient(120% 60% at 50% 0%, #0d2f78 0%, rgba(13, 47, 120, 0) 60%),
    linear-gradient(180deg, #06153f 0%, #08205a 40%, #071a4d 100%);
  color: var(--agh-ink);
  position: relative;
  overflow: hidden;
}
#view-aggregator h2, #view-aggregator h3 { color: var(--agh-ink); }
#view-aggregator .eyebrow { color: #b3c4e2; }
#view-aggregator .eyebrow .rule { background: rgba(255, 255, 255, 0.22); }
#view-aggregator .eyebrow > span:first-child { color: var(--signal); }
#view-aggregator code { font-family: var(--mono); }

/* the grain over the whole page: the house's own ordered dither, faint, fixed to the viewport */
#view-aggregator .agh-grain {
  position: absolute; inset: 0; pointer-events: none; z-index: 2;
  background-image: url("grain.png"); background-size: 180px 180px;
  opacity: 0.13; mix-blend-mode: overlay;
}

/* ------------------------------------------------------------------ hero */

.agh-hero {
  position: relative; margin-top: -68px; padding: 96px 0 330px;
  display: flex; flex-direction: column; justify-content: flex-start;
  isolation: isolate; overflow: hidden;
}
.agh-plate, .agh-plate img {
  position: absolute; inset: 0; width: 100%; height: 100%; display: block;
}
.agh-plate img { object-fit: cover; object-position: 50% 100%; transition: filter 1400ms var(--ease-out), opacity 1400ms var(--ease-out), transform 1400ms var(--ease-out); }
.agh-plate { z-index: 0; }
/* once the live field is drawing, the plate steps back to the light it gives off, and the field is the picture */
.agh-hero.agh-live .agh-plate img { filter: blur(16px) brightness(0.72) saturate(1.1); opacity: 0.85; transform: scale(1.06); }
.agh-field {
  position: absolute; inset: 0; width: 100%; height: 100%; z-index: 1; display: block;
  opacity: 0; transition: opacity 1400ms var(--ease-out); pointer-events: none;
}
.agh-hero.agh-live .agh-field { opacity: 1; }
.agh-hero[data-field^="retired"] .agh-field { opacity: 0; }
.agh-labels { position: absolute; inset: 0; z-index: 2; pointer-events: none; }
/* a label names a stream that is drawn: none while the field is compiling, retired, lost or never started */
.agh-hero:not(.agh-live) .agh-labels { display: none; }
.agh-label {
  position: absolute; transform: translate(-50%, -50%);
  font-family: var(--mono); font-size: 10.5px; letter-spacing: 0.14em; text-transform: uppercase;
  color: #e6eefb; text-shadow: 0 0 12px rgba(6, 21, 63, 0.9);
  display: flex; flex-direction: column; align-items: center; gap: 2px; white-space: nowrap;
  opacity: 0; animation: agh-fade 1200ms 900ms var(--ease-out) forwards;
}
.agh-label b { font-weight: 400; color: var(--agh-faint); letter-spacing: 0.08em; }
@keyframes agh-fade { to { opacity: 1; } }

/* the words sit on a soft full-bleed scrim so a stream behind them never costs a letter: from the left on a desktop,
   from the top on a phone, never a box */
.agh-hero::before {
  content: ""; position: absolute; inset: 0; z-index: 2; pointer-events: none;
  background: linear-gradient(180deg, rgba(6, 21, 63, 0.82) 0%, rgba(6, 21, 63, 0.62) 42%, rgba(6, 21, 63, 0.18) 68%, rgba(6, 21, 63, 0) 80%);
}
.agh-hero-in { position: relative; z-index: 3; width: 100%; }
.agh-hero h2 { font-size: clamp(34px, 8.6vw, 60px); line-height: 1.04; max-width: 15ch; margin-bottom: 18px; text-wrap: balance; }
.agh-hero .lede { color: var(--agh-dim); font-size: 16.5px; line-height: 1.58; max-width: 54ch; margin-bottom: 24px; }
.agh-hero .cli-install { display: flex; flex-wrap: wrap; gap: 10px; margin: 0 0 18px; }
.agh-hero .btn { min-height: 44px; color: var(--agh-ink); border-color: rgba(255, 255, 255, 0.34); background: rgba(7, 26, 77, 0.55); backdrop-filter: blur(6px); }
.agh-hero .btn:hover { border-color: var(--signal); color: var(--signal); }
/* the state line carries the page's warnings (a watch that stopped, what was not counted), and on a phone it sits on
   the plate's brightest ring, where the hero's scrim has thinned out: it has a soft scrim of its own, feathered into the
   plate and never a box, so every line of it reads in every state without dimming the hero (24 Oct review) */
.agh-state {
  position: relative; isolation: isolate;
  font-family: var(--mono); font-size: 11.5px; letter-spacing: 0.04em; color: var(--agh-dim); margin: 14px 0 0; max-width: 60ch;
}
/* full strength under every line (the words start 26px inside it), fading out over 24px above, below and to each side */
.agh-state::before {
  content: ""; position: absolute; inset: -26px -28px; z-index: -1; pointer-events: none;
  background: linear-gradient(180deg, rgba(6, 21, 63, 0) 0, rgba(6, 21, 63, 0.78) 24px, rgba(6, 21, 63, 0.78) calc(100% - 24px), rgba(6, 21, 63, 0) 100%);
  -webkit-mask-image: linear-gradient(90deg, transparent 0, #000 24px, #000 calc(100% - 24px), transparent 100%);
  mask-image: linear-gradient(90deg, transparent 0, #000 24px, #000 calc(100% - 24px), transparent 100%);
}

.agh-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 6px 0 22px; max-width: 640px; }
.agh-stat {
  border: 1px solid var(--agh-line); background: var(--agh-glass); backdrop-filter: blur(10px) saturate(1.2);
  border-radius: 6px; padding: 12px 14px 11px; min-width: 0;
}
.agh-stat b { display: block; font-family: var(--display); font-weight: 400; font-size: 30px; line-height: 1.05; color: #fff; }
.agh-stat b small { font-size: 17px; color: var(--agh-dim); }
.agh-stat span { display: block; font-family: var(--mono); font-size: 10.5px; letter-spacing: 0.06em; color: var(--agh-faint); margin-top: 6px; line-height: 1.45; }
.agh-stat.agh-good { border-color: rgba(159, 216, 196, 0.28); }
.agh-stat.agh-good b { color: #eafaf3; }
.agh-stat.agh-warn { border-color: rgba(240, 147, 127, 0.55); }

/* -------------------------------------------------------------- sections */

.agh-sect { position: relative; z-index: 3; padding: 56px 0; }
.agh-sect + .agh-sect { border-top: 1px solid var(--agh-line); }
.agh-sect h2 { font-size: clamp(28px, 6.4vw, 44px); margin-bottom: 12px; }
.agh-sect .body { color: var(--agh-dim); max-width: 62ch; }
.agh-empty { font-family: var(--mono); font-size: 12.5px; color: var(--agh-faint); }

.agh-cards { display: grid; grid-template-columns: 1fr; gap: 14px; margin-top: 26px; }
.agh-card {
  border: 1px solid var(--agh-line); border-radius: 8px; padding: 18px 16px 16px; min-width: 0;
  background: linear-gradient(180deg, var(--agh-glass-hi), var(--agh-glass));
  backdrop-filter: blur(12px) saturate(1.2);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.06) inset, 0 24px 60px rgba(2, 8, 30, 0.35);
  animation: agh-rise 700ms calc(var(--i, 0) * 80ms) var(--ease-out) both;
}
@keyframes agh-rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
/* a version string is whatever the contract answers, up to sixty characters with no space: it breaks inside its card */
.agh-card, .agh-look { overflow-wrap: anywhere; }
.agh-card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.agh-card-head h3 { font-size: 26px; margin: 2px 0 6px; overflow-wrap: anywhere; }
.agh-card-kicker { font-family: var(--mono); font-size: 10.5px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--agh-faint); margin: 0; }
.agh-chip {
  flex: none; font-family: var(--mono); font-size: 10px; letter-spacing: 0.1em; text-transform: uppercase;
  padding: 5px 8px; border-radius: 99px; border: 1px solid var(--agh-line); color: var(--agh-dim); white-space: nowrap;
}
.agh-chip-ok { border-color: rgba(159, 216, 196, 0.4); color: var(--agh-good); }
.agh-chip-no { border-color: rgba(240, 147, 127, 0.5); color: var(--signal); }
.agh-addr { margin: 4px 0 10px; font-size: 12px; overflow-wrap: anywhere; word-break: break-all; }
.agh-addr a { color: var(--agh-faint); text-decoration: none; border-bottom: 1px dotted rgba(159, 179, 214, 0.5); }
.agh-addr a:hover { color: #fff; }
.agh-note { font-family: var(--mono); font-size: 11.5px; color: var(--signal); margin: 0 0 12px; line-height: 1.5; }

.agh-figs { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; background: var(--agh-line); border: 1px solid var(--agh-line); border-radius: 6px; overflow: hidden; margin: 6px 0 14px; }
.agh-figs > div { background: rgba(6, 21, 63, 0.55); padding: 10px 12px; min-width: 0; }
.agh-figs b { display: block; font-family: var(--display); font-weight: 400; font-size: 24px; line-height: 1.1; }
.agh-figs span { display: block; font-family: var(--mono); font-size: 10px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--agh-faint); margin-top: 3px; }
.agh-figs em { display: block; font-style: normal; font-family: var(--mono); font-size: 11.5px; color: var(--agh-dim); margin-top: 2px; }
.agh-figs b.agh-fig-off { font-family: var(--mono); font-size: 13px; line-height: 1.85; letter-spacing: 0.04em; color: var(--agh-faint); }

.agh-bars { margin: 0 0 14px; }
.agh-bars svg { display: block; width: 100%; height: 44px; }
.agh-bars rect { fill: rgba(185, 200, 228, 0.75); }
.agh-bars rect:last-child { fill: #ffffff; }
.agh-bars figcaption { font-family: var(--mono); font-size: 10px; letter-spacing: 0.06em; color: var(--agh-faint); margin-top: 4px; }

.agh-checks { display: grid; gap: 8px; margin-bottom: 12px; }
.agh-meter { display: grid; gap: 5px; }
.agh-meter-bar { display: block; height: 3px; background: rgba(185, 200, 228, 0.16); border-radius: 2px; overflow: hidden; }
.agh-meter-bar i { display: block; height: 100%; background: linear-gradient(90deg, #8fb4dd, #ffffff); border-radius: 2px; }
.agh-meter-short .agh-meter-bar i { background: linear-gradient(90deg, var(--signal-lo), var(--signal)); }
.agh-meter-words { font-family: var(--mono); font-size: 11.5px; color: var(--agh-dim); line-height: 1.45; }
.agh-meter-words b { color: #fff; font-weight: 500; }
.agh-meter-empty .agh-meter-words { color: var(--agh-faint); }

.agh-facts { display: grid; grid-template-columns: 1fr; gap: 2px 14px; margin: 0; font-size: 14.5px; }
.agh-facts dt { font-family: var(--mono); font-size: 10px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--agh-faint); margin-top: 8px; }
.agh-facts dd { margin: 0; color: var(--agh-dim); line-height: 1.5; min-width: 0; overflow-wrap: anywhere; }
.agh-facts small { font-family: var(--mono); font-size: 10.5px; color: var(--agh-faint); }
.agh-pairs { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px !important; }
.agh-pairs span { font-family: var(--mono); font-size: 11px; padding: 3px 7px; border: 1px solid var(--agh-line); border-radius: 4px; color: var(--agh-dim); }
.agh-pairs .agh-more { border-style: dashed; color: var(--agh-faint); }

/* the tape: one row per swap, stacked on a phone */
.agh-tape { display: grid; gap: 1px; margin-top: 24px; border: 1px solid var(--agh-line); border-radius: 8px; overflow: hidden; background: var(--agh-line); }
.agh-row {
  display: grid; grid-template-columns: auto 1fr; grid-template-areas: "time usd" "trade trade" "checks checks";
  gap: 4px 12px; padding: 12px 14px; background: rgba(6, 21, 63, 0.72); color: var(--agh-ink); text-decoration: none; min-height: 44px;
  transition: background 200ms var(--ease-out);
}
.agh-row:hover { background: rgba(14, 40, 104, 0.85); }
.agh-row-time { grid-area: time; font-family: var(--mono); font-size: 11px; color: var(--agh-faint); align-self: center; }
.agh-row-usd { grid-area: usd; justify-self: end; font-family: var(--display); font-size: 19px; }
.agh-row-usd small { font-family: var(--mono); font-size: 10.5px; color: var(--agh-faint); }
.agh-row-trade { grid-area: trade; min-width: 0; }
.agh-row-trade b { display: block; font-weight: 500; font-size: 15px; overflow-wrap: anywhere; }
.agh-row-trade small { display: block; font-family: var(--mono); font-size: 10.5px; color: var(--agh-faint); margin-top: 2px; }
.agh-arrow { color: var(--agh-faint); }
.agh-row-checks { grid-area: checks; display: flex; flex-wrap: wrap; gap: 6px; }
.agh-row-checks span { font-family: var(--mono); font-size: 10px; letter-spacing: 0.08em; text-transform: uppercase; padding: 3px 7px; border-radius: 99px; border: 1px solid var(--agh-line); }
.agh-ok { color: var(--agh-good); border-color: rgba(159, 216, 196, 0.35) !important; }
.agh-bad { color: var(--signal); border-color: rgba(240, 147, 127, 0.5) !important; }
.agh-dim { color: var(--agh-faint); }

/* the flagged swaps, each one named with what failed, under the tape */
.agh-flags { margin-top: 34px; }
/* the board names only its newest flagged swaps: when there are more, how many of how many, above the list */
.agh-flags-count { font-family: var(--mono); font-size: 12px; line-height: 1.55; color: var(--agh-dim); margin: -4px 0 12px; max-width: 64ch; }
.agh-flags-list { display: grid; gap: 1px; margin-top: 4px; border: 1px solid rgba(240, 147, 127, 0.38); border-radius: 8px; overflow: hidden; background: rgba(240, 147, 127, 0.22); }
.agh-flag { display: grid; gap: 4px; padding: 12px 14px; background: rgba(6, 21, 63, 0.78); color: var(--agh-ink); text-decoration: none; min-height: 44px; min-width: 0; transition: background 200ms var(--ease-out); }
.agh-flag:hover { background: rgba(14, 40, 104, 0.85); }
.agh-flag-time { font-family: var(--mono); font-size: 11px; color: var(--agh-faint); }
.agh-flag-what { min-width: 0; }
.agh-flag-what b { display: block; font-weight: 500; font-size: 15px; overflow-wrap: anywhere; }
.agh-flag-what code { font-size: 11.5px; color: var(--agh-faint); }
.agh-flag-what small { display: block; font-family: var(--mono); font-size: 11px; line-height: 1.5; color: var(--signal); margin-top: 3px; overflow-wrap: anywhere; }

.agh-looks { display: grid; gap: 12px; margin-top: 22px; }
.agh-look { border: 1px dashed rgba(240, 147, 127, 0.38); border-radius: 8px; padding: 14px 16px; background: rgba(6, 21, 63, 0.5); min-width: 0; }
.agh-look-line { color: var(--agh-dim); margin: 0 0 8px; font-size: 15px; }
.agh-look ul { margin: 0; padding-left: 18px; color: var(--agh-dim); font-size: 14.5px; line-height: 1.55; }

.agh-rules { display: grid; grid-template-columns: 1fr; gap: 4px 28px; margin: 22px 0 0; }
.agh-rules dt { font-family: var(--display); font-size: 22px; color: #fff; margin-top: 18px; }
.agh-rules dd { margin: 6px 0 0; color: var(--agh-dim); line-height: 1.6; font-size: 16px; max-width: 64ch; }
.agh-not { margin-top: 30px; padding: 18px 16px; border: 1px solid var(--agh-line); border-radius: 8px; background: var(--agh-glass); }
.agh-not ul { margin: 8px 0 0; padding-left: 18px; color: var(--agh-dim); line-height: 1.6; }
.agh-words { font-family: var(--mono); font-size: 12px; color: var(--agh-faint); margin-top: 22px; line-height: 1.6; }
.agh-words code { color: #fff; }
.agh-words a { color: #fff; }

#agh-focus:not(:empty) { margin: 0 0 26px; }

/* -------------------------------------------------------------- desktop */

@media (min-width: 761px) {
  .agh-hero { padding: 150px 0 84px; min-height: min(920px, 100svh); justify-content: center; }
  .agh-plate img { object-position: 75% 50%; }
  .agh-hero::before { background: linear-gradient(90deg, rgba(6, 21, 63, 0.86) 0%, rgba(6, 21, 63, 0.66) 34%, rgba(6, 21, 63, 0.12) 56%, rgba(6, 21, 63, 0) 66%); }
  .agh-hero h2 { max-width: 13ch; }
  .agh-hero .lede { font-size: 18px; max-width: 46ch; }
  .agh-stats { grid-template-columns: repeat(3, minmax(0, 1fr)); max-width: 680px; }
  .agh-sect { padding: 88px 0; }
  .agh-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
  .agh-card { padding: 22px 22px 20px; }
  .agh-figs { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .agh-facts { grid-template-columns: 150px 1fr; }
  .agh-facts dt { margin-top: 10px; }
  .agh-facts dd { margin-top: 8px; }
  .agh-row { grid-template-columns: 92px minmax(0, 1fr) 110px 200px; grid-template-areas: "time trade usd checks"; align-items: center; padding: 12px 18px; }
  .agh-row-checks { justify-content: flex-end; }
  .agh-flag { grid-template-columns: 190px minmax(0, 1fr); align-items: baseline; padding: 12px 18px; }
  .agh-looks { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  /* #/aggregator/<hook> lands with the card's head below the fixed bar; a phone has the page's own scroll padding */
  #agh-focus { scroll-margin-top: 80px; }
  .agh-rules { grid-template-columns: 220px 1fr; }
  .agh-rules dd { margin-top: 20px; }
}

@media (prefers-reduced-motion: reduce) {
  .agh-card, .agh-label { animation: none; opacity: 1; }
  .agh-plate img, .agh-field { transition: none; }
}
