:root {
  --deep: #010d1c;
  --ocean: #011829;
  --sea: #4da2ff;
  --aqua: #c0e6ff;
  --ink: #eaf4ff;
  --muted: #7c97b6;
  --dim: #3f5b7c;
  --line: rgba(77, 162, 255, 0.18);
  --up: #3ddc97;
  --down: #ff7b7b;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --sans: "Inter Tight", Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { min-height: 100%; }

body {
  background: var(--deep);
  color: var(--ink);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* deep-water backdrop with a soft glow where SUI sits */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -2;
  background: radial-gradient(ellipse 70% 60% at 50% 48%, #07335f 0%, #021c36 45%, var(--deep) 100%);
}

/* ---------- rising bubbles ---------- */
.bubbles { position: fixed; inset: 0; z-index: -1; overflow: hidden; pointer-events: none; }
.bubble {
  position: absolute;
  bottom: -6vh;
  left: var(--x);
  width: var(--s);
  height: var(--s);
  border-radius: 50%;
  border: 1px solid rgba(77, 162, 255, 0.35);
  background: radial-gradient(circle at 35% 35%, rgba(192, 230, 255, 0.35), rgba(77, 162, 255, 0.04) 70%);
  animation: rise var(--d) linear var(--delay) infinite;
  will-change: transform, opacity;
}
@keyframes rise {
  0%   { transform: translate3d(0, 0, 0); opacity: 0; }
  8%   { opacity: 0.8; }
  92%  { opacity: 0.45; }
  100% { transform: translate3d(var(--sway), -118vh, 0); opacity: 0; }
}

/* ---------- header ---------- */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 28px;
}
.brand {
  display: flex; align-items: center; gap: 9px;
  color: var(--ink); text-decoration: none;
  font-weight: 700; font-size: 18px; letter-spacing: -0.02em;
}
.brand svg { width: 17px; height: auto; color: var(--sea); }
.status {
  display: flex; align-items: center; gap: 22px;
  font-family: var(--mono); font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--muted);
}
.toggle { display: flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; }
.toggle input {
  appearance: none; -webkit-appearance: none;
  width: 28px; height: 16px; border-radius: 99px;
  background: var(--dim); position: relative; cursor: pointer; transition: background 0.2s;
}
.toggle input::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 12px; height: 12px;
  border-radius: 50%; background: var(--ink); transition: transform 0.2s;
}
.toggle input:checked { background: var(--sea); }
.toggle input:checked::after { transform: translateX(12px); }
.share {
  display: inline-flex; align-items: center; gap: 7px;
  background: none; border: 0; padding: 0; cursor: pointer;
  color: var(--muted); font: inherit; letter-spacing: inherit; text-transform: inherit;
  transition: color 0.2s;
}
.share:hover, .share.done { color: var(--aqua); }
.share svg { width: 13px; height: 13px; }
.live { display: flex; align-items: center; gap: 8px; }
.dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--up); box-shadow: 0 0 8px var(--up);
  animation: blink 2.4s ease-in-out infinite;
}
.live.off .dot { background: var(--down); box-shadow: none; animation: none; }
@keyframes blink { 50% { opacity: 0.35; } }

/* ---------- stage ---------- */
.stage {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 0 0 40px;
  gap: 28px;
}
/* the whole ranking lives in one horizontal scroller; SUI is centred on load */
.scroller {
  width: 100%;
  overflow-x: auto; overflow-y: hidden;
  scrollbar-width: none;
  cursor: grab;
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 5%, #000 95%, transparent);
          mask-image: linear-gradient(90deg, transparent, #000 5%, #000 95%, transparent);
}
.scroller::-webkit-scrollbar { display: none; }
.scroller { user-select: none; -webkit-user-select: none; }
.scroller img, .scroller svg { -webkit-user-drag: none; user-drag: none; pointer-events: none; }
.scroller.dragging { cursor: grabbing; scroll-behavior: auto; }
.scroller.dragging * { pointer-events: none; }
.row {
  display: flex; align-items: center;
  width: max-content;
  gap: clamp(14px, 3vw, 44px);
  padding: 34px 12vw 12px;
}

@keyframes in {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: var(--o, 1); transform: none; }
}

/* neighbours */
.side {
  --o: 1;
  position: relative;
  display: flex; flex-direction: column; align-items: center; text-align: center;
  gap: 5px; min-width: 112px;
  opacity: 0;
  animation: in 0.7s cubic-bezier(0.2, 0.7, 0.2, 1) forwards;
  animation-delay: calc(min(var(--i), 6) * 90ms + 120ms);
}
.side.d1 { --l: 78px; }
.side.d2 { --l: 58px; --o: 0.78; }
.side.d3 { --l: 46px; --o: 0.6; }

