/* ═══════════════════════════════════════════════════════════════
   Arena Mobile Optimization
   Targets: Samsung Galaxy S24/S25, Galaxy Fold/Flip, iPhone 15/16,
            Pixel 9, Android tablets, iPads, Korean market phones
   ═══════════════════════════════════════════════════════════════ */

/* ── Viewport & Safe Area Foundation ──────────────────────────── */

.arena-container {
    padding-left: env(safe-area-inset-left, 0px);
    padding-right: env(safe-area-inset-right, 0px);
}

/* ── Performance: content-visibility for below-fold sections ── */

.arena-yesno-section,
.arena-scoreboard,
.arena-epoch-history,
.arena-feed-section {
    content-visibility: auto;
    contain-intrinsic-size: auto 300px;
}
/* .arena-positions excluded — JS scrollIntoView() after order needs immediate render */

/* ── Small Phones (≤430px) — iPhone 15/16 Pro Max, Galaxy S24+ ─ */

@media (max-width: 430px) {
    .arena-container {
        padding-top: 0.5rem;
        padding-bottom: 2rem;
        padding-left: max(0.5rem, env(safe-area-inset-left, 0px));
        padding-right: max(0.5rem, env(safe-area-inset-right, 0px));
    }

    /* Hero — tighter on small screens */
    .arena-hero {
        padding: 1.25rem 0.75rem;
        border-radius: 12px;
        margin-bottom: 1rem;
    }

    .arena-hero-title {
        font-size: 1.35rem;
        line-height: 1.2;
    }

    .arena-hero-subtitle {
        margin-bottom: 1rem;
    }

    .arena-epoch-bar {
        gap: 0.4rem;
        padding: 0.35rem 0.6rem;
        flex-wrap: wrap;
        justify-content: center;
    }

    /* Unfurl panels — stack layout */
    .arena-unfurl-panel {
        padding: 0.6rem;
        border-radius: 12px;
        margin-bottom: 1rem;
        gap: 0.75rem;
    }

    .arena-unfurl-info h2 {
        font-size: 15px;
        line-height: 1.25;
    }

    .arena-unfurl-desc {
        -webkit-line-clamp: 3;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        overflow: hidden;
    }

    .arena-unfurl-cta {
        padding: 0.65rem 1.25rem;
        border-radius: 10px;
        max-width: 100%;
        width: 100%;
        box-sizing: border-box;
        justify-content: center;
    }

    /* Chart — shorter on small phones */
    .arena-chart-section {
        padding: 0.6rem;
        border-radius: 12px;
        margin-bottom: 1rem;
        overflow: clip;
    }

    #arenaChartContainer {
        height: 300px !important;
        max-width: 100%;
        overflow: visible;
    }

    .arena-chart-prices {
        gap: 0.75rem;
    }

    /* Trade entry — full width, tighter spacing */
    .arena-trade-entry {
        padding: 1rem 0.75rem;
        border-radius: 10px;
        margin-bottom: 1rem;
    }

    .arena-outcome-btn {
        padding: 0.6rem 0.35rem;
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .arena-quick-amounts {
        gap: 0.3rem;
    }

    .arena-quick-btn {
        font-size: 0.75rem;
        padding: 0.6rem 0;
        min-height: 44px;
    }

    .arena-payout-row {
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .arena-payout-item {
        flex: 1 1 30%;
        min-width: 0;
    }

    /* payout-label/value font-sizes: controlled by mobile-responsive.css !important overrides */

    /* Scoreboard — compact */
    .arena-scoreboard {
        gap: 0.5rem;
        margin-bottom: 1rem;
    }

    .arena-team {
        padding: 1rem 0.75rem;
        border-radius: 10px;
    }

    .arena-team-nav {
        font-size: 1.3rem;
    }

    .arena-vs-score {
        font-size: 1.4rem;
    }

    /* Orderbook — tighter */
    .arena-yesno-section {
        border-radius: 12px;
        margin-bottom: 1rem;
    }

    .arena-yesno-body {
        padding: 0 0.75rem 0.75rem;
    }

    .arena-yesno-toggle {
        padding: 0.75rem 0.85rem;
    }

    /* Feed section */
    .arena-feed-section {
        padding: 1rem 0.75rem;
        border-radius: 12px;
    }

    /* Positions/orders tables */
    .arena-positions {
        padding: 1rem 0.75rem;
        border-radius: 10px;
        margin-bottom: 1rem;
    }

    /* Balance bar */
    #arenaBalanceBar {
        border-radius: 8px !important;
        padding: 8px 10px !important;
    }

    /* Mode toggle */
    .arena-mode-toggle {
        margin-bottom: 6px !important;
    }

    /* Trade modal — full width on small phones */
    .arena-trade-modal {
        max-width: 100%;
        border-radius: 14px 14px 0 0;
        max-height: 75vh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    .arena-trade-modal-body {
        padding: 0.6rem 1rem 0.75rem;
    }

    /* Close/cancel buttons — ensure 44px touch target */
    .btn-close-position,
    .btn-cancel-order {
        min-height: 44px !important;
    }
}

/* ── Standard Mobile (431-600px) ─────────────────────────────── */

@media (min-width: 431px) and (max-width: 600px) {
    .arena-container {
        padding-top: 0.75rem;
        padding-bottom: 2rem;
        padding-left: max(0.5rem, env(safe-area-inset-left, 0px));
        padding-right: max(0.5rem, env(safe-area-inset-right, 0px));
    }

    .arena-hero {
        padding: 1.5rem 1rem;
    }

    .arena-hero-title {
        font-size: 1.5rem;
    }

    .arena-unfurl-cta {
        width: 100%;
        justify-content: center;
    }

    #arenaChartContainer {
        height: 320px !important;
    }
}

