/**
 * ═══════════════════════════════════════════════════════════════════════════════
 * TSI MOBILE RESPONSIVE CSS v2.0
 * Cross-AI Synthesis: Claude × Grok × Gemini
 * ═══════════════════════════════════════════════════════════════════════════════
 * 
 * Import AFTER tsi-design-system.css:
 *   <link rel="stylesheet" href="/assets/css/tsi-design-system.css">
 *   <link rel="stylesheet" href="/assets/css/tsi-mobile-responsive.css">
 * 
 * ═══════════════════════════════════════════════════════════════════════════════
 */

/* ═══════════════════════════════════════════════════════════════════════════════
   SECTION 1: CSS CUSTOM PROPERTIES (Mobile Extensions)
   ═══════════════════════════════════════════════════════════════════════════════ */

:root {
    /* Dynamic Viewport (set by JS, fallback to CSS) */
    --tsi-vh: 1vh;
    --tsi-vw: 1vw;
    --tsi-dvh: 1dvh;
    
    /* Safe Areas (populated by browser) */
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
    --safe-right: env(safe-area-inset-right, 0px);
    
    /* Touch Targets */
    --tsi-touch-min: 44px;
    --tsi-touch-comfortable: 48px;
    
    /* Mobile Spacing */
    --tsi-mobile-padding: 16px;
    --tsi-mobile-gap: 12px;
}

/* ═══════════════════════════════════════════════════════════════════════════════
   SECTION 2: GLOBAL RESETS & FOUNDATIONS
   ═══════════════════════════════════════════════════════════════════════════════ */

*,
*::before,
*::after {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
}

html {
    -webkit-text-size-adjust: 100%;
    -moz-text-size-adjust: 100%;
    text-size-adjust: 100%;
    height: 100%;
    scroll-behavior: smooth;
}

body {
    /* Hybrid Viewport Height - Multiple fallbacks */
    min-height: 100vh;
    min-height: calc(var(--tsi-vh, 1vh) * 100);
    min-height: 100dvh;
    
    /* Safe Area Padding */
    padding-top: var(--safe-top);
    padding-bottom: var(--safe-bottom);
    padding-left: var(--safe-left);
    padding-right: var(--safe-right);
    
    /* Prevent Overscroll Bounce */
    overflow-x: hidden;
    overscroll-behavior: none;
    overscroll-behavior-y: contain;
    
    /* Smooth Scrolling */
    -webkit-overflow-scrolling: touch;
}

/* ═══════════════════════════════════════════════════════════════════════════════
   SECTION 3: GLASSMORPHISM ENGINE (Cross-Browser)
   ═══════════════════════════════════════════════════════════════════════════════ */

.glass-panel,
.tsi-glass-card,
.tsi-card {
    background: var(--tsi-glass-medium, rgba(18, 24, 32, 0.75));
    border: 1px solid rgba(255, 102, 0, 0.15);
    border-radius: var(--tsi-radius-lg, 12px);
    
    /* Safari requires -webkit- prefix */
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    backdrop-filter: blur(20px) saturate(180%);
    
    /* Performance optimizations */
    will-change: transform, backdrop-filter;
    transform: translateZ(0);
    contain: paint;
}

/* Fallback for browsers without backdrop-filter (Android WebView <76) */
@supports not (backdrop-filter: blur(20px)) {
    .glass-panel,
    .tsi-glass-card,
    .tsi-card {
        background: rgba(18, 24, 32, 0.95);
    }
}

/* ═══════════════════════════════════════════════════════════════════════════════
   SECTION 4: TOUCH TARGETS & INTERACTIONS
   ═══════════════════════════════════════════════════════════════════════════════ */

button,
.tsi-btn,
.tsi-nav-item,
.tsi-tab,
[role="button"],
input[type="button"],
input[type="submit"],
a.btn {
    min-height: var(--tsi-touch-min);
    min-width: var(--tsi-touch-min);
    padding: 12px 16px;
    touch-action: manipulation;
    cursor: pointer;
    
    /* Prevent double-tap zoom */
    -ms-touch-action: manipulation;
}

/* Active state for touch feedback */
button:active,
.tsi-btn:active,
[role="button"]:active {
    transform: scale(0.98);
    opacity: 0.9;
}

/* ═══════════════════════════════════════════════════════════════════════════════
   SECTION 5: TRAINING PAGE LAYOUT
   ═══════════════════════════════════════════════════════════════════════════════ */

.training-viewport {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: calc(var(--tsi-vh, 1vh) * 100);
    height: 100dvh;
    overflow: hidden;
    position: relative;
    
    /* Account for fixed control dock */
    padding-bottom: calc(80px + var(--safe-bottom));
}

/* Graph Container Stack */
.graph-stack {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    padding: var(--tsi-mobile-padding);
    gap: var(--tsi-mobile-gap);
    
    /* Performance isolation */
    contain: paint;
}

/* Individual Chart Container */
.chart-container {
    position: relative;
    width: 100%;
    flex: 1;
    min-height: 80px;
    max-height: 150px;
}

