/* ============================================
   Tablet (max-width: 1024px)
   ============================================ */
@media (max-width: 1024px) {
    /* Phase 1A: Hide fixed left nav + fix padding */
    .fixed-left-nav {
        display: none !important;
    }

    .main-container {
        padding: 0 16px;
    }

    .navbar-inner {
        padding: 0 16px;
    }

    /* Layout: stack main + sidebar */
    .main-layout {
        flex-direction: column;
        align-items: stretch;
    }

    /* Phase 1B: Sidebar vertical stack (not horizontal) */
    .sidebar {
        width: 100%;
        flex-direction: column;
    }

    .sidebar > .sidebar-card {
        flex: none;
        min-width: 0;
    }

    /* Lottery hall grid: single column */
    .lottery-grid.grid-mode {
        grid-template-columns: 1fr;
    }

    .lottery-grid.grid-mode .lottery-logo {
        width: 48px;
        height: 48px;
    }

    /* Rankings */
    .rankings-grid {
        grid-template-columns: 1fr;
    }

    /* Rules */
    .rules-layout {
        flex-direction: column;
        align-items: stretch;
    }

    .rules-sidebar {
        width: 100%;
    }

    /* Stats */
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    /* Text ads: 3 per row on tablet */
    .ad-text-bar {
        grid-template-columns: repeat(3, 1fr);
    }

    /* Site cards: 3 per row on tablet */
    .site-grid {
        grid-template-columns: repeat(3, 1fr);
    }

    .site-card-logo {
        width: 42px;
        height: 42px;
    }
}

/* ============================================
   Mobile (max-width: 768px)
   ============================================ */
