/* =====================================================
   GMG Responsive Design Fixes
   Addresses: Menu cutoff, Modal sizing, Large screen scaling
   ===================================================== */

/* =====================================================
   1. TOP MENU / HEADER RESPONSIVE FIXES
   ===================================================== */

/* Desktop nav - horizontally scrollable row */
.nav-desktop {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  flex-wrap: nowrap;
  flex-shrink: 0;
  max-width: 100%;
  box-sizing: border-box;
  overflow: visible;
  -webkit-overflow-scrolling: touch;
}

/* Prevent links from squishing; each link keeps its width */
.nav-desktop .nav-link {
  font-size: 0.85rem;
  padding: 0.35rem 0.5rem;
  white-space: nowrap;
  flex: 0 0 auto;
}

.nav-desktop .nav-link.nav-link-highlight {
  padding: 0.4rem 0.75rem;
}

.nav-desktop .account-btn {
  padding: 0.5rem;
  flex: 0 0 auto;
}

/* Dropdown buttons match nav link styling */
.nav-desktop .nav-dropdown {
  flex: 0 0 auto;
}

.nav-desktop .nav-dropdown-btn {
  font-size: 0.85rem;
  padding: 0.35rem 0.5rem;
  white-space: nowrap;
  gap: 0.25rem;
}

