/* Mobile overrides — all rules inside 768px media query for zero desktop impact */

@media (max-width: 768px) {

    /* ============================================
       GENERAL / CROSS-PAGE
       ============================================ */

    /* Single-column debate grids */
    .debate-grid {
        grid-template-columns: 1fr !important;
    }

    /* Larger touch targets for vote buttons */
    .vote-btn {
        padding: 8px 12px;
    }

    /* Thread detail title */
    .thread-detail-title {
        font-size: 1.1rem;
    }


    /* ============================================
       INDEX PAGE
       ============================================ */

    /* Override the 1100px breakpoint that hides sidebar-right entirely */
    #main-content.visible {
        grid-template-columns: 1fr !important;
    }

    .sidebar-left {
        display: none;
    }

    .sidebar-right {
        display: none !important;
    }

    .main-center {
        padding: 1rem;
    }

    /* FAB button for create debate */
    .mobile-create-fab {
        display: flex;
        position: fixed;
        bottom: 1.25rem;
        right: 1.25rem;
        width: 56px;
        height: 56px;
        border-radius: 50%;
        background: var(--btn-primary-bg);
        color: var(--btn-primary-text);
        border: none;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
        cursor: pointer;
        z-index: 900;
        align-items: center;
        justify-content: center;
        font-size: 1.5rem;
        transition: transform 0.2s ease, box-shadow 0.2s ease;
    }

    .mobile-create-fab:hover {
        transform: translateY(-2px);
        box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4);
    }

    /* Bottom sheet overlay */
    .mobile-bottom-sheet-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        backdrop-filter: blur(4px);
        -webkit-backdrop-filter: blur(4px);
        z-index: 9998;
    }

    .mobile-bottom-sheet-overlay.open {
        display: block;
    }

    /* Bottom sheet */
    .mobile-bottom-sheet {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: var(--bg-surface);
        border-top: 1px solid var(--border-accent);
        border-radius: 16px 16px 0 0;
        padding: 1.25rem;
        z-index: 9999;
        transform: translateY(100%);
        transition: transform 0.3s ease;
        max-height: 85vh;
        overflow-y: auto;
    }

    .mobile-bottom-sheet.open {
        transform: translateY(0);
    }

    .mobile-bottom-sheet-handle {
        width: 36px;
        height: 4px;
        background: var(--border-subtle);
        border-radius: 2px;
        margin: 0 auto 1rem;
    }

    .mobile-bottom-sheet-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        margin-bottom: 0.75rem;
    }

    .mobile-bottom-sheet-header .sidebar-title {
        margin-bottom: 0;
    }

    .mobile-bottom-sheet-close {
        width: 32px;
        height: 32px;
        border: none;
        background: var(--bg-elevated);
        border-radius: 50%;
        font-size: 1.25rem;
        color: var(--text-muted);
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        transition: all 0.15s ease;
    }

    .mobile-bottom-sheet-close:hover {
        background: var(--bg-hover);
        color: var(--text-primary);
    }

    .mobile-bottom-sheet .sidebar-title {
        font-family: 'Playfair Display', serif;
        font-size: 1.15rem;
        font-weight: 600;
        color: var(--text-primary);
        margin-bottom: 1rem;
    }

    .mobile-sheet-divider {
        height: 1px;
        background: var(--border-subtle);
        margin: 1.25rem 0;
    }

    /* Quick Play presets in bottom sheet */
    .mobile-presets-list {
        display: flex;
        flex-direction: column;
        gap: 0.4rem;
    }

    .mobile-presets-list .preset-btn {
        display: flex;
        flex-direction: column;
        gap: 0.35rem;
        padding: 0.75rem 1rem;
        background: var(--bg-elevated);
        border: 1px solid var(--border-subtle);
        color: var(--text-primary);
        font-family: inherit;
        text-align: left;
        cursor: pointer;
        transition: all 0.15s ease;
        border-radius: 6px;
    }

    .mobile-presets-list .preset-btn:hover {
        background: var(--bg-hover);
        border-color: var(--border-accent);
    }

    /* AI Practice in bottom sheet */
    .mobile-ai-btn {
        width: 100%;
        padding: 0.75rem 1rem;
        background: var(--btn-secondary-bg);
        border: 1px dashed var(--btn-secondary-border);
        border-radius: 6px;
        color: var(--text-secondary);
        font-family: inherit;
        font-size: 0.95rem;
        cursor: pointer;
        transition: all 0.15s ease;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 0.5rem;
    }

    .mobile-ai-btn:hover {
        border-style: solid;
        border-color: var(--btn-secondary-hover-border);
        color: var(--text-primary);
    }

    .mobile-ai-note {
        font-size: 0.75rem;
        color: var(--text-muted);
        text-align: center;
        margin-top: 0.4rem;
    }

    .mobile-bottom-sheet .create-form {
        display: flex;
        flex-direction: column;
        gap: 0.75rem;
    }

    .mobile-bottom-sheet .form-group {
        display: flex;
        flex-direction: column;
        gap: 0.3rem;
    }

    .mobile-bottom-sheet label {
        font-size: 0.85rem;
        font-weight: 600;
        color: var(--text-muted);
    }

    .mobile-bottom-sheet input,
    .mobile-bottom-sheet select {
        padding: 0.65rem 0.75rem;
        background: var(--bg-elevated);
        border: 1px solid var(--border-subtle);
        border-radius: 6px;
        color: var(--text-primary);
        font-family: inherit;
        font-size: 0.95rem;
    }

    .mobile-bottom-sheet .form-row {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 0.75rem;
    }

    .mobile-bottom-sheet .create-btn {
        padding: 0.75rem;
        background: var(--btn-primary-bg);
        color: var(--btn-primary-text);
        border: none;
        border-radius: 6px;
        font-family: inherit;
        font-size: 0.95rem;
        font-weight: 600;
        cursor: pointer;
        margin-top: 0.25rem;
    }

    .mobile-bottom-sheet .challenge-btn {
        width: 100%;
        padding: 0.65rem;
        background: var(--btn-secondary-bg);
        border: 1px solid var(--btn-secondary-border);
        border-radius: 6px;
        color: var(--text-secondary);
        font-family: inherit;
        font-size: 0.9rem;
        cursor: pointer;
        margin-top: 0.5rem;
    }


    /* ============================================
       FORUM PAGE
       ============================================ */

    /* Mobile category bar */
    .mobile-category-bar {
        display: flex;
        gap: 0.5rem;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        padding: 0.75rem 0;
        margin-bottom: 0.5rem;
        scrollbar-width: none;
    }

    .mobile-category-bar::-webkit-scrollbar {
        display: none;
    }

    .mobile-category-pill {
        flex-shrink: 0;
        padding: 0.4rem 0.85rem;
        background: var(--bg-elevated);
        border: 1px solid var(--border-subtle);
        border-radius: 20px;
        color: var(--text-secondary);
        font-size: 0.8rem;
        font-weight: 500;
        cursor: pointer;
        white-space: nowrap;
        transition: all 0.15s ease;
        font-family: inherit;
    }

    .mobile-category-pill:hover,
    .mobile-category-pill.active {
        background: var(--gold-subtle);
        border-color: var(--border-accent);
        color: var(--gold-primary);
    }

    /* Forum main content: single column on mobile */
    #main-content.visible {
        grid-template-columns: 1fr !important;
    }

    .sidebar-left {
        display: none !important;
    }


    /* ============================================
       DEBATE PAGE
       ============================================ */

    /* Sticky note: hidden by default on mobile, shown via toggle */
    .sticky-note {
        display: none !important;
        position: fixed !important;
        top: auto !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        width: 100% !important;
        height: 55vh !important;
        border-radius: 16px 16px 0 0 !important;
        z-index: 950 !important;
    }

    .sticky-note.mobile-visible {
        display: flex !important;
    }

    /* Disable drag and resize on mobile */
    .sticky-note .resize-handle {
        display: none !important;
    }

    .sticky-note-header {
        cursor: default !important;
    }

    /* Mobile notes toggle button */
    .mobile-notes-toggle {
        display: flex;
        position: fixed;
        bottom: 70px;
        right: 1rem;
        width: 44px;
        height: 44px;
        border-radius: 50%;
        background: var(--bg-surface);
        border: 1px solid var(--border-accent);
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
        cursor: pointer;
        z-index: 899;
        align-items: center;
        justify-content: center;
        font-size: 1.1rem;
        transition: all 0.15s ease;
    }

    .mobile-notes-toggle:hover {
        background: var(--bg-elevated);
    }

    /* Backdrop when notes are open */
    .mobile-notes-backdrop {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.4);
        z-index: 949;
    }

    .mobile-notes-backdrop.open {
        display: block;
    }

    [data-page="debate"] textarea {
        min-height: 120px;
    }

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

    .spectator-banner {
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    /* Panel window on mobile */
    .panel-window {
        width: calc(100vw - 2rem) !important;
        left: 1rem !important;
        right: 1rem !important;
        max-height: 70vh;
    }

    #tabbed-panel-container {
        bottom: 10px !important;
        right: 10px !important;
    }


    /* ============================================
       LEADERBOARD PAGE
       ============================================ */

    .leaderboard-table-wrap {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    [data-page="leaderboard"] .filter-section {
        flex-wrap: wrap;
    }


    /* ============================================
       RESULTS PAGE
       ============================================ */

    .share-buttons {
        flex-wrap: wrap;
        justify-content: center;
    }

    .toxicity-rating-buttons {
        flex-wrap: wrap;
        justify-content: center;
    }


    /* ============================================
       PROFILE PAGE
       ============================================ */

    .filter-section {
        flex-wrap: wrap;
    }
}

/* Hide FAB and bottom sheet on desktop */
@media (min-width: 769px) {
    .mobile-create-fab,
    .mobile-bottom-sheet-overlay,
    .mobile-bottom-sheet,
    .mobile-category-bar,
    .mobile-notes-toggle,
    .mobile-notes-backdrop {
        display: none !important;
    }
}
