/* =================================================================
   NUMTRIXIAN UNIVERSAL RESPONSIVE CSS
   Mobile, Tablet, Console, and All Devices
   ================================================================= */

/* ---- BASE RESPONSIVE RESET ---- */
*, *::before, *::after {
    box-sizing: border-box;
}

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

body {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow-x: hidden;
    width: 100%;
}

img, video, canvas, svg {
    max-width: 100%;
    height: auto;
    display: block;
}

input, button, textarea, select {
    font: inherit;
    max-width: 100%;
}

/* Prevent horizontal scroll from layout containers */
main, section, article, aside, header, footer, nav {
    max-width: 100vw;
    overflow-x: hidden;
}

/* Touch-friendly tap targets */
a, button, input[type="button"], input[type="submit"], .nav-btn, .category-btn, .dropdown-item {
    min-height: 44px;
    min-width: 44px;
}

/* Eliminate 300ms mobile tap delay on all interactive elements */
a, button, input, select, textarea, [onclick], [role="button"],
.category-orb, .module-card, .clickable, .nav-btn, .category-btn {
    touch-action: manipulation;
    -webkit-tap-highlight-color: rgba(0, 255, 136, 0.15);
}

/* =================================================================
   HAMBURGER MENU FOR MOBILE
   ================================================================= */
.mobile-menu-toggle {
    display: none;
    background: rgba(0, 255, 136, 0.2);
    border: 2px solid #00ff88;
    border-radius: 8px;
    color: #00ff88;
    padding: 10px 14px;
    font-size: 1.5rem;
    cursor: pointer;
    z-index: 10002;
    transition: all 0.3s ease;
    line-height: 1;
}

.mobile-menu-toggle:hover {
    background: rgba(0, 255, 136, 0.4);
}

/* =================================================================
   LARGE DESKTOP (1400px+) - Default styles apply
   ================================================================= */

/* =================================================================
   DESKTOP (1200px - 1399px)
   ================================================================= */
@media (max-width: 1399px) {
    .civilization-grid {
        grid-template-columns: repeat(3, 1fr) !important;
    }

    .communications-container {
        grid-template-columns: 1fr 2fr !important;
    }

    .commerce-container,
    .market-container {
        max-width: 100%;
        padding: 0 1rem;
    }
}

/* =================================================================
   SMALL DESKTOP / LARGE TABLET LANDSCAPE (992px - 1199px)
   ================================================================= */
@media (max-width: 1199px) {
    .main-container {
        flex-direction: column !important;
    }

    .login-section {
        border-right: none !important;
        border-bottom: 2px solid rgba(0, 255, 136, 0.3);
        min-height: auto;
        padding: 1.5rem;
    }

    .data-section {
        flex: 1;
    }

    .civilization-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        padding: 1.5rem !important;
    }

    .creation-grid {
        grid-template-columns: 1fr !important;
    }

    .communications-container {
        grid-template-columns: 1fr !important;
        height: auto !important;
        gap: 1rem;
    }

    .comm-sidebar, .shop-sidebar {
        order: 2;
    }

    .main-feed {
        order: 1;
    }

    .nav-main {
        gap: 6px;
    }

    .category-btn {
        padding: 10px 14px;
        font-size: 12px;
    }

    .nav-user-section {
        flex-wrap: wrap;
        justify-content: center;
    }
}

/* =================================================================
   TABLET PORTRAIT (768px - 991px)
   ================================================================= */
