/* ============================================================
   BUTTONS - Game-style with gradients and effects
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 24px;
  border-radius: 3px;
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  transition: all 0.2s;
  min-height: 44px;
  text-transform: uppercase;
  position: relative;
  overflow: hidden;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.btn-primary {
  background: linear-gradient(135deg, rgba(var(--accent-rgb), 0.25) 0%, rgba(var(--accent-rgb), 0.1) 100%);
  border: 1px solid rgba(var(--accent-rgb), 0.5);
  color: var(--cyan);
  box-shadow:
    0 0 16px rgba(var(--accent-rgb), 0.15),
    inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

.btn-primary::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.06), transparent);
  transition: left 0.5s;
}

.btn-primary:hover {
  background: linear-gradient(135deg, rgba(var(--accent-rgb), 0.35) 0%, rgba(var(--accent-rgb), 0.15) 100%);
  box-shadow:
    0 0 28px rgba(var(--accent-rgb), 0.25),
    inset 0 1px 0 rgba(255, 255, 255, 0.1);
  transform: translateY(-1px);
}

.btn-primary:hover::before {
  left: 100%;
}

.btn-primary:active {
  transform: scale(0.97) translateY(0);
  box-shadow: 0 0 12px rgba(var(--accent-rgb), 0.2);
}

.btn-primary:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  box-shadow: none;
  transform: none;
}

.btn-secondary {
  background: linear-gradient(135deg, rgba(148, 163, 184, 0.18) 0%, rgba(148, 163, 184, 0.06) 100%);
  border: 1px solid rgba(148, 163, 184, 0.4);
  color: #cbd5e1;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.btn-secondary:hover {
  background: linear-gradient(135deg, rgba(148, 163, 184, 0.28) 0%, rgba(148, 163, 184, 0.1) 100%);
  box-shadow: 0 0 16px rgba(148, 163, 184, 0.15), inset 0 1px 0 rgba(255, 255, 255, 0.08);
  transform: translateY(-1px);
}

.btn-secondary:active {
  transform: scale(0.97) translateY(0);
}

.btn-secondary:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  box-shadow: none;
  transform: none;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.7rem;
  min-height: 32px;
  border-radius: 2px;
}

.bld-btn-row {
  display: flex;
  gap: 4px;
  width: 100%;
  align-items: stretch;
}
.bld-btn-row .btn-upgrade {
  flex: 1;
  min-width: 0;
}
.bld-actions-stack {
  display: flex;
  flex-direction: column;
  gap: 0;
  width: 100%;
}
.bld-actions-stack.is-expanded {
  gap: 4px;
}
.btn-more-actions {
  --btn-color: #94a3b8;
  width: 40px;
  min-width: 40px;
  height: 52px;
  border-radius: 3px;
  border: 1px solid color-mix(in srgb, var(--btn-color) 40%, transparent);
  background: linear-gradient(135deg, color-mix(in srgb, var(--btn-color) 24%, rgba(6, 10, 18, 0.76)) 0%, rgba(6, 10, 18, 0.56) 100%);
  color: #e2e8f0;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--btn-color) 8%, transparent);
  transition: all 0.2s;
}
.btn-more-dots {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  width: 16px;
  height: 16px;
}
.btn-more-dots span {
  display: block;
  width: 4px;
  height: 4px;
  border-radius: 999px;
  background: currentColor;
}
.btn-more-actions:hover {
  --btn-color: var(--cyan);
  background: linear-gradient(135deg, color-mix(in srgb, var(--btn-color) 28%, rgba(6, 10, 18, 0.76)) 0%, rgba(6, 10, 18, 0.44) 100%);
  border-color: color-mix(in srgb, var(--btn-color) 40%, transparent);
  box-shadow:
    inset 0 0 0 1px color-mix(in srgb, var(--btn-color) 12%, transparent),
    0 0 16px color-mix(in srgb, var(--btn-color) 18%, transparent);
  color: #fff;
  transform: translateY(-1px);
}
.bld-actions-stack.is-expanded .btn-more-actions {
  color: var(--cyan);
  border-color: rgba(var(--accent-rgb), 0.45);
  box-shadow: 0 0 12px rgba(var(--accent-rgb), 0.16);
}
.card-secondary-actions {
  display: grid;
  gap: 4px;
  overflow: hidden;
  max-height: 0;
  opacity: 0;
  transform: translateY(-4px);
  pointer-events: none;
  transition: max-height 0.22s ease, opacity 0.18s ease, transform 0.22s ease;
}
.bld-actions-stack.is-expanded .card-secondary-actions {
  max-height: 96px;
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}
.btn-card-action {
  --btn-color: #94a3b8;
  width: 100%;
  min-height: 32px;
  border-radius: 3px;
  border: 1px solid color-mix(in srgb, var(--btn-color) 40%, transparent);
  background: linear-gradient(135deg, color-mix(in srgb, var(--btn-color) 24%, rgba(6, 10, 18, 0.76)) 0%, rgba(6, 10, 18, 0.56) 100%);
  color: #e2e8f0;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 10px;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--btn-color) 8%, transparent);
  text-shadow: 0 0 8px color-mix(in srgb, var(--btn-color) 24%, transparent);
  transition: all 0.2s;
}
.btn-card-action svg {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  flex-shrink: 0;
}
.btn-card-action:hover {
  background: linear-gradient(135deg, color-mix(in srgb, var(--btn-color) 28%, rgba(6, 10, 18, 0.76)) 0%, rgba(6, 10, 18, 0.44) 100%);
  box-shadow:
    inset 0 0 0 1px color-mix(in srgb, var(--btn-color) 12%, transparent),
    0 0 16px color-mix(in srgb, var(--btn-color) 18%, transparent);
  transform: translateY(-1px);
}
.btn-card-enqueue {
  --btn-color: #c084fc;
  color: #c084fc;
}
.btn-card-enqueue:hover {
  border-color: color-mix(in srgb, var(--btn-color) 40%, transparent);
}
.btn-card-downgrade {
  --btn-color: #f87171;
  color: #f87171;
}
.btn-card-downgrade:hover {
  border-color: color-mix(in srgb, var(--btn-color) 40%, transparent);
}
/* More-actions toggle button */
.btn-upgrade {
  --btn-color: #10b981;
  background: linear-gradient(135deg, color-mix(in srgb, var(--btn-color) 28%, rgba(6, 10, 18, 0.84)) 0%, rgba(6, 10, 18, 0.68) 100%);
  border: 1px solid color-mix(in srgb, var(--btn-color) 48%, transparent);
  color: var(--btn-color);
  width: 100%;
  font-size: 0.85rem;
  font-weight: 700;
  padding: 6px 8px;
  height: 52px;
  letter-spacing: 0.08em;
  border-radius: 3px;
  position: relative;
  overflow: hidden;
  text-shadow: 0 0 8px color-mix(in srgb, var(--btn-color) 30%, transparent);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--btn-color) 12%, transparent);
}

