/**
 * DJ Booth Mobile Responsive Layouts
 * Three-layout switching: Desktop, Mobile-Landscape, Mobile-Portrait
 * CSS-first approach with media queries
 */

/* ==============================================================
   CSS CUSTOM PROPERTIES (Tokens)
   ============================================================== */
:root {
  /* Mobile-landscape band heights */
  --band-a-height: 48px;
  --band-b-height: 62px;
  --band-c-height: 100px;
  --band-d-height: 135px;

  /* Spacing */
  --band-gap: 8px;
  --band-padding: 6px 12px;

  /* Component sizes (mobile-landscape) */
  --jog-size: 72px;
  --vu-height: 16px;
  --vu-width: 8px;
  --crossfader-height: 38px;
  --fader-track-width: 8px;
  --fader-track-height: 80px;
  --fader-cap-size: 16px;

  /* Typography */
  --hud-font-large: 20px;
  --hud-font-medium: 14px;
  --hud-font-small: 11px;
  --label-font: 10px;

  /* Touch targets */
  --min-touch-height: 44px;
}

/* ==============================================================
   BASE STYLES (Mobile-first = Portrait)
   Portrait: max-width: 1023px AND orientation: portrait
   ============================================================== */

/* Rotate notice styling (shown/hidden by media queries and JS) */
.rotate-notice {
  display: none; /* Hidden by default, shown in portrait MQ */
  position: relative;
  width: 100%;
  background: linear-gradient(135deg, #ff6b35 0%, #f7931e 100%);
  border-radius: 12px;
  padding: 16px 20px;
  margin-bottom: 16px;
  box-shadow: 0 4px 12px rgba(255, 107, 53, 0.3);
  color: #fff;
  text-align: center;
}

.rotate-notice.dismissed {
  display: none !important;
}

/* Bulletproof: ensure rotate notice is hidden in landscape/desktop via JS classes */
.js-landscape .rotate-notice,
.js-desktop .rotate-notice {
  display: none !important;
}

.rotate-notice-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.rotate-icons {
  font-size: 28px;
  animation: nudge-rotate 3s ease-in-out infinite;
}

@keyframes nudge-rotate {
  0%,
  100% {
    transform: translateX(0);
  }
  50% {
    transform: translateX(8px);
  }
}

.rotate-text {
  font-size: 15px;
  font-weight: 600;
  line-height: 1.4;
  max-width: 340px;
}

.rotate-actions {
  display: flex;
  gap: 12px;
}

.rotate-btn {
  background: rgba(255, 255, 255, 0.2);
  border: 2px solid rgba(255, 255, 255, 0.4);
  border-radius: 8px;
  padding: 8px 16px;
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s;
  min-height: 44px;
  min-width: 60px;
}

.rotate-btn:hover {
  background: rgba(255, 255, 255, 0.3);
  border-color: rgba(255, 255, 255, 0.6);
}

.rotate-btn:active {
  transform: scale(0.95);
}

/* ==============================================================
   MOBILE PORTRAIT LAYOUT - TOUCH DEVICES ONLY
   Primary query: Standard touch devices (iPhone, Pixel, most Android)
   Uses hover:none + pointer:coarse to exclude desktop narrow windows
   ============================================================== */
@media screen and (max-width: 768px) and (orientation: portrait) and (hover: none) and (pointer: coarse) {
  /* Show rotate banner in portrait - rotated 90° to prompt user to turn phone */
  .rotate-notice:not(.dismissed) {
    display: block;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) rotate(90deg);
    transform-origin: center center;
    z-index: 9999;
    width: 80vh; /* Use viewport height since rotated */
    max-width: 400px;
    margin: 0;
    box-shadow: 0 8px 32px rgba(255, 107, 53, 0.4);
  }

  .rotate-notice-content {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
  }

  .rotate-icons {
    font-size: 32px;
  }

  .rotate-text {
    font-size: 14px;
    text-align: center;
  }
}

/* ==============================================================
   SAMSUNG FALLBACK - Handles Samsung Hover Bug
   Samsung devices incorrectly report hover:hover for touchscreens
   Uses tighter width (480px) to ensure only phones match
   See: https://www.ctrl.blog/entry/css-media-hover-samsung.html
   ============================================================== */
