/*==============================================================================
 * PAGE_04_LOADOUT.CSS - RESPONSIVE LOADOUT & DECK BUILDER PAGE STYLES
 * Scaled fluidly based on #game-wrapper container query dimensions (cqw / cqh)
 *==============================================================================
 * TABLE OF CONTENTS:
 * -----------------------------------------------------------------------------
 *   1. Modal Overlay & Backdrop Controls
 *   2. Main Modal Container
 *   3. Header & Player Name Input
 *   4. Section Shells & Header Metadata
 *   5. Grid Layouts & Scroll Containers
 *   6. Unit Card Component & Interactive States
 *   7. Footer Action Bar & Action Buttons
 *==============================================================================*/


/*==============================================================================
 * SECTION 1: MODAL OVERLAY & BACKDROP CONTROLS
 *==============================================================================*/

/* Full-viewport absolute overlay positioning using container query height (cqh) & width (cqw) padding */
.loadout-modal-overlay {
  position: absolute;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5cqh 2cqw;
  box-sizing: border-box;
}

/* Modal hidden state overrides to cleanly remove element from render tree & pointer events */
.loadout-modal-overlay.hidden,
.loadout-modal-overlay[hidden] {
  display: none !important;
  opacity: 0;
  pointer-events: none;
}

/* Background Blur Strategy: visually blurs background containers when marked inert */
.menu-container[inert],
.initscreen-container[inert],
.play-modal-overlay[inert] {
  pointer-events: none !important;
  user-select: none !important;
  filter: blur(1.5px);
  transition: filter 0.2s ease-in-out;
}

/* Transparent backdrop positioning layer behind main modal card */
.loadout-modal-backdrop {
  position: absolute;
  inset: 0;
  background-color: transparent;
  backdrop-filter: none;
}


/*==============================================================================
 * SECTION 2: MAIN MODAL CONTAINER
 *==============================================================================*/

/* Card Container - Anchored layout using container query units (cqw/cqh) for responsive scaling */
.loadout-card {
  position: relative;
  z-index: 101;
  width: 96%;
  max-width: 96cqw;
  height: 96%;
  max-height: 96cqh;
  background-color: #120a06;
  border: 0.4cqw solid var(--border-gold, #c89d38);
  border-radius: 1.8cqw;
  padding: 1.8cqh 2.2cqw;
  box-shadow: 0 1.5cqh 4cqh rgba(0, 0, 0, 0.9), 0 0 2.2cqh rgba(200, 157, 56, 0.25);
  display: flex;
  flex-direction: column;
  gap: 1cqh;
  overflow: hidden;
  box-sizing: border-box;
}


/*==============================================================================
 * SECTION 3: HEADER & PLAYER NAME INPUT
 *==============================================================================*/

/* Modal header container for player name input section */
.loadout-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4cqh;
  flex-shrink: 0;
}

