/* Layout and sidebars */
.deck-header {
  flex-shrink: 0;
  color: white;
  padding: 1rem;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.deck-content {
  flex: 1;
  display: flex;
  overflow: visible;
}

.commanders-sidebar {
  width: 280px;
  flex-shrink: 0;
  padding: 1rem;
  overflow-y: visible;
  border-right: 3px solid #2980b9;
}

.sidebar {
  width: 250px;
  flex-shrink: 0;
  padding: 1rem;
  overflow-y: auto;
  height: 100vh;
  border-left: 3px solid #2980b9;
}

.commander-card,
.sidebar-stack {
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  margin-bottom: 1rem;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  position: relative;
  will-change: transform;
}

.commander-card a {
  text-decoration: none;
  color: inherit;
  display: block;
}

.commander-card:hover,
.sidebar-card:hover,
.card-stack-container:hover {
  transform: translateY(-4px) scale(1.05);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
  z-index: 1000;
}

.commander-img {
  width: 100%;
  object-fit: cover;
}

/* Main deck and stacks */
.deck-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow-y: visible;
}

.section-header {
  color: white;
  font-weight: bold;
  font-size: 1.2rem;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid var(--bs-primary);
  text-transform: uppercase;
}

.section-header .view-toggle-container {
  margin: 0;
}

.section-header .view-toggle-label {
  font-size: 0.75rem;
  text-transform: none;
}

.type-header {
  color: #f8f9fa;
  font-weight: 600;
  font-size: 1.1rem;
  margin: 1.5rem 0 0.75rem 0;
  padding: 0.5rem 0.75rem;
  background: rgba(52, 73, 94, 0.7);
  border-left: 4px solid var(--bs-primary);
  border-radius: 4px;
  text-transform: uppercase;
}

.type-header:first-child {
  margin-top: 0.75rem;
}

.deck-visual-grid {
  display: grid;
  gap: 16px;
  justify-items: center;
  /* Dynamic columns calculated by JavaScript based on container width and max card size */
  grid-template-columns: repeat(2, 1fr);
}


.card-stack-container {
  position: relative;
  width: 100%;
  max-width: 215px; /* Cap card width to 215px */
  transition: transform 0.2s ease;
}

.game-card,
.sidebar-card {
  position: absolute;
  width: 100%;
  max-width: 215px; /* Cap card width to 215px (results in ~300px height with 5/7 ratio) */
  aspect-ratio: 5 / 7;
  overflow: hidden;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
  border: 2px solid #1a1a1a;
  text-decoration: none;
  color: inherit;
  display: block;
  will-change: transform;
}

.game-card {
  border-radius: 8px;
  background: #2c3e50;
}

.sidebar-card {
  border-radius: 12px;
  background: #34495e;
}

.game-card:nth-child(n) {
  top: calc((var(--stack-index, 0)) * 40px);
}

.card-img,
.sidebar-card-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}


.sidebar-card-name {
  padding: 0.4rem;
  font-size: 0.65rem;
  z-index: 100;
}


.quantity-badge {
  position: absolute;
  bottom: 0.5rem;
  right: 0.5rem;
  background: rgba(0, 0, 0, 0.85);
  color: white;
  border-radius: 6px;
  min-width: 28px;
  height: 28px;
  padding: 0 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: 600;
  z-index: 20;
  border: 2px solid rgba(255, 255, 255, 0.9);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.5);
}

/* Sidebar cards */
.sidebar-stack {
  width: 100%;
}



.sidebar-card:hover .sidebar-card-name {
  opacity: 1;
}

/* Column stacking mode */
.column-stack-mode .deck-visual-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
  align-items: flex-start;
}

.column-stack-mode .card-stack-container {
  width: 120px;
  flex: 0 0 120px;
  position: relative;
}

.column-stack-mode .game-card {
  position: absolute;
  top: 0;
  left: 0;
  width: 120px;
  margin: 0;
  transition: none;
}

/* Text view styles */
.text-view {
  display: none;
}

.text-view.active {
  display: block;
}

.image-view.hidden {
  display: none;
}

.text-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.text-list-item {
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  transition: background-color 0.2s ease;
}

.text-list-item:hover {
  background-color: rgba(255, 255, 255, 0.05);
}

.text-list-item:last-child {
  border-bottom: none;
}

.card-name-text {
  flex-grow: 1;
  color: #f8f9fa;
  font-size: 0.9rem;
}

