:root {
    --bg-top: #0a0a10;
    --bg-bottom: #1f1018;
    --panel: rgba(18, 16, 25, 0.84);
    --panel-border: rgba(255, 255, 255, 0.09);
    --text: #f6efe5;
    --muted: #c5b7a6;
    --accent: #dd633d;
    --accent-deep: #8b2a31;
    --gold: #e7b56d;
    --green: #6f9f74;
    --ink: #120d12;
    --shadow: rgba(0, 0, 0, 0.45);
    --font-display: "Cinzel", Georgia, serif;
    --font-body: "Manrope", "Avenir Next", "Segoe UI", sans-serif;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-right: env(safe-area-inset-right, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    min-height: 100%;
    font-family: var(--font-body);
    color: var(--text);
    background:
        radial-gradient(circle at top, rgba(167, 49, 42, 0.18), transparent 30%),
        linear-gradient(180deg, var(--bg-top), var(--bg-bottom));
}

body {
    overflow: hidden;
    letter-spacing: 0.01em;
    overscroll-behavior: none;
}

.page-shell::before,
.admin-body::before {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    background:
        radial-gradient(circle at 20% 20%, rgba(231, 181, 109, 0.08), transparent 18%),
        radial-gradient(circle at 80% 10%, rgba(139, 42, 49, 0.14), transparent 24%);
}

.page-shell::after,
.admin-body::after {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    opacity: 0.18;
    background-image:
        linear-gradient(rgba(255, 255, 255, 0.04) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, 0.03) 1px, transparent 1px);
    background-size: 80px 80px;
    mask-image: radial-gradient(circle at center, black 48%, transparent 100%);
}

.app-shell {
    min-height: 100vh;
    height: 100vh;
    display: grid;
    grid-template-columns: minmax(320px, 400px) 1fr;
    overflow: hidden;
}

.sidebar,
.admin-panel {
    padding: 28px 24px;
    background:
        linear-gradient(180deg, rgba(10, 10, 14, 0.96), rgba(28, 15, 23, 0.78)),
        linear-gradient(135deg, rgba(231, 181, 109, 0.04), transparent 30%);
    border-right: 1px solid var(--panel-border);
    box-shadow: 10px 0 36px var(--shadow);
    position: relative;
    z-index: 2;
}

.sidebar {
    height: 100vh;
    overflow-y: auto;
}

.brand-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.brand-mark {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    font-size: 0.76rem;
    font-family: var(--font-body);
    color: var(--gold);
}

.brand-mark::before {
    content: "";
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: radial-gradient(circle, #ffd6a2, var(--accent));
    box-shadow: 0 0 18px rgba(223, 94, 57, 0.85);
}

.admin-link {
    color: var(--gold);
    text-decoration: none;
    font-size: 0.82rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    font-family: var(--font-body);
}

h1 {
    margin: 18px 0 12px;
    font-size: clamp(2.2rem, 4vw, 4.2rem);
    line-height: 0.95;
    letter-spacing: 0.06em;
    font-family: var(--font-display);
    font-weight: 800;
    text-transform: uppercase;
}

.intro {
    color: var(--muted);
    font-family: var(--font-body);
    font-size: 0.98rem;
    line-height: 1.72;
    max-width: 36ch;
}

.panel {
    margin-top: 24px;
    padding: 18px;
    border: 1px solid var(--panel-border);
    border-radius: 20px;
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.025), transparent 35%),
        var(--panel);
    backdrop-filter: blur(10px);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03);
}

.panel h2 {
    margin: 0 0 12px;
    font-size: 0.96rem;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--gold);
    font-family: var(--font-body);
    font-weight: 700;
}

