/* ============================================================
   KreepCore - Reset, Typography, Global Styles
   ============================================================ */

/* --- Reset & Base --- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* Kill expensive effects during resize */
.is-resizing *,
.is-resizing *::before,
.is-resizing *::after {
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
  transition: none !important;
  animation-play-state: paused !important;
}

/* Disable text selection and long-press context menu on mobile */
#app, #app * {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-user-drag: none;
}
/* Allow selection in input fields */
input, textarea, [contenteditable] {
  -webkit-user-select: text;
  user-select: text;
}
/* Prevent native image drag-and-drop ghost across the whole app */
img {
  -webkit-user-drag: none;
  -khtml-user-drag: none;
  -moz-user-drag: none;
  user-drag: none;
}

html {
  font-size: var(--font-size-base);
  -webkit-text-size-adjust: 100%;
  overflow: hidden;
  height: 100%;
}

/* Prevent accidental double-tap-to-zoom across the game while keeping pinch-zoom.
   Universal selector (0,0,0 specificity) so any specific touch-action override (eg
   map pan/login overlay with touch-action: none) still wins. */
* {
  touch-action: manipulation;
}

html.game-active {
  height: 100vh;
  height: var(--app-height);
}

body {
  font-family: var(--font-body);
  background: var(--bg-void);
  color: var(--text-primary);
  min-height: 100vh;
  min-height: var(--app-height);
  line-height: 1.5;
  overflow-x: hidden;
  overscroll-behavior: none;
  font-variant-numeric: tabular-nums;
}

/* Display typeface for titles, nav, key UI chrome.
   Body copy (p, span, labels) keeps the system stack for legibility.
   If Orbitron fails to load, font-display:swap falls back to system sans. */
h1, h2, h3, h4,
.logo, .nav, .nav-item, .bottom-nav .nav-label, .cmd-tabs,
.btn, .btn-primary, .btn-secondary {
  font-family: var(--font-display);
  letter-spacing: 0.03em;
}

html.pwa-standalone.game-active body {
  position: fixed;
  inset: 0;
  width: 100%;
  min-height: var(--app-height, 100vh);
  height: var(--app-height, 100vh);
  overflow: hidden;
}

/* Futuristic font classes */
.font-heading {
  font-family: var(--font-display);
  letter-spacing: 0.05em;
}

.font-mono {
  font-family: var(--font-mono);
}

a { color: var(--cyan); text-decoration: none; }
a:hover { text-decoration: underline; }

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
  font-size: inherit;
}

button:active:not(.planet-dropdown-trigger) {
  transform: scale(0.95);
}

/* --- Starfield Background --- */
#starfield {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  z-index: 0;
  pointer-events: none;
}

/* CSS nebula overlay - deeper, more dramatic */
body::before {
  content: '';
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse at 15% 50%, rgba(139, 92, 246, 0.07) 0%, transparent 55%),
    radial-gradient(ellipse at 85% 15%, rgba(var(--accent-rgb), 0.05) 0%, transparent 45%),
    radial-gradient(ellipse at 50% 85%, rgba(59, 130, 246, 0.04) 0%, transparent 50%),
    radial-gradient(ellipse at 70% 50%, rgba(239, 68, 68, 0.02) 0%, transparent 40%);
}

/* Subtle scan lines for depth */
body::after {
  content: '';
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  z-index: 0;
  pointer-events: none;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(var(--accent-rgb), 0.008) 2px,
    rgba(var(--accent-rgb), 0.008) 4px
  );
}

/* --- Scrollbar styling --- */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--bg-divider);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-dim);
}

/* --- Durations and rates render as "20h 56m" / "139K /h" even inside
   uppercase containers --- */
[data-fleet-eta],
[data-end-time],
.task-card-timer,
.gov-gain-rate,
.rec-gain-kc,
.kc-res-gain {
  text-transform: none;
}

/* --- Accessibility --- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* --- Battery optimization: pause all animations on mobile when tab hidden --- */
@media (pointer: coarse) {
  *, *::before, *::after {
    animation-play-state: var(--anim-state, running) !important;
  }
}

/* --- Negative resource balance: motion is the primary cue, hue accompanies --- */
.kc-neg-pulse { animation: kc-neg-pulse 1.2s ease-in-out infinite; }
@keyframes kc-neg-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}
@media (prefers-reduced-motion: reduce) {
  .kc-neg-pulse { font-weight: 800; }
}

