:root {
    --bg: #f4f5f7;
    --card: #ffffff;
    --card-soft: #f7f8fa;
    --text: #111318;
    --muted: #667085;
    --border: #e5e7eb;
    --gold: #f5b400;
    --orange: #ff9f0a;
    --blue: #229ed9;
    --shadow: 0 18px 48px rgba(16, 24, 40, .12);
}

body.dark-mode {
    --bg: #020203;
    --card: #0b0b0d;
    --card-soft: #131316;
    --text: #ffffff;
    --muted: #9a9aa0;
    --border: #202024;
    --shadow: 0 20px 58px rgba(0, 0, 0, .58);
}

* {
    box-sizing: border-box;
}

html,
body {
    width: 100%;
    height: 100%;
    background: var(--bg);
    overflow: hidden;
}

body.loyalcard-body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: 'Exo 2', system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
    transition: background .22s ease, color .22s ease;
    height: 100vh;
    height: 100dvh;
    min-height: -webkit-fill-available;
    overflow: hidden;
    color-scheme: light;
}

body.loyalcard-body.dark-mode {
    color-scheme: dark;
}

.loyalcard-body h1:not(#cardBusinessName),
.loyalcard-body h2,
.loyalcard-body h3,
.loyalcard-body .brand,
.loyalcard-body .modal-box h2,
.loyalcard-body .menu-category,
.loyalcard-body .points-count {
    font-weight: 700 !important;
}

.loyalcard-body .brand {
    font-weight: 800 !important;
}

.loyalcard-body #cardBusinessName {
    font-weight: 900 !important;
}

button,
input,
select {
    font: inherit;
}

button {
    color: inherit;
}

.app-shell {
    height: 100vh;
    height: 100dvh;
    min-height: -webkit-fill-available;
    background: var(--bg);
    overflow: hidden;
}

.topbar {
    position: fixed;
    z-index: 100;
    top: 0;
    left: 0;
    right: 0;
    height: calc(64px + env(safe-area-inset-top));
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: env(safe-area-inset-top) max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left));
    background: var(--card);
    background: color-mix(in srgb, var(--card) 92%, transparent);
    border-bottom: 1px solid var(--border);
    backdrop-filter: blur(22px);
    -webkit-backdrop-filter: blur(22px);
}

.brand {
    border: 0;
    background: transparent;
    color: var(--text);
    font-size: 21px;
    font-weight: 800;
    cursor: pointer;
    padding: 8px 0;
}

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

.icon-btn {
    width: 40px;
    height: 40px;
    border: 1px solid var(--border);
    border-radius: 15px;
    background: var(--card-soft);
    color: var(--text);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    cursor: pointer;
    box-shadow: 0 1px 0 rgba(255, 255, 255, .04) inset;
}

body:not(.dark-mode) .icon-btn {
    background: rgba(255, 255, 255, .9);
    box-shadow: 0 7px 20px rgba(16, 24, 40, .08), 0 1px 0 rgba(255, 255, 255, .9) inset;
}