@media screen and (max-width: 480px) and (orientation: portrait) and (pointer: coarse) {
  /* Show rotate banner in portrait - rotated 90° */
  .rotate-notice:not(.dismissed) {
    display: block;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) rotate(90deg);
    transform-origin: center center;
    z-index: 9999;
    width: 80vh;
    max-width: 400px;
    margin: 0;
    box-shadow: 0 8px 32px rgba(255, 107, 53, 0.4);
  }

  /* Same content styling as primary query for consistency */
  .rotate-notice-content {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
  }

  .rotate-icons {
    font-size: 32px;
  }

  .rotate-text {
    font-size: 14px;
    text-align: center;
  }
}

/* ==============================================================
   PORTRAIT LAYOUT ADJUSTMENTS
   Applied to all portrait devices (touch detection handled separately above)
   NOTE: Rotate notice display is ONLY controlled by touch-specific queries
   to prevent false positives on desktop narrow windows
   ============================================================== */
@media screen and (max-width: 1023px) and (orientation: portrait) {
  /*
   * DO NOT show rotate-notice here - only touch-specific queries above should show it.
   * This prevents desktop narrow windows from seeing the rotate prompt.
   * The .js-landscape and .js-desktop classes provide bulletproof hiding.
   */

  /* Hide complex controls in portrait (show only micro-faders) */
  /* Only apply after DJ Booth has loaded (indicated by .dj-booth-ready class) */
  .dj-booth-ready .deck-a,
  .dj-booth-ready .deck-b,
  .dj-booth-ready .dj-crossfader .crossfader-container,
  .dj-booth-ready .jog-wheel,
  .dj-booth-ready .transport-cluster {
    display: none;
  }

  /* Keep the band containers visible but hide their complex content */
  .dj-booth-ready .row-b,
  .dj-booth-ready .row-c {
    display: flex;
  }

  /* Portrait: Identity & HUD */
  .dj-topbar {
    padding: 12px 16px !important;
    gap: 12px !important;
    height: auto !important;
    grid-template-columns: 1fr !important;
  }

  .brand-title h1 {
    font-size: 1.1em !important;
  }

  .center-controls {
    flex-direction: row !important;
    flex-wrap: wrap;
    justify-content: center;
    gap: 12px !important;
  }

  .action-buttons {
    justify-content: center !important;
    padding-right: 0 !important;
  }

  .storage-hint {
    text-align: center;
    padding-right: 0 !important;
  }

  /* Portrait: Stacked HUD with large numerals */
  .dj-hud {
    padding: 16px !important;
  }

  .metrics-top {
    flex-direction: column !important;
    gap: 16px !important;
    padding: 16px !important;
  }

  .metric-display {
    width: 100%;
  }

  .metric-value {
    font-size: 2em !important;
  }

  .metric-divider {
    display: none !important;
  }

  .feasibility-section {
    padding: 12px !important;
  }

  .feasibility-gauge {
    height: 28px !important;
  }

  /* Portrait: Micro-faders at bottom (10 in one row) */
  .dj-faders {
    min-height: 130px !important;
    padding: 12px 8px !important;
    position: relative;
  }

  .sliders-container {
    gap: 6px !important;
    padding-bottom: env(safe-area-inset-bottom, 8px);
  }

  .slider-strip {
    min-width: calc((100% - 54px) / 10) !important;
    max-width: 40px;
  }

  .slider-emoji {
    font-size: 1.2em !important;
  }

  .slider-track {
    width: 6px !important;
    height: 70px !important;
  }

  .slider-cap {
    width: 14px !important;
    height: 16px !important;
  }

  .slider-cap:active {
    transform: translateX(-50%) scale(1.15) !important;
  }

  .mini-vu {
    width: 4px !important;
    height: 70px !important;
  }

  /* Center the VU meters in portrait */
  .master-vus {
    justify-content: center !important;
    margin: 16px auto !important;
    max-width: 200px !important;
  }

  .slider-readout {
    min-width: 36px !important;
    height: 24px !important;
    font-size: 0.65em !important;
  }

  .readout-value {
    font-size: 0.85em !important;
  }

  .slider-label {
    font-size: 0.6em !important;
    min-height: 20px !important;
  }

  /* Hide feasibility rings in portrait to save space */
  .feasibility-rings {
    display: none !important;
  }
}

