/* Mobile-specific styles for Tapestry Crochet App */

/* Mobile styles (up to 767px) */
@media screen and (max-width: 767px) {

  /* Force mobile body to scroll */
  * {
    -webkit-overflow-scrolling: touch !important;
  }

  html {
    height: auto !important;
    overflow-y: scroll !important;
    -webkit-overflow-scrolling: touch !important;
  }

  body {
    height: auto !important;
    overflow-y: scroll !important;
    -webkit-overflow-scrolling: touch !important;
    position: relative !important;
  }

  /* Welcome page mobile complete override */
  #welcomePage,
  .welcome-page {
    position: static !important;
    height: auto !important;
    min-height: 100vh !important;
    max-height: none !important;
    display: block !important;
    overflow: visible !important;
    -webkit-overflow-scrolling: touch !important;
    padding: 2rem 1rem !important;
  }

  .welcome-page {
    align-items: unset !important;
    justify-content: unset !important;
  }

  .welcome-content {
    width: 100% !important;
    max-width: none !important;
    margin: 0 auto !important;
    padding: 0 1rem !important;
    flex-shrink: unset !important;
    display: block !important;
  }

  .welcome-header {
    margin-bottom: 2rem;
  }

  .welcome-logo {
    width: 60px;
    height: 60px;
  }

  .studio-title {
    font-size: 2.5rem;
    line-height: 1.2;
  }

  .studio-tagline {
    font-size: 1.1rem;
    padding: 0 var(--space-4);
  }

  .welcome-features {
    margin-bottom: 2rem;
  }

  .feature-grid {
    grid-template-columns: 1fr;
    gap: 1rem;
    margin-top: 1rem;
  }

  .feature-card {
    padding: 1.5rem;
  }

  .feature-icon {
    font-size: 2.5rem;
  }

  .feature-card h3 {
    font-size: 1.1rem;
  }

  .feature-card p {
    font-size: 0.9rem;
    line-height: 1.5;
  }

  .welcome-actions {
    margin-bottom: 2rem;
  }

  .btn-large {
    width: 100%;
    padding: 1rem;
    font-size: 1.1rem;
  }

  .welcome-info p {
    font-size: 1rem;
    padding: 0 var(--space-4);
  }

  .welcome-footer {
    padding-bottom: var(--space-6);
  }

  .studio-url {
    font-size: 1.2rem;
  }

  .copyright {
    font-size: 0.8rem;
    padding: 0 var(--space-4);
    text-align: center;
  }

  /* Header adjustments */
  .header-content {
    padding: var(--space-3);
  }

  .app-title {
    font-size: var(--font-size-lg);
  }

  /* Show mobile menu toggle */
  .menu-toggle {
    display: flex;
    order: 1;
  }

  .user-actions {
    position: absolute;
    top: 100%;
    right: 0;
    left: 0;
    background-color: var(--white);
    border-top: 1px solid var(--gray-200);
    box-shadow: var(--shadow-lg);
    padding: var(--space-4);
    flex-direction: column;
    transform: translateY(-100%);
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
  }

  .user-actions.active {
    transform: translateY(0);
    opacity: 1;
    visibility: visible;
  }

  .user-actions .btn {
    width: 100%;
    justify-content: center;
  }

  /* Mobile layout - stack vertically */
  .app-main {
    flex-direction: column;
  }

  /* Control panel becomes slide-out on mobile */
  .control-panel {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100vh;
    z-index: 200;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    max-height: none;
    overflow-y: auto;
    padding-top: calc(60px + var(--space-6)); /* Account for header height */
  }

  .control-panel.active,
  .control-panel:not(.collapsed) {
    transform: translateX(0);
  }

  /* Control panel overlay */
  .control-panel-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100vh;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 199;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
  }

  .control-panel-overlay.active {
    opacity: 1;
    visibility: visible;
  }

  /* Display area takes full width on mobile */
  .display-area {
    width: 100%;
    min-height: calc(100vh - 120px); /* Account for header and status bar */
  }

  /* Color panel becomes slide-out on mobile */
  .color-panel {
    position: fixed;
    top: 0;
    right: 0;
    width: 100%;
    height: 100vh;
    z-index: 200;
    transform: translateX(100%);
    transition: transform 0.3s ease;
    max-height: none;
    overflow-y: auto;
    padding-top: calc(60px + var(--space-6)); /* Account for header height */
  }

  .color-panel.active,
  .color-panel:not(.collapsed) {
    transform: translateX(0);
  }

  /* Color panel overlay */
  .color-panel-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100vh;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 199;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
  }

  .color-panel-overlay.active {
    opacity: 1;
    visibility: visible;
  }

  /* Toolbar adjustments for mobile */
  .display-toolbar {
    flex-wrap: wrap;
    gap: var(--space-2);
    padding: var(--space-3);
  }

  .view-modes {
    order: 2;
    width: 100%;
    justify-content: center;
  }

  .zoom-controls {
    order: 1;
  }

  /* Canvas container adjustments */
  .canvas-container {
    padding: var(--space-2);
  }

  .main-canvas {
    touch-action: pan-x pan-y; /* Enable touch scrolling */
  }

  /* Status bar stacks on mobile */
  .status-bar {
    flex-direction: column;
    gap: var(--space-3);
    padding: var(--space-3);
  }

  .status-info {
    width: 100%;
    justify-content: space-around;
    flex-wrap: wrap;
    gap: var(--space-3);
  }

  .pattern-actions {
    width: 100%;
    justify-content: center;
  }

  /* Form adjustments for mobile */
  .grid-inputs {
    grid-template-columns: 1fr;
  }

  .aspect-ratio-buttons {
    grid-template-columns: repeat(4, 1fr);
    gap: var(--space-1);
  }

  /* Panel sections spacing */
  .panel-section {
    margin-bottom: var(--space-3);
  }

  /* Upload button larger touch targets */
  .upload-btn {
    padding: var(--space-4);
    min-height: 56px;
  }

  .upload-btn .upload-icon {
    font-size: var(--font-size-xl);
  }

  /* Slider adjustments for touch */
  .slider-group {
    flex-direction: column;
    align-items: stretch;
    gap: var(--space-2);
  }

  .slider-group label {
    margin-bottom: var(--space-1);
  }

  input[type="range"] {
    height: 8px; /* Larger for touch */
  }

  input[type="range"]::-webkit-slider-thumb {
    width: 24px;
    height: 24px;
  }

  input[type="range"]::-moz-range-thumb {
    width: 24px;
    height: 24px;
  }

  /* Color palette larger swatches */
  .color-palette {
    grid-template-columns: repeat(auto-fill, minmax(50px, 1fr));
  }

  .color-swatch {
    width: 50px;
    height: 50px;
  }

  /* Modal adjustments */
  .modal {
    padding: var(--space-2);
  }

  .modal-content {
    max-height: 95vh;
  }

  .modal-header {
    padding: var(--space-4);
  }

  .modal-body {
    padding: var(--space-4);
  }

  /* Button adjustments for touch */
  .btn {
    min-height: 48px; /* Larger touch target */
    padding: var(--space-4) var(--space-5);
  }

  .btn-small {
    min-height: 40px;
    padding: var(--space-3) var(--space-4);
  }

  /* Hide some elements on mobile to save space */
  .slider-value {
    display: none;
  }
}

