/* ============================================================
   词语星云 · Word Nebula
   Deep-space galaxy where every word is a planet sized by frequency.
   ============================================================ */

:root {
  color-scheme: dark;

  /* Space background */
  --space-0: #010207;
  --space-1: #030611;
  --space-2: #070a1f;

  /* Nebula accent hues */
  --neb-magenta: #ff4d8d;
  --neb-violet: #7b5cff;
  --neb-cyan: #38e6ff;
  --neb-teal: #24ffc3;
  --neb-gold: #ffd166;

  /* UI */
  --text: #eaf0ff;
  --muted: #93a0c8;
  --glass: rgba(14, 18, 40, 0.55);
  --glass-strong: rgba(10, 13, 30, 0.82);
  --line: rgba(150, 180, 255, 0.16);
  --line-bright: rgba(150, 190, 255, 0.4);
  --accent: var(--neb-cyan);
  --ok: #37f5b0;
  --danger: #ff6b8a;

  --hud-radius: 16px;
  --ease: cubic-bezier(0.22, 0.75, 0.24, 1);

  font-family: "Inter", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC",
    sans-serif;
}

* {
  box-sizing: border-box;
}

/* The [hidden] attribute must win even over elements that set their own
   display (.empty-state and .tooltip both use display + hidden). */
[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  overflow: hidden;
  color: var(--text);
  background:
    radial-gradient(115% 82% at 50% 8%, #090c24 0%, var(--space-1) 44%, var(--space-0) 100%),
    var(--space-0);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button,
textarea {
  font: inherit;
  color: inherit;
}

/* ============================================================
   Stage & background layers
   ============================================================ */

.stage {
  position: fixed;
  inset: 0;
  overflow: hidden;
  touch-action: none;
  cursor: grab;
}

/* A dark edge falloff gives the shared sky more depth without dimming the
   planets, orbiting words, or interface that sit above it. */
.stage::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background: radial-gradient(
    ellipse 78% 72% at 50% 46%,
    transparent 18%,
    rgba(1, 2, 10, 0.1) 58%,
    rgba(0, 1, 6, 0.68) 100%
  );
}

.stage.is-dragging {
  cursor: grabbing;
}

.starfield {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  opacity: 0.72;
  pointer-events: none;
}

/* Soft, drifting nebula clouds (GPU-composited) */
.nebula {
  position: absolute;
  inset: -12%;
  z-index: 0;
  pointer-events: none;
  filter: blur(68px) saturate(88%);
  mix-blend-mode: screen;
  opacity: 0.22;
}

.cloud {
  position: absolute;
  display: block;
  border-radius: 50%;
  opacity: 0.42;
  will-change: transform;
}

/* Give the selected view the frame budget during its first layout/paint burst. */
body.is-view-switching .cloud,
body.is-history-open .cloud {
  animation-play-state: paused;
}

.cloud-a {
  width: 62vmax;
  height: 62vmax;
  left: -6%;
  top: -8%;
  background: radial-gradient(circle at 50% 50%, rgba(123, 92, 255, 0.72), transparent 62%);
  animation: drift-a 46s var(--ease) infinite;
}

.cloud-b {
  width: 54vmax;
  height: 54vmax;
  right: -8%;
  top: 6%;
  background: radial-gradient(circle at 50% 50%, rgba(255, 77, 141, 0.5), transparent 60%);
  animation: drift-b 58s var(--ease) infinite;
}

.cloud-c {
  width: 66vmax;
  height: 66vmax;
  left: 18%;
  bottom: -22%;
  background: radial-gradient(circle at 50% 50%, rgba(56, 230, 255, 0.42), transparent 62%);
  animation: drift-c 52s var(--ease) infinite;
}

.cloud-d {
  width: 40vmax;
  height: 40vmax;
  right: 12%;
  bottom: -10%;
  background: radial-gradient(circle at 50% 50%, rgba(36, 255, 195, 0.34), transparent 60%);
  animation: drift-d 64s var(--ease) infinite;
}

.cloud-e {
  width: 48vmax;
  height: 48vmax;
  left: 34%;
  top: 22%;
  background: radial-gradient(circle at 50% 50%, rgba(255, 209, 102, 0.22), transparent 64%);
  animation: drift-e 72s var(--ease) infinite;
}

@keyframes drift-a {
  0%, 100% { transform: translate3d(0, 0, 0) scale(1); }
  50% { transform: translate3d(6%, 4%, 0) scale(1.12); }
}
@keyframes drift-b {
  0%, 100% { transform: translate3d(0, 0, 0) scale(1.05); }
  50% { transform: translate3d(-7%, 5%, 0) scale(0.92); }
}
@keyframes drift-c {
  0%, 100% { transform: translate3d(0, 0, 0) scale(1); }
  50% { transform: translate3d(4%, -6%, 0) scale(1.14); }
}
@keyframes drift-d {
  0%, 100% { transform: translate3d(0, 0, 0) scale(0.96); }
  50% { transform: translate3d(-5%, -4%, 0) scale(1.1); }
}
@keyframes drift-e {
  0%, 100% { transform: translate3d(0, 0, 0) scale(1); }
  50% { transform: translate3d(5%, 6%, 0) scale(1.16); }
}

.nebula-layer {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
}

/* Calm / read mode freezes ambient drift so labels are easy to read. */
.is-calm .cloud {
  animation-play-state: paused;
}

/* Orbit rings (planets around the star, plus the belt) — inside the layer so
   they pan and zoom with the bodies that travel along them. */
.orbits {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
}
.orbit {
  position: absolute;
  left: 50%;
  top: 50%;
  border: 1px solid rgba(150, 190, 255, 0.11);
  border-radius: 50%;
  pointer-events: none;
}
.orbit-belt {
  border-style: dashed;
  border-color: rgba(150, 190, 255, 0.08);
}

/* ============================================================
   View switch + Treemap (default "quickly find hot" view)
   ============================================================ */

.viewswitch {
  pointer-events: auto;
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--glass);
  backdrop-filter: blur(12px);
}
.view-btn {
  border: none;
  border-radius: 999px;
  padding: 6px 14px;
  color: var(--muted);
  background: transparent;
  font-size: 0.82rem;
  cursor: pointer;
  transition: color 0.2s ease, background 0.2s ease;
}
.view-btn.is-active {
  color: #041018;
  font-weight: 800;
  background: linear-gradient(120deg, var(--neb-cyan), var(--neb-teal));
}