/* Removed card-quantity-text styling - quantities now shown inline with card names */

.card-tooltip-image {
  width: 200px;
  height: auto;
  border-radius: 8px;
  margin: 0 auto 12px auto;
  border: 1px solid #444;
  display: block;
}

/* Text view column layout */
.text-view-columns {
  display: grid;
  gap: 2rem;
  grid-template-columns: 1fr;
}

.text-view-container {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

@media (min-width: 768px) {
  .text-view-columns {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (min-width: 992px) {
  .text-view-columns {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (min-width: 1200px) {
  .text-view-columns {
    grid-template-columns: repeat(4, 1fr);
  }
}

.text-column {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.text-type-section {
  break-inside: avoid;
  margin-bottom: 1rem;
}

/* Center-align commanders in text view */
.commanders-sidebar .text-list {
  text-align: center;
}

.commanders-sidebar .text-list-item {
  justify-content: center;
}

/* Toggle switch styles */
.view-toggle-container {
  margin: 0 0.5rem;
}

.view-toggle-label {
  font-size: 0.875rem;
  font-weight: 500;
  user-select: none;
}

.view-toggle-switch {
  position: relative;
  width: 50px;
  height: 24px;
  cursor: pointer;
}

.view-toggle-input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}

.view-toggle-slider {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(255, 255, 255, 0.3);
  border: 1px solid rgba(255, 255, 255, 0.5);
  border-radius: 24px;
  transition: all 0.3s ease;
}

.view-toggle-slider:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 2px;
  top: 2px;
  background-color: white;
  border-radius: 50%;
  transition: all 0.3s ease;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.view-toggle-input:checked + .view-toggle-slider {
  background-color: #007bff;
  border-color: #007bff;
}

.view-toggle-input:checked + .view-toggle-slider:before {
  transform: translateX(26px);
}

.view-toggle-switch:hover .view-toggle-slider {
  background-color: rgba(255, 255, 255, 0.4);
}

.view-toggle-input:checked + .view-toggle-slider:hover {
  background-color: #0056b3;
}

/* Responsive */
/* Card tooltip styles */
.card-tooltip {
  animation: fadeIn 0.2s ease-in-out;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-5px); }
  to { opacity: 1; transform: translateY(0); }
}

.card-tooltip-content {
  line-height: 1.4;
}

.card-tooltip-header h6 {
  font-weight: 600;
  color: #fff;
  margin-bottom: 4px;
}

.card-tooltip-header small {
  color: #ccc;
  font-style: italic;
}

.card-oracle-text {
  margin: 8px 0 4px 0;
  font-size: 0.8rem;
  color: #e0e0e0;
}

.card-pt {
  margin: 4px 0 0 0;
  text-align: right;
  color: #fff;
  font-size: 0.9rem;
}

/* Comparison modal specific styles */
.comparison-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.5rem;
  padding: 0.5rem;
}

@media (min-width: 576px) {
  .comparison-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (min-width: 768px) {
  .comparison-grid {
    grid-template-columns: repeat(5, 1fr);
  }
}

@media (min-width: 992px) {
  .comparison-grid {
    grid-template-columns: repeat(6, 1fr);
    gap: 0.75rem;
  }
}

@media (min-width: 1200px) {
  .comparison-grid {
    grid-template-columns: repeat(8, 1fr);
  }
}

.comparison-card-wrapper {
  position: relative;
  width: 100%;
  aspect-ratio: 5 / 7;
}

.comparison-card-link {
  display: block;
  position: relative;
  width: 100%;
  height: 100%;
  text-decoration: none;
  color: inherit;
  border-radius: 8px;
  overflow: hidden;
  background: #2c3e50;
  border: 2px solid #1a1a1a;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.comparison-card-link:hover {
  transform: translateY(-4px) scale(1.02);
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.3);
  z-index: 10;
}

.comparison-card-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.comparison-card-name {
  display: none;
}

.comparison-quantity-badge {
  position: absolute;
  bottom: 0.25rem;
  right: 0.25rem;
  background: rgba(0, 0, 0, 0.85);
  color: white;
  border-radius: 4px;
  min-width: 22px;
  height: 22px;
  padding: 0 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 600;
  z-index: 20;
  border: 1.5px solid rgba(255, 255, 255, 0.9);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}

/* Section comparison styling */
.section-comparison {
  border-radius: 8px;
  background: rgba(52, 58, 64, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.1);
  margin-bottom: 2rem;
}

.comparison-deck-title {
  font-weight: 600;
  font-size: 0.95rem;
}

/* Comparison visual improvements */
.comparison-results-content {
  overflow-y: auto;
  height: 100%;
}

#comparisonResultModal .modal-body {
  overflow-y: auto;
  height: calc(100vh - 60px);
}

#comparisonResultModal.modal.show {
  overflow: hidden;
}