.side .rank { font-family: var(--mono); font-size: 13px; letter-spacing: 0.04em; color: var(--muted); }
.logo {
  position: relative; width: var(--l, 72px); height: var(--l, 72px); border-radius: 50%;
  background: #0b2b4f; display: grid; place-items: center; overflow: hidden;
  font-weight: 700; color: var(--muted); font-size: calc(var(--l, 72px) * 0.4);
  box-shadow: 0 0 0 1px var(--line);
}
.logo img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.side .sym { font-weight: 700; font-size: 18px; letter-spacing: -0.01em; margin-top: 4px; }
.side .nm {
  font-size: 12px; color: var(--muted); margin-top: -4px;
  white-space: nowrap; max-width: 150px; overflow: hidden; text-overflow: ellipsis;
}
.side .gap {
  font-weight: 700; font-size: 25px; letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums; margin-top: 6px; white-space: nowrap;
}
.side.ahead .gap { color: var(--sea); }
.side.behind .gap { color: var(--muted); }
.side .tag {
  font-family: var(--mono); font-size: 10px; letter-spacing: 0.12em;
  text-transform: uppercase; color: var(--dim);
}
.side.d2 .gap { font-size: 20px; }
.side.d3 .gap { font-size: 17px; }
.side.d3 .sym { font-size: 15px; }

/* the one right above SUI */
.side.next::before {
  content: attr(data-next);
  position: absolute; top: -26px; left: 50%; transform: translateX(-50%);
  font-family: var(--mono); font-size: 10px; letter-spacing: 0.16em; text-transform: uppercase;
  color: var(--aqua); padding: 3px 9px; border-radius: 99px;
  border: 1px solid var(--line); background: rgba(77, 162, 255, 0.08);
}
.side.next .logo { box-shadow: 0 0 0 1px rgba(77, 162, 255, 0.5), 0 0 30px rgba(77, 162, 255, 0.25); }

/* hero */
.hero {
  position: relative;
  display: flex; flex-direction: column; align-items: center; text-align: center;
  padding: 0 clamp(8px, 2vw, 32px);
  opacity: 0;
  animation: in 0.9s cubic-bezier(0.2, 0.7, 0.2, 1) forwards;
}
.halo {
  position: absolute; top: 0; left: 50%; z-index: -1;
  width: min(50vw, 460px); aspect-ratio: 1; transform: translateX(-50%);
  border-radius: 50%; pointer-events: none;
  background: radial-gradient(circle, rgba(77, 162, 255, 0.3), rgba(77, 162, 255, 0) 62%);
  filter: blur(18px);
  animation: breathe 5.5s ease-in-out infinite;
}
@keyframes breathe { 50% { transform: translateX(-50%) scale(1.12); opacity: 0.75; } }
.sui {
  width: clamp(96px, 14vw, 168px); height: auto; color: var(--sea);
  filter: drop-shadow(0 0 28px rgba(77, 162, 255, 0.45));
}
.hero-rank {
  margin-top: 10px;
  font-size: clamp(120px, 20vw, 230px); font-weight: 900; line-height: 1; letter-spacing: -0.06em;
  padding: 0.06em 0.12em 0.04em 0.04em; margin: 0 -0.08em -0.08em 0; /* room for glyphs outside the line box (negative tracking + clip:text) */
  font-variant-numeric: tabular-nums;
  background: linear-gradient(180deg, #fff 0%, var(--aqua) 55%, var(--sea) 120%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.hero-name { margin-top: 14px; font-size: clamp(26px, 3vw, 36px); font-weight: 700; letter-spacing: 0.14em; padding-left: 0.14em; }
.hero-mcap {
  margin-top: 14px;
  display: flex; align-items: baseline; gap: 12px;
  font-size: clamp(22px, 2.4vw, 30px); font-weight: 600; letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
}
.chg { font-family: var(--mono); font-size: 13px; }
.chg.up { color: var(--up); }
.chg.down { color: var(--down); }
.hero .lbl {
  margin-top: 4px;
  font-family: var(--mono); font-size: 10px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--dim);
}

/* progress to the next one */
.progress {
  width: min(560px, 90vw);
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  opacity: 0;
  animation: in 0.8s 0.55s cubic-bezier(0.2, 0.7, 0.2, 1) forwards;
}
.bar {
  width: 100%; height: 5px; border-radius: 99px;
  background: rgba(77, 162, 255, 0.14); overflow: hidden;
}
.fill {
  position: relative; overflow: hidden;
  height: 100%; width: 0; border-radius: 99px;
  background: linear-gradient(90deg, var(--sea), var(--aqua));
  box-shadow: 0 0 16px rgba(77, 162, 255, 0.6);
  transition: width 1.8s cubic-bezier(0.2, 0.8, 0.2, 1);
}
/* motion over the gradient, opacity only: diagonal stripes drifting forward, plus an occasional sheen */
.fill::before {
  content: ""; position: absolute; inset: 0;
  background-image: linear-gradient(
    45deg,
    rgba(255, 255, 255, 0.35) 25%, transparent 25%, transparent 50%,
    rgba(255, 255, 255, 0.35) 50%, rgba(255, 255, 255, 0.35) 75%, transparent 75%, transparent
  );
  background-size: 14px 14px;
  animation: stripes 1.4s linear infinite;
}
@keyframes stripes { from { background-position: 0 0; } to { background-position: 14px 0; } }
.fill::after {
  content: ""; position: absolute; top: 0; bottom: 0; left: -25%; width: 25%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.6), transparent);
  animation: sheen 5s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}
