/* design-system/layouts/game-layout.css */
html,
body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    background: var(--bg-gradient);
    color: var(--text-primary);
    font-family: var(--font-family);
    overflow: hidden; /* Скрол тільки всередині .page-content */

    /* Mobile opts */
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

/* Глобально коректуємо box-sizing для передбачуваної верстки */
*,
*::before,
*::after {
    box-sizing: border-box;
}

/* Default vars if missing */
:root {
    --topbar-height: 60px;
    --tabbar-height: 56px;
    --safe-area-top: env(safe-area-inset-top, 0px);
    --safe-area-bottom: env(safe-area-inset-bottom, 0px);
    --safe-area-left: env(safe-area-inset-left, 0px);
    --safe-area-right: env(safe-area-inset-right, 0px);
    --content-padding: var(--space-md);
}

/* App Container for Desktop Mode Constraint */
.app-container {
    width: 100%;
    height: 100%;
    position: relative;
    display: flex;
    flex-direction: column;
}

/* На десктопі (768+) — 480px по центру, крім сторінки календаря (data-route="calendar") */
@media (min-width: 768px) {
    body:not([data-route="calendar"]) .app-container {
        max-width: 480px;
        margin-left: auto;
        margin-right: auto;
        border-left: 1px solid rgba(255, 255, 255, 0.05);
        border-right: 1px solid rgba(255, 255, 255, 0.05);
        box-shadow: 0 0 50px rgba(0, 0, 0, 0.5);
        background: var(--bg-gradient);
    }

    body {
        background: #000;
    }
}

.page-content {
    flex-grow: 1;
    width: 100%;

    /* Висота з урахуванням фіксованих topbar + tabbar */
    min-height: calc(100vh - var(--topbar-height) - var(--tabbar-height));
    min-height: calc(100dvh - var(--topbar-height) - var(--tabbar-height));

    /* Відступи: safe-area вже врахована у topbar/tabbar */
    padding-top: calc(var(--topbar-height) + var(--content-padding));
    padding-bottom: calc(var(--tabbar-height) + var(--content-padding));
    padding-left: calc(var(--safe-area-left) + var(--content-padding));
    padding-right: calc(var(--safe-area-right) + var(--content-padding));

    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    position: relative;
}

/* На головній сторінці гри /game фіксуємо контент без вертикального скролу */
body[data-route="game"] .page-content {
    overflow-y: hidden;
}

/* Page wrappers: на десктопі 480px тільки коли НЕ календар */
.page-wrapper {
    width: 100%;
    animation: fadeIn var(--transition-normal);
}

@media (min-width: 768px) {
    body:not([data-route="calendar"]) .page-wrapper {
        max-width: 480px;
        margin-left: auto;
        margin-right: auto;
    }
}

/* Utility layout classes */
.flex-row {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.flex-col {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

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

.mt-sm {
    margin-top: var(--space-sm);
}

.mt-md {
    margin-top: var(--space-md);
}

.mt-lg {
    margin-top: var(--space-lg);
}

.mb-lg {
    margin-bottom: var(--space-lg);
}

/* Календар і профіль: контейнер на всю ширину (як на сторінці календаря, 480px не застосовується) */
body[data-route="calendar"] .app-container,
body.route-calendar .app-container,
body[data-route="profile"] .app-container {
    width: 100% !important;
    max-width: none !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
}

body[data-route="calendar"] .page-content,
body[data-route="calendar"] .page-content > .calendar-page,
body[data-route="profile"] .page-content {
    width: 100% !important;
    max-width: none !important;
}

.shop-page {
    gap: var(--space-md);
}

.shop-page__intro-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: var(--space-md);
    padding: var(--space-lg) var(--space-md);
}

.shop-page__intro-content {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-xs);
}

.shop-page__intro-title,
.shop-page__intro-desc {
    text-align: center;
    margin: 0;
}

.shop-page__intro-desc {
    max-width: 480px;
}

/* Домашній слайдер під таймером */
.home-slider {
    margin-top: 0;
    padding: 0;
    position: relative;
}

