* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: rgba(255, 91, 107, 0.2);
}

:root {
    color-scheme: dark;
    --bg: #0b0d12;
    --bg-elev: #111522;
    --card: #151a28;
    --border: #21283a;
    --text: #f3f4f7;
    --muted: #9aa3b2;
    --accent: #ff5b6b;
    --accent-soft: rgba(255, 91, 107, 0.12);
    --chip: #1b2132;
    --chip-border: #2b354a;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
    --nav-height: 60px;
    --tg-safe-top: 0px;
    --tg-safe-bottom: 0px;
    --safe-bottom: max(env(safe-area-inset-bottom, 0px), var(--tg-safe-bottom));
    --safe-top: max(env(safe-area-inset-top, 0px), var(--tg-safe-top));
    --page-pad: 16px;
}

html {
    -webkit-text-size-adjust: 100%;
    scroll-behavior: smooth;
}

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
    background: radial-gradient(1200px 800px at 20% -10%, #1a2130 0%, transparent 55%),
        radial-gradient(900px 600px at 100% 0%, #1b1f2b 0%, transparent 50%),
        var(--bg);
    color: var(--text);
    line-height: 1.45;
    overflow-x: hidden;
}

body.has-mobile-nav {
    padding-bottom: calc(var(--nav-height) + var(--safe-bottom) + 8px);
}

.site-header {
    padding: max(18px, var(--safe-top)) var(--page-pad) 10px;
    text-align: left;
}

.scope-bar {
    position: sticky;
    top: 0;
    z-index: 50;
    padding: 10px var(--page-pad) 12px;
    background: rgba(11, 13, 18, 0.96);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
}

/* Inside Telegram the permanent top bar (.tg-app-bar) already occupies the real
   top of the viewport — sticky elements must stick just below it, not under it. */
html.tg-webapp .scope-bar {
    top: calc(max(var(--tg-bar-height), var(--safe-top) + 34px));
}

.scope-group {
    display: flex;
    align-items: stretch;
    gap: 8px;
    width: 100%;
}

.scope-pill {
    display: flex;
    flex: 1 1 0;
    min-width: 0;
    align-items: center;
    justify-content: center;
    min-height: 38px;
    padding: 9px 8px;
    border-radius: 12px;
    background: var(--bg-elev);
    border: 1px solid var(--chip-border);
    color: var(--text);
    text-decoration: none;
    font-size: 12.5px;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
    transition: transform 0.15s ease, background 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

.scope-pill.active {
    background: linear-gradient(135deg, #ff5b6b 0%, #ff7b90 100%);
    border-color: transparent;
    color: #1a0507;
    box-shadow: 0 4px 14px rgba(255, 91, 107, 0.4);
}

.scope-pill:active {
    transform: scale(0.96);
}

.filters-collapse {
    margin: 4px var(--page-pad) 0;
}

.filters-collapse summary {
    list-style: none;
    cursor: pointer;
    padding: 8px 2px;
    font-size: 12px;
    color: var(--muted);
    font-weight: 600;
}

.filters-collapse summary::-webkit-details-marker {
    display: none;
}

.filters-collapse summary::before {
    content: "⚙ ";
}

.filters-collapse .filters {
    padding-top: 4px;
}

.site-header h1 {
    margin: 0 0 4px;
    font-size: clamp(20px, 4.5vw, 24px);
    font-weight: 700;
    letter-spacing: -0.02em;
    background: linear-gradient(135deg, #ffffff 0%, #ffb3ba 100%);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    width: fit-content;
}

.app-splash {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #000;
    opacity: 1;
    visibility: visible;
    transition: opacity 0.35s ease, visibility 0.35s ease;
}

.app-splash.is-hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.app-splash-logo {
    width: 44vw;
    max-width: 220px;
    min-width: 140px;
    border-radius: 24px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
    animation: app-splash-pulse 1.6s ease-in-out infinite;
}

@keyframes app-splash-pulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.04); opacity: 0.9; }
}

.balance-chip-row {
    padding-top: 4px;
}

.balance-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 40px;
    padding: 8px 16px;
    border-radius: 999px;
    background: linear-gradient(135deg, rgba(255, 91, 107, 0.18) 0%, rgba(255, 176, 32, 0.14) 100%);
    border: 1px solid var(--chip-border);
    color: var(--text);
    text-decoration: none;
    font-size: 14px;
    font-weight: 700;
}