@keyframes sheen { 0% { left: -25%; } 45%, 100% { left: 110%; } }
.caption {
  font-family: var(--mono); font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--muted); text-align: center; line-height: 1.8;
}
.caption b { color: var(--aqua); font-weight: 500; }
.caption .note { color: var(--dim); }

/* empty / error */
.empty {
  display: flex; flex-direction: column; align-items: center; gap: 18px;
  font-family: var(--mono); font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted);
}
.empty .sui { animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.45; } }

/* quiet "SUI is over there" pill, shown only while the hero is off-screen */
.back {
  position: fixed; z-index: 6; bottom: 26px; left: 26px;
  display: inline-flex; align-items: center; gap: 7px;
  padding: 7px 12px 7px 10px; border-radius: 99px;
  border: 1px solid var(--line); background: rgba(1, 24, 41, 0.7);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  color: var(--aqua); font: 500 11px/1 var(--mono); letter-spacing: 0.08em;
  cursor: pointer; opacity: 0; transition: opacity 0.35s, transform 0.35s; transform: translateY(6px);
}
.back[hidden] { display: none; }
.back.on { opacity: 0.8; transform: none; }
.back:hover { opacity: 1; border-color: rgba(77, 162, 255, 0.45); }
.back svg { width: 11px; height: auto; color: var(--sea); }
.back .arr { width: 6px; height: 6px; border-left: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor; transform: rotate(45deg); opacity: 0.8; }
.back.right { left: auto; right: 26px; flex-direction: row-reverse; }
.back.right .arr { transform: rotate(-135deg); }
.back.up { left: 50%; right: auto; bottom: auto; top: 66px; transform: translate(-50%, -6px); }
.back.up.on { transform: translate(-50%, 0); }
.back.up .arr { transform: rotate(135deg); }
.back.down { left: 50%; right: auto; top: auto; bottom: 96px; transform: translate(-50%, 6px); }
.back.down.on { transform: translate(-50%, 0); }
.back.down .arr { transform: rotate(-45deg); }

/* ---------- responsive ---------- */
@media (max-width: 860px) {
  .top { padding: 16px 18px; }
  .status { gap: 14px; font-size: 10px; }
  .status .toggle span { white-space: nowrap; }
  .top { background: rgba(1, 13, 28, 0.88); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); }
  .stage { gap: 24px; padding: 0 16px 28px; justify-content: flex-start; }
  .scroller { overflow: visible; cursor: default; -webkit-mask-image: none; mask-image: none; }
  .row { flex-direction: column; gap: 10px; width: 100%; padding: 0; }

  .side, .side.d1, .side.d2, .side.d3 {
    display: grid;
    grid-template-columns: 40px 40px 1fr auto;
    grid-template-rows: auto auto;
    align-items: center; text-align: left;
    gap: 0 12px; width: min(100%, 440px); min-width: 0;
    padding: 9px 14px; border-radius: 14px;
    background: rgba(77, 162, 255, 0.05);
    box-shadow: 0 0 0 1px var(--line);
    --l: 40px; --o: 1;
  }
  .side .rank { grid-row: 1 / 3; font-size: 12px; }
  .side .logo { grid-row: 1 / 3; }
  .side .sym { grid-column: 3; grid-row: 1; font-size: 16px; margin: 0; }
  .side .nm { grid-column: 3; grid-row: 2; margin: 0; }
  .side .gap, .side.d2 .gap, .side.d3 .gap { grid-column: 4; grid-row: 1; font-size: 19px; margin: 0; text-align: right; }
  .side .tag { grid-column: 4; grid-row: 2; text-align: right; }
  .side.next::before { top: -9px; left: auto; right: 14px; transform: none; font-size: 9px; padding: 2px 7px; }
  .side.next .logo { box-shadow: 0 0 0 1px var(--line); }

  .hero { padding: 22px 0 12px; }
  .hero-rank { font-size: clamp(110px, 32vw, 160px); }
  .progress { position: sticky; bottom: 0; padding: 14px 0 18px; background: linear-gradient(180deg, rgba(1, 13, 28, 0), rgba(1, 13, 28, 0.97) 30%); }
}

@media (max-width: 480px) {
  .live #updated { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .bubble, .halo, .dot, .empty .sui, .fill::before, .fill::after { animation: none; }
  .side, .hero, .progress { animation-duration: 0.01s; animation-delay: 0s; }
  .fill { transition: none; }
}
