/* ===== Reset & Base ===== */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg: var(--tg-theme-bg-color, #ffffff);
    --text: var(--tg-theme-text-color, #000000);
    --hint: var(--tg-theme-hint-color, #999999);
    --link: var(--tg-theme-link-color, #2481cc);
    --btn: var(--tg-theme-button-color, #2481cc);
    --btn-text: var(--tg-theme-button-text-color, #ffffff);
    --card-bg: var(--tg-theme-secondary-bg-color, #f0f0f0);
    --border: rgba(128, 128, 128, 0.12);
    --shadow: rgba(0, 0, 0, 0.06);
    --danger: #ff3b30;
    --success: #34c759;
    --heart: #ff2d55;
}

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

/* ===== App ===== */
.app {
    max-width: 600px;
    margin: 0 auto;
    padding-bottom: 24px;
    min-height: 100vh;
}

/* ===== Tabs ===== */
.tabs {
    display: flex;
    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--bg);
    box-shadow: 0 1px 4px var(--shadow);
    padding: 0 8px;
}

.tab {
    flex: 1;
    padding: 14px 8px;
    border: none;
    background: transparent;
    color: var(--hint);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    position: relative;
    transition: color 0.2s;
    -webkit-tap-highlight-color: transparent;
}

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

.tab.active::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 20%;
    right: 20%;
    height: 3px;
    background: var(--link);
    border-radius: 3px 3px 0 0;
    animation: tabLine 0.25s ease;
}

@keyframes tabLine {
    from { transform: scaleX(0); }
    to { transform: scaleX(1); }
}

/* ===== Period sub-tabs ===== */
.periods {
    display: flex;
    gap: 6px;
    padding: 10px 12px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.period {
    flex-shrink: 0;
    padding: 6px 14px;
    border: 1px solid var(--border);
    border-radius: 20px;
    background: var(--card-bg);
    color: var(--text);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    -webkit-tap-highlight-color: transparent;
}

.period.active {
    background: var(--btn);
    color: var(--btn-text);
    border-color: var(--btn);
}

/* ===== Grid ===== */
.grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
    padding: 6px;
}

/* ===== Card ===== */
.card {
    position: relative;
    border-radius: 12px;
    overflow: hidden;
    background: var(--card-bg);
    cursor: pointer;
    aspect-ratio: 1;
    box-shadow: 0 1px 4px var(--shadow);
    transition: transform 0.15s ease;
    -webkit-tap-highlight-color: transparent;
}

.card:active {
    transform: scale(0.96);
}

.card img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: opacity 0.35s ease;
}

.card img.loaded {
    opacity: 1;
}

.card-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 28px 8px 8px;
    background: linear-gradient(transparent, rgba(0,0,0,0.6));
    color: #fff;
    pointer-events: none;
}

.card-likes {
    font-size: 13px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 4px;
}

.card-prompt {
    font-size: 11px;
    opacity: 0.85;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 2px;
}

/* ===== Rank badge ===== */
.card-rank {
    position: absolute;
    top: 8px;
    left: 8px;
    background: rgba(0,0,0,0.55);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    color: #fff;
    font-size: 14px;
    font-weight: 700;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

/* ===== Card placeholder ===== */
.card-placeholder {
    width: 100%;
    height: 100%;
    background: var(--card-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--hint);
    font-size: 28px;
}

/* ===== Skeleton loading ===== */
.card-skeleton {
    position: relative;
    background: var(--card-bg);
    overflow: hidden;
}

.skeleton-shimmer {
    position: absolute;
    inset: 0;
    background: linear-gradient(
        110deg,
        transparent 30%,
        rgba(255,255,255,0.18) 50%,
        transparent 70%
    );
    animation: shimmer 1.4s ease-in-out infinite;
}

@keyframes shimmer {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(100%); }
}

/* ===== Card entrance animation ===== */
.fade-in {
    animation: fadeInUp 0.35s ease both;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(16px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ===== Loading spinner ===== */
.loader {
    display: flex;
    justify-content: center;
    padding: 24px;
}

.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border);
    border-top-color: var(--link);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

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

/* ===== Empty State ===== */
.empty {
    text-align: center;
    padding: 70px 24px;
}

.empty-icon {
    font-size: 56px;
    margin-bottom: 14px;
    animation: emptyBounce 2s ease-in-out infinite;
}

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

.empty p {
    font-size: 17px;
    font-weight: 600;
    color: var(--text);
}

.empty-sub {
    font-size: 14px !important;
    font-weight: 400 !important;
    color: var(--hint) !important;
    margin-top: 6px;
}

/* ===== Detail Overlay ===== */
.overlay {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: flex-end;
    justify-content: center;
}

.overlay-bg {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    animation: fadeBg 0.2s ease;
}

@keyframes fadeBg {
    from { opacity: 0; }
    to { opacity: 1; }
}

.detail-card {
    position: relative;
    background: var(--bg);
    border-radius: 20px 20px 0 0;
    max-width: 600px;
    width: 100%;
    max-height: 92vh;
    overflow-y: auto;
    animation: slideUp 0.3s cubic-bezier(0.32, 0.72, 0, 1);
    -webkit-overflow-scrolling: touch;
}

@keyframes slideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

.close-btn {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: none;
    background: rgba(0, 0, 0, 0.45);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    color: #fff;
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    z-index: 5;
    display: flex;
    align-items: center;
    justify-content: center;
    -webkit-tap-highlight-color: transparent;
}

.detail-img-wrap {
    width: 100%;
    aspect-ratio: 1;
    background: var(--card-bg);
    overflow: hidden;
}

.detail-img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}

.detail-info {
    padding: 16px 16px 24px;
}

.detail-prompt {
    font-size: 16px;
    font-weight: 600;
    line-height: 1.4;
    margin-bottom: 8px;
}

.detail-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.detail-author {
    font-size: 14px;
    color: var(--link);
    font-weight: 500;
}

.detail-date {
    font-size: 13px;
    color: var(--hint);
}

.detail-actions {
    display: flex;
    gap: 10px;
}

.btn-like {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 12px 20px;
    border: 1.5px solid var(--border);
    border-radius: 14px;
    background: var(--card-bg);
    color: var(--text);
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    -webkit-tap-highlight-color: transparent;
}

.btn-like.liked {
    border-color: var(--heart);
    background: rgba(255, 45, 85, 0.1);
}

.btn-like .heart {
    font-size: 20px;
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.btn-like.liked .heart {
    transform: scale(1.15);
}

@keyframes heartPop {
    0% { transform: scale(1); }
    40% { transform: scale(1.4); }
    100% { transform: scale(1.15); }
}

.heart-animate {
    animation: heartPop 0.4s ease;
}

.btn-order {
    flex: 1;
    padding: 12px 20px;
    border: none;
    border-radius: 14px;
    background: var(--btn);
    color: var(--btn-text);
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.15s, transform 0.15s;
    -webkit-tap-highlight-color: transparent;
}

.btn-order:active {
    opacity: 0.85;
    transform: scale(0.97);
}

/* ===== Bottom Sheet ===== */
.sheet-overlay {
    position: fixed;
    inset: 0;
    z-index: 200;
}

.sheet-bg {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    animation: fadeBg 0.2s ease;
}

.bottom-sheet {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg);
    border-radius: 20px 20px 0 0;
    padding: 16px 16px 36px;
    max-width: 600px;
    margin: 0 auto;
    animation: slideUp 0.25s cubic-bezier(0.32, 0.72, 0, 1);
}

.sheet-handle {
    width: 40px;
    height: 4px;
    border-radius: 2px;
    background: var(--border);
    margin: 0 auto 16px;
}

.bottom-sheet h3 {
    text-align: center;
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 16px;
}

.sizes {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin-bottom: 16px;
}

.size-btn {
    padding: 14px 8px;
    border: 1.5px solid var(--border);
    border-radius: 14px;
    background: var(--card-bg);
    color: var(--text);
    font-size: 15px;
    font-weight: 600;
    text-align: center;
    cursor: pointer;
    transition: all 0.15s;
    -webkit-tap-highlight-color: transparent;
}

.size-btn:active {
    background: var(--btn);
    color: var(--btn-text);
    border-color: var(--btn);
    transform: scale(0.95);
}

.btn-cancel {
    width: 100%;
    padding: 14px;
    border: none;
    border-radius: 14px;
    background: var(--card-bg);
    color: var(--danger);
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

/* ===== Toast ===== */
.toast {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    padding: 12px 24px;
    border-radius: 14px;
    background: rgba(30, 30, 30, 0.88);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    color: #fff;
    font-size: 14px;
    font-weight: 600;
    z-index: 500;
    pointer-events: none;
    animation: toastIn 0.3s ease;
    max-width: 90%;
    text-align: center;
}

@keyframes toastIn {
    from { opacity: 0; transform: translateX(-50%) translateY(16px); }
    to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ===== Order Confirmation ===== */
.confirm-wrap {
    text-align: center;
    padding: 8px 0;
}

.confirm-text {
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 4px;
}

.confirm-detail {
    font-size: 22px;
    margin-bottom: 20px;
    color: var(--hint);
}

.confirm-detail strong {
    color: var(--text);
    font-weight: 800;
}

.btn-confirm {
    width: 100%;
    padding: 16px;
    border: none;
    border-radius: 14px;
    background: #34c759;
    color: #fff;
    font-size: 17px;
    font-weight: 700;
    cursor: pointer;
    margin-bottom: 8px;
    transition: opacity 0.15s;
}

.btn-confirm:active {
    opacity: 0.7;
}

/* ===== Utility ===== */
.hidden {
    display: none !important;
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar {
    width: 3px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 2px;
}