/* ==============================================================
   MOBILE LANDSCAPE LAYOUT
   max-width: 1023px AND orientation: landscape
   4-band compressed layout
   ============================================================== */
@media screen and (max-width: 1023px) and (orientation: landscape) {
  /* Hide rotate notice in landscape - reset all transforms */
  .rotate-notice {
    display: none !important;
    position: relative !important;
    transform: none !important;
    top: auto !important;
    left: auto !important;
    width: auto !important;
  }

  /* Band A: Top Bar (compressed) */
  .dj-topbar {
    height: var(--band-a-height) !important;
    padding: var(--band-padding) !important;
    gap: 12px !important;
    margin-bottom: var(--band-gap) !important;
  }

  .brand-title h1 {
    font-size: 0.9em !important;
  }

  .power-led {
    width: 10px !important;
    height: 10px !important;
  }

  .country-select-dropdown {
    min-width: 140px !important;
    padding: 6px 12px !important;
    font-size: 0.85em !important;
  }

  .scenarios-btn {
    padding: 6px 12px !important;
    font-size: 0.8em !important;
  }

  .action-btn {
    padding: 6px 12px !important;
    font-size: 0.75em !important;
  }

  .storage-hint {
    display: none !important;
  }

  /* Band B: HUD Strip (compressed metrics) */
  .dj-hud {
    min-height: var(--band-b-height) !important;
    padding: 8px 12px !important;
    margin-bottom: var(--band-gap) !important;
  }

  .metrics-top {
    padding: 10px !important;
    gap: 20px !important;
  }

  .metric-label {
    font-size: var(--label-font) !important;
  }

  .metric-value {
    font-size: var(--hud-font-large) !important;
  }

  .metric-divider {
    height: 40px !important;
  }

  .feasibility-section {
    padding: 10px !important;
  }

  .feasibility-title {
    font-size: 0.7em !important;
    margin-bottom: 6px !important;
  }

  .feasibility-gauge {
    height: 24px !important;
  }

  .feasibility-needle {
    width: 4px !important;
  }

  .ticker-strip {
    height: 24px !important;
    font-size: 0.65em !important;
    padding: 4px 8px !important;
  }

  /* Band C: Micro Decks + Crossfader */
  .dj-decks {
    min-height: var(--band-c-height) !important;
    margin-bottom: var(--band-gap) !important;
    padding: 8px 20px !important;
  }

  .row-b {
    grid-template-columns: 100px 1fr 100px !important;
    gap: 12px !important;
    min-height: auto !important;
  }

  /* Shrink jog wheels to 72px */
  .jog-wheel {
    width: var(--jog-size) !important;
    height: var(--jog-size) !important;
  }

  .jog-ring {
    width: 60px !important;
    height: 60px !important;
  }

  .jog-label {
    font-size: 0.7em !important;
    margin-bottom: 4px !important;
  }

  .jog-percent {
    font-size: 16px !important;
  }

  .jog-sublabel,
  .jog-deck {
    font-size: 8px !important;
  }

  .deck-a,
  .deck-b {
    padding: 8px !important;
    gap: 6px !important;
  }

  /* Hide deck screens in landscape to save space */
  .deck-screen {
    display: none !important;
  }

  /* Compress transport buttons */
  .transport-cluster {
    gap: 4px !important;
  }

  .transport-btn {
    padding: 4px 6px !important;
    font-size: 0.6em !important;
  }

  /* Thin twin master VUs above crossfader (in central metrics) */
  .master-vus {
    gap: 12px !important;
    margin-top: 6px !important;
  }

  .master-vu {
    width: var(--vu-width) !important;
    height: var(--vu-height) !important;
    border-width: 1px !important;
  }

  .vu-label {
    font-size: 0.55em !important;
    margin-top: 2px !important;
  }

  /* Crossfader: thin track */
  .dj-crossfader {
    height: var(--crossfader-height) !important;
    margin-bottom: var(--band-gap) !important;
    padding: 0 20px !important;
  }

  .crossfader-labels {
    font-size: 0.7em !important;
    padding: 0 4px !important;
    margin-bottom: 4px !important;
  }

  .crossfader-track {
    height: 24px !important;
  }

  .crossfader-cap {
    width: 40px !important;
    height: 28px !important;
  }

  /* Band D: Fader Dock (10 sliders in one row) */
  .dj-faders {
    min-height: var(--band-d-height) !important;
    padding: 12px !important;
  }

  .sliders-container {
    gap: 8px !important;
  }

  .slider-strip {
    min-width: calc((100% - 72px) / 10) !important;
    max-width: 90px;
    gap: 4px !important;
  }

  .slider-emoji {
    font-size: 1.3em !important;
  }

  .feasibility-rings {
    gap: 4px !important;
  }

  .ring {
    width: 8px !important;
    height: 8px !important;
    border-width: 1px !important;
  }

  .peak-led {
    width: 6px !important;
    height: 6px !important;
  }

  .slider-track {
    width: var(--fader-track-width) !important;
    height: var(--fader-track-height) !important;
    border-width: 1px !important;
  }

  .slider-cap {
    width: var(--fader-cap-size) !important;
    height: 12px !important;
    border-radius: 4px !important;
  }

  .slider-cap:hover {
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.5) !important;
  }

  .slider-cap:active {
    transform: translateX(-50%) scale(1.12) !important;
  }

  .mini-vu {
    width: 6px !important;
    height: var(--fader-track-height) !important;
  }

  .slider-readout {
    min-width: 50px !important;
    height: 28px !important;
  }

  .readout-value {
    font-size: 0.9em !important;
  }

  .readout-unit {
    font-size: 0.55em !important;
  }

  .slider-label {
    font-size: 0.65em !important;
    min-height: 24px !important;
  }
}

