/*
 * Nexus.
 *
 * The page has one job -- get you into another service in under two seconds --
 * so the visual budget goes on legibility and on making the target obvious, not
 * on decoration for its own sake. Three effects carry the whole thing:
 *
 *   1. a slow aurora wash behind everything, so the page has depth at rest;
 *   2. a cursor-tracked spotlight on the hovered card, so the thing under your
 *      pointer lights up before you have consciously aimed at it;
 *   3. per-service accent hues, held almost fully desaturated until hover.
 *
 * That last restraint is the whole trick. Sixty saturated tiles is a toybox;
 * sixty quiet tiles where only yours has colour is a tool. Every effect here is
 * transform/opacity only and sits behind prefers-reduced-motion.
 */

/* ============================================================ tokens */

:root {
  color-scheme: dark;

  --bg:          #07080e;
  --bg-deep:     #04050a;
  --panel:       rgba(255, 255, 255, 0.030);
  --panel-hi:    rgba(255, 255, 255, 0.055);
  --line:        rgba(255, 255, 255, 0.075);
  --line-hi:     rgba(255, 255, 255, 0.16);
  --text:        #eef1f8;
  --text-dim:    #98a1b8;
  --text-faint:  #626b83;

  --ok:      #37d399;
  --down:    #fb7185;
  --unknown: #8b94ab;

  /* Aurora blobs. Cyan / violet / magenta -- the Nexus icon's own gradient. */
  --aurora-1: #2b6cff;
  --aurora-2: #7c3cff;
  --aurora-3: #00c8d7;
  --aurora-alpha: 0.30;

  --radius:      18px;
  --radius-sm:   12px;
  --shell:       1400px;
  --ease:        cubic-bezier(0.22, 1, 0.36, 1);

  --font: "Segoe UI Variable Display", "SF Pro Display", -apple-system,
          BlinkMacSystemFont, "Segoe UI", Roboto, Inter, system-ui, sans-serif;
}

:root[data-theme="light"] {
  color-scheme: light;

  --bg:          #f4f6fc;
  --bg-deep:     #e9edf8;
  --panel:       rgba(255, 255, 255, 0.78);
  --panel-hi:    rgba(255, 255, 255, 0.95);
  --line:        rgba(14, 20, 45, 0.085);
  --line-hi:     rgba(14, 20, 45, 0.20);
  --text:        #0d1020;
  --text-dim:    #525b76;
  --text-faint:  #7c85a0;

  --ok:      #0e9f6e;
  --down:    #e11d48;
  --unknown: #8b94ab;

  --aurora-alpha: 0.30;
}

/* ============================================================ base */

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}

/* The aurora. Two fixed layers so they can drift against each other: the page
   never sits on flat black, and nothing here scrolls or repaints with content. */
body::before,
body::after {
  content: "";
  position: fixed;
  inset: -30vmax;
  z-index: -2;
  pointer-events: none;
  will-change: transform;
}

body::before {
  background:
    radial-gradient(38vmax 38vmax at 18% 12%, color-mix(in oklab, var(--aurora-1) calc(var(--aurora-alpha) * 100%), transparent), transparent 62%),
    radial-gradient(44vmax 44vmax at 82% 8%,  color-mix(in oklab, var(--aurora-2) calc(var(--aurora-alpha) * 100%), transparent), transparent 60%);
  animation: drift-a 44s var(--ease) infinite alternate;
}

body::after {
  background:
    radial-gradient(40vmax 40vmax at 72% 78%, color-mix(in oklab, var(--aurora-3) calc(var(--aurora-alpha) * 85%), transparent), transparent 62%),
    radial-gradient(34vmax 34vmax at 10% 88%, color-mix(in oklab, var(--aurora-2) calc(var(--aurora-alpha) * 70%), transparent), transparent 64%);
  animation: drift-b 56s var(--ease) infinite alternate;
}

@keyframes drift-a {
  from { transform: translate3d(-3%, -2%, 0) scale(1);    }
  to   { transform: translate3d( 4%,  3%, 0) scale(1.14); }
}
@keyframes drift-b {
  from { transform: translate3d( 3%,  2%, 0) scale(1.1);  }
  to   { transform: translate3d(-4%, -3%, 0) scale(1);    }
}

/* A single dark vignette over the aurora keeps text contrast constant no matter
   where the blobs happen to have drifted to. */
body > .veil {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background: radial-gradient(120vmax 90vmax at 50% -10%, transparent, var(--bg-deep) 88%);
  opacity: 0.78;
}