.treemap {
  position: absolute;
  left: 0;
  right: 0;
  top: 84px; /* clear the HUD */
  bottom: 12px;
  z-index: 3;
  padding: 6px;
}

.tile {
  position: absolute;
  border-radius: 12px;
  overflow: hidden;
  padding: 7px 10px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 4px;
  cursor: pointer;
  color: rgba(248, 250, 255, 0.97);
  /* Meteorological thermal color (blue→red→dark) with a soft top-light + bottom
     shade for depth, so it reads as a temperature map rather than a flat block. */
  background: linear-gradient(
      157deg,
      rgba(255, 255, 255, 0.16),
      rgba(255, 255, 255, 0) 32%,
      rgba(0, 0, 0, 0.32)
    ),
    rgb(var(--c, 44 64 116));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.09),
    inset 0 0 0 1px rgba(255, 255, 255, 0.05),
    0 0 calc(var(--n, 0) * 30px) rgb(var(--cg, 44 64 116) / calc(var(--n, 0) * 0.55)),
    0 8px 20px rgba(0, 0, 0, 0.42);
  transition: transform 0.55s var(--ease), background 0.5s var(--ease),
    box-shadow 0.5s var(--ease), opacity 0.5s var(--ease);
}
.tile.is-flipping {
  will-change: transform;
}
.tile-word {
  font-weight: 620;
  letter-spacing: 0.01em;
  line-height: 1.08;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.55);
}
.tile-foot {
  display: flex;
  align-items: baseline;
  gap: 6px;
}
.tile-count {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: rgba(255, 255, 255, 0.66);
}
.tile-trend {
  font-size: 0.72rem;
  font-variant-numeric: tabular-nums;
  opacity: 0.95;
}
.tile-trend.is-up {
  color: #b7ffd8;
}
.tile-trend.is-down {
  color: #ffcaa0;
}
.tile-trend.is-new {
  color: #fff2b0;
  font-weight: 800;
}
.tile.is-sm .tile-trend {
  display: none;
}
.tile.is-tiny {
  padding: 4px;
  align-items: center;
  justify-content: center;
}
.tile.is-tiny > * {
  display: none;
}
.tile.is-new-tile {
  box-shadow: inset 0 0 0 1px hsla(46, 88%, 70%, 0.55), 0 0 20px hsla(46, 85%, 58%, 0.24),
    0 8px 22px rgba(0, 0, 0, 0.45);
}
.tile:hover {
  filter: brightness(1.08);
  z-index: 50;
}
.tile:focus-visible {
  outline: none;
  box-shadow: inset 0 0 0 3px var(--neb-cyan), 0 6px 18px rgba(0, 0, 0, 0.34);
  z-index: 50;
}
.tile.is-entering {
  opacity: 0;
  transform: scale(0.6);
}

/* Mode visibility */
body.mode-treemap .nebula-layer {
  display: none;
}
body.mode-nebula .treemap {
  display: none;
}
/* In treemap mode the tiles ARE the ranked/trend data layer, so the hot list is
   redundant — hide it (and shrink the console) to avoid covering the top tiles. */
body.mode-treemap .hot {
  display: none;
}

/* ============================================================
   Planets
   ============================================================ */

.planet {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 3;
  width: var(--d, 60px);
  height: var(--d, 60px);
  margin-left: calc(var(--d, 60px) / -2);
  margin-top: calc(var(--d, 60px) / -2);
  display: grid;
  place-items: center;
  pointer-events: auto;
  cursor: pointer;
  will-change: transform;
  transition: width 0.85s var(--ease), height 0.85s var(--ease),
    margin-left 0.85s var(--ease), margin-top 0.85s var(--ease);
}

/* Soft, gaseous orb: a glowing core fading to transparent, additively blended so
   overlapping planets merge into nebula gas instead of hard-occluding (which also
   removes the z-fight "flicker" when orbits cross). */
.planet-body {
  position: absolute;
  inset: -8%;
  border-radius: 50%;
  background: radial-gradient(
    circle at 42% 38%,
    hsla(var(--hue), 95%, 92%, 0.92) 0%,
    hsla(var(--hue), var(--sat, 70%), calc(var(--light, 58%) + 8%), 0.62) 26%,
    hsla(var(--hue), var(--sat, 70%), var(--light, 58%), 0.24) 50%,
    hsla(var(--hue2, var(--hue)), 80%, 44%, 0.06) 70%,
    hsla(var(--hue2, var(--hue)), 80%, 40%, 0) 82%
  );
  transition: transform 0.5s var(--ease);
}

/* A small soft specular so it still reads as a body, not a flat disc. */
.planet-body::after {
  content: "";
  position: absolute;
  inset: 18%;
  border-radius: 50%;
  background: radial-gradient(circle at 34% 28%, rgba(255, 255, 255, 0.5), transparent 40%);
  mix-blend-mode: screen;
  opacity: 0.5;
}

/* The brightest word is a luminous star: a white-hot core bleeding into color. */
.planet.is-star .planet-body {
  background: radial-gradient(
    circle at 44% 40%,
    rgba(255, 255, 255, 0.98) 0%,
    hsla(var(--hue), 96%, 84%, 0.82) 18%,
    hsla(var(--hue), var(--sat, 70%), var(--light, 58%), 0.44) 40%,
    hsla(var(--hue2, var(--hue)), 88%, 48%, 0.12) 64%,
    hsla(var(--hue2, var(--hue)), 88%, 42%, 0) 80%
  );
}

