/* Mobile responsive styles for TCGEngine */

/* Base mobile styles */
@media (max-width: 768px) {
  /* Core layout changes */
  body {
    overflow-x: hidden;
  }
  
  .core-wrapper {
    flex-direction: column !important;
    height: auto !important;
    padding-bottom: 20px;
  }

  .column-wrapper {
    flex-direction: column !important;
  }

  .flex-wrapper {
    flex-direction: column !important;
  }

  /* Mobile layout specific */
  .mobile-layout {
    display: flex;
    flex-direction: column;
    width: 100%;
  }
  /* Search section - should appear at top */
  .search-section {
    order: 1;
    width: 100% !important;
    margin: 0 0 15px 0 !important;
  }

  /* Deck list section - should appear second */
  .decks-section {
    order: 2;
    width: 100% !important;
    margin: 0 0 15px 0 !important;
  }
  
  /* Force search above deck list regardless of DOM order */
  div[id*="SearchPanel"], 
  div[id*="searchPanel"], 
  div[class*="search"], 
  div[id*="search"],
  div[id*="filterPanel"],
  .searchContainer {
    order: 1 !important;
  }
  
  div[id*="DeckPanel"],
  div[id*="deckPanel"],
  div[id*="DeckList"],
  div[class*="deck"],
  div[id*="deck"] {
    order: 2 !important;
  }

  .tabs {
    width: 100% !important; 
    margin-left: 0 !important;
    margin-right: 0 !important;
  }

  /* News section - should appear at bottom */
  .news-section {
    order: 3;
    width: 100% !important;
    margin: 0 !important;
  }

  /* Improve spacing and padding */
  .container {
    margin-bottom: 15px !important;
    padding: 15px !important;
  }

  .flex-padder {
    flex: 0 !important;
    margin: 10px 0 !important;
  }

  /* Improve tab buttons */
  .tab-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
  }

  .tab-button {
    padding: 8px 10px !important;
    margin-bottom: 5px;
    flex: 1 1 auto;
    min-width: 70px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .tab-button.discord {
    min-width: 40px;
    padding: 8px 8px !important;
    background: #5865F2 !important;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
  }

  .tab-button.discord:hover {
    background: #4752C4 !important;
    transform: translateY(-2px);
    box-shadow: 0 2px 8px rgba(88, 101, 242, 0.4);
  }

  .tab-button.discord img {
    width: 22px;
    height: 22px;
    display: block;
  }

  /* Better scrolling for deck lists - share the page scrollbar */
  .sciFiScroll {
    max-height: none !important;
    height: auto !important;
    overflow: visible !important;
    overflow-x: visible !important;
    overflow-y: visible !important;
  }
  
  /* Fix the webkit scrollbar styling */
  .sciFiScroll::-webkit-scrollbar {
    width: 0 !important;
    display: none !important;
  }
  
  .sciFiScroll::-webkit-scrollbar-track {
    display: none !important;
  }
  
  .sciFiScroll::-webkit-scrollbar-thumb {
    display: none !important;
  }

  /* Ensure table cells can collapse better */
  table td {
    padding: 2px !important;
  }  /* Card images in deck list */
  img[src*="concat"] {
    height: 75px !important;
    max-width: 100% !important;
    border-radius: 5px !important;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3) !important;
    transition: transform 0.2s ease !important;
  }
  
  img[src*="concat"]:active {
    transform: scale(1.1) !important;
  }

  /* Make buttons easier to tap */
  button {
    min-height: 40px;
    min-width: 40px;
  }
  /* Prevent overflow */
  .container img {
    max-width: 100%;
  }

  /* Handle popup better on mobile */
  #cardSearchContent {
    width: 95% !important; 
    height: 95% !important;
  }
  
  /* Improve action buttons spacing */
  button {
    margin: 2px !important;
  }
  
  /* Better deck item handling */
  .sciFiScroll table tr td {
    vertical-align: middle;
  }
  
  /* Improve user interaction accessibility */
  [onclick], button {
    cursor: pointer;
    min-height: 32px;
    min-width: 32px;
  }
  
  /* Fixed position elements should work better */
  .nav-bar {
    z-index: 100;
  }
  /* Header improvements */
  .home-header {
    flex-direction: column;
    padding: 10px;
    height: auto !important;
  }

  .home-header .title {
    width: 100%;
    margin-top:30px;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    height: 100%;
  }

  .home-header h1 {
    font-size: 24px !important;
  }

  .home-header p {
    font-size: 14px !important;
  }

  .home-banner {
    width: 100%;
    margin-top: 5px;
  }
  /* Navigation bar improvements */
  .nav-bar ul {
    flex-direction: column !important;
    padding: 0 !important;
    margin: 15px 0 !important;
    width: 100% !important;
  }

  .nav-bar ul li {
    margin: 0 !important;
    width: 100% !important;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  }
  
  .nav-bar ul li a, .nav-bar ul li a.NavBarItem {
    display: block !important;
    padding: 15px 20px !important;
    text-align: left !important;
    font-size: 18px !important;
    width: 100% !important;
  }
  
  .nav-bar ul li a:hover, .nav-bar ul li a.NavBarItem:hover {
    background-color: rgba(255, 255, 255, 0.1) !important;
  }

  .nav-bar-user {
    width: 100% !important;
    display: flex !important;
    flex-direction: column !important;
  }

  .leftnav, .rightnav {
    width: 100% !important;
    margin: 0 !important;
  }

  /* Form improvements */
  input[type="text"], input[type="password"], input[type="email"] {
    width: 100% !important;
    margin: 5px 0 !important;
    padding: 8px !important;
  }

  select {
    width: 100% !important;
    padding: 8px !important;
  }
  
  /* Mobile touch feedback */
  .touch-active {
    opacity: 0.7 !important;
    transform: scale(0.98) !important;
    transition: all 0.1s ease-in-out !important;
  }

  /* Mobile card enlarge view */
  .mobile-card-enlarge {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.85);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10000;
  }

  .mobile-card-enlarge img {
    max-width: 90%;
    max-height: 80vh;
    object-fit: contain;
  }

  /* More touch-friendly inputs */
  input[type="checkbox"], input[type="radio"] {
    min-width: 20px;
    min-height: 20px;
  }
  
  select option {
    padding: 10px;
  }
    .burger-menu {
    top: 18px;
    right: 18px;
    z-index: 2300;
  }  .home-header {
    position: relative;
    z-index: 1500;
    background: #0a1830;
    /* Add a subtle shadow for separation */
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    padding-top: 18px !important;
    padding-bottom: 10px !important;
    margin-top: 0 !important;
  }  .nav-bar {
    z-index: 2200; /* Increased z-index to appear above header and menu overlay */
    top: 0;
    right: -100%;
    left: auto;
    /* Ensure menu starts below header */
    margin-top: 0 !important;
  }
  .nav-bar.active {
    right: 0;
  }
  .menu-overlay {
    z-index: 1999;
  }
  body.menu-open .home-header {
    /* Keep header above overlay/menu */
    z-index: 2001;
  }
  /* Burger menu should start below the header, not at the very top */
  .nav-bar {
    top: 60px; /* Height of the header */
    width: 80vw;
    left: auto;
    right: -80vw;
    border-top-left-radius: 12px;
    border-bottom-left-radius: 12px;
  }
  .nav-bar.active {
    right: 0;
  }
  
  h2 {
    font-size: 20px !important;
  }

  .deck-card-image {
    height: 50px !important;
  }

  /* Further reduce padding */
  .container {
    padding: 10px !important;
  }
  
  /* Smaller mobile header */
  .home-header h1 {
    font-size: 20px !important;
  }
  
  .home-header p {
    font-size: 12px !important;
  }
  
  /* Make search inputs take full width */
  .search-controls {
    flex-direction: column;
    align-items: stretch;
  }
  
  .search-controls input,
  .search-controls select,
  .search-controls button {
    width: 100% !important;
    margin: 3px 0 !important;
  }

  /* Additional table responsive styles */
  /* Handle narrow tables better on very small screens */
  .sciFiScroll table {
    font-size: 14px;
  }
  
  /* For very complex tables, allow horizontal scroll only when needed */
  .table-container {
    width: 100%;
    overflow-x: auto;
  }
  
  /* Improve card display in deck list */
  .deck-card-row img {
    display: block;
    margin: 0 auto;
  }
  
  /* Ensure action buttons don't crowd */
  .action-buttons {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
  }
  
  .action-buttons button,
  .action-buttons a {
    margin: 3px !important;
    flex: 0 0 auto;
  }

  /* Deck list table: make images only as wide as needed, name stretches */
  .decks-section table {
    table-layout: auto !important;
  }
  .decks-section table tr td:nth-child(1),
  .decks-section table tr td:nth-child(2) {
    white-space: nowrap !important;
    width: 1%;
    min-width: 0;
    max-width: 75px;
  }
  .decks-section table tr td:nth-child(3) {
    width: 100%;
  }

  /* Ensure both leader and base images in deck list are the same size */
  .decks-section table tr td:nth-child(1) img,
  .decks-section table tr td:nth-child(2) img {
    height: 75px !important;
    width: 75px !important;
    object-fit: cover;
    max-width: none !important;
    min-width: 0;
    display: block;
    margin: 0 auto;
  }
}