:root[data-theme="light"] body > .veil {
  background: radial-gradient(120vmax 90vmax at 50% -10%, rgba(255,255,255,.35), var(--bg-deep) 90%);
  opacity: 0.6;
}

/* ============================================================ shell */

.shell {
  max-width: var(--shell);
  margin: 0 auto;
  padding: 0 24px 96px;
}

/* ============================================================ masthead */

.masthead {
  padding: 68px 0 30px;
  text-align: center;
}

.wordmark {
  display: inline-flex;
  align-items: center;
  gap: 16px;
  margin: 0;
  font-size: clamp(2.6rem, 7vw, 4.4rem);
  font-weight: 700;
  letter-spacing: -0.035em;
  line-height: 1;
}

.wordmark img {
  width: clamp(44px, 8vw, 66px);
  height: auto;
  filter: drop-shadow(0 0 22px rgba(124, 108, 255, 0.45));
}

/* The letterforms carry the icon's gradient, panned slowly. Background-position
   animates on the compositor and the text stays selectable. */
.wordmark span {
  background: linear-gradient(100deg, #8be9ff 0%, #7c6cff 32%, #c46bff 58%, #8be9ff 100%);
  background-size: 260% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: shimmer 14s linear infinite;
}

:root[data-theme="light"] .wordmark span {
  background-image: linear-gradient(100deg, #0f8fb8 0%, #5b3fd6 32%, #a134d4 58%, #0f8fb8 100%);
}

@keyframes shimmer {
  to { background-position: -260% 0; }
}

.tagline {
  margin: 15px auto 0;
  max-width: 44ch;
  color: var(--text-dim);
  font-size: 1rem;
}

/* The running count sits on its own line rather than trailing the tagline:
   inline, it wrapped mid-phrase at most widths and read as a broken sentence. */
.stat {
  margin: 9px 0 0;
  color: var(--text-faint);
  font-size: 0.83rem;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
}

/* ============================================================ command bar */

.commandbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 26px 0 8px;
  padding: 14px 0;
  background: linear-gradient(to bottom, var(--bg) 62%, transparent);
}

.search {
  position: relative;
  flex: 1;
  min-width: 0;
}

.search > svg {
  position: absolute;
  left: 17px;
  top: 50%;
  translate: 0 -50%;
  width: 19px;
  height: 19px;
  color: var(--text-faint);
  pointer-events: none;
  transition: color 0.2s;
}

.search:focus-within > svg { color: #8be9ff; }

#q {
  width: 100%;
  height: 54px;
  padding: 0 116px 0 50px;
  font: inherit;
  font-size: 1rem;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
  outline: none;
  backdrop-filter: blur(20px) saturate(140%);
  -webkit-backdrop-filter: blur(20px) saturate(140%);
  transition: border-color 0.22s, background 0.22s, box-shadow 0.22s;
}

#q::placeholder { color: var(--text-faint); }

#q:focus {
  background: var(--panel-hi);
  border-color: rgba(124, 108, 255, 0.55);
  box-shadow: 0 0 0 4px rgba(124, 108, 255, 0.14);
}

/* The hint doubles as the clear button once there is something to clear. */
.search .hint {
  position: absolute;
  right: 8px;
  top: 50%;
  translate: 0 -50%;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 10px;
  height: 38px;
  color: var(--text-faint);
  font-size: 0.78rem;
  pointer-events: none;
}

kbd {
  display: inline-grid;
  place-items: center;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  font: inherit;
  font-size: 0.72rem;
  color: var(--text-dim);
  background: var(--panel-hi);
  border: 1px solid var(--line);
  border-radius: 6px;
}

.search .clear {
  position: absolute;
  right: 10px;
  top: 50%;
  translate: 0 -50%;
  display: none;
  place-items: center;
  width: 34px;
  height: 34px;
  color: var(--text-dim);
  background: var(--panel-hi);
  border: 1px solid var(--line);
  border-radius: 50%;
  cursor: pointer;
  transition: color 0.18s, border-color 0.18s;
}

.search .clear svg { width: 15px; height: 15px; }
.search .clear:hover { color: var(--text); border-color: var(--line-hi); }

body.searching .search .hint  { display: none; }
body.searching .search .clear { display: grid; }
body.searching #q { padding-right: 54px; }

.iconbtn {
  display: grid;
  place-items: center;
  flex: none;
  width: 54px;
  height: 54px;
  color: var(--text-dim);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 50%;
  cursor: pointer;
  backdrop-filter: blur(20px) saturate(140%);
  -webkit-backdrop-filter: blur(20px) saturate(140%);
  transition: color 0.2s, border-color 0.2s, background 0.2s, transform 0.2s var(--ease);
}

