:root {
    --bg: #12131b;
    --checkout-bar-height: 40px;
    --bg-raised: #1a1c27;
    --bg-card: #20232f;
    --border: #323748;
    --text: #f1f2f7;
    --text-muted: #9ba3b8;
    --gold: #f2b33d;
    --gold-strong: #ffd36e;
    --gold-text: #241703;
    --buy: #4cc35c;
    --buy-strong: #5fd86f;
    --buy-text: #08230d;
    --danger: #ff6b6b;
    --success: #4fd18b;
    --warn: #f5a524;
    --sandbox: #7c4dff;
    --tint: #5b6fb3;
    --radius: 14px;
    color-scheme: dark;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background:
        radial-gradient(1200px 600px at 50% -200px, rgba(124, 77, 255, 0.16), transparent 70%),
        var(--bg);
    color: var(--text);
    font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    min-height: 100vh;
}

button,
input,
select {
    font: inherit;
    color: inherit;
}

button {
    cursor: pointer;
}

button:disabled {
    cursor: progress;
    opacity: 0.6;
}

code {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

h3 {
    margin: 0;
    line-height: 1.2;
}

.sandbox-bar {
    background: var(--sandbox);
    color: #fff;
    font-size: 13px;
    padding: 6px 16px;
    text-align: center;
}

.sandbox-bar[hidden],
.country[hidden] {
    display: none;
}

.sandbox-bar a {
    color: #fff;
    font-weight: 700;
}

.sandbox-bar code {
    background: rgba(0, 0, 0, 0.25);
    border-radius: 4px;
    padding: 1px 6px;
}

/* ----- Game art ----- */

.store-page::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: -1;
    background:
        linear-gradient(180deg, rgba(18, 19, 27, 0.85) 0%, rgba(18, 19, 27, 0.5) 40%, rgba(18, 19, 27, 0.8) 75%, var(--bg) 100%),
        url("art/background.webp") center 20% / cover no-repeat;
}

.store-page.logged-out::before {
    background:
        linear-gradient(180deg, rgba(18, 19, 27, 0.55) 0%, rgba(18, 19, 27, 0.25) 45%, rgba(18, 19, 27, 0.85) 100%),
        url("art/background.webp") center 20% / cover no-repeat;
}

.logged-out .topbar {
    display: none;
}

/* ----- Top bar + tabs ----- */

.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    background: rgba(22, 24, 34, 0.82);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
}

.topbar-row {
    display: flex;
    flex-wrap: wrap;
    gap: 12px 24px;
    align-items: center;
    justify-content: space-between;
    max-width: 1100px;
    margin: 0 auto;
    padding: 12px 16px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 15px;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.brand img {
    height: 44px;
    width: auto;
    filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.6));
}

.brand span {
    color: var(--gold-strong);
}

.player {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px 14px;
}

.player[hidden] {
    display: none;
}

.player-name {
    font-weight: 700;
}