/* Burger menu button */
.burger-menu {
  display: none;
  position: fixed;
  top: 15px;
  right: 15px;
  z-index: 2300; /* Higher z-index to ensure visibility */
  width: 45px;
  height: 20px;
  background: linear-gradient(to bottom, #3a5b9d, #2a4b8d);
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
  cursor: pointer;
  padding: 13px 10px;
  transition: all 0.3s ease;
}

.burger-menu span {
  display: block;
  width: 100%;
  height: 3px;
  background-color: white;
  margin-bottom: 5px;
  border-radius: 2px;
  transition: all 0.3s ease;
}

.burger-menu.active span:nth-child(1) {
  transform: translateY(8px) rotate(45deg);
}

.burger-menu.active span:nth-child(2) {
  opacity: 0;
}

.burger-menu.active span:nth-child(3) {
  transform: translateY(-8px) rotate(-45deg);
}

@media (max-width: 768px) {
  .burger-menu {
    display: block;
  }
  
  /* Nav menu for mobile - only change properties needed for mobile */
  .nav-bar {
    position: fixed !important; /* Use !important to override menuStyles.css */
    top: 0 !important;
    right: -100% !important; /* Start offscreen */
    width: 80% !important;
    height: 100% !important;
    background: rgba(0, 10, 40, 0.98) !important;
    z-index: 2200 !important;
    overflow-y: auto !important;
    box-shadow: -5px 0 15px rgba(0, 0, 0, 0.5) !important;
    padding-top: 60px !important;
    transition: right 0.3s ease-in-out !important;
    
    /* Preserve original styling for nav items */
    display: block !important;
  }
  
  .nav-bar.active {
    right: 0 !important;
  }
    /* Menu overlay - dark background behind the menu */
  .menu-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.7);
    z-index: 2150;
    transition: opacity 0.3s ease;
  }
    /* Ensure proper z-index stacking order */  body.menu-open .burger-menu {
    z-index: 2300;
  }
  
  body.menu-open .nav-bar {
    z-index: 2200;
  }
  
  body.menu-open .menu-overlay {
    z-index: 2150;
  }
  
  /* Fix nav-bar children styles for mobile */
  @media (max-width: 768px) {
    .nav-bar-user, .nav-bar-links {
      background-color: transparent !important;
      backdrop-filter: none !important;
      padding: 10px 20px !important;
      border-radius: 0 !important;
      margin: 0 !important;
      width: 100% !important;
      display: block !important;
    }
    
    .nav-bar ul {
      display: block !important;
      width: 100% !important;
      padding: 0 !important;
    }
    
    .nav-bar ul li {
      display: block !important;
      margin: 15px 0 !important;
      width: 100% !important;
    }
    
    .nav-bar a {
      display: block !important;
      padding: 10px !important;
      font-size: 18px !important;
      color: white !important;
    }
  }
  
  /* Prevent body scrolling when menu is open */
  body.menu-open {
    overflow: hidden;
  }
  
  /* Fix for card popups on mobile */
  .cardPopup {
    position: fixed !important;
    width: 90% !important;
    height: auto !important;
    max-height: 80vh !important;
    top: 10% !important;
    left: 5% !important;
    overflow-y: auto !important;
    z-index: 1000 !important;
  }
  /* Improve table views on mobile */
  .sciFiScroll table {
    width: 100%;
    display: table;
    table-layout: fixed;
    margin-bottom: 20px !important;
  }
  
  .sciFiScroll table td {
    display: table-cell;
    word-break: break-word;
    padding: 12px 6px !important;
    font-size: 15px !important;
    line-height: 1.4 !important;
  }
    /* Improve deck list appearance */
  .decks-section table {
    border-collapse: separate;
    border-spacing: 0 10px;
    margin-top: 10px !important;
  }
  
  .decks-section table tr {
    background-color: rgba(42, 75, 141, 0.3);
    transition: background-color 0.2s ease;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
  }
  
  .decks-section table tr:hover {
    background-color: rgba(42, 75, 141, 0.5);
    box-shadow: 0 3px 6px rgba(0, 0, 0, 0.3);
  }
  
  .decks-section table tr td:first-child {
    border-top-left-radius: 8px;
    border-bottom-left-radius: 8px;
    padding-left: 12px !important;
  }
  
  .decks-section table tr td:last-child {
    border-top-right-radius: 8px;
    border-bottom-right-radius: 8px;
    padding-right: 12px !important;
  }
}

