/* ============================================================
   CARDS - Building cards, ship cards, trade cards, collection chips
   ============================================================ */

@property --chip-progress {
  syntax: '<percentage>';
  initial-value: 0%;
  inherits: true;
}
@keyframes chip-fill-progress {
  from { --chip-progress: 0%; }
  to { --chip-progress: 100%; }
}

/* --- Card Tabs - pill navigation --- */
.cards-header {
  display: flex;
  align-items: center;
}
.card-tabs {
  display: flex;
  gap: 4px;
  flex-wrap: nowrap;
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.card-tabs::-webkit-scrollbar { display: none; }
.card-tab {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--text-dim);
  font-size: 0.78rem;
  font-weight: 600;
  padding: 4px 12px;
  border-radius: 3px;
  cursor: pointer;
  transition: all 0.2s;
  letter-spacing: 0.03em;
}
.card-tab:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-secondary);
}
.card-tab.active {
  background: rgba(var(--accent-rgb), 0.15);
  border-color: rgba(var(--accent-rgb), 0.4);
  color: var(--cyan);
  text-shadow: 0 0 8px rgba(var(--accent-rgb), 0.3);
}
.tab-icon {
  display: none;
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
@media (max-width: 767px) and (orientation: portrait) {
  .card-tab .tab-icon { display: block; }
  .card-tab span { display: none; }
  .card-tab { padding: 8px 12px; }
  .card-tab.active span { display: inline; }
  .card-tab.active .tab-icon { display: none; }
}

/* --- Building Grid ---
   Auto-fill grid: every card has the same width within the container.
   Incomplete last rows leave right-side gaps rather than stretching,
   so card sizes stay consistent across all rows. */
.building-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: var(--grid-gap);
  align-items: start;
  position: relative;
  z-index: 1;
}
.building-grid > .collection-ribbon,
.building-grid > .collection-section-label,
.building-grid > .stationed-ships-section,
.building-grid > .loan-active-header {
  grid-column: 1 / -1;
}

@media (max-width: 600px) {
  .building-grid {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 6px;
  }
}

/* --- Collection Ribbon --- */
.collection-ribbon {
  grid-column: 1 / -1;
  padding: 0 2px;
  background: none;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  overflow: visible;
}

.collection-ribbon-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

/* Card size switch (Edificios header): mini / medium / large */
.card-size-switch {
  display: inline-flex;
  margin-left: auto;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 6px;
  overflow: hidden;
  flex-shrink: 0;
}
.card-size-btn {
  padding: 3px 8px;
  background: transparent;
  border: 0;
  color: var(--text-secondary, #94a3b8);
  font-family: var(--font-mono);
  font-size: 0.58rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  line-height: 1.4;
  cursor: pointer;
}
.card-size-btn + .card-size-btn {
  border-left: 1px solid rgba(255, 255, 255, 0.14);
}
.card-size-btn.is-active {
  background: rgba(0, 240, 255, 0.14);
  color: var(--text-primary, #e2e8f0);
}

/* Body content per card size: mini = benefit only, medium = + description */
.building-grid.card-size-s .card-info-lore,
.building-grid.card-size-s .card-info-quote,
.building-grid.card-size-m .card-info-quote {
  display: none;
}
.building-grid.card-size-s {
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
}

@media (max-width: 600px) {
  .collection-ribbon-head {
    flex-wrap: wrap;
  }
  .building-grid.card-size-s {
    grid-template-columns: repeat(auto-fill, minmax(118px, 1fr));
  }
}

.collection-ribbon-title {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--cyan);
}

/* Autofarm control in the Colonia sheet header. */
.ribbon-autofarm {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.ribbon-autofarm .autofarm-toggle {
  padding: 3px 10px;
  gap: 6px;
  font-size: 0.66rem;
}
.ribbon-autofarm .autofarm-prefix {
  letter-spacing: 0.04em;
}
.ribbon-autofarm-reason {
  font-size: 0.62rem;
  line-height: 1.15;
  color: var(--text-dim);
  max-width: 96px;
}

/* Colony vitals strip under the Edificios header. */
.colony-vitals {
  display: flex;
  align-items: center;
  gap: 16px;
  margin: -4px 0 10px;
  padding: 0 2px;
}
.colony-vital {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.72rem;
}
.colony-vital-icon {
  width: 13px;
  height: 13px;
  flex: none;
}
.colony-vital-val {
  font-variant-numeric: tabular-nums;
}

.collection-ribbon-total {
  min-width: 24px;
  height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  color: #d8f7ff;
  background: rgba(var(--accent-rgb), 0.16);
  border: 1px solid rgba(var(--accent-rgb), 0.28);
}

.collection-strip-wrap {
  position: relative;
}
.collection-strip-wrap::after {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 32px;
  background: linear-gradient(to right, transparent, rgba(13, 13, 31, 0.9));
  pointer-events: none;
  z-index: 1;
}
.collection-strip {
  display: flex;
  gap: 24px;
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 2px;
  padding-left: 4px;
  scrollbar-width: thin;
  scrollbar-color: rgba(var(--accent-rgb), 0.28) transparent;
}

.collection-strip::-webkit-scrollbar {
  height: 4px;
}

.collection-strip::-webkit-scrollbar-track {
  background: transparent;
}

.collection-strip::-webkit-scrollbar-thumb {
  background: rgba(var(--accent-rgb), 0.28);
  border-radius: 999px;
}

/* --- Collection Chip (compact icon grid) --- */
.collection-chip {
  --collection-color: var(--cyan);
  appearance: none;
  font: inherit;
  text-align: center;
  color: inherit;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 3px 2px 2px;
  border-radius: 4px;
  border: none;
  background: transparent;
  flex-shrink: 0;
  width: 48px;
  transition: transform 0.15s ease, background 0.15s ease;
}

.collection-chip:hover {
  transform: translateY(-1px);
  background: rgba(255, 255, 255, 0.06);
}

.collection-chip:focus:not(:focus-visible) {
  outline: none;
}
.collection-chip:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--collection-color) 56%, white);
  outline-offset: 1px;
  border-radius: 4px;
}

/* --- Vibrate/attention animation --- */
@keyframes chip-vibrate {
  0%, 100% { transform: translateX(0); }
  10% { transform: translateX(-3px) rotate(-1deg); }
  20% { transform: translateX(3px) rotate(1deg); }
  30% { transform: translateX(-3px) rotate(-0.5deg); }
  40% { transform: translateX(3px) rotate(0.5deg); }
  50% { transform: translateX(-2px); }
  60% { transform: translateX(2px); }
  70% { transform: translateX(-1px); }
  80% { transform: translateX(1px); }
}
.chip-vibrate {
  animation: chip-vibrate 0.5s ease-in-out;
}
.chip-vibrate .collection-chip-thumb {
  box-shadow: 0 0 12px rgba(var(--accent-rgb), 0.6);
}
.building-card.chip-vibrate {
  animation: chip-vibrate 0.5s ease-in-out;
  box-shadow: 0 0 16px rgba(var(--accent-rgb), 0.5);
}

@keyframes chip-bounce {
  0%   { transform: translateY(0); }
  25%  { transform: translateY(-8px); }
  50%  { transform: translateY(0); }
  70%  { transform: translateY(-3px); }
  100% { transform: translateY(0); }
}
.chip-bounce {
  animation: chip-bounce 0.45s ease-in-out;
}
.building-card.chip-bounce {
  animation: chip-bounce 0.45s ease-in-out;
  box-shadow: 0 0 12px rgba(var(--accent-rgb), 0.35);
}

.collection-chip-thumb {
  position: relative;
  width: 52px;
  height: 52px;
  border-radius: 4px;
  overflow: visible;
  background: rgba(6, 10, 18, 0.78);
  border: 1px solid transparent;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.32);
  flex-shrink: 0;
}
/* Border overlay: always renders on top of animated images */
.collection-chip-thumb::after {
  content: '';
  position: absolute;
  inset: -1px;
  border-radius: 4px;
  border: 1px solid color-mix(in srgb, var(--collection-color) 30%, rgba(148, 163, 184, 0.18));
  z-index: 2;
  pointer-events: none;
}

.collection-chip-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  border-radius: 3px;
  clip-path: inset(0 round 3px);
  -webkit-user-drag: none;
  user-drag: none;
  pointer-events: none;
}
/* Floating animation for ship/defense chips - uses scale+rotate to avoid overflow clipping */
.collection-chip[data-collection-kind="ship"] .collection-chip-thumb img,
.collection-chip[data-collection-kind="defense"] .collection-chip-thumb img {
  animation: chip-ship-float 5s ease-in-out infinite;
  will-change: transform;
}
@keyframes chip-ship-float {
  0%, 100% { transform: scale(1) rotate(0deg); }
  25%      { transform: scale(1.02) rotate(-0.6deg); }
  50%      { transform: scale(1.04) rotate(0deg); }
  75%      { transform: scale(1.02) rotate(0.6deg); }
}
.collection-chip[data-collection-kind="ship"]:nth-child(2n) .collection-chip-thumb img,
.collection-chip[data-collection-kind="defense"]:nth-child(2n) .collection-chip-thumb img { animation-delay: -1.2s; }
.collection-chip[data-collection-kind="ship"]:nth-child(3n) .collection-chip-thumb img,
.collection-chip[data-collection-kind="defense"]:nth-child(3n) .collection-chip-thumb img { animation-delay: -2.5s; }
.collection-chip[data-collection-kind="ship"]:nth-child(5n) .collection-chip-thumb img,
.collection-chip[data-collection-kind="defense"]:nth-child(5n) .collection-chip-thumb img { animation-delay: -3.8s; }

.collection-chip-badge {
  position: absolute;
  bottom: -5px;
  right: -6px;
  min-width: 26px;
  height: 26px;
  padding: 0 5px;
  font-size: 0.85rem;
  font-weight: 700;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  background: color-mix(in srgb, var(--collection-color) 80%, #111);
  border: 1.5px solid var(--scrim-50);
  border-radius: 13px;
  white-space: nowrap;
  z-index: 3;
  pointer-events: none;
}

/* ─── Chip upgrade fill animation ──────────────────────── */
/* Image stays full color; a ::before overlay dims the unfilled portion */
.chip-upgrading .collection-chip-thumb::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 1;
  border-radius: 3px;
  pointer-events: none;
  background: rgba(2, 6, 14, 0.55);
  -webkit-backdrop-filter: saturate(0.3) brightness(0.45);
  backdrop-filter: saturate(0.3) brightness(0.45);
  clip-path: inset(0 0 var(--chip-progress, 0%) 0);
}

