/* ==========================================================================
   Desktop: the wide layout (900px and up) and the phone-as-camera screens.
   Everything that changes the existing app sits inside @media (min-width: 900px), so phones and narrow windows look
   exactly as before. Colours, corners and glows come from the theme tokens (--sc-*), so equipped themes still apply.
   ========================================================================== */

/* The Scan tab's wrappers (BarcodeScanner) take no part in the phone layout */
.scan-layout,
.scan-main {
    display: contents;
}

/* ---------- The desktop's phone-camera panel and typed barcodes (only rendered on wide screens) ---------- */
.scan-side {
    display: flex;
    flex-direction: column;
    gap: 14px;
    min-width: 0;
}

.scan-phone {
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: 16px;
}

.scan-phone-head {
    display: flex;
    align-items: flex-start;
    gap: 12px;
}

.scan-phone-head > span:last-child {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.scan-phone-head strong {
    font-family: var(--sc-font-display);
    font-size: 18px;
}

.scan-phone-head small,
.scan-phone-device small {
    color: var(--sc-text-muted);
    font-size: 13px;
    line-height: 1.35;
}

.scan-phone-icon {
    display: inline-flex;
    flex-shrink: 0;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: calc(12px * var(--sc-radius-scale, 1));
    background: var(--sc-primary-soft);
    color: var(--sc-primary);
    font-size: 22px;
}

.scan-phone-start {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 46px;
}

.scan-phone-qr {
    display: grid;
    grid-template-columns: 168px minmax(0, 1fr);
    align-items: center;
    gap: 14px;
}

/* The code stays dark on white whatever the theme, so every phone camera reads it */
.scan-phone-qr-image {
    padding: 8px;
    border-radius: calc(14px * var(--sc-radius-scale, 1));
    background: #fff;
    box-shadow: 0 0 0 1px var(--sc-line-strong), 0 10px 30px rgba(var(--sc-primary-rgb), 0.25);
}

.scan-phone-qr-image svg {
    display: block;
    width: 100%;
    height: auto;
}

.scan-phone-steps {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin: 0;
    padding-left: 18px;
    color: var(--sc-text-muted);
    font-size: 13px;
    line-height: 1.35;
}

.scan-phone-steps li::marker {
    color: var(--sc-primary);
    font-weight: 800;
}

.scan-phone-steps ion-icon,
.scan-phone-device small ion-icon {
    margin-right: 3px;
    color: var(--sc-primary);
    font-size: 16px;
    vertical-align: -3px;
}

.scan-phone-device small ion-icon {
    font-size: 13px;
    vertical-align: -2px;
}

.scan-phone-qr-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.scan-phone-expiry {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--sc-text-muted);
    font-size: 13px;
    font-variant-numeric: tabular-nums;
}

.scan-phone-paired {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    border-radius: calc(14px * var(--sc-radius-scale, 1));
    background: var(--sc-primary-soft);
    box-shadow: inset 0 0 0 1px rgba(var(--sc-primary-rgb), 0.35);
}

.scan-phone-device {
    display: flex;
    flex: 1;
    flex-direction: column;
    min-width: 0;
}

