/* ═══════════════════════════════════════════════════════════════════════
   SilaLingo — Global Responsive Styles
   Phase 4: Comprehensive mobile & tablet support
   ═══════════════════════════════════════════════════════════════════════ */

/* ── Breakpoints ──
   sm: 576px   | md: 768px   | lg: 992px   | xl: 1200px
   We use 991.98px, 767.98px, 575.98px to match Bootstrap 5 behavior.
*/

/* =====================================================================
   1. NAVBAR
   ===================================================================== */

@media (max-width: 991.98px) {
    /* Collapsed navbar already styled in base.css; these are additions */
    .navbar .ms-auto {
        flex-direction: column !important;
        gap: 0.75rem !important;
    }

    /* Stats bar in navbar — stack and shrink */
    .navbar .ms-auto .d-flex.align-items-center.gap-3 {
        flex-wrap: wrap;
        justify-content: center;
        gap: 0.5rem !important;
    }

    .navbar .ms-auto .d-flex.align-items-center.gap-3 > span,
    .navbar .ms-auto .d-flex.align-items-center.gap-3 > a {
        font-size: 0.8rem;
    }

    /* Notification dropdown width fix on mobile */
    .notification-dropdown-menu.show {
        width: 280px;
        max-height: 60vh;
    }

    /* User dropdown button full width in collapsed nav */
    .navbar-collapse .dropdown-toggle {
        width: auto;
        justify-content: center;
    }
}

@media (max-width: 575.98px) {
    .navbar-brand img {
        height: 40px !important;
        width: auto;
    }

    .navbar .ms-auto .d-flex.align-items-center.gap-3 {
        gap: 0.35rem !important;
    }

    .navbar .ms-auto .badge,
    .navbar .ms-auto .fw-bold {
        font-size: 0.75rem;
    }

    /* Smaller toggler padding */
    .navbar-toggler {
        padding: 0.25rem 0.5rem;
    }
}

/* =====================================================================
   2. MAIN CONTAINER & GENERAL LAYOUT
   ===================================================================== */

@media (max-width: 767.98px) {
    main.container-lg {
        padding-left: 0.75rem;
        padding-right: 0.75rem;
        padding-top: 1rem !important;
        padding-bottom: 1rem !important;
    }

    .container.py-5,
    .container-fluid.py-5 {
        padding-top: 1.5rem !important;
        padding-bottom: 1.5rem !important;
    }

    .display-4 {
        font-size: 1.75rem;
    }

    .display-1 {
        font-size: 2.5rem;
    }

    h1, .h1 {
        font-size: 1.75rem;
    }

    h2, .h2 {
        font-size: 1.4rem;
    }

    h3, .h3 {
        font-size: 1.15rem;
    }

    .lead {
        font-size: 1rem;
    }
}

/* =====================================================================
   3. REVIEW SESSION
   ===================================================================== */

