:root {
  --bg-base: #0f1115;
  --bg-surface: #1a1d24;
  --bg-surface-hover: #242830;
  --border-color: #2a2e38;
  --text-main: #e2e8f0;
  --text-muted: #94a3b8;
  --accent: #3b82f6;
  --danger: #ef4444;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background-color: var(--bg-base);
  color: var(--text-main);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.5;
}

/* Shared Resets */
.btn-step,
.btn-remove,
.modal-close {
  background: transparent;
  border: none;
  cursor: pointer;
}

/* Header & Controls */
.top-nav {
  background-color: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  padding: 15px 30px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 20px;
}

.brand {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: 2px;
}

.brand-logo {
  max-height: 35px;
  width: auto;
  object-fit: contain;
}

.global-controls {
  display: flex;
  gap: 20px;
  align-items: center;
  flex-wrap: wrap;
}

.control-group {
  display: flex;
  flex-direction: column;
}

.control-group label {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 4px;
  text-transform: uppercase;
}

.control-group input[type="number"],
.control-group select {
  background-color: var(--bg-base);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 6px 10px;
  border-radius: 4px;
  font-size: 0.9rem;
}

/* Main Layout Grid */
.app-container {
  display: grid;
  grid-template-columns: 1fr 380px;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 30px;
  padding: 30px;
  max-width: 1600px;
  margin: 0 auto;
  height: calc(100vh - 85px);
}

.builder-controls-bar {
  grid-column: 1 / -1;
  justify-self: center; /* Shrinks the width to fit the content tightly */
  margin-top: -10px; /* Pulls it up slightly to reduce the top gap */
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 15px 30px;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  gap: 40px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  z-index: 10;
}

.override-group {
  justify-content: center;
  height: 100%;
  margin-top: 18px;
}
.override-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  text-transform: none !important;
  font-size: 0.95rem !important;
  color: var(--text-main) !important;
}

.panel-title {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 1.2rem;
  color: var(--text-main);
  border-bottom: 2px solid var(--border-color);
  padding-bottom: 10px;
  margin-bottom: 15px;
  text-transform: uppercase;
}

.title-icon {
  width: 28px;
  height: 28px;
  object-fit: contain;
}

/* Left Column: Roster */
.roster-panel {
  min-width: 0;
  overflow-y: auto;
  padding-right: 15px;
}

.roster-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 15px 20px;
  margin-bottom: 10px;
  transition: background-color 0.2s ease;
}

.roster-row:hover {
  background-color: var(--bg-surface-hover);
}

.roster-row.illegal {
  border-color: var(--danger);
  box-shadow: inset 4px 0 0 var(--danger);
}

.row-info {
  flex: 1;
}

.unit-name {
  font-size: 1.1rem;
  font-weight: 600;
}

.unit-type {
  font-size: 0.85rem;
  color: var(--accent);
  margin-bottom: 4px;
}

.unit-stats {
  font-size: 0.9rem;
  color: var(--text-main);
  background-color: var(--bg-base);
  padding: 4px 8px;
  border-radius: 4px;
  display: inline-block;
  margin-bottom: 4px;
}

