:root {
    --bg: #070302;
    --surface: rgba(16, 10, 8, 0.86);
    --surface-strong: rgba(26, 13, 10, 0.94);
    --surface-soft: rgba(177, 137, 82, 0.1);
    --ink: #e8d8b8;
    --muted: #a99068;
    --line: rgba(177, 137, 82, 0.28);
    --accent: #9f1714;
    --accent-strong: #c33b2f;
    --gold: #c6a36a;
    --gold-soft: #7d6541;
    --warn: #d4a247;
    --bad: #c94a3d;
    --shadow: 0 18px 52px rgba(0, 0, 0, 0.55);
}

* {
    box-sizing: border-box;
}

html,
body {
    min-height: 100%;
    margin: 0;
}

body {
    position: relative;
    overflow-x: hidden;
    padding: max(14px, env(safe-area-inset-top)) 12px max(18px, env(safe-area-inset-bottom));
    color: var(--ink);
    background:
        linear-gradient(90deg, rgba(0, 0, 0, 0.9), rgba(20, 4, 3, 0.62), rgba(0, 0, 0, 0.92)),
        image-set(url("/mini-app/static/backstage-reference.png") 1x);
    background-color: var(--bg);
    background-position: center top;
    background-size: cover;
    background-attachment: fixed;
    font-family: "Georgia", "Times New Roman", serif;
}

body::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: -1;
    pointer-events: none;
    background:
        linear-gradient(180deg, rgba(0, 0, 0, 0.22), rgba(0, 0, 0, 0.94)),
        repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.025) 0 1px, transparent 1px 5px);
    mix-blend-mode: multiply;
}

body::after {
    content: "";
    position: fixed;
    inset: 0;
    z-index: -1;
    pointer-events: none;
    background:
        radial-gradient(circle at 50% 0%, rgba(195, 59, 47, 0.2), transparent 34%),
        radial-gradient(circle at 50% 78%, rgba(198, 163, 106, 0.1), transparent 36%);
}

button,
input,
textarea {
    font: inherit;
}

a {
    color: inherit;
}

.app-shell {
    display: grid;
    gap: 12px;
    max-width: 920px;
    margin: 0 auto;
}

.topbar,
.profile-panel,
.panel,
.metric,
.plan-card,
.order-card,
.segmented,
.support-strip {
    border: 1px solid var(--line);
    border-radius: 8px;
    background:
        linear-gradient(180deg, rgba(30, 16, 11, 0.94), rgba(8, 4, 3, 0.9)),
        var(--surface);
    box-shadow: var(--shadow), inset 0 1px 0 rgba(255, 244, 211, 0.08);
    backdrop-filter: blur(10px);
}

.topbar {
    position: sticky;
    top: max(10px, env(safe-area-inset-top));
    z-index: 5;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px;
}

.brand-lockup,
.profile-main {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.brand-mark,
.avatar {
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    width: 44px;
    height: 44px;
    border: 1px solid rgba(198, 163, 106, 0.58);
    border-radius: 8px;
    color: var(--gold);
    background:
        radial-gradient(circle at 50% 35%, rgba(198, 163, 106, 0.18), transparent 42%),
        #0a0504;
    font-family: "Impact", "Arial Narrow", sans-serif;
    font-weight: 900;
    letter-spacing: 0;
    text-shadow: 0 0 18px rgba(198, 163, 106, 0.3);
}

.brand-name {
    overflow: hidden;
    color: var(--gold);
    font-family: "Impact", "Arial Narrow", sans-serif;
    font-size: 24px;
    font-weight: 900;
    letter-spacing: 0;
    line-height: 0.95;
    text-transform: uppercase;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.brand-subtitle,
.muted {
    color: var(--muted);
    font-family: "Avenir Next", "Segoe UI", sans-serif;
    font-size: 13px;
}

.icon-button {
    display: grid;
    place-items: center;
    width: 42px;
    height: 42px;
    border: 1px solid rgba(159, 23, 20, 0.74);
    border-radius: 50%;
    color: var(--accent-strong);
    background: rgba(10, 5, 4, 0.78);
    font-size: 20px;
    font-weight: 900;
    cursor: pointer;
}

.profile-panel {
    position: relative;
    display: grid;
    gap: 16px;
    min-height: 230px;
    padding: 20px;
    overflow: hidden;
}

.profile-panel::before {
    content: "";
    position: absolute;
    inset: 0;
    z-index: -1;
    background:
        linear-gradient(90deg, rgba(0, 0, 0, 0.42), rgba(0, 0, 0, 0.05)),
        url("/mini-app/static/backstage-reference.png");
    background-position: 60% 36%;
    background-size: cover;
    opacity: 0.42;
}

.profile-panel::after {
    content: "";
    position: absolute;
    left: 20px;
    right: 20px;
    bottom: 16px;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--gold-soft), transparent);
}

