:root {
    color-scheme: light dark;
    --page: var(--tg-theme-secondary-bg-color, light-dark(#edf2f6, #151d27));
    --panel: var(--tg-theme-bg-color, light-dark(#fff, #1e2936));
    --text: var(--tg-theme-text-color, light-dark(#172339, #f4f8ff));
    --muted: var(--tg-theme-subtitle-text-color, light-dark(#4c5d75, #b3c1d4));
    --accent: var(--tg-theme-link-color, light-dark(#125aab, #87c5ff));
    --button: var(--tg-theme-button-color, light-dark(#175da9, #91c6fc));
    --button-text: var(--tg-theme-button-text-color, light-dark(#fff, #122339));
    --rule: color-mix(in srgb, var(--text) 13%, transparent);
    font-family: system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--page);
    color: var(--text);
    -webkit-tap-highlight-color: transparent;
    -webkit-text-size-adjust: 100%;
    overscroll-behavior: none;
}

*, *::before, *::after {
    box-sizing: border-box;
}

[hidden] {
    display: none !important;
}

body {
    margin: 0;
    min-width: 0;
    min-height: 100dvh;
}

.shell {
    width: min(100%, 34rem);
    margin: 0 auto;
    padding: calc(1.25rem + max(env(safe-area-inset-top, 0px), var(--tg-content-safe-area-inset-top, 0px)))
        max(1rem, env(safe-area-inset-right, 0px))
        calc(1.5rem + max(env(safe-area-inset-bottom, 0px), var(--tg-content-safe-area-inset-bottom, 0px)))
        max(1rem, env(safe-area-inset-left, 0px));
}

.brand {
    display: flex;
    align-items: center;
    gap: .65rem;
    margin-bottom: 1.125rem;
    font-size: .95rem;
    font-weight: 650;
}

.brand-mark {
    display: grid;
    width: 2rem;
    height: 2rem;
    place-items: center;
    border-radius: .6rem;
    background: var(--button);
    color: var(--button-text);
    font-size: .72rem;
    font-weight: 800;
}

.panel, .balance {
    padding: clamp(1.125rem, 5vw, 1.6rem);
    border: 1px solid var(--rule);
    border-radius: 1.2rem;
    background: var(--panel);
}

h1, h2, p {
    margin: 0;
    overflow-wrap: anywhere;
}

h1 {
    font-size: clamp(1.45rem, 5.8vw, 1.85rem);
    line-height: 1.18;
    letter-spacing: -.025em;
}

h2 {
    font-size: 1.12rem;
    line-height: 1.35;
}

p {
    color: var(--muted);
    font-size: .95rem;
    line-height: 1.55;
}

h1 + p, h2 + p {
    margin-top: .55rem;
}

.account-overview {
    display: grid;
    gap: .9rem;
}

.mini-app-artwork {
    display: block;
    width: 100%;
    height: auto;
    border-radius: 1.2rem;
}

.balance {
    color: #fff;
    background: #143451;
    background: linear-gradient(148deg, #12304d, #1d4a68 75%, #24566d);
    border-color: #1e4662;
}

.balance p {
    margin-top: 1.35rem;
    color: #d0e2f0;
    font-size: .87rem;
}

.balance strong {
    display: block;
    font-size: clamp(1.9rem, 9vw, 2.65rem);
    letter-spacing: -.04em;
    line-height: 1.2;
    font-variant-numeric: tabular-nums;
    overflow-wrap: anywhere;
}

.balance .button {
    --button: #f9fbff;
    --button-text: #163a56;
    margin-top: 1rem;
    padding-inline: .95rem;
}

.button, .store-link, .order-link {
    touch-action: manipulation;
}

.button {
    display: inline-flex;
    min-height: 2.75rem;
    align-items: center;
    justify-content: center;
    gap: .45rem;
    padding: .65rem 1rem;
    border: 1px solid transparent;
    border-radius: .65rem;
    background: var(--button);
    color: var(--button-text);
    font: inherit;
    font-size: .9rem;
    font-weight: 680;
    line-height: 1.25;
    text-decoration: none;
    cursor: pointer;
    -webkit-user-select: none;
    user-select: none;
}

.button.secondary {
    background: transparent;
    border-color: var(--rule);
    color: var(--accent);
}

#status .button, .pairing-actions {
    margin-top: 1rem;
}

.pairing-actions, .order-actions {
    display: flex;
    flex-wrap: wrap;
    gap: .55rem;
}

.order-actions .button {
    flex: 1 1 8rem;
}

.order-actions .secondary {
    background: var(--panel);
}

#pairing-form {
    display: grid;
    gap: .55rem;
    margin-top: 1.25rem;
}

label {
    font-size: .9rem;
    font-weight: 650;
}

input {
    min-height: 3rem;
    min-width: 0;
    padding: .65rem .8rem;
    border: 1px solid var(--rule);
    border-radius: .65rem;
    background: var(--page);
    color: var(--text);
    font: inherit;
    font-size: 16px;
}

.form-message {
    color: var(--tg-theme-destructive-text-color, light-dark(#9b2437, #ff9ea9));
    font-size: .875rem;
}

.form-message:empty {
    margin-top: -.55rem;
}

#store-links {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 8.2rem), 1fr));
    gap: .55rem;
}

.store-link {
    display: grid;
    min-height: 2.75rem;
    padding: .6rem;
    place-items: center;
    border: 1px solid var(--rule);
    border-radius: .7rem;
    background: var(--panel);
    color: var(--accent);
    font-size: .88rem;
    font-weight: 650;
    text-align: center;
    text-decoration: none;
}

.account-view .back {
    margin-bottom: .8rem;
}

.ordering-services {
    display: grid;
    gap: .55rem;
    margin: 1rem 0 0;
    padding: 0;
    list-style: none;
}

.ordering-services .store-link {
    justify-items: start;
    padding-inline: .85rem;
    text-align: start;
}

.history-filters {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: .35rem;
    margin-block: 1rem .75rem;
}

.history-filters .button {
    min-width: 0;
    padding-inline: .2rem;
    font-size: .8rem;
}

.history-filters .button[aria-pressed="true"] {
    border-color: transparent;
    background: var(--button);
    color: var(--button-text);
}

#history-retry { margin-top: .55rem; }

.history-pages {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: .5rem;
    margin-top: 1rem;
    color: var(--muted);
    font-size: .83rem;
}

.history-pages .button { padding-inline: .7rem; }

.order-list {
    padding: 0;
    margin: .55rem 0 0;
    list-style: none;
}

.order-list li {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, auto);
    gap: .65rem;
    align-items: baseline;
    padding-block: .75rem;
    font-size: .93rem;
    line-height: 1.4;
    overflow-wrap: anywhere;
}

.order-list li + li {
    border-top: 1px solid var(--rule);
}

.order-list li:last-child {
    padding-bottom: 0;
}

.orders > p, .order-status {
    color: var(--muted);
    font-size: .83rem;
}

.order-status {
    max-width: 9rem;
    text-align: right;
}

.order-meta {
    display: block;
    margin-top: .24rem;
    color: var(--muted);
    font-size: .78rem;
}

.order-link {
    color: var(--accent);
    font-weight: 650;
    text-decoration-thickness: 1px;
    text-underline-offset: .18em;
}

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 3px;
}

.balance :focus-visible {
    outline-color: #fff;
}

.button:disabled {
    opacity: .65;
    cursor: wait;
}

.button:active, .store-link:active, .order-link:active {
    opacity: .72;
}

@media (max-width: 19rem) {
    .history-filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (hover: hover) and (pointer: fine) {
    .button:hover:not(:disabled), .store-link:hover, .order-link:hover {
        text-decoration: underline;
        text-underline-offset: .18em;
    }
}