.alert-banner {
    margin: 0 var(--page-pad) 14px;
    padding: 14px 16px;
    border-radius: 16px;
    font-size: 13px;
    line-height: 1.5;
}

.alert-banner strong {
    display: block;
    color: var(--text);
    font-size: 15px;
    margin-bottom: 4px;
}

.alert-success {
    background: rgba(70, 200, 130, 0.14);
    border: 1px solid rgba(70, 200, 130, 0.4);
    color: #7fe0ab;
}

.alert-error {
    background: rgba(255, 91, 107, 0.14);
    border: 1px solid rgba(255, 91, 107, 0.4);
    color: #ff8b96;
}

.empty-state {
    margin: 4px var(--page-pad) 16px;
    padding: 28px 18px;
    text-align: center;
    color: var(--muted);
    font-size: 14px;
    background: var(--card);
    border: 1px dashed var(--border);
    border-radius: 16px;
}

.site-header p {
    margin: 0;
    color: var(--muted);
    font-size: 13px;
}

.retention-notice {
    margin: 0 var(--page-pad) 12px;
    padding: 0;
    border-radius: 14px;
    border: 1px solid var(--chip-border);
    background: var(--accent-soft);
    color: var(--text);
    font-size: 13px;
    line-height: 1.45;
    overflow: hidden;
}

.retention-notice summary {
    list-style: none;
    cursor: pointer;
    padding: 12px 14px;
    font-weight: 600;
    color: #fff;
}

.retention-notice summary::-webkit-details-marker {
    display: none;
}

.retention-notice summary::after {
    content: "▾";
    float: right;
    color: var(--muted);
    transition: transform 0.15s ease;
}

.retention-notice[open] summary::after {
    transform: rotate(180deg);
}

.retention-notice-body {
    padding: 0 14px 12px;
    color: var(--muted);
}

.retention-notice-body strong {
    color: var(--text);
}

.post-expiry {
    margin: 0;
    padding: 0 16px 14px;
    color: var(--muted);
    font-size: 13px;
    line-height: 1.4;
}

.section {
    padding: 4px 0 14px;
}

.section h2 {
    margin: 14px var(--page-pad) 8px;
    font-size: 15px;
    font-weight: 700;
    letter-spacing: -0.01em;
}

.section-collapse {
    margin: 0 var(--page-pad) 12px;
    border: 1px solid var(--border);
    border-radius: 16px;
    background: var(--card);
    overflow: hidden;
}

.section-collapse-summary {
    list-style: none;
    cursor: pointer;
    padding: 14px 16px;
    font-size: 14px;
    font-weight: 700;
}

.section-collapse-summary::-webkit-details-marker {
    display: none;
}

.section-collapse-summary::after {
    content: "Показать";
    float: right;
    font-size: 13px;
    font-weight: 600;
    color: var(--accent);
}

.section-collapse[open] .section-collapse-summary::after {
    content: "Скрыть";
}

.section-collapse-body .section {
    padding-top: 0;
}

.section-collapse-body .section h2 {
    margin-top: 8px;
    font-size: 15px;
}

.tabs {
    display: flex;
    gap: 8px;
    padding: 4px var(--page-pad) 0;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}

.tabs::-webkit-scrollbar {
    display: none;
}

.tab {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 36px;
    padding: 7px 14px;
    border-radius: 999px;
    border: 1px solid var(--chip-border);
    color: var(--muted);
    text-decoration: none;
    font-size: 13px;
    background: var(--chip);
    white-space: nowrap;
    flex-shrink: 0;
}

.tab.active {
    background: var(--accent-soft);
    color: var(--text);
    border-color: transparent;
}

.filters {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    padding: 10px var(--page-pad) 0;
    align-items: flex-end;
}

.filters .filter-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    width: 100%;
}

.filters .filter-actions .tab {
    flex: 1 1 auto;
    min-width: 0;
}

.filter-item {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 12px;
    color: var(--muted);
    width: 100%;
}

.filter-item select,
.filter-item input,
.filter-item textarea {
    background: var(--bg-elev);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 12px;
    padding: 12px 14px;
    font-size: 16px;
    min-height: 48px;
    width: 100%;
    appearance: none;
}

.filter-item textarea {
    min-height: 160px;
    resize: vertical;
    font-family: inherit;
}