/* Menu overlay */
.menu-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.7);
  z-index: 999;
}

.menu-overlay.active {
  display: block;
}

/* Ensure header is not covered by the menu */
@media (max-width: 768px) {
  .home-header {
    margin-top: 0 !important;
    z-index: 5;
    padding-top: 75px !important; /* Give space for burger menu */
    padding-bottom: 10px !important;
  }
  
  body {
    padding-top: 0 !important;
    margin-top: 0 !important;
  }
  
  .home-header .title {
    padding-right: 60px !important; /* Make space for burger menu */
  }
}

/* Orientation-specific styles */
body.portrait .mobile-layout {
  flex-direction: column !important;
}

body.landscape .mobile-layout {
  flex-direction: row !important;
  flex-wrap: wrap !important;
}

/* Landscape mode optimizations */
@media (max-width: 768px) and (orientation: landscape) {
  .home-header {
    flex-direction: row !important;
    align-items: center;
    height: auto !important;
    padding: 5px !important;
  }
  
  .home-header .title {
    width: 60% !important;
    padding: 5px !important;
  }
  
  .home-banner {
    width: 40% !important;
    height: 8px !important;
  }
  
  /* Adjust form controls for landscape */
  .search-controls {
    flex-direction: row !important;
    flex-wrap: wrap !important;
  }
  
  .search-controls input,
  .search-controls select {
    flex: 1 1 40% !important;
    min-width: 100px !important;
    margin: 2px !important;
  }
  
  /* Better use of space in landscape */
  .tab-buttons {
    flex-wrap: nowrap !important;
    overflow-x: auto !important;
  }
}

