/* Mobile interaction layer. Desktop keeps the existing layout and theme tokens. */
.mobile-nav, .mobile-overview, .mobile-trade-indicator { display: none; }
.portfolio-tabs > button.ptab { appearance: none; border: 0; background: none; font-family: inherit; cursor: pointer; padding: 0; }

@media (max-width: 768px) {
    html { --mobile-nav-height: calc(64px + env(safe-area-inset-bottom, 0px)); scroll-padding-top: 164px; }
    html.mobile-overlay-open { overflow: hidden; overscroll-behavior: none; }
    html body {
        --mobile-muted: #526174;
        --mobile-line: #dce2e8;
        --mobile-surface: #ffffff;
        --mobile-bg: #f5f7f9;
        --mobile-accent: #166343;
        --mobile-tint: #eaf5ef;
        margin: 0;
        padding: max(8px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) calc(var(--mobile-nav-height) + 20px) max(12px, env(safe-area-inset-left));
        background: var(--mobile-bg);
        font-size: 15px;
        line-height: 1.5;
        -webkit-text-size-adjust: 100%;
        text-size-adjust: 100%;
    }
    html body.dark-mode, html body.is-lucky-mode:not(.fun-mode) {
        --mobile-muted: #b0bdcd;
        --mobile-line: #334155;
        --mobile-surface: #182231;
        --mobile-bg: #101722;
        --mobile-accent: #6ee7b7;
        --mobile-tint: #18392e;
    }
    html body.fun-mode {
        --mobile-muted: #705946;
        --mobile-line: #dfd0b9;
        --mobile-surface: #fffcf5;
        --mobile-bg: #fff8e7;
        --mobile-accent: #785000;
        --mobile-tint: #f7edce;
    }
    body :is(button, a, input, select, textarea, [role="button"], summary) { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
    body :is(button, a, input, select, textarea, [tabindex]):focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
    body :is(input, textarea) { caret-color: var(--accent); }
    body ::selection { color: var(--text-main); background: color-mix(in srgb, var(--accent) 24%, var(--mobile-surface)); }
    body :is(input, textarea)::placeholder { color: var(--mobile-muted); opacity: 1; }
    body button:disabled { opacity: .55; cursor: not-allowed; }
    body .mono { font-variant-numeric: tabular-nums; }
    html body .app-container { padding-inline: 0; }

    /* A quiet header: persistent context and search, no pulsing login affordance. */
    html body .header {
        padding: 8px 0 0;
        margin: 0 0 16px;
        gap: 4px;
        border: 0;
        border-radius: 0;
        box-shadow: none;
        background: var(--mobile-bg);
        top: 0;
        overflow: visible;
    }
    html body .header-main-row { row-gap: 10px !important; }
    html body .logo-wrapper { margin-left: 2px !important; }
    html body .logo-svg { max-width: 110px !important; }
    html body .top-controls-wrapper > *, html body #connectBtn {
        width: 44px;
        min-width: 44px;
        height: 44px;
        min-height: 44px;
        animation: none;
        box-shadow: none;
    }
    html body #connectBtn { border-radius: 12px; }
    html body.fun-mode #connectBtn {
        background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='22' height='22' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M21 12V7H5a2 2 0 0 1 0-4h14v4M3 5v14a2 2 0 0 0 2 2h16v-5M18 12a2 2 0 0 0 0 4h4v-4Z'/%3E%3C/svg%3E") !important;
        background-repeat: no-repeat !important;
        background-position: center !important;
    }
    html body .wallet-info-pill { min-height: 44px; border-radius: 12px; padding: 8px !important; }
    html body #wallet-dropdown-container { max-width: 40vw; }
    html body .search-wrapper { height: 44px; border: 1px solid var(--mobile-line); border-radius: 12px; background: var(--mobile-surface); }
    html body .search-input { font-size: 16px; font-weight: 400; }
    html body .search-btn { min-width: 52px; min-height: 44px; font-size: 13px; background: transparent; color: var(--mobile-muted); }
    html body #agent-create-btn { width: 44px; min-width: 44px; height: 44px; border-radius: 12px; }
    html body #search-clear-btn { min-width: 44px; min-height: 44px; right: 52px !important; color: var(--mobile-muted) !important; }
    html body .top-nav-menu { margin-top: 4px !important; padding: 0; gap: 18px; border-bottom: 1px solid var(--mobile-line); scrollbar-width: none; }
    html body .nav-item { min-height: 44px; padding: 10px 0; border: 0; border-radius: 0; font-size: 14px; font-weight: 500; color: var(--mobile-muted); box-shadow: none; background: none; }
    html body .top-nav-menu .nav-item.active { color: var(--text-main) !important; background: transparent !important; box-shadow: inset 0 -2px var(--mobile-accent) !important; font-weight: 700; }

    .mobile-nav:not([hidden]) {
        position: fixed;
        inset: auto 0 0;
        z-index: 900;
        display: grid;
        grid-template-columns: repeat(5, minmax(0, 1fr));
        min-height: var(--mobile-nav-height);
        padding: 4px max(6px, env(safe-area-inset-right)) max(4px, env(safe-area-inset-bottom)) max(6px, env(safe-area-inset-left));
        border-top: 1px solid var(--mobile-line);
        background: var(--mobile-surface);
    }
    .mobile-nav button { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; min-width: 0; min-height: 56px; padding: 5px 2px; border: 0; border-radius: 10px; background: transparent; color: var(--mobile-muted); font: 500 11px/1.3 var(--font-sans, sans-serif); overflow-wrap: anywhere; }
    .mobile-nav button > .ic { width: 22px; height: 22px; }
    .mobile-nav [aria-current="page"] { color: var(--mobile-accent); font-weight: 700; background: var(--mobile-tint); }
    .mobile-nav .has-unread::after { content: ''; position: absolute; top: 7px; left: calc(50% + 7px); width: 7px; height: 7px; border-radius: 50%; background: var(--home-red); }
    body.mobile-keyboard-open .mobile-nav { display: none; }
    html body .chat-fab-wrap:not(.open) > .chat-fab-btn { display: none; }
    html body .chat-fab-wrap.open { z-index: 10002; }
    html body .ai-chat-btn { width: 44px; height: 44px; right: 12px; bottom: calc(var(--mobile-nav-height) + 12px); box-shadow: none; border-radius: 12px; background: var(--mobile-surface); border: 1px solid var(--mobile-line); color: var(--mobile-accent); }
    html.mobile-overlay-open .ai-chat-btn, body.mobile-keyboard-open .ai-chat-btn { visibility: hidden; }
    html body #left-column { margin-bottom: 0; }
    body.mobile-detail { padding-bottom: calc(var(--mobile-nav-height) + 96px); }
    body.mobile-detail .ai-chat-btn { bottom: calc(var(--mobile-nav-height) + 96px); }

    .mobile-overview { display: block; margin-bottom: 12px; border-bottom: 1px solid var(--mobile-line); }
    .mobile-overview > summary { min-height: 48px; display: flex; align-items: center; gap: 8px; padding: 10px 2px; list-style: none; cursor: pointer; font-size: 14px; font-weight: 600; }
    .mobile-overview > summary::-webkit-details-marker { display: none; }
    .mobile-overview-hint { margin-left: auto; font-size: 12px; font-weight: 400; color: var(--mobile-muted); }
    .mobile-overview > summary .ic { transition: transform 160ms ease-out; }
    .mobile-overview[open] > summary .ic { transform: rotate(180deg); }
    .mobile-overview > :not(summary) { margin-top: 12px; }
    html body #bitcoin-market-panel { margin-bottom: 16px; border-radius: 14px; }
    html body .btc-market-head { padding: 14px; }
    html body .btc-market-heading { min-width: 0; }
    html body .btc-market-head { flex-wrap: wrap; gap: 12px; }
    html body .btc-market-kicker { flex-wrap: wrap; letter-spacing: .04em; }
    html body .btc-market-timer { width: 100%; min-width: 0; }
    html body .btc-market-outcomes { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    html body .btc-quick-presets button, html body .btc-quick-close { min-height: 44px; min-width: 44px; }
    html body .btc-quick-input-wrap input { font-size: 16px; min-height: 48px; }
    html body .btc-market h2 { font-size: 20px; }
    html body .btc-market-chart { padding: 12px 14px; }
    html body .btc-market-trade { padding: 14px; }
    html body .btc-chart-caption, html body .btc-market-quote-note { font-size: 12px; line-height: 1.5; }
    html body .btc-market-outcome { min-height: 72px; }

    /* Market list: readable questions, two distinct outcomes, quieter metadata. */
    html body #view-list > .card { padding: 0; border: 0; background: transparent; box-shadow: none; }
    html body #view-list .card-header { padding: 0 0 12px !important; gap: 10px; border-radius: 0 !important; }
    html body #view-list .card-header h3 { font-size: 18px !important; letter-spacing: -.02em; }
    html body .header-filters { gap: 8px !important; flex-wrap: wrap !important; padding: 0; }
    html body .header-filters .btn-mini { min-height: 44px; padding: 8px 10px !important; background: var(--mobile-surface) !important; border: 1px solid var(--mobile-line); border-radius: 10px; font-size: 12px; color: var(--mobile-muted); }
    html body .header-filters > [data-i18n="liveData"] { margin-left: auto; font-size: 11px !important; }
    html body #event-list { margin-top: 0 !important; gap: 12px !important; }
    html body :is(.ev-card, .event-item.rec-card) { padding: 16px; gap: 12px; border: 1px solid var(--mobile-line); border-radius: 14px; background: var(--mobile-surface); box-shadow: none; }
    html body :is(.ev-title, .rec-title) { font-size: 16px; line-height: 1.5; font-weight: 650; min-height: 0; -webkit-line-clamp: 3; color: var(--text-main); }
    html body :is(.ev-cat, .ev-time, .ev-vol) { font-size: 12px; color: var(--mobile-muted); font-weight: 500; }
    html body .ev-star { width: 44px; height: 44px; min-width: 44px; margin: -10px -10px -10px 0; display: inline-flex; align-items: center; justify-content: center; color: var(--mobile-muted); }
    html body .ev-star.favorited { color: var(--mobile-accent); }
    html body .ev-probbar { height: 4px; opacity: .8; }
    html body .ev-cta-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; max-height: 252px; }
    html body .market-opt-row { min-width: 0; min-height: 64px; padding: 10px !important; border-radius: 10px; background: color-mix(in srgb, var(--mobile-muted) 4%, var(--mobile-surface)); border-color: var(--mobile-line) !important; }
    html body .market-opt-row > div { min-width: 0; }
    html body .market-opt-row .ev-opt-name { font-size: 13px !important; line-height: 1.4 !important; overflow-wrap: anywhere; }
    html body .market-opt-row .ev-opt-odds { font-size: 11px !important; line-height: 1.5; color: var(--mobile-muted); }
    html body .market-opt-row .prob { font-size: 20px !important; }
    html body .market-prob-btn { min-height: 64px; border-radius: 10px; }
    html body :is(.ev-footer, .rec-footer) { color: var(--mobile-muted); font-size: 12px; }
    html body .ev-footer { padding-top: 10px; border-color: var(--mobile-line); }
    html body .past-series-toggle { min-height: 44px; }

    /* Detail and trading: persistent context, one scroll area and keyboard-safe height. */
    html body .detail-header { padding: 16px !important; background: var(--mobile-surface); border: 1px solid var(--mobile-line); box-shadow: none; border-radius: 14px !important; }
    html body #det-title { font-size: 22px !important; line-height: 1.4 !important; letter-spacing: -.02em; }
    html body #event-details-rules, html body #event-details-desc, html body .detail-storyline-entry { font-size: 15px; line-height: 1.75 !important; overflow-wrap: anywhere; }
    html body .chart-time-selector .time-btn { min-width: 44px; min-height: 36px; font-size: 12px; }
    html body .dtab { font-size: 14px; min-height: 48px; }
    html body .dtab-content .card { padding: 16px; border-radius: 14px; box-shadow: none; }
    html body #right-column, html body .app-container.is-detail #right-column {
        bottom: var(--mobile-nav-height);
        max-height: calc(var(--mobile-vh, 100dvh) - 24px);
        padding: 10px 16px 16px;
        border-radius: 18px 18px 0 0;
        background: var(--mobile-surface);
        box-shadow: 0 -8px 28px rgb(0 0 0 / .12);
        height: 76px;
        overflow: hidden;
        transform: none;
    }
    html body .app-container.is-detail #right-column.expanded { bottom: var(--mobile-keyboard-bottom, 0px); height: auto; transform: none; padding-bottom: max(16px, env(safe-area-inset-bottom)); }
    html body #trade-panel { max-height: calc(var(--mobile-vh, 100dvh) - 60px); background: transparent; }
    html body .trade-header-mobile { flex: 0 0 auto; min-height: 44px; margin-bottom: 8px !important; gap: 8px; }
    html body .trade-header-mobile h3 { font-size: 17px; }
    .mobile-trade-indicator { display: inline-flex; align-items: center; min-height: 44px; margin-left: auto; font-size: 12px; font-weight: 600; color: var(--mobile-accent); }
    html body .bs-handle { margin-bottom: 8px; }
    html body #trade-action-area, html body #poly-bridge-panel { min-height: 0; flex: 1 1 auto; padding-bottom: 12px; scroll-padding-bottom: 20px; }
    html body #right-column:not(.expanded) :is(#trade-action-area, #poly-bridge-panel) { visibility: hidden; }
    html body :is(#trade-action-area, #poly-bridge-panel) :is(input, select) { min-height: 48px; font-size: 16px !important; }
    html body :is(#trade-action-area, #poly-bridge-panel) .submit-btn { min-height: 50px; font-size: 16px !important; border-radius: 12px; }
    html body :is(#trade-action-area, #poly-bridge-panel) :is(.pct-btn-new, .btn-mini) { min-height: 44px; }
    html body .side-btn-custom { min-height: 52px; min-width: 0; gap: 8px; }
    html body .side-btn-custom .s-name { overflow-wrap: anywhere; }
    html body #dynamic-side-buttons { flex-shrink: 0; }
    html body #bs-overlay { background: rgb(6 12 20 / .5); backdrop-filter: none; }

    /* Sheets: one viewport bound, accessible close controls, no clipped wallet forms. */
    html body .modal-overlay { box-sizing: border-box; padding: 12px 12px max(12px, env(safe-area-inset-bottom)); align-items: center; overflow: auto; overscroll-behavior: contain; }
    html body .modal-overlay > .modal-content, html body #comment-modal-wrapper > .modal-content {
        box-sizing: border-box;
        width: 100% !important;
        max-width: 560px;
        min-width: 0;
        max-height: calc(var(--mobile-vh, 100dvh) - 24px) !important;
        padding: 20px !important;
        border-radius: 18px !important;
        overflow-y: auto;
        overscroll-behavior: contain;
        -webkit-overflow-scrolling: touch;
        scroll-padding-block: 20px;
    }
    html body .modal-header { gap: 12px; flex-shrink: 0; margin-bottom: 16px !important; padding-bottom: 12px !important; }
    html body .modal-header h3 { min-width: 0; font-size: 18px; line-height: 1.4; }
    html body .close-btn { width: 44px; height: 44px; min-width: 44px; min-height: 44px; display: inline-flex; justify-content: center; align-items: center; padding: 0 !important; border-radius: 10px; font-size: 26px; line-height: 1; }
    html body .modal-content :is(input:not([type="checkbox"]):not([type="radio"]), select, textarea) { box-sizing: border-box; min-height: 48px; max-width: 100%; font-size: 16px !important; border-radius: 10px; }
    html body .modal-content :is(.submit-btn, .btn-connect, .btn-mini, .wallet-menu-item) { min-height: 44px; }
    html body .lucky-max-btn { min-width: 52px; min-height: 44px; }
    html body #withdraw-modal :is(.back-nav, a[data-i18n="lucky.viewWithdrawHistory"]) { display: inline-flex; align-items: center; min-height: 44px; }
    html body .pf-bal-row, html body .pf-bal-locked { gap: 12px; flex-wrap: wrap; }
    html body .pf-bal-val { overflow-wrap: anywhere; }
    html body #wallet-menu { position: fixed; top: calc(env(safe-area-inset-top) + 66px); left: 12px; right: 12px; width: auto; max-width: none; max-height: calc(var(--mobile-vh, 100dvh) - 148px); overflow-y: auto; border-radius: 14px; background: var(--mobile-surface); border: 1px solid var(--mobile-line); }
    html body .wallet-menu-item { min-height: 48px; padding: 12px 16px; font-size: 15px; color: var(--text-main); }
    html body #side-menu-content { max-height: var(--mobile-vh, 100dvh); }
    html body #side-menu-content :is(button, .side-lang-btn) { min-height: 44px; min-width: 44px; }
    html body #payout-popover > .modal-content { height: min(88dvh, 760px); padding: 20px 16px !important; overflow: hidden; }
    html body #portfolio-content { min-height: 0; padding-right: 0 !important; font-size: 15px !important; overscroll-behavior: contain; }
    html body .portfolio-tabs { gap: 20px !important; padding-bottom: 0 !important; margin-bottom: 16px !important; scroll-snap-type: x proximity; }
    html body .portfolio-tabs .ptab { min-height: 48px; flex-shrink: 0; display: inline-flex; align-items: center; font-size: 14px !important; font-weight: 600; scroll-snap-align: start; color: var(--mobile-muted); }
    html body .portfolio-tabs .ptab.active { color: var(--mobile-accent); }
    html body .portfolio-tabs .ptab.active::after { bottom: 0; background: var(--mobile-accent); }
    html body .pf-filter-row { padding: 0; gap: 8px; }
    html body .pf-select { min-width: 0; min-height: 44px; flex: 1 1 0; padding: 8px; background: var(--mobile-surface); font-size: 14px !important; }
    html body .pf-h-row { display: grid; grid-template-columns: minmax(0, 1fr); align-items: start; gap: 10px; padding: 16px 0; border-radius: 0; border-color: var(--mobile-line); }
    html body .pf-h-row > * { min-width: 0; }
    html body .pf-h-title { font-size: 15px; line-height: 1.5; overflow-wrap: anywhere; }
    html body .pf-h-side, html body .pf-h-detail { font-size: 12px; line-height: 1.6; color: var(--mobile-muted); }
    html body .pf-h-row > .pf-right { text-align: left; }
    html body .pf-h-row .pf-right > .pf-right { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; text-align: left; }
    html body .pf-h-value { font-size: 18px; }
    html body .pf-h-pnl { font-size: 14px; }
    html body .pf-range-row { gap: 8px; padding-top: 0; }
    html body .pf-range-btn { min-height: 44px; flex: 1; padding: 8px; font-size: 13px; }
    html body .pf-pnl-value { font-size: 32px; letter-spacing: -.02em; }
    html body .pf-pnl-label { font-size: 14px; color: var(--mobile-muted); }
    html body .pf-hist-list { max-height: none; overflow: visible; padding: 0; }
    html body .pf-rec { gap: 12px; padding: 14px 0; background: transparent; border: 0; border-bottom: 1px solid var(--mobile-line); border-radius: 0; }
    html body .pf-rec-l { flex: 1; min-width: 0; max-width: none; }
    html body .pf-rec-title { font-size: 14px; white-space: normal; line-height: 1.5; }
    html body .pf-rec-time { font-size: 12px; }
    html body .pf-rec-amt { flex-shrink: 0; font-size: 16px; }
    html body .pf-fav-grid { grid-template-columns: minmax(0, 1fr); }
    html body .pf-empty { padding: 32px 16px; color: var(--mobile-muted); line-height: 1.7; }
    html body #ref-modal-wrapper .mc-stat { padding: 12px 8px; }
    html body #ref-modal-wrapper .mc-stat-label { font-size: 12px; }
    html body #ref-modal-wrapper .mc-stat-value { font-size: 20px; }
    html body #ref-modal-wrapper :is(.mc-insights-title, .mc-comm-head) { font-size: 16px; }
    html body #ref-modal-wrapper .mc-community { grid-template-columns: minmax(0, 1fr) !important; }
    html body #ref-modal-wrapper .mc-badge-grid { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
    html body #ref-modal-wrapper .lucky-ref-link { min-height: 44px; font-size: 14px !important; }
    html body #comment-input { min-width: 0; font-size: 16px !important; }
    html body #dtab-comments .submit-btn { padding: 10px 14px !important; min-height: 44px; }
    html body .wallet-list { max-height: none !important; }
    html body .wallet-coin-header { flex-wrap: wrap; gap: 4px; }
    html body #toast-container { left: 12px; right: 12px; top: max(16px, env(safe-area-inset-top)); width: auto; }
    html body #toast-container .toast { max-width: 100%; font-size: 14px; }
}

@media (max-width: 359px) {
    html body { padding-inline: 10px; }
    html body .logo-svg { max-width: 84px !important; }
    html body .top-nav-menu { gap: 14px; }
    html body .market-opt-row { flex-direction: column; align-items: flex-start; gap: 6px; }
    html body .header-filters > [data-i18n="liveData"] { width: 100%; order: 4; text-align: right; }
    html body .modal-overlay > .modal-content { padding: 16px !important; }
}
@media (max-width: 768px) and (max-height: 500px) {
    html body .header { position: relative; }
    html body .modal-overlay { align-items: flex-start; }
    html body #right-column.expanded { max-height: calc(var(--mobile-vh, 100dvh) - 8px); }
    html body #trade-panel { max-height: calc(var(--mobile-vh, 100dvh) - 42px); }
}
@media (prefers-reduced-motion: reduce) {
    .mobile-overview > summary .ic { transition: none; }
}
