/* =========================
   BASE
========================= */

:root {
    --tg-bg: #0e141b;
    --tg-surface: #151f2b;
    --tg-text: #ffffff;
    --tg-hint: #9aa7b2;
    --tg-link: #2ea6ff;
    --tg-button: #2ea6ff;
    --tg-button-text: #ffffff;
    --tg-divider: rgba(255, 255, 255, 0.08);
    --tg-surface-2: rgba(255, 255, 255, 0.04);
    --tg-press: rgba(255, 255, 255, 0.06);
    --tg-shadow: 0 2px 10px rgba(0, 0, 0, 0.18);
    --ui-ease: cubic-bezier(0.2, 0.8, 0.2, 1);
}

* {
    box-sizing: border-box;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    -webkit-tap-highlight-color: transparent;
}

img {
    max-width: 100%;
    width: 100%;
}

body {
    margin: 0;
    background: var(--tg-bg);
    color: var(--tg-text);
    transition: background-color 0.2s var(--ui-ease), color 0.2s var(--ui-ease);
    overflow-x: hidden;
}

.app {
    padding: 16px;
    max-width: 420px;
    margin: auto;
    transition: opacity 0.16s var(--ui-ease), transform 0.16s var(--ui-ease);
}

body.tg-loading .app {
    opacity: 0;
    transform: translateY(4px);
    pointer-events: none;
}

body.tg-ready .app {
    opacity: 1;
    transform: translateY(0);
}

.app.page-enter {
    animation: page-enter 0.18s var(--ui-ease);
}

.app.page-exit {
    opacity: 0;
    transform: translateY(4px);
}