/* Rings are reserved for the big "giant" planets so the dwarf field stays clean. */
.planet-ring {
  display: none;
  position: absolute;
  left: 50%;
  top: 50%;
  width: calc(var(--d) * 1.7);
  height: calc(var(--d) * 0.5);
  transform: translate(-50%, -50%) rotate(-24deg);
  border-radius: 50%;
  border: 2px solid hsla(var(--hue), 100%, 82%, 0.5);
  box-shadow: 0 0 14px hsla(var(--hue), 100%, 70%, 0.35);
  opacity: 0.7;
  pointer-events: none;
}

/* The decorative planet ring is now reserved for the central star; the orbiting
   moons and orbit rings convey structure for the other giants. */
.planet.is-star .planet-ring {
  display: block;
}

.planet-label {
  position: relative;
  z-index: 2;
  max-width: 168px;
  padding: 0 2px;
  font-weight: 650;
  font-size: clamp(11px, calc(var(--d) * 0.24), 30px);
  line-height: 1.05;
  color: #f7faff;
  text-align: center;
  letter-spacing: 0.01em;
  white-space: nowrap;
  pointer-events: none;
  text-shadow:
    0 1px 3px rgba(0, 0, 0, 0.85),
    0 0 10px rgba(0, 0, 0, 0.7),
    0 0 22px hsla(var(--hue), 100%, 60%, 0.45);
  transition: opacity 0.6s var(--ease);
}

/* Tiny planets: label sits just below the sphere so it stays readable */
.planet.is-dwarf .planet-label {
  position: absolute;
  top: calc(100% + 2px);
  font-size: 11px;
  opacity: var(--label-opacity, 0.72);
}

.planet:hover {
  z-index: 5000 !important;
}

.planet:hover .planet-body {
  transform: scale(1.06);
}

.planet:hover .planet-label {
  opacity: 1;
}

/* Entrance: a planet is born */
.planet.is-entering .planet-body {
  transform: scale(0.05);
  opacity: 0;
}
.planet.is-entering .planet-label {
  opacity: 0;
}

.planet-body {
  animation: none;
}

.planet.is-born .planet-body {
  animation: planet-birth 1.05s var(--ease) both;
}

.planet.is-pulse .planet-body {
  animation: planet-pulse 0.9s var(--ease);
}

.planet.is-leaving {
  pointer-events: none;
}
.planet.is-leaving .planet-body {
  transform: scale(0.02);
  opacity: 0;
  transition: transform 0.7s var(--ease), opacity 0.7s var(--ease);
}
.planet.is-leaving .planet-label {
  opacity: 0;
}

/* Birth flare ring */
.planet-flare {
  position: absolute;
  left: 50%;
  top: 50%;
  width: var(--d);
  height: var(--d);
  transform: translate(-50%, -50%);
  border-radius: 50%;
  pointer-events: none;
  box-shadow: 0 0 0 2px hsla(var(--hue), 100%, 85%, 0.9);
  opacity: 0;
}
.planet.is-born .planet-flare {
  animation: flare-out 1s var(--ease) both;
}

@keyframes planet-birth {
  0% { transform: scale(0.05); opacity: 0; }
  55% { transform: scale(1.18); opacity: 1; }
  75% { transform: scale(0.94); }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes planet-pulse {
  0% { transform: scale(1); filter: brightness(1); }
  30% { transform: scale(1.16); filter: brightness(1.45); }
  100% { transform: scale(1); filter: brightness(1); }
}

@keyframes flare-out {
  0% { opacity: 0.95; transform: translate(-50%, -50%) scale(0.6); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(2.7); }
}

/* ============================================================
   Tooltip
   ============================================================ */

.tooltip {
  position: absolute;
  z-index: 6000;
  padding: 6px 10px;
  border: 1px solid var(--line-bright);
  border-radius: 10px;
  background: var(--glass-strong);
  backdrop-filter: blur(10px);
  color: var(--text);
  font-size: 0.82rem;
  white-space: nowrap;
  pointer-events: none;
  transform: translate(-50%, -130%);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
}
.tooltip b {
  color: var(--accent);
}
.tooltip-trend.is-new {
  color: var(--neb-gold);
}
.tooltip-trend.is-up {
  color: var(--ok);
}
.tooltip-trend.is-down {
  color: #ff9d5c;
}

/* ============================================================
   Exact word-history dialog
   ============================================================ */

.history-dialog {
  width: min(940px, calc(100vw - 32px));
  max-width: none;
  max-height: min(820px, calc(100dvh - 32px));
  margin: auto;
  padding: 0;
  overflow: hidden;
  border: 1px solid rgba(145, 194, 255, 0.3);
  border-radius: 20px;
  color: var(--text);
  background:
    radial-gradient(circle at 12% 0%, rgba(56, 230, 255, 0.09), transparent 32%),
    radial-gradient(circle at 88% 0%, rgba(123, 92, 255, 0.13), transparent 36%),
    rgba(4, 7, 19, 0.97);
  box-shadow:
    0 30px 100px rgba(0, 0, 0, 0.78),
    0 0 70px rgba(52, 92, 190, 0.12),
    inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

.history-dialog::backdrop {
  /* Full-screen backdrop blur has to re-sample the animated galaxy each frame.
     A slightly deeper scrim preserves focus on the exact chart without that
     compositor cost. */
  background: rgba(0, 1, 7, 0.86);
}

.history-dialog-inner {
  display: grid;
  gap: 16px;
  max-height: min(820px, calc(100dvh - 32px));
  padding: 22px;
  overflow: auto;
  overscroll-behavior: contain;
}

.history-dialog-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
}

.history-kicker {
  margin: 0 0 5px;
  color: var(--neb-cyan);
  font-size: 0.72rem;
  font-weight: 750;
  letter-spacing: 0.14em;
}

.history-title {
  margin: 0;
  max-width: min(720px, 75vw);
  overflow-wrap: anywhere;
  color: #f7faff;
  font-size: clamp(1.35rem, 3vw, 2rem);
  line-height: 1.15;
}

.history-close,
.history-scroll-btn,
.history-retry {
  border: 1px solid var(--line);
  color: var(--text);
  background: rgba(255, 255, 255, 0.045);
  cursor: pointer;
}

.history-close {
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  font-size: 1.5rem;
  line-height: 1;
}

.history-close:hover,
.history-scroll-btn:hover:not(:disabled),
.history-retry:hover {
  border-color: var(--line-bright);
  background: rgba(56, 230, 255, 0.09);
}

.history-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px 16px;
}