.avatar {
    width: 70px;
    height: 70px;
    object-fit: cover;
    color: #100704;
    background:
        radial-gradient(circle at 50% 36%, #f3d9a4, #9f7845 62%, #2a140c 100%);
    font-size: 24px;
}

.profile-copy {
    min-width: 0;
}

.profile-copy h1 {
    margin: 0;
    overflow: hidden;
    color: var(--ink);
    font-size: clamp(30px, 8vw, 58px);
    font-weight: 700;
    line-height: 0.95;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-shadow: 0 2px 24px rgba(0, 0, 0, 0.85);
}

.profile-copy p {
    margin: 8px 0 0;
    color: var(--muted);
    font-family: "Avenir Next", "Segoe UI", sans-serif;
    overflow-wrap: anywhere;
}

.status-badge,
.mini-badge {
    display: inline-flex;
    width: fit-content;
    align-items: center;
    border-radius: 8px;
    padding: 7px 10px;
    font-family: "Avenir Next", "Segoe UI", sans-serif;
    font-size: 12px;
    font-weight: 850;
}

.status-badge {
    border: 1px solid rgba(198, 163, 106, 0.34);
    color: var(--gold);
    background: rgba(7, 3, 2, 0.72);
}

.status-badge.active {
    color: #e9c978;
    background: rgba(64, 45, 17, 0.78);
}

.status-badge.pending {
    color: var(--warn);
    background: rgba(85, 50, 10, 0.72);
}

.status-badge.cancelled,
.status-badge.expired {
    color: #ff9a8f;
    background: rgba(84, 14, 11, 0.72);
}

.mini-badge {
    border: 1px solid rgba(198, 163, 106, 0.28);
    color: var(--gold);
    background: rgba(198, 163, 106, 0.08);
}

.metrics-grid {
    display: grid;
    gap: 10px;
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.metric {
    display: grid;
    gap: 8px;
    min-height: 92px;
    padding: 14px;
}

.metric span {
    color: var(--muted);
    font-family: "Avenir Next", "Segoe UI", sans-serif;
    font-size: 12px;
}

.metric strong {
    overflow: hidden;
    color: var(--ink);
    font-size: 22px;
    line-height: 1;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.panel {
    padding: 16px;
}

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

.panel-head h2 {
    margin: 0;
    color: var(--gold);
    font-size: 23px;
    line-height: 1;
}

.subscription-content,
.empty-state {
    display: grid;
    gap: 10px;
    color: var(--muted);
    font-family: "Avenir Next", "Segoe UI", sans-serif;
    line-height: 1.45;
}

.subscription-url {
    overflow-wrap: anywhere;
    border: 1px solid rgba(198, 163, 106, 0.24);
    border-radius: 8px;
    padding: 12px;
    color: #f2dfb8;
    background: rgba(0, 0, 0, 0.5);
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 12px;
}

.quick-actions,
.support-strip {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.segmented {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 5px;
    padding: 5px;
    background: rgba(8, 4, 3, 0.86);
}

.segment {
    min-height: 42px;
    border: 1px solid transparent;
    border-radius: 7px;
    color: var(--muted);
    background: transparent;
    font-family: "Avenir Next", "Segoe UI", sans-serif;
    font-weight: 850;
    cursor: pointer;
}

.segment.active {
    border-color: rgba(159, 23, 20, 0.66);
    color: #f0d9af;
    background:
        linear-gradient(180deg, rgba(159, 23, 20, 0.52), rgba(57, 8, 7, 0.62));
    box-shadow: inset 0 1px 0 rgba(255, 224, 180, 0.12);
}

.view {
    display: none;
}

.view.active {
    display: grid;
    gap: 12px;
}

.plans,
.orders {
    display: grid;
    gap: 10px;
}

.orders.empty {
    padding: 16px;
    border: 1px dashed rgba(198, 163, 106, 0.34);
    border-radius: 8px;
    color: var(--muted);
    background: rgba(8, 4, 3, 0.72);
    font-family: "Avenir Next", "Segoe UI", sans-serif;
}

.plan-card,
.order-card {
    display: grid;
    gap: 12px;
    padding: 15px;
}

.plan-card.selected {
    border-color: rgba(195, 59, 47, 0.76);
    box-shadow: 0 16px 48px rgba(159, 23, 20, 0.24), inset 0 0 0 1px rgba(198, 163, 106, 0.16);
}

.plan-top,
.order-top,
.order-meta {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
}

.plan-card h3 {
    margin: 8px 0 4px;
    color: var(--ink);
    font-size: 30px;
    line-height: 0.96;
}

.plan-price {
    color: var(--gold);
    font-size: 23px;
    font-weight: 900;
    line-height: 1;
    white-space: nowrap;
}

.order-top strong {
    color: var(--ink);
    font-size: 21px;
}

.order-meta {
    justify-content: flex-start;
    flex-wrap: wrap;
    color: var(--muted);
    font-family: "Avenir Next", "Segoe UI", sans-serif;
    font-size: 13px;
}

.order-link {
    color: var(--gold);
    overflow-wrap: anywhere;
    font-family: "Avenir Next", "Segoe UI", sans-serif;
    font-weight: 800;
}

.order-form {
    display: grid;
    gap: 11px;
}

label {
    display: grid;
    gap: 7px;
}

label span {
    color: var(--muted);
    font-family: "Avenir Next", "Segoe UI", sans-serif;
    font-size: 12px;
    font-weight: 800;
}

input,
textarea {
    width: 100%;
    border: 1px solid rgba(198, 163, 106, 0.28);
    border-radius: 8px;
    padding: 12px 13px;
    color: var(--ink);
    background: rgba(3, 1, 1, 0.66);
}

input::placeholder,
textarea::placeholder {
    color: rgba(169, 144, 104, 0.7);
}

textarea {
    resize: vertical;
}

.primary-button,
.secondary-button {
    display: inline-flex;
    min-height: 42px;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    padding: 11px 14px;
    font-family: "Avenir Next", "Segoe UI", sans-serif;
    font-weight: 900;
    text-decoration: none;
    cursor: pointer;
}

.primary-button {
    border: 1px solid rgba(198, 163, 106, 0.42);
    color: #fbe9c2;
    background:
        linear-gradient(180deg, rgba(195, 59, 47, 0.95), rgba(103, 12, 10, 0.95));
    box-shadow: inset 0 1px 0 rgba(255, 224, 180, 0.2);
}

.secondary-button {
    border: 1px solid rgba(198, 163, 106, 0.32);
    color: var(--gold);
    background: rgba(0, 0, 0, 0.44);
}

.compact {
    min-height: 38px;
    padding: 9px 12px;
}

.primary-button:disabled {
    cursor: not-allowed;
    opacity: 0.48;
}

.support-strip {
    justify-content: space-between;
    padding: 12px 14px;
}

.support-strip a {
    color: var(--gold);
    font-family: "Avenir Next", "Segoe UI", sans-serif;
    font-weight: 900;
    text-decoration: none;
}

@media (min-width: 760px) {
    body {
        padding-top: 20px;
    }

    .profile-panel {
        grid-template-columns: minmax(0, 1fr) auto;
        align-items: center;
    }

    .plans {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 560px) {
    body {
        background-position: 58% top;
        background-size: auto 100vh;
    }

    .metrics-grid {
        grid-template-columns: 1fr;
    }

    .profile-main {
        align-items: flex-start;
        flex-direction: column;
    }

    .profile-copy h1 {
        white-space: normal;
    }

    .plan-top,
    .order-top {
        align-items: stretch;
        flex-direction: column;
    }

    .plan-price {
        white-space: normal;
    }

    .quick-actions .primary-button,
    .quick-actions .secondary-button,
    .plan-card .secondary-button {
        width: 100%;
    }
}
