/**
 * Mobile responsive styles for Occult Bookstore Text Adventure
 * Optimized for phones and tablets
 */

.choice-button .choice-detail {
    display: block;
    margin-top: 4px;
    font-size: 0.82rem;
    color: rgba(255, 255, 255, 0.8);
}

.choice-button.choice-disabled,
.choice-button:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

/* Tablet layout (768px and below) */
@media screen and (max-width: 768px) {
    :root {
        --sidebar-width: 280px;
        --header-height: 165px; /* Increased to accommodate stat bars */
        --padding: 15px;
    }

    /* Switch to flexbox layout for proper vertical stacking */
    #game-container {
        display: flex;
        flex-direction: column;
        min-height: 100vh;
    }

    #game-header {
        order: 1;
        flex: 0 0 auto;
        position: relative; /* Contain absolutely positioned stat overlays */
    }

    #game-main {
        order: 2;
        flex: 1 1 auto; /* Allow main to grow and push sidebar down */
        position: relative;
        overflow-y: visible;
        min-height: 50vh; /* Ensure minimum space for content */
    }

    #game-sidebar {
        order: 3;
        flex: 0 0 auto;
        border-left: none;
        border-top: 2px solid var(--accent-purple);
        max-height: none;
        position: sticky;
        bottom: 0;
        background: var(--bg-secondary); /* Ensure background covers content below */
        /* Display sections side-by-side on mobile */
        flex-direction: row;
        gap: 8px;
        padding: 8px;
    }

    #game-header h1 {
        font-size: 1.8em;
        margin-bottom: 0.3em;
    }

    #game-stats {
        justify-content: center;
        gap: 10px;
    }

    .stat-group {
        font-size: 0.85em;
        gap: 6px;
    }

    .sidebar-section {
        padding: 5px;
        flex: 1; /* Equal width for both sections */
    }

    .sidebar-section h3 {
        font-size: 0.85em;
        margin-bottom: 3px;
        padding-bottom: 2px;
    }

    .rep-grid {
        font-size: 0.7em;
        gap: 4px;
    }

    #game-sidebar button {
        font-size: 0.75em;
        padding: 6px 8px;
    }
}

/* Mobile layout (480px and below) */
@media screen and (max-width: 480px) {
    :root {
        --header-height: 170px; /* Increased to accommodate stat bars */
        --padding: 12px;
    }

    body {
        font-size: 14px;
    }

    /* Ensure flexbox layout persists */
    #game-container {
        display: flex;
        flex-direction: column;
        min-height: 100vh;
    }

    #game-header {
        order: 1;
        flex: 0 0 auto;
        position: relative; /* Contain absolutely positioned stat overlays */
    }

    #game-main {
        order: 2;
        flex: 1 1 auto;
        min-height: 40vh;
    }

    #game-sidebar {
        order: 3;
        flex: 0 0 auto;
        position: sticky;
        bottom: 0;
        background: var(--bg-secondary);
    }

    #game-header h1 {
        font-size: 1.6em;
    }

    #game-stats {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }

    .stat-group {
        justify-content: center;
        font-size: 0.8em;
    }

    .stat-bar-wrapper {
        min-width: 100px;
    }

    .stat-bar-fill {
        height: 16px;
    }

    .stat-value-overlay {
        font-size: 0.75em;
    }

    .float-number {
        font-size: 18px;
        /* Ensure visibility above mobile elements */
        z-index: 9999 !important;
    }

    .float-number.critical {
        font-size: 24px;
    }

    #story-text {
        padding: 20px;
        font-size: 1em;
        min-height: 150px;
    }

    /* Debug display adjustments for mobile */
    .debug-encounter-name {
        font-size: 9pt;
        top: 3px;
        right: 5px;
    }

    .choice-button {
        padding: 12px 15px;
        font-size: 0.95em;
    }

    .choice-number {
        width: 22px;
        height: 22px;
        font-size: 0.8em;
    }

    #game-sidebar {
        padding: 6px;
        gap: 6px;
        flex-direction: row; /* Side by side */
    }

    .sidebar-section {
        padding: 4px;
        flex: 1;
    }

    .sidebar-section h3 {
        font-size: 0.8em;
        margin-bottom: 2px;
        padding-bottom: 1px;
    }

    .rep-grid {
        font-size: 0.65em;
        gap: 2px;
    }

    #game-sidebar button {
        padding: 5px 6px;
        font-size: 0.7em;
    }

    /* Maintain button row layout on mobile */
    .menu-button-row {
        display: flex;
        gap: 6px;
    }

    .menu-button-half {
        width: calc(50% - 3px);
    }

    .notification {
        top: 10px;
        right: 10px;
        left: 10px;
        padding: 12px 15px;
        text-align: center;
    }
}