.field-label {
    display: block;
    font-size: 0.84rem;
    color: var(--muted);
    margin-bottom: 8px;
    font-family: var(--font-body);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.alias-input {
    width: 100%;
    padding: 12px 14px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(255, 255, 255, 0.045);
    color: var(--text);
    font-size: 0.98rem;
    font-family: var(--font-body);
    transition: border-color 160ms ease, background 160ms ease, transform 160ms ease;
}

.alias-input:focus {
    outline: none;
    border-color: rgba(231, 181, 109, 0.45);
    background: rgba(255, 255, 255, 0.07);
    transform: translateY(-1px);
}

.auth-grid {
    display: grid;
    gap: 10px;
}

.button-row {
    display: flex;
    gap: 10px;
    margin-top: 14px;
    flex-wrap: wrap;
}

.start-button,
.secondary-button,
.ghost-button {
    padding: 14px 18px;
    border-radius: 999px;
    font-size: 0.92rem;
    font-weight: 700;
    letter-spacing: 0.09em;
    text-transform: uppercase;
    cursor: pointer;
    font-family: var(--font-body);
    transition: transform 160ms ease, filter 160ms ease, box-shadow 160ms ease;
}

.start-button {
    width: 100%;
    margin-top: 14px;
    border: none;
    background: linear-gradient(135deg, #bb3f2c, #f07d45);
    color: #fff6ed;
    box-shadow: 0 12px 26px rgba(187, 63, 44, 0.32);
}

.secondary-button {
    border: none;
    background: linear-gradient(135deg, #60443e, #a0604f);
    color: var(--text);
}

.ghost-button {
    border: 1px solid rgba(255, 255, 255, 0.14);
    background: transparent;
    color: var(--text);
}

.start-button:hover,
.secondary-button:hover,
.ghost-button:hover {
    filter: brightness(1.08);
    transform: translateY(-1px);
}

.controls-list,
.status-list,
.leaderboard-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    gap: 10px;
}

.controls-list li,
.status-list li,
.leaderboard-list li {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    font-size: 0.93rem;
    font-family: var(--font-body);
}

.key {
    color: var(--gold);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.value {
    color: var(--text);
    text-align: right;
}

.muted-note {
    margin-top: 12px;
    font-size: 0.84rem;
    color: var(--muted);
    line-height: 1.5;
    font-family: var(--font-body);
}

.identity-card {
    margin-top: 14px;
    padding: 12px 14px;
    border-radius: 14px;
    background: rgba(223, 99, 61, 0.12);
    border: 1px solid rgba(223, 99, 61, 0.24);
    display: flex;
    justify-content: space-between;
    gap: 12px;
}

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

.identity-role {
    color: var(--gold);
    font-size: 0.86rem;
}

.relic-list {
    display: grid;
    gap: 10px;
    margin-top: 14px;
}

.relic-card {
    padding: 12px 14px;
    border-radius: 14px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(255, 255, 255, 0.03);
    display: grid;
    gap: 6px;
}

.relic-card strong {
    color: var(--text);
}

.relic-card span {
    color: var(--muted);
    font-size: 0.88rem;
    font-family: var(--font-body);
}

.relic-card.unlocked {
    border-color: rgba(231, 181, 109, 0.25);
}

.relic-card.active {
    background: rgba(231, 181, 109, 0.09);
    box-shadow: inset 0 0 0 1px rgba(231, 181, 109, 0.25);
}

.relic-card.locked {
    opacity: 0.72;
}

.game-stage {
    position: relative;
    display: grid;
    justify-items: center;
    justify-content: center;
    align-content: start;
    overflow: hidden;
    min-height: 100vh;
    padding: 24px 24px 18px;
}

.mobile-stage-bar,
.touch-controls {
    display: none;
}

.game-stage::before,
.game-stage::after {
    content: "";
    position: absolute;
    inset: auto auto 8% 7%;
    width: 240px;
    height: 240px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(223, 94, 57, 0.13), transparent 68%);
    pointer-events: none;
}

.game-stage::after {
    inset: 14% 10% auto auto;
    width: 300px;
    height: 300px;
    background: radial-gradient(circle, rgba(227, 178, 102, 0.08), transparent 70%);
}

#gameCanvas {
    width: min(calc(100vw - 472px), 1100px);
    max-width: 100%;
    aspect-ratio: 3 / 2;
    height: auto;
    max-height: calc(100vh - 40px);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 24px;
    background:
        radial-gradient(circle at top, rgba(255, 255, 255, 0.03), transparent 26%),
        rgba(8, 8, 12, 0.2);
    display: block;
    box-shadow:
        0 26px 60px rgba(0, 0, 0, 0.42),
        inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.hud-banner {
    position: absolute;
    top: 18px;
    right: 24px;
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    justify-content: flex-end;
    z-index: 2;
    max-width: min(72vw, 720px);
}

.pill {
    padding: 10px 14px;
    border-radius: 999px;
    background: rgba(9, 8, 15, 0.74);
    border: 1px solid rgba(255, 255, 255, 0.08);
    font-size: 0.88rem;
    color: var(--text);
    font-family: var(--font-body);
    letter-spacing: 0.05em;
}

.mobile-stage-button {
    border: none;
    border-radius: 999px;
    background: linear-gradient(135deg, #bb3f2c, #f07d45);
    color: #fff6ed;
    font-family: var(--font-body);
    font-size: 0.9rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    padding: 14px 18px;
    box-shadow: 0 10px 24px rgba(187, 63, 44, 0.28);
}

.mobile-stage-status {
    margin: 0;
    color: var(--muted);
    font-size: 0.82rem;
    line-height: 1.45;
    max-width: 36ch;
}

.touch-cluster {
    display: flex;
    gap: 12px;
}

.touch-button {
    min-width: 78px;
    min-height: 78px;
    border-radius: 24px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.07), rgba(255, 255, 255, 0.02)),
        rgba(9, 8, 15, 0.84);
    color: var(--text);
    font-family: var(--font-body);
    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    box-shadow: 0 16px 30px rgba(0, 0, 0, 0.28);
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
}

.touch-button.is-pressed {
    transform: translateY(1px) scale(0.98);
    background:
        linear-gradient(180deg, rgba(221, 99, 61, 0.24), rgba(255, 255, 255, 0.02)),
        rgba(9, 8, 15, 0.92);
    border-color: rgba(231, 181, 109, 0.3);
}

.touch-button-jump {
    min-width: 112px;
    border-radius: 30px;
}

.hidden {
    display: none !important;
}

.admin-body {
    overflow: auto;
}

.admin-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 32px 20px;
}