@media (max-width: 991px) {
    /* Navigation - Show hamburger */
    .mobile-menu-toggle {
        display: block;
    }

    .nav-container .nav-main {
        display: none;
        flex-direction: column;
        width: 100%;
        padding: 10px;
        gap: 4px;
        background: rgba(15, 27, 46, 0.98);
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        z-index: 10001;
        border-bottom: 2px solid #00ff88;
        max-height: 70vh;
        overflow-y: auto;
    }

    .nav-container .nav-main.mobile-open {
        display: flex !important;
    }

    .nav-container .brand {
        display: flex;
        justify-content: space-between;
        align-items: center;
    }

    .nav-category {
        width: 100%;
    }

    .category-btn {
        width: 100%;
        justify-content: flex-start;
        border-radius: 8px;
    }

    .dropdown-menu {
        position: static !important;
        opacity: 1 !important;
        visibility: visible !important;
        transform: none !important;
        display: none;
        width: 100%;
        margin-top: 0;
        border-radius: 0 0 8px 8px;
        box-shadow: none;
    }

    .nav-category.mobile-dropdown-open .dropdown-menu {
        display: block;
    }

    .nav-user-section {
        flex-direction: column;
        align-items: stretch;
        margin-left: 0;
        gap: 8px;
        padding: 10px;
        border-top: 1px solid rgba(0, 255, 136, 0.2);
    }

    .nav-trix-display,
    .civ-message-btn,
    .earnings-btn,
    .logout-btn {
        justify-content: center;
        text-align: center;
    }

    /* Typography */
    .login-title {
        font-size: 1.6rem !important;
    }

    .data-title {
        font-size: 1.4rem !important;
    }

    .nav-title {
        font-size: 1.5rem !important;
    }

    /* Grids */
    .civilization-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        padding: 1rem !important;
        gap: 1rem !important;
    }

    .overview-grid,
    .catalog-grid,
    .patents-grid,
    .metrics-grid,
    .financial-grid,
    .sales-grid {
        grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)) !important;
    }

    .market-grid,
    .games-grid,
    .inventory-grid {
        grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)) !important;
    }

    /* Dashboard */
    .dashboard-header {
        padding: 1rem !important;
    }

    .nav-menu {
        flex-direction: column;
        gap: 0.8rem;
    }

    .nav-buttons {
        flex-wrap: wrap;
        justify-content: center;
        gap: 0.5rem;
    }

    /* Forms */
    .form-row {
        grid-template-columns: 1fr !important;
    }

    .search-bar {
        flex-direction: column;
    }

    /* Cards */
    .civ-card {
        padding: 1rem;
    }

    .civ-name {
        font-size: 1.1rem;
    }

    /* Modals */
    .terms-content,
    .book-details-content,
    .save-manager-content {
        max-width: 95% !important;
        padding: 1.5rem !important;
        margin: 10px;
    }

    /* Companion Chat */
    .numtrixian-companion {
        max-width: 100%;
    }

    .chat-area {
        height: 300px;
    }

    #aiChatDisplay {
        min-height: 250px !important;
        max-height: 350px !important;
    }

    /* Section padding */
    .section:not(#inventorsSection):not(#commerceSection):not(#marketSection):not(#donationsSection):not(#infoSection) {
        padding: 1rem !important;
    }

    /* Fixed buttons */
    .save-button {
        width: 44px;
        height: 44px;
        bottom: 15px;
        right: 15px;
    }

    .save-manager-button {
        width: 44px;
        height: 44px;
        bottom: 15px;
        right: 70px;
    }
}

/* =================================================================
   MOBILE LANDSCAPE / LARGE PHONE (576px - 767px)
   ================================================================= */