@keyframes page-enter {
    from {
        opacity: 0;
        transform: translateY(6px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes item-in {
    from {
        opacity: 0;
        transform: translateY(4px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* =========================
   PRELOADER
========================= */

#preloader {
    position: fixed;
    inset: 0;
    background: var(--tg-bg);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 18px;
    z-index: 9999;
    opacity: 1;
    transition: opacity 0.16s var(--ui-ease), visibility 0.16s var(--ui-ease);
    will-change: opacity;
}

#preloader.is-hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

/* =========================
   CARDS
========================= */

.card {
    background: var(--tg-surface);
    border-radius: 16px;
    padding: 16px;
    margin-bottom: 14px;
    box-shadow: var(--tg-shadow);
    transition: transform 0.14s var(--ui-ease), box-shadow 0.14s var(--ui-ease), background-color 0.2s var(--ui-ease);
    will-change: transform, opacity;
}

.card.small {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.center-card {
    text-align: center;
}

.clickable {
    cursor: pointer;
}

/* =========================
   TYPOGRAPHY
========================= */

.balance-title {
    color: var(--tg-hint);
    font-size: 14px;
}

.balance-value {
    font-size: 28px;
    font-weight: 600;
    margin: 8px 0 12px;
}

.row,
.value {
    display: flex;
    align-items: center;
}

.emoji {
    font-size: 26px;
    margin-right: 12px;
}

.text .title {
    font-size: 16px;
    margin-bottom: 2px;
}

.text .subtitle {
    font-size: 13px;
    color: var(--tg-hint);
}

.hero-emoji {
    font-size: 42px;
    margin-bottom: 12px;
}

.hero-title {
    font-size: 20px;
    font-weight: 600;
    margin-bottom: 8px;
}

.hero-text {
    font-size: 14px;
    color: var(--tg-hint);
    line-height: 1.4;
}

/* =========================
   BUTTONS
========================= */

.primary-btn {
    width: 100%;
    background: var(--tg-button);
    border: none;
    border-radius: 12px;
    padding: 14px;
    color: var(--tg-button-text);
    font-size: 16px;
    cursor: pointer;
    transition: transform 0.1s var(--ui-ease), filter 0.12s var(--ui-ease), opacity 0.12s var(--ui-ease), background-color 0.16s var(--ui-ease), color 0.16s var(--ui-ease);
    will-change: transform;
}

.primary-btn:active {
    opacity: 0.95;
    transform: scale(0.985);
    filter: brightness(0.95);
}

.primary-btn.secondary {
    background: var(--tg-surface-2);
    color: var(--tg-link);
}

.copy-btn {
    background: none;
    border: none;
    font-size: 18px;
    cursor: pointer;
    color: var(--tg-link);
    transition: transform 0.12s var(--ui-ease), opacity 0.12s var(--ui-ease);
}

.copy-btn:active {
    transform: scale(0.95);
    opacity: 0.9;
}

/* =========================
   LIST
========================= */

.list {
    background: var(--tg-surface);
    border-radius: 16px;
    overflow: hidden;
    box-shadow: var(--tg-shadow);
}

.list-item {
    display: flex;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid var(--tg-divider);
    align-items: center;
    transition: background-color 0.14s var(--ui-ease), transform 0.14s var(--ui-ease);
    will-change: transform, opacity;
}

.list-item:active {
    background: var(--tg-press);
    transform: scale(0.997);
}

.list-item:last-child {
    border-bottom: none;
}

.value {
    color: var(--tg-hint);
}

.arrow {
    color: var(--tg-hint);
    font-size: 18px;
    transition: transform 0.2s var(--ui-ease);
}

.card.clickable > .row {
    width: 100%;
}

.card.clickable > .row > .text {
    flex: 1 1 auto;
    min-width: 0;
}

.card.clickable > .row > .arrow {
    margin-left: auto;
}

/* =========================
   PAGE BLOCKS
========================= */

.tg-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 6px 4px 16px;
}

.tg-back {
    font-size: 24px;
    cursor: pointer;
    color: var(--tg-link);
}

.tg-title {
    font-size: 17px;
    font-weight: 600;
}

.referral-hero {
    margin-bottom: 12px;
    background: linear-gradient(145deg, color-mix(in srgb, var(--tg-button) 16%, var(--tg-surface)), var(--tg-surface));
}

.app.referral-page {
    padding-bottom: 132px;
}

.ref-tier-topline {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 10px;
}

.ref-tier-chip {
    border-radius: 999px;
    background: color-mix(in srgb, var(--tg-bg) 72%, transparent);
    padding: 6px 12px;
    font-size: 13px;
    font-weight: 700;
}

.ref-tier-chip[data-tier="silver"] {
    background: linear-gradient(135deg, rgba(192, 198, 208, 0.38), rgba(120, 132, 150, 0.22));
}

.ref-tier-chip[data-tier="gold"] {
    background: linear-gradient(135deg, rgba(255, 215, 120, 0.44), rgba(255, 188, 64, 0.22));
}

.ref-tier-next {
    font-size: 12px;
    color: var(--tg-hint);
    text-align: right;
}

.ref-hero-title {
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 6px;
}

.ref-hero-subtitle {
    font-size: 14px;
    color: var(--tg-hint);
    line-height: 1.45;
}

.ref-progress-wrap {
    margin-top: 12px;
    display: grid;
    gap: 6px;
}

.ref-progress-track {
    width: 100%;
    height: 8px;
    border-radius: 999px;
    background: color-mix(in srgb, var(--tg-bg) 60%, transparent);
    overflow: hidden;
}

.ref-progress-fill {
    height: 100%;
    width: 0;
    border-radius: 999px;
    background: linear-gradient(90deg, #2ea6ff, #55e4b5);
    transition: width 0.28s var(--ui-ease);
}

.ref-progress-label {
    font-size: 12px;
    color: var(--tg-hint);
    text-align: right;
}

.referral-stats-card {
    padding-top: 14px;
}

.ref-stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.ref-stat-item {
    border-radius: 12px;
    background: color-mix(in srgb, var(--tg-surface-2) 80%, transparent);
    padding: 10px;
}

.ref-stat-label {
    color: var(--tg-hint);
    font-size: 12px;
    margin-bottom: 4px;
}

.ref-stat-value {
    font-size: 18px;
    font-weight: 700;
}

.ref-total-line {
    margin-top: 12px;
    padding-top: 10px;
    border-top: 1px solid var(--tg-divider);
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: var(--tg-hint);
}

.ref-total-line b {
    color: #67f5c5;
    font-size: 16px;
}

.ref-friend-left {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    flex: 1 1 auto;
}

.ref-friend-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #2f3440;
    font-size: 15px;
    font-weight: 700;
    letter-spacing: 0.2px;
    flex: 0 0 36px;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.38), 0 4px 10px rgba(0, 0, 0, 0.18);
}

.ref-friend-avatar.avatar-c0 { background: #f2b8c6; } /* pastel pink */
.ref-friend-avatar.avatar-c1 { background: #bfe3a8; } /* pastel green */
.ref-friend-avatar.avatar-c2 { background: #b8d7f7; } /* pastel blue */
.ref-friend-avatar.avatar-c3 { background: #f5cfab; } /* pastel peach */
.ref-friend-avatar.avatar-c4 { background: #d0c2f1; } /* pastel violet */

.ref-friend-main {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.ref-friend-name {
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ref-friend-date {
    font-size: 11px;
    color: var(--tg-hint);
}

.ref-friend-status {
    width: fit-content;
    border-radius: 999px;
    padding: 2px 8px;
    font-size: 10px;
    font-weight: 700;
}

.ref-friend-status.is-retained {
    color: #90ffd9;
    background: rgba(69, 214, 170, 0.18);
}

.ref-friend-status.is-new {
    color: #d2d8df;
    background: rgba(255, 255, 255, 0.1);
}

.ref-friend-bonuses {
    margin-left: 8px;
    display: flex;
    gap: 6px;
}

.ref-bonus-chip {
    min-width: 42px;
    text-align: center;
    border-radius: 999px;
    padding: 3px 8px;
    font-size: 11px;
    font-weight: 700;
}

.ref-bonus-chip.signup {
    color: #7dd3ff;
    background: rgba(46, 166, 255, 0.16);
}

.ref-bonus-chip.retention {
    color: #9effcf;
    background: rgba(54, 205, 148, 0.16);
}

.ref-link {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--tg-surface-2);
    border-radius: 12px;
    padding: 12px 14px;
    margin-top: 10px;
    font-size: 14px;
    word-break: break-all;

    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
    min-width: 0;
    flex: 1 1 auto;
}

#refLink{
    text-overflow: ellipsis;
    overflow: hidden;
    white-space: pre;
}

.empty {
    background: var(--tg-surface-2);
    border-radius: 12px;
    padding: 14px;
    margin-top: 10px;
    color: var(--tg-hint);
    font-size: 14px;
    text-align: center;
}

.bottom-bar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    padding: 12px 16px calc(20px + env(safe-area-inset-bottom, 0px));
    background: linear-gradient(transparent, var(--tg-bg) 40%);
    z-index: 20;
}

.bottom-bar.referral-action-bar {
    padding-top: 10px;
}

.referral-action-panel {
    background: color-mix(in srgb, var(--tg-surface) 82%, var(--tg-bg));
    border: 1px solid var(--tg-divider);
    border-radius: 16px;
    padding: 10px;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.2);
}

.referral-invite-btn {
    border: none;
    background: var(--tg-button);
    color: var(--tg-button-text);
    font-weight: 600;
    box-shadow: none;
    border-radius: 10px;
}

.referral-invite-btn:active {
    transform: scale(0.99);
    filter: brightness(0.96);
}

/* =========================
   TOGGLE
========================= */

.toggle-card {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 16px;
}

.switch {
    position: relative;
    width: 46px;
    height: 26px;
}

.switch input {
    opacity: 0;
}

.slider {
    position: absolute;
    inset: 0;
    background-color: color-mix(in srgb, var(--tg-hint) 35%, transparent);
    border-radius: 26px;
    transition: 0.18s var(--ui-ease);
}

.slider:before {
    content: "";
    position: absolute;
    height: 22px;
    width: 22px;
    left: 2px;
    top: 2px;
    background-color: var(--tg-bg);
    border-radius: 50%;
    transition: 0.18s var(--ui-ease);
}

.switch input:checked + .slider {
    background-color: var(--tg-button);
}

.switch input:checked + .slider:before {
    transform: translateX(20px);
}

/* =========================
   MODAL
========================= */

.modal,
.popup {
    animation: popup-in 0.16s var(--ui-ease);
}

@keyframes popup-in {
    from {
        opacity: 0;
        transform: translateY(6px) scale(0.98);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* =========================
   TABS
========================= */

.tabs {
    margin-bottom: 12px;
}

.tabs-header {
    display: flex;
    position: relative;
    background: color-mix(in srgb, var(--tg-surface) 70%, var(--tg-bg));
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
}

.tab {
    flex: 1;
    text-align: center;
    padding: 10px 0;
    font-size: 14px;
    font-weight: 600;
    color: var(--tg-hint);
    cursor: pointer;
    z-index: 1;
    position: relative;
    user-select: none;
    transition: color 0.2s ease;
}

.tab.active {
    color: var(--tg-link);
}

.tab-indicator {
    position: absolute;
    top: 0;
    left: 0;
    width: 50%;
    height: 100%;
    background: color-mix(in srgb, var(--tg-button) 14%, transparent);
    border-radius: 16px;
    transition: transform 0.3s ease;
    z-index: 0;
}

#readingsList {
    transition: opacity 0.2s ease, transform 0.2s ease;
}

/* =========================
   READING ACCORDION
========================= */

.reading {
    background: var(--tg-surface);
    border-radius: 12px;
    margin-bottom: 10px;
    overflow: hidden;
    transition: box-shadow 0.2s ease;
}

.reading-header {
    display: flex;
    align-items: center;
    padding: 12px;
    cursor: pointer;
    user-select: none;
}

.reading-header:hover {
    background: color-mix(in srgb, var(--tg-button) 10%, transparent);
}

.reading-header .emoji {
    font-size: 20px;
    margin-right: 10px;
}

.reading-header .text .title {
    font-weight: 600;
    font-size: 14px;
}

.reading-header .text .subtitle {
    font-size: 12px;
    color: var(--tg-hint);
}

.reading-header .arrow {
    margin-left: auto;
    font-size: 16px;
    color: var(--tg-hint);
    transition: transform 0.3s ease;
}

.reading.open .arrow {
    transform: rotate(90deg);
}

.reading-content {
    overflow: hidden;
    transition: height 0.25s ease, padding 0.25s ease;
}

.reading-content-inner {
    padding: 0 12px;
    font-size: 13px;
    color: var(--tg-hint);
    line-height: 1.4;
}

/* =========================
   FAQ PAGE
========================= */

.faq-item {
    background: var(--tg-surface);
    border-radius: 16px;
    margin-bottom: 12px;
    overflow: hidden;
    cursor: pointer;
}

.faq-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 16px;
}

.faq-header:hover {
    background: color-mix(in srgb, var(--tg-button) 10%, transparent);
}

.faq-content {
    height: 0;
    overflow: hidden;
    padding: 0 16px;
    transition: height 0.35s ease, padding-top 0.35s ease, padding-bottom 0.35s ease;
}

.faq-content-inner {
    padding: 0;
    font-size: 14px;
    line-height: 1.5;
    color: var(--tg-hint);
}

.faq-item .arrow {
    transition: transform 0.3s ease;
    color: var(--tg-text);
}

.faq-item.open .arrow {
    transform: rotate(90deg);
}

/* =========================
   PAGE SPECIFIC
========================= */

.how-to-ask-page .ask-title {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 8px;
}

.how-to-ask-page .ask-text {
    font-size: 14px;
    color: var(--tg-hint);
    line-height: 1.5;
}

.how-to-ask-page .note-card {
    background: color-mix(in srgb, var(--tg-bg) 88%, black);
    color: var(--tg-hint);
    font-size: 14px;
    text-align: center;
}

.how-to-ask-page .example {
    background: color-mix(in srgb, var(--tg-bg) 88%, black);
    border-radius: 10px;
    padding: 10px 12px;
    font-size: 14px;
    color: var(--tg-text);
    margin-top: 8px;
}

.legal-page .section-title {
    font-size: 13px;
    color: var(--tg-hint);
    text-transform: uppercase;
    margin: 18px 4px 8px;
    letter-spacing: 0.04em;
}

.legal-page .developer-card {
    background: var(--tg-surface);
    padding: 16px;
}

.legal-page .dev-name {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 8px;
}

.legal-page .dev-line {
    font-size: 14px;
    color: var(--tg-hint);
    margin-bottom: 4px;
}

.legal-page .dev-email {
    display: inline-block;
    margin-top: 8px;
    font-size: 14px;
    color: var(--tg-link);
    text-decoration: none;
}

.support-page .support-hero {
    margin-bottom: 12px;
}

.support-page .support-action {
    margin-bottom: 12px;
}

.support-page .support-info {
    background: color-mix(in srgb, var(--tg-surface) 70%, var(--tg-bg));
    font-size: 13px;
    color: var(--tg-hint);
}

.support-page .info-line {
    padding: 6px 0;
    text-align: center;
}

/* =========================
   SUBSCRIPTIONS PAGE
========================= */

.subscriptions-page {
    padding-bottom: 24px;
}

.hero-card {
    text-align: center;
    background: linear-gradient(180deg, color-mix(in srgb, var(--tg-surface) 70%, var(--tg-bg)), var(--tg-surface));
    border-radius: 16px;
    padding: 24px 16px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
}

.hero-card .hero-emoji {
    font-size: 48px;
    margin-bottom: 14px;
}

.hero-card .hero-title {
    font-size: 22px;
    font-weight: 600;
    color: var(--tg-text);
    margin-bottom: 4px;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
}

.hero-img {
    margin-bottom: 8px;
    border-radius: 16px;
}

.hero-subtitle {
    font-size: 15px;
    font-weight: 500;
    color: color-mix(in srgb, var(--tg-link) 80%, white 20%);
    margin-bottom: 12px;
}

.hero-description {
    font-size: 14px;
    color: var(--tg-hint);
    line-height: 1.6;
}

.tariffs {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.tariff {
    position: relative;
}

.tariff-title {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 6px;
}

.tariff-desc {
    font-size: 13px;
    color: var(--tg-hint);
    margin-bottom: 10px;
}

.tariff-points div {
    font-size: 14px;
    color: var(--tg-hint);
    margin-bottom: 6px;
}

.tariff.premium {
    background: linear-gradient(160deg, color-mix(in srgb, var(--tg-button) 16%, var(--tg-surface)), var(--tg-surface));
    box-shadow: 0 12px 32px rgba(120, 90, 255, 0.25);
}

.badge {
    position: absolute;
    top: -10px;
    right: 12px;
    background: var(--tg-button);
    color: var(--tg-bg);
    font-size: 12px;
    font-weight: 600;
    padding: 4px 8px;
    border-radius: 10px;
}

.tariff-price {
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 12px;
}

.tariff-price span {
    font-size: 13px;
    color: var(--tg-hint);
}

.tariff-benefits {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-bottom: 14px;
}

.benefit-card {
    background: color-mix(in srgb, var(--tg-bg) 88%, black);
    border-radius: 12px;
    padding: 10px;
    font-size: 13px;
}

.benefit-card b {
    display: block;
    font-weight: 600;
    margin-bottom: 2px;
}

.benefit-card span {
    color: var(--tg-hint);
}

.tariff.pro {
    opacity: 0.85;
}

.includes-card {
    background: color-mix(in srgb, var(--tg-surface) 70%, var(--tg-bg));
}

.includes-title {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 10px;
}

.includes-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.include-item {
    background: color-mix(in srgb, var(--tg-bg) 88%, black);
    border-radius: 10px;
    padding: 8px 10px;
    font-size: 13px;
    color: var(--tg-hint);
}

.trust-text {
    margin-top: 14px;
    font-size: 12px;
    color: var(--tg-hint);
    text-align: center;
}

#sub-buy-btn,
#sub-cancel-btn {
    justify-content: center;
    align-items: center;
    text-align: center;
}

/* =========================
   STAGGERED MOTION
========================= */

body.tg-ready .app .card,
body.tg-ready .app .list-item,
body.tg-ready .app .faq-item,
body.tg-ready .app .reading {
    animation: item-in 0.18s var(--ui-ease) both;
}

body.tg-ready .app .card:nth-of-type(1),
body.tg-ready .app .list-item:nth-child(1),
body.tg-ready .app .faq-item:nth-child(1),
body.tg-ready .app .reading:nth-child(1) {
    animation-delay: 0.02s;
}

body.tg-ready .app .card:nth-of-type(2),
body.tg-ready .app .list-item:nth-child(2),
body.tg-ready .app .faq-item:nth-child(2),
body.tg-ready .app .reading:nth-child(2) {
    animation-delay: 0.04s;
}

body.tg-ready .app .card:nth-of-type(3),
body.tg-ready .app .list-item:nth-child(3),
body.tg-ready .app .faq-item:nth-child(3),
body.tg-ready .app .reading:nth-child(3) {
    animation-delay: 0.06s;
}

body.tg-ready .app .card:nth-of-type(4),
body.tg-ready .app .list-item:nth-child(4),
body.tg-ready .app .faq-item:nth-child(4),
body.tg-ready .app .reading:nth-child(4) {
    animation-delay: 0.08s;
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation: none !important;
        transition-duration: 0.01ms !important;
    }
}