.content {
    position: fixed;
    top: calc(64px + env(safe-area-inset-top));
    right: 0;
    bottom: calc(76px + env(safe-area-inset-bottom));
    left: 0;
    width: 100%;
    max-width: 500px;
    margin: 0 auto;
    padding: 12px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.card-wrap {
    perspective: 1200px;
    padding: 0;
}

.flip {
    position: relative;
    height: 240px;
    flex: 0 0 240px;
    transform-style: preserve-3d;
    transition: none;
    transform-origin: center;
}

.flip.active {
    transform: none;
}

.flip.is-flipping {
    animation: loyalcardFlip .62s cubic-bezier(.2, .78, .22, 1);
}

@keyframes loyalcardFlip {
    0% {
        transform: perspective(1200px) rotateY(0deg) translateY(0) scale(1);
        filter: brightness(1);
    }

    44% {
        transform: perspective(1200px) rotateY(62deg) translateY(-1px) scale(.996);
        filter: brightness(.95);
    }

    56% {
        transform: perspective(1200px) rotateY(82deg) translateY(-1px) scale(.996);
        filter: brightness(.95);
    }

    100% {
        transform: perspective(1200px) rotateY(0deg) translateY(0) scale(1);
        filter: brightness(1);
    }
}

.loyal-card {
    position: absolute;
    inset: 0;
    border-radius: 28px;
    overflow: hidden;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    box-shadow: none;
    transition: opacity .26s ease, visibility .26s ease;
}

.front {
    background: #151515 center / cover no-repeat;
    color: #fff;
    padding: 22px;
}

.front .card-shade {
    position: absolute;
    inset: 0;
    background: linear-gradient(180deg, rgba(0, 0, 0, .14), rgba(0, 0, 0, .76));
    z-index: 1;
}

.front > *:not(.card-shade) {
    position: relative;
    z-index: 2;
}

.business-chip {
    display: inline-flex;
    align-items: center;
    gap: 9px;
    max-width: calc(100% - 118px);
    min-height: 42px;
    padding: 5px 12px 5px 5px;
    border-radius: 18px;
    background: rgba(255, 255, 255, .16);
    backdrop-filter: blur(12px);
    font-size: 13px;
    font-weight: 800;
}

.business-chip img {
    width: 32px;
    height: 32px;
    border-radius: 12px;
    object-fit: cover;
    background: #fff;
}

.timer {
    position: absolute;
    top: 16px;
    right: 16px;
    min-width: 92px;
    height: 42px;
    padding: 0 14px;
    border-radius: 18px;
    background: rgba(255, 255, 255, .16);
    backdrop-filter: blur(12px);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 800;
}

/* Hard overrides: the site may still have old snippets/custom CSS with generic
   names like .front, .timer or .username. These ID-scoped rules keep the card
   layout stable inside WordPress. */
.loyalcard-body #card {
    position: absolute !important;
    display: block !important;
    padding: 0 !important;
    transform: none !important;
    backface-visibility: hidden !important;
    -webkit-backface-visibility: hidden !important;
}

.loyalcard-body #backCard {
    transform: none !important;
    backface-visibility: hidden !important;
    -webkit-backface-visibility: hidden !important;
    z-index: 3;
}

.loyalcard-body #flip.active #card {
    opacity: 0 !important;
    visibility: hidden !important;
    pointer-events: none !important;
}

.loyalcard-body #flip.active #backCard {
    opacity: 1 !important;
    visibility: visible !important;
    pointer-events: auto !important;
}

.loyalcard-body #timerBadge {
    position: absolute !important;
    top: 18px !important;
    right: 18px !important;
    left: auto !important;
    bottom: auto !important;
    width: auto !important;
    min-width: 94px !important;
    max-width: 130px !important;
    height: 40px !important;
    padding: 0 12px !important;
    border-radius: 18px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    white-space: nowrap !important;
    font-size: 13px !important;
    line-height: 1 !important;
}

.loyalcard-body #card .business-chip {
    position: absolute !important;
    top: 18px !important;
    left: 18px !important;
    right: auto !important;
    bottom: auto !important;
    max-width: calc(100% - 170px) !important;
}

.loyalcard-body #cardBusinessName {
    position: absolute !important;
    left: 22px !important;
    right: 22px !important;
    top: auto !important;
    bottom: 66px !important;
    margin: 0 !important;
    max-width: calc(100% - 44px) !important;
    font-size: 30px !important;
    line-height: 1.02 !important;
    font-weight: 900 !important;
}

.loyalcard-body #cardBusinessDescription {
    position: absolute !important;
    left: 22px !important;
    right: 22px !important;
    top: auto !important;
    bottom: 44px !important;
    margin: 0 !important;
    max-width: calc(100% - 44px) !important;
    font-size: 14px !important;
    line-height: 1.35 !important;
}

.loyalcard-body #username {
    position: absolute !important;
    left: 22px !important;
    right: 22px !important;
    top: auto !important;
    bottom: 20px !important;
    font-size: 17px !important;
    line-height: 1.1 !important;
    font-weight: 800 !important;
}

.front h1 {
    position: absolute;
    left: 22px;
    right: 22px;
    top: 82px;
    margin: 0;
    max-width: 320px;
    font-size: 27px;
    line-height: 1.04;
    font-weight: 900;
}

