/*
 * Telegram Mini App + mobile shell for «Счастливый рейс»
 * Loaded after style.css. Keeps night garage / LiAZ palette.
 * Does not alter game rules — layout and touch only.
 */

:root {
    --tg-safe-top: 0px;
    --tg-safe-right: 0px;
    --tg-safe-bottom: 0px;
    --tg-safe-left: 0px;
    --tg-content-safe-top: 0px;
    --tg-content-safe-right: 0px;
    --tg-content-safe-bottom: 0px;
    --tg-content-safe-left: 0px;
    --app-height: 100dvh;
    --dock-h: 74px;
    --touch-min: 44px;
    --motion: 0.22s;
}

html {
    height: 100%;
    overflow-x: hidden;
}

body {
    min-height: var(--app-height);
    min-height: 100dvh;
    overflow-x: hidden;
    overscroll-behavior-y: contain;
    padding-top: max(env(safe-area-inset-top, 0px), var(--tg-safe-top), var(--tg-content-safe-top));
    padding-right: max(env(safe-area-inset-right, 0px), var(--tg-safe-right), var(--tg-content-safe-right));
    padding-left: max(env(safe-area-inset-left, 0px), var(--tg-safe-left), var(--tg-content-safe-left));
}

body.is-telegram {
    /* Telegram already paints chrome; keep asphalt */
    background: var(--asphalt);
}

.app {
    min-height: calc(var(--app-height) - max(env(safe-area-inset-top, 0px), var(--tg-safe-top), var(--tg-content-safe-top)));
}

/* Smooth, moderate transitions for interactive chrome */
.btn,
.stop,
.auth-link,
.auth-chip,
.purse,
.ride-select-item,
.chip-radio span,
.notice {
    transition:
        background-color var(--motion) var(--ease-out),
        color var(--motion) var(--ease-out),
        transform var(--motion) var(--ease-snap),
        opacity var(--motion) var(--ease-out),
        box-shadow var(--motion) var(--ease-out);
}

.btn:active:not(:disabled),
.stop:active,
.purse:active,
.chip-radio:active span {
    transform: scale(0.97);
}

.buy-btn:disabled,
.btn:disabled,
button:disabled {
    cursor: wait;
    opacity: 0.65;
    pointer-events: none;
}