.scan-phone-end {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

.scan-phone-live,
.phone-camera-live {
    flex-shrink: 0;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--sc-success, #3ddc97);
    box-shadow: 0 0 0 4px rgba(61, 220, 151, 0.2);
    animation: scan-phone-live 1.8s ease-in-out infinite;
}

@keyframes scan-phone-live {
    50% { box-shadow: 0 0 0 7px rgba(61, 220, 151, 0.05); }
}

.scan-phone-hint,
.scan-phone-error {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0;
    color: var(--sc-text-muted);
    font-size: 14px;
}

.scan-phone-error {
    color: var(--sc-danger, #ff6b6b);
}

.scan-phone-found {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.scan-phone-found-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-family: var(--sc-font-display);
    font-size: 18px;
    font-weight: 700;
}

.scan-phone-found-head > span {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--sc-primary);
}

.scan-phone-found-message {
    margin: 0;
    color: var(--sc-text-muted);
    font-size: 14px;
}

.scan-phone-nothing {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 20px;
    text-align: center;
    color: var(--sc-text-muted);
}

.scan-phone-nothing ion-icon {
    font-size: 34px;
}

/* ---------- The phone, paired as a desktop's camera (/camera) ---------- */
.phone-camera .phone-camera-body {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    min-height: 0;
    padding: 12px 16px calc(16px + var(--sc-safe-bottom));
    overflow-y: auto;
}

.phone-camera-banner {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin: 12px 16px 0;
    padding: 10px 14px;
    border-radius: var(--sc-radius-pill);
    background: var(--sc-primary-soft);
    box-shadow: inset 0 0 0 1px rgba(var(--sc-primary-rgb), 0.4);
    color: var(--sc-text);
    font-size: 14px;
    font-weight: 600;
}

.phone-camera-disconnect {
    padding: 0;
    border: none;
    background: none;
    color: var(--sc-primary);
    font-weight: 700;
    text-decoration: underline;
    text-underline-offset: 3px;
}

/* Floats over the decode and unlock reveals, which cover the whole screen */
.phone-camera-sent {
    position: fixed;
    top: calc(var(--sc-safe-top) + 14px);
    left: 50%;
    z-index: 3000;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border-radius: var(--sc-radius-pill);
    background: rgba(var(--sc-bg-rgb), 0.92);
    box-shadow: inset 0 0 0 1px rgba(61, 220, 151, 0.5), 0 8px 24px rgba(0, 0, 0, 0.4);
    color: var(--sc-success, #3ddc97);
    font-size: 14px;
    font-weight: 700;
    white-space: nowrap;
    /* translate, not transform, so the fade-in's own transform doesn't undo the centring */
    translate: -50% 0;
    pointer-events: none;
}

.phone-camera-ended {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    margin: auto 24px;
    padding: 28px 20px;
    text-align: center;
    border-radius: var(--sc-radius-lg);
    background: var(--sc-surface);
    box-shadow: inset 0 0 0 1px var(--sc-line);
}

.phone-camera-ended ion-icon {
    color: var(--sc-primary);
    font-size: 42px;
}

.phone-camera-ended strong {
    font-family: var(--sc-font-display);
    font-size: 20px;
}

.phone-camera-ended span {
    color: var(--sc-text-muted);
    line-height: 1.4;
}

/* ==========================================================================
   The wide layout
   ========================================================================== */
@media (min-width: 900px) {
    .app-shell {
        --rail-width: 216px;
        /* The tab bar is a rail at the side now, so nothing needs to leave room for it at the bottom */
        --sc-tabbar-height: 0px;
        max-width: 1200px;
    }

    .app-topbar {
        padding-left: 24px;
        padding-right: 24px;
    }

    /* ---------- The tab bar becomes a left rail ---------- */
    .app-shell > .tabs-bottom {
        flex-direction: row;
    }

    .tabs-bottom > .tabbar {
        position: relative;
        order: -1;
        z-index: 10;
        flex: 0 0 var(--rail-width);
        width: var(--rail-width);
        padding: 20px 12px;
        border-top: 0;
        border-right: 1px solid var(--sc-line);
        background: rgba(var(--sc-bg-rgb), 0.55);
    }

    .tabbar .tabs-nav {
        flex-direction: column;
        justify-content: flex-start;
        gap: 6px;
        max-width: none;
        height: auto;
        margin: 0;
    }

    .tabbar .tabs-item {
        flex: 0 0 auto;
        align-items: stretch;
    }

    .tabbar .tab-button {
        flex-direction: row;
        justify-content: flex-start;
        gap: 14px;
        height: 52px;
        padding: 0 14px;
        border-radius: calc(14px * var(--sc-radius-scale, 1));
        font-family: var(--sc-font-display);
        font-size: 16px;
        font-weight: 600;
        letter-spacing: 0.01em;
    }

    .tabbar .tab-button:hover:not(.is-disabled) {
        background: var(--sc-surface);
        color: var(--sc-text);
    }

    .tabbar .tab-button:active {
        transform: scale(0.98);
    }

    .tabbar .tab-button .tab-icon {
        justify-content: center;
        width: 30px;
    }

    .tabbar .tab-button.active {
        background: var(--sc-primary-soft);
    }

    .tabbar .tab-button.active ion-icon,
    .tabbar .tab-button.active .sk-nav-icon {
        transform: scale(1.08);
    }

    /* The active bar runs down the rail's edge of the button */
    .tabbar .tab-button::after {
        top: 50%;
        left: 0;
        width: 3px;
        height: 0;
        border-radius: 0 4px 4px 0;
        transform: translateY(-50%);
        transition: height 0.3s var(--sc-ease-spring);
    }

    .tabbar .tab-button.active::after {
        width: 3px;
        height: 26px;
    }

    /* Scan keeps its glowing round button, sitting in line with the others */
    .tabbar .tabs-item.is-primary {
        margin: 6px 0;
    }

    .tabbar .tabs-item.is-primary .tab-button {
        height: 60px;
        padding-left: 4px;
        color: var(--sc-text);
        font-weight: 700;
    }

    .tabbar .tabs-item.is-primary .tab-icon {
        width: 50px;
        height: 50px;
        margin-top: 0;
        box-shadow: 0 6px 20px rgba(var(--sc-primary-rgb), 0.45);
    }

    .tabbar .tabs-item.is-primary .tab-button.active .tab-icon {
        box-shadow: 0 0 24px rgba(var(--sc-primary-rgb), 0.75);
    }

    /* The pulse's glow layer (tabs.css), without the ring the bottom bar needs */
    .tabbar .tabs-item.is-primary .tab-icon::before {
        box-shadow: 0 6px 30px rgba(var(--sc-primary-rgb), 0.7);
    }

    .tabbar .notification-dot {
        top: -3px;
        right: -4px;
    }

    /* ---------- Screens use the width ---------- */
    .tabs-bottom > .tabs-panel {
        flex: 1 1 auto;
        min-width: 0;
    }

    .tabs-bottom > .tabs-panel > .tabs-panel-inner {
        padding: 24px 32px 40px;
    }

    /* Section switchers (All / Favorites, Friends / Trades / Mail) stay a comfortable size */
    .tabs-bottom > .tabs-panel > .tabs-panel-inner > .tabs-segmented > .tabs-nav {
        width: 100%;
        max-width: 520px;
    }

    /* Badge: the trainer card on the left, the dashboard's tiles three across beside it */
    .tabs-bottom .tabs-panel-inner:has(> .badge-hero) {
        display: grid;
        grid-template-columns: minmax(300px, 360px) minmax(0, 1fr);
        align-items: start;
        align-content: start;
        gap: 24px;
    }

    .tabs-bottom .tabs-panel-inner:has(> .badge-hero) > * {
        grid-column: 1 / -1;
    }

    .tabs-bottom .tabs-panel-inner:has(> .badge-hero) > .badge-hero {
        position: sticky;
        top: 0;
        grid-column: 1;
    }

    .tabs-bottom .tabs-panel-inner:has(> .badge-hero) > .hq-grid {
        grid-column: 2;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 14px;
        margin-top: 0;
    }

    .hq-tile {
        min-height: 132px;
        padding: 14px 16px 16px;
    }

    .hq-tile.is-wide {
        grid-column: span 2;
        min-height: 132px;
    }

    .hq-tile-label {
        font-size: 14px;
    }

    .hq-ring {
        width: 68px;
        height: 68px;
        font-size: 28px;
    }

    .hq-ring.is-art {
        width: 72px;
        height: 72px;
    }

    .hq-num {
        font-size: 32px;
    }

    .hq-pip {
        width: 52px;
        height: 52px;
        font-size: 22px;
    }

    .hq-pip.is-weekly {
        width: 58px;
        height: 58px;
        font-size: 25px;
    }

    /* Team: the roster's tiles, wider and more across, with the header on one line */
    .tm-grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
        gap: 14px;
    }

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

    .tm-tile:hover {
        transform: translateY(-3px);
    }

    .tm-tile:active {
        transform: scale(0.97);
    }

    /* Scan: the scanner, with the phone-camera panel and typed barcodes beside it */
    .scan-layout.is-wide {
        display: grid;
        grid-template-columns: minmax(0, 1fr) minmax(320px, 380px);
        align-items: start;
        align-content: start;
        gap: 24px;
    }

    .scan-layout.is-wide > .scan-main {
        display: flex;
        flex-direction: column;
        gap: 12px;
        min-width: 0;
    }

    .scan-layout.is-wide > .scan-main > .card.scan-card,
    .scan-layout.is-wide > .scan-main > .h-100 {
        max-width: 600px;
        width: 100%;
        margin: 0 auto;
    }

    .scan-layout.is-wide > .scan-main > .button {
        align-self: center;
        width: 100%;
        max-width: 600px;
    }

    .scan-layout.is-wide > .scan-side {
        position: sticky;
        top: 0;
    }

    /* Battle: the hub keeps its own phone-sized layout, centred in the screen */
    .tabs-bottom .tabs-panel-inner > .ah {
        width: 100%;
    }

    /* Social › Friends: your code and adding a friend side by side, the list below */
    .tabs-bottom .tabs-panel-inner:has(> .friend-code-card) {
        display: grid;
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
        align-items: stretch;
        align-content: start;
        column-gap: 16px;
    }

    .tabs-bottom .tabs-panel-inner:has(> .friend-code-card) > * {
        grid-column: 1 / -1;
    }

    .tabs-bottom .tabs-panel-inner:has(> .friend-code-card) > .friend-code-card {
        grid-column: 1;
        justify-content: center;
        margin-bottom: 14px;
    }

    .tabs-bottom .tabs-panel-inner:has(> .friend-code-card) > .friend-add-card {
        grid-column: 2;
        justify-content: center;
    }

    /* The Store's Bytes packs in one row */
    .title-sheet .store-packs {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }

    /* Social › Mail: gifts on the left, letters on the right */
    .mailbox:has(> .mailbox-gifts) {
        display: grid;
        grid-template-columns: minmax(0, 5fr) minmax(0, 6fr);
        align-items: start;
        align-content: start;
        gap: 14px 24px;
    }

    .mailbox:has(> .mailbox-gifts) > * {
        grid-column: 2;
    }

    .mailbox:has(> .mailbox-gifts) > .mailbox-hero {
        grid-column: 1 / -1;
    }

    .mailbox:has(> .mailbox-gifts) > .mailbox-gifts {
        grid-column: 1;
        grid-row: 2 / span 4;
    }

    /* ---------- Sheets and dialogs: larger, centred ---------- */
    .title-sheet-backdrop {
        align-items: center;
        padding: 32px;
    }

    .title-sheet {
        width: min(760px, 100%);
        max-height: min(88dvh, 920px);
        border-bottom: 1px solid var(--sc-line-strong);
        border-radius: var(--sc-radius-lg);
        animation-name: desktop-dialog-in;
    }

    .title-sheet-body {
        padding: 10px 20px 20px;
    }

    .popup-content {
        max-width: 560px;
    }

    @keyframes desktop-dialog-in {
        from {
            opacity: 0;
            transform: translateY(16px) scale(0.97);
        }
        to {
            opacity: 1;
            transform: none;
        }
    }

    /* ---------- Battles: phone width in the middle, the backdrop fills the screen ---------- */
    .mm-overlay {
        align-items: stretch;
    }

    .mm-screen {
        box-shadow: 0 0 0 1px var(--sc-line), 0 0 80px rgba(0, 0, 0, 0.45);
    }

    /* The fight itself fills a phone's width, so on a computer it gets one */
    .mm-overlay .mm-screen.bf-screen {
        max-width: 480px;
    }

    /* ---------- The paired phone's own screen, if opened on a computer ---------- */
    .phone-camera.app-shell {
        max-width: 560px;
    }
}