.history-range {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.025);
}

.history-range-btn {
  min-height: 36px;
  padding: 6px 13px;
  border: 0;
  border-radius: 8px;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
}

.history-range-btn.is-active {
  color: #031018;
  font-weight: 800;
  background: linear-gradient(120deg, var(--neb-cyan), var(--neb-teal));
  box-shadow: 0 0 18px rgba(56, 230, 255, 0.18);
}

.history-summary {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
  line-height: 1.45;
  text-align: right;
}

.history-state {
  min-height: 260px;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 14px;
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 16px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.018);
  text-align: center;
}

.history-state p {
  margin: 0;
}

.history-state.is-loading::before {
  content: "";
  width: 34px;
  height: 34px;
  border: 3px solid rgba(56, 230, 255, 0.16);
  border-top-color: var(--neb-cyan);
  border-radius: 50%;
  animation: history-spin 0.9s linear infinite;
}

.history-state.is-error {
  color: #ffabbc;
}

.history-state.is-empty {
  color: var(--muted);
}

.history-retry {
  min-height: 36px;
  padding: 7px 18px;
  border-radius: 10px;
}

@keyframes history-spin {
  to { transform: rotate(360deg); }
}

.history-chart-panel {
  min-width: 0;
}

.history-chart-nav {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr) 38px;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.history-scroll-btn {
  width: 38px;
  height: 34px;
  border-radius: 9px;
  font-size: 1rem;
}

.history-scroll-btn:disabled {
  opacity: 0.28;
  cursor: default;
}

.history-readout {
  min-width: 0;
  margin: 0;
  overflow-wrap: anywhere;
  color: #eef7ff;
  font-size: 0.85rem;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.history-chart-scroll {
  width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  border: 1px solid rgba(145, 194, 255, 0.18);
  border-radius: 14px;
  background:
    linear-gradient(rgba(255, 255, 255, 0.018), rgba(255, 255, 255, 0)),
    rgba(0, 2, 10, 0.72);
  cursor: crosshair;
  touch-action: pan-x pan-y;
  overscroll-behavior-inline: contain;
  scrollbar-gutter: stable;
  scrollbar-color: rgba(56, 230, 255, 0.45) rgba(255, 255, 255, 0.04);
}

.history-chart-scroll:focus-visible {
  outline: 2px solid var(--neb-cyan);
  outline-offset: 2px;
}

.history-chart {
  display: block;
  max-width: none;
  height: 300px;
  shape-rendering: geometricPrecision;
}

.history-grid-line {
  stroke: rgba(151, 183, 255, 0.12);
  stroke-width: 1;
}

.history-axis-label {
  fill: rgba(190, 204, 235, 0.72);
  font-size: 10px;
  font-variant-numeric: tabular-nums;
}

.history-axis-x {
  fill: rgba(190, 204, 235, 0.62);
}

.history-area {
  fill: url("#history-area-gradient");
}

.history-line {
  fill: none;
  stroke: url("#history-line-gradient");
  stroke-width: 2.25;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.history-active-guide {
  stroke: rgba(220, 244, 255, 0.32);
  stroke-width: 1;
  stroke-dasharray: 3 4;
}

.history-active-marker {
  fill: #f8fdff;
  stroke: var(--neb-cyan);
  stroke-width: 3;
  filter: drop-shadow(0 0 5px rgba(56, 230, 255, 0.75));
}

.history-active-marker.is-incomplete {
  stroke: var(--neb-gold);
}

.history-chart-help {
  margin: 7px 2px 0;
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.45;
}

.history-data-details {
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.history-data-details > summary {
  width: fit-content;
  color: var(--muted);
  font-size: 0.8rem;
  cursor: pointer;
}

.history-data-details[open] > summary {
  margin-bottom: 10px;
  color: var(--text);
}

.history-table-scroll {
  max-height: 230px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
}

.history-table {
  width: 100%;
  border-collapse: collapse;
  color: var(--text);
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
}

.history-table caption {
  padding: 10px 12px;
  color: var(--muted);
  text-align: left;
}

.history-table th,
.history-table td {
  padding: 8px 12px;
  border-top: 1px solid rgba(150, 180, 255, 0.1);
  text-align: left;
  white-space: nowrap;
}

.history-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  color: #dce7ff;
  background: #090d20;
}

.history-close:focus-visible,
.history-range-btn:focus-visible,
.history-scroll-btn:focus-visible,
.history-retry:focus-visible,
.history-data-details > summary:focus-visible {
  outline: 2px solid var(--neb-cyan);
  outline-offset: 2px;
}

@media (max-width: 620px) {
  .history-dialog {
    width: calc(100vw - 16px);
    max-height: calc(100dvh - 16px);
    border-radius: 16px;
  }
  .history-dialog-inner {
    gap: 14px;
    max-height: calc(100dvh - 16px);
    padding: 16px;
  }
  .history-title {
    max-width: calc(100vw - 96px);
  }
  .history-toolbar {
    align-items: stretch;
  }
  .history-range {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
  }
  .history-summary {
    width: 100%;
    text-align: left;
  }
  .history-state {
    min-height: 220px;
  }
}

/* ============================================================
   Loader & empty state
   ============================================================ */

.loader {
  position: absolute;
  z-index: 4;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  display: grid;
  justify-items: center;
  gap: 16px;
  color: var(--muted);
  transition: opacity 0.6s ease;
}
.loader.is-hidden {
  opacity: 0;
  pointer-events: none;
}
.loader-core {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: radial-gradient(circle at 34% 30%, #fff, var(--neb-cyan) 45%, #123 100%);
  box-shadow: 0 0 30px rgba(56, 230, 255, 0.7), 0 0 70px rgba(123, 92, 255, 0.4);
  animation: bob 2.4s var(--ease) infinite;
}
.loader-text {
  font-size: 0.9rem;
  letter-spacing: 0.14em;
}
@keyframes bob {
  0%, 100% { transform: translateY(-6px) scale(1); }
  50% { transform: translateY(6px) scale(1.06); }
}

.empty-state {
  position: absolute;
  z-index: 4;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  display: grid;
  justify-items: center;
  gap: 10px;
  max-width: min(86vw, 420px);
  text-align: center;
}
.empty-orb {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: radial-gradient(circle at 32% 28%, #fff, #6f7bff 42%, #1a1030 100%);
  box-shadow: 0 0 40px rgba(123, 92, 255, 0.55);
  animation: bob 3s var(--ease) infinite;
}
.empty-title {
  margin: 8px 0 0;
  font-size: 1.15rem;
  color: #eef2ff;
}
.empty-sub {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.5;
}

/* ============================================================
   HUD (top brand + status)
   ============================================================ */

.hud {
  position: fixed;
  z-index: 20;
}

.hud-top {
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px 14px;
  padding: max(16px, env(safe-area-inset-top)) 20px 8px;
  pointer-events: none;
}

.brand {
  pointer-events: auto;
}
.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 0.7rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}
.title {
  margin: 0;
  font-size: clamp(1.3rem, 3.4vw, 2.1rem);
  font-weight: 800;
  letter-spacing: 0.04em;
  background: linear-gradient(96deg, #fff 0%, var(--neb-cyan) 45%, var(--neb-violet) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 0 34px rgba(123, 92, 255, 0.35);
}

.status {
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--glass);
  backdrop-filter: blur(12px);
  color: var(--muted);
  font-size: 0.82rem;
  white-space: nowrap;
}
.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--neb-gold);
  box-shadow: 0 0 10px currentColor;
  animation: pulse-dot 1.6s ease-in-out infinite;
}
.dot.is-online {
  background: var(--ok);
  animation: none;
}
.dot.is-offline {
  background: var(--danger);
}
@keyframes pulse-dot {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 1; }
}