/* Theme toggle button - consistent sizing */
.theme-toggle-compact {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px !important;
  height: 32px !important;
  min-width: 32px;
  min-height: 32px;
  padding: 0 !important;
  margin: 0 0.25rem;
  background: transparent;
  border: 1px solid var(--color-border, #444);
  border-radius: 6px;
  cursor: pointer;
  flex-shrink: 0;
}

.theme-toggle-compact .theme-toggle-icon {
  font-size: 1rem;
  line-height: 1;
}

/* Show hamburger on smaller screens */
@media (max-width: 900px) {
  .hamburger {
    display: flex !important;
  }
  
  .nav-desktop {
    display: none !important;
  }
}

/* Show desktop nav only on larger screens */
@media (min-width: 901px) {
  .hamburger {
    display: none !important;
  }
  
  .nav-desktop {
    display: flex !important;
  }
  
  .site-logo-beta {
    display: inline-block;
  }
}

/* =====================================================
   2. MODAL / POPUP RESPONSIVE FIXES
   ===================================================== */

/* Base modal responsiveness */
.modal {
  width: min(500px, 92vw);
  max-width: 92vw;
  max-height: calc(100vh - 2rem);
  margin: 1rem;
}

.modal-body {
  max-height: calc(100vh - 180px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.modal-sm {
  width: min(400px, 92vw);
}

.modal-lg {
  width: min(700px, 92vw);
}

.modal-xl {
  width: min(900px, 92vw);
}

.modal-full {
  width: calc(100vw - 2rem);
  max-width: calc(100vw - 2rem);
  max-height: calc(100vh - 2rem);
}

/* Onboarding modal responsive fixes */
#onboardingModal .modal,
.onboarding-modal-card {
  width: min(480px, 90vw) !important;
  max-width: 90vw !important;
  max-height: calc(100vh - 4rem);
  margin: auto;
}

.onboarding-modal-card {
  padding: clamp(1rem, 4vw, 2rem);
}

.onboarding-features {
  padding: clamp(0.75rem, 3vw, 1.5rem);
}

.onboarding-feature {
  padding: clamp(0.5rem, 2vw, 0.75rem);
  font-size: clamp(0.8125rem, 2.5vw, 0.9375rem);
}

/* Welcome/onboarding modal mascot */
.onboarding-modal-card .modal-mascot,
.onboarding-mascot {
  max-width: min(120px, 25vw);
  height: auto;
}

/* Genre Engine modals */
.genre-engine-modal,
.world-seed-modal {
  width: min(600px, 92vw) !important;
  max-width: 92vw;
}

/* QR Code modal */
.qr-modal,
#qrCodeModal {
  width: min(400px, 90vw);
}

/* Small screen modal adjustments */
@media (max-width: 480px) {
  .modal {
    width: calc(100vw - 1rem);
    max-width: calc(100vw - 1rem);
    margin: 0.5rem;
    border-radius: 0.75rem;
  }
  
  .modal-header {
    padding: 0.75rem 1rem;
  }
  
  .modal-title {
    font-size: 1.125rem;
  }
  
  .modal-body {
    padding: 1rem;
    max-height: calc(100vh - 160px);
  }
  
  .modal-footer {
    padding: 0.75rem 1rem;
    flex-wrap: wrap;
  }
  
  .modal-footer .btn {
    flex: 1;
    min-width: 100px;
  }
  
  .onboarding-modal-card {
    padding: 1rem;
  }
  
  .onboarding-modal-card h2 {
    font-size: 1.25rem;
  }
}

/* =====================================================
   3. LARGE SCREEN SCALING
   Using !important to override inline styles that load after this file
   ===================================================== */

/* Fluid typography for body - !important needed to override inline :root */
html {
  font-size: clamp(16px, 1vw + 12px, 18px) !important;
}

/* Increase container widths on large screens */
@media (min-width: 1280px) {
  .app {
    max-width: 1100px !important;
  }
  
  .container {
    max-width: 1300px !important;
  }
  
  .container-xl {
    max-width: 1400px !important;
  }
}

@media (min-width: 1536px) {
  .app {
    max-width: 1280px !important;
  }
  
  .container {
    max-width: 1500px !important;
  }
  
  .container-xl {
    max-width: 1600px !important;
  }
  
  .container-2xl {
    max-width: 1800px !important;
  }
  
  /* Slightly larger text on ultrawide */
  html {
    font-size: clamp(16px, 0.9vw + 10px, 19px) !important;
  }
}

@media (min-width: 1920px) {
  .app {
    max-width: 1400px !important;
  }
  
  .container {
    max-width: 1600px !important;
  }
  
  /* Increase card padding on very large screens */
  .card {
    padding: 2.5rem !important;
  }
  
  /* Larger headings on ultrawide */
  h1 {
    font-size: 2.5rem !important;
  }
  
  h2 {
    font-size: 1.5rem !important;
  }
}

/* 2-column and 3-column layouts on large screens */
@media (min-width: 1280px) {
  .layout-3col {
    grid-template-columns: 340px 1fr 380px !important;
  }
  
  .layout-2col {
    grid-template-columns: 340px 1fr !important;
  }
}

@media (min-width: 1536px) {
  .layout-3col {
    grid-template-columns: 380px 1fr 420px !important;
  }
  
  .layout-2col {
    grid-template-columns: 380px 1fr !important;
  }
}

/* Hero section scaling */
@media (min-width: 1280px) {
  .hero-title {
    font-size: 3.25rem !important;
  }
  
  .hero-subtitle {
    font-size: 1.25rem !important;
    max-width: 700px !important;
  }
}

@media (min-width: 1536px) {
  .hero-title {
    font-size: 3.75rem !important;
  }
  
  .hero-subtitle {
    font-size: 1.375rem !important;
    max-width: 800px !important;
  }
}

/* Tools grid scaling on large screens */
@media (min-width: 1280px) {
  .tools-grid {
    grid-template-columns: repeat(3, 1fr) !important;
    gap: 1.5rem !important;
  }
}

@media (min-width: 1536px) {
  .tools-grid {
    grid-template-columns: repeat(4, 1fr) !important;
    gap: 1.75rem !important;
  }
}

/* Form elements scaling */
@media (min-width: 1280px) {
  input[type="file"],
  select,
  .input-field,
  textarea {
    font-size: 1rem !important;
    padding: 0.875rem 1rem !important;
  }
  
  .btn {
    padding: 0.75rem 1.5rem !important;
    font-size: 1rem !important;
  }
  
  .btn-lg {
    padding: 1rem 2rem !important;
    font-size: 1.125rem !important;
  }
}

/* Session dashboard / GM Screen scaling */
@media (min-width: 1280px) {
  .session-dashboard {
    max-width: 1400px !important;
  }
}

@media (min-width: 1536px) {
  .session-dashboard {
    max-width: 1600px !important;
  }
}

/* =====================================================
   4. ADDITIONAL MOBILE POLISH
   ===================================================== */

/* Ensure touch-friendly tap targets */
@media (max-width: 767px) {
  .nav-mobile-link {
    min-height: 44px;
    display: flex;
    align-items: center;
  }
  
  .btn, button {
    min-height: 44px;
  }
  
  /* Stack form buttons on mobile */
  .form-actions,
  .button-group {
    flex-direction: column;
  }
  
  .form-actions .btn,
  .button-group .btn {
    width: 100%;
  }
}

/* Mobile nav adjustments for new breakpoint */
@media (max-width: 1100px) {
  .nav-mobile {
    bottom: 70px;
  }
}

@media (min-width: 768px) and (max-width: 1100px) {
  .nav-mobile {
    bottom: 0;
  }
  
  body {
    padding-bottom: 0;
  }
}

/* Ensure scroll areas work properly on all devices */
.scroll-area {
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

/* =====================================================
   5. THEME-AWARE FORM CONTROLS FIX
   Override inline styles that use hardcoded dark colors
   ===================================================== */

/* Force all select elements to use theme colors, overriding inline styles */
select,
.input-field,
input[type="text"],
input[type="email"],
input[type="number"],
input[type="password"],
input[type="search"],
input[type="url"],
textarea {
  background: var(--color-surface) !important;
  color: var(--color-text) !important;
  border-color: var(--color-border) !important;
}

/* Dropdown options need theme colors too */
select option {
  background: var(--color-surface) !important;
  color: var(--color-text) !important;
}

/* Focus states use theme colors */
select:focus,
.input-field:focus,
input:focus,
textarea:focus {
  border-color: var(--color-primary) !important;
  outline-color: var(--color-primary) !important;
}

/* Placeholder text */
::placeholder {
  color: var(--color-muted) !important;
  opacity: 0.7;
}

/* Hero theme selector needs fixing too */
.hero-theme-selector select {
  background: var(--color-surface) !important;
  color: var(--color-text) !important;
  border-color: var(--color-border) !important;
}

/* Chat mode selector in header */
#chatModeSelector {
  background: var(--color-surface) !important;
  color: var(--color-text) !important;
  border-color: var(--color-border) !important;
}

/* Dropdown menus that may have dark backgrounds */
.dropdown-menu,
.dropdown-content,
.menu-dropdown,
.select-menu,
.autocomplete-dropdown {
  background: var(--color-surface) !important;
  color: var(--color-text) !important;
  border-color: var(--color-border) !important;
}

.dropdown-item,
.dropdown-option,
.menu-item {
  background: transparent !important;
  color: var(--color-text) !important;
}

.dropdown-item:hover,
.dropdown-option:hover,
.menu-item:hover {
  background: var(--color-surface-elevated) !important;
}

/* Form field container backgrounds */
.form-group,
.form-field,
.input-group {
  background: transparent;
}

/* Genre engine controls */
.genre-engine-modal select,
.world-seed-modal select,
.genre-controls select {
  background: var(--color-surface) !important;
  color: var(--color-text) !important;
  border-color: var(--color-border) !important;
}

/* Campaign and system dropdowns */
.campaign-dropdown,
#campaignSystem,
#campaignTheme,
#encounterSystem,
#encounterCampaign,
#participantType,
#newChatMode,
#newChatCampaign {
  background: var(--color-surface) !important;
  color: var(--color-text) !important;
  border-color: var(--color-border) !important;
}

/* VTT and edit modal controls */
#vttTokenSize,
#edit-rarity {
  background: var(--color-surface) !important;
  color: var(--color-text) !important;
  border-color: var(--color-border) !important;
}