/* Tablet styles (768px to 1023px) */
@media (min-width: 768px) and (max-width: 1023px) {

  /* Welcome page tablet adjustments */
  .welcome-page {
    padding: var(--space-4) 0;
  }

  .studio-title {
    font-size: 3rem;
  }

  .feature-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 1.5rem;
  }

  .btn-large {
    width: auto;
    padding: 1rem 2rem;
  }

  /* Control panel smaller on tablet */
  .control-panel {
    width: 280px;
    min-width: 280px;
  }

  /* Grid inputs side by side on tablet */
  .grid-inputs {
    grid-template-columns: 1fr 1fr;
  }

  /* Aspect ratio buttons in 2x2 grid */
  .aspect-ratio-buttons {
    grid-template-columns: repeat(2, 1fr);
  }

  /* Status bar horizontal layout */
  .status-bar {
    flex-direction: row;
  }

  /* Color palette smaller swatches */
  .color-palette {
    grid-template-columns: repeat(auto-fill, minmax(35px, 1fr));
  }

  .color-swatch {
    width: 35px;
    height: 35px;
  }
}

/* Safe area support for devices with notches */
@supports (padding: max(0px)) {
  .welcome-page {
    padding-left: max(var(--space-4), env(safe-area-inset-left));
    padding-right: max(var(--space-4), env(safe-area-inset-right));
    padding-top: max(var(--space-4), env(safe-area-inset-top));
    padding-bottom: max(var(--space-4), env(safe-area-inset-bottom));
  }
}

/* Very small screens (up to 375px) */
@media (max-width: 375px) {
  .welcome-page {
    padding: var(--space-4) 0;
  }

  .studio-title {
    font-size: 2rem;
  }

  .studio-tagline {
    font-size: 1rem;
    padding: 0 var(--space-2);
  }

  .feature-card {
    padding: 1rem;
  }

  .welcome-info p {
    padding: 0 var(--space-2);
  }

  .copyright {
    padding: 0 var(--space-2);
  }
}