.home-slider__track {
    display: flex;
    width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
}

.home-slide {
    min-width: 100%;
    padding-right: 10px;
    opacity: 0.4;
    transition: opacity 0.35s ease;
    scroll-snap-align: start;
}

.home-slide.is-active {
    opacity: 1;
}

.home-slide__card {
    position: relative;
    overflow: hidden;
    background: transparent;
    border-radius: 18px;
    padding: 12px 16px 18px;
    border: 1px solid rgba(129, 140, 248, 0.4);
}

.home-slide__card:empty {
    min-height: 92px;
}

.home-slide__card::before {
    content: '';
    position: absolute;
    inset: 0;
    background-image: var(--home-slide-bg-url);
    background-size: cover;
    background-position: center;
    opacity: 0.22;
    z-index: 0;
}

.home-slide__card::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(37, 99, 235, 0.18), rgba(147, 51, 234, 0.18));
    z-index: 1;
}

.home-slide__card > * {
    position: relative;
    z-index: 2;
}

.home-slide__title {
    margin: 0 0 4px;
    font-size: 0.9rem;
    font-weight: 600;
    color: #e5e7eb;
}

.home-slide__text {
    margin: 0;
    font-size: 0.78rem;
    line-height: 1.4;
    color: #cbd5f5;
}

.home-slider__dots {
    margin-top: 8px;
    display: flex;
    justify-content: center;
    gap: 6px;
    position: absolute;
    left: 0;
    right: 0;
    bottom: 6px;
    pointer-events: none;
    z-index: 5;
}

.home-slider__dot {
    width: 14px;
    height: 3px;
    border-radius: 999px;
    border: none;
    padding: 0;
    background: rgba(148, 163, 184, 0.35);
    cursor: pointer;
    transition: background 0.25s ease;
    pointer-events: auto;
    position: relative;
    overflow: hidden;
}

.home-slider__dot.is-active {
    background: rgba(96, 165, 250, 0.22);
}

/* Прогрес активного сегмента (без руху сусідів) */
.home-slider__dot::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 0%;
    background: linear-gradient(90deg, rgba(96, 165, 250, 1), rgba(147, 51, 234, 0.9));
    border-radius: 999px;
}

.home-slider__dot.is-active::before {
    animation: home-slider-dot-progress-fill 5s linear forwards;
}

@keyframes home-slider-dot-progress-fill {
    from { width: 0%; }
    to { width: 100%; }
}

.shop-page__history-btn {
    margin-top: var(--space-sm);
    padding: 10px 18px;
    border-radius: 12px;
    font-size: 0.875rem;
    font-weight: 600;
}

.shop-page__tabs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    padding: 0 var(--space-md);
}

.shop-tab-btn {
    appearance: none;
    border: 1px solid rgba(148, 163, 184, 0.35);
    background: rgba(15, 23, 42, 0.55);
    color: #e2e8f0;
    border-radius: 14px;
    padding: 10px 12px;
    font-size: 0.88rem;
    font-weight: 700;
    cursor: pointer;
    transition: transform 120ms ease, background 120ms ease, border-color 120ms ease, opacity 120ms ease;
}

.shop-tab-btn.is-active {
    background: rgba(56, 189, 248, 0.18);
    border-color: rgba(56, 189, 248, 0.55);
    color: #7dd3fc;
}

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

.shop-tab-btn:active:not(:disabled) {
    transform: scale(0.99);
}

.shop-page__tab-panels {
    display: block;
}

.shop-tab-panel[hidden] {
    display: none !important;
}

.shop-section {
    padding: var(--space-md);
}

.shop-exchange-section {
    margin-top: var(--space-lg, 24px);
}

/* У вкладках старт секцій має бути однаковий */
.shop-tab-panel .shop-exchange-section {
    margin-top: 0;
}

.shop-section__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-sm);
}

.shop-section__title {
    font-size: 1rem;
    font-weight: 600;
}

.shop-section__scroller {
    display: flex;
    flex-direction: row;
    gap: var(--space-sm);
    overflow-x: auto;
    padding-bottom: 4px;
    scrollbar-width: thin;
    width: 100%;
    box-sizing: border-box;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
}