/* =====================================================
   Campaign Manager Theme Fixes
   Override hardcoded dark backgrounds with theme-aware colors
   ===================================================== */

/* Main panels */
.cm-campaigns-panel,
.cm-detail-panel {
  background: var(--color-surface) !important;
  border-color: var(--color-border) !important;
}

/* Panel headers */
.cm-panel-header {
  background: var(--color-surface-elevated) !important;
  border-color: var(--color-border) !important;
}

.cm-panel-header h3 {
  color: var(--color-text) !important;
}

/* Session bar */
.cm-session-bar {
  background: var(--color-surface-elevated) !important;
  border-color: var(--color-border) !important;
}

/* Empty detail section */
.cm-empty-detail {
  color: var(--color-muted) !important;
}

.cm-empty-detail h3 {
  color: var(--color-text) !important;
}

/* Campaign items */
.cm-campaign-item {
  background: var(--color-surface-elevated) !important;
}

.cm-campaign-name {
  color: var(--color-text) !important;
}

.cm-campaign-stats {
  color: var(--color-muted) !important;
}

/* Detail section */
.cm-detail-title h3 {
  color: var(--color-text) !important;
}

.cm-detail-info {
  background: var(--color-surface-elevated) !important;
}

.cm-info-label {
  color: var(--color-muted) !important;
}

.cm-info-value {
  color: var(--color-text) !important;
}

/* History entries */
.cm-history-entry {
  background: var(--color-surface-elevated) !important;
  border-color: var(--color-border) !important;
}

.cm-entry-label {
  color: var(--color-text) !important;
}

.cm-entry-meta {
  color: var(--color-muted) !important;
}

/* Modal content */
.cm-modal-content {
  background: var(--color-surface) !important;
  border-color: var(--color-border) !important;
}

.cm-modal-header {
  background: var(--color-surface-elevated) !important;
  border-color: var(--color-border) !important;
}

.cm-modal-header h3 {
  color: var(--color-text) !important;
}

/* Form inputs in campaign manager */
.cm-form-group input,
.cm-form-group select,
.cm-form-group textarea {
  background: var(--color-surface) !important;
  color: var(--color-text) !important;
  border-color: var(--color-border) !important;
}

.cm-form-group label {
  color: var(--color-text) !important;
}

.cm-form-group small {
  color: var(--color-muted) !important;
}

/* History filters */
.cm-history-filters select {
  background: var(--color-surface) !important;
  color: var(--color-text) !important;
  border-color: var(--color-border) !important;
}

/* Cloud sync section */
.cloud-sync-section {
  background: var(--color-surface-elevated) !important;
  border-color: var(--color-border) !important;
}

.cloud-sync-section h3 {
  color: var(--color-text) !important;
}

/* Quick actions section */
.cm-quick-actions {
  background: var(--color-surface-elevated) !important;
  border-color: var(--color-border) !important;
}

.cm-quick-actions-header h4 {
  color: var(--color-primary) !important;
}

.cm-quick-actions-hint {
  color: var(--color-muted) !important;
}

.cm-quick-btn {
  background: var(--color-surface) !important;
  border-color: var(--color-border) !important;
  color: var(--color-text) !important;
}

.cm-quick-btn:hover {
  background: var(--color-surface-elevated) !important;
  border-color: var(--color-primary) !important;
}

/* Pinned items */
.cm-pinned-group {
  background: var(--color-surface-elevated) !important;
  border-color: var(--color-border) !important;
}

.cm-pinned-item {
  background: var(--color-surface) !important;
}

.cm-pinned-item:hover {
  background: var(--color-surface-elevated) !important;
}

.cm-pinned-label {
  color: var(--color-text) !important;
}

/* Welcome banner */
.cm-welcome-banner {
  background: var(--color-surface-elevated) !important;
  border-color: var(--color-border) !important;
}

.cm-welcome-content h3 {
  color: var(--color-primary) !important;
}

.cm-welcome-content p {
  color: var(--color-muted) !important;
}

/* Wizard styles */
.wizard-step-header h4 {
  color: var(--color-text) !important;
}

.wizard-step-header p {
  color: var(--color-muted) !important;
}

.wizard-preset-card {
  background: var(--color-surface-elevated) !important;
  border-color: var(--color-border) !important;
}

.wizard-preset-card:hover {
  background: var(--color-surface) !important;
}

.wizard-preset-label {
  color: var(--color-text) !important;
}