/* Mobile responsive for comparisons */
@media (max-width: 768px) {
  .section-comparison {
    margin-bottom: 1.5rem;
    padding: 0.5rem;
  }

  .comparison-results-content {
    padding: 0.75rem !important;
  }
}

@media (max-width: 992px) {
  /* Stack main content vertically */
  .deck-content {
    display: block;
    flex-direction: column;
  }

  /* Commander sidebar: wrap cards under the title */
  .commanders-sidebar {
    position: static;
    width: 100%;
    height: auto;
    padding: 1.5rem;
    border-right: none;
    max-height: none;
    overflow-y: visible;
  }

  .commanders-sidebar .image-view:not(.hidden) {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.5rem;
  }

  .commanders-sidebar .image-view.hidden {
    display: none;
  }

  /* Sidebar: stack title then cards */
  .sidebar {
    width: 100%;
    padding: 0.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    border-left: none;
    height: auto;
    overflow: visible;
  }

  /* Titles on their own full-width row */
  .commanders-sidebar > h5,
  .sidebar > h5 {
    width: 100%;
    margin-bottom: 0.5rem;
    flex: none;
  }

  /* Commander cards - allow side-by-side for partners */
  .commanders-sidebar .image-view > .commander-card {
    width: calc(50% - 0.5rem);
    max-width: 140px;
    aspect-ratio: 5 / 7;
    margin-bottom: 0;
  }

  /* Single commander - center it */
  .commanders-sidebar .image-view > .commander-card:only-of-type {
    width: 60%;
    max-width: 180px;
  }

  .commanders-sidebar > h5 {
    text-align: center;
    margin: 0 0 0.5rem;
  }

  .commander-card img {
    width: 100%;
    height: 100%;
    object-fit: cover;
  }

  /* Runes section - full width so it takes its own row */
  .commanders-sidebar .runes-section {
    width: 100%;
    flex-basis: 100%;
  }

  /* Battlefield section - full width, cards stack vertically */
  .commanders-sidebar .battlefield-section {
    width: 100%;
    flex-basis: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
  }

  .commanders-sidebar .battlefield-section .commander-card {
    width: 80%;
    max-width: 280px;
    aspect-ratio: 7 / 5;
    margin-bottom: 0;
  }

  .commanders-sidebar .battlefield-section .commander-card img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 8px;
  }

  /* Sidebar stack wrapper: flex-wrap container */
  .sidebar .image-view:not(.hidden) .sidebar-stack {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    width: 100%;
    margin: 0;
    padding: 0;
    height: auto !important;
    overflow: visible !important;
    justify-content: center;
    box-shadow: unset;
  }

  /* Sidebar cards fixed size, will wrap */
  .sidebar .image-view:not(.hidden) .sidebar-card {
    flex: 0 0 120px;
    max-width: 120px;
    width: auto !important;
    height: auto;
    aspect-ratio: 5/7;
    margin-right: 0;
    position: relative !important;
    top: 0 !important;
    display: block;
  }
}

/* Runes section styles */
.runes-section {
  border-top: 2px solid rgba(255, 255, 255, 0.1);
  padding-top: 1rem;
}

.battlefield-section {
  border-top: 2px solid rgba(255, 255, 255, 0.1);
  padding-top: 1rem;
}

.rune-cards-horizontal {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  align-items: flex-start;
  flex-wrap: nowrap;
}

.rune-card {
  position: relative;
  flex: 1 1 auto;
  max-width: calc(50% - 0.5rem);
  min-width: 100px;
  transition: transform 0.2s ease;
}

.rune-card:hover {
  transform: translateY(-2px) scale(1.05);
  z-index: 100;
}

.rune-card a {
  text-decoration: none;
  color: inherit;
  display: block;
  position: relative;
}

.rune-img {
  width: 100%;
  aspect-ratio: 5 / 7;
  object-fit: cover;
  border-radius: 8px;
  border: 2px solid #1a1a1a;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
  background: #2c3e50;
}