.front p {
    position: absolute;
    left: 22px;
    right: 22px;
    top: 144px;
    margin: 0;
    max-width: 300px;
    font-size: 14px;
    line-height: 1.42;
    opacity: .86;
}

.username {
    position: absolute;
    left: 22px;
    bottom: 20px;
    font-size: 18px;
    font-weight: 800;
}

.back {
    transform: none;
    background: #fff;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 10px 18px;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.flip.active .front {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.flip.active .back {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

.qr-box {
    width: clamp(194px, 52vw, 216px);
    height: clamp(194px, 52vw, 216px);
    max-width: 216px;
    max-height: 216px;
    background: #fff;
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4px;
}

.qr-box img,
.qr-box canvas {
    width: 100% !important;
    height: 100% !important;
}

.qr-state {
    display: none;
    min-height: 0;
    margin-top: 0;
    color: #555;
    font-size: 12px;
    font-weight: 700;
}

.primary-action {
    width: 100%;
    height: 58px;
    margin-top: 14px;
    border: 0;
    border-radius: 20px;
    background: var(--text);
    color: var(--bg);
    display: grid;
    grid-template-columns: 32px 1fr 32px;
    align-items: center;
    padding: 0 18px;
    font-size: 15px;
    font-weight: 900;
    cursor: pointer;
    box-shadow: 0 10px 24px rgba(0, 0, 0, .16);
}

body:not(.dark-mode) .primary-action {
    background: linear-gradient(180deg, #ffb13b 0%, var(--orange) 100%);
    color: #17130a;
    box-shadow: 0 8px 18px rgba(255, 159, 10, .18);
}

.primary-action span {
    text-align: center;
    white-space: nowrap;
}

.points-card {
    margin-top: 14px;
    padding: 16px;
    border: 1px solid var(--border);
    border-radius: 24px;
    background: var(--card);
    box-shadow: 0 1px 0 rgba(255, 255, 255, .04) inset;
}

body:not(.dark-mode) .points-card,
body:not(.dark-mode) .modal-box,
body:not(.dark-mode) .business-select,
body:not(.dark-mode) .input {
    box-shadow: 0 10px 26px rgba(16, 24, 40, .06);
}

.points-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 16px;
}

.muted-label {
    color: var(--muted);
    font-size: 13px;
    line-height: 1.35;
    font-weight: 800;
}

.small-hint {
    margin-top: 4px;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.35;
}

.points-count {
    flex: 0 0 auto;
    font-size: 22px;
    line-height: 1;
    font-weight: 900;
}

.stars-wrap {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 9px;
    margin-bottom: 14px;
}

.point-dot {
    min-height: 42px;
    aspect-ratio: 1;
    min-width: 0;
    border: 2px dashed rgba(17, 19, 24, .2);
    border-radius: 50%;
    border: 2px dashed color-mix(in srgb, var(--text) 20%, transparent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 900;
}

.point-dot i {
    font-size: 22px;
}

.point-dot.point-style-emoji {
    font-size: 21px;
    line-height: 1;
}

.point-dot.point-style-stars i {
    color: var(--gold);
    filter: drop-shadow(0 2px 5px rgba(245, 180, 0, .22));
}

.point-dot.active {
    background: #fff;
    color: #111;
    border-color: #fff;
}

body:not(.dark-mode) .point-dot.active {
    background: #fff;
    color: #344054;
    border-color: #d0d5dd;
    box-shadow: 0 7px 16px rgba(16, 24, 40, .09);
}

.info-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 15px 0;
    border-bottom: 1px solid var(--border);
    font-size: 15px;
}

.info-row:last-child {
    border-bottom: 0;
    padding-bottom: 0;
}

.info-row i {
    margin-right: 8px;
    color: var(--muted);
}

.gold {
    color: var(--gold);
    font-weight: 900;
}

.bottom-nav {
    position: fixed;
    z-index: 100;
    left: 0;
    right: 0;
    bottom: 0;
    height: calc(76px + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: var(--card);
    background: color-mix(in srgb, var(--card) 94%, transparent);
    border-top: 1px solid var(--border);
    backdrop-filter: blur(22px);
    -webkit-backdrop-filter: blur(22px);
    display: grid;
    grid-template-columns: repeat(5, 1fr);
}

.bottom-item {
    border: 0;
    background: transparent;
    color: var(--muted);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    font-size: 11px;
    font-weight: 800;
    cursor: pointer;
}

.bottom-item i {
    font-size: 20px;
}

.bottom-item.active {
    color: var(--gold);
}

.bottom-item.is-disabled,
.bottom-item:disabled {
    opacity: .38;
    cursor: default;
}

.modal {
    position: fixed;
    z-index: 1000;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: rgba(0, 0, 0, .66);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.modal.active {
    display: flex;
}

.modal-box {
    position: relative;
    width: 100%;
    max-width: 400px;
    max-height: calc(100vh - 32px);
    overflow: auto;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 26px;
    padding: 22px 20px 20px;
    box-shadow: var(--shadow);
}

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

#settingsModal .modal-box {
    padding: 20px 18px 18px;
}

.modal-box.tall {
    height: min(80vh, 680px);
    display: flex;
    flex-direction: column;
}

.modal-box h2 {
    margin: 0 0 14px;
    font-size: 26px;
    line-height: 1.1;
    font-weight: 900;
}

.modal-close {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 34px;
    height: 34px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--card-soft);
    color: var(--text);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.modal-copy {
    margin: 0 0 18px;
    color: var(--muted);
    line-height: 1.55;
}

.stack {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.offer-item {
    padding: 15px;
    border-radius: 18px;
    background: var(--card-soft);
}

.offer-item strong {
    display: block;
    margin-bottom: 7px;
}

.offer-item span {
    display: block;
    color: var(--muted);
    font-size: 14px;
    line-height: 1.45;
}

.review-stars {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-bottom: 18px;
}

.review-star {
    width: 44px;
    height: 44px;
    border: 0;
    border-radius: 14px;
    background: var(--card-soft);
    color: var(--gold);
    font-size: 26px;
    cursor: pointer;
}

.muted-text {
    color: var(--muted);
    font-size: 14px;
}

.menu-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    overflow: visible;
    padding-bottom: 6px;
    margin-bottom: 14px;
}

.menu-tab {
    flex: 0 1 auto;
    border: 0;
    border-radius: 14px;
    padding: 9px 13px;
    background: var(--card-soft);
    color: var(--text);
    font-size: 14px;
    font-weight: 900;
    cursor: pointer;
}

.menu-tab.active {
    background: var(--gold);
    color: #000;
}

.menu-content {
    display: none;
    overflow-y: auto;
    padding-right: 4px;
    flex: 1;
}

.menu-content.active {
    display: block;
}

.menu-contents {
    min-height: 0;
    flex: 1;
    overflow: hidden;
}

.menu-empty {
    height: 100%;
    min-height: 180px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--muted);
    text-align: center;
    font-weight: 700;
}

.support-link {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 9px;
    min-height: 52px;
    margin-top: 14px;
    border-radius: 17px;
    background: #229ed9;
    color: #fff;
    text-decoration: none;
    font-weight: 800;
    flex: 0 0 auto;
}

.support-link[hidden] {
    display: none !important;
}

.menu-category {
    font-size: 22px;
    font-weight: 900;
    margin-bottom: 8px;
}

.telegram-cta,
.login-link {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    min-height: 50px;
    border-radius: 15px;
    background: var(--blue);
    color: #fff;
    text-decoration: none;
    font-weight: 900;
}

#loginBtn[hidden],
.login-link[hidden] {
    display: none !important;
}

.field-label {
    display: block;
    margin-bottom: 7px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 800;
}

.input {
    width: 100%;
    height: 50px;
    border: 1px solid var(--border);
    border-radius: 15px;
    background: var(--card-soft);
    color: var(--text);
    padding: 0 14px;
    font-size: 16px;
    margin-bottom: 9px;
}

.business-select {
    width: 100%;
    min-height: 60px;
    border: 1px solid var(--border);
    border-radius: 16px;
    background: var(--card-soft);
    color: var(--text);
    padding: 9px 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    cursor: pointer;
    margin-bottom: 10px;
}

.support-link {
    min-height: 50px;
    margin: 0 0 10px;
    border-radius: 15px;
}

#businessSelectLabel {
    margin-top: 2px;
}