.filter-item.grow {
    flex: 1 1 100%;
}

.filter-submit {
    background: linear-gradient(135deg, #ff5b6b 0%, #ff7b90 100%);
    border: none;
    color: #0b0d12;
    border-radius: 12px;
    padding: 12px 18px;
    font-size: 16px;
    font-weight: 600;
    min-height: 48px;
    width: 100%;
    cursor: pointer;
}

.link-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 40px;
    padding: 9px 15px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--bg-elev);
    color: var(--text);
    text-decoration: none;
    font-size: 13px;
    font-weight: 600;
}

.section-actions {
    display: flex;
    flex-wrap: nowrap;
    gap: 8px;
    padding: 0 var(--page-pad);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}

.section-actions::-webkit-scrollbar {
    display: none;
}

.section-actions .link-button {
    flex-shrink: 0;
    margin-top: 4px;
}

.tab,
.filter-submit,
.page-link,
.link-button {
    transition: transform 0.15s ease, background 0.15s ease, color 0.15s ease;
}

.tab:active,
.page-link:active,
.link-button:active,
.filter-submit:active {
    transform: scale(0.98);
}

.card:hover {
    transform: translateY(-2px);
    box-shadow: 0 14px 34px rgba(0, 0, 0, 0.45);
}

.grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 14px;
    padding: 12px var(--page-pad) 8px;
}

.card {
    min-width: 0;
    max-width: 100%;
    background: var(--card);
    border-radius: 16px;
    overflow: hidden;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.media img {
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 100%;
    display: block;
}

.badges {
    position: absolute;
    left: 8px;
    top: 8px;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    max-width: calc(100% - 16px);
}

.badge {
    background: rgba(17, 21, 34, 0.9);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 5px 10px;
    font-size: 11px;
    font-weight: 600;
    backdrop-filter: blur(6px);
}

.badge-month {
    background: rgba(78, 40, 104, 0.85);
    border-color: #5b3a7a;
}

.media {
    position: relative;
    min-width: 0;
    aspect-ratio: 1 / 1;
    background: #0d111a;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

.meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px 12px;
    font-size: 13px;
    gap: 10px;
}

.author {
    color: var(--text);
    font-weight: 600;
    text-decoration: none;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.score {
    color: var(--accent);
    font-weight: 600;
    flex-shrink: 0;
}

.leaderboard {
    padding: 0 var(--page-pad) 6px;
}

.leader-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    min-height: 52px;
    padding: 11px 14px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 14px;
    margin-bottom: 8px;
    font-size: 13px;
    box-shadow: var(--shadow);
}

.leader-name {
    color: var(--text);
    text-decoration: none;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.leader-value {
    color: var(--muted);
    flex-shrink: 0;
    text-align: right;
}

.leader-item.wrap {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
}

.leader-item.wrap .leader-name {
    overflow: visible;
    white-space: normal;
    font-weight: 600;
}

.leader-item.wrap .leader-value {
    flex-shrink: 1;
    text-align: left;
    white-space: normal;
}

.post-card {
    margin: 12px var(--page-pad) 0;
    background: var(--card);
    border-radius: 18px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.post-media {
    display: flex;
    align-items: center;
    justify-content: center;
    max-height: 72vh;
    min-height: 180px;
    background: #0d111a;
    overflow: hidden;
}

.post-media img,
.post-media video {
    display: block;
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 72vh;
    object-fit: contain;
}

@media (min-width: 768px) {
    .post-card {
        max-width: 640px;
        margin-left: auto;
        margin-right: auto;
    }
}

.post-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 16px;
    gap: 10px;
}

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

.shop-card {
    display: flex;
    flex-direction: column;
}

.shop-media {
    aspect-ratio: 4 / 5;
}

.shop-meta {
    padding-bottom: 6px;
}

.shop-body {
    padding: 0 14px 16px;
    color: var(--muted);
    font-size: 14px;
}

.shop-body p {
    margin: 0 0 12px;
}

.shop-body .badge {
    margin-bottom: 10px;
    display: inline-flex;
}

.shop-body .filter-submit,
.shop-body .link-button {
    width: 100%;
}

.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    padding: 8px var(--page-pad) 16px;
}

.card-link {
    color: inherit;
    text-decoration: none;
    display: block;
}

.view-list .grid {
    grid-template-columns: 1fr;
    gap: 10px;
}

.view-list .card-link {
    display: flex;
    flex-direction: row;
    gap: 12px;
    align-items: stretch;
}

.view-list .media {
    width: 36%;
    min-width: 110px;
    max-width: 140px;
    aspect-ratio: 1 / 1;
    flex-shrink: 0;
}

.view-list .media img {
    width: 100%;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
    object-fit: cover;
}

.view-list .meta {
    flex: 1 1 auto;
    padding: 12px 12px 12px 0;
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;
}

.view-list .score {
    background: var(--accent-soft);
    padding: 6px 10px;
    border-radius: 999px;
}

.page-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    min-width: 44px;
    color: var(--text);
    text-decoration: none;
    border: 1px solid var(--border);
    padding: 8px 14px;
    border-radius: 12px;
    background: var(--bg-elev);
    font-size: 14px;
}