.iconbtn svg { width: 20px; height: 20px; }

.iconbtn:hover {
  color: var(--text);
  background: var(--panel-hi);
  border-color: var(--line-hi);
  transform: translateY(-2px);
}

.iconbtn .moon { display: none; }
:root[data-theme="light"] .iconbtn .sun  { display: none; }
:root[data-theme="light"] .iconbtn .moon { display: block; }

/* ============================================================ sections */

.section { margin-top: 44px; }
.section[hidden] { display: none; }

.section-head {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 18px;
  padding-left: 2px;
}

.section-head h2 {
  margin: 0;
  font-size: 0.82rem;
  font-weight: 650;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text);
}

.section-head p {
  flex: 1;
  min-width: 0;
  margin: 0;
  color: var(--text-faint);
  font-size: 0.85rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.section-head .count {
  flex: none;
  color: var(--text-faint);
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
}

/* ============================================================ grid */

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(232px, 1fr));
  gap: 14px;
}

/* ============================================================ card */

.card {
  position: relative;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 15px 16px;
  color: inherit;
  text-decoration: none;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  isolation: isolate;
  backdrop-filter: blur(16px) saturate(130%);
  -webkit-backdrop-filter: blur(16px) saturate(130%);
  transition: transform 0.28s var(--ease), border-color 0.28s, background 0.28s;
}

/* The spotlight. --mx/--my are written by one delegated pointermove listener on
   the page, not one per card, and only for the card actually under the cursor. */
.card::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  border-radius: inherit;
  opacity: 0;
  background: radial-gradient(
    260px circle at var(--mx, 50%) var(--my, 50%),
    hsl(var(--h) 92% 62% / 0.20),
    transparent 62%
  );
  transition: opacity 0.3s;
}

.card:hover,
.card:focus-visible {
  transform: translateY(-3px);
  background: var(--panel-hi);
  border-color: hsl(var(--h) 85% 62% / 0.42);
}

.card:hover::before,
.card:focus-visible::before { opacity: 1; }

/* The keyboard ring is an outline, not a box-shadow, so that the light theme
   below can own box-shadow for depth without the two fighting over it. */
.card:focus-visible {
  outline: 2px solid hsl(var(--h) 90% 62%);
  outline-offset: 2px;
}

.card:active { transform: translateY(-1px) scale(0.99); }

/* On dark, a 1px border against the aurora is enough to separate a card from
   the page. On light it is not -- white panels on a near-white background need
   a cast shadow or the grid reads as one flat sheet. */
:root[data-theme="light"] .card {
  box-shadow: 0 1px 2px rgba(16, 24, 50, 0.045),
              0 8px 20px -12px rgba(16, 24, 50, 0.16);
}

:root[data-theme="light"] .card:hover,
:root[data-theme="light"] .card:focus-visible {
  box-shadow: 0 2px 6px rgba(16, 24, 50, 0.06),
              0 18px 36px -18px hsl(var(--h) 72% 45% / 0.5);
}

/* -- icon tile -- */

.tile {
  position: relative;
  display: grid;
  place-items: center;
  flex: none;
  width: 44px;
  height: 44px;
  border-radius: var(--radius-sm);
  color: hsl(var(--h) 72% 72%);
  background: hsl(var(--h) 60% 55% / 0.11);
  border: 1px solid hsl(var(--h) 60% 62% / 0.18);
  transition: color 0.28s, background 0.28s, border-color 0.28s, box-shadow 0.28s;
}

:root[data-theme="light"] .tile {
  color: hsl(var(--h) 62% 40%);
  background: hsl(var(--h) 72% 55% / 0.12);
  border-color: hsl(var(--h) 60% 45% / 0.20);
}