@media (max-width: 767.98px) {
    .review-container {
        padding: 0 0.5rem;
    }

    /* Session progress bar */
    .session-progress-track {
        width: 100%;
        max-width: none;
    }

    .session-progress-bar {
        height: 8px;
    }

    /* Question card */
    .card-question {
        min-height: auto;
        padding: 1.5rem 1rem;
    }

    .card-question .card-body {
        padding: 1rem 0.5rem;
    }

    /* Choice buttons — full width, stacked */
    .choices-grid {
        flex-direction: column;
        align-items: stretch;
    }

    .choices-grid .choice-btn {
        width: 100%;
        min-width: 100%;
        margin-bottom: 0.5rem;
        padding: 0.875rem 1rem;
        font-size: 0.95rem;
    }

    .answer-options .btn,
    .choice-btn {
        width: 100%;
        margin-bottom: 0.5rem;
        padding: 0.875rem 1rem;
        font-size: 0.95rem;
    }

    .choice-btn .fw-bold {
        font-size: 1rem;
    }

    /* Question text sizing */
    .question-text.display-4 {
        font-size: 1.75rem;
    }

    /* Audio play button in review */
    .audio-play-btn {
        width: 64px;
        height: 64px;
    }

    /* Tile review */
    .tile-answer-area,
    .tile-pool-area {
        max-width: 100%;
        min-height: 80px;
        height: auto;
    }

    .tile-btn {
        font-size: 1rem;
        padding: 6px 12px;
        min-width: 40px;
    }

    /* Feedback section */
    #feedback-section {
        margin-top: 0.75rem;
    }

    #feedback-card .card-body {
        flex-direction: column;
        align-items: flex-start !important;
        gap: 0.75rem;
    }

    #feedback-card .card-body > div {
        width: 100%;
        text-align: center;
    }

    /* Shadowing review */
    .shadow-card-lg {
        min-height: auto;
        padding: 1.5rem 1rem;
    }

    .shadow-native-btn,
    .shadow-user-btn {
        width: 64px;
        height: 64px;
    }

    /* Combo milestone popup positioning */
    .combo-milestone {
        left: 0.5rem;
        right: 0.5rem;
        top: 20%;
        white-space: normal;
        text-align: center;
        font-size: 1.25rem;
        padding: 10px 16px;
    }
}

@media (max-width: 575.98px) {
    .card-question h2,
    .card-question .thai-text {
        font-size: 1.5rem;
    }

    .answer-options .btn,
    .choice-btn {
        font-size: 0.9rem;
        padding: 0.75rem;
    }

    .context-blank {
        min-width: 40px;
    }

    /* Speed bonus badge smaller */
    .speed-bonus-badge {
        font-size: 0.8rem;
        padding: 3px 10px;
    }
}

/* =====================================================================
   4. REVIEW DASHBOARD
   ===================================================================== */

@media (max-width: 767.98px) {
    .fsrs-card .row.align-items-center {
        text-align: center;
    }

    .fsrs-card .col-lg-5 {
        margin-top: 1rem;
    }

    .fsrs-slider-wrap {
        min-width: auto;
        width: 100%;
        align-items: center;
    }

    .fsrs-slider-wrap input[type="range"],
    .fsrs-slider-ticks {
        width: 100%;
        max-width: 240px;
    }

    .fsrs-card .d-flex.flex-column.align-items-start.align-items-lg-end {
        align-items: center !important;
    }

    /* Due word list items */
    .due-word-item {
        flex-direction: column;
        align-items: flex-start !important;
        gap: 0.5rem;
    }

    .due-word-item .text-end {
        text-align: left !important;
        width: 100%;
    }
}

/* =====================================================================
   5. VOCABULARY LIST
   ===================================================================== */

@media (max-width: 767.98px) {
    .vocabulary-page .page-header h1 {
        font-size: 1.75rem;
    }

    /* Filter form — full width inputs */
    .vocabulary-page form .col-md-3 {
        width: 100%;
    }

    /* Admin filters grid */
    .admin-filters-grid {
        flex-direction: column;
        gap: 0.75rem;
    }

    .admin-filter-group .btn-group {
        flex-wrap: wrap;
    }

    .admin-filter-group .btn-group .btn {
        flex: 1 1 auto;
        min-width: 80px;
    }

    /* Word cards — 2 columns on tablet */
    .vocabulary-page .row-cols-sm-2 > * {
        flex: 0 0 auto;
        width: 50%;
    }

    /* Page header flex wrap */
    .page-header.d-flex,
    .d-flex.align-items-center.justify-content-between {
        flex-wrap: wrap;
        gap: 0.75rem;
    }

    .page-header.d-flex > h1,
    .page-header.d-flex > .h2,
    .d-flex.align-items-center.justify-content-between > h1,
    .d-flex.align-items-center.justify-content-between > .h2 {
        flex: 1 1 auto;
    }
}

