/* =============================================================
   MOBILE OPTIMIZATIONS - AniSub.co
   Clean, consolidated, conflict-free
   ============================================================= */

/* ============================================================
   GLOBAL RULES (All screen sizes)
   ============================================================ */

/* Mobile search button - hidden by default, shown in media query */
.mobile-search-btn { display: none !important; }

/* ============================================================
   MOBILE BOTTOM NAVIGATION BAR
   ============================================================ */
.mobile-bottom-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 9998;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
    padding: 0;
    padding-bottom: env(safe-area-inset-bottom, 0);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    box-shadow: 0 -4px 20px rgba(0,0,0,0.15);
}

.mobile-nav-items {
    display: flex;
    align-items: stretch;
    justify-content: space-around;
    height: 60px;
    list-style: none;
    margin: 0;
    padding: 0;
}

.mobile-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    text-decoration: none;
    color: var(--text-muted);
    font-size: 0.65rem;
    font-weight: 600;
    padding: 8px 4px;
    position: relative;
    transition: color 0.15s;
    min-height: 44px;
    -webkit-tap-highlight-color: transparent;
}

.mobile-nav-item:active {
    background: var(--accent-surface);
}

.mobile-nav-item.active {
    color: var(--accent);
}

.mobile-nav-item.active::before {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 24px;
    height: 3px;
    background: var(--accent);
    border-radius: 0 0 3px 3px;
}

.mobile-nav-item i {
    font-size: 1.2rem;
    line-height: 1;
}

