/* Estilos base del juego. Simples a proposito, sin framework CSS. */

/* Tamanos reales de los assets fuente, ver docs/image_inventory.xlsx
   (generado por scripts/generate_image_inventory_xlsx.py) -- todo el arte
   por categoria es cuadrado y uniforme salvo banners. Los tamanos de
   despliegue de abajo son fracciones limpias de estos, a proposito: cuando
   se reemplace el placeholder por arte final del mismo tamano de origen,
   nada de esto necesita tocarse. */
:root {
  --bg: #ddc48c;
  --panel: #f1e2b8;
  --panel-alt: #e6d19f;
  --border: #6b4423;
  --accent: #b8862e;
  --accent-bright: #c9a24b;
  --text: #4a2c14;
  --text-muted: #7a5230;
  --divider: #a13a2a;
  --error: #8b1a1a;
  --ink-on-accent: #2b1a0a;
  --icon-src-building: 256px;
  --icon-src-unit: 128px;
  --icon-src-resource: 64px;
  --bronze: #8a6a3a;
  font-family: system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

h1, h2, h3 {
  font-family: Georgia, "Times New Roman", serif;
}

button {
  cursor: pointer;
  background: var(--accent);
  color: var(--ink-on-accent);
  border: none;
  border-radius: 4px;
  padding: 0.4rem 0.8rem;
  font-weight: 600;
}

input, select {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.3rem;
}

label {
  display: block;
  margin: 0.4rem 0;
}

.error {
  color: var(--error);
  font-weight: 600;
}

/* --- Loading overlay: primer hijo de <body>, visible por defecto desde el
   HTML server-rendered (sin esperar a que corra JS) para eliminar el flash
   de shell vacio entre login y que la ciudad/mundo terminen de cargar. --- */

.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  background: var(--bg);
  color: var(--text);
}

.loading-overlay[hidden] {
  display: none;
}

.spinner {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 4px solid var(--border);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}

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

/* --- Nav / shell --- */

.topnav {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.6rem 1rem;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

.brand {
  font-weight: 700;
  font-size: 1.2rem;
  color: var(--accent);
}

.tabs {
  display: flex;
  gap: 0.4rem;
  flex: 1;
}

.tab-link {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}

.tab-link.active {
  background: var(--accent);
  color: var(--ink-on-accent);
}

.logout {
  background: var(--error);
  color: white;
}

.content {
  padding: 1rem;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

/* --- World picker --- */

#world-list {
  list-style: none;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

/* --- City view --- */

.resource-bar {
  display: flex;
  gap: 0.8rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.resource-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  background: var(--panel);
  border: 1px solid var(--accent);
  border-radius: 4px;
  padding: 0.2rem 0.6rem;
  font-variant-numeric: tabular-nums;
  box-shadow: 0 0 4px rgba(201, 162, 75, 0.35);
}

/* Fuente 64x64 (--icon-src-resource), desplegado a 1/4 -- misma relacion
   de escala que building/unit mas abajo, por consistencia visual. */
.resource-pill img {
  width: calc(var(--icon-src-resource) / 4);
  height: calc(var(--icon-src-resource) / 4);
}

/* --- Vista de ciudad: una unica imagen de fondo fija (no una textura que
   se repite, ver app/core/city_layout.py), con edificios superpuestos en
   posiciones absolutas (%) sobre ella. --- */

.city-scene {
  position: relative;
  width: 100%;
  aspect-ratio: 3000 / 1408;
  background-image: url("/static/assets/img/backgrounds/city_ground.png");
  background-size: cover;
  background-position: center;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}

#city-slots {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
}

#city-slots .city-slot {
  pointer-events: auto;
}

/* Panel de construccion: anclado junto al slot clickeado (no un dialogo
   modal separado) -- iconos reales en vez de un <select> de texto, click
   directo construye al instante para que se sienta mas fluido/inmediato. */
.build-panel {
  position: absolute;
  z-index: 3;
  transform: translate(-50%, -50%);
  max-width: min(90%, 320px);
  background: rgba(241, 226, 184, 0.97);
  border: 1px solid var(--accent);
  border-radius: 6px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.6);
  padding: 0.5rem;
}

.build-panel[hidden] {
  display: none;
}

.build-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.4rem;
  color: var(--accent);
  font-weight: 600;
  font-size: 0.85rem;
}

.build-panel-close {
  background: transparent;
  color: var(--text);
  padding: 0 0.3rem;
  font-size: 1rem;
  line-height: 1;
}

.build-panel-options {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  max-height: 220px;
  overflow-y: auto;
}

.build-option {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
  width: 64px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.3rem;
  font-weight: 400;
  font-size: 0.6rem;
  color: var(--text);
  text-align: center;
  line-height: 1.1;
}

.build-option:hover {
  border-color: var(--accent);
  background: var(--panel-alt);
}

.build-option img {
  width: 32px;
  height: 32px;
  object-fit: contain;
}

.build-option span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

.city-slot {
  position: absolute;
  transform: translate(-50%, -50%);
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
}

.city-slot img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 1px 3px rgba(0, 0, 0, 0.7));
}