.chart-container canvas {
    width: 100% !important;
    height: 100% !important;
}

/* Gauge Display Strip */
.gauge-strip {
    flex: 0 0 auto;
    display: flex;
    overflow-x: auto;
    gap: 15px;
    padding: 10px var(--tsi-mobile-padding);
    background: rgba(0, 0, 0, 0.3);
    
    /* Smooth scrolling */
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x mandatory;
    scrollbar-width: none;
}

.gauge-strip::-webkit-scrollbar {
    display: none;
}

.gauge-item {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 70px;
    scroll-snap-align: start;
}

.gauge-item canvas,
.gauge-item svg {
    width: 60px;
    height: 60px;
    max-width: 100%;
}

.gauge-label {
    font-size: 0.7rem;
    color: var(--tsi-text-muted, #6B7280);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-top: 4px;
    white-space: nowrap;
}

/* Fixed Control Dock */
.control-dock {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 16px;
    
    height: calc(70px + var(--safe-bottom));
    padding: 10px var(--tsi-mobile-padding);
    padding-bottom: calc(10px + var(--safe-bottom));
    
    background: linear-gradient(
        to top,
        rgba(13, 17, 23, 0.98) 0%,
        rgba(13, 17, 23, 0.95) 50%,
        rgba(13, 17, 23, 0.85) 100%
    );
    border-top: 1px solid rgba(255, 102, 0, 0.2);
}

/* Control Buttons */
.control-dock .tsi-btn {
    flex: 0 0 auto;
    min-width: 70px;
    padding: 12px 20px;
}

/* ═══════════════════════════════════════════════════════════════════════════════
   SECTION 6: HEADER BAR (Level/Stage/XP/Score)
   ═══════════════════════════════════════════════════════════════════════════════ */

.training-header {
    flex: 0 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px var(--tsi-mobile-padding);
    padding-top: calc(10px + var(--safe-top));
    background: rgba(13, 17, 23, 0.9);
    border-bottom: 1px solid rgba(255, 102, 0, 0.15);
}

.training-title {
    font-family: var(--tsi-font-heading, 'Oswald', sans-serif);
    font-size: clamp(1rem, 4vw, 1.25rem);
    color: var(--tsi-orange, #FF6600);
    margin: 0;
}

.training-stats {
    display: flex;
    gap: 12px;
    font-family: var(--tsi-font-mono, monospace);
    font-size: clamp(0.7rem, 2.5vw, 0.85rem);
    color: var(--tsi-text-secondary, #B0B8C4);
}

.training-stats span {
    white-space: nowrap;
}

/* ═══════════════════════════════════════════════════════════════════════════════
   SECTION 7: SIDEBAR (Species Navigation)
   ═══════════════════════════════════════════════════════════════════════════════ */

/* Desktop: Vertical sidebar */
.species-sidebar {
    position: fixed;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    z-index: 100;
    
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 10px 8px;
    
    background: rgba(13, 17, 23, 0.8);
    border-radius: 0 12px 12px 0;
    border: 1px solid rgba(255, 102, 0, 0.15);
    border-left: none;
}

.species-sidebar-item {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.05);
    transition: all 0.2s ease;
}

.species-sidebar-item:hover,
.species-sidebar-item.active {
    background: rgba(255, 102, 0, 0.2);
    border-color: var(--tsi-orange);
}

.species-sidebar-item img {
    width: 28px;
    height: 28px;
    object-fit: contain;
}

/* ═══════════════════════════════════════════════════════════════════════════════
   SECTION 8: RESPONSIVE BREAKPOINTS
   ═══════════════════════════════════════════════════════════════════════════════ */

/* Tablet Portrait */
@media (max-width: 768px) {
    :root {
        --tsi-mobile-padding: 12px;
        --tsi-mobile-gap: 10px;
    }
    
    .training-viewport {
        padding-left: 0;
    }
    
    /* Hide sidebar on mobile, use bottom nav instead */
    .species-sidebar {
        display: none;
    }
    
    .chart-container {
        max-height: 120px;
    }
    
    .gauge-item canvas,
    .gauge-item svg {
        width: 50px;
        height: 50px;
    }
}

/* Phone Portrait */
@media (max-width: 480px) {
    :root {
        --tsi-mobile-padding: 10px;
        --tsi-mobile-gap: 8px;
    }
    
    .training-header {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .training-stats {
        width: 100%;
        justify-content: space-between;
    }
    
    .chart-container {
        max-height: 100px;
    }
    
    .control-dock {
        gap: 10px;
    }
    
    .control-dock .tsi-btn {
        min-width: 60px;
        padding: 10px 14px;
        font-size: 0.85rem;
    }
}

/* Small Phone */
@media (max-width: 360px) {
    .training-stats {
        font-size: 0.65rem;
        gap: 8px;
    }
    
    .gauge-strip {
        gap: 10px;
    }
    
    .gauge-item {
        min-width: 55px;
    }
    
    .gauge-item canvas,
    .gauge-item svg {
        width: 40px;
        height: 40px;
    }
}

/* Landscape Phone */
@media (max-height: 500px) and (orientation: landscape) {
    .training-viewport {
        flex-direction: row;
        padding-bottom: 0;
        padding-right: calc(80px + var(--safe-right));
    }
    
    .graph-stack {
        flex-direction: row;
        flex: 1;
    }
    
    .chart-container {
        flex: 1;
        max-height: none;
        min-height: 0;
    }
    
    .gauge-strip {
        position: absolute;
        bottom: var(--safe-bottom);
        left: 0;
        right: calc(80px + var(--safe-right));
        flex-direction: row;
        overflow-x: auto;
    }
    
    .control-dock {
        position: fixed;
        bottom: 0;
        right: 0;
        left: auto;
        top: 0;
        width: calc(70px + var(--safe-right));
        height: 100%;
        flex-direction: column;
        padding: var(--safe-top) 10px var(--safe-bottom) 10px;
        padding-right: calc(10px + var(--safe-right));
        border-top: none;
        border-left: 1px solid rgba(255, 102, 0, 0.2);
    }
    
    .training-header {
        position: absolute;
        top: 0;
        left: 0;
        right: calc(70px + var(--safe-right));
        padding-top: var(--safe-top);
    }
}

/* Large Tablets */
@media (min-width: 769px) and (max-width: 1024px) {
    .training-viewport {
        padding-left: 60px;
    }
    
    .species-sidebar {
        width: 50px;
    }
}

/* ═══════════════════════════════════════════════════════════════════════════════
   SECTION 9: CAMP PAGE STYLES
   ═══════════════════════════════════════════════════════════════════════════════ */

.camp-viewport {
    min-height: 100vh;
    min-height: calc(var(--tsi-vh, 1vh) * 100);
    min-height: 100dvh;
    padding: var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left);
}

.camp-compass-nav {
    position: relative;
    width: min(300px, 80vw);
    height: min(300px, 80vw);
    margin: 0 auto;
}

/* ═══════════════════════════════════════════════════════════════════════════════
   SECTION 10: ADVENTURE PAGE STYLES
   ═══════════════════════════════════════════════════════════════════════════════ */

.adventure-viewport {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    height: calc(var(--tsi-vh, 1vh) * 100);
    height: 100dvh;
    overflow: hidden;
}

.adventure-hud {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    z-index: 100;
    
    padding: var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left);
}

.adventure-hud > * {
    pointer-events: auto;
}

/* ═══════════════════════════════════════════════════════════════════════════════
   SECTION 11: UTILITY CLASSES
   ═══════════════════════════════════════════════════════════════════════════════ */

/* Full viewport height with iOS fix */
.full-height {
    height: 100vh;
    height: calc(var(--tsi-vh, 1vh) * 100);
    height: 100dvh;
}

/* Safe area padding utilities */
.safe-padding {
    padding: var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left);
}