/* Uppercase typography label for the loadout/player header */
.loadout-label {
  font-family: 'Cinzel', serif;
  font-size: 2.4cqw;
  font-weight: 700;
  color: var(--text-gold, #e2b755);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  white-space: nowrap;
}

/* Player name input field with fluid cqw/cqh dimensions */
.loadout-input {
  width: 100%;
  max-width: 78cqw;
  background-color: #0b0604;
  border: 0.25cqw solid var(--border-gold, #c89d38);
  border-radius: 1cqw;
  padding: 0.8cqh 1.8cqw;
  color: #ffffff;
  font-family: 'Cinzel', serif;
  font-weight: 700;
  font-size: 3cqw;
  text-align: center;
  outline: none;
  box-shadow: inset 0 0.2cqh 0.4cqh rgba(0, 0, 0, 0.8);
}

/* Glow highlight on input focus state */
.loadout-input:focus {
  border-color: var(--border-gold-light, #f3d078);
  box-shadow: 0 0 1.2cqw rgba(243, 208, 120, 0.4);
}


/*==============================================================================
 * SECTION 4: SECTION SHELLS & HEADER METADATA
 *==============================================================================*/

/* Base section wrapper shell */
.loadout-section {
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  width: 100%;
}

/* Dynamic flex sizing: :has() pseudo-selector expands section housing #unit-pool-grid to fill available vertical space */
.loadout-section:has(#unit-pool-grid) {
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

/* Flexbox header container for section titles and metadata counter/hints */
.loadout-section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.4cqh;
  padding: 0 0.2cqw;
  flex-shrink: 0;
  white-space: nowrap;
  gap: 0.3cqw;
}

/* Section title text style */
.loadout-section-title {
  font-family: 'Cinzel', serif;
  font-size: 2.3cqw;
  font-weight: 700;
  color: var(--text-gold, #e2b755);
  letter-spacing: 0.03em;
  text-transform: uppercase;
  white-space: nowrap;
}

/* Deck unit counter display */
.loadout-deck-count {
  font-family: 'Inter', sans-serif;
  font-size: 2.4cqw;
  font-weight: 700;
  color: var(--text-gold, #e2b755);
  white-space: nowrap;
}

/* Instructional hint label in header */
.loadout-hint {
  font-size: 1.9cqw;
  color: rgba(255, 255, 255, 0.75);
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 0.4cqw;
  white-space: nowrap;
  flex-shrink: 0;
}

/* Circular question mark icon badge inside hint text */
.hint-question {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 3.2cqw;
  height: 3.2cqw;
  border-radius: 50%;
  background: #c0392b;
  color: #fff;
  font-size: 2cqw;
  font-weight: 900;
  flex-shrink: 0;
}


/*==============================================================================
 * SECTION 5: GRID LAYOUTS & SCROLL CONTAINERS
 *==============================================================================*/

/* Strict 4 Equal Columns Grid with Non-Collapsing Track Heights */
.loadout-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-auto-rows: max-content;
  column-gap: 1.2cqw;
  row-gap: 1cqh;
  width: 100%;
  box-sizing: border-box;
}

/* Active Deck Grid Container */
#active-deck-grid {
  flex-shrink: 0;
}

/* Unit Pool Grid Vertical Scroll Configuration: flex-grow fills space with smooth scrolling */
#unit-pool-grid {
  flex: 1 1 auto;
  min-height: 0;
  max-height: none;
  overflow-y: auto;
  overflow-x: hidden;
  padding-right: 0.4cqw;
  padding-bottom: 0.5cqh;
  scroll-behavior: smooth;
}

/* Custom WebKit Scrollbar Styling for Unit Pool Grid */
#unit-pool-grid::-webkit-scrollbar {
  width: 1cqw;
}

#unit-pool-grid::-webkit-scrollbar-track {
  background: rgba(18, 10, 6, 0.6);
  border-radius: 0.5cqw;
}

#unit-pool-grid::-webkit-scrollbar-thumb {
  background: #7d5b22;
  border-radius: 0.5cqw;
}

#unit-pool-grid::-webkit-scrollbar-thumb:hover {
  background: #c89d38;
}


/*==============================================================================
 * SECTION 6: UNIT CARD COMPONENT & INTERACTIVE STATES
 *==============================================================================*/