.shop-section__scroller::-webkit-scrollbar {
    height: 6px;
}

.shop-section__scroller::-webkit-scrollbar-thumb {
    background: rgba(148, 163, 184, 0.6);
    border-radius: 999px;
}

.shop-card {
    flex: 0 0 100%;
    min-width: 0;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    scroll-snap-align: start;
    scroll-snap-stop: always;
    border-radius: 16px;
    background: rgba(15, 23, 42, 0.9);
    border: 1px solid rgba(148, 163, 184, 0.4);
    padding: 10px 12px 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.shop-card__top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 6px;
}

.shop-card__title {
    font-size: 0.9rem;
    font-weight: 600;
}

.shop-card__price-badge {
    padding: 3px 8px;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    background: rgba(56, 189, 248, 0.15);
    color: #7dd3fc;
    white-space: nowrap;
}

.shop-card__discount {
    font-size: 0.8rem;
    font-weight: 500;
    color: #facc15;
}

.shop-card__description {
    font-size: 0.78rem;
    color: #d1d5db;
}

.shop-card__meta {
    display: flex;
    justify-content: space-between;
    gap: 6px;
    font-size: 0.72rem;
    color: #9ca3af;
}

.shop-card__note {
    font-size: 0.75rem;
    color: #a7f3d0;
}

.shop-card__note--muted {
    color: #9ca3af;
}

.shop-card__buy-btn {
    margin-top: 4px;
    width: 100%;
}

.shop-buy-btn__label {
    display: block;
    line-height: 1.1;
}

.shop-buy-btn__price {
    display: block;
    font-size: 0.78em;
    line-height: 1.1;
    opacity: 0.85;
    margin-top: 2px;
}

/* Карточка обміну: кристали по центру, кнопка з вартістю в монетах */
.shop-card--exchange .shop-card__crystals {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 14px 0;
    margin: 4px 0;
}
.shop-card--exchange .shop-card__crystals-num {
    font-size: 1.5rem;
    font-weight: 700;
    color: #e0e7ff;
    line-height: 1;
}
.shop-card--exchange .shop-card__crystals-icon {
    font-size: 1.5rem;
    line-height: 1;
}

/* Історія обміну — модалка */
.shop-history-list {
    list-style: none;
    margin: 0;
    padding: 0;
    max-height: 50vh;
    overflow-y: auto;
}

.shop-history-list__item {
    padding: 12px 14px;
    border-radius: 12px;
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid rgba(148, 163, 184, 0.3);
    margin-bottom: 10px;
}

.shop-history-list__item:last-child {
    margin-bottom: 0;
}

.shop-history-list__title {
    font-size: 0.9rem;
    font-weight: 600;
    color: #f1f5f9;
    margin: 0;
}

.shop-history-list__top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 6px;
}

.shop-history-list__subtitle {
    font-size: 0.78rem;
    color: #cbd5e1;
    margin-bottom: 8px;
}

.shop-history-pill {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 600;
    border: 1px solid rgba(148, 163, 184, 0.25);
    white-space: nowrap;
}
.shop-history-pill.is-active {
    background: rgba(34, 197, 94, 0.12);
    color: #86efac;
    border-color: rgba(34, 197, 94, 0.25);
}
.shop-history-pill.is-used {
    background: rgba(148, 163, 184, 0.12);
    color: #cbd5e1;
}
.shop-history-pill.is-expired {
    background: rgba(239, 68, 68, 0.12);
    color: #fca5a5;
    border-color: rgba(239, 68, 68, 0.25);
}

.shop-history-list__code {
    font-size: 0.95rem;
    margin: 0 0 6px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.shop-history-list__code code {
    padding: 4px 10px;
    border-radius: 8px;
    background: rgba(56, 189, 248, 0.15);
    color: #7dd3fc;
    font-family: ui-monospace, monospace;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
}

.shop-history-list__meta {
    font-size: 0.75rem;
    color: #94a3b8;
}