.city-slot.empty {
  background: rgba(42, 32, 26, 0.55);
  border: 1px dashed var(--accent);
  color: var(--accent);
  font-size: 1rem;
  line-height: 1;
}

.city-slot.landmark.empty {
  border-width: 2px;
  font-size: 1.4rem;
}

.city-slot.tower.empty {
  border-color: var(--bronze);
  color: var(--bronze);
}

/* Con ~110 slots libres en pantalla a la vez, un marcador mas liviano que
   el de torre/landmark evita que la plaza se vea sobrecargada. */
.city-slot.free.empty {
  background: rgba(42, 32, 26, 0.25);
  border: 1px dashed rgba(201, 162, 75, 0.55);
  font-size: 0.7rem;
}

.city-slot.free.empty:hover {
  background: rgba(42, 32, 26, 0.6);
  border-color: var(--accent);
}

.city-slot.occupied.under-construction img {
  opacity: 0.6;
}

.level-badge {
  position: absolute;
  bottom: -2px;
  right: -2px;
  background: rgba(0, 0, 0, 0.75);
  font-size: 0.6rem;
  padding: 0 3px;
  border-radius: 3px;
  pointer-events: none;
}

dialog {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.5);
}

.dialog-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.6rem;
}

.building-detail-level {
  font-variant-numeric: tabular-nums;
  color: var(--accent);
}

.building-detail-notes {
  font-style: italic;
  color: var(--text-muted);
  max-width: 280px;
}

.building-detail-countdown {
  font-family: monospace;
  color: var(--accent);
}

/* --- Army view --- */

.unit-list {
  list-style: none;
  padding: 0;
}

.unit-list li {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.2rem 0;
}

/* Fuente 128x128 (--icon-src-unit), desplegado a 1/4. */
.unit-list img {
  width: calc(var(--icon-src-unit) / 4);
  height: calc(var(--icon-src-unit) / 4);
}

.dispatch-unit-row {
  display: flex;
  gap: 0.4rem;
  margin-bottom: 0.3rem;
}

/* --- Auth page --- */

.auth-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

.auth-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 2rem;
  width: 320px;
}

.auth-card h1 {
  color: var(--accent);
  text-align: center;
}

/* --- Header: panel de ciudad (izquierda) + ministros (derecha) --- */

.topnav-left {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  flex-wrap: wrap;
}

.topnav-city-name {
  margin: 0;
  font-size: 1rem;
  color: var(--text);
}

.topnav .resource-bar {
  margin-bottom: 0;
}

.topnav-right {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

/* --- Tooltip compartido (static/js/ui.js) --- */

.ui-tooltip {
  position: fixed;
  z-index: 10000;
  max-width: 280px;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.5rem 0.6rem;
  font-size: 0.75rem;
  line-height: 1.35;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
  pointer-events: none;
}

.ui-tooltip[hidden] {
  display: none;
}

.ui-tooltip h4 {
  margin: 0 0 0.3rem;
  color: var(--accent);
  font-size: 0.85rem;
  border-bottom: 1px solid var(--divider);
  padding-bottom: 0.2rem;
}

.ui-tooltip p {
  margin: 0 0 0.3rem;
}

.ui-tooltip-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
}

.ui-tooltip-row img {
  width: 16px;
  height: 16px;
  vertical-align: middle;
  margin-right: 0.2rem;
}

.ui-tooltip-loading {
  opacity: 0.7;
  font-style: italic;
}

/* Linea roja separadora, reusable dentro de tooltips/dialogos. */
.section-divider {
  border: none;
  border-bottom: 2px solid var(--divider);
  margin: 0.4rem 0;
}

/* --- Widget de ministros (arriba a la derecha) --- */

.ministers-widget {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.minister-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 2px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 50%;
}

.minister-icon.active {
  border-color: var(--accent);
  box-shadow: 0 0 4px rgba(184, 134, 46, 0.6);
}

.minister-icon img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: 50%;
}

/* --- Modal de detalle de edificio: estadisticas --- */

.building-detail-stats {
  font-size: 0.85rem;
  margin: 0.4rem 0;
}

.building-detail-stats .ui-tooltip-row {
  padding: 0.1rem 0;
}

/* --- Submenu de reclutamiento --- */

.recruitment-unit-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-height: 420px;
  overflow-y: auto;
}

.recruitment-unit-row {
  display: flex;
  gap: 0.6rem;
  padding: 0.5rem;
  background: var(--panel-alt);
  border: 1px solid var(--border);
  border-radius: 6px;
}

.recruitment-unit-row img {
  width: calc(var(--icon-src-unit) / 4);
  height: calc(var(--icon-src-unit) / 4);
  flex-shrink: 0;
}

.recruitment-unit-body {
  flex: 1;
  min-width: 0;
}

.recruitment-unit-body h4 {
  margin: 0 0 0.2rem;
  color: var(--accent);
}

.recruitment-unit-description {
  font-style: italic;
  color: var(--text-muted);
  font-size: 0.8rem;
  margin: 0 0 0.3rem;
}

.recruitment-unit-costs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  font-size: 0.75rem;
  margin-bottom: 0.3rem;
}

.recruitment-unit-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.recruitment-unit-actions input[type="number"] {
  width: 4.5rem;
}