/* ── Tablet (601-1024px) ─────────────────────────────────────── */

@media (min-width: 601px) and (max-width: 1024px) {
    .arena-container {
        padding-top: 1rem;
        padding-bottom: 2rem;
        padding-left: max(1.5rem, env(safe-area-inset-left, 0px));
        padding-right: max(1.5rem, env(safe-area-inset-right, 0px));
    }

    /* Two-column unfurl on tablet */
    .arena-unfurl-panel {
        padding: 1rem 1.25rem;
    }

    .arena-unfurl-image {
        flex: 0 0 30%;
        max-width: 30%;
    }

    /* Chart height — balanced for tablet */
    #arenaChartContainer {
        height: 440px !important;
    }

    /* Scoreboard — keep grid but tighter */
    .arena-scoreboard {
        grid-template-columns: 1fr auto 1fr;
    }

    .arena-team {
        padding: 1.25rem;
    }

    /* Trade entry centered, constrained */
    .arena-trade-entry {
        max-width: 420px;
    }

    /* Feed — keep two-column on tablet */
    .arena-feed-cols {
        grid-template-columns: 1fr 1fr;
    }
}

/* ── Landscape Mode ──────────────────────────────────────────── */

@media (orientation: landscape) and (max-height: 500px) {
    .arena-hero {
        padding: 0.75rem 1.5rem;
        margin-bottom: 0.75rem;
    }

    .arena-hero-title {
        font-size: 1.2rem;
        margin-bottom: 0.25rem;
    }

    .arena-hero-subtitle {
        display: none;
    }

    .arena-epoch-bar {
        padding: 0.3rem 0.75rem;
    }

    #arenaChartContainer {
        height: 240px !important;
    }

    .arena-scoreboard {
        grid-template-columns: 1fr auto 1fr;
    }

    .arena-team {
        padding: 0.75rem;
    }

    .arena-team-nav {
        font-size: 1.2rem;
    }

    /* Trade modal in landscape — side-by-side */
    .arena-trade-modal {
        max-height: 90vh;
        max-height: 90dvh;
    }
}

/* ── Foldable Devices (Samsung Galaxy Fold/Flip) ─────────────── */

/* Galaxy Z Fold cover screen (~374px folded) */
@media (max-width: 380px) and (min-resolution: 2.5dppx) {
    .arena-hero-title {
        font-size: 1.2rem;
    }

    .arena-epoch-bar {
        gap: 0.3rem;
        padding: 0.3rem 0.5rem;
    }

    .arena-hero-badge {
        font-size: 0.7rem;
        padding: 2px 6px;
    }

    .arena-unfurl-cta {
        padding: 0.55rem 1rem;
        font-size: 0.8rem;
    }

    .arena-chart-prices {
        gap: 0.5rem;
    }

    .chart-range-btn {
        padding: 8px 10px;
        min-height: 44px;
    }

    #arenaChartContainer {
        height: 240px !important;
    }

    .arena-prob-bar-label {
        font-size: 0.7rem;
    }

    .arena-prob-pill {
        font-size: 0.7rem;
        min-width: 44px;
        padding: 4px 6px;
    }

    .arena-prob-multiplier {
        font-size: 0.7rem;
        min-width: 32px;
    }

    .arena-unfurl-info h2 {
        font-size: 14px;
    }

    .arena-scoreboard {
        gap: 0.5rem;
    }
}

