/* ==========================================================================
   Phone layout for the blackjack calculator (screens under 768px).
   Markup: #phoneApp in templates/blackjack/calculator.html
   Logic:  static/js/phone-app.js
   On wider screens #phoneApp is hidden and the desktop page is unchanged.
   Colours and fonts come from static/css/theme.css (--ap-*).
   ========================================================================== */

.pa { display: none; }

@media (max-width: 767px) {
    /* Hide the desktop page; modals (checkout, sign-in, feedback) stay. */
    .ap-app .calc-header,
    .ap-app #noticeStack,
    .ap-app #calcInstrument,
    .ap-app > footer {
        display: none !important;
    }
    .ap-app .calc-shell { padding: 0; }
    body.ap-app { overflow: hidden; }

    .pa {
        --pa-bg: #0a0f0c;
        --pa-raise: #0d1410;
        --pa-panel: #131c17;
        --pa-chip: #141d18;
        --pa-line: rgba(200, 164, 92, 0.16);
        --pa-line-strong: rgba(200, 164, 92, 0.45);
        --pa-text: var(--ap-text, #ece9e0);
        --pa-muted: var(--ap-muted, #97a39c);
        --pa-soft: #c3ccc7;
        --pa-brass: #e7cd8e;
        --pa-brass-deep: #c8a45c;
        --pa-green: #57d27f;
        --pa-red: #f08a80;
        --pa-key-h: clamp(46px, 8.6dvh, 72px);

        position: fixed;
        inset: 0;
        z-index: 20;
        display: flex;
        flex-direction: column;
        background: var(--pa-bg);
        color: var(--pa-text);
        font-family: var(--ap-font-body, 'Hanken Grotesk', system-ui, sans-serif);
        -webkit-tap-highlight-color: transparent;
    }
    .pa [hidden] { display: none !important; }
    .pa button { font-family: inherit; color: inherit; cursor: pointer; }
    .pa button:focus-visible,
    .pa a:focus-visible { outline: 2px solid var(--pa-brass); outline-offset: 2px; }

    .pa-mono { font-family: var(--ap-font-mono, 'JetBrains Mono', monospace); font-variant-numeric: tabular-nums; }
    .pa-muted { color: var(--pa-muted); }
    .pa-small { font-size: 13px; color: var(--pa-soft); }
    .pa-label {
        font-family: var(--ap-font-mono, 'JetBrains Mono', monospace);
        font-size: 11px;
        letter-spacing: 0.08em;
        text-transform: uppercase;
        color: var(--pa-muted);
    }
    .pa-label--gap { margin-top: 4px; }

    /* ---- Top bar ---- */
    .pa-top {
        flex-shrink: 0;
        height: 52px;
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 0 6px 0 16px;
        padding-top: env(safe-area-inset-top, 0px);
        border-bottom: 1px solid var(--pa-line);
    }
    .pa-shoe {
        display: flex;
        align-items: center;
        gap: 8px;
        min-height: 44px;
        padding: 0;
        background: none;
        border: 0;
        font-size: 15px;
        font-weight: 600;
    }
    .pa-shoe .pa-mono { font-size: 13px; }
    .pa-shoe svg { color: var(--pa-muted); }
    .pa-top__right { display: flex; align-items: center; gap: 2px; }
    .pa-pill {
        display: inline-flex;
        align-items: center;
        gap: 5px;
        min-height: 36px;
        padding: 0 12px;
        border-radius: 999px;
        border: 1px solid rgba(200, 164, 92, 0.55);
        background: none;
        color: var(--pa-brass) !important;
        font-size: 13px;
        font-weight: 600;
        text-decoration: none;
        white-space: nowrap;
    }
    .pa-icon-btn {
        width: 44px;
        height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
        background: none;
        border: 0;
        color: var(--pa-soft) !important;
    }

    /* ---- Live readout ---- */
    .pa-readout {
        flex-shrink: 0;
        padding: 12px 16px;
        display: flex;
        flex-direction: column;
        gap: 10px;
        background: var(--pa-raise);
        border-bottom: 1px solid var(--pa-line);
    }
    .pa-readout__main { display: flex; align-items: flex-end; justify-content: space-between; }
    .pa-readout__edge { text-align: right; }
    .pa-tc { font-size: 48px; font-weight: 700; line-height: 1; margin-top: 4px; letter-spacing: -0.02em; }
    .pa-edge { font-size: 30px; font-weight: 700; line-height: 1; margin-top: 6px; }
    .pa-edge[data-sign="pos"] { color: var(--pa-green); }
    .pa-edge[data-sign="neg"] { color: var(--pa-red); }

    .pa-bet {
        display: flex;
        align-items: center;
        gap: 12px;
        padding: 10px 12px;
        border-radius: 12px;
        background: var(--pa-panel);
        border: 1px solid rgba(200, 164, 92, 0.18);
    }
    .pa-bet__dot { flex-shrink: 0; width: 10px; height: 10px; border-radius: 50%; background: #5d6a63; }
    .pa-bet__title { font-size: 15px; font-weight: 700; }
    .pa-bet__sub { font-size: 13px; color: #b9c3bd; }
    .pa-bet[data-mood="warm"] .pa-bet__dot { background: var(--pa-brass); }
    .pa-bet[data-mood="hot"] {
        background: rgba(63, 181, 104, 0.14);
        border-color: rgba(87, 210, 127, 0.5);
    }
    .pa-bet[data-mood="hot"] .pa-bet__dot { background: var(--pa-green); box-shadow: 0 0 10px var(--pa-green); }

    .pa-meta { display: flex; justify-content: space-between; font-size: 12px; color: var(--pa-muted); }
    .pa-pen { height: 4px; border-radius: 2px; background: #1c2721; overflow: hidden; margin-top: -4px; }
    .pa-pen > div { height: 100%; width: 0; background: var(--pa-brass-deep); transition: width 0.2s ease; }

    /* On Best play, keep the count and edge; drop the rest to make room. */
    .pa[data-tab="play"] .pa-bet,
    .pa[data-tab="play"] .pa-meta,
    .pa[data-tab="play"] .pa-pen { display: none; }
    .pa[data-tab="play"] .pa-readout { padding-top: 8px; padding-bottom: 8px; }
    .pa[data-tab="play"] .pa-tc { font-size: 34px; }
    .pa[data-tab="play"] .pa-edge { font-size: 24px; }

    /* ---- Body ---- */
    .pa-body {
        flex: 1;
        min-height: 0;
        overflow-y: auto;
        overscroll-behavior: contain;
        display: flex;
        flex-direction: column;
    }
    .pa-panel { flex: 1; display: flex; flex-direction: column; padding: 4px 0 12px; }

    /* ---- Cards tab ---- */
    .pa-row-head {
        min-height: 48px;
        padding: 0 12px 0 16px;
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 8px;
    }
    .pa-row-head .pa-small { margin-left: 6px; font-size: 12px; color: var(--pa-muted); }
    .pa-newshoe {
        display: inline-flex;
        align-items: center;
        gap: 6px;
        min-height: 40px;
        padding: 0 14px;
        border-radius: 999px;
        background: var(--pa-chip);
        border: 1px solid var(--pa-line-strong);
        font-size: 14px;
        font-weight: 600;
        white-space: nowrap;
    }
    .pa-newshoe.is-late { background: var(--pa-brass); border-color: var(--pa-brass); color: #1a1408 !important; }

    .pa-recent { display: flex; gap: 6px; padding: 0 16px; min-height: 44px; overflow: hidden; }
    .pa-recent__empty { align-self: center; font-size: 14px; color: var(--pa-muted); }
    .pa-mini {
        flex-shrink: 0;
        width: 34px;
        height: 44px;
        border-radius: 7px;
        display: flex;
        align-items: center;
        justify-content: center;
        font-family: var(--ap-font-mono, 'JetBrains Mono', monospace);
        font-size: 15px;
        font-weight: 700;
    }
    .pa-mini--low { background: #163d27; color: #8ee6a9; }
    .pa-mini--neutral { background: #222b26; color: var(--pa-soft); }
    .pa-mini--high { background: #4a1d19; color: #ffb3ab; }
    .pa-mini.is-latest { box-shadow: inset 0 0 0 2px currentColor; }

    .pa-spacer { flex: 1; min-height: 12px; }
    .pa-tip {
        margin: 0 16px;
        padding: 12px 14px;
        border-radius: 14px;
        background: #121c17;
        border: 1px solid rgba(200, 164, 92, 0.28);
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        align-items: center;
        gap: 4px 12px;
    }
    .pa-tip p { margin: 0; }
    .pa-tip__title { font-family: var(--ap-font-display, Fraunces, Georgia, serif); font-size: 18px; font-weight: 600; }
    .pa-tip__body { grid-column: 1 / -1; font-size: 14px; line-height: 1.4; color: var(--pa-soft); }
    .pa-tip .pa-btn { min-height: 40px; padding: 0 14px; font-size: 14px; }

    .pa-pad {
        padding: 0 12px;
        display: grid;
        grid-template-columns: repeat(5, minmax(0, 1fr));
        gap: 8px;
    }
    .pa-key {
        position: relative;
        height: var(--pa-key-h);
        border-radius: 12px;
        border: 0;
        color: #fff !important;
        font-family: var(--ap-font-mono, 'JetBrains Mono', monospace) !important;
        font-size: 26px;
        font-weight: 700;
        display: flex;
        align-items: center;
        justify-content: center;
        box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.28);
        touch-action: manipulation;
        user-select: none;
        -webkit-user-select: none;
    }
    .pa-key:active { transform: translateY(1px); filter: brightness(1.15); }
    .pa-key--low { background: #1d6a3f; }
    .pa-key--neutral { background: #27312c; }
    .pa-key--high { background: #a3352d; }
    .pa-key__tag { position: absolute; top: 6px; right: 8px; font-size: 11px; font-weight: 500; opacity: 0.75; }
    .pa-undo {
        grid-column: span 2;
        height: var(--pa-key-h);
        border-radius: 12px;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 8px;
        background: transparent;
        border: 1px solid rgba(240, 138, 128, 0.5);
        color: #ffb3ab !important;
        font-size: 16px;
        font-weight: 600;
        touch-action: manipulation;
    }
    .pa-undo:disabled { opacity: 0.4; }

    /* ---- Segmented controls and chips ---- */
    .pa-seg {
        display: grid;
        padding: 3px;
        border-radius: 10px;
        background: var(--pa-chip);
        border: 1px solid var(--pa-line);
    }
    .pa-seg--2 { grid-template-columns: repeat(2, minmax(0, 1fr)); margin: 4px 16px 0; }
    .pa-seg--2 button { min-height: 34px; }
    .pa-seg--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .pa-seg button {
        min-height: 38px;
        border-radius: 8px;
        border: 0;
        background: transparent;
        color: var(--pa-muted) !important;
        font-size: 14px;
        font-weight: 600;
    }
    .pa-seg button.is-active { background: #2a352f; color: var(--pa-text) !important; }

    .pa-chips { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; }
    .pa-chip {
        min-height: 44px;
        border-radius: 10px;
        background: var(--pa-chip);
        border: 1px solid rgba(200, 164, 92, 0.18);
        font-family: var(--ap-font-mono, 'JetBrains Mono', monospace) !important;
        font-size: 15px;
        font-weight: 700;
        touch-action: manipulation;
    }
    .pa-chip.is-active { background: var(--pa-brass); border-color: var(--pa-brass); color: #1a1408 !important; }

    /* ---- Best play: lookup ---- */
    .pa-lookup { flex: 1; display: flex; flex-direction: column; }
    .pa-answer {
        margin: 10px 16px 0;
        padding: 12px 14px;
        border-radius: 16px;
        display: flex;
        flex-direction: column;
        gap: 4px;
        border: 1px solid;
    }
    .pa-answer__word { font-family: var(--ap-font-display, Fraunces, Georgia, serif); font-size: 36px; font-weight: 600; line-height: 1.05; }
    .pa-answer[data-act="H"] { background: rgba(70, 110, 210, 0.16); border-color: rgba(120, 155, 240, 0.45); }
    .pa-answer[data-act="H"] .pa-answer__word { color: #a9c1ff; }
    .pa-answer[data-act="S"] { background: rgba(214, 69, 61, 0.14); border-color: rgba(240, 138, 128, 0.45); }
    .pa-answer[data-act="S"] .pa-answer__word { color: #ffb3ab; }
    .pa-answer[data-act="D"] { background: rgba(63, 181, 104, 0.14); border-color: rgba(87, 210, 127, 0.45); }
    .pa-answer[data-act="D"] .pa-answer__word { color: #8ee6a9; }
    .pa-answer[data-act="P"] { background: rgba(200, 164, 92, 0.16); border-color: rgba(231, 205, 142, 0.5); }
    .pa-answer[data-act="P"] .pa-answer__word { color: var(--pa-brass); }
    .pa-answer[data-act="R"] { background: rgba(150, 90, 200, 0.16); border-color: rgba(190, 140, 240, 0.45); }
    .pa-answer[data-act="R"] .pa-answer__word { color: #d7b6ff; }
    .pa-answer__dev { display: flex; align-items: flex-start; gap: 8px; font-size: 13px; line-height: 1.4; color: #dfe5e1; }
    .pa-badge {
        flex-shrink: 0;
        padding: 2px 8px;
        border-radius: 999px;
        background: var(--pa-brass);
        color: #1a1408;
        font-size: 11px;
        font-weight: 700;
        letter-spacing: 0.04em;
        text-transform: uppercase;
    }
    .pa-grow { flex: 1; min-height: 10px; }
    .pa-inputs { padding: 0 16px; display: flex; flex-direction: column; gap: 6px; }

    /* ---- Best play: chart ---- */
    .pa-chart-wrap { padding: 12px 16px 0; display: flex; flex-direction: column; gap: 10px; }
    .pa-chart {
        display: grid;
        grid-template-columns: 44px repeat(10, minmax(0, 1fr));
        gap: 2px;
        font-size: 12px;
    }
    .pa-chart__corner { font-size: 10px; color: var(--pa-muted); align-self: end; text-transform: uppercase; }
    .pa-chart__head { text-align: center; color: var(--pa-muted); padding: 4px 0; }
    .pa-chart__label { font-weight: 700; display: flex; align-items: center; letter-spacing: -0.03em; }
    .pa-cell {
        height: 28px;
        border-radius: 4px;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 13px;
        font-weight: 700;
    }
    .pa-cell--H { background: #24427f; color: #e3ebff; }
    .pa-cell--S { background: #7c2620; color: #ffe4e0; }
    .pa-cell--D { background: #1d6a3f; color: #e2ffe9; }
    .pa-cell--P { background: #6e521a; color: #fff0cc; }
    .pa-cell--R { background: #4f2a7a; color: #efe2ff; }
    .pa-cell.is-changed { box-shadow: inset 0 0 0 2px var(--pa-brass); }
    .pa-legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin: 0; font-size: 12px; color: var(--pa-soft); }
    .pa-ink-H { color: #a9c1ff; }
    .pa-ink-S { color: #ffb3ab; }
    .pa-ink-D { color: #8ee6a9; }
    .pa-ink-P { color: var(--pa-brass); }
    .pa-legend__changed { display: inline-flex; align-items: center; gap: 6px; }
    .pa-legend__changed > span { width: 12px; height: 12px; border-radius: 3px; box-shadow: inset 0 0 0 2px var(--pa-brass); }

    /* ---- Tab bar ---- */
    .pa-tabs {
        flex-shrink: 0;
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        min-height: 60px;
        padding-bottom: env(safe-area-inset-bottom, 0px);
        background: var(--pa-raise);
        border-top: 1px solid var(--pa-line);
    }
    .pa-tabs button {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 4px;
        border: 0;
        background: transparent;
        color: var(--pa-muted) !important;
        font-size: 12px;
        font-weight: 600;
        box-shadow: inset 0 2px 0 transparent;
    }
    .pa-tabs button.is-active { color: var(--pa-brass) !important; box-shadow: inset 0 2px 0 var(--pa-brass); }

    /* ---- Sheets ---- */
    .pa-sheet { position: fixed; inset: 0; z-index: 30; display: flex; flex-direction: column; justify-content: flex-end; }
    .pa-sheet__scrim { position: absolute; inset: 0; border: 0; background: rgba(3, 6, 4, 0.72); }
    .pa-sheet__panel {
        position: relative;
        max-height: 90dvh;
        overflow-y: auto;
        padding: 10px 20px calc(24px + env(safe-area-inset-bottom, 0px));
        border-radius: 20px 20px 0 0;
        background: #111a15;
        border-top: 1px solid rgba(200, 164, 92, 0.3);
        display: flex;
        flex-direction: column;
        gap: 14px;
    }
    .pa-sheet__handle { align-self: center; width: 40px; height: 4px; border-radius: 2px; background: #3a463f; }
    .pa-sheet__title { margin: 0; font-family: var(--ap-font-display, Fraunces, Georgia, serif); font-size: 26px; font-weight: 600; }
    .pa-sheet__body { margin: 0; font-size: 15px; line-height: 1.45; color: var(--pa-soft); }
    .pa-chips--decks { margin-top: -6px; }
    .pa-btn {
        min-height: 48px;
        padding: 0 18px;
        border-radius: 12px;
        font-size: 15px;
        font-weight: 700;
    }
    .pa-btn--primary { border: 0; background: var(--pa-brass); color: #1a1408 !important; }
    .pa-btn--ghost { border: 1px solid rgba(200, 164, 92, 0.3); background: none; }
    .pa-btn--block { width: 100%; min-height: 52px; }
    .pa-menu-item {
        display: flex;
        align-items: center;
        min-height: 52px;
        padding: 0 4px;
        border: 0;
        border-bottom: 1px solid var(--pa-line);
        background: none;
        color: var(--pa-text) !important;
        font-size: 16px;
        font-weight: 600;
        text-decoration: none;
        text-align: left;
    }

    /* Existing modals become bottom sheets above the phone layout. */
    #upgradeModal, #feedbackModal, #loginRequiredModal, #cardVerifyModal, #usResourcesModal {
        align-items: flex-end;
        padding: 0;
    }
    #upgradeModal > div, #feedbackModal > div, #loginRequiredModal > div, #cardVerifyModal > div, #usResourcesModal > div {
        margin: 0;
        max-height: 92dvh;
        overflow-y: auto;
        border-radius: 20px 20px 0 0;
        padding: 24px 20px calc(24px + env(safe-area-inset-bottom, 0px));
    }
    #statusMessage { top: 60px; bottom: auto; left: 16px; right: 16px; z-index: 40; }
    #statusMessage > div { max-width: none; }
}