@media (max-width: 575.98px) {
    /* Word cards — 1 column on phone */
    .vocabulary-page .row-cols-1 > * {
        width: 100%;
    }

    .word-card .thai-medium {
        font-size: 1.4rem;
    }

    .word-card .d-flex.align-items-center.gap-2 {
        gap: 0.35rem !important;
    }

    .word-card .badge {
        font-size: 0.7rem;
    }

    /* Pagination compact */
    .pagination .page-link {
        padding: 0.375rem 0.625rem;
        font-size: 0.875rem;
    }
}

/* =====================================================================
   6. WORD DETAIL
   ===================================================================== */

@media (max-width: 767.98px) {
    .word-detail-card {
        padding: 1.25rem;
    }

    .word-detail-page .word-main h1.thai-xlarge {
        font-size: 2.5rem;
    }

    /* Audio buttons row wrap */
    .word-actions {
        flex-wrap: wrap;
        justify-content: flex-start;
        width: 100%;
    }

    /* Example sentences */
    .examples-list .card-body .d-flex.align-items-start.justify-content-between {
        flex-direction: column;
    }

    .examples-list .card-body .d-flex.align-items-start.justify-content-between > .flex-shrink-0 {
        margin-left: 0 !important;
        margin-top: 0.75rem;
        flex-direction: row !important;
        width: 100%;
        justify-content: flex-start;
    }

    /* Confusion words */
    .word-confusions .d-flex.align-items-center.justify-content-between {
        flex-direction: column;
        align-items: flex-start !important;
        gap: 0.5rem;
    }

    .word-confusions .d-flex.align-items-center.justify-content-between > .d-flex {
        width: 100%;
    }

    /* Related words grid already uses Bootstrap row-cols */

    /* Sentence cards audio panel */
    .sentence-audio-panel {
        width: 48px;
        min-height: 60px;
    }
}

@media (max-width: 575.98px) {
    .word-detail-page .word-main h1.thai-xlarge {
        font-size: 2rem;
    }

    .word-romanization .romanization {
        font-size: 1.1rem;
    }

    .definition-main {
        font-size: 1.05rem;
    }

    .example-card .thai-text {
        font-size: 1.1rem;
    }
}

/* =====================================================================
   7. PROGRESS DASHBOARD
   ===================================================================== */

@media (max-width: 767.98px) {
    .progress-page {
        padding: 0 0.5rem;
    }

    .stats-overview {
        grid-template-columns: 1fr 1fr;
        gap: 0.75rem;
    }

    .stat-card {
        padding: 1rem;
        gap: 0.75rem;
    }

    .stat-icon {
        font-size: 1.75rem;
    }

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

    /* Mastery chart */
    .mastery-chart {
        height: 140px;
        gap: 0.25rem;
        padding: 0.5rem 0.125rem;
    }

    .chart-bar {
        max-width: 28px;
        border-radius: 0.25rem 0.25rem 0 0;
    }

    .bar-count {
        font-size: 0.65rem;
    }

    .bar-label {
        font-size: 0.55rem;
        margin-top: 0.25rem;
    }

    /* Category grid */
    .category-grid {
        grid-template-columns: 1fr 1fr;
        gap: 0.75rem;
    }

    .category-card {
        padding: 1rem;
    }

    .progress-ring {
        width: 64px;
        height: 64px;
    }

    .progress-value {
        font-size: 0.95rem;
    }

    /* Achievements */
    .achievements-grid {
        gap: 0.5rem;
        padding: 0.25rem;
    }

    .achievement-card {
        min-width: 80px;
        padding: 0.75rem 0.5rem;
    }

    .achievement-icon {
        font-size: 1.5rem;
    }

    .achievement-name {
        font-size: 0.7rem;
    }
}

@media (max-width: 575.98px) {
    .stats-overview {
        grid-template-columns: 1fr 1fr;
    }

    .stat-card {
        flex-direction: column;
        text-align: center;
        gap: 0.25rem;
    }

    .category-grid {
        grid-template-columns: 1fr 1fr;
    }

    .mastery-chart {
        height: 120px;
    }
}