/* Foldable unfolded / screen-spanning (Fold inner display ~717px) */
@media (min-width: 700px) and (max-width: 768px) and (min-resolution: 2.5dppx) {
    .arena-scoreboard {
        grid-template-columns: 1fr auto 1fr;
    }

    .arena-feed-cols {
        grid-template-columns: 1fr 1fr;
    }
}

/* Screen-spanning (dual-screen foldables — Galaxy Fold, Surface Duo) */
@media (horizontal-viewport-segments: 2) {
    .arena-container {
        display: grid;
        grid-template-columns: env(viewport-segment-width 0 0) env(viewport-segment-width 1 0);
        column-gap: env(viewport-segment-left 1 0, 0px);
    }

    /* Default: all children span both columns */
    .arena-container > * {
        grid-column: 1 / -1;
    }

    /* Split trade entry and orderbook across the hinge */
    .arena-trade-entry {
        grid-column: 1;
        max-width: 100%;
    }

    .arena-yesno-section {
        grid-column: 2;
    }
}

/* ── Touch Targets — Arena-Specific ──────────────────────────── */

@media (max-width: 768px) {
    /* Outcome buttons must be easy to tap */
    .arena-outcome-btn {
        min-height: 56px;
        touch-action: manipulation;
    }

    /* Quick amount buttons */
    .arena-quick-btn {
        min-height: 44px;
        touch-action: manipulation;
    }

    /* Trade submit — large tap target */
    .arena-trade-submit {
        min-height: 48px;
        font-size: 0.9rem;
        touch-action: manipulation;
    }

    /* Chart range buttons — WCAG 44px touch target */
    .chart-range-btn {
        min-height: 44px;
        min-width: 44px;
        touch-action: manipulation;
    }

    /* Orderbook toggle */
    .arena-yesno-toggle {
        min-height: 48px;
        touch-action: manipulation;
    }

    /* Orderbook action buttons */
    .arena-yesno-buy,
    .arena-yesno-sell {
        min-height: 44px;
        touch-action: manipulation;
    }

    /* Tab buttons in orderbook */
    .arena-yesno-tab {
        min-height: 44px;
        touch-action: manipulation;
    }

    /* All Markets link */
    .arena-all-markets-link {
        min-height: 44px;
        padding: 10px 14px;
    }

    /* Tradable event panel — whole area is tappable */
    .arena-unfurl-panel {
        -webkit-tap-highlight-color: transparent;
    }

    /* Balance bar buttons */
    #btnArenaDeposit,
    #btnArenaWithdraw {
        min-height: 44px !important;
        padding: 8px 16px !important;
        touch-action: manipulation;
    }

    /* Withdraw form buttons */
    #btnWithdrawMax,
    #btnWithdrawConfirm,
    #arenaWithdrawForm button {
        min-height: 44px !important;
    }

    /* Developer links at bottom */
    .arena-container > div:last-child a {
        min-height: 44px;
        display: inline-flex;
        align-items: center;
    }
}

/* ── Samsung Internet Fixes ──────────────────────────────────── */

/* Samsung Internet has known issues with backdrop-filter */
@supports not (backdrop-filter: blur(4px)) {
    .arena-team {
        background: rgba(17, 26, 40, 0.85);
    }

    .arena-trade-entry {
        background: rgba(17, 26, 40, 0.85);
    }

    .arena-trade-modal-backdrop {
        background: rgba(0, 0, 0, 0.75);
    }
}

/* Font sizes for arena elements are controlled by mobile-responsive.css
   arena-specific overrides (with !important) to avoid blanket 14px rule.
   Do NOT set font-size here without !important — it will be overridden. */

/* ── Balance Bar Mobile ──────────────────────────────────────── */

@media (max-width: 600px) {
    #arenaBalanceBar > div {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 6px !important;
    }

    #arenaBalanceBar > div > div:last-child {
        width: 100%;
        display: flex;
    }

    #arenaBalanceBar > div > div:last-child a,
    #arenaBalanceBar > div > div:last-child button {
        flex: 1;
        text-align: center;
    }

    /* Withdraw form — stack on mobile */
    #arenaWithdrawForm > div {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 6px !important;
    }

    #arenaWithdrawForm input[type="number"] {
        width: 100% !important;
    }

    #arenaWithdrawForm > div > div {
        width: 100%;
    }
}

/* ── Positions Table — Card Layout on Mobile ─────────────────── */