@media (max-width: 768px) {
    /* Navbar: hide desktop menu, show hamburger, align with content */
    .navbar {
        padding: 0;
    }

    .navbar-inner {
        padding: 0 10px;
    }

    .navbar-menu {
        display: none;
    }

    .navbar-right-btns {
        display: flex;
    }

    .navbar-rate-btn,
    .navbar-market-btn {
        display: flex;
    }

    .navbar-toggle {
        display: flex;
    }

    .navbar-brand img {
        height: 42px;
    }

    .navbar-brand {
        font-size: 19px;
    }

    /* Main container */
    .main-container {
        padding: 0 10px;
        margin-top: 76px;
    }

    .main-container.has-marquee {
        margin-top: 108px;
    }

    /* Phase 8A: iOS input 16px zoom prevention */
    input, select, textarea {
        font-size: 16px !important;
    }

    /* ---- Lottery Cards (home) — logo+info row centered, numbers centered below ---- */
    .lottery-card {
        flex-wrap: wrap;
        justify-content: center;
        padding: 12px 14px;
        gap: 8px;
    }

    .lottery-card-logo-wrap {
        flex-shrink: 0;
    }

    .lottery-card-logo,
    .lottery-card-logo-fallback {
        width: 72px;
        height: 72px;
        font-size: 24px;
    }

    .lottery-card-info {
        width: auto !important;
        flex: none !important;
        text-align: left;
    }

    .lottery-card-info h3 {
        font-size: 14px;
    }

    .lottery-card-info .period {
        font-size: 11px;
        white-space: normal;
    }

    .lottery-card-info .schedule {
        font-size: 10px;
        white-space: normal;
    }

    .lottery-card-countdown-line {
        flex-wrap: wrap;
    }

    /* Numbers: full width, centered */
    .lottery-card-numbers {
        width: 100%;
        flex: none;
    }

    .lottery-card-numbers .ball-row {
        max-width: none;
        justify-content: center;
    }

    .lottery-card-numbers .ball {
        width: 34px;
        height: 34px;
        font-size: 14px;
    }

    .lottery-card-numbers .ball-plus {
        height: 34px;
        font-size: 17px;
    }

    .lottery-card-numbers .zodiac {
        font-size: 10px;
    }

    /* Video button smaller */
    .video-icon-btn {
        width: 34px;
        height: 34px;
        font-size: 14px;
    }

    /* ---- Site Cards ---- */
    .site-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
        padding: 10px;
    }

    .site-card {
        padding: 10px 12px;
        gap: 0 10px;
    }

    .site-card-logo {
        width: 46px;
        height: 46px;
    }

    .site-card-logo-fallback {
        font-size: 18px;
    }

    .site-card-name {
        font-size: 15px;
    }

    .site-card-badge {
        font-size: 15px;
        padding: 0;
        right: 8px;
    }

    .site-card .star-rating i {
        font-size: 12px;
    }

    .site-card-more-btn {
        font-size: 15px;
        padding: 4px 8px;
        right: 0;
    }

    .nav-cat-title {
        font-size: 14px;
        padding: 8px 12px;
    }

    /* ---- Text Ads: 2 per row ---- */
    .ad-text-bar {
        grid-template-columns: repeat(2, 1fr);
        gap: 6px;
    }

    .ad-text-btn {
        font-size: 11px;
        padding: 6px 8px;
    }

    /* ---- Lottery Detail (mobile — centered, compact) ---- */
    .detail-top {
        flex-direction: column;
        padding: 14px;
        gap: 8px;
    }

    .detail-col-logo {
        display: none;
    }

    .detail-col-main {
        width: 100%;
        gap: 6px;
        align-items: center;
        text-align: center;
    }

    .detail-row-info {
        flex-wrap: wrap;
        gap: 2px 8px;
        justify-content: center;
    }

    .detail-name {
        font-size: 16px;
        flex-basis: 100%;
    }

    .detail-period {
        font-size: 14px;
        font-weight: 700;
    }

    .detail-schedule-text {
        font-size: 12px;
    }

    .detail-numbers .ball-row {
        justify-content: center;
    }

    .detail-numbers .ball {
        width: 34px;
        height: 34px;
        font-size: 14px;
    }

    .detail-numbers .ball-plus {
        font-size: 16px;
    }

    /* Countdown: label + timer stick together, centered */
    .detail-col-right {
        width: 100%;
        flex-direction: row;
        align-items: center;
        justify-content: center;
        gap: 8px;
        border-top: 1px dashed var(--border-subtle);
        padding-top: 10px;
    }

    .detail-countdown {
        display: flex;
        flex-direction: row;
        align-items: center;
        gap: 6px;
    }

    .detail-countdown .countdown-label {
        font-size: 13px;
        margin-bottom: 0;
        white-space: nowrap;
    }

    .detail-countdown .countdown-timer {
        margin-left: 0;
    }

    .detail-countdown .countdown-timer .cd-num {
        min-width: 26px;
        height: 30px;
        font-size: 14px;
        padding: 3px 5px;
    }

    .detail-countdown .countdown-timer .cd-sep {
        font-size: 14px;
    }

    /* Video: text button instead of cover */
    .detail-video {
        flex-shrink: 0;
        border-radius: var(--radius-sm);
        background: var(--accent);
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 4px;
        padding: 6px 12px;
        overflow: visible;
        width: auto;
        height: auto;
    }

    .detail-video img {
        display: none;
    }

    .detail-video::before {
        content: '\f04b';
        font-family: 'Font Awesome 7 Free';
        font-weight: 900;
        font-size: 11px;
        color: #fff;
    }

    .detail-video::after {
        content: '视频';
        font-size: 12px;
        font-weight: 600;
        color: #fff;
    }

    /* Phase 2B + 2C: History table + date filter wrap + column toggle */
    .history-header {
        flex-wrap: wrap;
        gap: 8px;
    }

    .date-filter {
        flex-wrap: wrap;
        width: 100%;
        gap: 6px;
    }

    .date-quick-btn {
        padding: 0 10px;
        font-size: 12px;
        height: 30px;
        line-height: 30px;
    }

    .date-filter input {
        width: 120px;
        font-size: 12px !important;
        padding: 0 10px;
        height: 30px;
        line-height: 30px;
    }

    /* Mobile: hide individual stat columns, show toggle in combined cell */
    .history-table [data-grp="stat"] {
        display: none !important;
    }

    .history-table .th-label {
        display: none;
    }

    .history-table .th-toggle-btns {
        display: inline-flex;
    }

    /* Toggle content in combined number/stat cell */
    .history-table[data-view="stat"] .cell-stat {
        display: block;
    }

    .history-table[data-view="stat"] .cell-num {
        display: none;
    }

    /* Fixed layout so columns don't jump on toggle */
    .history-table {
        min-width: 0;
        font-size: 12px;
        table-layout: fixed;
    }

    .history-table th:first-child,
    .history-table td:first-child {
        width: 58px;
    }

    .history-table th:nth-child(2),
    .history-table td:nth-child(2) {
        width: 72px;
    }

    .history-table thead th {
        font-size: 12px;
        padding: 10px 8px;
    }

    .history-table tbody td {
        padding: 10px 8px;
    }

    .history-table .numbers-cell .ball {
        width: 26px;
        height: 26px;
        font-size: 11px;
    }

    .history-table .numbers-cell .ball-plus {
        height: 26px;
        font-size: 12px;
    }

    /* ---- Lottery Hall ---- */
    /* Phase 3A: Tab horizontal scroll */
    .lot-hub-tabs {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .lot-hub-tab {
        flex-shrink: 0;
        padding: 10px 14px;
        font-size: 13px;
    }

    .lot-hub-cats {
        padding: 6px 14px 10px;
    }

    .lot-cat-row {
        flex-direction: column;
        align-items: stretch;
        gap: 4px;
        padding: 6px 0;
    }

    .lot-cat-label {
        width: auto;
        font-size: 12px;
    }

    .lot-cat-type {
        font-size: 12px;
        padding: 3px 8px;
    }

    /* ---- Lottery Hall Grid Cards ---- */
    .lottery-grid.grid-mode .lottery-card-header {
        padding: 14px 16px;
        gap: 12px;
    }

    .lottery-grid.grid-mode .lottery-logo {
        width: 56px;
        height: 56px;
        border-width: 2px;
    }

    .lottery-grid.grid-mode .lottery-card-info-grid h3 {
        font-size: 14px;
    }

    .lottery-grid.grid-mode .lottery-card-info-grid .schedule {
        font-size: 12px;
    }

    .lottery-grid.grid-mode .lottery-card-status .status-label {
        font-size: 12px;
    }

    .lottery-grid.grid-mode .lottery-card-status .status-countdown {
        font-size: 13px;
    }

    .lottery-grid.grid-mode .lottery-card-body {
        padding: 14px 16px;
    }

    .lottery-grid.grid-mode .lottery-card-body .ball {
        width: 34px;
        height: 34px;
        font-size: 15px;
    }

    .lottery-grid.grid-mode .lottery-card-body .ball-plus {
        font-size: 17px;
    }

    .lottery-grid.grid-mode .lottery-card-body .zodiac {
        font-size: 11px;
    }

    /* ---- Lottery Hall Type Icons ---- */
    .lottery-type-grid {
        gap: 10px;
        padding: 14px;
    }

    .lottery-type-item {
        width: 80px;
    }

    .lottery-type-icon {
        width: 64px;
        height: 64px;
    }

    .lottery-type-name {
        font-size: 11px;
        max-width: 80px;
    }

    /* Stats responsive */
    .stats-row {
        gap: 6px 16px;
        margin-top: 10px;
        padding-top: 10px;
    }

    .stats-title {
        font-size: 12px;
    }

    .stat-tag {
        font-size: 12px;
        padding: 1px 8px;
    }

    /* ---- Phase 4A: Rules sidebar → horizontal pill bar ---- */
    .rules-sidebar {
        border-radius: var(--radius-lg);
        overflow: hidden;
    }

    #rulesNavList {
        display: flex;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        gap: 0;
        padding: 4px 8px;
    }

    .rules-nav-item {
        white-space: nowrap;
        border-bottom: none;
        border-radius: var(--radius-sm);
        padding: 8px 14px;
        flex-shrink: 0;
        border-left: none !important;
    }

    .rules-nav-item.active {
        border-left: none;
        background: var(--accent);
        color: #fff;
    }

    .rules-content {
        padding: var(--spacing-md);
    }

    /* Phase 4B: Rules content table scroll */
    .rules-html-content table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* ---- Phase 5B: Dividends year tabs scroll ---- */
    .dividends-year-tabs {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 4px;
        gap: 4px;
    }

    .year-tab {
        flex-shrink: 0;
        padding: 5px 12px;
        font-size: 12px;
    }

    /* ---- Rankings ---- */
    .rankings-grid {
        grid-template-columns: 1fr;
    }

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

    /* ---- Phase 6A: Articles tag bar scroll ---- */
    .articles-tag-bar {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        padding: 12px 14px;
        gap: 6px;
    }

    .articles-pill {
        flex-shrink: 0;
        padding: 5px 14px;
        font-size: 12px;
    }

    /* Phase 6B: Article detail */
    .article-detail {
        padding: var(--spacing-md);
    }

    .article-detail-content table {
        display: block;
        overflow-x: auto;
    }

    .article-detail-meta {
        flex-wrap: wrap;
        gap: 6px;
    }

    .article-card-item {
        padding: 12px 14px;
    }

    .article-detail-title {
        font-size: 18px;
    }

    /* ---- About ---- */
    .about-info-row {
        flex-direction: column;
        gap: 2px;
    }

    .about-info-label {
        width: auto;
        font-weight: 600;
    }

    /* ---- Submit Form ---- */
    .submit-form .form-row {
        flex-direction: column;
    }

    .submit-form .url-row {
        flex-direction: column;
    }

    .submit-form .form-actions {
        flex-direction: column;
    }

    .submit-form .form-actions .btn {
        width: 100%;
    }

    /* ---- Floating Contact ---- */
    .floating-contact {
        right: 6px;
        bottom: 12px;
    }

    .floating-btn {
        width: 38px;
        height: 38px;
        font-size: 14px;
    }

    /* ---- Misc ---- */
    .section-title {
        font-size: 15px;
    }

    /* Sidebar cards */
    .sidebar {
        gap: 10px;
    }

    .sidebar-card {
        min-width: 0;
    }

    /* Extra URLs popup */
    .extra-urls-list {
        gap: 6px;
    }

    .extra-url-item {
        padding: 5px 10px;
        font-size: 11px;
    }
}