/* =====================================================================
   8. SETTINGS
   ===================================================================== */

@media (max-width: 767.98px) {
    .settings-container {
        padding-left: 0.75rem;
        padding-right: 0.75rem;
    }

    /* Stack preference rows vertically */
    .pref-row {
        flex-direction: column;
        align-items: flex-start !important;
        gap: 0.75rem;
        padding: 1rem 0;
    }

    .pref-info {
        width: 100%;
    }

    /* Thai font picker */
    #thaifontPicker {
        justify-content: center;
    }

    .thai-font-btn {
        min-width: 90px;
        padding: 10px 8px;
    }

    .thai-font-btn .font-preview {
        font-size: 1.1rem;
    }

    .thai-font-btn .font-label {
        font-size: 0.7rem;
    }

    /* Subscription section */
    .settings-section .d-flex.align-items-center.gap-3 {
        flex-wrap: wrap;
    }

    /* Danger zone button */
    .settings-section .d-flex.align-items-center.justify-content-between {
        flex-direction: column;
        align-items: flex-start !important;
        gap: 0.75rem;
    }

    .settings-section .d-flex.align-items-center.justify-content-between .btn {
        align-self: flex-start;
    }
}

/* =====================================================================
   9. ROADMAP / LEARNING
   ===================================================================== */

@media (max-width: 767.98px) {
    .roadmap-page {
        padding-bottom: 2rem;
    }

    /* Sidebar search dropdown */
    .search-results-dropdown {
        max-height: 50vh;
        position: fixed;
        top: auto;
        left: 0.75rem;
        right: 0.75rem;
        z-index: 9999;
    }

    .search-result-thai {
        font-size: 1rem;
    }

    .search-result-meta {
        font-size: 0.75rem;
    }

    /* Level circle smaller */
    .level-circle-wrapper {
        width: 80px;
        height: 80px;
    }

    .level-number {
        font-size: 2rem;
    }

    /* Continue learning card */
    .continue-learning-card {
        max-width: 100%;
    }

    /* Timeline cards */
    .timeline-card-main {
        padding: 0.625rem 0.875rem;
    }

    .timeline-card-icon {
        width: 36px;
        height: 36px;
        font-size: 1.1rem;
    }

    .timeline-card-title {
        font-size: 0.85rem;
    }

    /* Module cards in grid */
    .modules-grid {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
        gap: 0.875rem;
    }

    .module-card-body {
        padding: 0.875rem;
    }

    .module-title {
        font-size: 0.88rem;
    }

    /* Milestone card */
    .milestone-thai-text {
        font-size: 1.15rem;
        padding: 0.4rem;
    }

    .milestone-sentence-wrap {
        flex-wrap: wrap;
    }

    /* Nav tabs */
    .nav-tabs {
        gap: 0.35rem;
    }

    .nav-tabs .nav-link {
        padding: 0.45rem 0.875rem;
        font-size: 0.85rem;
    }
}

@media (max-width: 575.98px) {
    .roadmap-page.container-fluid {
        padding-left: 0.75rem !important;
        padding-right: 0.75rem !important;
    }

    .winding-path-wrap {
        padding-left: 0;
        padding-right: 0;
    }

    /* Unit section padding */
    .unit-section {
        padding: 1rem !important;
        margin-bottom: 1.5rem !important;
    }

    .unit-header {
        flex-direction: column;
        align-items: flex-start !important;
        gap: 0.75rem;
    }

    .unit-icon-wrapper {
        margin-right: 0;
    }

    .modules-grid {
        grid-template-columns: 1fr;
    }

    /* Gate smaller */
    .gate-platform {
        width: 96px;
        height: 96px;
    }

    .gate-img {
        width: 76px;
        height: 76px;
    }

    .gate-badge {
        font-size: 0.75rem;
        padding: 0.25rem 1rem;
    }

    /* Lesson items in dropdown */
    .lesson-item {
        padding: 0.5rem 0.75rem;
        font-size: 0.8rem;
    }
}