/* ==============================================================
   DESKTOP LAYOUT (≥1024px)
   Ensure existing desktop styles remain unchanged
   ============================================================== */
@media screen and (min-width: 1024px) {
  /* Hide rotate notice on desktop - reset all transforms */
  .rotate-notice {
    display: none !important;
    position: relative !important;
    transform: none !important;
    top: auto !important;
    left: auto !important;
    width: auto !important;
  }

  /* Desktop uses inline styles from dj-booth.html */
  /* No overrides needed - existing desktop layout is preserved */
}

/* ==============================================================
   PERFORMANCE & POLISH
   ============================================================== */

/* Touch action for drag controls */
.slider-track,
.crossfader-track,
.slider-cap,
.crossfader-cap {
  touch-action: none;
}

/* GPU compositing for moving elements */
.slider-cap,
.crossfader-cap,
.feasibility-needle {
  will-change: transform;
}

/* Prevent text selection during drag */
.slider-strip,
.crossfader-container,
.jog-wheel {
  user-select: none;
  -webkit-user-select: none;
}

/* Safe area insets for notched devices */
@supports (padding: env(safe-area-inset-bottom)) {
  .dj-faders {
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
  }
}

/* Reduced motion preference */
@media (prefers-reduced-motion: reduce) {
  .rotate-icons,
  .power-led,
  .loading {
    animation: none !important;
  }

  .slider-cap,
  .crossfader-cap,
  .feasibility-needle {
    will-change: auto;
  }
}

/* Reduced motion + mobile portrait: Show banner centered but without rotation animation */
@media (prefers-reduced-motion: reduce) and (max-width: 768px) and (orientation: portrait) and (hover: none) and (pointer: coarse) {
  .rotate-notice:not(.dismissed) {
    transform: translate(-50%, -50%) rotate(0deg) !important; /* Centered but no rotation */
  }
}

/* Reduced motion + Samsung fallback */
@media (prefers-reduced-motion: reduce) and (max-width: 480px) and (orientation: portrait) and (pointer: coarse) {
  .rotate-notice:not(.dismissed) {
    transform: translate(-50%, -50%) rotate(0deg) !important;
  }
}