@media (max-width: 767px) {
    body {
        font-size: 14px;
    }

    /* Navigation */
    .brand {
        font-size: 16px !important;
        padding: 10px 12px !important;
    }

    /* Typography */
    .login-title {
        font-size: 1.3rem !important;
        letter-spacing: 1px;
    }

    .data-title {
        font-size: 1.2rem !important;
    }

    .nav-title {
        font-size: 1.2rem !important;
    }

    .feature-title {
        font-size: 1rem;
    }

    /* Grids - Single column on small screens */
    .civilization-grid {
        grid-template-columns: 1fr !important;
        padding: 0.8rem !important;
        gap: 0.8rem !important;
    }

    .overview-grid,
    .catalog-grid,
    .patents-grid,
    .metrics-grid,
    .financial-grid,
    .sales-grid,
    .market-grid,
    .games-grid,
    .inventory-grid {
        grid-template-columns: 1fr !important;
    }

    .civ-stats {
        grid-template-columns: 1fr 1fr;
        gap: 0.5rem;
    }

    /* Dashboard */
    .dashboard-header {
        padding: 0.8rem !important;
    }

    .dashboard-content {
        padding: 0.5rem !important;
    }

    .nav-buttons {
        width: 100%;
    }

    .nav-btn {
        flex: 1;
        text-align: center;
        font-size: 0.7rem;
        padding: 0.5rem 0.6rem;
        min-width: 0;
    }

    /* Market */
    .market-header {
        flex-direction: column !important;
        gap: 0.8rem;
    }

    .market-actions {
        flex-direction: column !important;
        width: 100%;
    }

    .category-filters {
        flex-wrap: wrap;
        justify-content: flex-start;
    }

    /* Corp */
    .corp-header {
        flex-direction: column !important;
        gap: 0.8rem;
    }

    .corp-finances {
        flex-direction: column !important;
        width: 100%;
    }

    .finance-actions {
        flex-direction: column !important;
    }

    /* Promotion pricing */
    .promotion-pricing {
        grid-template-columns: 1fr !important;
    }

    /* Gaming */
    .gaming-nav {
        flex-direction: column !important;
        align-items: stretch !important;
    }

    .nav-icon {
        width: 100% !important;
        max-width: none !important;
    }

    /* Chat / AI Companion */
    .chat-area {
        height: 250px !important;
    }

    #aiChatDisplay {
        min-height: 200px !important;
        max-height: 300px !important;
    }

    .companion-header {
        padding: 0.8rem 1rem;
    }

    .chat-input-area {
        padding: 0.8rem;
        flex-direction: column;
        gap: 0.5rem;
    }

    .send-btn {
        width: 100%;
    }

    .message {
        max-width: 90%;
        padding: 0.8rem;
        font-size: 0.9rem;
    }

    /* Forms */
    .form-input, .form-select, .form-textarea {
        padding: 0.7rem;
        font-size: 0.9rem;
    }

    .login-form {
        max-width: 100%;
        padding: 0 0.5rem;
    }

    /* Buttons */
    .login-button, .guest-button {
        padding: 1rem;
        font-size: 0.95rem;
    }

    .orb-controls {
        flex-direction: column;
        width: 100%;
    }

    .orb-btn {
        width: 100%;
        text-align: center;
    }

    /* Avatar */
    .energy-orb {
        width: 150px;
        height: 150px;
    }

    .avatar-form,
    .avatar-info,
    .energy-orb-container {
        padding: 1rem;
    }

    .avatar-preview {
        min-height: 200px;
    }

    /* Modals - fullscreen on small screens */
    .terms-content,
    .book-details-content {
        max-width: 100% !important;
        max-height: 95vh !important;
        border-radius: 8px !important;
        margin: 5px;
        padding: 1rem !important;
    }

    .terms-title, .book-details-title {
        font-size: 1.2rem;
    }

    .terms-buttons, .book-form-buttons {
        flex-direction: column;
    }

    .terms-accept, .terms-decline, .book-form-submit, .book-form-cancel {
        width: 100%;
        text-align: center;
    }

    /* Feature highlights */
    .feature-highlights {
        max-width: 100%;
        padding: 1rem;
    }

    /* Sections */
    .section:not(#inventorsSection):not(#commerceSection):not(#marketSection):not(#donationsSection):not(#infoSection) {
        padding: 0.8rem !important;
    }

    .section-header, .production-header, .employees-header, .rd-header, .marketing-header, .finances-header, .marketplace-header {
        flex-direction: column;
        gap: 0.5rem;
        text-align: center;
    }

    /* Empty states */
    .empty-dashboard, .empty-inventory, .empty-market, .empty-state {
        padding: 1.5rem;
        font-size: 1rem;
    }

    /* Notifications */
    .notification {
        top: 10px;
        right: 10px;
        left: 10px;
        max-width: none;
        text-align: center;
    }

    /* Save buttons - stack vertically on mobile */
    .save-button {
        bottom: 10px;
        right: 10px;
        width: 42px;
        height: 42px;
        font-size: 1.2rem;
    }

    .save-manager-button {
        bottom: 60px;
        right: 10px;
        width: 42px;
        height: 42px;
        font-size: 1.2rem;
    }
}