/* Device detection specific styles */
html.mobile-device {
  touch-action: manipulation; /* Prevents double tap to zoom */
}

html.mobile-device * {
  -webkit-tap-highlight-color: rgba(0,0,0,0); /* Remove default tap highlight */
}

/* Improve form elements on touch devices */
html.mobile-device input[type="text"],
html.mobile-device input[type="email"],
html.mobile-device input[type="password"],
html.mobile-device input[type="search"],
html.mobile-device select,
html.mobile-device textarea {
  font-size: 16px !important; /* Prevents iOS zoom on input */
  max-height: none !important; /* Prevents iOS height constraint issues */
}

/* Button specific enhancements */
html.mobile-device button,
html.mobile-device .tab-button,
html.mobile-device [role="button"] {
  cursor: pointer;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}

/* Fix font rendering issues on mobile */
html.mobile-device {
  -webkit-text-size-adjust: 100%; /* Prevents unwanted text size adjustments */
  text-size-adjust: 100%;
}

/* Hover effects don't make sense on mobile */
@media (hover: none) {
  a:hover, button:hover, [role="button"]:hover {
    /* Remove any existing hover effects that might look odd on touch */
    transform: none !important;
    transition: none !important;
  }
}

/* Card zoom functionality */
.card-zoom-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.85);
  z-index: 10000;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
}

.card-zoomed-image {
  max-width: 90%;
  max-height: 80vh;
  border-radius: 10px;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.5);
}

.card-zoom-close {
  position: absolute;
  top: 20px;
  right: 20px;
  width: 40px;
  height: 40px;
  background-color: rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  display: flex;
  justify-content: center;
  align-items: center;
  color: white;
  font-size: 30px;
  cursor: pointer;
}

/* Fix disclaimer positioning */
.disclaimer, 
#disclaimer, 
footer, 
.footer, 
.copyright,
div[id*="disclaimer"],
div[class*="disclaimer"] {
  position: relative !important;
  bottom: auto !important;
  width: 100% !important;
  clear: both !important;
  order: 999 !important; /* Ensure it's the last item */
}

/* Push footer to bottom */
.content-main,
main,
.main-content {
  flex: 1;
}