/* ============================================================
   Compact time-window controls in the top-right HUD
   ============================================================ */

.hud-actions {
  pointer-events: auto;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  margin-left: auto;
}

.window-panel {
  width: 244px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--glass);
  backdrop-filter: blur(12px);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.34);
}

.windows {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
}

.chip {
  min-width: 0;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.03);
  color: var(--text);
  font-size: 0.86rem;
  cursor: pointer;
  transition: border-color 0.2s ease, background 0.2s ease, transform 0.1s ease;
}
.chip:hover {
  border-color: var(--line-bright);
}
.chip:active {
  transform: scale(0.96);
}
.chip.is-active {
  border-color: transparent;
  color: #041018;
  font-weight: 800;
  background: linear-gradient(120deg, var(--neb-cyan), var(--neb-teal));
  box-shadow: 0 0 18px rgba(56, 230, 255, 0.4);
}

.console-toggle {
  flex: none;
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.03);
  cursor: pointer;
  transition: border-color 0.2s ease;
}
.console-toggle:hover {
  border-color: var(--line-bright);
}
.console-toggle-icon {
  width: 11px;
  height: 11px;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: rotate(-135deg);
  transition: transform 0.3s var(--ease);
  margin-top: 3px;
}
.console-toggle[aria-expanded="true"] .console-toggle-icon {
  transform: rotate(45deg);
  margin-top: -3px;
}

.console-body {
  padding: 4px 12px 14px;
  display: grid;
  gap: 14px;
  border-top: 1px solid var(--line);
}

.metrics {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin: 12px 0 0;
}
.metrics > div {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.02);
}
.metrics dt {
  color: var(--muted);
  font-size: 0.72rem;
  letter-spacing: 0.04em;
}
.metrics dd {
  margin: 5px 0 0;
  font-size: 1.05rem;
  font-weight: 700;
  color: #f4f7ff;
  overflow-wrap: anywhere;
}

.ingest {
  display: grid;
  gap: 8px;
}
.ingest-label {
  color: var(--muted);
  font-size: 0.78rem;
  letter-spacing: 0.04em;
}
textarea {
  width: 100%;
  min-height: 62px;
  resize: vertical;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.28);
  color: var(--text);
  outline: none;
  transition: border-color 0.2s ease;
}
textarea:focus {
  border-color: var(--accent);
}
.ingest-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.btn-primary {
  flex: none;
  min-height: 40px;
  padding: 0 16px;
  border: none;
  border-radius: 12px;
  font-weight: 800;
  color: #041018;
  background: linear-gradient(120deg, var(--neb-cyan), var(--neb-teal));
  cursor: pointer;
  box-shadow: 0 0 18px rgba(56, 230, 255, 0.35);
  transition: transform 0.1s ease, filter 0.2s ease;
}
.btn-primary:hover {
  filter: brightness(1.08);
}
.btn-primary:active {
  transform: scale(0.97);
}
.btn-primary:disabled {
  opacity: 0.5;
  cursor: default;
}
.ingest-result {
  color: var(--muted);
  font-size: 0.8rem;
  overflow-wrap: anywhere;
}

/* ---- console body scroll + calm button ---- */
.console-body {
  max-height: min(70vh, 560px);
  overflow-y: auto;
}