/* --- Battery optimization: disable heavy decorative animations on mobile --- */
@media (pointer: coarse) {
  .card-recommended-badge,
  .card-recommended-badge::after,
  .card-queue-badge,
  .commander-card,
  .resource-card::after,
  .res-warning,
  .mission-step-ring,
  .mission-current-pulse,
  .btn-upgrade.affordable {
    animation: none !important;
  }
}

/* Focus styles */
:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
}

/* --- Misc utility classes --- */
.hidden { display: none !important; }

.text-cyan { color: var(--cyan); }
.text-green { color: var(--green); }
.text-amber { color: var(--amber); }
.text-red { color: var(--red); }
.text-purple { color: var(--purple); }
.text-dim { color: var(--text-dim); }
.text-secondary { color: var(--text-secondary); }

.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mb-8 { margin-bottom: 8px; }

.empty-state {
  text-align: center;
  padding: 32px 16px;
  color: var(--text-dim);
}

.empty-state .empty-icon {
  font-size: 2.5rem;
  margin-bottom: 12px;
  opacity: 0.5;
}

.empty-state .empty-text {
  font-size: 0.8rem;
  line-height: 1.5;
  max-width: 260px;
  margin: 0 auto;
}

/* --- Fleet hero art drift ---
   Very slow background-position pan shared by every "soft ship art behind a
   fleet block" surface (dispatch form, Flotas roster cards, map Estacionadas
   rows). Kept CSS-only; callers pause it via --anim-state and disable it
   under reduced-motion / coarse pointer alongside the hero's own filter. */
@keyframes kc-hero-drift-a { from { background-position: center 25%; } to { background-position: 54% 34%; } }
@keyframes kc-hero-drift-b { from { background-position: 46% 34%; } to { background-position: 57% 47%; } }
@keyframes kc-hero-drift-c { from { background-position: 48% 46%; } to { background-position: 55% 54%; } }

/* --- Skeleton Loading --- */
.skeleton {
  background: linear-gradient(90deg, var(--bg-panel) 25%, var(--bg-surface) 50%, var(--bg-panel) 75%);
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.5s infinite;
  border-radius: 4px;
}

@keyframes skeleton-shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.skeleton-text {
  height: 14px;
  width: 80%;
  margin-bottom: 8px;
}

.skeleton-block {
  height: 60px;
  width: 100%;
}

/* --- Tabs (screen switching) --- */
.screen {
  display: none;
}

.screen.active {
  display: block;
  animation: fade-in 0.25s ease-out;
}

@keyframes fade-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* --- Glow Animations --- */
@keyframes glow-pulse {
  0%, 100% { opacity: 0.7; }
  50% { opacity: 1; }
}

@keyframes glow-pulse-green {
  0%, 100% {
    box-shadow: 0 0 6px rgba(16, 185, 129, 0.2);
  }
  50% {
    box-shadow: 0 0 18px rgba(16, 185, 129, 0.4);
  }
}

@keyframes glow-pulse-btn {
  0%, 100% {
    box-shadow: 0 0 6px color-mix(in srgb, var(--btn-color) 20%, transparent);
  }
  50% {
    box-shadow: 0 0 18px color-mix(in srgb, var(--btn-color) 40%, transparent);
  }
}

@keyframes glow-pulse-cyan {
  0%, 100% { box-shadow: 0 0 6px rgba(var(--accent-rgb), 0.2); }
  50% { box-shadow: 0 0 14px rgba(var(--accent-rgb), 0.4); }
}

@keyframes glow-pulse-red {
  0%, 100% { box-shadow: 0 0 8px rgba(239, 68, 68, 0.3); }
  50% { box-shadow: 0 0 16px rgba(239, 68, 68, 0.6); }
}

/* --- Build completion flash --- */
@keyframes build-complete-flash {
  0% { background: rgba(16, 185, 129, 0.3); }
  100% { background: transparent; }
}

.build-complete-flash {
  animation: build-complete-flash 0.6s ease-out;
}

/* --- Level up animation --- */
@keyframes level-pop {
  0% { transform: scale(1.5); color: var(--green); }
  100% { transform: scale(1); color: var(--text-secondary); }
}

.level-pop {
  animation: level-pop 0.4s ease-out;
}