.unit-keywords {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.row-controls {
  display: flex;
  align-items: center;
  gap: 30px;
}

.cost-limit {
  display: flex;
  flex-direction: column;
  text-align: right;
}

.cost {
  font-weight: bold;
  font-size: 1.1rem;
}

.limit {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.stepper {
  display: flex;
  align-items: center;
  background-color: var(--bg-base);
  border: 1px solid var(--border-color);
  border-radius: 4px;
}

.btn-step {
  color: var(--text-main);
  padding: 8px 15px;
  font-size: 1.2rem;
}

.btn-step:disabled {
  color: var(--text-muted);
  cursor: not-allowed;
}

.stepper .qty {
  padding: 0 15px;
  font-weight: bold;
  min-width: 40px;
  text-align: center;
}

/* Right Column: Manifest */
.sticky-wrapper {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 20px;
}

.manifest-item {
  border-bottom: 1px solid var(--border-color);
  padding: 10px 0;
}

.manifest-panel {
  overflow-y: auto;
  padding-right: 10px;
}

.manifest-item:last-child,
.kw-entry:last-child {
  border-bottom: none;
}

.manifest-details {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.manifest-footer,
.export-section {
  margin-top: 20px;
  padding-top: 15px;
  border-top: 2px solid var(--border-color);
}

.totals-row {
  display: flex;
  justify-content: space-between;
  font-size: 1.1rem;
  font-weight: bold;
  margin-bottom: 5px;
}

.total-value.over-limit {
  color: var(--danger);
}

@media (max-width: 992px) {
  .app-container {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto; /* Allow natural flow */
    height: auto;
  }

  .roster-panel,
  .manifest-panel {
    overflow-y: visible;
    padding-right: 0;
  }

  .sticky-wrapper {
    position: static;
  }

  .builder-controls-bar {
    position: sticky;
    top: 0;
    z-index: 100;
    padding: 15px;
    gap: 15px;
    justify-self: stretch; /* Forces it back to full width on mobile */
  }
}

.export-controls,
.export-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.export-grid {
  margin-bottom: 10px;
}

.export-title {
  font-size: 0.9rem;
  color: var(--text-muted);
  text-transform: uppercase;
  margin-bottom: 10px;
}

.btn-export {
  background-color: var(--bg-surface-hover);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 8px;
  border-radius: 4px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-export:hover {
  background-color: var(--accent);
  border-color: var(--accent);
}

/* Clear Army Button */
.btn-clear {
  width: 100%;
  margin-top: 15px;
  background-color: transparent;
  border: 1px solid var(--danger);
  color: var(--danger);
  padding: 8px;
  border-radius: 4px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-clear:hover {
  background-color: var(--danger);
  color: white;
}

/* Manifest Item Header Layout */
.manifest-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 600;
  margin-bottom: 4px;
}

.manifest-title {
  flex: 1;
  display: flex;
  justify-content: space-between;
  margin-right: 15px;
}

.btn-remove {
  color: var(--text-muted);
  font-size: 1.2rem;
  line-height: 1;
  padding: 0 5px;
}

.btn-remove:hover {
  color: var(--danger);
}

/* Home Screen Layout */
.home-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 60px 20px;
  max-width: 1200px;
  margin: 0 auto;
}

.home-title {
  font-size: 2.5rem;
  margin-bottom: 50px;
  letter-spacing: 1px;
}

.faction-group-title {
  color: var(--text-muted);
  text-transform: uppercase;
  font-size: 1.1rem;
  letter-spacing: 2px;
  margin-bottom: 25px;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 5px;
  width: 100%;
  text-align: center;
}

.factions-grid {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 20px;
}

/* Major Faction Icon Cards */
.major-grid {
  gap: 30px;
}

.faction-card {
  background-color: var(--bg-surface);
  border: 2px solid var(--border-color);
  border-radius: 12px;
  padding: 30px 20px;
  width: 200px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.faction-card:hover {
  border-color: var(--accent);
  transform: translateY(-5px);
  background-color: var(--bg-surface-hover);
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2);
}

.faction-icon {
  width: 100px;
  height: 100px;
  margin-bottom: 20px;
  object-fit: contain;
}

.faction-card-name {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-main);
}

/* Minor Faction Text Buttons */
.minor-btn {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 12px 24px;
  border-radius: 6px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.minor-btn:hover {
  background-color: var(--accent);
  border-color: var(--accent);
  color: white;
}

/* Header Navigation Links */
.nav-links {
  display: flex;
  gap: 15px;
  align-items: center;
  margin-left: auto; /* Pushes the links to the far right of the header */
}

.nav-btn {
  padding: 6px 16px;
  background-color: var(--bg-surface);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 600;
  transition: all 0.15s ease-in-out;
}

.nav-btn:hover {
  background-color: var(--bg-surface-hover);
  border-color: var(--accent);
}

.nav-btn.donate-btn {
  background-color: #ffdd00;
  color: #000000;
  border-color: #ffdd00;
}

.nav-btn.donate-btn:hover {
  background-color: #ffea00;
  border-color: #ffea00;
}

.export-container {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 20px;
}

.print-btn {
  width: 100%;
}

.btn-export.btn-success {
  background-color: #28a745;
  color: white;
  border-color: #28a745;
}

.nav-btn.architect-btn:hover {
  background-color: #27ae60; /* Matches the 'Generate' button green */
  border-color: #27ae60;
  color: white;
}

/* Modal Stacking Context */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background-color: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(4px);
  z-index: 9999; /* Ensures it sits above sticky headers */
  display: flex;
  justify-content: center;
  align-items: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease-in-out;
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.modal-content {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  width: 90%;
  max-width: 600px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4);
  transform: translateY(20px);
  transition: transform 0.3s ease-out;
}

.modal-overlay.active .modal-content {
  transform: translateY(0);
}

.modal-header {
  padding: 20px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-close {
  color: var(--text-muted);
  font-size: 2rem;
}

.modal-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
}

/* Internal Keyword Styling */
.kw-entry {
  margin-bottom: 20px;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 15px;
}

.kw-name {
  color: var(--accent);
  font-weight: bold;
  font-size: 1.1rem;
  margin-bottom: 5px;
  display: block;
}

.kw-desc {
  font-size: 0.95rem;
  color: var(--text-main);
  line-height: 1.4;
}

/* --- Mission Modal Split Panel --- */
.mission-modal-content {
  max-width: 1400px; /* Increased from 900px */
  width: 95vw; /* Fill 95% of the screen width */
  height: 90vh; /* Fill 90% of the screen height */
  display: flex;
  flex-direction: column;
}

.modal-split-body {
  display: flex;
  gap: 30px;
  padding: 20px;
  flex: 1; /* Grow to fill the modal height */
  overflow: hidden; /* Keep the main container clean */
}

.modal-list-side {
  flex: 0 0 400px; /* Keep the list at a readable fixed width */
  overflow-y: auto;
  height: 100%; /* Fill the new modal height */
  padding-right: 15px;
}

/* --- Mission Modal Right Panel --- */
.modal-preview-side {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: flex-start; /* Ensures everything aligns left */
  justify-content: flex-start; /* Forces content to anchor to the top */
  background-color: rgba(0, 0, 0, 0.2);
  border-radius: 8px;
  padding: 20px;
  overflow-y: auto; /* Allows vertical scrolling */
  position: relative;
}

/* Toggle Button & Header */
.mission-preview-header {
  display: flex;
  justify-content: flex-end; /* Pushes button to top right */
  width: 100%;
  margin-bottom: 15px;
}

.btn-toggle-view {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 6px 12px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: bold;
  transition: all 0.2s;
}

.btn-toggle-view:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* Text View Deployment Map */
.deployment-map-img {
  width: 100%;
  max-width: 576px; /* Adheres to your requested dimensions */
  height: auto;
  margin-top: 20px;
  border: 2px solid var(--border-color);
  border-radius: 8px;
  align-self: center;
}

/* Card View Image */
.mission-card-img {
  width: 100%;
  max-width: 450px; /* Prevents the card from becoming gigantic on large screens */
  height: auto;
  aspect-ratio: 3.5 / 5;
  object-fit: contain;
  border-radius: 12px;
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.5);
  border: 1px solid var(--border-color);
}

/* Card View Placeholder */
.mission-card-placeholder {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  width: 100%;
  min-height: 400px;
  background-color: var(--bg-base);
  border: 2px dashed var(--border-color);
  border-radius: 12px;
  color: var(--text-muted);
  text-align: center;
  padding: 40px;
}

.placeholder-content {
  max-width: 320px;
}
.placeholder-icon {
  font-size: 4rem;
  margin-bottom: 20px;
  display: block;
  opacity: 0.4;
}
.mission-card-placeholder h3 {
  color: var(--text-main);
  margin-bottom: 12px;
  text-transform: uppercase;
  font-size: 1.2rem;
}
.mission-card-placeholder p {
  font-size: 0.95rem;
  line-height: 1.6;
  margin: 0;
}
