:root {
  --bg: #070b1a;
  --ink: #eef1ff;
  --dim: #9aa4c7;
  --cyan: #4df3ff;
  --magenta: #ff5ad1;
  --green: #5dff9b;
  --red: #ff4d6d;
  --blue: #6db8ff;
  --panel: rgba(12, 18, 42, 0.7);
  --edge: rgba(77, 243, 255, 0.35);
  --inset-top: env(safe-area-inset-top, 0px);
  --inset-right: env(safe-area-inset-right, 0px);
  --inset-bottom: env(safe-area-inset-bottom, 0px);
  --inset-left: env(safe-area-inset-left, 0px);
}

[hidden] { display: none !important; }

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

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-weight: 700;
  letter-spacing: 0.08em;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
}

button { font: inherit; color: inherit; }

#game {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

/* ---------- HUD ---------- */

#hud {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 5;
  padding: calc(var(--inset-top) + 10px) calc(var(--inset-right) + 12px) 0 calc(var(--inset-left) + 12px);
  pointer-events: none;
}

#hud-xp {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: rgba(255, 255, 255, 0.08);
}

#hud-xp-fill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--green), var(--cyan));
  box-shadow: 0 0 10px rgba(93, 255, 155, 0.8);
  transition: width 0.2s linear;
}

.hud-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 44px;
}

.hud-left {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

#hud-score {
  font-size: 24px;
  font-weight: 900;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 0 10px rgba(77, 243, 255, 0.7);
  transform-origin: left center;
}

#hud-score.bump { animation: bump 0.25s ease-out; }

@keyframes bump {
  from { transform: scale(1.18); }
  to { transform: scale(1); }
}

.hud-meta {
  margin-top: 4px;
  font-size: 11px;
  color: var(--dim);
  letter-spacing: 0.18em;
  white-space: nowrap;
}

.hud-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

#hud-hull {
  display: flex;
  align-items: center;
  gap: 4px;
}

.pip {
  display: block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 1.5px solid;
}

.pip.hull { border-color: rgba(255, 77, 109, 0.5); }
.pip.hull.on {
  background: var(--red);
  border-color: var(--red);
  box-shadow: 0 0 8px rgba(255, 77, 109, 0.8);
}

.pip.shield { border-color: rgba(109, 184, 255, 0.5); }
.pip.shield.on {
  background: var(--blue);
  border-color: var(--blue);
  box-shadow: 0 0 8px rgba(109, 184, 255, 0.8);
}

.hud-btn {
  pointer-events: auto;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid var(--edge);
  background: var(--panel);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  box-shadow: 0 0 12px rgba(77, 243, 255, 0.15);
  font-size: 16px;
  line-height: 1;
  touch-action: manipulation;
}

.hud-btn svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
}

/* ---------- banner ---------- */

#banner {
  position: fixed;
  left: 0;
  right: 0;
  top: 34%;
  z-index: 6;
  padding: 0 16px;
  text-align: center;
  font-size: clamp(34px, 11vw, 64px);
  font-weight: 900;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #fff;
  text-shadow: 0 0 6px #fff, 0 0 22px var(--cyan), 0 0 44px rgba(77, 243, 255, 0.5);
  opacity: 0;
  pointer-events: none;
}

#banner.show {
  animation: banner-in var(--banner-ms, 1400ms) ease-out both;
}

@keyframes banner-in {
  0% { opacity: 0; transform: translateY(12px) scale(0.85); }
  12% { opacity: 1; transform: translateY(0) scale(1.05); }
  22% { opacity: 1; transform: scale(1); }
  75% { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: translateY(-16px) scale(1); }
}

/* ---------- stick (drawn by input.js) ---------- */

.stick-base,
.stick-knob {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 8;
  border-radius: 50%;
  pointer-events: none;
}

.stick-base {
  width: 120px;
  height: 120px;
  border: 2px solid rgba(77, 243, 255, 0.45);
  background: radial-gradient(circle, rgba(77, 243, 255, 0.1), rgba(77, 243, 255, 0.03) 70%);
  box-shadow: 0 0 18px rgba(77, 243, 255, 0.22);
}

.stick-knob {
  width: 52px;
  height: 52px;
  border: 1.5px solid rgba(77, 243, 255, 0.85);
  background: radial-gradient(circle at 35% 35%, rgba(255, 255, 255, 0.6), rgba(77, 243, 255, 0.4) 55%, rgba(77, 243, 255, 0.18));
  box-shadow: 0 0 14px rgba(77, 243, 255, 0.55);
}