.btn-upgrade::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.06), transparent);
  transition: left 0.4s;
}

.btn-upgrade:hover {
  background: linear-gradient(135deg, color-mix(in srgb, var(--btn-color) 32%, rgba(6, 10, 18, 0.86)) 0%, rgba(6, 10, 18, 0.58) 100%);
  box-shadow:
    inset 0 0 0 1px color-mix(in srgb, var(--btn-color) 16%, transparent),
    0 0 16px color-mix(in srgb, var(--btn-color) 18%, transparent);
  transform: translateY(-1px);
}

.btn-upgrade:hover::before {
  left: 100%;
}

.btn-upgrade.affordable {
  animation: glow-pulse-btn 2s infinite;
}

.btn-upgrade:disabled,
.btn-upgrade.disabled {
  --btn-color: #64748b;
  opacity: 0.45;
  cursor: not-allowed;
  animation: none;
  border-color: color-mix(in srgb, var(--btn-color) 30%, transparent);
  color: #64748b;
  background: linear-gradient(135deg, color-mix(in srgb, var(--btn-color) 18%, rgba(6, 10, 18, 0.9)) 0%, rgba(6, 10, 18, 0.78) 100%);
  text-shadow: none;
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--btn-color) 8%, transparent);
  transform: none;
}
/* Disabled buttons styled via CSS class (not HTML disabled) are still clickable */
.btn-upgrade.disabled:not(:disabled) {
  cursor: pointer;
}
.btn-upgrade.enqueue {
  --btn-color: #64748b;
  animation: none;
  border-color: color-mix(in srgb, var(--btn-color) 46%, transparent);
  color: #94a3b8;
  background: linear-gradient(135deg, color-mix(in srgb, var(--btn-color) 28%, rgba(6, 10, 18, 0.84)) 0%, rgba(6, 10, 18, 0.68) 100%);
  text-shadow: none;
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--btn-color) 12%, transparent);
  cursor: pointer;
}

