* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --tg-theme-bg-color: #ffffff;
    --tg-theme-text-color: #000000;
    --tg-theme-hint-color: #999999;
    --tg-theme-link-color: #2678b6;
    --tg-theme-button-color: #2678b6;
    --tg-theme-button-text-color: #ffffff;
    --tg-theme-secondary-bg-color: #f0f0f0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--tg-theme-bg-color);
    color: var(--tg-theme-text-color);
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
}

#app {
    padding-bottom: 20px;
}

/* Header */
.header {
    text-align: center;
    padding: 16px 16px 8px;
}

.header h1 {
    font-size: 22px;
    font-weight: 700;
}

.subtitle {
    font-size: 13px;
    color: var(--tg-theme-hint-color);
    margin-top: 2px;
}

/* Categories */
.categories {
    display: flex;
    gap: 8px;
    padding: 12px 16px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}

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

.cat-btn {
    flex-shrink: 0;
    padding: 8px 16px;
    border-radius: 20px;
    border: none;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    background: var(--tg-theme-secondary-bg-color);
    color: var(--tg-theme-text-color);
}

.cat-btn.active {
    background: var(--tg-theme-button-color);
    color: var(--tg-theme-button-text-color);
}

/* Products grid */
.products {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    padding: 8px 16px;
}

.loading {
    grid-column: 1 / -1;
    text-align: center;
    padding: 40px;
    color: var(--tg-theme-hint-color);
    font-size: 15px;
}

.empty-state {
    grid-column: 1 / -1;
    text-align: center;
    padding: 40px;
    color: var(--tg-theme-hint-color);
}

/* Product card */
.product-card {
    background: var(--tg-theme-secondary-bg-color);
    border-radius: 12px;
    overflow: hidden;
    cursor: pointer;
    transition: transform 0.15s;
    -webkit-tap-highlight-color: transparent;
}

.product-card:active {
    transform: scale(0.97);
}

.card-photo {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
    display: block;
}

.card-no-photo {
    width: 100%;
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 48px;
    background: var(--tg-theme-secondary-bg-color);
}

.card-info {
    padding: 10px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    min-height: 60px;
}

.card-name {
    font-size: 14px;
    font-weight: 600;
    line-height: 1.3;
    height: 2.6em;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.card-price {
    font-size: 15px;
    font-weight: 700;
    color: var(--tg-theme-button-color);
    margin-top: auto;
    padding-top: 4px;
}

/* Modal */
.modal {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: flex-end;
    visibility: hidden;
    opacity: 0;
    transition: visibility 0.3s, opacity 0.3s;
}

.modal.open {
    visibility: visible;
    opacity: 1;
}

.modal-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
}

.modal-content {
    position: relative;
    width: 100%;
    max-height: 90vh;
    background: var(--tg-theme-bg-color);
    border-radius: 16px 16px 0 0;
    overflow-y: auto;
    transform: translateY(100%);
    transition: transform 0.3s ease-out;
}

.modal.open .modal-content {
    transform: translateY(0);
}

.modal-close {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background: rgba(0, 0, 0, 0.4);
    color: #fff;
    font-size: 20px;
    cursor: pointer;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-photo-wrap {
    width: 100%;
    aspect-ratio: 1;
    position: relative;
    overflow: hidden;
}

.modal-photo-wrap img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.modal-photo-wrap img.hidden {
    display: none;
}

.no-photo {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 80px;
    background: var(--tg-theme-secondary-bg-color);
}

.no-photo.hidden {
    display: none;
}

.modal-body {
    padding: 16px;
}

.modal-body h2 {
    font-size: 20px;
    font-weight: 700;
    margin-bottom: 8px;
}

#modal-desc {
    font-size: 14px;
    line-height: 1.5;
    color: var(--tg-theme-text-color);
    margin-bottom: 12px;
}

#modal-desc:empty {
    display: none;
}

.chars {
    font-size: 13px;
    line-height: 1.6;
    color: var(--tg-theme-hint-color);
    margin-bottom: 16px;
    white-space: pre-line;
}

.chars:empty {
    display: none;
}

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

.price {
    font-size: 22px;
    font-weight: 700;
    color: var(--tg-theme-button-color);
}

.quantity-selector {
    display: flex;
    align-items: center;
    gap: 12px;
}

.qty-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: var(--tg-theme-secondary-bg-color);
    color: var(--tg-theme-text-color);
    font-size: 20px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

#qty-value {
    font-size: 18px;
    font-weight: 600;
    min-width: 24px;
    text-align: center;
}

.order-btn {
    width: 100%;
    padding: 14px;
    border-radius: 12px;
    border: none;
    background: var(--tg-theme-button-color);
    color: var(--tg-theme-button-text-color);
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s;
}

.order-btn:active {
    opacity: 0.8;
}

/* Success screen */
.success-screen {
    position: fixed;
    inset: 0;
    z-index: 200;
    background: var(--tg-theme-bg-color);
    display: flex;
    align-items: center;
    justify-content: center;
    visibility: hidden;
    opacity: 0;
    transition: visibility 0.3s, opacity 0.3s;
}

.success-screen.open {
    visibility: visible;
    opacity: 1;
}

.success-content {
    text-align: center;
    padding: 20px;
}

.success-icon {
    font-size: 64px;
    margin-bottom: 16px;
}

.success-content h2 {
    font-size: 22px;
    margin-bottom: 8px;
}

.success-content p {
    color: var(--tg-theme-hint-color);
    margin-bottom: 24px;
    font-size: 15px;
}

.success-content .order-btn {
    max-width: 280px;
    margin: 0 auto;
}