/* ---------- overlays & panels ---------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(var(--inset-top) + 16px) calc(var(--inset-right) + 16px) calc(var(--inset-bottom) + 16px) calc(var(--inset-left) + 16px);
  background: radial-gradient(ellipse at center, rgba(7, 11, 26, 0.45) 0%, rgba(7, 11, 26, 0.86) 75%);
  touch-action: none;
}

.panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  width: min(100%, 420px);
  max-height: 100%;
  overflow-y: auto;
  scrollbar-width: none;
  padding: 28px 22px 24px;
  text-align: center;
  border-radius: 24px;
  border: 1px solid var(--edge);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0) 40%), var(--panel);
  backdrop-filter: blur(16px) saturate(140%);
  -webkit-backdrop-filter: blur(16px) saturate(140%);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.03), 0 0 48px rgba(77, 243, 255, 0.18), 0 24px 60px rgba(0, 0, 0, 0.55);
}

.panel::-webkit-scrollbar { display: none; }

.upgrade-panel { width: min(100%, 980px); }

.title {
  margin: 4px 0 0;
  font-size: clamp(40px, 12.5vw, 76px);
  font-weight: 900;
  line-height: 0.95;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.title span { display: block; }

.title-a {
  color: #e9feff;
  text-shadow: 0 0 4px #fff, 0 0 14px var(--cyan), 0 0 34px var(--cyan);
}

.title-b {
  color: #ffe9f8;
  text-shadow: 0 0 4px #fff, 0 0 14px var(--magenta), 0 0 34px var(--magenta);
}

@media (prefers-reduced-motion: no-preference) {
  .title { animation: title-glow 3.2s ease-in-out infinite alternate; }
}

@keyframes title-glow {
  from { filter: brightness(1); }
  to { filter: brightness(1.15) saturate(1.2); }
}

.howto {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 15px;
  line-height: 1.4;
  letter-spacing: 0.02em;
  font-weight: 600;
  color: #cfd6f5;
}

.howto li:last-child {
  font-size: 13px;
  color: var(--dim);
}

.best {
  font-size: 14px;
  letter-spacing: 0.2em;
  color: var(--dim);
}

.best span {
  margin-left: 6px;
  font-size: 22px;
  font-weight: 900;
  letter-spacing: 0.04em;
  color: var(--green);
  text-shadow: 0 0 10px rgba(93, 255, 155, 0.6);
  font-variant-numeric: tabular-nums;
}

.heading {
  margin: 0;
  font-size: clamp(24px, 7vw, 34px);
  font-weight: 900;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #fff;
  text-shadow: 0 0 12px var(--cyan), 0 0 28px rgba(77, 243, 255, 0.5);
}

.heading-danger {
  text-shadow: 0 0 12px var(--red), 0 0 28px rgba(255, 77, 109, 0.5);
}

.section-label {
  margin-top: 4px;
  font-size: 11px;
  letter-spacing: 0.3em;
  color: var(--dim);
}

/* ---------- buttons ---------- */

.btn {
  appearance: none;
  display: block;
  width: 100%;
  min-height: 64px;
  padding: 0 20px;
  border: 1px solid transparent;
  border-radius: 18px;
  font-size: 20px;
  font-weight: 900;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.08s ease, box-shadow 0.2s ease;
}

.btn:active { transform: scale(0.97); }

.btn-primary {
  color: var(--bg);
  background: linear-gradient(120deg, var(--cyan) 0%, #a78bff 55%, var(--magenta) 100%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.5), 0 0 22px rgba(77, 243, 255, 0.45), 0 10px 26px rgba(0, 0, 0, 0.45);
}

.btn-ghost {
  color: var(--ink);
  background: rgba(255, 255, 255, 0.06);
  border-color: var(--edge);
}

:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 3px;
}

/* ---------- game over ---------- */

.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  width: 100%;
}

.stat {
  padding: 12px 10px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.09);
}

.stat-wide { grid-column: 1 / -1; }

.stat-label {
  font-size: 11px;
  letter-spacing: 0.24em;
  color: var(--dim);
}

.stat-value {
  margin-top: 4px;
  font-size: 26px;
  font-weight: 900;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.stat-wide .stat-value {
  font-size: 44px;
  color: var(--cyan);
  text-shadow: 0 0 14px rgba(77, 243, 255, 0.6);
}

.badge {
  display: inline-block;
  vertical-align: middle;
  margin-left: 8px;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 10px;
  letter-spacing: 0.14em;
  color: var(--bg);
  background: var(--green);
  box-shadow: 0 0 10px rgba(93, 255, 155, 0.6);
}

.chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  width: 100%;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px 6px 8px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.07);
  font-size: 13px;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.chip-icon {
  font-size: 16px;
  line-height: 1;
}