.icon-btn {
  flex: none;
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.03);
  cursor: pointer;
  transition: border-color 0.2s ease, background 0.2s ease;
}
.icon-btn:hover {
  border-color: var(--line-bright);
}
.calm-glyph {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: radial-gradient(circle at 34% 30%, #fff, var(--neb-cyan) 55%, #123);
  box-shadow: 0 0 10px rgba(56, 230, 255, 0.6);
}
.icon-btn[aria-pressed="true"] {
  border-color: var(--line-bright);
  background: rgba(56, 230, 255, 0.12);
}
.icon-btn[aria-pressed="true"] .calm-glyph {
  background: #4a5578;
  box-shadow: none;
}

/* ---- hot list ---- */
.hot {
  display: grid;
  gap: 8px;
  padding-top: 12px;
}
.hot-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}
.hot-title {
  font-size: 0.86rem;
  font-weight: 700;
  color: #eaf0ff;
  letter-spacing: 0.04em;
}
.coverage {
  font-size: 0.72rem;
  color: var(--muted);
}
.hotlist {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 2px;
}
.hot-row {
  display: grid;
  grid-template-columns: 20px 12px 1fr auto auto;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 5px 8px;
  border: 1px solid transparent;
  border-radius: 9px;
  background: transparent;
  color: var(--text);
  text-align: left;
  font: inherit;
  cursor: pointer;
  transition: background 0.18s ease, border-color 0.18s ease;
}
.hot-row:hover,
.hot-row:focus-visible {
  background: rgba(255, 255, 255, 0.05);
  border-color: var(--line);
  outline: none;
}
.hot-rank {
  color: var(--muted);
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
  text-align: right;
}
.hot-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: radial-gradient(circle at 34% 30%, #fff, hsl(var(--hue), 90%, 60%) 55%, hsl(var(--hue), 70%, 22%));
  box-shadow: 0 0 8px hsla(var(--hue), 100%, 65%, 0.6);
}
.hot-word {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.9rem;
}
.hot-count {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: #f4f7ff;
}
.hot-trend {
  min-width: 38px;
  text-align: right;
  font-size: 0.74rem;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}
.hot-trend.is-up {
  color: var(--ok);
}
.hot-trend.is-down {
  color: #ff9d5c;
}
.hot-trend.is-new {
  color: var(--neb-gold);
  font-weight: 800;
}

/* ---- size legend ---- */
.legend {
  display: flex;
  align-items: center;
  gap: 6px;
  padding-top: 2px;
  color: var(--muted);
  font-size: 0.7rem;
}
.legend-dot {
  border-radius: 50%;
  background: radial-gradient(circle at 34% 30%, #fff, var(--neb-cyan) 55%, #123);
  flex: none;
}
.legend-sm {
  width: 7px;
  height: 7px;
}
.legend-lg {
  width: 14px;
  height: 14px;
}
.legend-track {
  flex: 1;
  height: 2px;
  border-radius: 2px;
  background: linear-gradient(90deg, var(--neb-violet), var(--neb-cyan), var(--neb-gold));
  opacity: 0.7;
}
.legend-cap {
  font-variant-numeric: tabular-nums;
}
.legend-note {
  margin-left: 6px;
  white-space: nowrap;
}

.metrics dd.is-stale {
  color: var(--neb-gold);
}

.ingest-details {
  border-top: 1px solid var(--line);
  padding-top: 10px;
}
.ingest-details > summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 0.8rem;
  list-style: none;
  user-select: none;
}
.ingest-details > summary::-webkit-details-marker {
  display: none;
}
.ingest-details[open] > summary {
  margin-bottom: 10px;
  color: var(--text);
}

/* ---- planet: persistent "new" + located highlight ---- */
.planet.is-new .planet-body {
  outline: 2px solid hsla(var(--hue), 100%, 85%, 0.75);
  outline-offset: 3px;
  animation: new-ring 1.6s ease-in-out infinite;
}
@keyframes new-ring {
  0%, 100% { outline-color: hsla(var(--hue), 100%, 85%, 0.3); }
  50% { outline-color: hsla(var(--hue), 100%, 90%, 0.9); }
}
.planet.is-located .planet-body {
  box-shadow:
    0 0 0 3px rgba(255, 255, 255, 0.85),
    0 0 26px hsla(var(--hue), 100%, 75%, 0.9),
    0 0 60px hsla(var(--hue), 100%, 65%, 0.5);
}
.planet:focus-visible {
  outline: none;
}
.planet:focus-visible .planet-body {
  box-shadow:
    0 0 0 3px var(--neb-cyan),
    0 0 24px rgba(56, 230, 255, 0.7);
}

/* ============================================================
   Responsive
   ============================================================ */

@media (max-width: 760px) {
  .hud-top {
    padding-top: max(12px, env(safe-area-inset-top));
    padding-inline: 14px;
  }
  .hud-actions {
    flex: 0 0 100%;
    gap: 6px;
  }
  .window-panel {
    flex: 1;
    width: auto;
  }
  .planet-label {
    max-width: 120px;
  }
  /* The controls wrap into a second HUD row; keep the heatmap below it. */
  .treemap {
    top: 126px;
    bottom: max(12px, env(safe-area-inset-bottom));
  }
}

@media (max-width: 400px) {
  .hud-actions .status {
    gap: 6px;
    padding: 7px 9px;
    font-size: 0.76rem;
  }
  .title {
    font-size: 1.25rem;
  }
  .view-btn {
    padding-inline: 11px;
  }
  .chip {
    min-height: 32px;
    font-size: 0.8rem;
  }
}

/* Coarse pointers (touch): hover cues are unreliable, keep labels legible */
@media (hover: none) {
  .planet.is-dwarf .planet-label {
    opacity: 0.85;
  }
}

@media (prefers-reduced-motion: reduce) {
  .cloud,
  .loader-core,
  .empty-orb,
  .history-state.is-loading::before,
  .dot {
    animation: none !important;
  }
  .planet.is-born .planet-body,
  .planet.is-pulse .planet-body,
  .planet.is-born .planet-flare {
    animation: none !important;
  }
  .planet.is-entering .planet-body {
    transform: none;
    opacity: 1;
  }
}

/* ============================================================
   Galaxy gas view
   Reuses the orbital word engine, but replaces concrete planets with luminous
   type over a diffuse spiral gas field. The whole field lives inside the
   transformed nebula layer so it stays aligned during pan and zoom.
   ============================================================ */

