/* ============================================================
   Tap Empire — Telegram Mini App styles
   Uses Telegram theme CSS variables with sensible fallbacks so
   the app matches the user's Telegram light/dark theme.
   ============================================================ */

:root {
    --bg: var(--tg-theme-bg-color, #18222d);
    --bg-secondary: var(--tg-theme-secondary-bg-color, #131c26);
    --text: var(--tg-theme-text-color, #ffffff);
    --hint: var(--tg-theme-hint-color, #8a9aa9);
    --link: var(--tg-theme-link-color, #62bcf9);
    --button: var(--tg-theme-button-color, #2ea6ff);
    --button-text: var(--tg-theme-button-text-color, #ffffff);
    --accent: var(--tg-theme-accent-text-color, #2ea6ff);
    --card: var(--tg-theme-section-bg-color, rgba(255, 255, 255, 0.06));
    --danger: #e64545;
    --gold: #f5b93c;
    --radius: 16px;
    --nav-height: 64px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    height: 100%;
    overscroll-behavior: none;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
}

.hidden { display: none !important; }

/* ============ Splash ============ */
.splash {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    background: var(--bg);
    z-index: 100;
}

.splash-coin {
    font-size: 72px;
    animation: bounce 1s ease-in-out infinite;
}

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-14px); }
}

.splash-spinner {
    width: 28px;
    height: 28px;
    border: 3px solid var(--hint);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ============ Layout ============ */
.app {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    min-height: 100dvh;
    padding-bottom: calc(var(--nav-height) + env(safe-area-inset-bottom));
}

.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    padding-top: calc(12px + env(safe-area-inset-top));
}

.user-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--button), #7b5cf0);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 16px;
    background-size: cover;
    background-position: center;
    flex-shrink: 0;
}

.avatar-lg {
    width: 56px;
    height: 56px;
    font-size: 22px;
}

.user-meta {
    display: flex;
    flex-direction: column;
    line-height: 1.25;
}

.user-name { font-weight: 700; font-size: 15px; }
.user-rank { font-size: 12px; color: var(--hint); }

.icon-btn {
    background: var(--card);
    border: none;
    border-radius: 12px;
    width: 40px;
    height: 40px;
    font-size: 18px;
    cursor: pointer;
}

.icon-btn:active { transform: scale(0.92); }

/* ============ Tabs ============ */
.tab {
    display: none;
    flex: 1;
    flex-direction: column;
    padding: 8px 16px 24px;
}

.tab.active { display: flex; }

.tab-title {
    font-size: 22px;
    margin: 8px 0 16px;
}

/* ============ Home / tap game ============ */
.balance-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 12px 0 4px;
}

.balance-label {
    font-size: 13px;
    color: var(--hint);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.balance-value {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 42px;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
}

.coin-icon { font-size: 34px; }

.chip-row {
    display: flex;
    gap: 8px;
}

.chip {
    font-size: 12.5px;
    font-weight: 700;
    color: var(--gold);
    background: var(--card);
    border-radius: 20px;
    padding: 5px 12px;
}

.tap-area {
    position: relative;
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 260px;
}

.tap-coin {
    width: min(62vw, 240px);
    height: min(62vw, 240px);
    border-radius: 50%;
    border: none;
    cursor: pointer;
    background: radial-gradient(circle at 32% 28%, #ffe9a8, var(--gold) 55%, #b87e0e);
    box-shadow: 0 10px 34px rgba(245, 185, 60, 0.35),
                inset 0 -8px 18px rgba(0, 0, 0, 0.25);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.06s ease;
}

.tap-coin:active,
.tap-coin.pressed { transform: scale(0.94); }

.tap-coin.exhausted {
    filter: grayscale(0.8);
    opacity: 0.6;
}

.tap-coin-inner {
    font-size: min(30vw, 118px);
    pointer-events: none;
}

#floaters {
    position: absolute;
    inset: 0;
    pointer-events: none;
    overflow: hidden;
}

.floater {
    position: absolute;
    font-size: 24px;
    font-weight: 800;
    color: var(--text);
    text-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
    animation: floatUp 0.9s ease-out forwards;
    pointer-events: none;
}

@keyframes floatUp {
    0%   { opacity: 1; transform: translateY(0) scale(1); }
    100% { opacity: 0; transform: translateY(-90px) scale(1.25); }
}

.energy-box {
    padding: 8px 4px 4px;
}

.energy-label {
    display: flex;
    justify-content: space-between;
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 6px;
}

.energy-bar {
    height: 12px;
    border-radius: 6px;
    background: var(--card);
    overflow: hidden;
}

.energy-fill {
    height: 100%;
    width: 100%;
    border-radius: 6px;
    background: linear-gradient(90deg, #35c46f, #9be15d);
    transition: width 0.25s ease;
}

/* ============ Cards ============ */
.card {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--card);
    border-radius: var(--radius);
    padding: 14px;
    margin-bottom: 10px;
}

.card-icon {
    font-size: 26px;
    width: 44px;
    height: 44px;
    border-radius: 12px;
    background: rgba(127, 127, 127, 0.12);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.card-body { flex: 1; min-width: 0; }
.card-title { font-weight: 700; font-size: 15px; }
.card-sub { font-size: 12.5px; color: var(--hint); margin-top: 2px; }

.card-btn {
    border: none;
    border-radius: 12px;
    background: var(--button);
    color: var(--button-text);
    font-weight: 700;
    font-size: 13px;
    padding: 10px 14px;
    cursor: pointer;
    white-space: nowrap;
    flex-shrink: 0;
}

.card-btn:active { transform: scale(0.95); }

.card-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.buy-btn { background: var(--gold); color: #3a2a00; }

.ads-note {
    font-size: 12px;
    color: var(--hint);
    text-align: center;
    margin-top: 8px;
    line-height: 1.5;
}

/* ============ Profile ============ */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin-bottom: 18px;
}

.stat {
    background: var(--card);
    border-radius: var(--radius);
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.stat-val {
    font-size: 20px;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    overflow: hidden;
    text-overflow: ellipsis;
}

.stat-key { font-size: 12px; color: var(--hint); }

.section-title {
    font-size: 15px;
    margin: 6px 0 10px;
}

.sdk-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    margin-bottom: 18px;
}

.sdk-btn {
    border: none;
    border-radius: 12px;
    background: var(--card);
    color: var(--text);
    font-size: 13.5px;
    font-weight: 600;
    padding: 12px 8px;
    cursor: pointer;
}

.sdk-btn:active { transform: scale(0.96); }
.sdk-btn.danger { color: var(--danger); }

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

.cloud-status {
    font-size: 12px;
    color: var(--hint);
    text-align: center;
    margin-top: 10px;
}

/* ============ Bottom nav ============ */
.nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: calc(var(--nav-height) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    display: flex;
    background: var(--bg-secondary);
    border-top: 1px solid rgba(127, 127, 127, 0.15);
    z-index: 50;
}

.nav-btn {
    flex: 1;
    border: none;
    background: none;
    color: var(--hint);
    font-size: 11px;
    font-weight: 600;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    cursor: pointer;
}

.nav-btn span { font-size: 20px; }

.nav-btn.active { color: var(--accent); }

/* ============ Toast ============ */
.toast {
    position: fixed;
    left: 50%;
    bottom: calc(var(--nav-height) + 20px + env(safe-area-inset-bottom));
    transform: translateX(-50%) translateY(20px);
    background: rgba(20, 20, 20, 0.92);
    color: #fff;
    padding: 10px 18px;
    border-radius: 22px;
    font-size: 14px;
    font-weight: 600;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease, transform 0.25s ease;
    z-index: 200;
    max-width: 86vw;
    text-align: center;
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ============ Golden coin & frenzy ============ */
.golden-coin {
    position: absolute;
    width: 56px;
    height: 56px;
    border: none;
    background: none;
    font-size: 44px;
    cursor: pointer;
    z-index: 5;
    filter: drop-shadow(0 0 12px rgba(245, 185, 60, 0.9));
    animation: goldenPulse 0.7s ease-in-out infinite alternate;
}

@keyframes goldenPulse {
    from { transform: scale(1) rotate(-8deg); }
    to   { transform: scale(1.25) rotate(8deg); }
}

.frenzy-banner {
    position: absolute;
    top: 4px;
    left: 50%;
    transform: translateX(-50%);
    background: linear-gradient(90deg, #ff5e3a, #ff9e2c);
    color: #fff;
    font-weight: 800;
    font-size: 14px;
    padding: 6px 16px;
    border-radius: 20px;
    z-index: 6;
    box-shadow: 0 4px 14px rgba(255, 94, 58, 0.5);
    animation: goldenPulse 0.4s ease-in-out infinite alternate;
}

body.frenzy .tap-coin {
    background: radial-gradient(circle at 32% 28%, #ffd0a8, #ff9e2c 55%, #c93f00);
    box-shadow: 0 10px 40px rgba(255, 94, 58, 0.6),
                inset 0 -8px 18px rgba(0, 0, 0, 0.25);
}

.frenzy-floater { color: #ff9e2c; }

/* ============ Streak ============ */
.streak-card { flex-direction: column; align-items: stretch; }

.streak-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 12px;
}

.streak-cal {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 5px;
}

.streak-day {
    background: rgba(127, 127, 127, 0.12);
    border-radius: 10px;
    padding: 7px 2px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    font-size: 10.5px;
    color: var(--hint);
}

.streak-day .sd-val { font-weight: 800; font-size: 11.5px; color: var(--text); }

.streak-day.done {
    background: rgba(53, 196, 111, 0.22);
}
.streak-day.done .sd-val { color: #35c46f; }

.streak-day.next {
    outline: 2px solid var(--gold);
    background: rgba(245, 185, 60, 0.15);
}
.streak-day.next .sd-val { color: var(--gold); }

/* ============ Quests ============ */
.quest-bar {
    height: 6px;
    border-radius: 3px;
    background: rgba(127, 127, 127, 0.18);
    overflow: hidden;
    margin: 6px 0 4px;
}

.quest-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--button), #7b5cf0);
    border-radius: 3px;
    transition: width 0.3s ease;
}

.quest-btn { min-width: 66px; }

/* ============ Modal & wheel ============ */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.65);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 150;
}

.modal-box {
    background: var(--bg);
    border-radius: 20px;
    padding: 20px;
    width: min(88vw, 340px);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
}

.modal-title { font-size: 18px; }

.modal-close {
    background: none;
    border: none;
    color: var(--hint);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    padding: 6px;
}

.wheel-wrap {
    position: relative;
    width: min(66vw, 250px);
    height: min(66vw, 250px);
}

.wheel-pointer {
    position: absolute;
    top: -14px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 26px;
    color: var(--text);
    z-index: 2;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.4);
}

.wheel {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    border: 6px solid rgba(255, 255, 255, 0.25);
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
    position: relative;
    overflow: hidden;
}

.wheel-label {
    position: absolute;
    top: 50%;
    left: 50%;
    margin: -12px 0 0 -24px;
    width: 48px;
    text-align: center;
    font-weight: 800;
    font-size: 13px;
    color: #fff;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.55);
    transform-origin: center;
}

.wheel-spin-btn {
    width: 100%;
    padding: 13px;
    font-size: 15px;
}

/* ============ Rank-up overlay ============ */
.rank-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.78);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 180;
}

.rank-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    text-align: center;
    color: #fff;
    z-index: 2;
}

.rank-content h2 {
    font-size: 26px;
    letter-spacing: 2px;
}

.rank-content p { font-size: 20px; font-weight: 700; color: var(--gold); }

.rank-big {
    font-size: 84px;
    animation: rankPop 0.6s cubic-bezier(0.2, 1.6, 0.4, 1);
}

@keyframes rankPop {
    from { transform: scale(0); }
    to   { transform: scale(1); }
}

#confetti {
    position: absolute;
    inset: 0;
    overflow: hidden;
    pointer-events: none;
}

.confetti-bit {
    position: absolute;
    top: -30px;
    animation: confettiFall linear forwards;
}

@keyframes confettiFall {
    to { transform: translateY(110vh) rotate(360deg); }
}