.wizard-preset-desc {
  color: var(--color-muted) !important;
}

.wizard-summary {
  background: var(--color-surface-elevated) !important;
}

.wizard-summary-label {
  color: var(--color-muted) !important;
}

.wizard-summary-value {
  color: var(--color-text) !important;
}

.wizard-what-creates {
  background: var(--color-surface-elevated) !important;
  border-color: var(--color-border) !important;
}

.wizard-what-creates ul {
  color: var(--color-text) !important;
}

/* GM Notes section */
.cm-gm-notes-section {
  background: var(--color-surface-elevated) !important;
  border-color: var(--color-border) !important;
}

.cm-gm-notes-input {
  background: var(--color-surface) !important;
  color: var(--color-text) !important;
  border-color: var(--color-border) !important;
}

/* Active and pinned states - override dark rgba backgrounds */
.cm-campaign-item.active {
  background: var(--color-surface-elevated) !important;
  border-color: var(--color-primary) !important;
}

.cm-history-entry.pinned {
  background: var(--color-surface-elevated) !important;
  border-color: var(--color-primary) !important;
}

/* D20 logo icon styling for theme awareness */
.d20-icon {
  color: var(--color-primary) !important;
}

.cm-welcome-icon,
.cm-empty-icon {
  color: var(--color-primary) !important;
}

/* Ensure empty states use theme colors */
.cm-empty {
  color: var(--color-muted) !important;
}

/* Session Dashboard no-campaign icon */
.no-campaign-icon {
  color: var(--color-muted) !important;
}

/* Entry result pre blocks */
.cm-entry-result pre {
  background: var(--color-surface-elevated) !important;
  color: var(--color-text) !important;
}

/* Wizard tagpacks list */
.wizard-tagpacks-list {
  background: var(--color-surface-elevated) !important;
}

/* Button overrides for campaign manager */
.campaign-manager .btn-secondary {
  background: var(--color-surface-elevated) !important;
  color: var(--color-text) !important;
  border-color: var(--color-border) !important;
}

.campaign-manager .btn-secondary:hover {
  background: var(--color-surface) !important;
}

/* =====================================================
   6. PRINT MEDIA QUERY IMPROVEMENTS
   ===================================================== */

@media print {
  .site-header,
  .nav-desktop,
  .nav-mobile,
  .hamburger,
  .mobile-bottom-nav {
    display: none !important;
  }
  
  body {
    padding: 0;
  }
  
  .app {
    max-width: 100%;
    padding: 0;
  }
}

/* =====================================================
   7. HELP VIEW STYLING
   ===================================================== */

.help-body {
  font-size: 0.875rem;
  line-height: 1.6;
}

.help-body h2 {
  margin: 1.25rem 0 0.5rem 0;
  font-size: 1.1rem;
  color: var(--color-text);
}

.help-body h3 {
  margin-top: 0.75rem;
  margin-bottom: 0.25rem;
  font-size: 1rem;
}

.help-body p {
  margin: 0 0 0.5rem 0;
}

.help-body .help-section {
  margin-bottom: 1.25rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--color-border);
}

.help-body .help-section:last-child {
  border-bottom: none;
  margin-bottom: 0;
}

.help-body .help-list {
  padding-left: 1.25rem;
  margin: 0.5rem 0;
}

.help-body .help-list li {
  margin-bottom: 0.35rem;
}

.help-body .help-flows {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1rem;
  margin-top: 0.75rem;
}

.help-body .help-flow-card {
  background: var(--color-surface-elevated);
  border-radius: 0.5rem;
  padding: 1rem;
  border: 1px solid var(--color-border);
}

.help-body .help-flow-card h3 {
  margin: 0 0 0.5rem 0;
  font-size: 0.95rem;
  color: var(--color-primary);
}

.help-body .help-tools-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.help-body .help-toggle-row {
  background: var(--color-surface-elevated);
  padding: 0.75rem;
  border-radius: 0.5rem;
  margin-top: 0.5rem;
}

.help-body .help-small {
  font-size: 0.8rem;
  color: var(--color-muted);
  margin-top: 0.25rem;
}

.help-body .help-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.help-body .help-action-btn {
  padding: 0.5rem 1rem;
  background: var(--color-surface-elevated);
  border: 1px solid var(--color-border);
  border-radius: 0.375rem;
  color: var(--color-text);
  cursor: pointer;
  font-size: 0.85rem;
  transition: background 0.15s;
}

.help-body .help-action-btn:hover {
  background: var(--color-surface);
  border-color: var(--color-primary);
}

/* =====================================================
   8. BUG REPORT VIEW STYLING
   ===================================================== */

.bugreport-body {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  font-size: 0.875rem;
}

.bugreport-body .bug-section {
  margin-bottom: 0.5rem;
}

.bugreport-body .bug-section h2 {
  font-size: 1rem;
  margin: 0 0 0.5rem 0;
  color: var(--color-text);
}

.bugreport-body .bug-row {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  margin-bottom: 0.75rem;
}

.bugreport-body .bug-row label {
  font-weight: 500;
  font-size: 0.85rem;
  color: var(--color-text);
}

.bugreport-body .bug-row input,
.bugreport-body .bug-row select,
.bugreport-body .bug-row textarea {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--color-border);
  border-radius: 0.375rem;
  background: var(--color-surface);
  color: var(--color-text);
  font-size: 0.875rem;
}