/* Larger tap targets without changing desktop density too much */
@media (max-width: 900px) {
    .btn {
        min-height: var(--touch-min);
        padding-left: 16px;
        padding-right: 16px;
    }

    .btn--sm {
        min-height: 40px;
    }

    .auth-form input[type="email"],
    .auth-form input[type="password"],
    .auth-form input[type="text"],
    .auth-form input[type="number"],
    .deposit-form input,
    input[type="email"],
    input[type="password"],
    input[type="text"],
    input[type="number"] {
        min-height: var(--touch-min);
        font-size: 16px; /* prevent iOS zoom */
    }

    .app {
        grid-template-columns: 1fr;
        gap: 10px;
        padding:
            8px
            10px
            calc(var(--dock-h) + 14px + max(env(safe-area-inset-bottom, 0px), var(--tg-safe-bottom), var(--tg-content-safe-bottom)));
        width: 100%;
        max-width: 100vw;
        overflow-x: hidden;
    }

    .mobilebar {
        display: flex;
        position: sticky;
        top: 0;
        z-index: 40;
        align-items: center;
        justify-content: space-between;
        gap: 10px;
        padding: 8px 4px;
        margin: 0 -2px;
        background: linear-gradient(180deg, var(--asphalt) 70%, transparent);
        backdrop-filter: blur(0); /* keep ink look; no glass casino */
    }

    .mobilebar .brand-name {
        max-width: 46vw;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        line-height: 1.15;
    }

    .mobilebar-right {
        flex-shrink: 0;
        gap: 8px;
    }

    .purse--compact {
        min-height: 40px;
    }

    /* Bottom dock: route only — auth stays in mobilebar */
    .rail {
        position: fixed;
        top: auto;
        left: max(8px, env(safe-area-inset-left, 0px), var(--tg-safe-left));
        right: max(8px, env(safe-area-inset-right, 0px), var(--tg-safe-right));
        bottom: max(8px, env(safe-area-inset-bottom, 0px), var(--tg-safe-bottom), var(--tg-content-safe-bottom));
        z-index: 60;
        height: auto;
        min-height: 0;
        max-height: none;
        padding: 6px;
        border-radius: 18px;
        box-shadow: 0 12px 32px rgba(0, 0, 0, 0.55);
        background: var(--depot);
        pointer-events: auto;
    }

    .rail .brand,
    .rail .purse,
    .rail-auth {
        display: none !important;
    }

    .route {
        flex-direction: row;
        justify-content: space-between;
        align-items: stretch;
        gap: 2px;
        margin: 0;
    }

    .route::before {
        display: none;
    }

    .stop {
        flex: 1 1 0;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        gap: 3px;
        min-width: 0;
        min-height: 58px;
        padding: 6px 2px;
        font-size: 0.7rem;
        border-radius: 14px;
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
    }

    .stop-art {
        width: 36px;
        height: 36px;
        border-radius: 11px;
        pointer-events: none;
    }

    .stop-art img {
        width: 100%;
        height: 100%;
        object-fit: cover;
        pointer-events: none;
    }

    .stop-label {
        max-width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        line-height: 1.1;
        pointer-events: none;
    }

    .stop-bus {
        display: none;
    }

    .stop.is-active {
        background: var(--depot-3);
        box-shadow: inset 0 0 0 1px var(--line-2);
    }

    .stop[data-tone="yellow"].is-active { box-shadow: inset 0 0 0 2px rgba(245, 194, 27, 0.55); }
    .stop[data-tone="pink"].is-active { box-shadow: inset 0 0 0 2px rgba(242, 140, 184, 0.55); }
    .stop[data-tone="orange"].is-active { box-shadow: inset 0 0 0 2px rgba(240, 86, 46, 0.55); }
    .stop[data-tone="teal"].is-active { box-shadow: inset 0 0 0 2px rgba(34, 191, 169, 0.55); }
    .stop[data-tone="lime"].is-active { box-shadow: inset 0 0 0 2px rgba(185, 221, 74, 0.55); }

    .stage {
        padding: 0;
        width: 100%;
        max-width: 100%;
        overflow-x: hidden;
    }

    .colophon {
        padding-bottom: 8px;
        font-size: 0.78rem;
    }

    /* Notices must not block dock */
    .notice {
        position: relative;
        z-index: 5;
    }

    /* Cabin: keep 4 seat columns + aisle */
    .cabin-body,
    .split {
        grid-template-columns: 1fr;
    }

    .bus {
        width: 100%;
        max-width: 100%;
        overflow: hidden;
    }

    .bus-interior {
        overflow: hidden;
    }

    .seat-row {
        gap: 4px;
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 12px minmax(0, 1fr) minmax(0, 1fr);
    }

    .seats-grid {
        gap: 4px;
    }

    .seat {
        min-height: 52px;
        max-width: 100%;
    }

    .buy-form,
    .buy-btn {
        z-index: 3;
        touch-action: manipulation;
        -webkit-tap-highlight-color: transparent;
    }

    .seat.buying {
        pointer-events: none;
    }

    .seat .seat-number {
        pointer-events: none;
    }

    .announce-count {
        margin-left: 0;
    }

    .cabin-side {
        display: grid;
        gap: 12px;
    }

    /* Forms / wallet / history / results */
    .auth-panel,
    .deposit-panel,
    .panel {
        max-width: 100%;
    }

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

    .page-head {
        gap: 10px;
    }

    .rides-list {
        display: grid;
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .seed-value,
    .seed-hash-mini,
    .deposit-address code {
        word-break: break-all;
        overflow-wrap: anywhere;
    }

    .winner-item,
    .facts {
        max-width: 100%;
    }

    /* Avoid accidental horizontal scroll from tilted tickets */
    .ticket.ride-stub {
        transform: none !important;
    }
}

@media (max-width: 720px) {
    .seat {
        min-height: 50px;
        border-radius: 10px 10px 6px 6px;
    }

    .buy-btn .price {
        font-size: 0.8rem;
    }

    .occupied-marker {
        width: 32px;
        height: 32px;
    }

    .ticket-number {
        font-size: 0.68rem;
        letter-spacing: -0.02em;
    }

    .cabin-head {
        grid-template-columns: 1fr;
    }

    .jackpot-chip {
        justify-self: stretch;
    }
}

@media (max-width: 380px) {
    .stop-label {
        font-size: 0.62rem;
    }

    .seat-number {
        display: none;
    }

    .seat-row {
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 8px minmax(0, 1fr) minmax(0, 1fr);
        gap: 3px;
    }
}

/* Keyboard / shrinking viewport in Telegram */
body.is-telegram.is-viewport-shrunk .rail {
    opacity: 0;
    pointer-events: none;
    transform: translateY(120%);
    transition: opacity 0.18s var(--ease-out), transform 0.18s var(--ease-out);
}

body.is-telegram.is-viewport-shrunk .app {
    padding-bottom: 16px;
}

/* Prefer reduced motion */
@media (prefers-reduced-motion: reduce) {
    .btn,
    .stop,
    .auth-link,
    .auth-chip,
    .purse,
    .ride-select-item,
    .chip-radio span,
    .notice,
    .seat,
    body.is-telegram.is-viewport-shrunk .rail {
        transition: none !important;
    }

    .btn:active:not(:disabled),
    .stop:active,
    .purse:active,
    .chip-radio:active span {
        transform: none;
    }
}