/* Glowing scan line at the fill surface */
.chip-upgrading .collection-chip-thumb::after {
  inset: auto;
  border: none;
  left: 2px;
  right: 2px;
  bottom: var(--chip-progress, 0%);
  height: 2px;
  border-radius: 1px;
  background: linear-gradient(90deg, transparent 0%, #fbbf24 20%, #fff 50%, #fbbf24 80%, transparent 100%);
  box-shadow: 0 0 5px 1px rgba(251, 191, 36, 0.7), 0 0 12px 2px rgba(245, 158, 11, 0.35);
  opacity: 0.9;
  animation: chip-scanline-pulse 1.8s ease-in-out infinite;
}
@keyframes chip-scanline-pulse {
  0%, 100% { opacity: 0.7; }
  50% { opacity: 1; }
}

/* Badge blink for new construction (level 0 → 1) */
.chip-badge-new {
  animation: chip-badge-blink 2s step-end infinite;
}
@keyframes chip-badge-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

/* Badge alternation: current level fades out, next level fades in */
.chip-badge-alt {
  animation: chip-badge-fade 2.4s ease-in-out infinite;
}
.chip-badge-alt::after {
  content: attr(data-next);
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  animation: chip-badge-fade-in 2.4s step-end infinite;
}
@keyframes chip-badge-fade {
  0%, 50% { color: rgba(255, 255, 255, 0.7); }
  50.01%, 100% { color: transparent; }
}
@keyframes chip-badge-fade-in {
  0%, 50% { opacity: 0; }
  50.01%, 100% { opacity: 1; }
}

/* Working border for upgrading and queued chips: static frame with a slow
   breathe, calmer than marching ants */
.chip-upgrading,
.chip-queued {
  position: relative;
}
.chip-upgrading .collection-chip-thumb,
.chip-upgrading.chip-mission .collection-chip-thumb,
.chip-queued .collection-chip-thumb,
.chip-queued.chip-mission .collection-chip-thumb {
  border-color: transparent;
}
.chip-upgrading::before,
.chip-queued::before {
  content: '';
  position: absolute;
  top: 3px;
  left: 50%;
  width: 52px;
  height: 52px;
  transform: translateX(-50%);
  border-radius: 5px;
  pointer-events: none;
  z-index: 3;
  border: 2px solid var(--chip-march-color);
  animation: chip-working-breathe 2.8s ease-in-out infinite;
}
.chip-upgrading { --chip-march-color: #f59e0b; }
.chip-queued { --chip-march-color: color-mix(in srgb, var(--collection-color) 50%, rgba(148, 163, 184, 0.5)); }
@keyframes chip-working-breathe {
  0%, 100% { opacity: 0.35; }
  50% { opacity: 0.95; }
}
@media (prefers-reduced-motion: reduce) {
  .chip-upgrading::before,
  .chip-queued::before { animation: none; opacity: 0.8; }
}

/* Queued chip: slightly dimmed image */
.chip-queued .collection-chip-thumb > img {
  filter: saturate(0.4) brightness(0.55);
  opacity: 0.7;
}
.chip-queued .collection-chip-badge {
  opacity: 0.7;
}

/* Shimmer on upgrading / queued chip names */
.chip-upgrading .collection-chip-name,
.chip-queued .collection-chip-name {
  background: linear-gradient(
    90deg,
    rgba(248, 250, 252, 0.72) 0%,
    rgba(248, 250, 252, 0.72) 30%,
    #fff 50%,
    rgba(248, 250, 252, 0.72) 70%,
    rgba(248, 250, 252, 0.72) 100%
  );
  background-size: 300% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  animation: chip-name-shimmer 3s ease-in-out infinite;
}
@keyframes chip-name-shimmer {
  0%   { background-position: 100% 0; }
  100% { background-position: -100% 0; }
}

/* Queued + blocked (insufficient resources): warning overlay */
.chip-queued-blocked-icon {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  z-index: 3;
  filter: drop-shadow(0 0 4px var(--scrim-70));
}
.chip-blocked-phase {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  white-space: nowrap;
}
.chip-blocked-prohib {
  width: 26px;
  height: 26px;
  color: #f59e0b;
  animation: chip-alt-a 4s step-end infinite;
}
.chip-blocked-deficit {
  font-size: 0.85rem;
  font-weight: 800;
  animation: chip-alt-b 4s step-end infinite;
}
.chip-blocked-deficit .cost-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}
.chip-deficit-num {
  color: #ef4444;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.9);
}
/* When there's no deficit data, keep single icon pulsing */
.chip-queued-blocked-icon:not(:has(.chip-blocked-deficit)) .chip-blocked-prohib {
  animation: chip-blocked-pulse 2s ease-in-out infinite;
}
@keyframes chip-blocked-pulse {
  0%, 100% { opacity: 0.85; }
  50% { opacity: 1; }
}
/* Alternation: show prohib for 2s, then deficit for 2s */
@keyframes chip-alt-a {
  0%  { opacity: 1; }
  50% { opacity: 0; }
}
@keyframes chip-alt-b {
  0%  { opacity: 0; }
  50% { opacity: 1; }
}
.collection-grid-lg .chip-blocked-prohib {
  width: 32px;
  height: 32px;
}
.collection-grid-lg .chip-blocked-deficit {
  font-size: 0.95rem;
}
.collection-grid-lg .chip-blocked-deficit .cost-icon {
  width: 22px;
  height: 22px;
}
.chip-queued-blocked .collection-chip-thumb {
  border-color: transparent;
}
.chip-queued-blocked { --chip-march-color: color-mix(in srgb, #f59e0b 50%, rgba(148, 163, 184, 0.5)); }
.chip-queued-blocked .collection-chip-thumb > img {
  filter: saturate(0.15) brightness(0.3);
  opacity: 0.5;
}

/* Unbuilt chip: available but not yet constructed */
.chip-unbuilt .collection-chip-thumb {
  border-style: dashed;
  border-color: transparent;
}

/* Available chip: requirements met AND resources sufficient.
   Subtle warm border = ready to build. Plays a small idle bounce
   every few seconds to nudge the player toward what they can do. */
.chip-available .collection-chip-thumb {
  border: 2px solid rgba(200, 160, 64, 0.55);
}
@keyframes chip-idle-bounce {
  0%, 92%, 100% { transform: translateY(0); }
  94%           { transform: translateY(-6px); }
  96%           { transform: translateY(0); }
  98%           { transform: translateY(-2px); }
}
.chip-available {
  animation: chip-idle-bounce 9s ease-in-out infinite;
}
/* Pause the bounce while the user is interacting with that chip
   so it does not jitter under the cursor. */
.chip-available:hover,
.chip-available:focus-visible {
  animation-play-state: paused;
}

/* Short-resources chip: requirements met, NOT enough resources yet.
   Dashed amber border + desaturated image + coin-slash corner icon. */
.chip-short-resources .collection-chip-thumb {
  border: 2px dashed #f59e0b;
}
.chip-short-resources .collection-chip-thumb > img {
  filter: saturate(0.55) brightness(0.75);
}
.chip-short-icon {
  position: absolute;
  right: -6px;
  bottom: -6px;
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(11, 18, 32, 0.95);
  border: 1px solid rgba(245, 158, 11, 0.7);
  border-radius: 50%;
  color: #f59e0b;
  z-index: 4;
  pointer-events: none;
  filter: drop-shadow(0 0 4px rgba(245, 158, 11, 0.5));
}
.chip-short-icon svg {
  width: 14px;
  height: 14px;
}

/* Recommended chip visual removed - was confusing (looked like "built") */

/* Mission chip: solid gold border */
.chip-mission .collection-chip-thumb {
  border: 2px solid #f59e0b;
}

/* Mission star icon (top-left, opposite level badge) */
.chip-mission-star {
  position: absolute;
  top: -4px;
  left: -4px;
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(30, 30, 50, 0.85);
  border: 1px solid rgba(245, 158, 11, 0.5);
  border-radius: 10px;
  z-index: 3;
  pointer-events: none;
  color: #f59e0b;
  filter: drop-shadow(0 0 3px rgba(245, 158, 11, 0.6));
  animation: missionStarPulse 2s ease-in-out infinite;
}
@keyframes missionStarPulse {
  0%, 100% { filter: drop-shadow(0 0 3px rgba(245, 158, 11, 0.4)); opacity: 0.85; }
  50% { filter: drop-shadow(0 0 6px rgba(245, 158, 11, 0.9)); opacity: 1; }
}
.chip-upgrading .chip-mission-star {
  animation: missionStarSpin 1.5s linear infinite;
}
@keyframes missionStarSpin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}
.chip-mission-star svg {
  width: 12px;
  height: 12px;
  fill: currentColor;
}
.collection-grid-lg .chip-mission-star {
  width: 24px;
  height: 24px;
  border-radius: 12px;
  top: -5px;
  left: -5px;
}
.collection-grid-lg .chip-mission-star svg {
  width: 14px;
  height: 14px;
}

/* Locked chip: tech-gated */
.chip-locked .collection-chip-thumb {
  border-color: rgba(100, 116, 139, 0.15);
}
.chip-locked .collection-chip-thumb > img {
  filter: saturate(0) brightness(0.2);
  opacity: 0.25;
}
.chip-locked .collection-chip-thumb::after {
  border-color: rgba(100, 116, 139, 0.1);
}
.chip-locked .collection-chip-badge {
  display: none;
}
.chip-locked .collection-chip-name {
  opacity: 0.45;
  color: rgba(148, 163, 184, 0.6);
}
/* Dark overlay on locked chip thumbnail */
.chip-dark-overlay {
  position: absolute;
  inset: 0;
  background: rgba(6, 10, 18, 0.6);
  border-radius: 3px;
  z-index: 1;
  pointer-events: none;
}
.chip-lock-icon {
  position: absolute;
  bottom: -4px;
  right: -4px;
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(30, 30, 50, 0.9);
  border: 1px solid rgba(100, 116, 139, 0.3);
  border-radius: 11px;
  z-index: 3;
  pointer-events: none;
  color: rgba(148, 163, 184, 0.55);
}
.chip-lock-icon svg {
  width: 12px;
  height: 12px;
  fill: currentColor;
}

/* Unbuilt chip: "+" badge */
.chip-unbuilt .collection-chip-thumb::after {
  border-style: dashed;
  border-color: color-mix(in srgb, var(--collection-color) 40%, rgba(148, 163, 184, 0.25));
}
.chip-badge-plus {
  background: color-mix(in srgb, var(--collection-color) 25%, rgba(30, 30, 50, 0.9));
  border: 1px solid color-mix(in srgb, var(--collection-color) 50%, transparent);
  color: var(--collection-color);
  font-weight: 700;
  font-size: 0.85rem;
}
.chip-unbuilt .collection-chip-thumb > img {
  opacity: 0.55;
  filter: brightness(0.75) saturate(0.7);
}
.chip-unbuilt .collection-chip-name {
  opacity: 0.72;
}

/* ─── Collection grid (wrapping, replaces strip scroll) ── */
.collection-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(58px, 1fr));
  gap: 8px 4px;
  padding: 4px 0;
  justify-items: center;
}
.collection-grid.collection-grid-lg {
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
}

/* ─── Large grid mode ────────────────────────────────────── */
.collection-grid-lg .collection-chip {
  width: 88px;
}
.collection-grid-lg .collection-chip-thumb {
  width: 96px;
  height: 96px;
  border-radius: 6px;
}
.collection-grid-lg .collection-chip-badge {
  min-width: 30px;
  height: 30px;
  font-size: 1rem;
  border-radius: 15px;
  bottom: -6px;
  right: -7px;
}
.collection-grid-lg .chip-lock-icon {
  width: 26px;
  height: 26px;
  border-radius: 13px;
  bottom: -5px;
  right: -5px;
}
.collection-grid-lg .chip-lock-icon svg {
  width: 14px;
  height: 14px;
}
.collection-grid-lg .chip-upgrading::before,
.collection-grid-lg .chip-queued::before {
  width: 96px;
  height: 96px;
  border-radius: 7px;
}
/* .collection-grid-lg .chip-recommended removed */
.collection-grid-lg .chip-mission .collection-chip-thumb {
  border-width: 3px;
}
.collection-grid-lg .collection-chip-name {
  font-size: 0.68rem;
  max-width: 96px;
}
.collection-grid-lg .chip-fill {
  height: 2px;
}
.collection-grid-lg .chip-dark-overlay {
  border-radius: 5px;
}
.collection-grid-lg .chip-badge-plus {
  font-size: 1.1rem;
}

/* Research progress ribbon: explicit active / queued status tag */
.research-chip-tag {
  margin-top: 1px;
  padding: 1px 6px;
  border-radius: 999px;
  font-size: 0.5rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  line-height: 1.4;
  white-space: nowrap;
}
.research-chip-tag--active {
  color: #cdebff;
  background: rgba(56, 189, 248, 0.18);
  border: 1px solid rgba(56, 189, 248, 0.5);
}
.research-chip-tag--queued {
  color: #ffe7ad;
  background: rgba(251, 191, 36, 0.16);
  border: 1px solid rgba(251, 191, 36, 0.5);
}