.bugreport-body .bug-small {
  font-size: 0.8rem;
  color: var(--color-muted);
  margin: 0.25rem 0;
}

.bugreport-body .bug-env-preview,
.bugreport-body #bugEnvPreview {
  max-height: 180px;
  overflow-y: auto;
  font-size: 0.75rem;
  background: rgba(15,23,42,0.9);
  color: #e2e8f0;
  border-radius: 0.375rem;
  padding: 0.75rem;
  white-space: pre-wrap;
  word-break: break-word;
}

.bugreport-body .bug-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.bugreport-body .bug-status-label {
  font-size: 0.8rem;
  color: var(--color-muted);
}

/* =====================================================
   9. FACTIONS VIEW STYLING
   ===================================================== */

.factions-topbar-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
}

.factions-topbar-controls label {
  color: var(--color-muted);
}

.factions-topbar-controls select {
  min-width: 150px;
}

.factions-summary-label {
  color: var(--color-muted);
  font-size: 0.8rem;
}

.factions-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.5fr) minmax(0, 1.5fr);
  gap: 0.75rem;
}

@media (max-width: 1100px) {
  .factions-layout {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }
  
  .factions-graph-card {
    grid-column: 1 / -1;
  }
}

@media (max-width: 700px) {
  .factions-layout {
    grid-template-columns: minmax(0, 1fr);
  }
  
  .factions-topbar-controls {
    width: 100%;
    justify-content: flex-start;
  }
}

.factions-list-card,
.factions-detail-card,
.factions-graph-card {
  min-height: 200px;
}

.factions-graph-overlay {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: var(--color-muted);
  font-size: 0.85rem;
  text-align: center;
}

/* =====================================================
   10. REGION MAP VIEW STYLING
   ===================================================== */

.region-map-wrapper {
  width: 100%;
  min-height: calc(100vh - 200px);
}

#regionMapContainer {
  width: 100%;
}

/* Region map already has its own CSS, just ensure it respects containers */
.region-map-layout {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
  gap: 0.75rem;
  align-items: stretch;
}

.region-map-pane {
  min-height: 300px;
  overflow: hidden;
}

.region-sidebar {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-height: calc(100vh - 200px);
  overflow-y: auto;
}

@media (max-width: 900px) {
  .region-map-layout {
    grid-template-columns: minmax(0, 1fr);
  }
  
  .region-sidebar {
    max-height: none;
  }
}

/* =====================================================
   11. GMG ERROR TOAST STYLING
   ===================================================== */

.gmg-error-toast {
  background: rgba(248,113,113,0.95);
  color: #111827;
  border-radius: 0.5rem;
  padding: 0.45rem 0.6rem;
  font-size: 0.8rem;
  box-shadow: 0 8px 24px rgba(0,0,0,0.45);
  max-width: 260px;
  transform: translateY(0);
  opacity: 1;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.gmg-error-toast--hide {
  opacity: 0;
  transform: translateY(6px);
}

.gmg-error-toast--warning {
  background: rgba(251,191,36,0.95);
  color: #1f2937;
}

.gmg-error-toast--success {
  background: rgba(52,211,153,0.95);
  color: #111827;
}

.gmg-error-title {
  font-weight: 600;
  margin-bottom: 0.15rem;
}

.gmg-error-message {
  line-height: 1.4;
}

/* =====================================================
   12. GMG LOADING OVERLAY STYLING
   ===================================================== */

.gmg-loading-overlay {
  position: absolute;
  inset: 0;
  background: rgba(15,23,42,0.75);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  z-index: 999;
  pointer-events: none;
  border-radius: inherit;
}

.gmg-loading-spinner {
  width: 28px;
  height: 28px;
  border-radius: 999px;
  border: 3px solid rgba(148,163,184,0.6);
  border-top-color: rgba(248,250,252,0.95);
  animation: gmg-spin 0.7s linear infinite;
  margin-bottom: 0.35rem;
}

.gmg-loading-label {
  font-size: 0.8rem;
  opacity: 0.9;
  color: #f8fafc;
}

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

/* =====================================================
   13. ACCESSIBILITY FOCUS STYLING
   ===================================================== */

button:focus,
.hub-tile:focus,
.btn:focus,
a:focus {
  outline: 2px solid #60a5fa !important;
  outline-offset: 2px;
}

button:focus-visible,
.hub-tile:focus-visible,
.btn:focus-visible,
a:focus-visible {
  outline: 2px solid #93c5fd !important;
  outline-offset: 2px;
}

/* Ensure clickable elements show focus */
.session-prep-step:focus,
.gm-module-header:focus,
.em-modal-item:focus,
.cm-campaign-info:focus,
.cm-pinned-item:focus,
.region-poi-item:focus {
  outline: 2px solid #60a5fa !important;
  outline-offset: 2px;
}

/* Remove focus on mouse click but keep for keyboard */
button:focus:not(:focus-visible),
a:focus:not(:focus-visible) {
  outline: none !important;
}

/* Button styling for converted accessibility elements */
button.session-prep-step,
button.gm-module-header,
button.gms-module-option,
button.em-modal-item,
button.cm-campaign-info,
button.cm-pinned-item,
button.region-poi-item {
  appearance: none;
  -webkit-appearance: none;
  background: inherit;
  border: none;
  text-align: left;
  width: 100%;
  cursor: pointer;
  font: inherit;
  color: inherit;
  padding: inherit;
}

button.gm-module-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

button.session-prep-step {
  display: flex;
  align-items: center;
  gap: 1rem;
}

/* =====================================================
   14. DEV PERFORMANCE PANEL
   ===================================================== */

#gmgPerfPanel {
  position: fixed;
  left: 0.5rem;
  bottom: 0.5rem;
  z-index: 9998;
  max-width: 260px;
  max-height: 40vh;
  overflow-y: auto;
  font-size: 0.7rem;
  background: rgba(15,23,42,0.95);
  color: #e5e7eb;
  border-radius: 0.5rem;
  padding: 0.5rem;
  box-shadow: 0 10px 30px rgba(0,0,0,0.6);
  font-family: 'JetBrains Mono', monospace;
}