.safe-padding-top {
    padding-top: var(--safe-top);
}

.safe-padding-bottom {
    padding-bottom: var(--safe-bottom);
}

/* Hide on mobile */
@media (max-width: 768px) {
    .hide-mobile {
        display: none !important;
    }
}

/* Hide on desktop */
@media (min-width: 769px) {
    .hide-desktop {
        display: none !important;
    }
}

/* Show only in landscape */
@media (orientation: portrait) {
    .landscape-only {
        display: none !important;
    }
}

/* Show only in portrait */
@media (orientation: landscape) {
    .portrait-only {
        display: none !important;
    }
}

/* ═══════════════════════════════════════════════════════════════════════════════
   SECTION 12: ANIMATION PERFORMANCE
   ═══════════════════════════════════════════════════════════════════════════════ */

/* Reduce motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* GPU-accelerated transforms */
.gpu-accelerated {
    transform: translateZ(0);
    will-change: transform;
}

/* ═══════════════════════════════════════════════════════════════════════════════
   SECTION 13: MOBILE OVERFLOW FIX
   Adventure pages set body { overflow: hidden } which blocks scrolling on mobile.
   Override on small screens so users can scroll when content overflows.
   ═══════════════════════════════════════════════════════════════════════════════ */

@media (max-width: 768px) {
    body {
        overflow-y: auto !important;
        overflow-x: hidden !important;
    }
}

/* ═══════════════════════════════════════════════════════════════════════════════
   SECTION 14: iOS FORM ZOOM PREVENTION
   iOS Safari auto-zooms when input font-size < 16px. Force 16px minimum
   on all interactive elements to prevent unwanted zoom on focus.
   ═══════════════════════════════════════════════════════════════════════════════ */

@media screen and (max-width: 768px) {
    input,
    select,
    textarea,
    button {
        font-size: 16px !important;
    }
}

/* ═══════════════════════════════════════════════════════════════════════════════
   END OF TSI MOBILE RESPONSIVE CSS v2.0
   ═══════════════════════════════════════════════════════════════════════════════ */