.tile svg {
  width: 23px;
  height: 23px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.card:hover .tile,
.card:focus-visible .tile {
  color: hsl(var(--h) 96% 78%);
  background: hsl(var(--h) 82% 58% / 0.22);
  border-color: hsl(var(--h) 82% 66% / 0.45);
  box-shadow: 0 6px 22px -8px hsl(var(--h) 90% 55% / 0.65);
}

:root[data-theme="light"] .card:hover .tile {
  color: hsl(var(--h) 72% 34%);
  background: hsl(var(--h) 85% 58% / 0.20);
}

/* -- text -- */

.meta { min-width: 0; flex: 1; }

.meta .name {
  display: flex;
  align-items: center;
  gap: 7px;
  font-weight: 600;
  font-size: 0.96rem;
  letter-spacing: -0.008em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.meta .desc {
  margin-top: 2px;
  color: var(--text-faint);
  font-size: 0.8rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: color 0.28s;
}

.card:hover .meta .desc { color: var(--text-dim); }

/* A hit inside the name or description, from the search filter. */
mark {
  padding: 0 1px;
  color: inherit;
  background: hsl(var(--h) 90% 60% / 0.26);
  border-radius: 3px;
}

/* -- badges -- */

.lock {
  flex: none;
  width: 12px;
  height: 12px;
  color: var(--text-faint);
  stroke-width: 2;
}

/* -- status dot -- */

.dot {
  position: absolute;
  top: 13px;
  right: 13px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--unknown);
  transition: background 0.3s, box-shadow 0.3s;
}

.card[data-state="up"]   .dot { background: var(--ok);   box-shadow: 0 0 0 3px hsl(160 84% 45% / 0.16); }
.card[data-state="down"] .dot { background: var(--down); box-shadow: 0 0 0 3px hsl(351 95% 65% / 0.18); }
.card[data-state="none"] .dot { opacity: 0; }

/* Only the live ones breathe, and only while the tab is visible. */
.card[data-state="up"] .dot { animation: breathe 3.4s ease-in-out infinite; }

/* The floor is 0.62, not something lower: a 6px dot dimmed much further reads
   as grey rather than green, and "running" would stop being legible at a
   glance for half of every cycle. */
@keyframes breathe {
  0%, 100% { opacity: 1;    }
  50%      { opacity: 0.62; }
}

/* A stopped service still opens -- it might just be slow to report -- but it
   should not look equal to a healthy one. */
.card[data-state="down"] { opacity: 0.62; }
.card[data-state="down"]:hover { opacity: 1; }

/* -- pin -- */

.pin {
  position: absolute;
  top: 8px;
  right: 8px;
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  padding: 0;
  color: var(--text-faint);
  background: transparent;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.2s, color 0.2s, background 0.2s, transform 0.2s var(--ease);
}

.pin svg {
  width: 14px;
  height: 14px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linejoin: round;
}

.card:hover .pin,
.card:focus-within .pin,
.pin:focus-visible { opacity: 1; }

.pin:hover {
  color: #ffd166;
  background: var(--panel-hi);
  transform: scale(1.12);
}

/* Pinned stays visible, and the dot moves aside to make room for it. */
.card.pinned .pin { opacity: 1; color: #ffc94d; }
.card.pinned .pin svg { fill: currentColor; }
.card.pinned .dot { right: 40px; }

/* ============================================================ empty state */

.empty {
  padding: 72px 20px;
  text-align: center;
  color: var(--text-faint);
}

.empty strong {
  display: block;
  margin-bottom: 6px;
  color: var(--text);
  font-size: 1.05rem;
}

.empty[hidden] { display: none; }

/* ============================================================ footer */

.footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px 18px;
  margin-top: 60px;
  padding-top: 26px;
  border-top: 1px solid var(--line);
  color: var(--text-faint);
  font-size: 0.8rem;
}

.footer .legend {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.footer .legend i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--unknown);
}

.footer .legend.up   i { background: var(--ok);   }
.footer .legend.down i { background: var(--down); }

/* ============================================================ entrance */

/* Staggered reveal on first paint only. --i is set inline per card, capped so a
   sixty-card wall finishes in well under a second. */
@media (prefers-reduced-motion: no-preference) {
  body.booting .card {
    animation: rise 0.5s var(--ease) both;
    animation-delay: calc(var(--i, 0) * 14ms);
  }
  @keyframes rise {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: none; }
  }
}

/* ============================================================ responsive */

@media (max-width: 860px) {
  .shell { padding: 0 16px 72px; }
  .masthead { padding: 44px 0 22px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 11px; }
  .section-head p { display: none; }
}

@media (max-width: 560px) {
  body { font-size: 14px; }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }

  /* Two across on a phone only works if the card goes vertical -- side by side
     the label gets about nine characters before it ellipses. */
  .card {
    flex-direction: column;
    align-items: flex-start;
    gap: 11px;
    padding: 14px;
  }
  .meta .name { font-size: 0.9rem; }
  .meta .desc { white-space: normal; line-height: 1.35; }
  .card.pinned .dot { right: 36px; }

  /* Pointer-tracked spotlights mean nothing without a pointer. */
  .card::before { display: none; }

  /* The hint is hidden down here, so the room the desktop reserves for it on
     the right has to come back -- otherwise the placeholder is clipped by
     ~100px of empty padding. */
  .search .hint { display: none; }
  #q { height: 50px; padding-left: 46px; padding-right: 18px; }
  body.searching #q { padding-right: 50px; }
  .iconbtn { width: 50px; height: 50px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