/* Touch device specific styles */
@media (hover: none) and (pointer: coarse) {

  /* Force scrolling on touch devices */
  html, body {
    overflow-y: scroll !important;
    -webkit-overflow-scrolling: touch;
    height: auto !important;
  }

  .welcome-page {
    position: relative !important;
    height: auto !important;
    min-height: 100vh;
    overflow: visible !important;
    align-items: flex-start !important;
  }

  /* Welcome page touch optimizations */
  .btn-large {
    min-height: 48px;
    touch-action: manipulation;
  }

  .feature-card {
    touch-action: manipulation;
  }

  /* Remove hover effects on touch devices */
  .btn:hover,
  .upload-btn:hover,
  .color-swatch:hover {
    transform: none;
    background-color: initial;
    border-color: initial;
  }

  .feature-card:hover {
    transform: none;
    background: rgba(255, 255, 255, 0.1);
  }

  /* Add active states for touch feedback */
  .btn:active {
    transform: scale(0.98);
  }

  .color-swatch:active {
    transform: scale(0.95);
  }

  .upload-btn:active {
    background-color: var(--gray-100);
  }
}

/* Landscape orientation adjustments */
@media (max-width: 767px) and (orientation: landscape) {

  /* Welcome page landscape optimizations */
  .welcome-page {
    padding: var(--space-4) 0;
  }

  .welcome-header {
    margin-bottom: 1rem;
  }

  .welcome-logo {
    width: 50px;
    height: 50px;
  }

  .studio-title {
    font-size: 2rem;
  }

  .studio-tagline {
    font-size: 1rem;
  }

  .welcome-features {
    margin-bottom: 1.5rem;
  }

  .feature-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
  }

  .feature-card {
    padding: 1rem;
  }

  .feature-icon {
    font-size: 2rem;
    margin-bottom: 0.5rem;
  }

  .feature-card h3 {
    font-size: 1rem;
    margin-bottom: 0.5rem;
  }

  .feature-card p {
    font-size: 0.8rem;
  }

  .welcome-actions {
    margin-bottom: 1rem;
  }

  .btn-large {
    padding: 0.8rem 1.5rem;
    font-size: 1rem;
  }

  .welcome-footer {
    padding-bottom: var(--space-4);
  }

  /* Smaller header in landscape */
  .app-header {
    padding: var(--space-2) 0;
  }

  .header-content {
    padding: var(--space-2) var(--space-3);
  }

  /* Control panel slides from left in landscape */
  .control-panel {
    width: 320px;
    padding-top: calc(50px + var(--space-4));
  }

  /* Status bar more compact in landscape */
  .status-bar {
    padding: var(--space-2) var(--space-3);
  }

  /* Display area adjustments */
  .display-area {
    min-height: calc(100vh - 100px);
  }
}

/* High DPI displays */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {

  /* Ensure crisp borders on high DPI */
  .btn,
  .modal-content,
  .control-panel,
  .main-canvas {
    border-width: 0.5px;
  }
}

/* Accessibility - Prefers reduced motion */
@media (prefers-reduced-motion: reduce) {

  /* Disable animations for users who prefer reduced motion */
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  .spinner {
    animation: none;
  }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {

  :root {
    --white: #1f2937;
    --gray-50: #111827;
    --gray-100: #1f2937;
    --gray-200: #374151;
    --gray-300: #4b5563;
    --gray-400: #6b7280;
    --gray-500: #9ca3af;
    --gray-600: #d1d5db;
    --gray-700: #e5e7eb;
    --gray-800: #f3f4f6;
    --gray-900: #f9fafb;
  }

  body {
    background-color: var(--gray-50);
    color: var(--gray-900);
  }
}

/* Mobile Bottom Menu */
.mobile-bottom-menu {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--gray-200);
  display: none;
  flex-direction: row;
  justify-content: space-around;
  padding: 8px;
  z-index: 300;
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.1);
}

.mobile-menu-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.3s ease;
  min-width: 60px;
  min-height: 56px;
}

.mobile-menu-btn:hover {
  background: var(--gray-100);
  transform: translateY(-1px);
}

.mobile-menu-btn:active {
  transform: translateY(0);
  background: var(--gray-200);
}

.mobile-menu-btn.active {
  background: #e0e7ff !important; /* Light indigo background when panel is open */
}

.mobile-menu-btn.active .menu-label {
  color: #4f46e5 !important; /* Indigo text when active */
  font-weight: 600;
}

.menu-icon {
  font-size: 1.5rem;
  margin-bottom: 2px;
}

.menu-label {
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--gray-600);
}

/* Show mobile bottom menu on mobile screens */
@media (max-width: 767px) {
  .mobile-bottom-menu {
    display: flex;
  }

  /* Hide existing fixed toggle buttons on mobile */
  .control-panel-toggle-fixed,
  .color-panel-toggle-fixed {
    display: none !important;
  }

  /* Adjust display area to account for bottom menu */
  .display-area {
    min-height: calc(100vh - 120px - 60px); /* Header + Status + Bottom Menu */
    padding-bottom: 70px; /* Space for bottom menu */
  }

  /* Adjust status bar to not overlap with bottom menu */
  .status-bar {
    margin-bottom: 60px;
  }
}