/* ============================================
   Small Mobile (max-width: 480px)
   ============================================ */
@media (max-width: 480px) {
    .main-container {
        padding: 0 6px;
    }

    .navbar-inner {
        padding: 0 6px;
    }

    /* Lottery cards (home page): tighter */
    .lottery-card {
        padding: 10px;
        gap: 6px;
    }

    .lottery-card-logo,
    .lottery-card-logo-fallback {
        width: 64px;
        height: 64px;
        font-size: 22px;
    }

    .lottery-card-info h3 {
        font-size: 13px;
        white-space: normal;
        line-height: 1.3;
    }

    .lottery-card-info .period {
        font-size: 10px;
        white-space: normal;
    }

    .lottery-card-info .schedule {
        display: none;
    }

    .lottery-card-countdown-line .countdown-label {
        font-size: 10px;
    }

    .lottery-card-countdown-line .countdown-value {
        font-size: 12px;
    }

    .lottery-card-numbers .ball {
        width: 28px;
        height: 28px;
        font-size: 12px;
    }

    .lottery-card-numbers .ball-plus {
        height: 28px;
        font-size: 14px;
    }

    .lottery-card-numbers .zodiac {
        font-size: 9px;
    }

    /* Lottery hall grid cards: small mobile */
    .lottery-grid.grid-mode {
        grid-template-columns: 1fr;
    }

    .lottery-grid.grid-mode .lottery-card-header {
        padding: 12px;
        gap: 10px;
    }

    .lottery-grid.grid-mode .lottery-logo {
        width: 48px;
        height: 48px;
    }

    .lottery-grid.grid-mode .lottery-card-info-grid h3 {
        font-size: 13px;
        white-space: normal;
    }

    .lottery-grid.grid-mode .lottery-card-info-grid .schedule {
        display: none;
    }

    .lottery-grid.grid-mode .lottery-card-status .status-label {
        font-size: 11px;
    }

    .lottery-grid.grid-mode .lottery-card-status .status-countdown {
        font-size: 12px;
    }

    .lottery-grid.grid-mode .lottery-card-body {
        padding: 12px;
    }

    .lottery-grid.grid-mode .lottery-card-body .ball {
        width: 30px;
        height: 30px;
        font-size: 13px;
    }

    .lottery-grid.grid-mode .lottery-card-body .ball-plus {
        font-size: 15px;
    }

    .lottery-grid.grid-mode .lottery-card-body .zodiac {
        font-size: 10px;
    }

    /* Stats small mobile */
    .stats-row {
        gap: 5px 12px;
        margin-top: 8px;
        padding-top: 8px;
    }

    .stats-title {
        font-size: 11px;
    }

    .stat-tag {
        font-size: 11px;
        padding: 1px 6px;
    }

    /* Site cards: 2 per row on small mobile */
    .site-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 6px;
        padding: 8px;
    }

    .site-card {
        padding: 8px 10px;
        gap: 0 8px;
    }

    .site-card-logo {
        width: 42px;
        height: 42px;
    }

    .site-card-logo-fallback {
        font-size: 16px;
    }

    .site-card-name {
        font-size: 14px;
    }

    .site-card .star-rating i {
        font-size: 11px;
    }

    .site-card-badge {
        font-size: 14px;
        padding: 0;
        right: 8px;
    }

    .site-card-more-btn {
        font-size: 14px;
        padding: 3px 8px;
        right: 0;
    }

    .nav-cat-title {
        font-size: 13px;
        padding: 7px 10px;
    }

    /* Text ads */
    .ad-text-bar {
        grid-template-columns: repeat(2, 1fr);
    }

    .ad-text-btn {
        font-size: 10px;
        padding: 5px 6px;
    }

    /* Lottery detail */
    .detail-top {
        padding: 10px;
        gap: 6px;
    }

    .detail-name {
        font-size: 14px;
    }

    .detail-period {
        font-size: 13px;
    }

    .detail-schedule-text {
        font-size: 10px;
    }

    .detail-countdown .countdown-label {
        font-size: 11px;
    }

    .detail-countdown .countdown-timer .cd-num {
        min-width: 24px;
        font-size: 13px;
        padding: 3px 4px;
    }

    .detail-countdown .countdown-timer .cd-sep {
        font-size: 13px;
    }

    .detail-video {
        padding: 5px 10px;
    }

    .detail-numbers .ball {
        width: 30px;
        height: 30px;
        font-size: 13px;
    }

    /* Date filter small mobile */
    .date-quick-btn {
        padding: 0 8px;
        font-size: 11px;
        height: 26px;
        line-height: 26px;
    }

    .date-filter input {
        width: 110px;
        font-size: 11px !important;
        padding: 0 8px;
        height: 26px;
        line-height: 26px;
    }

    /* History table small mobile */
    .history-table {
        font-size: 11px;
    }

    .history-table thead th {
        font-size: 11px;
        padding: 8px 6px;
    }

    .history-table tbody td {
        padding: 8px 6px;
    }

    .history-table .numbers-cell .ball {
        width: 24px;
        height: 24px;
        font-size: 10px;
    }

    .history-table .numbers-cell .ball-plus {
        height: 24px;
        font-size: 11px;
    }

    .history-table .numbers-cell .zodiac {
        font-size: 8px;
    }

    /* Marquee */
    .home-marquee-content {
        font-size: 12px;
    }

    /* Sidebar */
    .sidebar > .sidebar-card {
        min-width: 0;
    }

    /* Phase 5A: Rankings compact */
    .ranking-entry {
        gap: 8px;
        padding: 6px 0;
    }

    .ranking-position {
        width: 24px;
        height: 24px;
        font-size: 11px;
    }

    .ranking-entry-logo {
        width: 24px;
        height: 24px;
    }

    .ranking-entry-name {
        font-size: 12px;
    }

    .ranking-entry-views {
        font-size: 11px;
    }

    /* Phase 5C: Dividends table compact */
    .dividends-table thead th,
    .dividends-table tbody td {
        padding: 8px 10px;
        font-size: 13px;
    }

    /* Phase 5D: About page stats compact */
    .stat-value {
        font-size: 22px;
    }

    .about-section-body {
        padding: var(--spacing-md);
    }

    /* Phase 7A: Submit form compact */
    .submit-form {
        padding: var(--spacing-md);
    }

    .submit-conditions {
        padding: var(--spacing-md);
    }

    .logo-upload-area {
        height: 100px;
    }

    /* Phase 8D: Footer small */
    .footer {
        padding: 20px 12px;
        font-size: 11px;
    }
}

