:root {
    color-scheme: dark;
    --bg: #0b121d;
    --surface: #111d2a;
    --surface-container: #172638;
    --surface-high: #20334a;
    --card: #142334;
    --card-hover: #192b40;
    --border: #2a4059;
    --border-soft: rgba(171, 207, 240, .15);
    --text: #f3f7fc;
    --text2: #a9bbce;
    --muted: #72889f;
    --accent: #7fc0ff;
    --accent-strong: #479de9;
    --accent-pressed: #add9ff;
    --on-accent: #061d33;
    --success: #8ed6b0;
    --danger: #ffb4ab;
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
    --telegram-top-inset: max(env(safe-area-inset-top, 0px), var(--tg-safe-area-inset-top, 0px), var(--tg-content-safe-area-inset-top, 0px));
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { min-height: 100%; background: var(--bg); }
body { min-height: 100dvh; overflow-x: hidden; color: var(--text); background: var(--bg); font-family: var(--font); -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; }
button, select, input { font: inherit; }
button, a, select { -webkit-tap-highlight-color: transparent; }

/* Older Telegram clients may not expose the content-safe-area variable. */
.telegram-webapp { --telegram-top-inset: max(env(safe-area-inset-top, 0px), var(--tg-safe-area-inset-top, 0px), var(--tg-content-safe-area-inset-top, 48px)); }

.app { width: min(1280px, 100%); margin: 0 auto; padding: max(10px, calc(var(--telegram-top-inset) + 10px)) max(16px, env(safe-area-inset-right)) max(40px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); }
.app-header { position: sticky; top: max(8px, var(--telegram-top-inset)); z-index: 200; display: grid; grid-template-columns: max-content minmax(0, 1fr); align-items: center; gap: 10px; min-height: 60px; margin-bottom: 12px; padding: 6px; border: 1px solid var(--border-soft); border-radius: 14px; background: var(--surface); box-shadow: 0 5px 16px rgba(0, 0, 0, .2); }
.language-switcher { display: inline-flex; align-items: center; gap: 2px; min-width: 0; min-height: 42px; padding: 3px; border: 1px solid transparent; border-radius: 10px; background: var(--surface-high); box-shadow: none; }
.language-switcher-label { padding: 0 5px 0 7px; color: var(--text2); font-size: 12px; font-weight: 650; }
.language-button { min-height: 34px; padding: 0 9px; border: 0; border-radius: 9px; color: var(--text2); background: transparent; cursor: pointer; font-size: 12px; font-weight: 700; transition: color .18s ease, background-color .18s ease, opacity .18s ease; }
.language-button:hover { color: var(--text); background: rgba(157, 204, 255, .1); }
.language-button.active { color: var(--on-accent); background: var(--accent); }
.language-button:disabled { cursor: wait; opacity: .6; }

.user-balance { display: flex; align-items: center; justify-self: end; gap: 10px; width: max-content; max-width: 100%; min-height: 42px; padding: 3px 7px 3px 4px; border: 1px solid transparent; border-radius: 10px; background: transparent; box-shadow: none; }
.user-avatar { width: 38px; height: 38px; flex: none; border: 1px solid rgba(210, 231, 250, .24); border-radius: 12px; object-fit: cover; }
.user-avatar-fallback { display: flex; align-items: center; justify-content: center; color: var(--on-accent); background: var(--accent); font-size: 16px; font-weight: 800; }
.user-avatar-fallback[hidden] { display: none; }
.user-summary { min-width: 0; line-height: 1.15; }
.user-name { max-width: 220px; overflow: hidden; color: var(--text); font-size: 13px; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.balance-value { margin-top: 5px; color: var(--accent); font-size: 14px; font-weight: 750; }

.tabs-bar { position: sticky; top: calc(var(--telegram-top-inset) + 74px); z-index: 100; display: flex; gap: 2px; margin-bottom: 14px; padding: 4px; overflow: hidden; border: 1px solid var(--border-soft); border-radius: 14px; background: var(--surface); box-shadow: 0 5px 16px rgba(0, 0, 0, .2); }
.tab { position: relative; z-index: 1; flex: 1; min-height: 40px; padding: 10px 6px; border: 0; border-radius: 9px; color: var(--text2); background: transparent; cursor: pointer; font-size: 13px; font-weight: 650; text-align: center; transition: color .18s ease, background-color .18s ease; user-select: none; }
.tab.active { color: var(--on-accent); }
.tab-indicator { position: absolute; top: 4px; bottom: 4px; z-index: 0; height: auto; border-radius: 10px; background: var(--accent); box-shadow: none; transition: left .22s ease, width .22s ease; }

.page { display: none; }
.page.active { display: block; }
.filters-row { position: relative; z-index: 40; display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; padding: 0 0 12px; }
.filters-row:has(> :only-child) { grid-template-columns: 1fr; }
.filters-row:has(.custom-select.open) { z-index: 600; }
.filter-select { width: 100%; min-height: 42px; padding: 10px 34px 10px 12px; border: 1px solid var(--border); border-radius: 10px; outline: 0; color: var(--text); background-color: var(--surface-container); background-image: url("data:image/svg+xml,%3Csvg width='12' height='8' viewBox='0 0 12 8' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1.5L6 6.5L11 1.5' stroke='%23a9bbce' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E"); background-position: right 12px center; background-repeat: no-repeat; cursor: pointer; font-size: 13px; -webkit-appearance: none; appearance: none; }
.filter-select:focus { border-color: var(--accent-strong); box-shadow: 0 0 0 3px rgba(100, 181, 246, .16); }
.filter-select option { color: var(--text); background: var(--surface); }

.grid { position: relative; z-index: 1; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); grid-auto-rows: 1fr; gap: 12px; align-items: stretch; }
.card { display: flex; min-width: 0; min-height: 352px; overflow: hidden; flex-direction: column; border: 1px solid var(--border-soft); border-radius: 12px; background: var(--card); box-shadow: 0 5px 14px rgba(0, 0, 0, .16); transition: transform .18s ease, border-color .18s ease, background-color .18s ease, box-shadow .18s ease; }
.card:hover { border-color: rgba(127, 192, 255, .44); background: var(--card-hover); box-shadow: 0 9px 22px rgba(0, 0, 0, .24); transform: translateY(-2px); }
.card-visual { display: grid; height: 124px; flex: none; place-items: center; padding: 14px; border-bottom: 1px solid rgba(171, 207, 240, .09); background: #102236; }
.gift-img, .nft-img { width: 90px; height: 90px; object-fit: contain; }
.gift-fallback, .nft-fallback { color: var(--accent); font-size: 48px; font-weight: 700; line-height: 1; }
.number-badge { margin: 10px 10px 5px; padding: 7px 9px; overflow: hidden; border: 1px solid rgba(6, 29, 51, .14); border-radius: 8px; color: var(--on-accent); font-size: 12px; font-weight: 750; text-align: center; text-overflow: ellipsis; white-space: nowrap; }
.card-subtitle, .number-raw { padding: 0 10px 4px; overflow: hidden; color: var(--text2); font-size: 10px; text-align: center; text-overflow: ellipsis; white-space: nowrap; }
.number-raw { padding-bottom: 7px; letter-spacing: .06em; }
.username-display { padding: 2px 10px 7px; overflow: hidden; color: var(--text); font-size: 13px; font-weight: 750; text-align: center; text-overflow: ellipsis; white-space: nowrap; }
.card-body { display: flex; min-height: 0; flex: 1; flex-direction: column; padding: 0 10px 11px; }
.card-title { min-height: 34px; margin: 9px 0 7px; overflow: hidden; color: var(--text); font-size: 13px; font-weight: 700; line-height: 1.3; }
.price-table { min-height: 62px; margin-bottom: 7px; }
.price-row { display: flex; justify-content: space-between; padding: 2px 0; color: var(--text2); font-size: 11px; }
.price-row.accent span:last-child { color: var(--accent); font-weight: 650; }
.price-box { min-height: 60px; margin: 0 0 8px; padding: 8px 0; border: 1px solid rgba(127, 192, 255, .12); border-radius: 9px; background: #0f1d2c; text-align: center; }
.price-label { margin-bottom: 3px; color: var(--muted); font-size: 10px; letter-spacing: .08em; }
.price-value { color: var(--accent); font-size: 18px; font-weight: 750; }
.card-meta { display: flex; justify-content: space-between; min-height: 16px; margin: 0 0 10px; color: var(--text2); font-size: 10px; }

.btn-rent { display: flex; min-height: 39px; align-items: center; justify-content: center; gap: 7px; margin-top: auto; padding: 9px 10px; border: 0; border-radius: 9px; color: var(--on-accent); background: var(--accent); box-shadow: none; font-size: 11px; font-weight: 800; letter-spacing: .06em; text-align: center; text-decoration: none; transition: background-color .18s ease, transform .18s ease, opacity .18s ease; }
.btn-rent:hover { background: var(--accent-pressed); transform: translateY(-1px); }
.btn-rent:active { background: var(--accent-strong); transform: translateY(0); }
.btn-rent.is-disabled { cursor: not-allowed; filter: grayscale(.25); opacity: .42; }
.btn-rent.is-disabled:hover { transform: none; }
.btn-arrow { font-size: 16px; line-height: 1; transition: transform .18s ease; }
.btn-rent:hover .btn-arrow { transform: translate(2px, -2px); }

.btn-more { display: block; width: 100%; margin-top: 16px; padding: 12px; border: 1px solid var(--accent-strong); border-radius: 10px; color: var(--accent); background: transparent; cursor: pointer; font-size: 13px; font-weight: 700; transition: background-color .18s ease, border-color .18s ease; }
.btn-more:hover { border-color: var(--accent); background: rgba(100, 181, 246, .1); }

.username-tools { position: relative; z-index: 40; margin-bottom: 12px; padding: 10px; overflow: visible; border: 1px solid var(--border-soft); border-radius: 12px; background: var(--surface); }
.username-tools:has(.custom-select.open) { z-index: 600; }
.search-box { display: flex; height: 44px; align-items: center; gap: 10px; padding: 0 13px; border: 1px solid var(--border); border-radius: 11px; background: #111d2a; }
.search-box:focus-within { border-color: var(--accent-strong); box-shadow: 0 0 0 3px rgba(100, 181, 246, .14); }
.search-icon { position: relative; width: 15px; height: 15px; flex: none; border: 2px solid var(--text2); border-radius: 50%; }
.search-icon::after { position: absolute; right: -5px; bottom: -2px; width: 6px; height: 2px; border-radius: 2px; background: var(--text2); content: ""; transform: rotate(45deg); }
.search-box input { width: 100%; border: 0; outline: 0; color: var(--text); background: transparent; font-size: 14px; }
.search-box input::placeholder { color: var(--muted); }
.username-filters { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }

.custom-select { position: relative; min-width: 0; overflow: visible; }
.custom-select > select { position: absolute !important; width: 1px !important; height: 1px !important; opacity: 0 !important; pointer-events: none !important; }
.custom-select-trigger { position: relative; width: 100%; min-height: 42px; padding: 10px 34px 10px 12px; overflow: hidden; border: 1px solid var(--border); border-radius: 12px; outline: 0; color: var(--text); background: var(--surface-container); cursor: pointer; font-size: 13px; text-align: left; text-overflow: ellipsis; white-space: nowrap; }
.custom-select-trigger::after { position: absolute; top: 15px; right: 14px; width: 7px; height: 7px; border-right: 2px solid var(--text2); border-bottom: 2px solid var(--text2); content: ""; transform: rotate(45deg); transition: transform .18s ease, top .18s ease; }
.custom-select.open { z-index: 700; }
.custom-select.open .custom-select-trigger { border-color: var(--accent-strong); box-shadow: 0 0 0 3px rgba(100, 181, 246, .14); }
.custom-select.open .custom-select-trigger::after { top: 19px; transform: rotate(225deg); }
.custom-select-menu { position: absolute; top: calc(100% + 6px); left: 0; right: 0; z-index: 800; display: none; max-height: min(300px, 46vh); overflow-y: auto; padding: 5px; border: 1px solid var(--border); border-radius: 12px; background: #152536; box-shadow: 0 12px 28px rgba(0, 0, 0, .36); }
.custom-select.open .custom-select-menu { display: block; animation: select-in .14s ease-out; }
.custom-select-option { display: block; width: 100%; padding: 10px 11px; border: 0; border-radius: 8px; color: var(--text2); background: transparent; cursor: pointer; font-size: 13px; text-align: left; }
.custom-select-option:hover { color: var(--text); background: rgba(157, 204, 255, .1); }
.custom-select-option.selected { color: var(--on-accent); background: var(--accent); font-weight: 650; }

.loading, .empty { grid-column: 1 / -1; padding: 42px 20px; color: var(--text2); font-size: 14px; text-align: center; }
.app-toast { position: fixed; bottom: max(20px, env(safe-area-inset-bottom)); left: 50%; z-index: 1000; width: max-content; max-width: calc(100vw - 32px); padding: 11px 15px; border: 1px solid var(--border); border-radius: 10px; color: var(--text); background: var(--surface-high); box-shadow: 0 8px 22px rgba(0, 0, 0, .3); font-size: 12px; opacity: 0; pointer-events: none; text-align: center; transform: translate(-50%, 10px); transition: opacity .18s ease, transform .18s ease; }
.app-toast.visible { opacity: 1; transform: translate(-50%, 0); }

.btn-rent:focus-visible, .btn-more:focus-visible, .tab:focus-visible, .filter-select:focus-visible, .custom-select-trigger:focus-visible, .language-button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
@keyframes select-in { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: translateY(0); } }

@media (max-width: 1120px) {
    .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 760px) {
    .app { padding-top: max(18px, calc(var(--telegram-top-inset) + 14px)); }
    .app-header { position: relative; top: auto; gap: 6px; min-height: 44px; margin-bottom: 10px; padding: 4px; border-radius: 12px; }
    .language-switcher { min-height: 40px; padding: 3px; border-radius: 12px; }
    .language-switcher-label { display: none; }
    .language-button { min-height: 34px; padding: 0 8px; border-radius: 8px; font-size: 11px; }
    .user-balance { gap: 7px; min-height: 40px; padding: 3px 5px 3px 3px; border-radius: 9px; }
    .user-avatar { width: 32px; height: 32px; border-radius: 9px; }
    .user-name { max-width: 132px; font-size: 12px; }
    .balance-value { margin-top: 3px; font-size: 13px; }
    .tabs-bar { position: relative; top: auto; gap: 0; margin-bottom: 10px; padding: 3px; border-radius: 12px; box-shadow: none; }
    .tab { min-height: 38px; padding: 7px 3px; border-radius: 8px; font-size: 12px; line-height: 1.15; white-space: nowrap; }
    .tab-indicator { top: 3px; bottom: 3px; border-radius: 8px; }
    .grid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
    .filters-row { grid-template-columns: 1fr; }
    .card { min-height: 210px; border-radius: 9px; }
    .card-visual { height: 76px; min-height: 0; padding: 8px; }
    .gift-img, .nft-img { width: 54px; height: 54px; }
    .gift-fallback, .nft-fallback { font-size: 30px; }
    .number-badge { margin: 6px 5px 2px; padding: 5px 4px; border-radius: 6px; font-size: 9px; }
    .card-subtitle, .number-raw, .username-display { display: none; }
    .card-body { padding: 0 6px 6px; }
    .card-title { min-height: 27px; margin: 6px 0 4px; font-size: 10px; line-height: 1.3; }
    .price-table { min-height: 21px; margin-bottom: 4px; }
    .price-row { padding: 1px 0; font-size: 9px; }
    .price-table .price-row:not(:first-child) { display: none; }
    .price-box { min-height: 34px; margin-bottom: 4px; padding: 5px 2px; border-radius: 6px; }
    .price-label { display: none; }
    .price-value { font-size: 12px; }
    .card-meta { display: none; }
    .btn-rent { min-height: 31px; gap: 0; padding: 6px; border-radius: 7px; font-size: 0; }
    .btn-arrow { font-size: 15px; }
}

@media (max-width: 420px) {
    .app { padding-right: 10px; padding-left: 10px; }
    .user-name { max-width: min(108px, 100%); }
    .username-filters { grid-template-columns: 1fr; }
}

@media (max-width: 360px) {
    .language-switcher { gap: 1px; }
    .language-button { padding: 0 6px; }
    .user-balance { gap: 6px; padding-right: 7px; }
    .user-name { max-width: 78px; }
    .tab { font-size: 11px; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; }
}

@supports not ((backdrop-filter: blur(2px)) or (-webkit-backdrop-filter: blur(2px))) {
    .card, .tabs-bar, .username-tools, .user-balance { background: var(--surface); }
}

[data-mirror] .app-header {
    grid-template-columns: minmax(0, 1fr) auto;
    padding-inline: 10px;
    background: linear-gradient(110deg, var(--surface-high), var(--surface) 64%);
}
[data-mirror] .language-switcher { grid-column: 2; }
.store-brand { display: flex; align-items: center; gap: 9px; min-width: 0; }
.store-brand > div:last-child { min-width: 0; }
.store-brand h1, .store-brand a { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.store-brand h1 { font-size: clamp(14px, 2.5vw, 18px); line-height: 1.2; }
.store-brand a { color: var(--text2); font-size: 12px; text-decoration: none; }
.store-brand a:hover { color: var(--accent); text-decoration: underline; }
.store-brand-initial {
    display: grid;
    place-items: center;
    flex: 0 0 36px;
    height: 36px;
    border: 1px solid var(--border-soft);
    border-radius: 11px;
    background: var(--accent);
    color: var(--on-accent);
    font-weight: 750;
}