/* =================================================================
   SMALL MOBILE PORTRAIT (max-width: 480px)
   ================================================================= */
@media (max-width: 480px) {
    body {
        font-size: 13px;
    }

    .brand {
        font-size: 14px !important;
        letter-spacing: 1px;
    }

    .login-title {
        font-size: 1.1rem !important;
        letter-spacing: 0;
    }

    .data-title, .nav-title {
        font-size: 1rem !important;
    }

    /* Even smaller grids */
    .civ-stats {
        grid-template-columns: 1fr;
    }

    .stat-item {
        padding: 0.5rem;
    }

    .stat-value {
        font-size: 1rem;
    }

    .stat-label {
        font-size: 0.7rem;
    }

    /* Tech tags wrap */
    .tech-tag {
        font-size: 0.65rem;
        padding: 0.2rem 0.4rem;
    }

    /* Buttons */
    .nav-btn {
        font-size: 0.65rem;
        padding: 0.4rem 0.5rem;
    }

    /* Chat */
    .chat-area {
        height: 200px !important;
    }

    #aiChatDisplay {
        min-height: 150px !important;
        max-height: 250px !important;
    }

    .message {
        max-width: 95%;
        font-size: 0.85rem;
        padding: 0.6rem;
    }

    /* Energy orb */
    .energy-orb {
        width: 120px;
        height: 120px;
    }

    /* Login options */
    .login-options {
        flex-direction: column;
        gap: 0.8rem;
        align-items: flex-start;
    }

    /* Companion avatar */
    .companion-avatar {
        width: 40px;
        height: 40px;
    }
}

/* =================================================================
   VERY SMALL SCREENS (max-width: 360px) - Galaxy Fold, etc
   ================================================================= */
@media (max-width: 360px) {
    .brand {
        font-size: 12px !important;
    }

    .login-title {
        font-size: 1rem !important;
    }

    .category-btn {
        padding: 8px 10px;
        font-size: 11px;
    }

    .form-input, .form-select, .form-textarea {
        padding: 0.6rem;
        font-size: 0.85rem;
    }

    .login-button, .guest-button {
        padding: 0.8rem;
        font-size: 0.85rem;
        letter-spacing: 1px;
    }
}

/* =================================================================
   TABLET LANDSCAPE SPECIFIC
   ================================================================= */
@media (min-width: 768px) and (max-width: 1024px) and (orientation: landscape) {
    .main-container {
        flex-direction: row !important;
    }

    .login-section {
        flex: 0 0 40%;
        border-right: 2px solid rgba(0, 255, 136, 0.3) !important;
        border-bottom: none !important;
    }

    .civilization-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    .communications-container {
        grid-template-columns: 1fr 2fr !important;
    }
}

/* =================================================================
   LANDSCAPE MOBILE SPECIFIC
   ================================================================= */
@media (max-height: 500px) and (orientation: landscape) {
    .main-container {
        height: auto;
        min-height: 100vh;
    }

    .login-section {
        padding: 1rem;
    }

    .login-title {
        font-size: 1.2rem !important;
        margin-bottom: 0.3rem;
    }

    .login-subtitle {
        margin-bottom: 1rem;
    }

    .feature-highlights {
        display: none;
    }

    .chat-area {
        height: 180px !important;
    }

    /* Reduce padding in landscape */
    .section:not(#inventorsSection):not(#commerceSection):not(#marketSection):not(#donationsSection):not(#infoSection) {
        padding: 0.5rem !important;
    }
}

/* =================================================================
   GAMING CONSOLE SPECIFIC (TV / Console Browsers)
   Large screens with controller/remote navigation
   ================================================================= */