.nebula {
  transition: opacity 0.8s ease;
}

body.mode-galaxy .treemap {
  display: none;
}

.view-btn:focus-visible {
  outline: 2px solid var(--neb-cyan);
  outline-offset: 2px;
}

body.mode-galaxy .nebula {
  display: none;
}

.galaxy-gas {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 1;
  width: min(96vw, 184vh);
  aspect-ratio: 1.515;
  transform: translate(-50%, -50%) rotate(-10deg);
  background: url("galaxy-gas-v1.webp") center / 100% 100% no-repeat;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  contain: layout paint style;
  transition: opacity 0.9s ease, visibility 0s linear 0.9s;
}

body.mode-galaxy .galaxy-gas {
  opacity: 0.86;
  visibility: visible;
  transition-delay: 0s;
}

.galaxy-gas > span {
  position: absolute;
  display: block;
  pointer-events: none;
  animation-play-state: paused;
}

body.mode-galaxy .galaxy-gas > span,
body.mode-galaxy .galaxy-disc::before {
  animation-play-state: running;
  will-change: transform, opacity;
}

.galaxy-halo {
  inset: -9%;
  border-radius: 50%;
  background:
    radial-gradient(
      ellipse at 50% 50%,
      rgba(235, 249, 255, 0.2) 0%,
      rgba(77, 225, 255, 0.2) 13%,
      rgba(123, 92, 255, 0.16) 32%,
      rgba(255, 77, 141, 0.08) 50%,
      transparent 73%
    ),
    radial-gradient(ellipse at 37% 50%, rgba(56, 230, 255, 0.2), transparent 34%),
    radial-gradient(ellipse at 67% 45%, rgba(184, 108, 255, 0.18), transparent 36%);
  filter: blur(26px);
  mix-blend-mode: screen;
  animation: galaxy-breathe 10s ease-in-out infinite;
}

.galaxy-disc {
  inset: 4%;
  border-radius: 50%;
  background:
    conic-gradient(
      from -28deg at 50% 50%,
      rgba(70, 95, 210, 0.02) 0deg,
      rgba(56, 230, 255, 0.05) 12deg,
      rgba(86, 221, 255, 0.4) 31deg,
      rgba(123, 92, 255, 0.28) 48deg,
      rgba(255, 77, 141, 0.09) 66deg,
      rgba(70, 95, 210, 0.025) 100deg,
      rgba(70, 95, 210, 0.02) 180deg,
      rgba(56, 230, 255, 0.04) 192deg,
      rgba(86, 221, 255, 0.35) 211deg,
      rgba(123, 92, 255, 0.24) 228deg,
      rgba(255, 77, 141, 0.075) 246deg,
      rgba(70, 95, 210, 0.02) 282deg,
      rgba(70, 95, 210, 0.02) 360deg
    ),
    radial-gradient(
      ellipse at 50% 50%,
      rgba(255, 255, 255, 0.16),
      rgba(82, 195, 255, 0.12) 22%,
      rgba(112, 82, 220, 0.08) 48%,
      transparent 76%
    );
  -webkit-mask-image: radial-gradient(
    ellipse,
    #000 0%,
    rgba(0, 0, 0, 0.98) 22%,
    rgba(0, 0, 0, 0.72) 58%,
    transparent 92%
  );
  mask-image: radial-gradient(
    ellipse,
    #000 0%,
    rgba(0, 0, 0, 0.98) 22%,
    rgba(0, 0, 0, 0.72) 58%,
    transparent 92%
  );
  filter: blur(28px);
  mix-blend-mode: screen;
  opacity: 0.68;
  animation: galaxy-turn 110s linear infinite;
}

.galaxy-disc::before,
.galaxy-disc::after {
  content: "";
  position: absolute;
  inset: 5%;
  border-radius: 50%;
  pointer-events: none;
}

.galaxy-disc::before {
  background:
    radial-gradient(circle at 15% 56%, rgba(163, 243, 255, 0.8) 0 0.7%, transparent 4.5%),
    radial-gradient(circle at 27% 30%, rgba(114, 199, 255, 0.72) 0 0.8%, transparent 5%),
    radial-gradient(circle at 42% 72%, rgba(192, 135, 255, 0.7) 0 0.9%, transparent 5.5%),
    radial-gradient(circle at 63% 25%, rgba(83, 232, 255, 0.72) 0 0.7%, transparent 4.8%),
    radial-gradient(circle at 76% 62%, rgba(255, 122, 193, 0.62) 0 0.8%, transparent 5%),
    radial-gradient(circle at 88% 46%, rgba(147, 224, 255, 0.7) 0 0.6%, transparent 4%);
  filter: blur(7px);
  mix-blend-mode: screen;
  animation: galaxy-knots 14s ease-in-out infinite alternate;
  animation-play-state: paused;
}

.galaxy-disc::after {
  inset: 9% 4%;
  background: repeating-radial-gradient(
    ellipse at 50% 50%,
    transparent 0 8%,
    rgba(8, 7, 28, 0.2) 10%,
    transparent 14% 20%
  );
  filter: blur(9px);
  opacity: 0.62;
  mix-blend-mode: multiply;
}

.galaxy-dust {
  inset: 16% 7%;
  border-radius: 50%;
  background: conic-gradient(
    from 10deg,
    transparent 0deg,
    transparent 24deg,
    rgba(1, 2, 14, 0.46) 39deg,
    transparent 57deg,
    transparent 180deg,
    transparent 204deg,
    rgba(1, 2, 14, 0.42) 219deg,
    transparent 238deg,
    transparent 360deg
  );
  -webkit-mask-image: radial-gradient(
    ellipse,
    transparent 0 12%,
    #000 28%,
    rgba(0, 0, 0, 0.8) 62%,
    transparent 90%
  );
  mask-image: radial-gradient(
    ellipse,
    transparent 0 12%,
    #000 28%,
    rgba(0, 0, 0, 0.8) 62%,
    transparent 90%
  );
  filter: blur(13px);
  opacity: 0.46;
  mix-blend-mode: multiply;
  animation: galaxy-turn-reverse 150s linear infinite;
}

