/* =============================================
   ENHANCED MOBILE RESPONSIVE STYLES
   VampireApp - Professional Responsive Design
   ============================================= */

/* ======================================
   BASE MOBILE IMPROVEMENTS
   ====================================== */

/* Prevent horizontal scrolling */
html, body {
    overflow-x: hidden;
    width: 100%;
}

/* Improve tap targets on all devices */
button, .btn, a, 
input[type="submit"], 
input[type="button"],
select {
    min-height: 44px;
    min-width: 44px;
    touch-action: manipulation; /* Prevent double-tap zoom */
}

/* Prevent text size adjustment in iOS */
html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

/* Improve form input rendering on iOS */
input, select, textarea {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    border-radius: 10px;
}

/* ======================================
   TABLET BREAKPOINT (1024px and below)
   ====================================== */
@media (max-width: 1024px) {
    /* Reduce header size */
    header h1 {
        font-size: 1.8rem;
        letter-spacing: 0.05em;
    }
    
    /* Adjust section spacing */
    section, .section {
        padding: 1.5rem;
        margin-bottom: 1.5rem;
    }
    
    /* Grid adjustments */
    .grid-3 {
        grid-template-columns: repeat(2, 1fr);
    }
    
    /* Character grid - 2 columns */
    .character-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 1.25rem;
    }
}

/* ======================================
   TABLET PORTRAIT (768px and below)
   ====================================== */