.page-info {
    color: var(--muted);
    font-size: 13px;
    width: 100%;
    text-align: center;
}

.mobile-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 100;
    display: flex;
    align-items: stretch;
    min-height: var(--nav-height);
    padding-bottom: var(--safe-bottom);
    background: rgba(11, 13, 18, 0.92);
    border-top: 1px solid var(--border);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

.mobile-nav-item {
    flex: 1 1 0;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: var(--nav-height);
    color: var(--muted);
    text-decoration: none;
    font-size: 13px;
    font-weight: 600;
    letter-spacing: -0.01em;
    transition: color 0.15s ease, background 0.15s ease;
}

.mobile-nav-item.active {
    color: var(--text);
    background: var(--accent-soft);
}

.mobile-nav-item:active {
    background: rgba(255, 91, 107, 0.18);
}

:root {
    /* Telegram's own header (back/close chrome) draws over the WebView on top;
       safe-area-inset is often 0 on older clients, so the bar reserves a
       generous minimum height regardless of reported safe area. */
    --tg-bar-height: 44px;
}

.tg-app-bar-slot {
    display: flex;
    align-items: center;
    min-width: 32px;
    min-height: 32px;
}

.tg-app-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 300;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: calc(max(var(--tg-bar-height), var(--safe-top) + 34px));
    padding: 0 10px;
    background: rgba(11, 13, 18, 0.94);
    border-bottom: 1px solid var(--border);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

/* Reserve space under the permanent bar so page content never scrolls behind it. */
html.tg-webapp body {
    padding-top: calc(max(var(--tg-bar-height), var(--safe-top) + 34px));
}

/* The permanent top bar already has its own "←" back control — these in-page
   back links would otherwise duplicate it. Keep them for plain-browser visits
   (outside Telegram, where the bar doesn't exist). */
html.tg-webapp .page-back-link {
    display: none;
}

.tg-app-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 1px solid var(--chip-border);
    background: rgba(255, 255, 255, 0.06);
    color: var(--text);
    font-size: 15px;
    font-weight: 700;
    line-height: 1;
    cursor: pointer;
}

.tg-app-btn:active {
    background: rgba(255, 91, 107, 0.25);
}

@media (min-width: 480px) {
    .filter-item {
        width: auto;
        flex: 1 1 calc(50% - 10px);
    }

    .filter-submit {
        width: auto;
        flex: 1 1 auto;
        min-width: 140px;
    }

    .grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (min-width: 768px) {
    :root {
        --page-pad: 24px;
    }

    body.has-mobile-nav {
        padding-bottom: 0;
    }

    .mobile-nav {
        display: none;
    }

    .section-collapse {
        margin: 0;
        border: none;
        background: transparent;
        border-radius: 0;
    }

    .section-collapse-summary {
        display: none;
    }

    .section-collapse > .section-collapse-body {
        display: block !important;
    }

    .shop-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .grid {
        grid-template-columns: repeat(2, 1fr);
        padding: 16px 24px;
    }

    .filter-item.grow {
        flex: 1 1 180px;
    }

    .filter-item {
        width: auto;
    }

    .filter-submit {
        width: auto;
    }

    .section-collapse-summary::after {
        content: "";
    }
}

@media (min-width: 1100px) {
    .grid {
        grid-template-columns: repeat(3, 1fr);
        max-width: 1200px;
        margin: 0 auto;
    }

    .shop-grid {
        max-width: 1200px;
        margin: 0 auto;
    }
}