/* =====================================================================
   10. LESSON PRACTICE
   ===================================================================== */

@media (max-width: 767.98px) {
    .lesson-practice-page {
        padding: 1rem;
    }

    .practice-header h1 {
        font-size: 1.4rem;
    }

    .items-preview {
        padding: 1rem;
    }

    .practice-item {
        padding: 0.75rem;
        gap: 0.75rem;
    }

    .item-content .thai-text {
        font-size: 1.1rem;
    }

    .mastery-dots {
        gap: 2px;
    }

    .dot {
        width: 6px;
        height: 6px;
    }
}

/* =====================================================================
   11. TYPING
   ===================================================================== */

@media (max-width: 767.98px) {
    .keyboard-container {
        padding: 0 0.25rem;
    }

    .exercise-text {
        font-size: 1.3rem;
        line-height: 2;
        min-height: 80px;
    }

    .completion-stats {
        gap: 1rem;
    }

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

@media (max-width: 575.98px) {
    .new-key-showcase .key-char {
        font-size: 2rem;
    }

    .stat-badge {
        font-size: 0.875rem;
    }
}

/* =====================================================================
   12. HOME PAGE (LOGGED-IN & LOGGED-OUT)
   ===================================================================== */

@media (max-width: 767.98px) {
    .hero-content--auth {
        padding: 2.5rem 1rem;
    }

    .hero-content--auth h1 {
        font-size: 1.75rem;
    }

    .hero-split {
        padding: 2rem 1rem;
        min-height: auto;
    }

    .hero-title {
        font-size: 1.75rem;
    }

    .hero-mascot {
        width: 140px;
    }

    .hero-signup-card {
        padding: 1.5rem;
    }

    .features-section {
        padding: 2.5rem 0 2rem;
    }

    .features-section h2 {
        font-size: 1.5rem;
        margin-bottom: 2rem;
    }

    .feature-card {
        padding: 1.75rem 1.25rem;
    }

    /* Logged-in roadmap on home */
    .roadmap-container {
        padding-left: 20px;
        margin-top: 1rem;
    }

    .units-path::before {
        left: 8px;
    }

    .unit-block {
        padding: 1.25rem;
        margin-bottom: 2rem;
    }

    .unit-block::before {
        left: -26px;
        width: 14px;
        height: 14px;
        border-width: 3px;
    }

    .modules-grid {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
        gap: 1rem;
    }

    .module-icon-circle {
        width: 64px;
        height: 64px;
        font-size: 2.25rem;
    }

    .quick-stats {
        flex-wrap: wrap;
        gap: 0.75rem;
    }

    .stat-card {
        min-width: auto;
        flex: 1 1 45%;
    }
}

/* =====================================================================
   13. FOOTER
   ===================================================================== */

@media (max-width: 767.98px) {
    .footer {
        padding: 1.75rem 0;
        text-align: center;
    }

    .footer .row.align-items-center {
        flex-direction: column;
        gap: 0.75rem;
    }

    .footer .col-md-6 {
        text-align: center !important;
    }

    .footer a {
        margin-right: 0.75rem;
        margin-left: 0.75rem;
        font-size: 0.875rem;
    }
}

/* =====================================================================
   14. MODALS
   ===================================================================== */

@media (max-width: 767.98px) {
    .modal-dialog {
        margin: 0.5rem;
    }

    .modal-dialog.modal-lg,
    .modal-dialog.modal-xl {
        max-width: calc(100% - 1rem);
        margin: 0.5rem auto;
    }

    .modal-content {
        border-radius: 0.75rem;
    }

    .modal-body {
        padding: 1rem;
    }

    .modal-mascot-img {
        max-width: 100px;
    }
}

@media (max-width: 575.98px) {
    .modal-dialog.modal-dialog-centered {
        min-height: calc(100% - 1rem);
    }

    .modal-footer {
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .modal-footer .btn {
        flex: 1 1 auto;
    }
}

/* =====================================================================
   15. TABLES (admin dashboards, lists)
   ===================================================================== */

@media (max-width: 767.98px) {
    .table-responsive {
        border-radius: 0.5rem;
    }

    /* Force tables to be responsive when not wrapped */
    table:not(.table-responsive) {
        display: block;
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
}

/* =====================================================================
   16. ALPHABET & SIGNS
   ===================================================================== */

@media (max-width: 767.98px) {
    .alphabet-grid {
        grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)) !important;
        gap: 0.75rem !important;
    }

    .alphabet-card {
        padding: 0.75rem !important;
    }

    .alphabet-card .thai-large {
        font-size: 2rem !important;
    }
}

@media (max-width: 575.98px) {
    .alphabet-grid {
        grid-template-columns: repeat(auto-fill, minmax(80px, 1fr)) !important;
    }

    .alphabet-card .thai-large {
        font-size: 1.75rem !important;
    }
}

/* =====================================================================
   17. FORMS & INPUTS
   ===================================================================== */

@media (max-width: 575.98px) {
    .form-control,
    .form-select {
        font-size: 16px; /* Prevent iOS zoom on focus */
    }

    .btn-lg {
        padding: 0.625rem 1.25rem;
        font-size: 1rem;
    }

    .input-group {
        flex-wrap: wrap;
    }

    .input-group > .form-control,
    .input-group > .form-select,
    .input-group > .btn {
        width: 100%;
        border-radius: var(--radius-md) !important;
        margin-bottom: 0.25rem;
    }
}

/* =====================================================================
   18. NOTIFICATIONS LIST
   ===================================================================== */

@media (max-width: 767.98px) {
    .notification-list-item {
        padding: 0.75rem;
    }

    .notification-list-item .d-flex {
        flex-direction: column;
        gap: 0.5rem;
    }

    .notification-list-item .text-muted.small {
        align-self: flex-start;
    }
}

/* =====================================================================
   19. AUTH PAGES
   ===================================================================== */

@media (max-width: 575.98px) {
    .auth-page {
        padding: 1rem;
        min-height: calc(100vh - 160px);
    }

    .auth-card {
        padding: 1.5rem;
        border-radius: 0.875rem;
    }

    .auth-mascot {
        max-width: 100px;
    }
}

/* =====================================================================
   20. SUBSCRIPTIONS / PRICING
   ===================================================================== */

@media (max-width: 767.98px) {
    .pricing-card {
        margin-bottom: 1rem;
    }

    .pricing-toggle {
        flex-direction: column;
        gap: 0.5rem;
    }

    /* Promo code input */
    .card-body .d-flex.gap-2.justify-content-center {
        flex-wrap: wrap;
    }

    .card-body .d-flex.gap-2.justify-content-center .form-control {
        flex: 1 1 auto;
        min-width: 200px;
    }
}

/* =====================================================================
   21. BRAINMAP
   ===================================================================== */

@media (max-width: 767.98px) {
    .brainmap-container {
        padding: 0.5rem;
    }

    .brainmap-legend {
        flex-wrap: wrap;
        gap: 0.5rem;
    }
}

/* =====================================================================
   22. ADMIN DASHBOARD
   ===================================================================== */

@media (max-width: 767.98px) {
    .admin-pre-output {
        max-height: 40vh;
        font-size: 0.75rem;
    }

    .admin-section-header,
    .admin-subsection-header {
        font-size: 0.7rem;
    }
}

/* =====================================================================
   23. UTILITIES — Mobile-only helpers
   ===================================================================== */

@media (max-width: 575.98px) {
    .u-fs-3rem {
        font-size: 2rem !important;
    }

    .u-fs-2-5rem {
        font-size: 1.75rem !important;
    }

    .u-fs-1-8rem {
        font-size: 1.4rem !important;
    }

    .u-fs-1-5rem {
        font-size: 1.25rem !important;
    }
}