/* Desktop: disclaimer/footer always at the bottom, not as a side pane */
@media (min-width: 769px) {
  .disclaimer, 
  #disclaimer, 
  footer, 
  .footer, 
  .copyright,
  div[id*="disclaimer"],
  div[class*="disclaimer"] {
    position: relative !important;
    bottom: auto !important;
    left: 0 !important;
    right: 0 !important;
    margin-bottom: 0 !important;
    width: 100% !important;
    max-width: 100vw !important;
    clear: both !important;
    order: 999 !important;
    display: block !important;
    float: none !important;
    /* align-self: flex-end !important; */
    flex: 0 0 auto !important;
    text-align: center !important;
    background: none !important;
    box-shadow: none !important;
    border-radius: 0 !important;
    z-index: auto !important;
  }
  .disclaimer p {
    font-size: 13px !important;
    font-weight: 300;
    text-align: center !important;
    margin: 0 auto !important;
    line-height: 1.5;
  }
  /* Ensure main containers are column flex for sticky footer */

  .content-main,
  main,
  .main-content {
    flex: 1 0 auto;
  }  .core-wrapper {
    display: flex !important;
    flex-direction: row !important;
    align-items: flex-start;
    width: 100%;
    flex: 0 1 auto; /* Changed from 1 0 auto to prevent excessive stretching */
    overflow: visible !important;
  }
  .left-pane {
    flex: 0 0 60%;
    min-width: 400px;
    max-width: 1000px;
    padding: 0 20px;
    box-sizing: border-box;
    overflow: visible !important;
  }
.right-pane {
    flex: 1 0 40%;
    min-width: 300px;
    max-width: 600px;
    padding: 0 60px 0 20px;
    box-sizing: border-box;
    overflow: visible !important;
}
  .sciFiScroll {
    max-height: none !important;
    height: auto !important;
    overflow: visible !important;
    overflow-x: visible !important;
    overflow-y: visible !important;
  }
  
  /* Prevent the scrollbar on page container */
  html, body {
    overflow-x: hidden !important;
    overflow-y: auto !important;
  }
  
  .pageContainer {
    overflow: visible !important;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
  }
  .decks-section.tabs {
    width: 100% !important;
    margin: 0 !important;
    max-width: 100%;
  }
  .news-section {
    margin-top: 20px !important;
  }
  .pageContainer {
    overflow-y: visible !important;
  }
}

/* Fix the page container and body scrolling */
html, body {
  height: 100%;
  margin: 0;
  padding: 0;
  overflow-x: hidden;
  overflow-y: auto;
}

body {
  position: relative;
}

.pageContainer {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  width: 100%;
  position: relative;
  overflow: hidden;
}

/* Only show scrollbars where they are needed */
.sciFiScroll {
  overflow-y: auto !important;
  max-height: calc(100vh - 380px) !important;
  height: auto !important;
}

/* Ensure smooth scrolling */
html {
  scroll-behavior: smooth;
}

/* Custom scrollbar styling only for sciFiScroll */
.sciFiScroll::-webkit-scrollbar {
  width: 12px;
}

.sciFiScroll::-webkit-scrollbar-track {
  background: #000022;
  box-shadow: inset 0 0 5px #000;
  border-radius: 8px;
}

.sciFiScroll::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, #2a4b8d, #001f4d);
  border-radius: 12px;
  box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.5);
}

/* Default behavior for other scrollbars on the page */
::-webkit-scrollbar {
  width: 0px; /* Make invisible but maintain functionality */
  background: transparent;
}

/* Mobile-specific scroll handling */
@media (max-width: 768px) {
  /* Better scrolling for deck lists - share the page scrollbar */
  .sciFiScroll {
    max-height: none !important;
    height: auto !important;
    overflow: visible !important;
    overflow-x: visible !important;
    overflow-y: visible !important;
  }
  
  /* Fix the webkit scrollbar styling */
  .sciFiScroll::-webkit-scrollbar {
    width: 0 !important;
    display: none !important;
  }
  
  .sciFiScroll::-webkit-scrollbar-track {
    display: none !important;
  }
  
  .sciFiScroll::-webkit-scrollbar-thumb {
    display: none !important;
  }
  
  /* Core layout changes */
  body {
    overflow-x: hidden;
  }
  
  .core-wrapper {
    flex-direction: column !important;
    height: auto !important;
    padding-bottom: 20px;
  }
}