.business-select-main {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
    text-align: left;
}

.business-select-main img {
    width: 40px;
    height: 40px;
    flex: 0 0 auto;
    border-radius: 14px;
    object-fit: cover;
    background: #fff;
}

.business-select-main strong,
.business-select-main small {
    display: block;
}

.business-select-main strong {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 240px;
}

.business-select-main small {
    color: var(--muted);
    margin-top: 2px;
}

.save-btn {
    width: 100%;
    height: 50px;
    border: 0;
    border-radius: 15px;
    background: var(--text);
    color: var(--bg);
    font-size: 17px;
    font-weight: 900;
    cursor: pointer;
    margin-bottom: 10px;
}

.business-search {
    margin-bottom: 10px;
}

.category-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    overflow: visible;
    padding-bottom: 8px;
    margin-bottom: 10px;
}

.category-filter {
    flex: 0 1 auto;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--card-soft);
    color: var(--text);
    min-height: 36px;
    padding: 0 13px;
    font-size: 13px;
    font-weight: 900;
    cursor: pointer;
}

.category-filter.active {
    background: var(--gold);
    border-color: var(--gold);
    color: #000;
}

.business-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-height: min(52vh, 430px);
    overflow-y: auto;
    padding-right: 3px;
}

.business-item {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 18px;
    background: var(--card-soft);
    color: var(--text);
    padding: 12px;
    display: flex;
    align-items: center;
    gap: 12px;
    text-align: left;
    cursor: pointer;
}