@media (max-width: 768px) {
    /* Typography scaling */
    header h1 {
        font-size: 1.5rem;
        text-align: center;
        letter-spacing: 0.03em;
    }
    
    section h2, .section h2 {
        font-size: 1.5rem;
    }
    
    section h3, .section h3 {
        font-size: 1.2rem;
    }
    
    /* Header layout - stack vertically */
    .header-content {
        flex-direction: column;
        gap: 1rem;
        padding: 1rem;
    }
    
    .header-buttons {
        display: flex;
        flex-wrap: wrap;
        justify-content: center;
        gap: 0.5rem;
        width: 100%;
    }
    
    .header-buttons button,
    .header-buttons .btn {
        flex: 1 1 auto;
        min-width: 120px;
        padding: 0.5rem 1rem;
        font-size: 0.85rem;
    }
    
    /* Stats row - stack vertically */
    .stats-row {
        flex-direction: column;
        gap: 0.75rem;
        align-items: stretch;
    }
    
    .stat-divider {
        display: none; /* Hide dividers on tablet */
    }
    
    .stat-item {
        width: 100%;
        padding: 0.75rem;
    }
    
    /* Section spacing */
    section, .section {
        padding: 1rem;
        margin-bottom: 1rem;
    }
    
    /* Attributes grid - single column */
    .grid-3 {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    
    /* Form adjustments */
    .form-row {
        flex-direction: column;
        gap: 1rem;
    }
    
    .form-group {
        margin-bottom: 1.5rem;
    }
    
    /* Dashboard buttons */
    .player-dashboard-btn,
    .st-dashboard-btn,
    .merits-flaws-btn,
    .in-the-blood-btn,
    .downtime-btn,
    .challenge-btn {
        width: 100%;
        padding: 0.75rem 1rem;
        font-size: 0.9rem;
    }
    
    /* Save footer - make static on mobile */
    .save-footer {
        padding: 1rem;
    }
    
    .save-btn {
        width: 100%;
        max-width: 100%;
        padding: 1rem;
        font-size: 1rem;
    }
    
    /* Modals - full screen on tablet */
    .modal-content {
        width: 95%;
        max-width: 600px;
        max-height: 90vh;
        overflow-y: auto;
    }
    
    /* Challenge page adjustments */
    .combat-row {
        flex-direction: column;
        gap: 1rem;
    }
    
    .resource-bar {
        flex-wrap: wrap;
        justify-content: center;
        gap: 0.75rem;
    }
    
    /* Downtime allocations */
    .allocation-bar {
        flex-direction: column;
        gap: 1rem;
        padding: 1rem;
    }
    
    .period-selector {
        width: 100%;
    }
}

/* ======================================
   MOBILE LANDSCAPE (568px-768px landscape)
   ====================================== */
@media (max-width: 768px) and (orientation: landscape) {
    /* Reduce header size in landscape */
    header {
        padding: 0.5rem 1rem;
    }
    
    header h1 {
        font-size: 1.2rem;
    }
    
    /* Compact resource displays */
    .resource-bar {
        flex-direction: row;
        flex-wrap: wrap;
        gap: 0.5rem;
    }
    
    /* Use horizontal space better */
    .stats-row {
        flex-direction: row;
        flex-wrap: wrap;
    }
    
    .stat-item {
        flex: 1 1 auto;
        min-width: 150px;
    }
}

/* ======================================
   MOBILE PORTRAIT (480px and below)
   ====================================== */
@media (max-width: 480px) {
    /* Typography scaling */
    header h1 {
        font-size: 1.3rem;
        letter-spacing: 0.03em;
        padding: 0.5rem;
    }
    
    section h2, .section h2 {
        font-size: 1.3rem;
    }
    
    section h3, .section h3 {
        font-size: 1.1rem;
    }
    
    /* Section padding */
    section, .section {
        padding: 0.75rem;
        margin-bottom: 0.75rem;
        border-radius: 12px;
    }
    
    /* Character grid - single column */
    .character-grid {
        grid-template-columns: 1fr;
        gap: 0.75rem;
    }
    
    /* All grids single column */
    .grid-2, .grid-3, .grid-4 {
        grid-template-columns: 1fr;
        gap: 0.75rem;
    }
    
    /* Button sizing */
    button, .btn, .auth-btn {
        width: 100%;
        padding: 0.875rem 1rem;
        font-size: 0.95rem;
    }
    
    /* Form inputs - prevent iOS zoom */
    input, select, textarea {
        font-size: 16px !important; /* Prevents iOS zoom */
        padding: 0.875rem 1rem;
    }
    
    /* Auth pages */
    .auth-container {
        padding: 0.5rem;
    }
    
    .auth-box {
        padding: 1.5rem 1rem;
        margin: 0.5rem;
        border-radius: 16px;
    }
    
    .auth-logo {
        width: 80px;
        height: 80px;
    }
    
    .auth-box h1 {
        font-size: 1.5rem;
        letter-spacing: 2px;
    }
    
    .auth-box h2 {
        font-size: 0.85rem;
        letter-spacing: 3px;
        margin-bottom: 1.5rem;
    }
    
    /* Modal - full screen on mobile */
    .modal-content {
        width: 100%;
        max-width: 100%;
        height: 100vh;
        max-height: 100vh;
        margin: 0;
        border-radius: 0;
        overflow-y: auto;
    }
    
    .modal-header {
        position: sticky;
        top: 0;
        background: #1a1a1a;
        z-index: 10;
        padding: 1rem;
    }
    
    /* Resource displays - stack */
    .resource-bar {
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .resource-item {
        width: 100%;
    }
    
    /* XP container - wrap */
    #xp-container {
        flex-wrap: wrap;
        justify-content: center;
        gap: 0.5rem;
    }
    
    /* Dots and controls - slightly larger for touch */
    .gen-dot {
        width: 32px;
        height: 32px;
        min-width: 32px;
        min-height: 32px;
    }
    
    /* Tables - make responsive */
    table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    /* Compact checkbox/radio groups */
    .checkbox-group,
    .radio-group {
        flex-direction: column;
        gap: 0.75rem;
    }
}

/* ======================================
   SMALL MOBILE (375px and below)
   ====================================== */
@media (max-width: 375px) {
    /* Further typography reduction */
    header h1 {
        font-size: 1.1rem;
        letter-spacing: 0.02em;
    }
    
    section h2, .section h2 {
        font-size: 1.2rem;
    }
    
    section h3, .section h3 {
        font-size: 1rem;
    }
    
    /* Tighter spacing */
    section, .section {
        padding: 0.5rem;
        margin-bottom: 0.5rem;
    }
    
    .auth-box {
        padding: 1rem 0.75rem;
    }
    
    .auth-logo {
        width: 70px;
        height: 70px;
    }
    
    /* Smaller buttons */
    button, .btn, .auth-btn {
        padding: 0.75rem 0.875rem;
        font-size: 0.9rem;
    }
    
    /* Compact form groups */
    .form-group {
        margin-bottom: 1rem;
    }
    
    .form-group label {
        font-size: 0.8rem;
    }
    
    .form-group small {
        font-size: 0.75rem;
    }
}

/* ======================================
   TOUCH-FRIENDLY IMPROVEMENTS
   ====================================== */

/* Larger tap targets on all touch devices */
@media (pointer: coarse) {
    button, .btn, a,
    input[type="checkbox"],
    input[type="radio"] {
        min-height: 48px;
        min-width: 48px;
    }
    
    /* Add spacing between tappable elements */
    .button-group > *,
    .nav-links > * {
        margin: 0.25rem;
    }
    
    /* Increase form spacing */
    .form-group {
        margin-bottom: 1.75rem;
    }
}

/* ======================================
   SAFE AREAS (iPhone Notch, etc.)
   ====================================== */
@supports (padding: max(0px)) {
    body {
        padding-left: max(0px, env(safe-area-inset-left));
        padding-right: max(0px, env(safe-area-inset-right));
    }
    
    .save-footer,
    header,
    .modal-header {
        padding-left: max(1rem, env(safe-area-inset-left));
        padding-right: max(1rem, env(safe-area-inset-right));
    }
    
    .save-footer {
        padding-bottom: max(1rem, env(safe-area-inset-bottom));
    }
}

/* ======================================
   PRINT STYLES
   ====================================== */
@media print {
    /* Hide navigation and interactive elements */
    header .header-buttons,
    .back-btn,
    .save-footer,
    button,
    .btn,
    nav,
    .loading-overlay {
        display: none !important;
    }
    
    /* Expand all collapsed sections */
    details {
        display: block;
    }
    
    details summary {
        display: none;
    }
    
    /* Remove background effects for printing */
    body, #app {
        background: white;
        color: black;
    }
    
    section, .section {
        border: 1px solid #333;
        box-shadow: none;
        page-break-inside: avoid;
        margin-bottom: 1rem;
    }
    
    /* Ensure readability */
    * {
        color: black !important;
        background: white !important;
    }
    
    a {
        text-decoration: underline;
    }
}

/* ======================================
   ACCESSIBILITY - LARGE TEXT MODE
   ====================================== */
@media (prefers-contrast: high) {
    /* Increase border thickness */
    section, .section,
    .auth-box,
    input, select, textarea,
    button, .btn {
        border-width: 2px;
        border-color: #8b0000;
    }
    
    /* Stronger focus indicators */
    *:focus {
        outline: 3px solid #8b0000;
        outline-offset: 3px;
    }
}

/* ======================================
   DARK MODE SUPPORT (if implementing)
   ====================================== */
@media (prefers-color-scheme: dark) {
    /* VampireApp is already dark, but ensure contrast */
    body {
        background: #000;
    }
    
    section, .section {
        background: rgba(20, 20, 20, 0.95);
    }
}

/* ======================================
   UTILITY CLASSES FOR RESPONSIVE
   ====================================== */

/* Hide on mobile */
.hide-mobile {
    display: none;
}

@media (min-width: 769px) {
    .hide-mobile {
        display: block;
    }
    
    .hide-desktop {
        display: none;
    }
}

/* Show only on mobile */
.show-mobile {
    display: none;
}

@media (max-width: 768px) {
    .show-mobile {
        display: block;
    }
}