/* ============================================
   Phase 8B: Safe area (notch/home indicator)
   ============================================ */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
    .footer {
        padding-bottom: calc(32px + env(safe-area-inset-bottom));
    }

    .floating-contact {
        bottom: calc(20px + env(safe-area-inset-bottom));
    }
}

/* ============================================
   Phase 8C: Disable hover transforms on touch
   ============================================ */
@media (hover: none) {
    /* Home lottery cards: disable all hover effects */
    .lottery-card:hover {
        background: transparent;
    }

    .lottery-card:hover::before {
        opacity: 0;
    }

    .lottery-card:hover .lottery-card-logo,
    .lottery-card:hover .lottery-logo {
        border-color: var(--border-color);
        box-shadow: 0 3px 12px rgba(0, 0, 0, 0.1);
    }

    .lottery-card:hover .lottery-card-info h3 {
        color: var(--text-primary);
    }

    /* Grid mode cards + site cards */
    .lottery-grid.grid-mode .lottery-card:hover {
        transform: none;
        box-shadow: var(--shadow-card);
        border-color: var(--border-color);
    }

    .lottery-grid.grid-mode .lottery-card:hover .lottery-logo {
        border-color: var(--border-color);
        box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    }

    .lottery-grid.grid-mode .lottery-card-topbar:hover {
        background: linear-gradient(135deg, #8b6914, var(--accent), #e8c36a);
    }

    .site-card:hover {
        transform: none;
        box-shadow: var(--shadow-card);
    }

    .ad-text-btn:hover {
        transform: none;
    }

    .floating-btn:hover {
        transform: none;
    }

    /* On touch: don't show tooltip via hover, only via .active class */
    .floating-item:hover .floating-tooltip {
        opacity: 0;
        visibility: hidden;
    }

    .floating-item.active .floating-tooltip {
        opacity: 1;
        visibility: visible;
    }
}