.business-item.selected {
    border-color: var(--gold);
    box-shadow: inset 0 0 0 1px var(--gold);
}

.business-item img {
    width: 44px;
    height: 44px;
    border-radius: 14px;
    object-fit: cover;
    background: #fff;
}

.business-item strong,
.business-item small {
    display: block;
}

.business-item small {
    margin-top: 3px;
    color: var(--muted);
}

.empty-list {
    display: none;
    padding: 18px;
    color: var(--muted);
    text-align: center;
    border: 1px dashed var(--border);
    border-radius: 18px;
}

.empty-list.active {
    display: block;
}

.toast {
    position: fixed;
    z-index: 1200;
    left: 50%;
    bottom: 92px;
    transform: translateX(-50%) translateY(16px);
    min-width: min(320px, calc(100vw - 32px));
    max-width: calc(100vw - 32px);
    padding: 13px 16px;
    border-radius: 16px;
    background: #111;
    color: #fff;
    text-align: center;
    font-weight: 800;
    opacity: 0;
    pointer-events: none;
    transition: opacity .18s ease, transform .18s ease;
}

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

@media (max-width: 380px) {
    .front h1 {
        font-size: 24px;
    }

    .front p {
        top: 138px;
        font-size: 13px;
    }

    .timer {
        min-width: 78px;
        padding: 0 10px;
    }

    .business-chip {
        max-width: calc(100% - 96px);
    }
}

@media (max-width: 430px) {
    .loyalcard-body #cardBusinessName {
        bottom: 94px !important;
        font-size: 24px !important;
        line-height: 1.05 !important;
        max-height: 52px !important;
        overflow: hidden !important;
        display: -webkit-box !important;
        -webkit-line-clamp: 2 !important;
        -webkit-box-orient: vertical !important;
    }

    .loyalcard-body #cardBusinessDescription {
        bottom: 52px !important;
        font-size: 13px !important;
        line-height: 1.28 !important;
        max-height: 36px !important;
        overflow: hidden !important;
        display: -webkit-box !important;
        -webkit-line-clamp: 2 !important;
        -webkit-box-orient: vertical !important;
    }

    .loyalcard-body #username {
        bottom: 20px !important;
        font-size: 16px !important;
    }
}

@media (max-height: 740px) {
    .flip {
        height: 226px;
        flex-basis: 226px;
    }

    .qr-box {
        width: clamp(190px, 50vw, 204px);
        height: clamp(190px, 50vw, 204px);
        max-width: 204px;
        max-height: 204px;
    }

    .points-card {
        padding: 14px;
    }

    .stars-wrap {
        gap: 7px;
        margin-bottom: 10px;
    }

    .info-row {
        padding: 12px 0;
    }
}