@media (max-width: 600px) {
    .arena-positions-table thead {
        display: none;
    }

    .arena-positions-table tbody,
    .arena-positions-table tr,
    .arena-positions-table td {
        display: block;
        width: 100%;
    }

    .arena-positions-table tr {
        padding: 0.75rem;
        margin-bottom: 0.5rem;
        background: rgba(255, 255, 255, 0.03);
        border-radius: 8px;
        border-bottom: none;
    }

    .arena-positions-table td {
        display: flex;
        justify-content: space-between;
        padding: 0.25rem 0;
        border-bottom: none;
    }

    .arena-positions-table td::before {
        content: attr(data-label);
        font-size: 0.7rem;
        color: rgba(255, 255, 255, 0.35);
        text-transform: uppercase;
        letter-spacing: 0.05em;
        font-weight: 500;
    }

    /* Hide label pseudo-element on action/cancel columns (empty data-label) */
    .arena-positions-table td[data-label=""]::before {
        display: none;
    }

    /* Action td — justify to end on mobile cards */
    .arena-positions-table td[data-label="Actions"],
    .arena-positions-table td[data-label=""] {
        justify-content: flex-end;
    }

    /* Epoch table — same card treatment */
    .arena-epoch-table thead {
        display: none;
    }

    .arena-epoch-table tbody,
    .arena-epoch-table tr,
    .arena-epoch-table td {
        display: block;
        width: 100%;
    }

    .arena-epoch-table tr {
        padding: 0.75rem;
        margin-bottom: 0.5rem;
        background: rgba(255, 255, 255, 0.03);
        border-radius: 8px;
    }

    .arena-epoch-table td {
        display: flex;
        justify-content: space-between;
        padding: 0.2rem 0;
        border-bottom: none;
    }

    .arena-epoch-table td::before {
        content: attr(data-label);
        font-size: 0.7rem;
        color: rgba(255, 255, 255, 0.35);
        text-transform: uppercase;
        letter-spacing: 0.05em;
    }
}

/* ── Live Consent Modal — Mobile ─────────────────────────────── */

@media (max-width: 600px) {
    #liveConsentModal {
        top: auto !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        transform: none !important;
        width: 100% !important;
        max-width: 100% !important;
        border-radius: 16px 16px 0 0 !important;
        padding: 20px 16px calc(20px + env(safe-area-inset-bottom, 0px)) !important;
    }
}

/* ── Bottom padding to clear Nexus chat bar ──────────────────── */

@media (max-width: 768px) {
    .arena-container {
        padding-bottom: 100px;
    }
}

/* ── Epoch Timer Readability ─────────────────────────────────── */

@media (max-width: 600px) {
    .arena-epoch-timer {
        font-size: 0.85rem !important;
        letter-spacing: 0.04em;
    }
}

/* ── Scoreboard VS — Better mobile spacing ───────────────────── */

@media (max-width: 768px) {
    .arena-vs {
        padding: 0.35rem 0;
    }

    .arena-vs-label {
        font-size: 0.7rem;
    }

    .arena-team-name {
        font-size: 0.9rem;
    }

    .arena-team-wins {
        font-size: 0.7rem;
    }
}

/* ── Recent Trades Readability ───────────────────────────────── */

@media (max-width: 768px) {
    .arena-trade-row {
        font-size: 0.72rem !important;
        padding: 0.4rem 0.35rem;
    }

    .arena-trade-row > span:first-child {
        flex: 0 0 75px;
    }
}

/* ── Payout Row — prevent overflow on small screens ──────────── */

@media (max-width: 430px) {
    .arena-payout-label {
        font-size: 0.7rem !important;
        white-space: nowrap;
    }

    .arena-payout-value {
        font-size: 0.78rem !important;
    }

    .arena-payout-value.green small {
        font-size: 0.7rem;
    }
}

/* ── Epoch History — prevent Performance truncation ──────────── */

@media (max-width: 600px) {
    .arena-epoch-table td:nth-child(3) {
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
        max-width: 80px;
    }
}

/* ── Unfurl CTA — larger tap target on mobile ────────────────── */

@media (max-width: 600px) {
    .arena-unfurl-cta {
        min-height: 48px;
        display: inline-flex;
        align-items: center;
        font-size: 0.85rem;
    }

    .arena-all-markets-link-2nd {
        display: none;
    }
}

/* ── Reduce Motion for users who prefer it ───────────────────── */

@media (prefers-reduced-motion: reduce) {
    .arena-hero-badge,
    .arena-tradable-event-title::before,
    .arena-live-indicator::before {
        animation: none;
    }

    .arena-unfurl-cta,
    .arena-trade-modal,
    .arena-yesno-chevron {
        transition: none;
    }

    .arena-trade-row,
    .arena-headline-row {
        animation: none;
    }
}