#gmgPerfPanel div {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* =====================================================
   15. MOBILE & TABLET LAYOUT HARDENING (Beta Polish)
   ===================================================== */

/* A1: Standard breakpoints & container widths */
.app {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0.5rem;
  box-sizing: border-box;
}

@media (max-width: 1024px) {
  .hub-grid {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) !important;
  }
  
  .factions-layout,
  .region-layout,
  .region-map-layout,
  .session-layout,
  .gm-screen-layout {
    grid-template-columns: minmax(0, 1fr) !important;
  }
  
  .pack-builder-layout,
  .encounter-manager-layout,
  .character-sheets-layout {
    grid-template-columns: minmax(0, 1fr) !important;
  }
}

@media (max-width: 768px) {
  .hub-grid {
    grid-template-columns: minmax(0, 1fr) !important;
  }
  
  .card {
    margin-bottom: 0.5rem;
  }
  
  .app {
    padding: 0.25rem;
  }
}

/* A2: Scrollable panels - height-limited instead of whole page */
.scroll-panel {
  max-height: calc(100vh - 160px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

#factionsListContainer,
#regionPoisContainer,
.session-log-entries,
.em-encounter-list,
.pack-preview-list,
.character-list-container {
  max-height: calc(100vh - 200px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

@media (max-width: 768px) {
  .scroll-panel,
  #factionsListContainer,
  #regionPoisContainer,
  .session-log-entries,
  .em-encounter-list,
  .pack-preview-list,
  .character-list-container {
    max-height: 50vh;
  }
}

/* A3: Tap target size & spacing for touch devices */
.btn,
.hub-tile,
button {
  min-height: 2.25rem;
}

.hub-tile {
  padding: 0.9rem;
}

.hub-tile h2 {
  font-size: 1rem;
}

@media (max-width: 768px) {
  .btn,
  .hub-tile,
  button {
    min-height: 2.75rem;
    padding: 0.5rem 0.75rem;
  }
  
  .hub-tile {
    padding: 1rem;
  }
  
  .player-view-footer-btns .btn,
  .gm-screen-controls .btn,
  .session-header-actions .btn,
  .pack-toolbar .btn {
    min-height: 2.75rem;
    min-width: 2.75rem;
    padding: 0.5rem;
  }
}

/* A4: Avoid 100vh pitfalls on mobile */
.full-height-panel {
  min-height: calc(100vh - 120px);
  height: auto;
}

.session-dashboard,
.gm-screen-container,
.encounter-manager-container {
  min-height: calc(100vh - 60px);
  height: auto;
}

@media (max-width: 768px) {
  .session-dashboard,
  .gm-screen-container,
  .encounter-manager-container {
    min-height: calc(100vh - 120px);
  }
}

/* Prevent horizontal scrolling on tablet widths */
@media (max-width: 1024px) {
  body {
    overflow-x: hidden;
  }
  
  .app,
  .main-content,
  main {
    max-width: 100vw;
    overflow-x: hidden;
  }
}

/* =====================================================
   BETA BUILD STATUS STRIP
   ===================================================== */

#gmgStatusStrip {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.25rem 0.5rem;
  background: rgba(15, 23, 42, 0.96);
  color: #e5e7eb;
  border-bottom: 1px solid rgba(148, 163, 184, 0.4);
  font-size: 0.75rem;
}

#gmgStatusStrip .btn-xs {
  font-size: 0.75rem;
  padding: 0.15rem 0.4rem;
}

#gmgStatusBuild {
  font-weight: 600;
  color: var(--accent-teal, #14b8a6);
}

#gmgStatusContext {
  flex: 1;
  text-align: center;
  opacity: 0.85;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (max-width: 600px) {
  #gmgStatusStrip {
    font-size: 0.65rem;
    padding: 0.2rem 0.35rem;
  }
  
  #gmgStatusContext {
    display: none;
  }
}

/* Beta Scenario Harness cards */
.beta-scenario-card {
  margin-bottom: 1rem;
}

.beta-scenario-card h3 {
  font-size: 1rem;
  margin: 0 0 0.5rem 0;
}

.beta-scenario-card ol {
  margin: 0.25rem 0 0.5rem 0;
}

.beta-scenario-card code {
  background: rgba(148, 163, 184, 0.2);
  padding: 0.1rem 0.3rem;
  border-radius: 4px;
  font-size: 0.7rem;
}

/* =====================================================
   HERO SECTION LAYOUT FIXES
   Prevent image from overlapping text
   ===================================================== */

.hero-section-new {
  overflow: visible !important;
  position: relative;
}

/* Ensure content doesn't get cut off by mascot */
.hero-content-new {
  flex-shrink: 0 !important;
  min-width: 0;
  word-wrap: break-word;
  z-index: 2;
  position: relative;
}