.mobile-nav-item .nav-label {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

.mobile-nav-badge {
    position: absolute;
    top: 4px;
    right: calc(50% - 18px);
    min-width: 16px;
    height: 16px;
    border-radius: 8px;
    background: var(--red);
    color: #fff;
    font-size: 0.55rem;
    font-weight: 800;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
    line-height: 1;
    border: 2px solid var(--bg-secondary);
}

.mobile-nav-badge.visible {
    display: flex;
}

.mobile-nav-item.upload-item {
    color: var(--accent);
}

.mobile-nav-item.upload-item i {
    background: var(--accent);
    color: #000;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    margin-top: -14px;
    box-shadow: 0 4px 12px var(--accent-glow);
    border: 3px solid var(--bg-secondary);
}

/* ============================================================
   1000px
   ============================================================ */
@media (max-width: 1000px) {
    .profil-layout {
        padding: 0 0.75rem 2rem !important;
    }

    .profil-stats-row {
        gap: 0.5rem;
    }

    .profil-stat-card {
        padding: 0.75rem;
    }

    .profil-stat-val {
        font-size: 1.2rem;
    }

    .profil-stat-lbl {
        font-size: 0.62rem;
    }
}

/* ============================================================
   991px
   ============================================================ */
@media (max-width: 991px) {
    .idx-layout {
        padding: 0.75rem !important;
        gap: 1rem !important;
    }

    .idx-section {
        padding-bottom: 0.6rem;
        margin-bottom: 0.75rem;
    }

    .idx-section-title {
        font-size: 0.95rem;
    }

    .idx-grid {
        gap: 0.75rem;
    }

    .idx-poster-frame {
        border-radius: var(--radius);
    }

    .idx-poster-title {
        font-size: 0.78rem;
    }

    .idx-trending-card {
        flex: 0 0 140px;
    }

    .idx-trending-cover {
        height: 90px;
    }

    .idx-trending-name {
        font-size: 0.75rem;
    }

    .idx-trending-stats {
        font-size: 0.68rem;
    }
}

/* ============================================================
   900px
   ============================================================ */
@media (max-width: 900px) {
    /* Subtitles page */
    .an-page {
        padding: 0 0.75rem 1.5rem !important;
    }

    .an-hero-content {
        grid-template-columns: 1fr !important;
        gap: 1rem !important;
    }

    .an-hero-poster-col {
        max-width: 200px !important;
        margin: 0 auto !important;
    }

    .an-hero-banner-content {
        min-height: 280px !important;
        padding: 1rem !important;
    }

    .an-title {
        font-size: 1.3rem !important;
        text-align: center !important;
    }

    .an-subtitle {
        font-size: 0.95rem !important;
        text-align: center !important;
    }

    .an-pills, .an-genres, .an-actions {
        justify-content: center !important;
    }

    .an-breadcrumb {
        justify-content: center !important;
        flex-wrap: wrap;
    }

    .an-hero-side-widget, .an-cover-card, .an-hero-links-card {
        margin-bottom: 0.75rem;
    }

    .an-layout {
        gap: 1rem !important;
    }

    .an-widget {
        padding: 1rem !important;
        margin-bottom: 1rem !important;
    }

    .an-widget-head {
        font-size: 0.9rem !important;
    }

    .an-sub-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
        padding: 10px 12px;
    }

    .an-sub-avatar {
        width: 32px;
        height: 32px;
    }

    .an-sub-title {
        font-size: 0.85rem;
    }

    .an-sub-meta {
        font-size: 0.72rem;
        gap: 8px;
    }

    .an-sub-arrow {
        display: none;
    }

    .an-similar-grid {
        grid-template-columns: repeat(3, 1fr) !important;
        gap: 8px !important;
    }

    .an-form-row {
        flex-direction: column;
        gap: 0.75rem;
    }

    .an-form-group {
        min-width: auto;
    }

    .an-stats-bar {
        gap: 0.75rem !important;
        flex-wrap: wrap;
    }

    .an-stat-item {
        font-size: 0.78rem;
    }

    .an-comment-tabs {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .an-comment-tab {
        flex-shrink: 0;
        padding: 10px 14px;
    }

    .an-modal-dialog {
        width: calc(100vw - 1rem) !important;
        max-height: 85vh;
        margin: 0.75rem auto;
    }

    .an-modal-head {
        padding: 0.75rem 1rem 0;
    }

    .an-modal .an-torrent-search {
        margin: 0.75rem 1rem 1rem;
    }

    /* Messages */
    .msg-container {
        height: calc(100vh - 56px);
        padding: 0;
    }

    .msg-wrapper {
        border-radius: 0;
        border: none;
    }

    .msg-sidebar {
        width: 100%;
        position: absolute;
        inset: 0;
        z-index: 2;
        transition: transform 0.3s ease;
    }

    .msg-chat {
        position: absolute;
        inset: 0;
        z-index: 1;
        transform: translateX(100%);
        transition: transform 0.3s ease;
    }

    .msg-wrapper.chat-open .msg-sidebar {
        transform: translateX(-100%);
    }

    .msg-wrapper.chat-open .msg-chat {
        transform: translateX(0);
        z-index: 3;
    }

    .msg-back-btn {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 44px;
        height: 44px;
    }

    .msg-convo {
        padding: 10px 1rem;
        gap: 10px;
    }

    .msg-convo-avatar {
        width: 44px;
        height: 44px;
    }

    .msg-convo-name {
        font-size: 0.88rem;
    }

    .msg-convo-preview {
        font-size: 0.75rem;
    }

    .msg-search-input {
        min-height: 44px;
    }

    .msg-sidebar-title {
        font-size: 0.95rem;
    }
}

/* ============================================================
   820px
   ============================================================ */
@media (max-width: 820px) {
    .chat-page {
        padding: 0.75rem;
    }

    .chat-hero {
        padding: 1.25rem;
        margin-bottom: 0.75rem;
    }

    .chat-hero h1 {
        font-size: 1.4rem;
    }

    .chat-hero p {
        font-size: 0.85rem;
    }

    .chat-shell {
        grid-template-columns: 1fr;
        gap: 0;
        min-height: auto;
    }

    .chat-left, .chat-center {
        border-radius: var(--radius-lg);
    }

    .chat-left {
        order: 1;
    }

    .chat-room-list {
        max-height: calc(100vh - 340px);
    }

    .chat-center {
        order: 2;
        display: none;
    }

    .chat-center.active {
        display: flex;
        position: fixed;
        inset: 0;
        z-index: 100;
        border-radius: 0;
    }

    .chat-center.active .chat-center-header {
        background: var(--bg-secondary);
    }

    .chat-feed {
        height: calc(100vh - 260px);
        padding: 0.75rem 0.5rem 0;
    }

    .chat-message {
        grid-template-columns: 38px 1fr;
        gap: 8px;
        padding: 0.5rem 0.25rem;
    }

    .chat-message-avatar {
        width: 38px;
        height: 38px;
        border-radius: 12px;
    }

    .chat-message-text {
        font-size: 0.88rem;
    }

    .chat-composer-wrap {
        padding: 0.75rem;
    }

    .chat-composer-input {
        min-height: 44px;
        font-size: 0.88rem;
    }

    .chat-back-btn {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 44px;
        height: 44px;
        border: none;
        background: none;
        color: var(--text-secondary);
        font-size: 1.1rem;
        cursor: pointer;
        border-radius: var(--radius);
    }

    .chat-back-btn:hover {
        background: var(--bg-hover);
        color: var(--accent);
    }

    body.chat-room-active .chat-left {
        display: none;
    }

    body.chat-room-active .chat-center {
        display: flex;
        order: 1;
    }
}

/* ============================================================
   768px - MAIN MOBILE BREAKPOINT
   ============================================================ */
@media (max-width: 768px) {
    /* --- OVERFLOW --- */
    html, body {
        overflow-x: hidden !important;
        max-width: 100vw !important;
    }

    /* --- BOTTOM NAV VISIBLE --- */
    .mobile-bottom-nav { display: block; }

    body {
        padding-bottom: calc(60px + env(safe-area-inset-bottom, 0));
    }

    .site-footer {
        margin-bottom: calc(60px + env(safe-area-inset-bottom, 0));
    }

    /* --- HEADER — no stacking context on mobile --- */
    .header-root {
        position: sticky !important;
        top: 0 !important;
        left: auto !important;
        right: auto !important;
        width: 100% !important;
        max-width: 100% !important;
        overflow: visible !important;
        z-index: 9000 !important;
        backdrop-filter: none !important;
        -webkit-backdrop-filter: none !important;
        background: var(--bg-secondary) !important;
        box-shadow: 0 2px 12px rgba(0,0,0,0.3) !important;
    }

    .header-container {
        position: relative !important;
    }

    .header-container {
        padding: 0 10px !important;
        max-width: 100% !important;
        width: 100% !important;
        overflow: visible !important;
    }

    .header-bar {
        height: 56px !important;
        padding: 0 !important;
        gap: 8px !important;
        flex-wrap: nowrap !important;
        width: 100% !important;
        max-width: 100% !important;
        overflow: visible !important;
    }

    /* Logo */
    .header-logo {
        margin-right: 0 !important;
        flex-shrink: 1 !important;
        min-width: 0 !important;
    }

    .logo-text {
        font-size: 1.1rem !important;
    }

    .header-logo-icon {
        height: 24px !important;
    }

    /* Actions */
    .header-actions,
    .header-user-actions {
        gap: 0 !important;
        flex-shrink: 1 !important;
        min-width: 0 !important;
        justify-content: flex-end !important;
    }

    .user-btn, .icon-btn {
        width: 38px !important;
        height: 38px !important;
        padding: 0 !important;
        flex-shrink: 0 !important;
    }

    .user-avatar-link {
        width: 32px !important;
        height: 32px !important;
        flex-shrink: 0 !important;
    }

    .register-btn {
        padding: 6px 10px !important;
        font-size: 0.72rem !important;
        min-height: 38px !important;
        display: inline-flex !important;
        align-items: center !important;
        flex-shrink: 0 !important;
    }

    .btn-upload-nav {
        padding: 6px 10px !important;
        font-size: 0.7rem !important;
        min-height: 38px !important;
        display: inline-flex !important;
        align-items: center !important;
        flex-shrink: 0 !important;
    }

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

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

    /* --- SEARCH (hidden by default, shown via button) --- */
    .header-search:not(.mobile-active) {
        display: none !important;
    }

    .header-search {
        position: fixed !important;
        top: 0;
        left: 0;
        right: 0;
        width: 100vw !important;
        max-width: 100vw !important;
        margin: 0 !important;
        z-index: calc(var(--z-header) + 50) !important;
        padding: 8px 10px;
        padding-top: max(8px, env(safe-area-inset-top));
        background: var(--bg-secondary);
        transform: translateY(-100%);
        transition: transform 0.25s ease;
        box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    }

    .header-search.mobile-active {
        display: flex !important;
        transform: translateY(0);
    }

    .search-box {
        height: 44px !important;
    }

    .search-box input {
        font-size: 16px !important;
        padding: 0 10px !important;
    }

    .suggestions-box {
        min-width: auto !important;
        left: 10px !important;
        right: 10px !important;
        max-width: calc(100vw - 20px) !important;
    }

    .mobile-search-btn,
    .mobile-search-btn.hide-tablet {
        display: inline-flex !important;
    }

    /* --- DROPDOWNS - handled entirely by JS inline styles --- */
    .dropdown.show::before {
        display: none !important;
    }

    .dropdown-header-user {
        padding: 16px !important;
        margin-bottom: 8px !important;
    }

    .dropdown-header-user img {
        width: 48px !important;
        height: 48px !important;
        flex-shrink: 0 !important;
    }

    .dropdown-user-name {
        font-size: 1rem !important;
        word-break: break-word !important;
    }

    .dropdown-user-handle {
        font-size: 0.8rem !important;
    }

    .dropdown-item {
        padding: 14px 16px !important;
        font-size: 0.95rem !important;
        min-height: 50px !important;
        width: 100% !important;
        box-sizing: border-box !important;
    }

    .dropdown-item i {
        width: 22px !important;
        font-size: 1rem !important;
        flex-shrink: 0 !important;
    }

    .dropdown-divider {
        margin: 4px 0 !important;
    }

    /* Notification panel */
    .notif-header {
        padding: 16px !important;
        font-size: 1rem !important;
        position: sticky;
        top: 0;
        background: var(--bg-card);
        z-index: 1;
        border-radius: 12px 12px 0 0;
    }

    .notif-list {
        max-height: 65vh !important;
        padding: 0 4px !important;
    }

    .notif-item {
        padding: 14px 12px !important;
        font-size: 0.9rem !important;
        line-height: 1.5 !important;
        border-radius: 8px;
        margin-bottom: 4px;
    }

    .notif-item .notif-content {
        word-break: break-word !important;
    }

    .notif-item .notif-content b {
        font-size: 0.9rem !important;
    }

    .notif-item .notif-time {
        font-size: 0.75rem !important;
    }

    .notif-none {
        padding: 32px 16px !important;
        font-size: 0.95rem !important;
    }

    .notif-item .notif-icon {
        font-size: 1.1rem !important;
        width: 28px !important;
        flex-shrink: 0 !important;
    }

    /* --- MOBILE NAV DRAWER --- */
    .mobile-nav-drawer {
        width: 85vw !important;
        max-width: 300px !important;
        right: -300px !important;
        padding: 0 !important;
    }

    .mobile-nav-drawer.active {
        right: 0 !important;
    }

    .mobile-nav-close {
        position: sticky;
        top: 0;
        right: 0;
        float: none !important;
        display: flex !important;
        align-items: center;
        justify-content: center;
        width: 44px !important;
        height: 44px !important;
        margin: 0 0 8px auto !important;
        padding: 0 !important;
        background: var(--bg-hover) !important;
        border-radius: var(--radius) !important;
    }

    .mobile-nav-links a {
        padding: 14px 20px !important;
        font-size: 0.95rem !important;
        border-bottom: 1px solid var(--border) !important;
        min-height: 52px !important;
        display: flex !important;
        align-items: center !important;
    }

    .mobile-nav-links a i {
        width: 24px !important;
        text-align: center !important;
        font-size: 1rem !important;
        flex-shrink: 0 !important;
    }

    .mobile-nav-user {
        display: flex;
        align-items: center;
        gap: 12px;
        padding: 16px 20px !important;
        border-bottom: 1px solid var(--border);
        background: var(--bg-hover);
    }

    .mobile-nav-user img {
        width: 44px !important;
        height: 44px !important;
        border-radius: var(--radius-full) !important;
        object-fit: cover;
    }

    .mobile-nav-user-name {
        font-weight: 700;
        color: var(--text-bright);
        font-size: 0.95rem;
        word-break: break-word !important;
    }

    .mobile-nav-user-handle {
        color: var(--text-muted);
        font-size: 0.78rem;
    }

    .main-nav.active {
        padding-bottom: env(safe-area-inset-bottom, 8px);
        max-height: calc(100vh - 56px);
        overflow-y: auto;
        overflow-x: hidden;
    }

    .nav-list {
        overflow-x: hidden !important;
    }

    .nav-link {
        min-height: 52px;
        padding: 14px 16px;
        font-size: 0.95rem;
        word-break: break-word !important;
        white-space: normal !important;
    }

    .btn-upload-nav {
        margin: 10px 16px !important;
        justify-content: center !important;
        display: flex !important;
    }

    /* Theme toggle */
    .theme-toggle {
        gap: 2px;
    }

    .theme-option {
        width: 30px;
        height: 30px;
        min-height: 44px;
        padding: 16px 10px;
    }

    /* Color swatches */
    .color-swatch {
        min-height: 44px;
        min-width: 44px;
        aspect-ratio: 1;
    }

    /* --- 44px TOUCH TARGETS --- */
    .an-btn, .btn-signup, .btn-login, .btn-upload-nav,
    .profil-act-btn, .msg-send-btn, .chat-send-btn,
    .an-comment-submit, .idx-section-link,
    .wl-status-pill, .profil-pg {
        min-height: 44px;
        min-width: 44px;
        padding-top: 10px;
        padding-bottom: 10px;
    }

    .mobile-nav-links a {
        min-height: 48px;
        padding: 14px 0 !important;
    }

    .profil-tab, .idx-tab-btn, .an-comment-tab {
        min-height: 44px;
        padding: 12px 8px;
    }

    .icon-btn, .theme-toggle-btn, .settings-toggle-btn,
    .chat-icon-btn, .msg-act-btn, .chat-toolbar-btn,
    .mobile-btn, .mobile-toggle, .an-modal-close {
        min-height: 44px;
        min-width: 44px;
        width: 44px;
        height: 44px;
    }

    .search-box input, .msg-text-input, .chat-composer-input,
    .an-form-group input, .an-form-group select,
    .an-comment-form textarea {
        min-height: 44px;
        padding-top: 12px;
        padding-bottom: 12px;
    }

    input[type="checkbox"], input[type="radio"] {
        width: 22px;
        height: 22px;
        margin: 4px;
    }

    .an-sub-item {
        min-height: 56px;
    }

    .idx-sub-card, .profil-card,
    .chat-room-link, .msg-convo {
        min-height: 52px;
    }

    .footer-social a {
        min-height: 44px;
        min-width: 44px;
        width: 44px;
        height: 44px;
    }

    .footer-azlist a {
        min-height: 36px;
        min-width: 36px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .settings-close {
        min-height: 44px;
        min-width: 44px;
        width: 44px;
        height: 44px;
    }

    /* --- PROFILE PAGE --- */
    .profil-hero {
        height: 180px;
        border-radius: var(--radius);
    }

    .profil-user-bar {
        flex-direction: column;
        align-items: center;
        text-align: center;
        margin-top: -45px;
        gap: 0.75rem;
        padding: 0 0.75rem;
    }

    .profil-avatar {
        width: 80px;
        height: 80px;
        border-width: 3px;
    }

    .profil-display-name {
        font-size: 1.15rem;
        justify-content: center;
    }

    .profil-username {
        font-size: 0.78rem;
    }

    .profil-bio {
        max-width: 100%;
        font-size: 0.82rem;
    }

    .profil-actions {
        justify-content: center;
    }

    .profil-act-btn {
        padding: 8px 14px;
        font-size: 0.78rem;
    }

    .profil-stats-row {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.5rem;
    }

    .profil-main-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    .profil-sidebar {
        order: -1;
    }

    .profil-tabs {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .profil-tab {
        flex-shrink: 0;
        min-width: 80px;
        padding: 10px 12px;
        font-size: 0.78rem;
    }

    .profil-anime-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 0.5rem;
    }

    .profil-card-body {
        padding: 8px 10px;
    }

    .profil-card-title {
        font-size: 0.72rem;
    }

    .profil-widget-body {
        padding: 12px;
    }

    .profil-info-row {
        padding: 6px 0;
        font-size: 0.75rem;
    }

    .profil-pg {
        min-width: 36px;
        height: 36px;
    }

    .wl-status-pill {
        padding: 6px 10px;
        font-size: 0.7rem;
    }

    /* --- BROWSE & LISTING --- */
    .browse-grid, .media-grid {
        grid-template-columns: repeat(3, 1fr) !important;
        gap: 0.5rem;
    }

    .filter-bar {
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .filter-btn, .filter-select {
        min-height: 44px;
        padding: 10px 14px;
        font-size: 0.82rem;
    }

    .sort-dropdown {
        min-height: 44px;
    }

    /* --- FORUM --- */
    .forum-thread {
        padding: 10px 12px;
    }

    .forum-thread-title {
        font-size: 0.88rem;
    }

    .forum-thread-meta {
        font-size: 0.72rem;
    }

    .forum-post {
        padding: 12px;
    }

    .forum-post-avatar {
        width: 40px;
        height: 40px;
    }

    .forum-post-content {
        font-size: 0.88rem;
    }

    /* --- UPLOAD FORM --- */
    .upload-form-group {
        margin-bottom: 1rem;
    }

    .upload-form-label {
        font-size: 0.82rem;
        margin-bottom: 6px;
    }

    .upload-form-input,
    .upload-form-select,
    .upload-form-textarea {
        min-height: 44px;
        padding: 12px;
        font-size: 0.88rem;
    }

    .upload-form-textarea {
        min-height: 120px;
    }

    .upload-dropzone {
        padding: 1.5rem 1rem;
    }

    .upload-dropzone-icon {
        font-size: 2rem;
    }

    .upload-dropzone-text {
        font-size: 0.85rem;
    }

    /* --- TOOLS --- */
    .tools-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 0.75rem;
    }

    .tool-card {
        padding: 1rem;
    }

    .tool-card-icon {
        width: 48px;
        height: 48px;
        font-size: 1.2rem;
    }

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

    .tool-card-desc {
        font-size: 0.75rem;
    }

    /* --- SCROLL & OVERFLOW --- */
    .page-content {
        padding-top: 0 !important;
    }

    main#main-content {
        padding-top: 0 !important;
    }

    img {
        max-width: 100%;
        height: auto;
    }

    .table-responsive, .an-subtitles-table-wrapper {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    input, select, textarea {
        font-size: 16px !important;
    }

    .an-title, .profil-display-name, .idx-sub-title,
    .chat-center-title h2, .msg-chat-user-name {
        word-break: break-word;
        overflow-wrap: break-word;
    }

    .an-modal-overlay, .theme-settings-overlay,
    .mobile-nav-overlay {
        padding: 12px;
    }

    .theme-settings-panel {
        width: 100% !important;
        max-height: 80vh;
        padding: 20px !important;
    }

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

    .theme-selector {
        flex-direction: column;
    }

    .theme-option {
        flex-direction: row;
        padding: 12px 16px;
    }

    main#main-content {
        padding-top: 0 !important;
    }

    .header-container {
        padding-left: max(10px, env(safe-area-inset-left));
        padding-right: max(10px, env(safe-area-inset-right));
    }

    /* --- ACCESSIBILITY --- */
    :focus {
        outline: 2px solid var(--accent);
        outline-offset: 2px;
    }

    :focus:not(:focus-visible) {
        outline: none;
    }

    :focus-visible {
        outline: 2px solid var(--accent);
        outline-offset: 2px;
    }

    .skip-nav {
        font-size: 0.9rem;
        padding: 12px 20px;
    }
}

/* ============================================================
   640px
   ============================================================ */
@media (max-width: 640px) {
    /* Index */
    .idx-layout {
        padding: 0.5rem !important;
        gap: 0.75rem !important;
    }

    .idx-sub-card {
        padding: 8px;
    }

    .idx-sub-cover {
        width: 32px;
        height: 44px;
    }

    .idx-sub-title {
        font-size: 0.78rem;
    }

    .idx-sub-tag {
        font-size: 0.6rem;
        padding: 2px 5px;
    }

    .idx-sub-uploader img {
        width: 22px;
        height: 22px;
    }

    .idx-activity-list {
        max-height: 240px;
    }

    .idx-act-item {
        padding: 8px 0.75rem;
    }

    .idx-comment {
        padding: 8px 0.75rem;
    }

    .ka-wrapper {
        padding: 0 0.5rem;
        margin-bottom: 2rem;
    }

    .ka-section-header h2 {
        font-size: 0.9rem;
    }

    .ka-rss-container {
        padding: 0.75rem;
    }

    .idx-update-item {
        padding: 10px;
        gap: 10px;
    }

    .idx-update-dot {
        width: 28px;
        height: 28px;
        font-size: 0.65rem;
    }

    .idx-update-text {
        font-size: 0.78rem;
    }

    .idx-update-badge {
        font-size: 0.58rem;
    }

    /* Messages */
    .msg-container {
        height: calc(100vh - 52px);
    }

    .msg-row {
        max-width: 88%;
    }

    .msg-bubble {
        padding: 10px 14px;
        font-size: 0.85rem;
    }

    .msg-bubble-avatar {
        width: 24px;
        height: 24px;
    }

    .msg-chat-user img {
        width: 36px;
        height: 36px;
    }

    .msg-chat-user-name {
        font-size: 0.9rem;
    }

    .msg-text-input {
        min-height: 44px;
        padding: 10px 16px;
    }

    .msg-send-btn {
        width: 44px;
        height: 44px;
    }

    .msg-input-area {
        padding: 0.75rem 1rem;
    }

    .msg-messages {
        padding: 1rem;
    }

    .msg-date-sep span {
        font-size: 0.65rem;
        padding: 4px 12px;
    }
}

/* ============================================================
   480px - EXTRA COMPACT
   ============================================================ */
@media (max-width: 480px) {
    /* Typography */
    h1 { font-size: 1.35rem; }
    h2 { font-size: 1.2rem; }
    h3 { font-size: 1.05rem; }

    .container { padding: 0 12px !important; }

    /* Header */
    .header-bar {
        height: 48px !important;
        gap: 4px !important;
    }

    .header-container {
        padding: 0 8px !important;
    }

    .logo-text {
        font-size: 0.95rem !important;
    }

    .header-logo-icon {
        height: 20px !important;
    }

    .user-avatar-link {
        width: 30px !important;
        height: 30px !important;
    }

    .icon-btn {
        width: 36px !important;
        height: 36px !important;
    }

    .mobile-search-btn {
        width: 36px !important;
        height: 36px !important;
    }

    .mobile-toggle {
        width: 36px !important;
        height: 36px !important;
    }

    /* Chat */
    .chat-hero {
        padding: 1rem;
    }

    .chat-hero h1 {
        font-size: 1.2rem;
    }

    .chat-room-link {
        padding: 0.75rem 0.85rem;
        gap: 10px;
    }

    .chat-room-icon {
        width: 38px;
        height: 38px;
    }

    .chat-room-name {
        font-size: 0.85rem;
    }

    .chat-feed {
        height: calc(100vh - 280px);
    }

    /* Subtitles page */
    .an-hero-poster-col {
        max-width: 150px !important;
    }

    .an-hero-banner-content {
        min-height: 220px !important;
    }

    .an-title {
        font-size: 1.15rem !important;
    }

    .an-pill {
        padding: 4px 10px;
        font-size: 0.72rem;
    }

    .an-genre {
        padding: 3px 8px;
        font-size: 0.7rem;
    }

    .an-btn {
        padding: 8px 14px;
        font-size: 0.78rem;
    }

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

    .an-sub-list {
        gap: 6px;
    }

    /* Index */
    .idx-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 0.5rem;
    }

    .idx-poster-title {
        font-size: 0.72rem;
        min-height: auto;
        -webkit-line-clamp: 1;
    }

    .idx-trending-card {
        flex: 0 0 120px;
    }

    .idx-trending-cover {
        height: 75px;
    }

    .idx-trending-body {
        padding: 8px 10px;
    }

    /* Profile */
    .profil-hero {
        height: 150px;
    }

    .profil-user-bar {
        margin-top: -35px;
    }

    .profil-avatar {
        width: 70px;
        height: 70px;
    }

    .profil-display-name {
        font-size: 1.05rem;
    }

    .profil-anime-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 0.4rem;
    }

    .profil-card-gradient {
        height: 45%;
    }

    .profil-card-overlay {
        display: none;
    }

    .profil-card-score {
        bottom: 4px;
        left: 4px;
        padding: 2px 5px;
        font-size: 0.6rem;
    }

    .profil-cbadge {
        font-size: 0.5rem;
        padding: 1px 5px;
    }

    .profil-socials {
        gap: 4px;
        top: 6px;
        right: 6px;
    }

    .profil-social-icon {
        width: 30px;
        height: 30px;
        font-size: 0.75rem;
    }

    /* Browse */
    .browse-grid, .media-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    /* Tools */
    .tools-grid {
        grid-template-columns: 1fr !important;
    }
}

/* ============================================================
   PRINT
   ============================================================ */
@media print {
    .header-root, .mobile-bottom-nav, .site-footer {
        display: none !important;
    }

    body {
        padding: 0 !important;
        background: #fff !important;
        color: #000 !important;
    }
}