/* Unit Card Slot Base Container */
.unit-card-slot {
  position: relative;
  background: linear-gradient(180deg, #1f130b 0%, #150b06 100%);
  border: 0.25cqw solid rgba(200, 157, 56, 0.4);
  border-radius: 1.2cqw;
  padding: 0.8cqh 0.4cqw 0.6cqh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  user-select: none;
  transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease;
  aspect-ratio: 1 / 1.05;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  overflow: hidden;
}

/* Hover state lift & gold border highlight */
.unit-card-slot:hover {
  border-color: var(--border-gold-light, #f3d078);
  transform: translateY(-1px);
}

/* Fluid Responsive Card Icon */
.unit-card-icon {
  font-size: 4.8cqw;
  line-height: 1;
  margin-bottom: 0.4cqh;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Fluid Responsive Text Name with truncation */
.unit-card-name {
  font-size: 2.2cqw;
  font-weight: 700;
  line-height: 1.2;
  color: var(--text-gold, #e2b755);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  width: 100%;
  padding: 0 0.2cqw;
  box-sizing: border-box;
}

/* Unit Info Button (?) in upper-right corner */
.unit-info-btn {
  position: absolute;
  top: 0.4cqw;
  right: 0.4cqw;
  width: 4.16cqw;
  height: 4.16cqw;
  border-radius: 50%;
  background: radial-gradient(circle, #e74c3c 0%, #902b1e 100%);
  border: 0.26cqw solid #f3d078;
  color: #ffffff;
  font-size: 2.34cqw;
  font-weight: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  cursor: pointer;
  z-index: 3;
  box-shadow: 0 0.2cqh 0.4cqh rgba(0, 0, 0, 0.6);
}

.unit-info-btn:hover {
  transform: scale(1.15);
  filter: brightness(1.2);
}

/* Conditional Selection State: Selected Slot for Replacement */
.unit-card-slot.is-selected {
  border: 0.4cqw solid #f3d078;
  box-shadow: 0 0 1.5cqw rgba(243, 208, 120, 0.8), inset 0 0 0.8cqw rgba(243, 208, 120, 0.3);
}

/* Badge shown on top-left of selected unit card slot */
.replace-badge {
  position: absolute;
  top: 0.4cqw;
  left: 0.4cqw;
  background-color: #f3d078;
  color: #120a06;
  font-size: 1.5cqw;
  font-weight: 900;
  padding: 0.2cqh 0.6cqw;
  border-radius: 0.4cqw;
  letter-spacing: 0.02em;
  line-height: 1;
  z-index: 2;
  max-width: calc(100% - 5cqw);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Conditional Selection State: Equipped State (Pool cards active in deck) */
.unit-card-slot.is-equipped {
  opacity: 0.35;
  filter: grayscale(30%);
  cursor: default;
}


/*==============================================================================
 * SECTION 7: FOOTER ACTION BAR & ACTION BUTTONS
 *==============================================================================*/

/* Footer Action Bar Layout */
.loadout-actions-bar {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.2cqw;
  margin-top: auto;
  padding-top: 1.2cqh;
  border-top: 1px solid rgba(200, 157, 56, 0.25);
  box-sizing: border-box;
  flex-shrink: 0;
}

/* Switch Loadout Button */
#btn-loadout-switch {
  grid-column: 1 / -1;
  order: 1;
  width: 100%;
  height: 5cqh;
  font-size: 2.5cqw;
}

/* Primary Button (Save & Close) - `#btn-loadout-randomize` removed to prevent primary style override conflicts */
#btn-loadout-save,
#btn-loadout-randomize,
.btn-loadout-primary {
  grid-column: 1;
  order: 2;
  width: 100%;
  height: 4.8cqh;
  background: linear-gradient(180deg, #c89d38 0%, #8c6a28 100%);
  border: 0.25cqw solid #f3d078;
  border-radius: 1cqw;
  color: #1a0f0a;
  font-family: 'Cinzel', serif;
  font-size: 2.5cqw;
  font-weight: 700;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: all 0.2s ease-in-out;
  text-align: center;
}

.btn-loadout-primary:hover {
  background: linear-gradient(180deg, #f3d078 0%, #a88238 100%);
  box-shadow: 0 0 1.5cqw rgba(243, 208, 120, 0.4);
  transform: translateY(-1px);
}

/* Secondary Action Buttons (Randomize) */
.btn-loadout-secondary {
  height: 4.8cqh;
  background: linear-gradient(180deg, #2a1910 0%, #160d08 100%);
  border: 0.25cqw solid #7d5b22;
  border-radius: 1cqw;
  color: #e2b755;
  font-family: 'Cinzel', serif;
  font-size: 2.4cqw;
  font-weight: 700;
  letter-spacing: 0.03em;
  cursor: pointer;
  transition: all 0.2s ease-in-out;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6cqw;
}

#btn-loadout-randomize {
  grid-column: 2;
  order: 3;
  width: 100%;
  flex: none;
}

.btn-loadout-secondary:hover {
  border-color: #f3d078;
  color: #f3d078;
  background: linear-gradient(180deg, #382216 0%, #1f120c 100%);
  box-shadow: 0 0 1.2cqw rgba(200, 157, 56, 0.3);
  transform: translateY(-1px);
}

.btn-loadout-secondary:active,
.btn-loadout-primary:active {
  transform: translateY(1px);
}

.btn-loadout-primary:disabled,
.btn-loadout-secondary:disabled,
#btn-loadout-save:disabled,
#btn-loadout-randomize:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  filter: grayscale(65%);
  pointer-events: none;
  transform: none;
}