/* Mascot should shrink, not overlap content */
.hero-mascot-new {
  flex-shrink: 1 !important;
  min-width: 150px;
  position: relative;
  z-index: 1;
}

/* On desktop, prevent overlap with strict sizing */
@media (min-width: 768px) {
  .hero-section-new {
    flex-wrap: nowrap;
    overflow: visible !important;
    gap: 1.5rem !important;
    justify-content: space-between !important;
  }
  
  .hero-content-new {
    flex: 1 0 auto !important;
    min-width: 320px;
    max-width: 50% !important;
  }
  
  .hero-mascot-new {
    flex: 0 1 280px !important;
    max-width: 280px !important;
    width: 280px !important;
    height: 280px !important;
  }
}

@media (min-width: 1024px) {
  .hero-content-new {
    max-width: 55% !important;
  }
  
  .hero-mascot-new {
    flex: 0 1 320px !important;
    max-width: 320px !important;
    width: 320px !important;
    height: 320px !important;
  }
}

@media (min-width: 1280px) {
  .hero-mascot-new {
    flex: 0 1 380px !important;
    max-width: 380px !important;
    width: 380px !important;
    height: 380px !important;
  }
}

/* =====================================================
   DROPDOWN MENU Z-INDEX FIX
   Ensure dropdowns appear above all content
   ===================================================== */

.nav-dropdown {
  position: relative;
  z-index: 9999;
}

.nav-dropdown-menu {
  z-index: 99999 !important;
  position: absolute !important;
  display: block !important;
}

/* Queue tray dropdown fix */
.queue-tray {
  position: relative !important;
  z-index: 9999 !important;
}

.queue-tray-dropdown {
  z-index: 99999 !important;
  pointer-events: auto !important;
}

.queue-tray-dropdown * {
  pointer-events: auto !important;
}

.queue-job-view-btn,
.queue-job-cancel-btn {
  pointer-events: auto !important;
  cursor: pointer !important;
  position: relative !important;
  z-index: 100000 !important;
}

/* Ensure header and nav allow overflow for dropdowns */
.site-header,
header,
.header,
nav,
.nav-desktop,
.nav-dev-section {
  overflow: visible !important;
}

/* Build status strip shouldn't block dropdowns */
#gmgStatusStrip,
.global-build-status {
  z-index: 900;
}

/* System/genre bar shouldn't block dropdowns */
#globalSystemGenreBar {
  z-index: 800;
}

/* =====================================================
   QUICKSTART STEPS HORIZONTAL LAYOUT FIX
   Prevent cutoff on Prep Hub "Next Steps" section
   ===================================================== */

/* Override horizontal layout to wrap or scroll */
@media (min-width: 768px) {
  .quickstart-steps {
    flex-wrap: wrap !important;
    overflow-x: visible !important;
  }
  
  .quickstart-step {
    flex: 1 1 200px !important;
    min-width: 180px;
    max-width: 250px;
  }
}

/* Container should not clip content */
#prepNextStepsCard .card-body,
#playNextStepsCard .card-body {
  overflow: visible;
}

/* =====================================================
   CAMPAIGN MANAGER PANEL FIXES
   Prevent button/text cutoff
   ===================================================== */

.cm-campaigns-panel,
.cm-detail-panel {
  overflow: visible;
}

.cm-campaigns-panel .card-header,
.cm-campaign-item {
  overflow: visible;
  min-width: 0;
}

/* New Campaign button should not be cut off */
.cm-campaigns-panel button,
.cm-campaign-item button {
  white-space: nowrap;
  flex-shrink: 0;
}

/* Allow text to wrap in campaign items */
.cm-campaign-item .campaign-title,
.cm-campaign-item h4 {
  word-wrap: break-word;
  overflow-wrap: break-word;
  min-width: 0;
}

/* =====================================================
   CHARACTER SHEETS THEME FIXES
   Ensure proper light/dark mode styling
   ===================================================== */

#characterSheetsView {
  --card-bg: var(--color-surface, #1a1a2e);
  --input-bg: var(--color-surface-elevated, #0f0f1a);
  --hover-bg: var(--color-surface-hover, #252540);
  --text-color: var(--color-text, #e5e7eb);
  --border-color: var(--color-border, #334155);
}

#characterSheetsView .cs-header,
#characterSheetsView .cs-controls,
#characterSheetsView .cs-main {
  background: var(--color-surface) !important;
  color: var(--color-text) !important;
  border-color: var(--color-border) !important;
}

#characterSheetsView select,
#characterSheetsView input {
  background: var(--color-surface-elevated, var(--color-surface)) !important;
  color: var(--color-text) !important;
  border-color: var(--color-border) !important;
}

#characterSheetsView .character-card,
#characterSheetsView .cs-character-item {
  background: var(--color-surface) !important;
  color: var(--color-text) !important;
  border-color: var(--color-border) !important;
}

#characterSheetsView .character-card:hover,
#characterSheetsView .cs-character-item:hover {
  background: var(--color-surface-hover) !important;
}

/* Character wizard also needs theme fixes */
#characterWizardView .cs-header,
#characterWizardView .cs-controls,
#characterWizardView .cs-main {
  background: var(--color-surface) !important;
  color: var(--color-text) !important;
}

#characterWizardView select,
#characterWizardView input,
#characterWizardView textarea {
  background: var(--color-surface-elevated, var(--color-surface)) !important;
  color: var(--color-text) !important;
  border-color: var(--color-border) !important;
}