.btn-afford-fill {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  background: linear-gradient(90deg, rgba(16, 185, 129, 0.18) 0%, rgba(16, 185, 129, 0.08) 100%);
  border-right: 1px solid rgba(16, 185, 129, 0.3);
  transition: width 1s ease;
  pointer-events: none;
}

.btn-upgrade {
  display: flex;
  justify-content: center;
  align-items: center;
}

/* Ship cards: single-line Build — must come AFTER .btn-upgrade { height: 52px }. */
.bld-btn-row-ship {
  align-items: stretch;
  gap: 4px;
}
.bld-btn-row-ship .btn-upgrade {
  height: 28px;
  min-height: 28px;
  max-height: 28px;
  font-size: 0.72rem;
  padding: 0 8px;
  letter-spacing: 0.04em;
}
.bld-btn-row-ship .btn-upgrade:hover {
  transform: none;
}
.bld-btn-row-ship .btn-text {
  flex-wrap: nowrap;
}

.btn-text {
  position: relative;
  z-index: 1;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0 6px;
  line-height: 1.2;
  overflow: hidden;
  max-height: 100%;
}

.btn-label {
  position: relative;
  z-index: 1;
}

.btn-benefit {
  font-size: 11.5px;
  font-weight: 400;
  opacity: 0.8;
  letter-spacing: 0.02em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}
.btn-benefit.trade-benefit > span {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  font-size: 0.85rem;
}
.btn-benefit.trade-benefit .cost-icon {
  width: 16px;
  height: 16px;
}

.btn-upgrade.in-progress {
  --btn-color: var(--amber);
  border-color: var(--amber);
  color: var(--amber);
  background: linear-gradient(135deg, color-mix(in srgb, var(--btn-color) 22%, rgba(6, 10, 18, 0.62)) 0%, rgba(6, 10, 18, 0.42) 100%);
  cursor: default;
  animation: none;
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--btn-color) 8%, transparent);
}