.galaxy-core {
  left: 31%;
  right: 31%;
  top: 36%;
  bottom: 36%;
  border-radius: 50%;
  background: radial-gradient(
    ellipse,
    rgba(255, 255, 255, 0.74) 0%,
    rgba(202, 246, 255, 0.52) 11%,
    rgba(78, 221, 255, 0.3) 30%,
    rgba(136, 87, 255, 0.12) 55%,
    transparent 80%
  );
  filter: blur(12px);
  mix-blend-mode: screen;
  animation: galaxy-core-pulse 7s ease-in-out infinite;
}

@keyframes galaxy-turn {
  to {
    transform: rotate(360deg);
  }
}

@keyframes galaxy-turn-reverse {
  to {
    transform: rotate(-360deg);
  }
}

@keyframes galaxy-breathe {
  0%,
  100% {
    transform: scale(0.97);
    opacity: 0.76;
  }
  50% {
    transform: scale(1.04);
    opacity: 1;
  }
}

@keyframes galaxy-knots {
  0% {
    transform: rotate(-2deg) scale(0.98);
    opacity: 0.72;
  }
  100% {
    transform: rotate(5deg) scale(1.04);
    opacity: 1;
  }
}

@keyframes galaxy-core-pulse {
  0%,
  100% {
    transform: scale(0.92);
    opacity: 0.8;
  }
  50% {
    transform: scale(1.08);
    opacity: 1;
  }
}

/* In galaxy mode, words orbit as light instead of being rendered as planets. */
body.mode-galaxy .planet-body,
body.mode-galaxy .planet .planet-ring,
body.mode-galaxy .planet-flare {
  display: none;
}

body.mode-galaxy .planet-label,
body.mode-galaxy .planet.is-dwarf .planet-label {
  position: relative;
  top: auto;
  display: block;
  max-width: min(180px, 44vw);
  /* A clipped text shadow ends at the label's rectangular paint box. Let the
     glow fade outside that box so bright inner words never look like tiles. */
  overflow: visible;
  padding: 0.28em 0.5em;
  pointer-events: auto;
  cursor: pointer;
  font-size: clamp(11px, calc(var(--d) * 0.24), 28px);
  font-weight: 680;
  color: rgba(245, 252, 255, 0.96);
  opacity: 0.9;
  text-shadow:
    0 1px 3px rgba(0, 0, 0, 0.96),
    0 0 7px rgba(0, 0, 0, 0.86),
    0 0 10px hsla(var(--hue), 100%, 72%, 0.58),
    0 0 22px hsla(var(--hue2, var(--hue)), 100%, 60%, 0.22);
  transform: scale(1);
  transition:
    opacity 0.45s var(--ease),
    transform 0.45s var(--ease),
    color 0.45s ease;
}

body.mode-galaxy .planet.is-dwarf .planet-label {
  opacity: 0.82;
}

body.mode-galaxy .planet[data-tier="star"] .planet-label {
  font-size: clamp(19px, calc(var(--d) * 0.3), 34px);
  font-weight: 780;
  letter-spacing: 0.035em;
  color: #fff;
  text-shadow:
    0 2px 4px rgba(0, 0, 0, 0.96),
    0 0 9px rgba(255, 255, 255, 0.68),
    0 0 22px rgba(80, 229, 255, 0.64),
    0 0 38px rgba(123, 92, 255, 0.34);
}

body.mode-galaxy .planet:hover .planet-label {
  opacity: 1;
  transform: scale(1.12);
}

body.mode-galaxy .planet.is-new .planet-label {
  color: #fff3c2;
}

body.mode-galaxy .planet.is-born .planet-label,
body.mode-galaxy .planet.is-pulse .planet-label {
  animation: galaxy-word-pulse 0.9s var(--ease);
}

body.mode-galaxy .planet.is-located .planet-label,
body.mode-galaxy .planet:focus-visible .planet-label {
  outline: 1px solid rgba(140, 235, 255, 0.7);
  border-radius: 999px;
  background: rgba(8, 18, 40, 0.52);
  box-shadow: 0 0 22px rgba(56, 230, 255, 0.34);
}

body.mode-galaxy .planet.is-entering .planet-label,
body.mode-galaxy .planet.is-leaving .planet-label {
  opacity: 0;
  transform: scale(0.7);
}

body.mode-galaxy .orbit {
  border-color: rgba(126, 218, 255, 0.08);
  box-shadow: 0 0 18px rgba(92, 109, 255, 0.04);
}

@keyframes galaxy-word-pulse {
  0% {
    transform: scale(1);
  }
  35% {
    transform: scale(1.18);
  }
  100% {
    transform: scale(1);
  }
}

.is-calm .galaxy-gas > span,
.is-calm .galaxy-disc::before {
  animation-play-state: paused !important;
}

/* The history dialog obscures the stage. Freeze the retained scene so its
   full-screen backdrop can reuse a stable surface instead of compositing every
   decorative animation underneath the chart. */
body.is-history-open .galaxy-gas > span,
body.is-history-open .galaxy-disc::before,
body.is-history-open .planet-body,
body.is-history-open .planet-flare,
body.is-history-open .planet-label {
  animation-play-state: paused !important;
}

body.mode-galaxy.is-calm .planet-label {
  animation: none !important;
  transition: none;
}

@media (max-width: 620px) {
  .galaxy-gas {
    width: min(104vw, 184vh);
  }

  .galaxy-halo {
    filter: blur(18px);
  }

  .galaxy-disc {
    filter: blur(16px);
  }

  .galaxy-dust {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .galaxy-gas,
  .nebula,
  body.mode-galaxy .planet-label {
    transition: none !important;
  }

  .galaxy-gas > span,
  .galaxy-disc::before,
  body.mode-galaxy .planet-label {
    animation: none !important;
  }
}