/* Ultra-small screens (360px and below) */
@media screen and (max-width: 360px) {
    :root {
        --header-height: 180px; /* Increased to accommodate stat bars */
        --padding: 10px;
    }

    /* Ensure flexbox layout persists */
    #game-container {
        display: flex;
        flex-direction: column;
        min-height: 100vh;
    }

    #game-header {
        order: 1;
        flex: 0 0 auto;
        position: relative; /* Contain absolutely positioned stat overlays */
    }

    #game-main {
        order: 2;
        flex: 1 1 auto;
        min-height: 35vh;
    }

    #game-sidebar {
        order: 3;
        flex: 0 0 auto;
        position: sticky;
        bottom: 0;
        background: var(--bg-secondary);
        flex-direction: row; /* Side by side */
        padding: 4px;
        gap: 4px;
    }

    #game-header h1 {
        font-size: 1.4em;
        word-break: break-word;
    }

    #story-text {
        padding: 15px;
        font-size: 0.95em;
    }

    /* Debug display for ultra-small screens */
    .debug-encounter-name {
        font-size: 8pt;
        top: 2px;
        right: 3px;
    }

    .choice-button {
        padding: 10px 12px;
        font-size: 0.9em;
        gap: 8px;
    }

    .sidebar-section {
        padding: 3px;
        flex: 1;
    }

    .sidebar-section h3 {
        font-size: 0.75em;
        margin-bottom: 2px;
        padding-bottom: 1px;
    }

    .rep-grid {
        font-size: 0.6em;
        gap: 2px;
    }

    #game-sidebar button {
        padding: 4px 5px;
        font-size: 0.65em;
        margin-bottom: 2px;
    }
}

/* Landscape mobile orientation - use grid for side-by-side layout */
/* Only apply when screen is wide enough (min 600px) */
@media screen and (min-width: 600px) and (max-height: 500px) and (orientation: landscape) {
    :root {
        --header-height: 80px;
    }

    /* In landscape, use grid with sidebar on the side */
    #game-container {
        display: grid;
        grid-template-areas:
            "header header"
            "main sidebar";
        grid-template-columns: 1fr 250px;
        grid-template-rows: var(--header-height) 1fr;
        height: 100vh;
    }

    #game-header {
        grid-area: header;
        order: initial;
    }

    #game-main {
        grid-area: main;
        order: initial;
    }

    #game-sidebar {
        grid-area: sidebar;
        order: initial;
        border-left: 2px solid var(--accent-purple);
        border-top: none;
        max-height: none;
    }

    #game-header h1 {
        font-size: 1.4em;
        margin-bottom: 0.2em;
    }

    #game-stats {
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: space-around;
        gap: 8px;
    }

    .stat-group {
        font-size: 0.75em;
        gap: 4px;
    }

    .sidebar-section {
        padding: 5px;
    }

    .sidebar-section h3 {
        font-size: 0.9em;
        margin-bottom: 4px;
    }

    #game-sidebar button {
        padding: 8px 10px;
        font-size: 0.8em;
        margin-bottom: 4px;
    }
}

/* Touch-friendly enhancements */
@media (hover: none) {
    .choice-button:hover {
        transform: none;
        background: linear-gradient(135deg, var(--bg-tertiary), var(--bg-secondary));
    }

    .choice-button:active {
        background: linear-gradient(135deg, var(--accent-purple), var(--bg-tertiary));
        border-color: var(--accent-gold);
    }

    #game-sidebar button:hover {
        transform: none;
        background: linear-gradient(135deg, var(--accent-blue), var(--bg-tertiary));
    }

    #game-sidebar button:active {
        background: linear-gradient(135deg, var(--accent-gold), var(--accent-blue));
    }

    /* Increase touch targets */
    .choice-button {
        min-height: 48px;
        padding: 15px 20px;
    }

    #game-sidebar button {
        min-height: 44px;
        padding: 12px 16px;
    }
}

/* Accessibility improvements for mobile */
@media screen and (max-width: 768px) {
    /* Skip to main content for screen readers */
    .skip-to-main {
        position: absolute;
        top: -40px;
        left: 6px;
        background: var(--accent-gold);
        color: var(--bg-primary);
        padding: 8px;
        text-decoration: none;
        border-radius: 0 0 var(--border-radius) var(--border-radius);
        z-index: 1000;
    }

    .skip-to-main:focus {
        top: 0;
    }

    /* Improve focus indicators on mobile */
    button:focus,
    .choice-button:focus {
        outline: 3px solid var(--accent-gold);
        outline-offset: 2px;
    }

    /* Better tap highlights */
    .choice-button {
        -webkit-tap-highlight-color: rgba(138, 43, 226, 0.3);
    }

    #game-sidebar button {
        -webkit-tap-highlight-color: rgba(70, 130, 180, 0.3);
    }
}

/* Dark mode preference */
@media (prefers-color-scheme: light) {
    /* If user prefers light mode, we could provide overrides here */
    /* For now, keeping the dark occult theme regardless */
}

/* Print styles (in case someone wants to print their story) */
@media print {
    #game-container {
        grid-template-areas:
            "header"
            "main"
            "sidebar";
        grid-template-columns: 1fr;
    }

    #game-header,
    #game-sidebar {
        background: white !important;
        color: black !important;
        box-shadow: none !important;
    }

    #story-text {
        background: white !important;
        color: black !important;
        border: 1px solid black;
        box-shadow: none !important;
        page-break-inside: avoid;
    }

    .choice-button {
        background: white !important;
        color: black !important;
        border: 1px solid black !important;
        display: none; /* Hide choices in print */
    }

    .notification {
        display: none !important;
    }
}