/* =====================================================
   GLOBAL THEME FIXES FOR ALL DYNAMIC VIEWS
   Override hardcoded dark colors with theme variables
   ===================================================== */

/* Define CSS variable fallbacks for dynamically rendered content */
:root {
  --card-bg: var(--color-surface);
  --input-bg: var(--color-surface-elevated);
  --hover-bg: var(--color-surface-hover);
  --text-color: var(--color-text);
  --border-color: var(--color-border);
}

/* GM Screen theme fixes */
#gmScreenView,
#gmScreenView .gm-widget,
#gmScreenView .gm-panel {
  background: var(--color-surface) !important;
  color: var(--color-text) !important;
  border-color: var(--color-border) !important;
}

/* Encounter Manager theme fixes */
#encounterManagerView,
#encounterManagerView .em-panel,
#encounterManagerView .em-encounter-card {
  background: var(--color-surface) !important;
  color: var(--color-text) !important;
  border-color: var(--color-border) !important;
}

#encounterManagerView select,
#encounterManagerView input {
  background: var(--color-surface-elevated, var(--color-surface)) !important;
  color: var(--color-text) !important;
  border-color: var(--color-border) !important;
}

/* Campaign Dashboard theme fixes */
#campaignView,
#campaignView .campaign-panel,
#campaignView .campaign-card {
  background: var(--color-surface) !important;
  color: var(--color-text) !important;
  border-color: var(--color-border) !important;
}

/* Battle Map theme fixes */
#battleMapView .bm-toolbar,
#battleMapView .bm-sidebar {
  background: var(--color-surface) !important;
  color: var(--color-text) !important;
  border-color: var(--color-border) !important;
}

/* Player View theme fixes */
#playerView .pv-content,
#playerView .pv-display-card {
  background: var(--color-surface) !important;
  color: var(--color-text) !important;
}

/* Session Dashboard theme fixes */
#sessionDashboardView,
#sessionDashboardView .sd-panel,
#sessionDashboardView .sd-card {
  background: var(--color-surface) !important;
  color: var(--color-text) !important;
  border-color: var(--color-border) !important;
}

/* Factions View theme fixes */
#factionsView,
#factionsView .faction-card,
#factionsView .faction-panel {
  background: var(--color-surface) !important;
  color: var(--color-text) !important;
  border-color: var(--color-border) !important;
}

/* Session Log theme fixes */
#sessionLogView,
#sessionLogView .session-entry,
#sessionLogView .session-card {
  background: var(--color-surface) !important;
  color: var(--color-text) !important;
  border-color: var(--color-border) !important;
}

/* Dev Tools theme fixes */
#devToolsView,
#devToolsView .dev-panel,
#devToolsView .dev-card {
  background: var(--color-surface) !important;
  color: var(--color-text) !important;
  border-color: var(--color-border) !important;
}

/* Pack Builder/QA theme fixes */
#packQaView,
#packQaView .pack-panel {
  background: var(--color-surface) !important;
  color: var(--color-text) !important;
  border-color: var(--color-border) !important;
}

/* Hub Views theme fixes */
#prepHubView,
#playHubView,
#worldHubView {
  background: var(--color-background) !important;
}

#prepHubView .hub-tile,
#playHubView .hub-tile,
#worldHubView .hub-tile {
  background: var(--color-surface) !important;
  color: var(--color-text) !important;
  border-color: var(--color-border) !important;
}

/* Save/Load View theme fixes */
#saveLoadView,
#saveLoadView .save-slot,
#saveLoadView .save-card {
  background: var(--color-surface) !important;
  color: var(--color-text) !important;
  border-color: var(--color-border) !important;
}

/* Help View theme fixes */
#helpView,
#helpView .help-section,
#helpView .help-card {
  background: var(--color-surface) !important;
  color: var(--color-text) !important;
  border-color: var(--color-border) !important;
}

/* Region Map theme fixes */
#regionMapView,
#regionMapView .region-panel,
#regionMapView .poi-card {
  background: var(--color-surface) !important;
  color: var(--color-text) !important;
  border-color: var(--color-border) !important;
}

/* Library/Gallery views theme fixes */
#libraryView .gallery-card,
#libraryView .item-card {
  background: var(--color-surface) !important;
  color: var(--color-text) !important;
  border-color: var(--color-border) !important;
}

/* Generic dynamic content selectors */
[style*="background: #1e293b"],
[style*="background: #0f172a"],
[style*="background: #1a1a2e"],
[style*="background:#1e293b"],
[style*="background:#0f172a"],
[style*="background:#1a1a2e"] {
  background: var(--color-surface) !important;
}

/* Forms and inputs in all views */
.app select,
.app input[type="text"],
.app input[type="email"],
.app input[type="number"],
.app textarea {
  background: var(--color-surface-elevated, var(--color-surface)) !important;
  color: var(--color-text) !important;
  border-color: var(--color-border) !important;
}

/* Buttons with hardcoded backgrounds - keep accent colors */
.app button.btn-primary,
.app button[style*="background: #14B8A6"],
.app button[style*="background:#14B8A6"] {
  background: var(--color-primary, #14B8A6) !important;
}

/* Cards and panels in all views */
.app .card,
.app .panel {
  background: var(--color-surface) !important;
  color: var(--color-text) !important;
  border-color: var(--color-border) !important;
}