/* Card action row (speedup + cancel inside building card) */
.card-action-row {
  display: flex;
  gap: 4px;
  padding: 4px 8px 6px;
  justify-content: center;
  position: relative;
  z-index: 5;
}
.btn-speedup-card, .btn-cancel-card {
  flex: 0 0 auto;
  padding: 4px 16px;
  border-radius: 4px;
  /* game-wide type floor: never render text below 11.5px */
  font-size: max(11.5px, 0.65rem);
  font-weight: 500;
  cursor: pointer;
  border: 1px solid;
  transition: background 0.15s, opacity 0.15s;
}
.btn-speedup-card {
  background: rgba(0, 240, 255, 0.1);
  border-color: rgba(0, 240, 255, 0.3);
  color: var(--cyan);
}
.btn-speedup-card:hover { background: rgba(0, 240, 255, 0.2); }
.btn-speedup-card.btn.cta {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 10px;
  min-width: 88px;
}
.btn-speedup-card.btn.cta .cl {
  font-size: max(11.5px, 0.62rem);
  line-height: 1.2;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.btn-speedup-card.btn.cta .cc {
  font-family: var(--font-mono);
  font-size: max(11.5px, 0.6rem);
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  color: var(--text-secondary);
}
.btn-speedup-card.btn.cta.dim .cc { color: #f87171; }
.btn-cancel-card {
  background: rgba(239, 68, 68, 0.14);
  border-color: rgba(239, 68, 68, 0.45);
  color: #f87171;
}
.btn-cancel-card:hover { background: rgba(239, 68, 68, 0.24); }
.btn-speedup-card:disabled, .btn-cancel-card:disabled {
  opacity: 0.4;
  cursor: default;
}
body.speedup-cooldown .btn-speedup-card,
body.speedup-cooldown .cqp-btn[data-cqp-action="speedup"] {
  pointer-events: none;
  opacity: 0.4;
}

/* Danger Zone */
.btn-danger {
  background: linear-gradient(135deg, rgba(239, 68, 68, 0.2), rgba(239, 68, 68, 0.08));
  border: 1px solid rgba(239, 68, 68, 0.4);
  color: var(--red);
}

.btn-danger:hover {
  background: linear-gradient(135deg, rgba(239, 68, 68, 0.3), rgba(239, 68, 68, 0.12));
  box-shadow: 0 0 12px rgba(239, 68, 68, 0.2);
}

/* Cost icons */
.cost-icon {
  width: 14px;
  height: 14px;
  fill: currentColor;
  stroke: currentColor;
  stroke-width: 1.5;
  margin-left: 1px;
  opacity: 0.8;
}
.btn-missing-list {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-basis: 100%;
  flex-wrap: wrap;
  gap: 4px;
  font-size: 0.68rem;
  min-width: 0;
  max-width: 100%;
}
.cost-missing {
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  gap: 1px;
}
/* Shape cue (not colour-only) for unaffordable cost figures */
.cost-num-cell.cost-missing {
  text-decoration: underline dotted;
  text-underline-offset: 2px;
}
.cost-have {
  font-weight: 400;
  font-size: 0.72em;
  opacity: 0.7;
  margin-left: 2px;
}
.trade-deficit {
  color: #ef4444;
  font-weight: 700;
  font-size: 0.62rem;
  display: inline-flex;
  align-items: center;
  gap: 1px;
  margin-left: 4px;
  opacity: 0.9;
}

/* Universal "Ver en mapa" reticle action */
.kc-viewmap-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  padding: 0;
  flex: 0 0 auto;
  border: 1px solid rgba(0, 240, 255, 0.35);
  border-radius: 6px;
  background: rgba(0, 240, 255, 0.08);
  color: var(--cyan, #00f0ff);
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.kc-viewmap-btn svg {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
}
.kc-viewmap-btn:hover {
  background: rgba(0, 240, 255, 0.18);
  border-color: rgba(0, 240, 255, 0.6);
}
.kc-viewmap-btn:active {
  transform: scale(0.94);
}

/* ─── Async action button states (KC.ui.asyncAction) ──────
   Busy flips on the same frame as the tap: inline spinner + slim
   indeterminate bar pinned to the button's bottom edge. Success shows a
   brief check state; failure restores the original label. Paused while the
   tab is hidden (--anim-state, the house battery mechanism); reduced motion
   keeps static busy shapes. */
.kc-btn-busy { position: relative; overflow: hidden; }
.kc-btn-spin {
  display: inline-block;
  width: 0.85em;
  height: 0.85em;
  margin-right: 7px;
  vertical-align: -0.08em;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: kc-btn-spin 0.7s linear infinite;
  animation-play-state: var(--anim-state, running);
}
@keyframes kc-btn-spin { to { transform: rotate(360deg); } }
.kc-btn-bar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 2px;
  pointer-events: none;
  overflow: hidden;
}
.kc-btn-bar::before {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 45%;
  background: currentColor;
  opacity: 0.85;
  transform: translateX(-100%);
  animation: kc-btn-bar-slide 1.1s ease-in-out infinite;
  animation-play-state: var(--anim-state, running);
}
@keyframes kc-btn-bar-slide { to { transform: translateX(330%); } }
.kc-btn-done .kc-btn-check { margin-right: 6px; font-weight: 700; }
@media (prefers-reduced-motion: reduce) {
  .kc-btn-spin { animation: none; border-right-color: currentColor; opacity: 0.55; }
  .kc-btn-bar::before { animation: none; transform: none; width: 100%; opacity: 0.45; }
}

/* Editable label: a name that doubles as its own rename control. */
[data-planet-rename] {
  appearance: none;
  background: none;
  border: 0;
  border-bottom: 1px dashed var(--border, #334155);
  padding: 0 0 1px;
  font: inherit;
  color: inherit;
  cursor: pointer;
  text-align: inherit;
}
[data-planet-rename]:hover,
[data-planet-rename]:focus-visible { border-bottom-style: solid; }