/* --- Number float animation --- */
@keyframes float-up {
  0% { opacity: 1; transform: translateY(0); }
  100% { opacity: 0; transform: translateY(-30px); }
}

.float-number {
  position: absolute;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--green);
  pointer-events: none;
  animation: float-up 1.2s ease-out forwards;
}

/* --- Progress Bars - with glow and shimmer --- */
.progress-bar {
  width: 100%;
  height: 8px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 4px;
  overflow: hidden;
  position: relative;
}

.progress-fill {
  height: 100%;
  border-radius: 4px;
  position: relative;
  overflow: hidden;
  transition: none;
  background: var(--amber);
}

.progress-fill,
.dom-tracking-fill,
.dd-progress-bar,
.fields-summary-fill,
.mission-progress-fill,
.campaign-ch-progress-fill,
.campaign-progress-fill {
  position: relative;
  overflow: hidden;
  animation: progress-fill-glow 2.6s ease-in-out infinite;
}

.progress-fill.construction {
  background: linear-gradient(90deg, #d97706, var(--amber));
  box-shadow: 0 0 8px rgba(245, 158, 11, 0.4);
}

.progress-fill.downgrade {
  background: linear-gradient(90deg, #dc2626, #ef4444);
  box-shadow: 0 0 8px rgba(239, 68, 68, 0.4);
}

.progress-fill.research {
  background: linear-gradient(90deg, #7c3aed, var(--purple));
  box-shadow: 0 0 8px rgba(139, 92, 246, 0.4);
}
.progress-fill.innovation {
  background: linear-gradient(90deg, #7c3aed, var(--purple));
  box-shadow: 0 0 8px rgba(139, 92, 246, 0.5);
}
.progress-fill.trade {
  background: linear-gradient(90deg, #059669, var(--green, #10b981));
  box-shadow: 0 0 8px rgba(16, 185, 129, 0.4);
}

.progress-fill.shipyard {
  background: linear-gradient(90deg, #0891b2, var(--cyan));
  box-shadow: 0 0 8px rgba(var(--accent-rgb), 0.4);
}
.progress-fill.fleet {
  background: linear-gradient(90deg, #0369a1, #0ea5e9);
  box-shadow: 0 0 8px rgba(14, 165, 233, 0.4);
}

.progress-fill.terraform {
  background: linear-gradient(90deg, #059669, #22c55e);
  box-shadow: 0 0 8px rgba(34, 197, 94, 0.4);
}
.progress-fill.atmosphere {
  background: linear-gradient(90deg, #2563eb, #60a5fa);
  box-shadow: 0 0 8px rgba(96, 165, 250, 0.4);
}

.progress-fill.queued {
  background: linear-gradient(90deg, #d97706, var(--amber));
  box-shadow: 0 0 8px rgba(245, 158, 11, 0.4);
  opacity: 0.5;
}
.progress-fill.queued.research, .progress-fill.queued-blocked.research {
  background: linear-gradient(90deg, #7c3aed, var(--purple));
  box-shadow: 0 0 8px rgba(139, 92, 246, 0.4);
}
.progress-fill.queued-blocked {
  background: linear-gradient(90deg, #d97706, var(--amber));
  box-shadow: 0 0 8px rgba(245, 158, 11, 0.4);
  opacity: 0.5;
}
/* Textured overlays for progress bars by task type */
.progress-fill.construction::before,
.progress-fill.queued::before,
.progress-fill.queued-blocked::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background-image: url("data:image/svg+xml,%3Csvg width='6' height='6' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M0 3 L3 0 L6 3 L3 6Z' fill='rgba(0,0,0,0.15)'/%3E%3C/svg%3E");
  background-size: 6px 6px;
  pointer-events: none;
  z-index: 1;
}

.progress-fill.research::before,
.progress-fill.innovation::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background-image: url("data:image/svg+xml,%3Csvg width='8' height='8' xmlns='http://www.w3.org/2000/svg'%3E%3Crect x='0' y='3' width='8' height='1' fill='rgba(255,255,255,0.1)'/%3E%3Crect x='3' y='0' width='1' height='8' fill='rgba(255,255,255,0.08)'/%3E%3C/svg%3E");
  background-size: 8px 8px;
  pointer-events: none;
  z-index: 1;
}

.progress-fill.trade::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background-image: url("data:image/svg+xml,%3Csvg width='10' height='5' xmlns='http://www.w3.org/2000/svg'%3E%3Ccircle cx='2' cy='2' r='1' fill='rgba(255,255,255,0.12)'/%3E%3Ccircle cx='7' cy='4' r='0.8' fill='rgba(255,255,255,0.08)'/%3E%3C/svg%3E");
  background-size: 10px 5px;
  pointer-events: none;
  z-index: 1;
}

.progress-fill.shipyard::before,
.progress-fill.fleet::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background-image: url("data:image/svg+xml,%3Csvg width='8' height='4' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M0 2 L4 0 L8 2 L4 4Z' fill='rgba(255,255,255,0.1)'/%3E%3C/svg%3E");
  background-size: 8px 4px;
  pointer-events: none;
  z-index: 1;
}

.progress-fill.terraform::before,
.progress-fill.atmosphere::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background-image: url("data:image/svg+xml,%3Csvg width='12' height='12' xmlns='http://www.w3.org/2000/svg'%3E%3Ccircle cx='3' cy='3' r='2' fill='none' stroke='rgba(255,255,255,0.08)' stroke-width='0.5'/%3E%3Ccircle cx='9' cy='9' r='1.5' fill='none' stroke='rgba(255,255,255,0.06)' stroke-width='0.5'/%3E%3C/svg%3E");
  background-size: 12px 12px;
  pointer-events: none;
  z-index: 1;
}

.progress-fill.power-toggle::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background-image: url("data:image/svg+xml,%3Csvg width='6' height='6' xmlns='http://www.w3.org/2000/svg'%3E%3Cline x1='0' y1='6' x2='6' y2='0' stroke='rgba(255,255,255,0.1)' stroke-width='0.5'/%3E%3C/svg%3E");
  background-size: 6px 6px;
  pointer-events: none;
  z-index: 1;
}

.progress-fill.downgrade::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background-image: url("data:image/svg+xml,%3Csvg width='4' height='4' xmlns='http://www.w3.org/2000/svg'%3E%3Crect x='0' y='0' width='2' height='2' fill='rgba(0,0,0,0.12)'/%3E%3Crect x='2' y='2' width='2' height='2' fill='rgba(0,0,0,0.12)'/%3E%3C/svg%3E");
  background-size: 4px 4px;
  pointer-events: none;
  z-index: 1;
}

/* Shared animated sheen for progress bars */
.progress-fill::after,
.dom-tracking-fill::after,
.dd-progress-bar::after,
.fields-summary-fill::after,
.mission-progress-fill::after,
.campaign-ch-progress-fill::after,
.campaign-progress-fill::after {
  content: '';
  position: absolute;
  top: 0;
  left: -42%;
  width: 42%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(255, 255, 255, 0.08) 10%,
    rgba(255, 255, 255, 0.4) 50%,
    rgba(255, 255, 255, 0.08) 90%,
    transparent 100%
  );
  pointer-events: none;
  z-index: 2;
  animation: progress-fill-sheen 2s ease-in-out infinite;
}

@keyframes progress-fill-glow {
  0%, 100% {
    filter: saturate(1) brightness(1);
  }
  50% {
    filter: saturate(1.08) brightness(1.12);
  }
}

@keyframes progress-fill-sheen {
  from {
    transform: translateX(0);
  }
  to {
    transform: translateX(340%);
  }
}

@keyframes progress-texture-scroll {
  from { background-position: 0 0; }
  to   { background-position: 120px 0; }
}

.progress-fill.construction::before,
.progress-fill.queued::before,
.progress-fill.queued-blocked::before,
.progress-fill.research::before,
.progress-fill.innovation::before,
.progress-fill.trade::before,
.progress-fill.shipyard::before,
.progress-fill.fleet::before,
.progress-fill.terraform::before,
.progress-fill.atmosphere::before,
.progress-fill.power-toggle::before,
.progress-fill.downgrade::before {
  animation: progress-texture-scroll 4s linear infinite;
}

/* --- Language Switcher --- */
.lang-switcher {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-right: 4px;
}

.lang-switcher-login {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 10;
  opacity: 0;
  animation: login-fade-in 1.5s ease-out 2.5s forwards;
}

.lang-option {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-dim);
  text-decoration: none;
  padding: 4px 6px;
  border-radius: 4px;
  transition: color 0.15s, background 0.15s;
  letter-spacing: 0.05em;
  cursor: pointer;
  line-height: 1;
}

.lang-option:hover {
  color: var(--text-secondary);
  text-decoration: none;
}

.lang-option.active {
  color: var(--cyan);
  background: rgba(var(--accent-rgb), 0.1);
}

.lang-sep {
  color: var(--text-dim);
  font-size: 0.65rem;
  opacity: 0.5;
  user-select: none;
}

/* Native pinch zoom in progress or held: quiet everything that multiplies
   WebKit's re-raster cost at zoom scale (animations, transitions, backdrop
   blurs, card blend overlays). kc-core.js toggles the class from
   visualViewport.scale. */
html.kc-pinch-zoom *,
html.kc-pinch-zoom *::before,
html.kc-pinch-zoom *::after {
  animation-play-state: paused !important;
  transition: none !important;
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
}
html.kc-pinch-zoom .building-card::after {
  mix-blend-mode: normal;
  opacity: 0.2;
}

/* ─── Living highlight (shared selection/focus language) ──
   One selection language app-wide: a soft outer glow that breathes gently
   (opacity-only pulse, compositor-friendly, no per-frame repaint since the
   box-shadow itself is static). Pauses while the tab is hidden,
   reduced-motion keeps a static glow (shape + color cue, never a
   color-only tell). Color per context via --kc-ring-color. Elements whose
   ::after is taken (cards) get the same glow from a .kc-live-ring-el child
   overlay instead. */
.kc-live-ring { position: relative; }
/* App-wide selected states share the one living-ring language. Hosts keep
   their existing tinted background as the base (and as the fallback when the
   ring cannot render). */
.e2scope .brow.sel,
.brow.sel,
.map-bridge-browse-row.is-selected,
.map-bridge-browse-tile.is-selected,
.map-gg-row.is-selected,
.map-cell-body-row.is-selected,
.map-fleet-ship-target.is-selected,
.kc-layout-desktop3 .kc-d3-colony-card.is-active,
.kc-layout-desktop3 .kc-d3-fleet-card.is-active,
.kc-batch-pill.selected {
  position: relative;
  --kc-ring-color: rgba(var(--accent-rgb, 34, 211, 238), 0.9);
}
.e2scope .brow.sel,
.brow.sel { border-radius: 8px; }
.kc-live-ring::after,
.e2scope .brow.sel::after,
.brow.sel::after,
.map-bridge-browse-row.is-selected::after,
.map-bridge-browse-tile.is-selected::after,
.map-gg-row.is-selected::after,
.map-cell-body-row.is-selected::after,
.map-fleet-ship-target.is-selected::after,
.kc-layout-desktop3 .kc-d3-colony-card.is-active::after,
.kc-layout-desktop3 .kc-d3-fleet-card.is-active::after,
.kc-batch-pill.selected::after,
.kc-live-ring-el {
  content: '';
  position: absolute;
  inset: -2px;
  border-radius: inherit;
  pointer-events: none;
  z-index: 7;
  box-shadow: 0 0 0 1px var(--kc-ring-color, var(--cyan, #22d3ee)),
    0 0 9px 1px var(--kc-ring-color, var(--cyan, #22d3ee));
  opacity: 0.45;
  animation: kc-live-glow-pulse 2s ease-in-out infinite;
  /* Hidden tab freezes the pulse (house battery mechanism, app.js sets
     --anim-state on visibilitychange); reduced-motion keeps a static glow
     below (no pulse, box-shadow itself never animates so this stays
     compositor-only: opacity is the sole animated property). */
  animation-play-state: var(--anim-state, running);
}
@keyframes kc-live-glow-pulse { 0%, 100% { opacity: 0.3; } 50% { opacity: 0.68; } }
@media (prefers-reduced-motion: reduce) {
  .kc-live-ring::after,
  .e2scope .brow.sel::after,
  .brow.sel::after,
  .map-bridge-browse-row.is-selected::after,
  .map-bridge-browse-tile.is-selected::after,
  .map-gg-row.is-selected::after,
  .map-cell-body-row.is-selected::after,
  .map-fleet-ship-target.is-selected::after,
  .kc-layout-desktop3 .kc-d3-colony-card.is-active::after,
  .kc-layout-desktop3 .kc-d3-fleet-card.is-active::after,
  .kc-batch-pill.selected::after,
  .kc-live-ring-el {
    animation: none;
    opacity: 0.5;
  }
}