.player-meta {
    color: var(--text-muted);
    font-size: 12px;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.gems {
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 4px 12px 4px 6px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.gems img {
    width: 24px;
    height: 24px;
    object-fit: contain;
}

.country {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--text-muted);
    font-size: 13px;
}

select,
input {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 6px 10px;
}

select {
    max-width: 200px;
}

.ghost {
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 6px 12px;
}

.ghost:hover {
    background: var(--bg-card);
}

.tabs {
    display: flex;
    gap: 4px;
    max-width: 1100px;
    margin: 0 auto;
    padding: 0 16px;
    overflow-x: auto;
    scrollbar-width: none;
}

.tabs[hidden] {
    display: none;
}

.tab {
    position: relative;
    flex: none;
    display: flex;
    align-items: center;
    gap: 8px;
    background: none;
    border: 0;
    border-bottom: 3px solid transparent;
    padding: 10px 16px 9px;
    color: var(--text-muted);
    font-weight: 700;
    letter-spacing: 0.02em;
}

.tab:hover {
    color: var(--text);
}

.tab.active {
    color: var(--gold-strong);
    border-bottom-color: var(--gold);
}

.tab-new {
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    border-radius: 999px;
    background: var(--danger);
    color: #fff;
    font-size: 11px;
    line-height: 20px;
    text-align: center;
}

/* ----- Login ----- */

main {
    max-width: 1100px;
    margin: 0 auto;
    padding: 20px 16px 120px;
}

.login {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 24px;
    min-height: 60vh;
}

.login-logo {
    width: min(340px, 80vw);
    height: auto;
    filter: drop-shadow(0 6px 18px rgba(0, 0, 0, 0.7));
}

.store-page .login {
    min-height: calc(100vh - 140px);
}

.store-page .login-card {
    background: rgba(26, 28, 39, 0.82);
    backdrop-filter: blur(10px);
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
}

.login[hidden] {
    display: none;
}

.login-card {
    width: min(420px, 100%);
    display: grid;
    gap: 12px;
    background: var(--bg-raised);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 28px;
}

.login-card h1 {
    margin: 0;
    font-size: 24px;
}

.login-card p {
    margin: 0;
    color: var(--text-muted);
}

.login-card input {
    padding: 10px 12px;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.primary {
    background: var(--gold);
    color: var(--gold-text);
    border: 0;
    border-radius: 10px;
    padding: 10px 16px;
    font-weight: 800;
}

.form-error {
    color: var(--danger) !important;
    min-height: 1.4em;
}

.form-error:empty {
    display: none;
}

.game-login-steps {
    display: grid;
    gap: 12px;
    justify-items: center;
    text-align: center;
}

.game-login-steps[hidden] {
    display: none;
}

.qr {
    background: #fff;
    border-radius: 12px;
    padding: 12px;
    line-height: 0;
}

.qr[hidden] {
    display: none;
}

.qr-fallback {
    display: block;
    max-width: 260px;
    color: #111;
    font-size: 12px;
    line-height: 1.4;
    word-break: break-all;
}

.hint {
    font-size: 14px;
}

.link-button {
    display: block;
    width: 100%;
    text-align: center;
    text-decoration: none;
}

.link-button[hidden] {
    display: none;
}

.code-form {
    display: flex;
    gap: 8px;
    justify-self: stretch;
}

.code-form input {
    flex: 1;
    width: 100%;
    min-width: 0;
}

#code-input {
    font: 700 24px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
    letter-spacing: 0.4em;
    text-align: center;
}

.link {
    background: none;
    border: 0;
    color: var(--text-muted);
    text-decoration: underline;
    font-size: 13px;
}

.dev-login {
    border-top: 1px solid var(--border);
    padding-top: 12px;
    color: var(--text-muted);
    font-size: 13px;
}

.dev-login[hidden] {
    display: none;
}

.dev-login summary {
    cursor: pointer;
    margin-bottom: 10px;
}

/* ----- Page + shared card parts ----- */

.page {
    display: grid;
    gap: 14px;
}

.card {
    position: relative;
    background:
        linear-gradient(135deg, color-mix(in srgb, var(--tint) 28%, transparent), transparent 60%),
        var(--bg-card);
    border: 1px solid color-mix(in srgb, var(--tint) 45%, var(--border));
    border-radius: var(--radius);
}

.ribbon {
    position: absolute;
    top: 12px;
    left: -6px;
    z-index: 2;
    background: linear-gradient(180deg, #e34b4b, #b52a2a);
    color: #fff;
    font-size: 12px;
    font-weight: 800;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    padding: 4px 12px 4px 14px;
    border-radius: 0 6px 6px 0;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
}

.value-badge {
    position: absolute;
    top: -10px;
    right: 12px;
    z-index: 2;
    background: var(--gold);
    color: var(--gold-text);
    font-size: 12px;
    font-weight: 900;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    border-radius: 999px;
    padding: 3px 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

.pill {
    background: rgba(227, 75, 75, 0.18);
    color: #ff9b9b;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
    padding: 2px 8px;
    white-space: nowrap;
}

.desc {
    margin: 0;
    color: var(--text-muted);
    font-size: 13px;
}

.meta {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 12px;
    font-size: 12px;
    font-weight: 700;
}

.timer {
    color: var(--warn);
    font-variant-numeric: tabular-nums;
}

.timer::before {
    content: "⏱ ";
}

.stock {
    color: var(--text-muted);
}

.buy {
    background: linear-gradient(180deg, var(--buy-strong), var(--buy));
    color: var(--buy-text);
    border: 0;
    border-radius: 10px;
    padding: 10px 18px;
    font-size: 16px;
    font-weight: 900;
    white-space: nowrap;
    box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.18);
}

.buy:hover:not(:disabled) {
    filter: brightness(1.08);
}

.buy:disabled {
    background: var(--border);
    color: var(--text-muted);
}

.chips {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.chip {
    display: flex;
    align-items: center;
    gap: 4px;
    background: rgba(0, 0, 0, 0.28);
    border-radius: 8px;
    padding: 3px 8px 3px 4px;
    font-size: 13px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.chip img {
    width: 22px;
    height: 22px;
    object-fit: contain;
}

.chip.more {
    padding: 3px 8px;
    color: var(--text-muted);
}

.item-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 6px 16px;
}

.item-list li {
    display: grid;
    grid-template-columns: 30px 1fr auto;
    align-items: center;
    gap: 8px;
    font-size: 14px;
}

.item-list li.main {
    font-weight: 700;
}

.item-list img {
    width: 30px;
    height: 30px;
    object-fit: contain;
}

.item-qty {
    color: var(--gold-strong);
    font-weight: 800;
    font-variant-numeric: tabular-nums;
}

/* ----- RowBig: hero banner ----- */

.row-big {
    display: grid;
    grid-template-columns: minmax(0, 5fr) minmax(0, 6fr);
    min-height: 280px;
    overflow: visible;
}

.row-big-art {
    border-radius: var(--radius) 0 0 var(--radius);
    background-size: cover;
    background-position: center;
    -webkit-mask-image: linear-gradient(90deg, #000 70%, transparent);
    mask-image: linear-gradient(90deg, #000 70%, transparent);
}

.row-big-body {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 28px 24px 20px 8px;
}

.row-big-body .ribbon {
    position: static;
    align-self: flex-start;
    border-radius: 6px;
    padding: 4px 12px;
}

.row-big h3 {
    font-size: 26px;
}

.row-big .buy {
    align-self: flex-start;
    margin-top: auto;
    padding: 12px 32px;
    font-size: 18px;
}

/* ----- RowDefault: art + contents + price ----- */

.row {
    display: grid;
    grid-template-columns: 150px minmax(0, 1fr) auto;
    gap: 18px;
    align-items: center;
    padding: 16px 18px 16px 16px;
}

.row-art {
    width: 150px;
    height: 150px;
    display: grid;
    place-items: center;
}

.row-art img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    filter: drop-shadow(0 6px 10px rgba(0, 0, 0, 0.45));
}

.row-body {
    display: grid;
    gap: 8px;
    padding-top: 18px;
}

.row h3 {
    font-size: 19px;
}

.row-side .buy {
    min-width: 120px;
}

/* ----- RowSimple: compact row ----- */

.row-simple {
    display: grid;
    grid-template-columns: 64px minmax(0, 1fr) auto;
    gap: 14px;
    align-items: center;
    padding: 12px 16px 12px 12px;
}

.simple-art {
    width: 64px;
    height: 64px;
    display: grid;
    place-items: center;
}

.simple-art img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.simple-body {
    display: grid;
    gap: 6px;
    min-width: 0;
}

.simple-title {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 10px;
}

.row-simple h3 {
    font-size: 16px;
}

.row-simple .buy {
    min-width: 104px;
}

/* ----- GridDefault / GridItems: tiles ----- */

.tile-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 14px;
}

.tile {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 16px 14px 14px;
    text-align: center;
}

.tile-art {
    width: 100%;
    height: 128px;
    display: grid;
    place-items: center;
}

.tile-art img {
    max-width: 128px;
    max-height: 128px;
    object-fit: contain;
    filter: drop-shadow(0 6px 10px rgba(0, 0, 0, 0.45));
}

.tile h3 {
    font-size: 17px;
}

.tile .chips {
    justify-content: center;
}

.tile .buy {
    width: 100%;
    margin-top: auto;
}

/* ----- Orders, log, toast, checkout ----- */

.orders {
    margin-top: 40px;
    background: var(--bg-raised);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 20px;
}

.orders-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.orders h2 {
    margin: 0;
    font-size: 16px;
}

.orders-list {
    margin: 12px 0 0;
    padding-left: 20px;
    color: var(--text-muted);
    font-size: 13px;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.orders-list:empty {
    display: none;
}

.log {
    position: fixed;
    right: 16px;
    bottom: 16px;
    width: min(440px, calc(100vw - 32px));
    background: rgba(18, 19, 27, 0.96);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    z-index: 20;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
}

.log[hidden] {
    display: none;
}

.log.collapsed {
    width: auto;
}

.log-head {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    width: 100%;
    background: none;
    border: 0;
    padding: 10px 14px;
    font-weight: 700;
    font-size: 13px;
}

.log-head span {
    background: var(--bg-card);
    border-radius: 999px;
    padding: 0 8px;
    font-variant-numeric: tabular-nums;
}

.log.collapsed .log-list {
    display: none;
}

.log-list {
    list-style: none;
    margin: 0;
    padding: 0 14px 12px;
    max-height: 34vh;
    overflow: auto;
    font-size: 12px;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.log-list li {
    padding: 4px 0;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    word-break: break-word;
}

.log-list time {
    color: var(--text-muted);
    margin-right: 6px;
}

.log-kind {
    font-weight: 700;
    margin-right: 6px;
}

.log-kind.checkout { color: #8ab4ff; }
.log-kind.api { color: var(--text-muted); }
.log-kind.grant { color: var(--success); }
.log-kind.error { color: var(--danger); }

.log-list details summary {
    cursor: pointer;
    color: var(--text-muted);
}

.log-list pre {
    margin: 4px 0 0;
    white-space: pre-wrap;
    color: var(--text-muted);
}

.toast {
    position: fixed;
    left: 50%;
    bottom: 24px;
    transform: translateX(-50%);
    max-width: min(560px, calc(100vw - 32px));
    background: var(--bg-raised);
    border: 1px solid var(--border);
    border-left: 4px solid var(--gold);
    border-radius: 10px;
    padding: 12px 16px;
    z-index: 40;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }
.toast.warn { border-left-color: var(--warn); }

/* Our own bar keeps a way out when the checkout fails to load and never shows its own close button. */
.checkout-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 10000;
    height: var(--checkout-bar-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 0 16px;
    box-sizing: border-box;
    background: var(--bg-raised);
    border-bottom: 1px solid var(--border);
    color: var(--text);
    font-size: 13px;
    font-weight: 700;
}

.checkout-bar[hidden] {
    display: none;
}

/* AppCharge's checkout SDK places its frame at the top of the document, which a scrolled page has moved out of view,
   and the frame covers the page invisibly for the seconds the checkout takes to appear. */
body > iframe.iframe {
    position: fixed;
    top: var(--checkout-bar-height);
    height: calc(100% - var(--checkout-bar-height));
    background: rgba(0, 0, 0, 0.6);
}

.empty {
    color: var(--text-muted);
    text-align: center;
    padding: 48px 0;
}

/* ----- Narrow screens ----- */

@media (max-width: 960px) {
    .country span {
        display: none;
    }
}

@media (max-width: 720px) {

    .brand img {
        height: 34px;
    }

    .row-big {
        grid-template-columns: 1fr;
    }

    .row-big-art {
        min-height: 200px;
        border-radius: var(--radius) var(--radius) 0 0;
        -webkit-mask-image: linear-gradient(180deg, #000 70%, transparent);
        mask-image: linear-gradient(180deg, #000 70%, transparent);
    }

    .row-big-body {
        padding: 0 16px 16px;
    }

    .row {
        grid-template-columns: 96px minmax(0, 1fr);
    }

    .row-art {
        width: 96px;
        height: 96px;
    }

    .row-side {
        grid-column: 1 / -1;
    }

    .row-side .buy {
        width: 100%;
    }

    .row-simple {
        grid-template-columns: 52px minmax(0, 1fr);
    }

    .simple-art {
        width: 52px;
        height: 52px;
    }

    .row-simple .buy {
        grid-column: 1 / -1;
        width: 100%;
    }

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