.admin-panel {
    width: min(960px, 100%);
    border-radius: 22px;
    border: 1px solid var(--panel-border);
}

.admin-run-list {
    display: grid;
    gap: 14px;
    margin-top: 18px;
}

.admin-run-card {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: center;
    padding: 14px;
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
}

.admin-run-copy {
    display: grid;
    gap: 5px;
}

.admin-run-copy span {
    color: var(--muted);
    font-size: 0.9rem;
    font-family: var(--font-body);
}

.sidebar::-webkit-scrollbar {
    width: 10px;
}

.sidebar::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.03);
}

.sidebar::-webkit-scrollbar-thumb {
    background: rgba(231, 181, 109, 0.24);
    border-radius: 999px;
}

@media (max-width: 1100px) {
    body {
        overflow: auto;
    }

    .app-shell {
        height: auto;
        grid-template-columns: 1fr;
        overflow: visible;
    }

    .sidebar {
        height: auto;
        overflow: visible;
        border-right: 0;
        border-bottom: 1px solid var(--panel-border);
    }

    .game-stage {
        min-height: auto;
        padding-top: 0;
        padding-bottom: 0;
        padding-left: 0;
        padding-right: 0;
    }

    #gameCanvas {
        width: 100%;
        max-height: min(75vh, 620px);
        border-left: 0;
        border-radius: 0;
    }
}

@media (max-width: 900px) {
    body {
        overflow-x: hidden;
        overflow-y: auto;
    }

    .app-shell {
        display: flex;
        flex-direction: column;
        min-height: auto;
        height: auto;
    }

    .game-stage {
        order: 1;
        position: sticky;
        top: 0;
        z-index: 4;
        min-height: 100svh;
        padding:
            calc(var(--safe-top) + 12px)
            calc(var(--safe-right) + 10px)
            calc(var(--safe-bottom) + 18px)
            calc(var(--safe-left) + 10px);
        background:
            linear-gradient(180deg, rgba(10, 10, 14, 0.96), rgba(21, 12, 19, 0.9)),
            radial-gradient(circle at top, rgba(223, 99, 61, 0.12), transparent 34%);
        gap: 12px;
    }

    .sidebar {
        order: 2;
        height: auto;
        overflow: visible;
        padding:
            16px
            calc(var(--safe-right) + 14px)
            calc(var(--safe-bottom) + 28px)
            calc(var(--safe-left) + 14px);
        border-right: 0;
        border-bottom: 0;
        box-shadow: none;
        background: transparent;
        display: grid;
        gap: 14px;
    }

    .brand-row,
    h1,
    .intro {
        margin-left: 4px;
        margin-right: 4px;
    }

    h1 {
        margin-top: 8px;
        margin-bottom: 8px;
        font-size: clamp(2rem, 12vw, 3.5rem);
    }

    .intro {
        font-size: 0.92rem;
        line-height: 1.6;
        max-width: none;
    }

    .panel {
        margin-top: 0;
        border-radius: 18px;
        padding: 16px;
    }

    .controls-list li,
    .status-list li,
    .leaderboard-list li {
        font-size: 0.88rem;
    }

    .game-stage::before,
    .game-stage::after {
        opacity: 0.8;
    }

    .hud-banner {
        position: static;
        width: 100%;
        max-width: none;
        justify-content: flex-start;
        gap: 8px;
        padding: 0 2px;
    }

    .pill {
        padding: 8px 11px;
        font-size: 0.74rem;
        letter-spacing: 0.04em;
        white-space: nowrap;
    }

    .mobile-stage-bar {
        display: grid;
        width: 100%;
        gap: 10px;
        align-items: center;
        grid-template-columns: minmax(148px, 180px) 1fr;
    }

    #gameCanvas {
        width: 100%;
        max-width: 100%;
        max-height: min(58svh, 520px);
        border-radius: 20px;
        border-left: 1px solid rgba(255, 255, 255, 0.08);
    }

    .touch-controls {
        display: flex;
        width: 100%;
        justify-content: space-between;
        align-items: end;
        gap: 16px;
        padding: 2px 2px 0;
    }
}

@media (max-width: 720px) {
    .mobile-stage-bar {
        grid-template-columns: 1fr;
    }

    .mobile-stage-button {
        width: 100%;
    }

    .touch-controls {
        position: sticky;
        bottom: 0;
        padding-bottom: max(2px, var(--safe-bottom));
    }

    .touch-button {
        min-width: 70px;
        min-height: 70px;
        border-radius: 22px;
        font-size: 0.74rem;
    }

    .touch-button-jump {
        min-width: 104px;
    }

    .button-row {
        flex-direction: column;
    }

    .admin-run-card {
        flex-direction: column;
        align-items: stretch;
    }
}