@media (min-width: 1920px) {
    body {
        font-size: 18px;
    }

    .brand {
        font-size: 28px;
        padding: 20px 30px;
    }

    .category-btn {
        padding: 16px 28px;
        font-size: 16px;
    }

    .nav-btn {
        padding: 1rem 1.5rem;
        font-size: 1rem;
    }

    .login-title {
        font-size: 3rem !important;
    }

    .civ-card {
        padding: 2rem;
    }

    .civ-name {
        font-size: 1.5rem;
    }

    .stat-value {
        font-size: 1.5rem;
    }

    /* Bigger touch targets for remote/controller */
    a, button, .nav-btn, .category-btn, .dropdown-item {
        min-height: 56px;
    }

    .dropdown-item {
        padding: 18px 24px;
        font-size: 16px;
    }

    .form-input, .form-select, .form-textarea {
        padding: 1.2rem 1.5rem;
        font-size: 1.1rem;
    }

    .login-button, .guest-button {
        padding: 1.4rem;
        font-size: 1.2rem;
    }
}

/* =================================================================
   4K / Ultra-wide
   ================================================================= */
@media (min-width: 2560px) {
    body {
        font-size: 20px;
    }

    .commerce-container,
    .market-container {
        max-width: 2200px;
    }

    .civilization-grid {
        grid-template-columns: repeat(5, 1fr) !important;
    }
}

/* =================================================================
   HIGH CONTRAST / ACCESSIBILITY
   ================================================================= */
@media (prefers-contrast: high) {
    .civ-card, .login-card, .avatar-form, .energy-orb-container {
        border-width: 3px;
    }

    .form-input, .form-select, .form-textarea {
        border-width: 3px;
    }

    .nav-btn, .category-btn {
        border-width: 3px;
    }
}

/* =================================================================
   REDUCED MOTION
   ================================================================= */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }

    .star {
        animation: none !important;
    }
}

/* =================================================================
   PRINT STYLES
   ================================================================= */
@media print {
    .cosmic-background,
    .star-field,
    .nav-container,
    .save-button,
    .save-manager-button,
    .mobile-menu-toggle {
        display: none !important;
    }

    body {
        background: #fff;
        color: #000;
    }

    .civ-card {
        border: 1px solid #ccc;
        break-inside: avoid;
    }
}

/* =================================================================
   SAFE AREA INSETS (Notched phones, etc.)
   ================================================================= */
@supports (padding: max(0px)) {
    .nav-container {
        padding-left: max(20px, env(safe-area-inset-left));
        padding-right: max(20px, env(safe-area-inset-right));
    }

    .dashboard-content,
    .section {
        padding-left: max(0.5rem, env(safe-area-inset-left));
        padding-right: max(0.5rem, env(safe-area-inset-right));
    }

    .save-button,
    .save-manager-button {
        bottom: max(10px, env(safe-area-inset-bottom));
    }
}

/* =================================================================
   IFRAME RESPONSIVE
   ================================================================= */
iframe {
    max-width: 100%;
    border: none;
}

.iframe-container {
    position: relative;
    width: 100%;
    padding-bottom: 56.25%; /* 16:9 */
    height: 0;
    overflow: hidden;
}

.iframe-container iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

/* =================================================================
   SCROLLBAR STYLING (for all devices)
   ================================================================= */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.3);
}

::-webkit-scrollbar-thumb {
    background: rgba(0, 255, 136, 0.4);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 255, 136, 0.6);
}

@media (max-width: 767px) {
    ::-webkit-scrollbar {
        width: 4px;
        height: 4px;
    }
}

/* =================================================================
   OVERFLOW / TABLE RESPONSIVE
   ================================================================= */
.table-responsive {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

table {
    min-width: 100%;
}

/* =================================================================
   FLEX / GRID UTILITIES FOR RESPONSIVE
   ================================================================= */
.flex-wrap-mobile {
    display: flex;
    flex-wrap: wrap;
}

@media (max-width: 767px) {
    .stack-mobile {
        flex-direction: column !important;
    }

    .hide-mobile {
        display: none !important;
    }

    .full-width-mobile {
        width: 100% !important;
        max-width: 100% !important;
        flex: none !important;
    }
}

@media (min-width: 768px) {
    .hide-desktop {
        display: none !important;
    }
}

@media (max-width: 991px) {
    .hide-tablet {
        display: none !important;
    }
}