.chip-lv {
  color: var(--cyan);
  font-variant-numeric: tabular-nums;
}

.chip-empty {
  padding-left: 12px;
  color: var(--dim);
  font-weight: 600;
}

/* ---------- upgrade cards ---------- */

.upgrade-cards {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
}

.upgrade-card {
  --rc: #9aa4c7;
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  min-height: 76px;
  padding: 12px 14px;
  border: 2px solid var(--rc);
  border-radius: 18px;
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.01)), rgba(9, 13, 32, 0.88);
  box-shadow: 0 0 16px -4px var(--rc), inset 0 0 22px -12px var(--rc);
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  touch-action: manipulation;
  animation: card-in 0.34s cubic-bezier(0.2, 0.9, 0.3, 1.25) backwards;
}

.upgrade-card:active { transform: scale(0.98); }

.rarity-common { --rc: #9aa4c7; }
.rarity-rare { --rc: #4df3ff; }
.rarity-epic { --rc: #ff5ad1; }

@keyframes card-in {
  from { opacity: 0; transform: translateY(18px) scale(0.94); }
  to { opacity: 1; transform: none; }
}

.uc-icon {
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 14px;
  font-size: 28px;
  line-height: 1;
  background: rgba(255, 255, 255, 0.06);
  box-shadow: inset 0 0 0 1px var(--rc);
}

.uc-main {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

/* name and rarity share this row on phones; when the name needs the room the rarity wraps below it */
.uc-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 2px 8px;
}

.uc-name {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 17px;
  font-weight: 900;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  white-space: normal;
}

.uc-rarity {
  flex: 0 0 auto;
  font-size: 10px;
  letter-spacing: 0.2em;
  color: var(--rc);
}

.uc-desc {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: 0.01em;
  color: #cfd6f5;
}

.uc-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 2px;
}

.uc-level {
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.12em;
  color: var(--rc);
  font-variant-numeric: tabular-nums;
}

.uc-pips {
  display: flex;
  gap: 3px;
}

.uc-pip {
  width: 8px;
  height: 8px;
  border-radius: 2px;
  border: 1px solid var(--rc);
  opacity: 0.35;
}

.uc-pip.on {
  background: var(--rc);
  opacity: 1;
  box-shadow: 0 0 6px var(--rc);
}

@media (min-width: 700px) {
  .upgrade-cards { flex-direction: row; }

  .upgrade-card {
    flex: 1 1 0;
    min-height: 230px;
    flex-direction: column;
    align-items: stretch;
    text-align: center;
  }

  .uc-icon {
    align-self: center;
    width: 64px;
    height: 64px;
    font-size: 36px;
  }

  .uc-main { align-items: center; }
  .uc-head { flex-direction: column; flex-wrap: nowrap; gap: 4px; }
  .uc-desc { text-align: center; }
  .uc-foot { justify-content: center; flex-direction: column; }
}

/* ---------- v2: HUD sector label, boss bar, sector intro (never block input) ---------- */

.hud-sector {
  font-size: 10px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--sector, var(--cyan));
  text-shadow: 0 0 8px var(--sector, var(--cyan));
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 60vw;
}

.hud-sector:empty { display: none; }

.boss-bar {
  position: fixed;
  top: calc(var(--inset-top) + 80px);
  left: 50%;
  z-index: 5;
  width: min(72vw, 360px);
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  pointer-events: none;
}

.boss-name {
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: #ffe9b0;
  text-shadow: 0 0 8px rgba(255, 209, 102, 0.8), 0 1px 2px #000;
  white-space: nowrap;
}

.boss-hp {
  position: relative;
  width: 100%;
  height: 12px;
  padding: 2px;
  border-radius: 999px;
  border: 1.5px solid rgba(255, 209, 102, 0.7);
  background: rgba(7, 11, 26, 0.75);
  box-shadow: 0 0 14px rgba(255, 77, 109, 0.25), inset 0 2px 4px rgba(0, 0, 0, 0.5);
}

.boss-hp-fill {
  height: 100%;
  width: 100%;
  border-radius: 999px;
  /* gold at full, shading to red as the boss weakens */
  background: linear-gradient(90deg, #ff4d6d 0%, #ff9f43 45%, #ffd166 100%);
  background-size: 100% 100%;
  box-shadow: 0 0 10px rgba(255, 209, 102, 0.7);
  transform-origin: left center;
  transition: width 0.25s ease-out;
}

.boss-bar.shake { animation: boss-shake 0.35s ease-in-out; }
.boss-hp.flash { animation: boss-flash 0.3s ease-out; }

@keyframes boss-shake {
  0%, 100% { transform: translateX(-50%); }
  20% { transform: translateX(calc(-50% - 4px)); }
  40% { transform: translateX(calc(-50% + 4px)); }
  60% { transform: translateX(calc(-50% - 2px)); }
  80% { transform: translateX(calc(-50% + 2px)); }
}

@keyframes boss-flash {
  0% { filter: brightness(2.2) saturate(0.4); }
  100% { filter: none; }
}

.sector-intro {
  position: fixed;
  left: 0;
  right: 0;
  top: 28%;
  z-index: 7;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 0 16px;
  text-align: center;
  pointer-events: none;
  opacity: 0;
  animation: sector-intro-fade 2.6s ease-in-out both;
}

.si-name {
  font-size: clamp(30px, 10vw, 56px);
  font-weight: 900;
  line-height: 1;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #fff;
  text-shadow: 0 0 6px #fff, 0 0 22px var(--sector, var(--cyan)), 0 0 46px var(--sector, var(--cyan));
}

/* phones: a touch smaller so the title stays clear of the ship's centre-screen position */
@media (max-width: 699px) {
  .si-name { font-size: clamp(28px, 10vw, 44px); }
}

.si-tag {
  font-size: clamp(12px, 3.6vw, 16px);
  font-weight: 600;
  letter-spacing: 0.08em;
  line-height: 1.35;
  max-width: 34ch;
  color: var(--sector, var(--cyan));
  text-shadow: 0 0 10px var(--sector, var(--cyan));
}

@keyframes sector-intro-fade {
  0% { opacity: 0; transform: scale(0.94); }
  18% { opacity: 1; transform: scale(1); }
  76% { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(1.03); }
}

/* ---------- v2: star map ---------- */

.map-overlay {
  align-items: stretch;
  justify-content: center;
  padding: 0;
  background:
    radial-gradient(ellipse at 50% 0%, rgba(77, 243, 255, 0.10), transparent 55%),
    radial-gradient(ellipse at 50% 100%, rgba(255, 90, 209, 0.08), transparent 60%),
    var(--bg);
  overflow: hidden;
}

.map-wrap {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  height: 100%;
  padding: calc(var(--inset-top) + 12px) calc(var(--inset-right) + 14px) calc(var(--inset-bottom) + 18px) calc(var(--inset-left) + 14px);
}

.map-head {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
  padding-bottom: 8px;
}

.map-head .heading {
  text-align: center;
  font-size: clamp(20px, 6vw, 28px);
}

.map-head-spacer { width: 84px; }

.btn-back {
  appearance: none;
  height: 40px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid var(--edge);
  background: var(--panel);
  color: var(--ink);
  font-size: 13px;
  font-weight: 900;
  letter-spacing: 0.18em;
  cursor: pointer;
  touch-action: manipulation;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.btn-back:active { transform: scale(0.96); }

/* the scrolling route: one row per sector, number badges in a left gutter */
.map-sectors {
  --gutter: 56px;   /* left column reserved for the route and number badges */
  --route-x: 30px;  /* centre of the route line, measured from the list's left edge */
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 8px 2px 16px;
  overflow-y: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
}

.map-sectors::-webkit-scrollbar { display: none; }

.sector-row {
  --sc: #4df3ff;
  position: relative;
  flex: 0 0 auto;
  /* the gap between rows is padding so the route line can run through it */
  padding: 0 0 18px var(--gutter);
  animation: sector-row-in 0.3s ease-out backwards;
  animation-delay: var(--sc-delay, 0ms);
}

.sector-row:last-child { padding-bottom: 0; }

.sector-row.is-locked { --sc: #5a6287; }

/* glowing dotted route: joins badge 1 to badge N, behind the badges and cards (z-index 0 < 1) */
.sector-row::before {
  content: "";
  position: absolute;
  z-index: 0;
  left: var(--route-x);
  top: 0;
  bottom: 0;
  width: 0;
  border-left: 2px dotted rgba(77, 243, 255, 0.55);
  box-shadow: 0 0 10px rgba(77, 243, 255, 0.35);
  transform: translateX(-1px);
  pointer-events: none;
}

/* start the line at the centre of the first badge (card padding-top 14 + half of 38) */
.sector-row:first-child::before { top: 33px; }

/* stop the line at the centre of the last badge */
.sector-row:last-child::before { bottom: auto; height: 33px; }

@keyframes sector-row-in {
  from { opacity: 0; transform: translateY(14px) scale(0.96); }
  to { opacity: 1; transform: none; }
}

.sector-card {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
  padding: 14px 16px 14px;
  border-radius: 20px;
  border: 1.5px solid var(--sc);
  background:
    radial-gradient(120% 100% at 0% 0%, color-mix(in srgb, var(--sc) 22%, transparent), transparent 60%),
    linear-gradient(170deg, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0) 45%),
    rgba(8, 12, 30, 0.88);
  box-shadow: 0 0 22px -6px var(--sc), inset 0 0 26px -14px var(--sc);
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  touch-action: manipulation;
  font-weight: 700;
}

.sector-card:active:not(:disabled) { transform: scale(0.98); }

.sector-card.is-locked {
  cursor: default;
  filter: grayscale(0.85) brightness(0.62);
  box-shadow: none;
  border-style: dashed;
  background: rgba(10, 12, 26, 0.7);
}

.sc-top {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

/* number badge: sits in the row's left gutter, centred on the route line */
.sc-num {
  position: absolute;
  z-index: 1;
  top: 14px;
  left: calc(var(--route-x) - 19px);
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 12px;
  border: 1.5px solid var(--sc);
  background: rgba(8, 12, 30, 0.92);
  font-size: 17px;
  font-weight: 900;
  color: var(--sc);
  text-shadow: 0 0 10px var(--sc);
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}

.sector-row.is-locked .sc-num {
  filter: grayscale(0.85) brightness(0.62);
  text-shadow: none;
}

.sc-title {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sc-name {
  font-size: 18px;
  font-weight: 900;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #fff;
  line-height: 1.1;
  white-space: normal;
}

.sc-tag {
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: 0.01em;
  line-height: 1.35;
  color: #cfd6f5;
  white-space: normal;
}

.sc-badge {
  flex: 0 0 auto;
  align-self: flex-start;
  padding: 4px 9px;
  border-radius: 999px;
  font-size: 10px;
  letter-spacing: 0.16em;
  white-space: nowrap;
  color: var(--bg);
  background: var(--sc);
  box-shadow: 0 0 10px var(--sc);
}

.sc-badge.badge-cleared { background: var(--green); box-shadow: 0 0 10px rgba(93, 255, 155, 0.7); }
.sc-badge.badge-new { animation: badge-pulse 1.4s ease-in-out infinite; }
.sc-badge.badge-locked { background: #2a3050; color: #9aa4c7; box-shadow: none; }

@keyframes badge-pulse {
  0%, 100% { transform: scale(1); box-shadow: 0 0 6px var(--sc); }
  50% { transform: scale(1.12); box-shadow: 0 0 16px var(--sc); }
}

.sc-boss {
  font-size: 12px;
  letter-spacing: 0.1em;
  color: var(--dim);
}

.sc-boss b {
  color: var(--sc);
  font-weight: 900;
  text-shadow: 0 0 8px var(--sc);
}

.sc-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 2px;
}

.sc-rewards {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.sc-reward {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px 3px 6px;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--sc) 55%, transparent);
  background: rgba(255, 255, 255, 0.05);
  font-size: 11px;
  letter-spacing: 0.03em;
  white-space: nowrap;
}

.sc-reward i { font-style: normal; font-size: 13px; line-height: 1; }

.sc-best {
  font-size: 12px;
  letter-spacing: 0.12em;
  color: var(--dim);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.sc-best b {
  color: var(--green);
  font-weight: 900;
  text-shadow: 0 0 8px rgba(93, 255, 155, 0.6);
}

.sector-card.is-new {
  animation: new-glow 2.2s ease-in-out infinite;
}

@keyframes new-glow {
  0%, 100% { box-shadow: 0 0 18px -6px var(--sc), inset 0 0 22px -14px var(--sc); }
  50% { box-shadow: 0 0 36px -2px var(--sc), inset 0 0 30px -10px var(--sc); }
}

@media (prefers-reduced-motion: reduce) {
  .sc-badge.badge-new, .sector-card.is-new { animation: none; }
}

/* ---------- v2: upgrade meta, reroll, evolution (legendary) cards ---------- */

.upgrade-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  margin-top: -4px;
}

.upgrade-slots {
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.2em;
  color: var(--dim);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.upgrade-slots.is-full { color: var(--magenta); text-shadow: 0 0 8px rgba(255, 90, 209, 0.6); }

.reroll-btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 36px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid var(--edge);
  background: var(--panel);
  color: var(--cyan);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.14em;
  white-space: nowrap;
  cursor: pointer;
  touch-action: manipulation;
  box-shadow: 0 0 12px rgba(77, 243, 255, 0.18);
  transition: transform 0.08s ease, opacity 0.2s ease;
}

.reroll-btn:active:not(:disabled) { transform: scale(0.96); }

.reroll-btn:disabled {
  color: var(--dim);
  border-color: rgba(255, 255, 255, 0.12);
  box-shadow: none;
  opacity: 0.5;
  cursor: default;
}

.rarity-legendary { --rc: #ffd166; }

.upgrade-card.rarity-legendary {
  position: relative;
  overflow: hidden;
  border-width: 2px;
  background:
    linear-gradient(160deg, rgba(255, 209, 102, 0.16), rgba(255, 209, 102, 0.02) 60%),
    rgba(20, 16, 8, 0.92);
  box-shadow: 0 0 24px -4px rgba(255, 209, 102, 0.75), inset 0 0 26px -10px var(--rc);
}

/* shimmer sweep across the card */
.upgrade-card.rarity-legendary::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: -60%;
  width: 40%;
  pointer-events: none;
  background: linear-gradient(100deg, transparent 0%, rgba(255, 246, 214, 0.55) 50%, transparent 100%);
  transform: skewX(-18deg);
  animation: shimmer 2.8s ease-in-out infinite;
}

@keyframes shimmer {
  0%, 35% { left: -60%; }
  100% { left: 130%; }
}

.uc-evo-tag {
  display: inline-block;
  align-self: flex-start;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 9.5px;
  font-weight: 900;
  letter-spacing: 0.22em;
  color: #2a1d00;
  background: linear-gradient(90deg, #ffd166, #fff1b8, #ffd166);
  box-shadow: 0 0 10px rgba(255, 209, 102, 0.7);
}

.uc-requires {
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: #ffe6a6;
  opacity: 0.9;
}

@media (prefers-reduced-motion: reduce) {
  .upgrade-card.rarity-legendary::after { animation: none; display: none; }
}

@media (min-width: 700px) {
  .upgrade-card.rarity-legendary { min-height: 250px; }
}

/* ---------- v2: victory screen ---------- */

.victory-panel {
  border-color: rgba(255, 209, 102, 0.6);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.03), 0 0 60px rgba(255, 209, 102, 0.28), 0 24px 60px rgba(0, 0, 0, 0.55);
  background:
    radial-gradient(120% 60% at 50% 0%, rgba(255, 209, 102, 0.22), transparent 70%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0) 40%),
    var(--panel);
}

.victory-kicker {
  font-size: 11px;
  letter-spacing: 0.4em;
  color: #ffd166;
  text-shadow: 0 0 10px rgba(255, 209, 102, 0.8);
}

.heading-gold {
  color: #fff6d6;
  text-shadow: 0 0 10px #ffd166, 0 0 26px rgba(255, 209, 102, 0.7), 0 0 52px rgba(255, 170, 60, 0.45);
  font-size: clamp(22px, 6.4vw, 30px);
}

#victory-stats .stat-wide .stat-value {
  color: #ffd166;
  text-shadow: 0 0 14px rgba(255, 209, 102, 0.7);
}

.chip-new {
  border-color: rgba(255, 209, 102, 0.7);
  background: linear-gradient(90deg, rgba(255, 209, 102, 0.22), rgba(255, 209, 102, 0.08));
  color: #fff3cc;
  box-shadow: 0 0 10px rgba(255, 209, 102, 0.35);
}

.chip-new .chip-tag {
  padding: 2px 6px;
  border-radius: 999px;
  font-size: 9px;
  letter-spacing: 0.16em;
  color: #2a1d00;
  background: #ffd166;
}

.chip-kind-evolution { border-color: rgba(255, 209, 102, 0.55); }

@media (prefers-reduced-motion: no-preference) {
  .victory-panel .heading-gold { animation: gold-pulse 2.4s ease-in-out infinite alternate; }
}

@keyframes gold-pulse {
  from { filter: brightness(1); }
  to { filter: brightness(1.18); }
}