.collection-chip-name {
  font-size: 0.6rem;
  font-weight: 600;
  color: rgba(248, 250, 252, 0.72);
  line-height: 1.15;
  max-width: 68px;
  text-align: center;
  word-wrap: break-word;
  overflow-wrap: break-word;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.collection-empty {
  padding: 8px 2px 2px;
  color: var(--text-dim);
  font-size: 0.74rem;
}

.collection-section-label {
  grid-column: 1 / -1;
  margin-top: 8px;
  margin-bottom: -2px;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: rgba(194, 246, 255, 0.92);
}

/* Building group headings inside the Edificios grid */
.collection-section-label.bld-group-label {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 14px;
  font-size: 0.72rem;
}
.collection-section-label.bld-group-label::after {
  content: '';
  flex: 1;
  height: 1px;
  background: rgba(194, 246, 255, 0.22);
}
.building-grid > .bld-group-label:first-child { margin-top: 0; }

/* Spaceport hangar capacity (mission-first P1) */
.building-grid > .hangar-cap {
  grid-column: 1 / -1;
}
.hangar-cap {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin: 6px 0 0;
  font-size: 0.8rem;
  color: rgba(194, 246, 255, 0.92);
  appearance: none;
  border: none;
  background: transparent;
  padding: 0;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.hangar-cap:hover {
  color: #e8fcff;
}
.hangar-cap:focus-visible {
  outline: 2px solid rgba(0, 240, 255, 0.55);
  outline-offset: 2px;
  border-radius: 6px;
}
.hangar-cap .icon {
  width: 16px;
  height: 16px;
  color: #00f0ff;
  flex-shrink: 0;
}
.hangar-cap-bar {
  flex: 0 1 140px;
  height: 6px;
  border-radius: 3px;
  background: rgba(0, 240, 255, 0.15);
  overflow: hidden;
}
.hangar-cap-fill {
  height: 100%;
  border-radius: 3px;
  background: #00f0ff;
}
.hangar-cap-full .icon,
.hangar-cap-full .font-mono {
  color: #fbbf24;
}
.hangar-cap-full .hangar-cap-fill {
  background: #fbbf24;
}
.hangar-cap-body {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.hangar-cap-status-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-size: 0.72rem;
  line-height: 1.2;
}
.hangar-cap-upgrading .hangar-cap-label {
  color: rgba(194, 246, 255, 0.92);
  font-weight: 600;
  line-height: 1.2;
}
.hangar-cap-upgrading .hangar-cap-status,
.hangar-cap-upgrading .hangar-cap-upgrade-pct {
  color: #fbbf24;
}
.hangar-cap-upgrading {
  align-items: flex-start;
  flex-wrap: nowrap;
}
.hangar-cap-upgrading .icon {
  align-self: flex-start;
  margin-top: 3px;
}
.hangar-cap-upgrading .hangar-cap-body {
  flex: 1;
  min-width: 0;
}
.hangar-cap-upgrading .hangar-cap-bar {
  flex: 0 0 6px;
  width: 100%;
  max-width: 168px;
  height: 6px;
  margin: 5px auto 0;
  align-self: center;
  background: rgba(251, 191, 36, 0.2);
}
.hangar-cap-upgrading .hangar-cap-fill {
  background: linear-gradient(90deg, #f59e0b, #fbbf24);
  animation: hangar-cap-pulse 1.6s ease-in-out infinite;
}
.hangar3d-cap .hangar-cap-upgrading {
  border-color: rgba(251, 191, 36, 0.45);
  background: rgba(20, 12, 2, 0.82);
}
.hangar3d-cap .hangar-cap-upgrading:hover {
  border-color: rgba(251, 191, 36, 0.65);
  background: rgba(28, 16, 4, 0.9);
}
@keyframes hangar-cap-pulse {
  0%, 100% { opacity: 0.85; }
  50% { opacity: 1; }
}
.hangar-cap-hint {
  flex-basis: 100%;
  color: #fde68a;
}
/* With 4 tabs (Civiles/Ligeras/Pesadas/Capitales), the longest label
   ("Capitales") would push past the rounded container because flex items
   default to min-width:auto. Allow each tab to shrink to its flex-basis
   and tighten horizontal padding/gap so all four fit comfortably. */
.ships-class-subtabs .leaders-subtab {
  min-width: 0;
  padding: 8px 8px;
  gap: 6px;
}
.ships-class-subtabs .leaders-subtab > span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ships-class-subtabs .ships-class-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  opacity: 0.8;
  transition: opacity 120ms ease;
}
.ships-class-subtabs .leaders-subtab:hover .ships-class-icon,
.ships-class-subtabs .leaders-subtab.active-fleet .ships-class-icon {
  opacity: 1;
}

.build-slots-badge {
  display: inline-block;
  margin-left: 8px;
  padding: 1px 6px;
  font-size: 0.62rem;
  letter-spacing: 0.06em;
  border-radius: 4px;
  background: rgba(139, 92, 246, 0.25);
  border: 1px solid rgba(139, 92, 246, 0.5);
  color: #c4b5fd;
  vertical-align: middle;
}

.build-fields-badge {
  display: inline-block;
  margin-left: 8px;
  padding: 1px 6px;
  font-size: 11.5px;
  letter-spacing: 0.06em;
  border-radius: 4px;
  background: rgba(0, 240, 255, 0.18);
  border: 1px solid rgba(0, 240, 255, 0.45);
  color: #a8eeff;
  vertical-align: middle;
}


/* --- Collection Detail Overlay --- */
body.collection-detail-open {
  overflow: hidden;
}
body.collection-detail-open .bottom-nav {
  display: none;
}

.collection-detail-overlay {
  position: fixed;
  inset: 0;
  z-index: 1200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(20px + env(safe-area-inset-top, 0px)) 14px calc(20px + env(safe-area-inset-bottom, 0px));
  background:
    radial-gradient(circle at top, rgba(var(--accent-rgb), 0.14), transparent 34%),
    rgba(3, 6, 14, 0.82);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}

.collection-detail-overlay[hidden] {
  display: none !important;
}

.collection-detail-panel {
  --detail-color: var(--cyan);
  width: min(720px, 100%);
  max-height: min(88vh, 900px);
  max-height: min(88dvh, 900px);
  overflow: auto;
  overscroll-behavior: none;
  display: flex;
  flex-direction: column;
  padding: 18px;
  padding-top: 0;
  border-radius: 4px;
  border-image-source: url('../../assets/ui/hud-frame.webp');
  border-image-slice: 94;
  border-image-width: 7px;
  border-image-repeat: stretch;
  border-style: solid;
  border-width: 7px;
  box-shadow:
    0 24px 60px var(--scrim-50),
    0 0 30px color-mix(in srgb, var(--detail-color) 10%, transparent);
}

.collection-detail-dismiss {
  position: sticky;
  top: 6px;
  align-self: flex-end;
  width: 34px;
  height: 34px;
  padding: 0;
  margin: 6px -14px -40px 0;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(10, 14, 24, 0.9);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 2;
  flex-shrink: 0;
  transition: all 0.18s ease;
}
.collection-detail-dismiss svg {
  display: block;
  flex-shrink: 0;
}

.collection-detail-dismiss:hover {
  color: #fff;
  border-color: color-mix(in srgb, var(--detail-color) 28%, rgba(255, 255, 255, 0.12));
  box-shadow: 0 0 18px color-mix(in srgb, var(--detail-color) 14%, transparent);
}

.collection-detail-hero {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  margin-bottom: 12px;
}

.collection-detail-art {
  position: relative;
  width: calc(100% + 36px);
  margin: 0 -18px 0;
  min-height: 180px;
  max-height: 200px;
  border-radius: 0;
  overflow: hidden;
  border: none;
  background: rgba(8, 12, 24, 0.9);
}

.collection-detail-art::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(180deg,
      rgba(8, 12, 24, 0) 0%,
      rgba(8, 12, 24, 0.1) 50%,
      rgba(8, 12, 24, 0.65) 85%,
      rgba(8, 12, 24, 0.95) 100%),
    linear-gradient(90deg,
      rgba(8, 12, 24, 0.3) 0%,
      transparent 30%,
      transparent 70%,
      rgba(8, 12, 24, 0.3) 100%);
}

.collection-detail-art img {
  width: 100%;
  height: 100%;
  min-height: 180px;
  max-height: 200px;
  object-fit: cover;
  object-position: center center;
  display: block;
  filter: brightness(0.88) saturate(1.12);
  will-change: transform;
  animation: detail-art-pan 60s linear infinite;
}
@keyframes detail-art-pan {
  0%   { transform: scale(1.08) translateY(0); }
  25%  { transform: scale(1.15) translateY(-3%); }
  50%  { transform: scale(1.08) translateY(0); }
  75%  { transform: scale(1.15) translateY(3%); }
  100% { transform: scale(1.08) translateY(0); }
}

.collection-detail-head {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.collection-detail-kicker,
.collection-detail-section-title {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: color-mix(in srgb, var(--detail-color) 70%, #d8f7ff);
}

.collection-detail-title {
  margin: 0;
  font-size: 1.15rem;
  line-height: 1.1;
  color: #f8fafc;
}

.collection-detail-subtitle {
  color: var(--text-secondary);
  font-size: 0.8rem;
  line-height: 1.45;
}

.collection-detail-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.collection-detail-tag {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 11px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-secondary);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.collection-detail-tag.is-accent {
  border-color: color-mix(in srgb, var(--detail-color) 28%, rgba(255, 255, 255, 0.1));
  background: color-mix(in srgb, var(--detail-color) 14%, rgba(255, 255, 255, 0.04));
  color: color-mix(in srgb, var(--detail-color) 76%, white);
}

.collection-detail-section + .collection-detail-section {
  margin-top: 12px;
}

.collection-detail-subtab-strip {
  display: flex;
  gap: 0;
  margin: 4px 0 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.collection-detail-subtab {
  position: relative;
  flex: 1 1 auto;
  padding: 10px 14px;
  border: none;
  border-bottom: 2px solid transparent;
  background: transparent;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.5);
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

.collection-detail-subtab:hover {
  color: rgba(255, 255, 255, 0.85);
}

.collection-detail-subtab.is-active {
  color: color-mix(in srgb, var(--detail-color) 80%, white);
  border-bottom-color: var(--detail-color);
  background: linear-gradient(180deg, transparent, color-mix(in srgb, var(--detail-color) 8%, transparent));
}

.collection-detail-subtab-pane[hidden] {
  display: none;
}

.collection-detail-facts,
.collection-detail-cost-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 8px;
}
.economy-no-title .collection-detail-cost-grid {
  grid-template-columns: 1fr;
}
.collection-detail-cost-grid.single {
  grid-template-columns: 1fr;
}

.collection-detail-fact,
.collection-detail-cost-card {
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background:
    linear-gradient(180deg, rgba(11, 16, 28, 0.92), rgba(7, 11, 21, 0.82));
  padding: 8px 10px 7px;
  min-width: 0;
}
.collection-detail-cost-card {
  display: flex;
  flex-direction: column;
}
.collection-detail-cost-card .btn-detail-upgrade {
  margin-top: auto;
}

.collection-detail-fact-label,
.collection-detail-cost-label {
  font-size: 0.64rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 4px;
}

.collection-detail-fact-value,
.collection-detail-cost-value {
  color: #f8fafc;
  font-size: 0.85rem;
  line-height: 1.35;
  min-width: 0;
  overflow-wrap: break-word;
  word-break: normal;
}
.collection-detail-cost-value .bld-cost {
  gap: 0 6px;
}
.collection-detail-cost-value {
  /* Flex-wrap so 4+ resource pairs can flow onto a second row inside the
     narrow 2-column cost card (half the panel width on mobile). The inline
     grid-row/grid-column styles emitted by formatCost() become no-ops on
     flex items - pairs render in document order: icon, number, icon, number.
     Without wrap, 4 pairs would overflow the card border on iPhone. */
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  column-gap: 0;
  row-gap: 2px;
}
.collection-detail-cost-value .cost-icon-cell {
  padding-right: 2px;
}
.collection-detail-cost-value .cost-num-cell {
  padding-right: 8px;
  white-space: nowrap;
}
.collection-detail-cost-value .cost-num-cell:last-of-type {
  padding-right: 0;
}

.collection-detail-fact-value .cost-icon,
.collection-detail-cost-value .cost-icon {
  width: 14px;
  height: 14px;
  vertical-align: -2px;
}
.collection-detail-cost-card .card-action-row {
  padding: 8px 0 0;
}
.collection-detail-cost-card .detail-status-badge {
  margin-top: 6px;
}
.detail-queue-deficit {
  font-size: 0.7rem;
  line-height: 1.35;
  margin: 2px 0 6px;
}
.detail-queue-deficit .queue-missing-label {
  color: var(--text-dim);
}
.detail-startnow-btn {
  white-space: nowrap;
}

/* Row-based characteristics layout */
.collection-detail-facts-rows {
  display: grid;
  grid-template-columns: auto 1fr;
  column-gap: 16px;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: linear-gradient(180deg, rgba(11, 16, 28, 0.92), rgba(7, 11, 21, 0.82));
  overflow: hidden;
}
.collection-detail-fact-row {
  display: contents;
}
.collection-detail-fact-row .collection-detail-fact-label,
.collection-detail-fact-row .collection-detail-fact-value {
  padding: 6px 12px;
  margin-bottom: 0;
}
.collection-detail-fact-row .collection-detail-fact-label {
  padding-right: 0;
}
.collection-detail-fact-row .collection-detail-fact-value {
  text-align: left;
  padding-left: 0;
}
.collection-detail-fact-row + .collection-detail-fact-row .collection-detail-fact-label,
.collection-detail-fact-row + .collection-detail-fact-row .collection-detail-fact-value {
  border-top: 1px solid rgba(255, 255, 255, 0.05);
}
.fact-icon {
  width: 14px;
  height: 14px;
  vertical-align: -2px;
  margin-right: 5px;
  opacity: 0.85;
  flex-shrink: 0;
}
.detail-req-check { color: #22c55e; margin-left: 4px; }
.detail-req-missing { color: #f87171; font-size: 0.65rem; margin-left: 4px; font-family: var(--font-mono); }
.fact-unmet .collection-detail-fact-label,
.fact-unmet .collection-detail-fact-value { color: #f87171; }
.collection-detail-fact-clickable .collection-detail-fact-label,
.collection-detail-fact-clickable .collection-detail-fact-value {
  cursor: pointer;
  transition: background-color 0.15s ease;
}
.collection-detail-fact-clickable:hover .collection-detail-fact-label,
.collection-detail-fact-clickable:hover .collection-detail-fact-value {
  background: rgba(255, 255, 255, 0.04);
}

/* Compact variant: pack each requirement as a single inline chip and lay
 * them out in a 2-3 column grid. Used for the research detail "Requisitos"
 * list which can have 6+ rows and otherwise stretches the modal. */
.collection-detail-facts-rows.collection-detail-facts-compact {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  column-gap: 6px;
  row-gap: 4px;
  border: 0;
  background: transparent;
  border-radius: 0;
  overflow: visible;
}
.collection-detail-facts-compact .collection-detail-fact-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 4px 8px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: linear-gradient(180deg, rgba(11, 16, 28, 0.92), rgba(7, 11, 21, 0.82));
}
.collection-detail-facts-compact .collection-detail-fact-row + .collection-detail-fact-row .collection-detail-fact-label,
.collection-detail-facts-compact .collection-detail-fact-row + .collection-detail-fact-row .collection-detail-fact-value {
  border-top: 0;
}
.collection-detail-facts-compact .collection-detail-fact-row .collection-detail-fact-label,
.collection-detail-facts-compact .collection-detail-fact-row .collection-detail-fact-value {
  padding: 0;
  font-size: 0.7rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.collection-detail-facts-compact .collection-detail-fact-row .collection-detail-fact-label {
  flex: 1 1 auto;
  min-width: 0;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 0.6rem;
  opacity: 0.85;
}
.collection-detail-facts-compact .collection-detail-fact-row .collection-detail-fact-value {
  flex: 0 0 auto;
}

.collection-detail-cost-meta {
  margin-top: 8px;
  color: var(--text-dim);
  font-size: 0.68rem;
  font-family: var(--font-mono);
}

.btn-detail-upgrade {
  margin-top: 10px;
  width: 100%;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
  transition: all 0.18s ease;
  /* Prevent iOS double-tap-to-zoom when the user taps Construir twice fast. */
  touch-action: manipulation;
}

.btn-detail-upgrade {
  color: color-mix(in srgb, var(--detail-color) 80%, white);
  border: 1px solid color-mix(in srgb, var(--detail-color) 32%, rgba(255, 255, 255, 0.1));
  background: color-mix(in srgb, var(--detail-color) 16%, rgba(9, 13, 24, 0.85));
}

.btn-detail-upgrade:disabled,
.btn-detail-upgrade.btn-detail-unaffordable {
  opacity: 0.5;
  cursor: not-allowed;
}
.btn-detail-upgrade.btn-detail-unaffordable {
  animation: none;
}

/* ── Paired sections/actions: two columns that hold at phone widths and
   only fall back to a stack on very narrow screens ── */
.collection-detail-duo {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  align-items: start;
}
.collection-detail-duo > .collection-detail-section { min-width: 0; margin-top: 0; }
.collection-detail-duo > .collection-detail-section + .collection-detail-section { margin-top: 0; }
.detail-action-duo {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  align-items: stretch;
  margin-top: 10px;
}
.detail-action-duo > .btn-detail-upgrade { margin-top: 0; height: auto; min-width: 0; }
.detail-action-duo > .perf-block { margin-top: 0; min-width: 0; }
/* Compact Mejorar cell: label + modifier + cost stacked inside the button */
.btn-detail-mejorar {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 8px 6px;
}
.btn-detail-mejorar b {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
}
.btn-detail-mejorar .mejorar-benefit {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: none;
  letter-spacing: 0.02em;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 2px;
}
.btn-detail-mejorar .mejorar-cost {
  font-size: 0.66rem;
  font-family: var(--font-mono);
  text-transform: none;
  letter-spacing: 0.02em;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 2px 7px;
  opacity: 0.92;
}
.btn-detail-mejorar .mejorar-cost svg,
.btn-detail-mejorar .mejorar-benefit svg { width: 13px; height: 13px; }
@media (max-width: 340px) {
  .collection-detail-duo, .detail-action-duo { grid-template-columns: 1fr; }
}

/* ── Perfection track (hybrid fusion): diamond pips + hatched XP bar.
   Shape/pattern coded on purpose: it must read apart from the plain paid
   level bar without relying on hue. ── */
.perf-block {
  margin-top: 12px;
  padding: 10px 12px;
  border: 1px dashed color-mix(in srgb, var(--detail-color) 40%, rgba(255, 255, 255, 0.14));
  border-radius: 8px;
  background: rgba(9, 13, 24, 0.55);
  text-align: left;
}
.perf-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 2px 8px;
  flex-wrap: wrap;
}
.perf-label { white-space: nowrap; }
.perf-label {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: color-mix(in srgb, var(--detail-color) 75%, white);
}
.perf-bonus {
  font-size: 0.72rem;
  font-family: var(--font-mono);
  color: var(--text-dim);
}
.perf-pips {
  /* flex row, never an unbreakable inline run: pips shrink to the column
     and wrap instead of spilling past the dashed border */
  display: flex;
  flex-wrap: wrap;
  column-gap: 2px;
  row-gap: 3px;
  margin-top: 6px;
  font-size: 0.8rem;
  letter-spacing: 0;
  line-height: 1;
  user-select: none;
  max-width: 100%;
  overflow: hidden;
}
.perf-pip { opacity: 0.35; }
.perf-pip.filled { opacity: 1; }
.perf-xpbar {
  margin-top: 7px;
  height: 6px;
  border-radius: 3px;
  overflow: hidden;
  background: repeating-linear-gradient(
    -45deg,
    rgba(255, 255, 255, 0.06) 0 4px,
    rgba(255, 255, 255, 0.14) 4px 8px
  );
}
.perf-xpbar i {
  display: block;
  height: 100%;
  background: repeating-linear-gradient(
    -45deg,
    color-mix(in srgb, var(--detail-color) 75%, white) 0 4px,
    color-mix(in srgb, var(--detail-color) 45%, transparent) 4px 8px
  );
}
.btn-detail-perfect {
  margin-top: 10px;
  border-style: dashed;
}

/* Glow pulse animation for active build/upgrade buttons */
@keyframes btn-glow-pulse {
  0%, 100% {
    box-shadow: 0 0 6px color-mix(in srgb, var(--detail-color) 12%, transparent),
                inset 0 0 4px color-mix(in srgb, var(--detail-color) 6%, transparent);
    border-color: color-mix(in srgb, var(--detail-color) 32%, rgba(255, 255, 255, 0.1));
  }
  50% {
    box-shadow: 0 0 16px color-mix(in srgb, var(--detail-color) 28%, transparent),
                0 0 30px color-mix(in srgb, var(--detail-color) 10%, transparent),
                inset 0 0 8px color-mix(in srgb, var(--detail-color) 10%, transparent);
    border-color: color-mix(in srgb, var(--detail-color) 55%, rgba(255, 255, 255, 0.15));
  }
}

.btn-detail-upgrade:not(.btn-detail-disabled):not(.btn-detail-locked):not(.btn-detail-enqueue):not(:disabled) {
  animation: btn-glow-pulse 2.4s ease-in-out infinite;
}

.btn-detail-upgrade:hover {
  background: color-mix(in srgb, var(--detail-color) 24%, rgba(9, 13, 24, 0.9));
  box-shadow: 0 0 18px color-mix(in srgb, var(--detail-color) 16%, transparent);
  animation: none;
}

.btn-detail-upgrade.btn.cta {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 10px 12px;
  animation: none;
}
.btn-detail-upgrade.btn.cta .cl {
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.btn-detail-upgrade.btn.cta .cc {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  color: var(--text-secondary);
}
.btn-detail-upgrade.btn.cta.ok .cc { color: #a7f3d0; }
.btn-detail-upgrade.btn.cta.dim .cc { color: #f87171; }

.btn-detail-enqueue {
  background: rgba(168, 85, 247, 0.12);
  border-color: rgba(168, 85, 247, 0.3);
  color: #a855f7;
}
.btn-detail-enqueue:hover {
  background: rgba(168, 85, 247, 0.2);
}
.btn-detail-locked {
  background: rgba(100, 116, 139, 0.12);
  border-color: rgba(100, 116, 139, 0.3);
  color: #64748b;
  cursor: not-allowed;
  opacity: 0.6;
}
.detail-benefit {
  font-size: 0.78rem;
  font-weight: 600;
  margin-bottom: 6px;
  line-height: 1.3;
}
.detail-energy-forecast {
  margin: 0 0 8px;
  padding: 8px 9px;
  border: 1px solid rgba(248, 113, 113, 0.42);
  border-radius: 8px;
  background: rgba(127, 29, 29, 0.16);
  color: #fecaca;
  font-size: 0.72rem;
  line-height: 1.35;
}
.detail-energy-forecast-title {
  margin-bottom: 2px;
  color: #fca5a5;
  font-family: var(--font-mono);
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.detail-energy-fix {
  display: inline-flex;
  margin-top: 5px;
  padding: 0;
  border: 0;
  background: none;
  color: #67e8f9;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}
.detail-energy-fix:hover { color: #a5f3fc; }

/* Two-column layout: characteristics + benefits side by side */
.collection-detail-two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  align-items: start;
}
.collection-detail-two-col-left,
.collection-detail-two-col-right {
  min-width: 0;
}
.collection-detail-two-col .collection-detail-section + .collection-detail-section {
  margin-top: 12px;
}
.collection-detail-two-col + .collection-detail-section {
  margin-top: 18px;
}
@media (max-width: 540px) {
  .collection-detail-two-col {
    grid-template-columns: 1fr;
  }
}

/* Benefits list for research cards */
.collection-detail-benefits {
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: linear-gradient(180deg, rgba(11, 16, 28, 0.92), rgba(7, 11, 21, 0.82));
  overflow: hidden;
}
.detail-benefit-row {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 5px 14px;
  font-size: 0.75rem;
  line-height: 1.4;
}
.detail-benefit-row + .detail-benefit-row {
  border-top: 1px solid rgba(255, 255, 255, 0.04);
}
.detail-benefit-level {
  flex-shrink: 0;
  white-space: nowrap;
  font-size: 0.62rem;
  color: var(--detail-color);
  opacity: 0.7;
}
.detail-benefit-text {
  color: var(--text-secondary);
  font-size: 0.72rem;
}

.detail-missing {
  font-size: 0.72rem;
  color: var(--text-dim);
  text-align: center;
  margin-top: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  flex-wrap: wrap;
}

.btn-detail-disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

/* Detail overlay prereqs */
.collection-detail-prereqs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 12px;
}
.detail-prereq-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 10px;
  border-radius: 6px;
  font-size: 0.72rem;
  cursor: pointer;
  border: 1px solid color-mix(in srgb, var(--prereq-color) 30%, rgba(255, 255, 255, 0.1));
  background: color-mix(in srgb, var(--prereq-color) 10%, rgba(9, 13, 24, 0.85));
  color: color-mix(in srgb, var(--prereq-color) 80%, white);
  transition: all 0.18s ease;
}
.detail-prereq-chip:hover {
  background: color-mix(in srgb, var(--prereq-color) 20%, rgba(9, 13, 24, 0.9));
  box-shadow: 0 0 12px color-mix(in srgb, var(--prereq-color) 16%, transparent);
}
.detail-prereq-chip.met {
  opacity: 0.6;
}
.detail-prereq-chip.unmet {
  border-color: color-mix(in srgb, var(--prereq-color) 50%, rgba(255, 255, 255, 0.15));
}
.detail-prereq-check { color: #22c55e; }
.detail-prereq-current { color: #f87171; font-size: 0.65rem; }
.detail-inline-prereqs {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
}
.detail-inline-prereqs-label {
  font-size: 0.7rem;
  color: #f87171;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
}
.detail-blocked-reason {
  padding: 6px 12px;
  margin-top: 6px;
  font-size: 0.7rem;
  color: #fca5a5;
  text-align: center;
}

/* Level Progression Table */
.progression-table-wrap {
  margin: 8px 0 0;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: linear-gradient(180deg, rgba(11, 16, 28, 0.92), rgba(7, 11, 21, 0.82));
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.progression-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.72rem;
}
.progression-table th {
  padding: 6px 8px;
  font-size: 0.6rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-dim);
  text-align: left;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  white-space: nowrap;
}
.progression-group-header th {
  text-align: center;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  padding-bottom: 4px;
  color: var(--text-dim);
}
.progression-table td {
  padding: 5px 8px;
  color: var(--text-secondary);
  white-space: nowrap;
}
.progression-table tbody tr + tr {
  border-top: 1px solid rgba(255, 255, 255, 0.04);
}
.progression-table .res-icon {
  width: 12px;
  height: 12px;
  vertical-align: -1px;
}
.progression-spacer {
  width: 100%;
  padding: 0 !important;
}
.progression-num {
  text-align: right;
  width: 1%;
}
.progression-group-start {
  border-left: 1px solid rgba(255, 255, 255, 0.08);
}
.progression-output {
  white-space: normal !important;
  width: 100%;
}
tr.progression-current {
  background: rgba(0, 240, 255, 0.08);
}
tr.progression-current td {
  color: var(--cyan);
  font-weight: 600;
}
tr.progression-capped {
  opacity: 0.3;
}
.progression-ellipsis td {
  text-align: center;
  opacity: 0.5;
  padding: 2px 0;
  font-size: 1rem;
  font-weight: 700;
}
.progression-card-cell {
  width: 1px;
  vertical-align: middle;
}
.progression-card-thumb {
  display: block;
  width: 52px;
  height: 52px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid rgba(0, 240, 255, 0.25);
  cursor: pointer;
  transition: border-color 0.15s;
}
.progression-card-thumb:hover {
  border-color: rgba(0, 240, 255, 0.6);
}
.progression-card-name {
  font-weight: 600;
  font-size: 0.75rem;
  margin-bottom: 3px;
}
.progression-bonuses {
  font-size: 0.65rem;
  margin-bottom: 3px;
  opacity: 0.8;
}
.progression-unlocks {
  white-space: normal !important;
  width: 100%;
}
.progression-sep {
  opacity: 0.35;
  margin: 0 1px;
}
.clr-green { color: #4caf50; }
.progression-unlock-chip {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 6px;
  margin: 1px 2px;
  border-radius: 4px;
  font-size: 0.65rem;
  background: rgba(0, 240, 255, 0.08);
  border: 1px solid rgba(0, 240, 255, 0.15);
  color: var(--cyan);
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.progression-unlock-chip:hover {
  background: rgba(0, 240, 255, 0.18);
  border-color: rgba(0, 240, 255, 0.35);
}
.progression-unlock-icon {
  width: 14px;
  height: 14px;
  border-radius: 2px;
}

.collection-detail-lore {
  margin-top: 12px;
}

.collection-detail-lore .collection-detail-copy {
  margin-top: 0;
}

.collection-detail-copy {
  margin-top: 10px;
  color: var(--text-primary);
  font-size: 0.82rem;
  line-height: 1.6;
}

.collection-detail-quote {
  margin: 12px 0 0;
  padding: 12px 14px;
  border-left: none;
  border-radius: 10px;
  background: linear-gradient(180deg, rgba(6, 12, 22, 0.88), color-mix(in srgb, var(--detail-color) 12%, rgba(6, 12, 22, 0.72)));
  color: color-mix(in srgb, var(--detail-color) 75%, white);
  font-size: 0.78rem;
  line-height: 1.55;
  font-style: italic;
}

.collection-detail-quote-mark {
  font-size: 1rem;
  color: color-mix(in srgb, var(--detail-color) 40%, #d8f7ff);
}

.collection-detail-quote-author {
  margin-top: 8px;
  color: var(--text-secondary);
  font-size: 0.68rem;
  font-style: normal;
  text-align: right;
}

.collection-detail-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
}

/* Compact ship/defense detail overlay */
.detail-kind-ship .collection-detail-art,
.detail-kind-defense .collection-detail-art {
  min-height: 120px;
  max-height: 140px;
}
.detail-kind-ship .collection-detail-art img,
.detail-kind-defense .collection-detail-art img {
  min-height: 120px;
  max-height: 140px;
}
/* Taller hero when the 3D viewer is mounted so the model has room */
.detail-kind-ship .collection-detail-art.kc-ship3d-host,
.detail-kind-ship .collection-detail-art.kc-ship3d-host img {
  min-height: 200px;
  max-height: 220px;
}
.detail-kind-ship .collection-detail-head,
.detail-kind-defense .collection-detail-head {
  gap: 3px;
}
.detail-kind-ship .collection-detail-lore,
.detail-kind-defense .collection-detail-lore {
  margin-top: 4px;
}
.detail-kind-ship .collection-detail-copy,
.detail-kind-defense .collection-detail-copy {
  font-size: 0.78rem;
  line-height: 1.4;
  margin-top: 0;
}
.detail-kind-ship .collection-detail-quote,
.detail-kind-defense .collection-detail-quote {
  margin-top: 6px;
  padding: 8px 12px;
  font-size: 0.74rem;
  line-height: 1.4;
}
.detail-kind-ship .collection-detail-quote-author,
.detail-kind-defense .collection-detail-quote-author {
  margin-top: 4px;
}
.detail-kind-ship .collection-detail-hero,
.detail-kind-defense .collection-detail-hero {
  gap: 6px;
  margin-bottom: 6px;
}
.detail-kind-ship .collection-detail-section + .collection-detail-section,
.detail-kind-defense .collection-detail-section + .collection-detail-section {
  margin-top: 6px;
}
.detail-kind-ship .collection-detail-fact-row .collection-detail-fact-label,
.detail-kind-ship .collection-detail-fact-row .collection-detail-fact-value,
.detail-kind-defense .collection-detail-fact-row .collection-detail-fact-label,
.detail-kind-defense .collection-detail-fact-row .collection-detail-fact-value {
  padding: 5px 12px;
}
/* Ship/defense: 2-column on mobile by default, 4-column on desktop (see @media min-width: 768px below) */
.detail-kind-ship .collection-detail-facts-rows,
.detail-kind-defense .collection-detail-facts-rows {
  grid-template-columns: auto minmax(0, 1fr);
}
/* Desktop 4-column layout overrides are inside @media (min-width: 768px) further below */
.detail-kind-ship .collection-detail-cost-grid,
.detail-kind-defense .collection-detail-cost-grid {
  margin-top: 6px;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

/* Megaproject detail - same layout as buildings */

/* Mobile compact detail overlay */
@media (max-width: 499px) {
  .collection-detail-panel {
    padding: 8px;
    padding-top: 0;
    max-height: min(94vh, 900px);
    max-height: min(94dvh, 900px);
  }
  .collection-detail-dismiss {
    width: 36px;
    height: 36px;
    font-size: 1.2rem;
    top: 4px;
    right: 4px;
  }
  .collection-detail-hero {
    gap: 4px;
    margin-bottom: 4px;
  }
  .collection-detail-art {
    width: calc(100% + 16px);
    margin: 0 -8px 0;
    min-height: 100px;
    max-height: 120px;
    border-radius: 0;
  }
  .collection-detail-art img {
    min-height: 100px;
    max-height: 120px;
  }
  .collection-detail-head {
    gap: 2px;
  }
  .collection-detail-title {
    font-size: 1rem;
  }
  .collection-detail-subtitle {
    font-size: 0.75rem;
  }
  .collection-detail-kicker,
  .collection-detail-section-title {
    font-size: 0.6rem;
    margin-top: 6px;
  }
  .collection-detail-tags {
    gap: 4px;
  }
  .collection-detail-tag {
    font-size: 0.6rem;
    min-height: 22px;
    padding: 0 8px;
  }
  .collection-detail-section + .collection-detail-section {
    margin-top: 6px;
  }
  /* Facts: compact rows */
  .collection-detail-facts {
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 4px;
    margin-top: 4px;
  }
  .collection-detail-fact:not(.collection-detail-fact-row) {
    padding: 4px 6px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    gap: 4px;
  }
  /* Keep row-based facts as display:contents so label+value flow into the parent grid */
  .collection-detail-fact-row {
    display: contents;
  }
  .collection-detail-fact-label {
    margin-bottom: 0;
    font-size: 0.58rem;
    white-space: nowrap;
  }
  .collection-detail-fact-value {
    font-size: 0.78rem;
  }
  .collection-detail-facts-rows {
    border-radius: 8px;
  }
  .collection-detail-fact-row .collection-detail-fact-label,
  .collection-detail-fact-row .collection-detail-fact-value {
    padding: 4px 10px;
  }
  /* Cost cards */
  .collection-detail-cost-grid {
    gap: 6px;
    margin-top: 4px;
  }
  .collection-detail-cost-card {
    padding: 5px 7px;
    border-radius: 6px;
  }
  .collection-detail-cost-label {
    margin-bottom: 2px;
    font-size: 0.58rem;
  }
  .collection-detail-cost-value {
    font-size: 0.78rem;
  }
  .collection-detail-cost-meta {
    margin-top: 3px;
    font-size: 0.6rem;
  }
  .btn-detail-upgrade {
    margin-top: 5px;
    padding: 6px 8px;
    font-size: 0.7rem;
  }
  .collection-detail-lore {
    margin-top: 4px;
  }
  .collection-detail-copy {
    font-size: 0.76rem;
    margin-top: 4px;
    line-height: 1.4;
  }
  .collection-detail-quote {
    margin-top: 4px;
    padding: 6px 8px;
    font-size: 0.72rem;
    line-height: 1.35;
  }
  .collection-detail-quote-author {
    margin-top: 3px;
    font-size: 0.6rem;
  }
  .collection-detail-actions {
    margin-top: 6px;
  }
  .collection-detail-close-btn {
    padding: 6px 14px;
    font-size: 0.72rem;
  }
  /* Progression table: tighter on mobile */
  .progression-table-wrap {
    margin: 6px 0 0;
  }
  .progression-table {
    font-size: 0.68rem;
  }
  .progression-table th {
    padding: 3px 3px;
    font-size: 0.55rem;
  }
  .progression-table td {
    padding: 3px 3px;
  }
  .progression-table .res-icon {
    width: 11px;
    height: 11px;
  }
  /* Ship/defense: extra compact on mobile */
  .detail-kind-ship .collection-detail-art,
  .detail-kind-defense .collection-detail-art {
    min-height: 80px;
    max-height: 100px;
  }
  .detail-kind-ship .collection-detail-art img,
  .detail-kind-defense .collection-detail-art img {
    min-height: 80px;
    max-height: 100px;
  }
  /* Taller hero on mobile too when hosting the 3D viewer */
  .detail-kind-ship .collection-detail-art.kc-ship3d-host,
  .detail-kind-ship .collection-detail-art.kc-ship3d-host img {
    min-height: 200px;
    max-height: 220px;
  }
  .detail-kind-ship .collection-detail-facts-rows,
  .detail-kind-defense .collection-detail-facts-rows {
    grid-template-columns: auto minmax(0, 1fr);
  }
  .detail-kind-ship .collection-detail-fact-row:nth-child(2) .collection-detail-fact-label,
  .detail-kind-ship .collection-detail-fact-row:nth-child(2) .collection-detail-fact-value,
  .detail-kind-defense .collection-detail-fact-row:nth-child(2) .collection-detail-fact-label,
  .detail-kind-defense .collection-detail-fact-row:nth-child(2) .collection-detail-fact-value {
    border-top: 1px solid rgba(255, 255, 255, 0.05);
  }
  .detail-kind-ship .collection-detail-fact-row:nth-child(odd) .collection-detail-fact-value,
  .detail-kind-defense .collection-detail-fact-row:nth-child(odd) .collection-detail-fact-value {
    border-right: none;
  }
  .detail-kind-ship .collection-detail-fact-row .collection-detail-fact-label,
  .detail-kind-ship .collection-detail-fact-row .collection-detail-fact-value,
  .detail-kind-defense .collection-detail-fact-row .collection-detail-fact-label,
  .detail-kind-defense .collection-detail-fact-row .collection-detail-fact-value {
    padding: 3px 8px;
  }
  /* Two-column layout compact */
  .collection-detail-two-col {
    gap: 6px;
  }
  /* Benefits compact */
  .detail-benefit-row {
    padding: 3px 0;
    font-size: 0.72rem;
  }
  /* Prereq chips compact */
  .detail-prereq-chip {
    font-size: 0.6rem;
    padding: 2px 6px;
  }
}

.collection-detail-action {
  min-width: 120px;
  min-height: 40px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  padding: 10px 14px;
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  transition: all 0.18s ease;
}

.collection-detail-close-btn {
  color: color-mix(in srgb, var(--detail-color) 76%, white);
  border-color: color-mix(in srgb, var(--detail-color) 28%, rgba(255, 255, 255, 0.12));
  background: color-mix(in srgb, var(--detail-color) 14%, rgba(9, 13, 24, 0.9));
}

.collection-detail-close-btn:hover {
  background: color-mix(in srgb, var(--detail-color) 20%, rgba(9, 13, 24, 0.92));
  box-shadow: 0 0 22px color-mix(in srgb, var(--detail-color) 14%, transparent);
}

@media (min-width: 768px) {
  .collection-detail-overlay {
    align-items: center;
    padding-top: calc(var(--topbar-height) + 18px);
  }

  .collection-detail-panel {
    padding: 22px;
    padding-top: 0;
  }

  .collection-detail-art {
    width: calc(100% + 44px);
    margin: 0 -22px 0;
    min-height: 200px;
    max-height: 220px;
    border-radius: 0;
  }

  .collection-detail-art img {
    min-height: 200px;
    max-height: 220px;
  }

  /* Ship/defense: 4-column characteristics grid on desktop/tablet */
  .detail-kind-ship .collection-detail-facts-rows,
  .detail-kind-defense .collection-detail-facts-rows {
    grid-template-columns: auto minmax(0, 1fr) auto minmax(0, 1fr);
  }
  .detail-kind-ship .collection-detail-fact-row:nth-child(2) .collection-detail-fact-label,
  .detail-kind-ship .collection-detail-fact-row:nth-child(2) .collection-detail-fact-value,
  .detail-kind-defense .collection-detail-fact-row:nth-child(2) .collection-detail-fact-label,
  .detail-kind-defense .collection-detail-fact-row:nth-child(2) .collection-detail-fact-value {
    border-top: none;
  }
  .detail-kind-ship .collection-detail-fact-row:nth-child(odd) .collection-detail-fact-value,
  .detail-kind-defense .collection-detail-fact-row:nth-child(odd) .collection-detail-fact-value {
    border-right: 1px solid rgba(255, 255, 255, 0.05);
  }
}

@media (max-width: 520px) {
  .collection-detail-facts {
    grid-template-columns: 1fr;
  }
  .collection-detail-facts,
  .collection-detail-actions {
    flex-direction: column;
  }

  .collection-detail-action {
    width: 100%;
  }
}

/* --- Magic/TCG Card Style --- */

/* Rarity border colors */
.building-card { --rarity-color: #64748b; } /* common: grey */
.building-card[data-rarity="uncommon"] { --rarity-color: #22c55e; }
.building-card[data-rarity="rare"] { --rarity-color: #3b82f6; }
.building-card[data-rarity="epic"] { --rarity-color: #a855f7; }
.building-card[data-rarity="legendary"] { --rarity-color: #f59e0b; }
.building-card[data-rarity="rare"],
.building-card[data-rarity="epic"],
.building-card[data-rarity="legendary"] {
  box-shadow:
    0 2px 12px var(--scrim-50),
    0 0 12px color-mix(in srgb, var(--rarity-color) 20%, transparent),
    inset 0 0 0 1px color-mix(in srgb, var(--rarity-color) 15%, transparent);
}

/* Technique cards: plain sci-fi frame (rarity reads in the title, not the border). */
.building-card.catalog-card,
.building-card.variant-revealed-card {
  box-shadow: 0 4px 16px var(--scrim-60);
  text-align: left;
}

/* --- Full-Art Glassmorphism Card --- */
.building-card {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  border-radius: 4px;
  border-image-source: url('../../assets/ui/hud-frame.webp');
  border-image-slice: 94;
  border-image-width: 7px;
  border-image-repeat: stretch;
  border-style: solid;
  border-width: 7px;
  overflow: hidden;
  transition: transform 0.25s, box-shadow 0.3s, border-color 0.3s;
  position: relative;
  aspect-ratio: 5/7;
  box-shadow:
    0 4px 16px var(--scrim-60);
}
/* Card color tint overlay on the frame border */
.building-card::after {
  content: '';
  position: absolute;
  inset: -7px;
  z-index: 6;
  pointer-events: none;
  border: 7px solid var(--card-color, var(--rarity-color));
  border-radius: 4px;
  opacity: 0.35;
  mix-blend-mode: color;
}
/* Queued/upgrading cards: no extra FX, keep default sci-fi border */
@keyframes card-march {
  to {
    background-position:
      12px 0,
      -12px 100%,
      0 -12px,
      100% 12px;
  }
}
/* Art area - inset from card edges to create frame */
.building-card .card-art {
  position: absolute;
  overflow: hidden;
  border-radius: 2px;
  inset: 0;
  z-index: 0;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  background: var(--bg-void, #080c18);
}
/* Framed image showcase (MTG-style) */
.building-card .card-frame {
  position: relative;
  z-index: 1;
  width: calc(100% - 12px);
  margin: -2px auto 0;
  flex: 1;
  min-height: 0;
  border-radius: 4px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.15);
  box-shadow: inset 0 0 12px var(--scrim-50);
}
.building-card .card-frame img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.building-card.unaffordable .card-frame img {
  opacity: 0.4;
  filter: grayscale(0.4) brightness(0.7);
}
.building-card.locked .card-frame img {
  opacity: 0.3;
  filter: grayscale(0.6) brightness(0.5);
}
/* Hide frame on upgrading cards */
.building-card.upgrading .card-frame {
  display: none;
}
.building-card .card-art img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.22s ease, opacity 0.22s ease, filter 0.22s ease;
}
/* Subtle floating animation for flying ship card images */
@keyframes ship-float {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  25%      { transform: translateY(-2px) rotate(-0.4deg); }
  50%      { transform: translateY(-3.5px) rotate(0deg); }
  75%      { transform: translateY(-2px) rotate(0.4deg); }
}
[data-card-kind="ship"]:not([data-lore-key="recycler"]) .card-art img {
  animation: ship-float 5s ease-in-out infinite;
  will-change: transform;
}
/* Stagger animation start so ships don't bob in sync */
[data-card-kind="ship"]:nth-child(2n) .card-art img { animation-delay: -1.2s; }
[data-card-kind="ship"]:nth-child(3n) .card-art img { animation-delay: -2.5s; }
[data-card-kind="ship"]:nth-child(5n) .card-art img { animation-delay: -3.8s; }
[data-card-kind="ship"]:nth-child(7n) .card-art img { animation-delay: -0.7s; }
/* Active 3D: silence the float and dim the .webp underneath so the canvas reads cleanly */
.building-card.kc-ship3d-active .card-art img {
  animation-play-state: paused;
  opacity: 0;
  transition: opacity 280ms ease;
}
.building-card.unaffordable .card-art img {
  opacity: 0.35;
  filter: grayscale(0.5) brightness(0.8);
}
.building-card.unaffordable {
  border-color: rgba(100, 116, 139, 0.2);
}
/* Unbuilt buildings / unresearched techs (level 0) that are still buildable.
   Locked cards keep their stronger 'locked' treatment with the lock icon. */
.building-card.card-dim:not(.locked) {
  border-image: none;
  border-style: dashed;
  border-width: 2px;
  border-color: rgba(148, 163, 184, 0.5);
}
.building-card.card-dim:not(.locked)::after {
  display: none;
}
.building-card.locked .card-art img {
  opacity: 0.25;
  filter: grayscale(0.8) brightness(0.6);
}
.building-card.locked {
  border-color: rgba(239, 68, 68, 0.15);
}
/* Lock icon overlay for locked building cards */
.card-lock-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
  pointer-events: none;
}
.card-lock-overlay svg {
  width: 32px;
  height: 32px;
  color: rgba(255, 255, 255, 0.35);
  filter: drop-shadow(0 2px 8px var(--scrim-70));
}

/* Combat / sabotage damage overlay (no dim on art — layer sits above vignette) */
.card-damage-layer {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  border-radius: inherit;
  overflow: hidden;
}
.card-damage-layer::after {
  content: '';
  position: absolute;
  inset: 6px;
  pointer-events: none;
  border: 1px solid rgba(239, 68, 68, 0.28);
  border-radius: 2px;
  background:
    linear-gradient(rgba(239, 68, 68, 0.65), rgba(239, 68, 68, 0.65)) left top / 14px 2px no-repeat,
    linear-gradient(rgba(239, 68, 68, 0.65), rgba(239, 68, 68, 0.65)) left top / 2px 14px no-repeat,
    linear-gradient(rgba(239, 68, 68, 0.65), rgba(239, 68, 68, 0.65)) right top / 14px 2px no-repeat,
    linear-gradient(rgba(239, 68, 68, 0.65), rgba(239, 68, 68, 0.65)) right top / 2px 14px no-repeat;
  opacity: 0.8;
}
.building-card.card-damaged-sabotaged .card-damage-layer::after {
  border-color: rgba(56, 189, 248, 0.28);
  background:
    linear-gradient(rgba(56, 189, 248, 0.65), rgba(56, 189, 248, 0.65)) left top / 14px 2px no-repeat,
    linear-gradient(rgba(56, 189, 248, 0.65), rgba(56, 189, 248, 0.65)) left top / 2px 14px no-repeat,
    linear-gradient(rgba(56, 189, 248, 0.65), rgba(56, 189, 248, 0.65)) right top / 14px 2px no-repeat,
    linear-gradient(rgba(56, 189, 248, 0.65), rgba(56, 189, 248, 0.65)) right top / 2px 14px no-repeat;
}
.card-damage-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  overflow: hidden;
}
.building-card.card-damaged .card-art img {
  filter: saturate(0.82) sepia(0.22) hue-rotate(-12deg) contrast(1.08);
}
.building-card.card-damaged.card-damaged-sabotaged .card-art img {
  filter: saturate(0.75) sepia(0.12) hue-rotate(180deg) contrast(1.05);
}
.card-damage-flame-icon {
  width: 80px;
  height: 80px;
  color: #ef4444;
  opacity: 0.95;
  filter:
    drop-shadow(0 0 18px rgba(239, 68, 68, 0.95))
    drop-shadow(0 0 6px rgba(251, 191, 36, 0.65))
    drop-shadow(0 3px 10px rgba(0, 0, 0, 0.55));
}
.card-damage-flame-icon path {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.35;
  stroke-linejoin: round;
  stroke-linecap: round;
}
.building-card.card-damaged-sabotaged .card-damage-flame-icon {
  color: #38bdf8;
  filter:
    drop-shadow(0 0 18px rgba(56, 189, 248, 0.9))
    drop-shadow(0 0 6px rgba(129, 140, 248, 0.55))
    drop-shadow(0 3px 10px rgba(0, 0, 0, 0.55));
}

.building-card.card-damaged {
  border-color: rgba(239, 68, 68, 0.45);
  box-shadow:
    inset 0 0 0 1px rgba(239, 68, 68, 0.18),
    0 0 18px rgba(239, 68, 68, 0.12);
  animation: damage-border-pulse 2.4s ease-in-out infinite;
}
.building-card.card-damaged.card-damaged-sabotaged {
  border-color: rgba(56, 189, 248, 0.45);
  box-shadow:
    inset 0 0 0 1px rgba(56, 189, 248, 0.18),
    0 0 18px rgba(56, 189, 248, 0.12);
  animation: damage-border-pulse-sabotage 2.4s ease-in-out infinite;
}
@keyframes damage-border-pulse {
  0%, 100% { box-shadow: inset 0 0 0 1px rgba(239, 68, 68, 0.15), 0 0 12px rgba(239, 68, 68, 0.08); }
  50%      { box-shadow: inset 0 0 0 1px rgba(239, 68, 68, 0.35), 0 0 22px rgba(239, 68, 68, 0.2); }
}
@keyframes damage-border-pulse-sabotage {
  0%, 100% { box-shadow: inset 0 0 0 1px rgba(56, 189, 248, 0.15), 0 0 12px rgba(56, 189, 248, 0.08); }
  50%      { box-shadow: inset 0 0 0 1px rgba(56, 189, 248, 0.35), 0 0 22px rgba(56, 189, 248, 0.2); }
}
.building-card.card-damaged::before {
  background: linear-gradient(180deg,
    rgba(69, 10, 10, 0.28) 0%,
    rgba(127, 29, 29, 0.08) 40%,
    rgba(69, 10, 10, 0.22) 72%,
    rgba(0, 0, 0, 0.78) 100%);
}
.building-card.card-damaged.card-damaged-sabotaged::before {
  background: linear-gradient(180deg,
    rgba(12, 30, 69, 0.28) 0%,
    rgba(30, 58, 138, 0.08) 40%,
    rgba(12, 30, 69, 0.22) 72%,
    rgba(0, 0, 0, 0.78) 100%);
}
.building-card.card-damaged .card-body {
  margin: auto 4px 4px;
  padding: 10px 8px 8px;
  gap: 0;
  border-radius: 2px;
  background: rgba(20, 6, 6, 0.88);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-top: 1px solid rgba(239, 68, 68, 0.28);
}
.building-card.card-damaged.card-damaged-sabotaged .card-body {
  background: rgba(6, 12, 24, 0.88);
  border-top-color: rgba(56, 189, 248, 0.28);
}
.building-card.card-damaged .bld-damage-progress {
  margin-top: 0;
  padding: 0;
}
.building-card.card-damaged .bld-damage-progress .progress-bar {
  background: rgba(69, 10, 10, 0.65);
  box-shadow: inset 0 0 4px rgba(0, 0, 0, 0.45);
}
.building-card.card-damaged .bld-damage-timer {
  margin-top: 0;
  padding: 4px 0 2px;
  color: #fca5a5;
  font-size: 0.72rem;
}
.building-card.card-damaged.card-damaged-sabotaged .bld-damage-timer {
  color: #93c5fd;
}
.building-card.card-damaged .bld-damage-label {
  text-align: center;
  font-size: 0.58rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #f87171;
  font-weight: 700;
}
.building-card.card-damaged.card-damaged-sabotaged .bld-damage-label {
  color: #60a5fa;
}
.progress-fill.damage-recovery {
  background: linear-gradient(90deg, #7f1d1d, #dc2626, #f87171);
  box-shadow: 0 0 10px rgba(239, 68, 68, 0.55);
  animation: damage-bar-pulse 1.8s ease-in-out infinite;
}
.building-card.card-damaged-sabotaged .progress-fill.damage-recovery {
  background: linear-gradient(90deg, #1e3a8a, #2563eb, #60a5fa);
  box-shadow: 0 0 10px rgba(56, 189, 248, 0.45);
}
@keyframes damage-bar-pulse {
  0%, 100% { filter: brightness(1); }
  50%      { filter: brightness(1.15); }
}

.collection-chip.chip-damaged .collection-chip-thumb {
  position: relative;
}
.collection-chip.chip-damaged .card-damage-overlay {
  border-radius: inherit;
}
.collection-chip.chip-damaged .card-damage-flame-icon {
  width: 36px;
  height: 36px;
}
.chip-damage-progress {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 3px;
  background: rgba(0, 0, 0, 0.45);
  z-index: 4;
  pointer-events: none;
}
.chip-damage-fill {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, #7f1d1d, #dc2626, #f87171);
  box-shadow: 0 0 6px rgba(239, 68, 68, 0.55);
  transition: width 0.4s linear;
}
.chip-damaged-sabotaged .chip-damage-fill {
  background: linear-gradient(90deg, #1e3a8a, #2563eb, #60a5fa);
  box-shadow: 0 0 6px rgba(56, 189, 248, 0.45);
}
/* Dark vignette overlay for readability */
.building-card::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 1;
  background: linear-gradient(180deg,
    var(--scrim-50) 0%,
    rgba(0,0,0,0.1) 35%,
    var(--scrim-15) 55%,
    rgba(0,0,0,0.75) 100%);
  pointer-events: none;
}
.building-card:hover {
  box-shadow:
    0 8px 28px var(--scrim-60),
    0 0 20px color-mix(in srgb, var(--card-color, var(--rarity-color)) 30%, transparent);
}
.building-card:hover::after {
  opacity: 0.55;
}

.building-card.art-preview {
  z-index: 12;
  transform: scale(1.03);
  box-shadow:
    0 16px 36px rgba(0, 0, 0, 0.68),
    0 0 22px color-mix(in srgb, var(--card-color) 24%, transparent);
}

.building-card.art-preview::before {
  opacity: 0;
}

.building-card.art-preview > :not(.card-art) {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.building-card.art-preview .card-art img {
  transform: scale(1.04);
}

/* Glassmorphism panels - all content above art */
.card-title-bar, .card-type-badge, .card-branch-icon, .card-branch-level, .card-body, .card-recommended-badge, .card-system-badge, .card-lvl {
  position: relative;
  z-index: 3;
}

.card-system-badge {
  position: absolute;
  top: 34px;
  left: 6px;
  max-width: calc(100% - 28px);
  padding: 3px 8px;
  border-radius: 3px;
  background: rgba(0, 0, 0, 0.75);
  color: #67e8f9;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  z-index: 4;
  text-shadow: 0 0 6px color-mix(in srgb, #67e8f9 40%, transparent);
}

.card-damage-badge {
  position: absolute;
  left: 0;
  top: 38px;
  font-size: 0.52rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-weight: 800;
  color: #fff;
  background: linear-gradient(135deg, #7f1d1d, #dc2626, #ef4444, #dc2626, #7f1d1d);
  background-size: 300% 100%;
  border: 1px solid rgba(248, 113, 113, 0.65);
  border-left: none;
  padding: 5px 4px;
  border-radius: 0 4px 4px 0;
  z-index: 4;
  text-shadow: 0 1px 2px var(--scrim-50);
  box-shadow: 0 0 10px rgba(239, 68, 68, 0.45);
  animation: rec-shimmer 2.2s ease-in-out infinite;
  writing-mode: vertical-rl;
  text-orientation: mixed;
  transform: rotate(180deg);
}
.building-card.card-damaged-sabotaged .card-damage-badge {
  background: linear-gradient(135deg, #1e3a8a, #2563eb, #38bdf8, #2563eb, #1e3a8a);
  border-color: rgba(96, 165, 250, 0.65);
  box-shadow: 0 0 10px rgba(56, 189, 248, 0.4);
}

.card-recommended-badge,
.building-card .recband {
  position: absolute;
  right: 0;
  top: 40px;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-weight: 800;
  color: #fff;
  background: linear-gradient(135deg, #059669, #10b981, #34d399, #10b981, #059669);
  background-size: 300% 100%;
  border: 1px solid rgba(52, 211, 153, 0.6);
  border-right: none;
  padding: 5px 4px;
  border-radius: 4px 0 0 4px;
  z-index: 2;
  text-shadow: 0 1px 2px var(--scrim-50);
  box-shadow:
    0 0 8px rgba(16, 185, 129, 0.4),
    inset 0 1px 0 rgba(255, 255, 255, 0.2);
  animation: rec-shimmer 3s ease-in-out infinite;
  overflow: hidden;
  writing-mode: vertical-rl;
  text-orientation: mixed;
  transform: rotate(180deg);
}
.card-recommended-badge::after,
.building-card .recband::after {
  content: '';
  position: absolute;
  left: 0;
  bottom: -100%;
  width: 100%;
  height: 60%;
  background: linear-gradient(0deg, transparent, rgba(255,255,255,0.35), transparent);
  animation: rec-shine 3s ease-in-out infinite;
}
@keyframes rec-shimmer {
  0%, 100% { background-position: 0% 50%; box-shadow: 0 0 8px rgba(16, 185, 129, 0.4), inset 0 1px 0 rgba(255,255,255,0.2); }
  50% { background-position: 100% 50%; box-shadow: 0 0 14px rgba(16, 185, 129, 0.6), inset 0 1px 0 rgba(255,255,255,0.3); }
}
@keyframes rec-shine {
  0%, 20% { bottom: -100%; }
  60%, 100% { bottom: 150%; }
}

.card-mission-badge {
  background: linear-gradient(135deg, #b45309, #d97706, #f59e0b, #d97706, #b45309) !important;
  border-color: rgba(245, 158, 11, 0.6) !important;
  box-shadow: 0 0 8px rgba(245, 158, 11, 0.4);
}

/* Queued research badge */
.card-queued-badge {
  background: linear-gradient(135deg, #0e7490, #06b6d4, #22d3ee, #06b6d4, #0e7490);
  border-color: rgba(34, 211, 238, 0.6) !important;
  box-shadow: 0 0 8px rgba(34, 211, 238, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

.card-active-badge {
  background: linear-gradient(135deg, #5b21b6, #8b5cf6, #a78bfa, #8b5cf6, #5b21b6);
  border-color: rgba(167, 139, 250, 0.55) !important;
  box-shadow: 0 0 8px rgba(139, 92, 246, 0.35);
}

/* Equipped technique badge (collection browser only): static status marker */
.card-equipped-badge {
  background: linear-gradient(135deg, #0e7490, #06b6d4, #22d3ee, #06b6d4, #0e7490);
  border-color: rgba(34, 211, 238, 0.6) !important;
  box-shadow: 0 0 8px rgba(34, 211, 238, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.2);
  animation: none;
}
.card-equipped-badge::after { content: none; }

/* Trade discount badge */
.trade-discount-card-badge {
  background: linear-gradient(135deg, #059669, #10b981) !important;
  border-color: rgba(52, 211, 153, 0.6) !important;
}

/* Title bar - frosted top */
.card-title-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 8px;
  background: rgba(0, 0, 0, 0.75);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
/* Reserve room for the level badge only when one is rendered. */
.card:has(> .card-lvl) > .card-title-bar {
  padding-right: 36px;
}

@media (min-width: 1024px) {
  .card-title-bar {
    background: rgba(0, 0, 0, 0.45);
    backdrop-filter: blur(var(--blur-lg));
    -webkit-backdrop-filter: blur(var(--blur-lg));
  }
}
.card-name {
  font-size: 0.7rem;
  font-weight: 700;
  color: #fff;
  overflow: hidden;
  flex: 1;
  min-width: 0;
  line-height: 1.15;
  text-shadow: 0 1px 3px rgba(0,0,0,0.8);
}
.card-name-inner {
  display: inline-block;
  white-space: nowrap;
  transform-origin: left center;
  will-change: transform;
}
.card-lvl {
  position: absolute;
  top: 3px;
  right: 6px;
  font-size: 0.82rem;
  font-weight: 900;
  color: #fff;
  background: var(--scrim-70);
  border: 2px solid var(--card-color, var(--rarity-color));
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  z-index: 5;
  text-shadow: 0 1px 3px rgba(0,0,0,0.8);
  box-shadow: 0 0 6px var(--scrim-50);
  padding-top: 1px;
}

/* Type badge - overlaid on art */
.card-type-badge {
  position: absolute;
  left: 6px;
  top: 34px;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-weight: 700;
  color: var(--rarity-color);
  background: rgba(0, 0, 0, 0.75);
  padding: 3px 8px;
  border-radius: 3px;
  z-index: 2;
  text-shadow: 0 0 6px color-mix(in srgb, var(--rarity-color) 40%, transparent);
}

@media (min-width: 1024px) {
  .card-type-badge {
    background: var(--scrim-60);
    backdrop-filter: blur(var(--blur-sm));
    -webkit-backdrop-filter: blur(var(--blur-sm));
  }
}

/* Research branch icon — inline at right of title row */
.card-title-bar:has(.card-branch-icon),
.card-title-bar:has(.card-branch-level) {
  padding-right: 6px;
}
.card-branch-icon {
  flex-shrink: 0;
  width: 1.25em;
  height: 1.25em;
  margin-left: 4px;
  background: none;
  padding: 0;
  box-shadow: none;
  pointer-events: auto;
}
.card-branch-icon img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  opacity: 0.75;
}

/* Research program cards: branch icon + level inline in title row */
.card-branch-level {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 3px;
  margin-left: 4px;
  pointer-events: auto;
}
.card-branch-level-icon {
  width: 1.05em;
  height: 1.05em;
  flex-shrink: 0;
}
.card-branch-level-icon img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  opacity: 0.75;
}
.card-branch-level-num {
  font-size: 0.82rem;
  font-weight: 900;
  color: #e2e8f0;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.85);
  line-height: 1;
}

.card-impact {
  display: none;
}

.card-impact .cost-icon {
  width: 14px;
  height: 14px;
}

.impact-pos { color: var(--green); }
.impact-neg { color: #ff6666; opacity: 0.7; }
.impact-store { color: var(--text-dim); }

/* Card body - no background, buttons float over art */
.card-body {
  margin-top: auto;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.card-body {
  transition: opacity 0.2s ease;
}

.card-queued-right {
  left: auto;
  right: 6px;
  background: linear-gradient(135deg, #b45309, #f59e0b);
  color: #fff;
  text-shadow: 0 1px 2px var(--scrim-50);
}
.card-queue-badge {
  font-size: 0.5rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-weight: 800;
  color: #fff;
  text-align: center;
  padding: 3px 8px;
  margin: 0 2px 3px auto;
  width: fit-content;
  background: linear-gradient(135deg, #b45309, #f59e0b, #fbbf24, #f59e0b, #b45309);
  background-size: 300% 100%;
  border: 1px solid rgba(251, 191, 36, 0.6);
  border-radius: 4px;
  position: relative;
  z-index: 2;
  text-shadow: 0 1px 2px var(--scrim-50);
  box-shadow: 0 0 8px rgba(245, 158, 11, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.2);
  animation: rec-shimmer 3s ease-in-out infinite;
  overflow: hidden;
}

.building-card.upgrading .card-body,
.building-card.researching .card-body {
  margin: auto 4px 4px;
  padding: 10px 8px 8px;
  gap: 0;
  border-radius: 2px 2px 2px 2px;
  background: rgba(4, 6, 12, 0.85);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}
.building-card.upgrading .bld-progress,
.building-card.researching .bld-progress {
  margin-top: 0;
  padding: 0;
}
.building-card.upgrading .bld-timer,
.building-card.researching .bld-timer {
  margin-top: 0;
  padding: 4px 0 4px;
}
.building-card.upgrading .card-action-row,
.building-card.researching .card-action-row {
  padding: 4px 0 0;
}

/* Card Lore Overlay */
.card-lore-content {
  padding: 6px 8px;
  animation: loreFadeIn 0.25s ease-out;
  overflow-y: auto;
  overflow-x: hidden;
  max-height: 140px;
  background: linear-gradient(180deg, rgba(5, 10, 18, 0.72) 0%, rgba(5, 10, 18, 0.6) 100%);
  border: 1px solid rgba(148, 163, 184, 0.14);
  border-radius: 3px;
  backdrop-filter: blur(var(--blur-lg));
  -webkit-backdrop-filter: blur(var(--blur-lg));
  scrollbar-width: thin;
  scrollbar-color: rgba(var(--accent-rgb), 0.3) transparent;
}
.card-body[data-lore-active] {
  margin-top: 0;
  flex: 1;
  min-height: 0;
  padding-top: 16px;
}
.card-body[data-lore-active] .card-lore-content {
  height: 100%;
  max-height: none;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  padding: 8px 10px 10px;
}
.card-lore-content::-webkit-scrollbar {
  width: 3px;
}
.card-lore-content::-webkit-scrollbar-track {
  background: transparent;
}
.card-lore-content::-webkit-scrollbar-thumb {
  background: rgba(var(--accent-rgb), 0.3);
  border-radius: 3px;
}
@keyframes loreFadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}
.lore-text {
  font-size: 0.7rem;
  line-height: 1.42;
  color: var(--text-primary);
  margin-bottom: 6px;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
}
.lore-quote {
  font-size: 0.65rem;
  font-style: italic;
  line-height: 1.4;
  color: var(--cyan);
  padding: 5px 8px;
  border-left: 2px solid rgba(var(--accent-rgb), 0.4);
  background: linear-gradient(180deg, rgba(4, 12, 20, 0.78) 0%, rgba(var(--accent-rgb), 0.14) 100%);
  border-radius: 0 4px 4px 0;
}
.lore-quote-mark {
  font-size: 1rem;
  color: rgba(var(--accent-rgb), 0.5);
  vertical-align: -2px;
}
.lore-author {
  font-size: 0.6rem;
  color: var(--text-dim);
  text-align: right;
  margin-top: 3px;
  font-style: italic;
  text-shadow: 0 1px 2px var(--scrim-40);
}

/* Mobile: hide lore quotes, truncate description to 2 lines */
@media (max-width: 700px) {
  .lore-quote,
  .lore-author {
    display: none;
  }
  .lore-text {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }
}

/* Research prerequisites */
.research-prereqs {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  padding: 4px 8px 2px;
  font-size: 0.6rem;
}

.research-prereqs-label {
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.55rem;
}

.research-prereq-chip {
  --prereq-color: var(--cyan);
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 6px;
  border-radius: 3px;
  font-size: 0.58rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  border: 1px solid;
}

.research-prereq-chip.met {
  color: var(--prereq-color);
  border-color: color-mix(in srgb, var(--prereq-color) 30%, transparent);
  background: color-mix(in srgb, var(--prereq-color) 8%, transparent);
  opacity: 0.7;
}

.research-prereq-chip.unmet {
  color: #ff6b6b;
  border-color: rgba(255, 107, 107, 0.3);
  background: rgba(255, 107, 107, 0.08);
}

/* Research next level effect */
.research-next-effect {
  --effect-color: var(--cyan);
  padding: 3px 8px;
  font-size: 0.58rem;
  font-weight: 600;
  line-height: 1.4;
  color: color-mix(in srgb, var(--effect-color) 80%, #fff);
  background: color-mix(in srgb, var(--effect-color) 8%, transparent);
  border-radius: 3px;
  border-left: 2px solid var(--effect-color);
}

.research-next-label {
  font-weight: 800;
  color: var(--effect-color);
}

.building-card.research-card {
  --rarity-color: var(--card-color);
  box-shadow:
    0 2px 12px var(--scrim-50),
    0 0 12px color-mix(in srgb, var(--rarity-color) 20%, transparent),
    inset 0 0 0 1px color-mix(in srgb, var(--rarity-color) 15%, transparent);
}

.building-card.research-card.researching {
  box-shadow:
    0 8px 28px var(--scrim-60),
    0 0 18px color-mix(in srgb, var(--card-color) 26%, transparent);
}

.research-card-track {
  border-radius: 8px;
  border: 1px solid color-mix(in srgb, var(--card-color) 18%, rgba(148, 163, 184, 0.16));
  background: linear-gradient(180deg, color-mix(in srgb, var(--card-color) 10%, rgba(5, 10, 18, 0.92)), rgba(5, 10, 18, 0.78));
  padding: 8px 8px 6px;
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--card-color) 6%, transparent);
}

.research-card .tech-nodes-scroll {
  padding: 0 0 2px;
}

.research-card .tech-connector {
  width: 12px;
}

.research-card .tech-node {
  width: 30px;
  height: 30px;
  cursor: default;
}

.research-card .tech-node-level {
  font-size: 0.6rem;
}

.research-node-indicator {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: var(--card-color);
  box-shadow: 0 0 8px color-mix(in srgb, var(--card-color) 55%, transparent);
}


.research-card .tech-node-btn {
  min-height: 48px;
  height: auto;
  padding: 8px;
}

.research-card .btn-missing-list {
  font-size: 0.62rem;
  line-height: 1.25;
}

.research-card .bld-progress {
  margin-top: 0;
  padding: 0;
}

.research-card .bld-timer {
  margin-top: 0;
  padding-bottom: 0;
  color: color-mix(in srgb, var(--card-color) 78%, white);
  text-shadow: 0 0 8px color-mix(in srgb, var(--card-color) 24%, transparent);
}

.research-card-actions {
  padding: 0;
}

.research-card-actions .btn-cancel-card {
  flex: 1;
}

.research-card .research-card-cost {
  font-size: 0.62rem;
}

.research-card .btn-upgrade .btn-label {
  white-space: normal;
  line-height: 1.3;
  font-size: 0.6rem;
  color: var(--text-dim);
}

.building-card .bld-cost,
.research-card .bld-cost {
  font-size: 0.68rem;
  color: var(--text-dim);
  display: grid;
  grid-template-rows: auto;
  justify-content: center;
  align-items: center;
  gap: 0 1px;
  white-space: nowrap;
  background: rgba(0, 0, 0, 0.8);
  border-radius: 4px;
  padding: 3px 6px;
  transform-origin: left top;
}

/* Trade exchange line: "[resource] por [credits]" with both chips */
.trade-exchange {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 4px;
  font-size: 0.62rem;
  line-height: 1.2;
}
.trade-exchange .kc-res-chip {
  font-size: 0.62rem;
}
.trade-exchange-sep {
  color: var(--text-dim);
  text-transform: lowercase;
  opacity: 0.85;
}
.task-card-exchange {
  justify-content: flex-start;
  margin: 2px 0 4px;
}

@media (min-width: 1024px) {
  .building-card .bld-cost,
  .research-card .bld-cost {
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(var(--blur-lg));
    -webkit-backdrop-filter: blur(var(--blur-lg));
  }
}

.building-card .bld-cost .cost-icon-cell,
.research-card .bld-cost .cost-icon-cell {
  display: flex;
  align-items: center;
  justify-content: center;
}

.building-card .bld-cost .cost-icon-cell svg,
.research-card .bld-cost .cost-icon-cell svg {
  width: 14px;
  height: 14px;
}

.building-card .bld-cost .cost-num-cell,
.research-card .bld-cost .cost-num-cell {
  padding-right: 6px;
}
.building-card .bld-cost .cost-num-cell:last-of-type,
.research-card .bld-cost .cost-num-cell:last-of-type {
  padding-right: 0;
}

/* Requirement links: unmet gates render bright red + underlined and are
   tappable (they open the blocking Ciencia card or Edificios card). Met
   requirements keep the surrounding text style. */
button.req-link {
  display: inline;
  margin: 0;
  padding: 0;
  background: transparent;
  border: 0;
  font: inherit;
  text-align: inherit;
  touch-action: manipulation;
}
.req-link-unmet {
  cursor: pointer;
  color: #ff4d4d;
  font-weight: 600;
  text-decoration: underline;
  text-decoration-color: currentColor;
  text-underline-offset: 2px;
  transition: color 0.15s ease-out;
}
.req-link-unmet:hover {
  color: #ff8585;
}
.req-link-met {
  color: inherit;
  text-decoration: none;
}
.bld-lock-reasons .req-link {
  display: block;
  width: 100%;
  font-size: 11.5px;
}
.lw-lock .req-link {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

/* Landing highlight after tapping a requirement link: the shared living
   ring (kc-live-ring-el overlay injected by reqLinkFocus, since the card's
   own pseudos are taken) in the unmet-requirement color, plus a soft glow. */
.req-focus {
  position: relative;
  z-index: 1;
  --kc-ring-color: rgb(255, 77, 77);
  box-shadow: 0 0 22px rgba(255, 77, 77, 0.4);
}
@media (prefers-reduced-motion: reduce) {
  .req-focus {
    outline: 3px solid rgba(255, 77, 77, 0.9);
    outline-offset: 2px;
  }
}

/* Locked-card reasons stack: one row per requirement, no commas, no bullets */
.building-card .bld-cost.bld-lock-reasons,
.research-card .bld-cost.bld-lock-reasons {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  white-space: normal;
  line-height: 1.25;
  text-align: center;
}
.bld-cost.bld-lock-reasons .bld-lock-reason {
  display: block;
  list-style: none;
  font-size: 11.5px;
}
.bld-cost.bld-lock-reasons .bld-lock-reason::before,
.bld-cost.bld-lock-reasons .bld-lock-reason::marker {
  content: none;
}

/* Ship quantity control */
.ship-qty-control {
  display: flex;
  align-items: center;
  height: 28px;
  border: 1px solid rgba(0, 240, 255, 0.25);
  border-radius: 6px;
  background: var(--scrim-40);
  overflow: hidden;
  flex-shrink: 0;
}

.ship-qty-btn {
  width: 22px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 240, 255, 0.08);
  border: none;
  color: var(--cyan, #00f0ff);
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s;
  padding: 0;
  line-height: 1;
  /* Prevent iOS double-tap-to-zoom on rapid +/- taps. */
  touch-action: manipulation;
}

.ship-qty-btn:active {
  background: rgba(0, 240, 255, 0.25);
}

.ship-qty-input {
  width: 22px;
  height: 26px;
  text-align: center;
  background: transparent;
  border: none;
  border-left: 1px solid rgba(0, 240, 255, 0.15);
  border-right: 1px solid rgba(0, 240, 255, 0.15);
  color: #fff;
  font-size: 0.75rem;
  font-family: inherit;
  padding: 0;
  -moz-appearance: textfield;
}

.ship-qty-input::-webkit-outer-spin-button,
.ship-qty-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

/* Market batch pills (x10 / x100 / MAX) */
.kc-batch-row {
  display: flex;
  gap: 4px;
  margin-top: 4px;
  justify-content: space-between;
}

.kc-batch-pill {
  flex: 1;
  min-width: 0;
  padding: 3px 4px;
  font-family: var(--font-mono);
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.04em;
  background: rgba(0, 240, 255, 0.08);
  color: var(--cyan, #00f0ff);
  border: 1px solid rgba(0, 240, 255, 0.25);
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
  touch-action: manipulation;
  line-height: 1;
}

.kc-batch-pill:hover:not([disabled]) {
  background: rgba(0, 240, 255, 0.18);
  border-color: rgba(0, 240, 255, 0.5);
}

.kc-batch-pill:active:not([disabled]) {
  background: rgba(0, 240, 255, 0.3);
}

.kc-batch-pill[disabled] {
  opacity: 0.35;
  cursor: not-allowed;
}

.kc-batch-pill.selected {
  background: rgba(0, 240, 255, 0.35);
  border-color: rgba(0, 240, 255, 0.85);
  color: #fff;
}

.res-energy-warn {
  font-size: 11.5px;
  font-weight: 700;
  color: #ff4444;
  text-shadow: 0 0 6px rgba(255, 68, 68, 0.5);
  background: rgba(255, 68, 68, 0.1);
  padding: 1px 6px;
  border-radius: 4px;
  letter-spacing: 0.05em;
}

.building-card .card-deficit-warn {
  text-align: center;
  font-size: 11.5px;
  padding: 2px 8px;
  margin: 0 auto 2px;
  width: fit-content;
  background: rgba(10, 8, 20, 0.8);
  animation: pulse-warn 2s ease-in-out infinite;
}

.detail-qbit-warn,
.detail-qbit-warn.res-energy-warn,
.detail-qbit-warn.res-qbit-warn {
  text-align: center;
  font-size: 0.95rem;
  font-weight: 700;
  padding: 10px 16px;
  margin: 10px 12px;
  border-radius: 8px;
  letter-spacing: 0.03em;
}

@keyframes pulse-warn {
  0%, 100% { color: #8b5cf6; }
  50% { color: rgba(139, 92, 246, 0.5); }
}

.building-card .bld-progress {
  width: 100%;
  margin-top: 4px;
  padding: 0 8px;
}

.building-card .bld-progress .progress-bar {
  background: rgba(255, 255, 255, 0.1);
}

.building-card .bld-timer {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  color: var(--amber);
  margin-top: 2px;
  text-shadow: 0 0 6px rgba(245, 158, 11, 0.3);
  padding-bottom: 8px;
}

/* Cards upgrading/queued: no visual FX on cards, only the built-in progress bar */

.building-card.empty-slot {
  border-style: dashed;
  border-color: rgba(var(--accent-rgb), 0.15);
  cursor: pointer;
  min-height: 120px;
  justify-content: center;
  padding: 12px 8px;
}

.building-card.empty-slot:hover {
  border-color: rgba(var(--accent-rgb), 0.35);
  background: rgba(var(--accent-rgb), 0.03);
}

.building-card.empty-slot .bld-icon {
  color: var(--text-dim);
  font-size: 1.8rem;
  background: none;
  border: none;
}

.building-card.empty-slot .bld-name {
  color: var(--text-dim);
}

/* --- Tech Tree (Skill Tree) --- */
.tech-tree {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.tech-branch {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(13, 13, 31, 0.6);
  border-radius: 3px;
  border: 1px solid rgba(var(--accent-rgb), 0.08);
  padding: 8px;
  min-height: 64px;
}
.tech-branch-label {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 56px;
  flex-shrink: 0;
}
.tech-branch-icon {
  width: 32px;
  height: 32px;
  border-radius: 2px;
  object-fit: cover;
}
.tech-branch-name {
  font-size: 0.55rem;
  color: var(--branch-color);
  text-align: center;
  font-weight: 600;
  letter-spacing: 0.03em;
}
.tech-branch-lvl {
  font-size: 0.6rem;
  color: var(--text-dim);
}

/* Scrollable nodes area */
.tech-nodes-scroll {
  flex: 1;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  -ms-overflow-style: none;
  padding: 4px 0;
}
.tech-nodes-scroll::-webkit-scrollbar { display: none; }
.tech-nodes-track {
  display: flex;
  align-items: center;
  gap: 0;
  min-width: max-content;
}

.tech-node-wrapper {
  display: flex;
  align-items: center;
}
.tech-connector {
  width: 16px;
  height: 2px;
  background: rgba(100, 116, 139, 0.3);
  flex-shrink: 0;
}
.tech-connector.completed {
  background: var(--branch-color);
  box-shadow: 0 0 4px var(--branch-color);
}

.tech-node {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  border: 2px solid;
  transition: all 0.2s;
  position: relative;
}
.tech-node.completed {
  border-color: var(--branch-color);
  background: color-mix(in srgb, var(--branch-color) 20%, transparent);
  box-shadow: 0 0 6px color-mix(in srgb, var(--branch-color) 40%, transparent);
}
.tech-node.completed .tech-node-level {
  color: var(--branch-color);
  font-weight: 700;
}
.tech-node.available {
  border-color: var(--branch-color);
  background: var(--scrim-40);
  animation: techPulse 2s ease-in-out infinite;
  cursor: pointer;
}
.tech-node.available .tech-node-level { color: var(--branch-color); }
@keyframes techPulse {
  0%, 100% { box-shadow: 0 0 4px transparent; }
  50% { box-shadow: 0 0 12px color-mix(in srgb, var(--branch-color) 50%, transparent); }
}
.tech-node.researching {
  border-color: var(--branch-color);
  background: var(--scrim-40);
  animation: techSpin 3s linear infinite;
}
@keyframes techSpin {
  0% { box-shadow: 0 0 6px var(--branch-color), inset 0 0 6px transparent; }
  50% { box-shadow: 0 0 12px var(--branch-color), inset 0 0 8px color-mix(in srgb, var(--branch-color) 20%, transparent); }
  100% { box-shadow: 0 0 6px var(--branch-color), inset 0 0 6px transparent; }
}
.tech-node.researching .tech-node-level { display: none; }
.tech-node-timer {
  font-size: 0.5rem;
  color: var(--branch-color);
  white-space: nowrap;
}
.tech-node.next-locked {
  border-color: rgba(100, 116, 139, 0.4);
  background: rgba(0, 0, 0, 0.3);
}
.tech-node.next-locked .tech-node-level { color: var(--text-dim); }
.tech-node.locked {
  border-color: rgba(100, 116, 139, 0.2);
  background: rgba(0, 0, 0, 0.2);
  opacity: 0.4;
}
.tech-node.locked .tech-node-level { color: var(--text-dim); }
.tech-node-level {
  font-size: 0.65rem;
  color: var(--text-secondary);
}

/* Action area (right side) */
.tech-branch-action {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  min-width: 72px;
  flex-shrink: 0;
}
.tech-cancel-btn {
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 0.6rem;
  border: 1px solid rgba(239, 68, 68, 0.3);
  background: rgba(239, 68, 68, 0.1);
  color: var(--red);
  cursor: pointer;
}
.tech-cost {
  font-size: 0.6rem;
  color: var(--text-dim);
  display: flex;
  gap: 3px;
  flex-wrap: wrap;
  justify-content: center;
}
.tech-time {
  font-size: 0.55rem;
  color: var(--text-dim);
}
.tech-lock-msg {
  font-size: 0.55rem;
  color: var(--text-dim);
  text-align: center;
}

/* Mobile: stack vertically on very small screens */
@media (max-width: 400px) {
  .tech-branch {
    flex-wrap: wrap;
  }
  .tech-branch-label {
    flex-direction: row;
    gap: 6px;
    min-width: 100%;
    justify-content: flex-start;
  }
  .tech-branch-action {
    min-width: 100%;
    flex-direction: row;
    justify-content: center;
  }
}

/* All building cards are clickable */
.building-card[data-lore-key] {
  cursor: pointer;
}
/* Tappable card: full-art like research cards */
.card-tappable .card-body {
  position: relative;
  z-index: 2;
  margin-top: auto;
}

/* Card info text panel - glassmorphism overlay */
.card-info-text {
  padding: 6px 8px 4px;
  background: rgba(8, 12, 24, 0.7);
  backdrop-filter: blur(var(--blur-lg));
  -webkit-backdrop-filter: blur(var(--blur-lg));
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}
.card-info-benefit {
  font-size: 0.7rem;
  font-weight: 700;
  color: #e2e8f0;
  margin-bottom: 5px;
  line-height: 1.3;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 2px 4px;
}
.card-info-benefit > span {
  display: inline-flex;
  align-items: center;
  gap: 2px;
}
.card-info-lore {
  font-size: 11.5px;
  color: #94a3b8;
  line-height: 1.4;
  margin-bottom: 4px;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card-info-lore.research-lore-mono,
.progression-lore {
  font-family: var(--font-mono);
  font-size: 11.5px;
  font-style: normal;
  color: #64748b;
  -webkit-line-clamp: 2;
}
.progression-lore {
  margin-top: 4px;
  line-height: 1.35;
}
.card-info-quote {
  font-size: 11.5px;
  font-style: italic;
  color: #64748b;
  line-height: 1.3;
  margin-top: 2px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card-info-author {
  font-style: normal;
  opacity: 0.7;
}

/* Cost integrated in card info text */
.card-info-cost {
  margin-top: 4px;
  padding: 2px 0 0;
  background: none !important;
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
  border-radius: 0;
}

/* ─── Chip Quick Panel ─────────────────────────────────────
   Compact bottom-anchored panel that previews a chip when tapped.
   Slides up over the play area; shows cost / requirements / status
   plus Build (✓), Expand (⇱) and Close (✕) actions. */
#chip-quick-panel.cqp {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translate(-50%, 24px);
  z-index: 1500;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: rgba(11, 18, 32, 0.96);
  border: 1px solid rgba(34, 211, 238, 0.4);
  border-radius: 14px;
  box-shadow: 0 16px 40px var(--scrim-70), 0 0 0 1px rgba(34, 211, 238, 0.2) inset;
  -webkit-backdrop-filter: blur(var(--blur-lg)) saturate(140%);
  backdrop-filter: blur(var(--blur-lg)) saturate(140%);
  min-width: min(360px, calc(100vw - 32px));
  max-width: calc(100vw - 32px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms ease-out, transform 200ms ease-out;
}
#chip-quick-panel.cqp[hidden] { display: none; }
#chip-quick-panel.cqp.cqp-open {
  opacity: 1;
  transform: translate(-50%, 0);
  pointer-events: auto;
}
.cqp-thumb {
  flex-shrink: 0;
  width: 56px;
  height: 56px;
  border-radius: 6px;
  overflow: hidden;
  background: var(--scrim-40);
  border: 1px solid rgba(148, 163, 184, 0.25);
}
.cqp-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cqp-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.cqp-name {
  font-weight: 700;
  font-size: 0.95rem;
  color: #f1f5f9;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cqp-desc {
  font-size: 0.72rem;
  color: rgba(203, 213, 225, 0.78);
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cqp-status {
  font-size: 0.68rem;
  color: rgba(148, 163, 184, 0.85);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.cqp-status-warn { color: #f59e0b; }
.cqp-status-locked { color: #94a3b8; }
.cqp-status-active { color: #22d3ee; }
.cqp-status-queued { color: #f59e0b; }
.cqp-cost {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-top: 2px;
}
.cqp-cost-label {
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: rgba(148, 163, 184, 0.85);
  padding-right: 2px;
}
.cqp-cost-warn .cqp-cost-label {
  color: #f59e0b;
}
.cqp-cost-label-warn {
  color: #f87171;
}
.cqp-cost-item {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.85rem;
  font-family: var(--font-mono);
  font-weight: 700;
  white-space: nowrap;
}
.cqp-cost-icon {
  display: inline-flex;
  align-items: center;
  /* color comes from inline style so resIcon's currentColor adopts it */
}
.cqp-cost-icon svg,
.cqp-cost-icon img { width: 16px; height: 16px; flex-shrink: 0; }
.cqp-cost-num { color: #f1f5f9; }
.cqp-cost-num.missing { color: #f87171; }
.cqp-reqs {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
}
.cqp-req {
  display: inline-block;
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: 10px;
}
.cqp-req.met { color: #22d3ee; background: rgba(34, 211, 238, 0.12); }
.cqp-req.unmet { color: #f87171; background: rgba(248, 113, 113, 0.14); }
.cqp-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}
.cqp-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  padding: 0;
  border: 1px solid rgba(148, 163, 184, 0.3);
  border-radius: 50%;
  background: rgba(15, 23, 42, 0.7);
  color: #f1f5f9;
  cursor: pointer;
  transition: transform 120ms ease, box-shadow 120ms ease, border-color 120ms ease, background 120ms ease;
}
.cqp-btn:hover {
  border-color: rgba(34, 211, 238, 0.7);
  background: rgba(34, 211, 238, 0.15);
  transform: translateY(-1px);
}
.cqp-btn:active { transform: translateY(0); }
.cqp-btn svg { width: 18px; height: 18px; }
.cqp-btn-build {
  border-color: #22d3ee;
  background: rgba(34, 211, 238, 0.22);
  color: #22d3ee;
  box-shadow: 0 0 12px rgba(34, 211, 238, 0.35);
}
.cqp-btn-build:hover {
  background: rgba(34, 211, 238, 0.4);
  box-shadow: 0 0 18px rgba(34, 211, 238, 0.6);
}
.cqp-btn-loading {
  pointer-events: none;
  opacity: 0.8;
}
.cqp-btn-loading svg { display: none; }
.cqp-btn-loading::after {
  content: '';
  width: 16px;
  height: 16px;
  border: 2px solid rgba(34, 211, 238, 0.25);
  border-top-color: #22d3ee;
  border-radius: 50%;
  animation: cqp-spin 0.7s linear infinite;
}
@keyframes cqp-spin {
  to { transform: rotate(360deg); }
}
@media (max-width: 520px) {
  #chip-quick-panel.cqp {
    bottom: 80px;
    left: 8px;
    right: 8px;
    transform: translateY(24px);
    min-width: 0;
    max-width: none;
    padding: 9px 10px;
    gap: 10px;
  }
  #chip-quick-panel.cqp.cqp-open {
    transform: translateY(0);
  }
  .cqp-thumb { width: 48px; height: 48px; }
  .cqp-name { font-size: 0.88rem; }
  .cqp-btn { width: 36px; height: 36px; }
}

/* ─── Stationed Ships Section (Ships tab) ──────────────── */
.stationed-ships-section {
  grid-column: 1 / -1;
  margin-bottom: 12px;
  padding: 0 0 12px;
}
.reserve-hibernated-banner {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  margin-bottom: 12px;
  background: rgba(120, 120, 160, 0.08);
  border: 1px solid rgba(160, 170, 200, 0.25);
  border-radius: 10px;
  color: rgba(220, 225, 240, 0.85);
}
.reserve-hibernated-banner .icon {
  width: 18px;
  height: 18px;
  color: rgba(180, 195, 230, 0.7);
  flex-shrink: 0;
}
.reserve-hibernated-text { flex: 1; min-width: 0; }
.reserve-hibernated-title {
  font-weight: 600;
  font-size: 0.85rem;
  margin-bottom: 2px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: rgba(225, 230, 245, 0.92);
}
.reserve-hibernated-hint { font-size: 0.78rem; opacity: 0.75; }
.reserve-hibernated-wake {
  background: rgba(0, 240, 255, 0.12);
  border: 1px solid rgba(0, 240, 255, 0.45);
  color: #6be8ff;
  padding: 6px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-family: var(--font-heading);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  transition: background 0.15s, border-color 0.15s;
}
.reserve-hibernated-wake:hover {
  background: rgba(0, 240, 255, 0.22);
  border-color: rgba(0, 240, 255, 0.7);
}
.stationed-ships-title {
  color: #00f0ff;
  font-size: 0.82rem;
  font-weight: 600;
  margin: 0 0 8px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.stationed-ships-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 6px;
}
.stationed-ship-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px 6px 0;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 8px;
  transition: border-color 0.2s;
  cursor: pointer;
  overflow: hidden;
}
.stationed-ship-item:hover {
  border-color: rgba(0, 240, 255, 0.2);
}
.stationed-ship-icon {
  width: 56px;
  align-self: stretch;
  margin: -6px 0;
  border-radius: 7px 0 0 7px;
  flex-shrink: 0;
  object-fit: cover;
  background: rgba(0, 0, 0, 0.3);
}
.stationed-ship-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.stationed-ship-name {
  font-size: 0.75rem;
  color: #e0e0e0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.stationed-ship-qty {
  font-size: 0.85rem;
  font-weight: 600;
  color: #00f0ff;
}

/* Compact spaceport capacity chip on the colony back-bar row (Naves) */
#colony-back-aux .hangar-cap {
  display: inline-flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: 6px;
  min-width: 0;
  margin: 0;
  padding: 4px 10px;
  background: rgba(2, 8, 14, 0.72);
  border: 1px solid rgba(0, 240, 255, 0.18);
  border-radius: 8px;
  font-size: 0.72rem;
}
#colony-back-aux .hangar-cap:hover {
  border-color: rgba(0, 240, 255, 0.42);
  background: rgba(2, 12, 20, 0.88);
}
#colony-back-aux .hangar-cap-bar { flex: 0 1 56px; min-width: 28px; }
#colony-back-aux .hangar-cap-hint { display: none; }
#colony-back-aux .hangar-cap-label { white-space: nowrap; }
@media (max-width: 419px) {
  #colony-back-aux .hangar-cap-label { display: none; }
}

/* ── Hangar orbital 3D (library; theater consumes createOrbitDiorama) ── */
.hangar3d-host {
  position: relative;
  height: 275px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  overflow: hidden;
  background: #020408;
}
@media (min-width: 900px) {
  .hangar3d-host { height: 360px; }
}
.hangar3d-canvas {
  display: block;
  width: 100%;
  height: 100%;
}
.hangar3d-host::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(ellipse 120% 100% at 50% 42%, rgba(0,0,0,0) 58%, rgba(0,0,0,0.42) 100%);
}
.hangar3d-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 2;
}
.hangar3d-cap {
  position: absolute;
  left: 10px;
  bottom: 8px;
  z-index: 3;
  pointer-events: none;
  max-width: calc(100% - 20px);
}
.hangar3d-cap .hangar-cap-upgrading {
  padding-top: 6px;
  padding-bottom: 6px;
}
.hangar3d-cap .hangar-cap-upgrading .hangar-cap-bar {
  max-width: 140px;
  flex: 0 0 6px;
  height: 6px;
}
.hangar3d-cap .hangar-cap {
  margin: 0;
  padding: 4px 10px;
  background: rgba(2, 8, 14, 0.72);
  border: 1px solid rgba(0, 240, 255, 0.18);
  border-radius: 8px;
  font-size: 0.72rem;
  pointer-events: auto;
}
.hangar3d-cap .hangar-cap:hover {
  border-color: rgba(0, 240, 255, 0.42);
  background: rgba(2, 12, 20, 0.88);
}
.hangar3d-cap .hangar-cap > .hangar-cap-bar {
  flex: 0 1 90px;
}
.hangar3d-host + .stationed-ships-grid {
  margin-top: 8px;
}
.stationed-ships-section > .hangar3d-host:last-child {
  margin-bottom: 4px;
}
.hangar3d-empty {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 4;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  max-width: min(92%, 320px);
  padding: 10px 14px;
  text-align: center;
  pointer-events: none;
  background: rgba(2, 8, 14, 0.62);
  border: 1px solid rgba(0, 240, 255, 0.14);
  border-radius: 10px;
  backdrop-filter: blur(4px);
}
.hangar3d-empty-text {
  color: rgba(220, 235, 248, 0.92);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}
.hangar3d-empty-hint {
  color: rgba(160, 190, 215, 0.72);
  font-size: 0.72rem;
  line-height: 1.35;
}
.stationed-ships-empty {
  padding: 8px 0 4px;
}
.stationed-ships-empty .empty-text {
  font-size: 0.8rem;
  opacity: 0.75;
}
.hangar3d-label {
  position: absolute;
  left: 0;
  top: 0;
  pointer-events: auto;
  background: rgba(2, 8, 14, 0.78);
  border: 1px solid rgba(0, 240, 255, 0.25);
  border-radius: 7px;
  color: #cfeefb;
  font-family: var(--font-mono, monospace);
  font-size: 11.5px;
  letter-spacing: 0.04em;
  padding: 2px 7px;
  white-space: nowrap;
  cursor: pointer;
}
.hangar3d-label:hover {
  border-color: rgba(0, 240, 255, 0.6);
  color: #ffffff;
}
.hangar3d-label-fleet {
  border-color: rgba(255, 196, 77, 0.4);
  color: #ffe2a8;
}
.hangar3d-label-fleet:hover {
  border-color: rgba(255, 196, 77, 0.8);
}

/* ── KC price cell + breakdown popover (credit economy) ── */
.kc-price { cursor: pointer; }
.kc-price-flag {
  font-size: 0.75em;
  color: #f59e0b;
  vertical-align: 1px;
}
.kc-price-pop {
  position: fixed;
  z-index: 3000;
  background: rgba(10, 16, 28, 0.97);
  border: 1px solid rgba(120, 160, 220, 0.35);
  border-radius: 10px;
  padding: 10px 12px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.55);
  font-size: 12px;
  backdrop-filter: blur(6px);
}
.kc-price-foundry {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  margin-top: 8px;
  padding: 6px 8px;
  background: rgba(245, 205, 95, 0.10);
  border: 1px solid rgba(245, 205, 95, 0.45);
  border-radius: 7px;
  color: #f5cd5f;
  font-size: 11.5px;
  cursor: pointer;
}
.kc-price-foundry .icon { width: 13px; height: 13px; fill: none; stroke: currentColor; stroke-width: 2; flex: none; }
.kc-price-foundry .kpf-go { margin-left: auto; font-weight: 600; white-space: nowrap; }
.kc-price-pop-title {
  font-family: 'Share Tech Mono', monospace;
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #8fa3c0;
  margin-bottom: 6px;
}
.kc-price-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 8px;
  align-items: center;
  padding: 3px 0;
}
.kc-price-row-res { display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; }
.kc-price-row-amt { font-family: 'Share Tech Mono', monospace; text-align: right; color: #e6edf7; }
.kc-price-mark {
  font-family: 'Share Tech Mono', monospace;
  font-size: 10px;
  white-space: nowrap;
  padding: 1px 6px;
  border-radius: 6px;
}
.kc-price-mark.ok { color: #34d399; background: rgba(52, 211, 153, 0.12); }
.kc-price-mark.up { color: #f59e0b; background: rgba(245, 158, 11, 0.14); }
.kc-price-mark.fix { color: #9fb0c8; background: rgba(159, 176, 200, 0.12); }
.kc-price-total {
  border-top: 1px solid rgba(120, 160, 220, 0.25);
  margin-top: 4px;
  padding-top: 6px;
  font-weight: 600;
}