/* Mobile responsive for runes */
@media (max-width: 992px) {
  .rune-cards-horizontal {
    justify-content: center;
    gap: 0.75rem;
  }
  
  .rune-card {
    max-width: 100px;
  }
  
  .rune-card .quantity-badge {
    width: 18px;
    height: 18px;
    font-size: 0.55rem;
  }
}

/* Battlefield cards - stacked landscape cards in commander sidebar */
.battlefield-stack {
  width: 100%;
  position: relative;
  margin-bottom: 1rem;
}

.battlefield-card {
  position: absolute;
  width: 100%;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  transition: transform 0.2s ease;
}

.battlefield-card:hover {
  transform: translateY(-4px) scale(1.05);
  z-index: 1000 !important;
}

.battlefield-card a {
  text-decoration: none;
  color: inherit;
  display: block;
  position: relative;
  width: 100%;
  height: 100%;
}

.battlefield-card-img {
  width: 100%;
  object-fit: cover;
  border-radius: 12px;
  border: 2px solid #1a1a1a;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
  background: #34495e;
}

.battlefield-card .quantity-badge {
  position: absolute;
  bottom: 0.5rem;
  right: 0.5rem;
  background: rgba(0, 0, 0, 0.85);
  color: white;
  border-radius: 6px;
  min-width: 28px;
  height: 28px;
  padding: 0 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: 600;
  z-index: 20;
  border: 2px solid rgba(255, 255, 255, 0.9);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.5);
}

.battlefield-card-name {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(0, 0, 0, 0.9);
  color: white;
  font-weight: 500;
  text-align: center;
  line-height: 1.1;
  padding: 0.4rem;
  font-size: 0.65rem;
  z-index: 100;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.battlefield-card:hover .battlefield-card-name {
  opacity: 1;
}

/* Mobile responsive for battlefield cards */
@media (max-width: 992px) {
  .battlefield-stack {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    width: 100%;
    margin: 0;
    padding: 0;
    height: auto !important;
    overflow: visible !important;
    justify-content: center;
  }

  .battlefield-card {
    flex: 0 0 120px;
    max-width: 120px;
    width: auto !important;
    height: auto;
    margin-right: 0;
    position: relative !important;
    top: 0 !important;
    display: block;
  }

  .battlefield-card .quantity-badge {
    width: 20px;
    height: 20px;
    font-size: 0.6rem;
  }
}

@media (max-width: 576px) {
  .battlefield-card .quantity-badge {
    width: 18px;
    height: 18px;
    font-size: 0.55rem;
  }
}

/* Landscape cards - rotates portrait images to horizontal */
.landscape-cards-container {
  display: flex;
  gap: 1rem;
  align-items: flex-start;
  flex-wrap: wrap;
  margin: 1rem 0;
}

.landscape-card {
  position: relative;
  transition: transform 0.2s ease;
  overflow: hidden;
}

.landscape-card:hover {
  transform: translateY(-4px) scale(1.05);
  z-index: 100;
}

.landscape-card a {
  text-decoration: none;
  color: inherit;
  display: block;
  position: relative;
  width: 100%;
  height: 100%;
}

.landscape-card-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 8px;
  border: 2px solid #1a1a1a;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
  background: #2c3e50;
}

.landscape-card .quantity-badge {
  position: absolute;
  bottom: 0.25rem;
  right: 0.25rem;
  background: rgba(220, 53, 69, 0.9);
  color: white;
  border-radius: 50%;
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.65rem;
  font-weight: bold;
  z-index: 20;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}



/* Mobile responsive for landscape cards */
@media (max-width: 992px) {
  .landscape-cards-container {
    gap: 0.75rem;
    justify-content: center;
  }

  .landscape-card {
    /* Override JS-set dimensions on mobile with reasonable constraints */
    width: calc(50% - 0.5rem) !important;
    max-width: 200px !important;
    height: auto !important;
    aspect-ratio: 7 / 5;
  }

  .landscape-card-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
  }

  .landscape-card .quantity-badge {
    width: 20px;
    height: 20px;
    font-size: 0.6rem;
  }
}

@media (max-width: 576px) {
  .landscape-card {
    width: calc(50% - 0.375rem) !important;
    max-width: 160px !important;
  }

  .landscape-card .quantity-badge {
    width: 18px;
    height: 18px;
    font-size: 0.55rem;
  }
}