:root {
    --bg-0: #05070d;
    --bg-1: #0c1220;
    --text: #f3ecdf;
    --muted: #a1a8bd;
    --panel: rgba(12, 18, 30, 0.86);
    --border: rgba(255, 186, 110, 0.2);
    --accent: #ffb35c;
    --cool: #7fd8ff;
    --glow: rgba(255, 179, 92, 0.42);
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html,
body {
    margin: 0;
    min-height: 100%;
    background:
        radial-gradient(circle at top, rgba(255, 179, 92, 0.14), transparent 30%),
        radial-gradient(circle at bottom, rgba(95, 156, 255, 0.14), transparent 32%),
        linear-gradient(180deg, var(--bg-1), var(--bg-0));
    color: var(--text);
    font-family: "Trebuchet MS", "Segoe UI", sans-serif;
}

body {
    display: flex;
    justify-content: center;
    min-height: 100dvh;
}

.shell {
    width: min(460px, 100vw);
    min-height: 100dvh;
    height: 100dvh;
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    overflow: hidden;
}

.topline,
.player-card,
.stat-card,
.pulse-banner,
.controls-shell,
.map-shell {
    border: 1px solid var(--border);
    background: var(--panel);
    box-shadow: 0 16px 30px rgba(0, 0, 0, 0.26);
}

.topline,
.player-card,
.controls-shell,
.map-shell {
    border-radius: 22px;
}

.topline {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
}

.header-title {
    min-width: 0;
}

.eyebrow,
.meta-label {
    color: var(--cool);
    font-size: 0.7rem;
    letter-spacing: 0.2em;
    text-transform: uppercase;
}

.topline h1 {
    margin: 6px 0 0;
    font-size: 1.8rem;
    line-height: 0.94;
    letter-spacing: 0.04em;
}

.header-actions {
    display: flex;
    flex: 0 0 auto;
    flex-direction: column;
    gap: 6px;
    width: 112px;
}

.header-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 32px;
    padding: 0 11px;
    border: 1px solid rgba(255, 186, 110, 0.24);
    border-radius: 999px;
    color: var(--text);
    font: inherit;
    font-size: 0.75rem;
    font-weight: 700;
    line-height: 1;
    text-align: center;
    text-decoration: none;
    cursor: pointer;
    background: rgba(255, 255, 255, 0.06);
    transition: transform 120ms ease, background 120ms ease, border-color 120ms ease;
}

.reset-pill {
    color: #ffe2b4;
    background: rgba(255, 179, 92, 0.16);
}

.header-pill:hover,
.header-pill:focus {
    border-color: rgba(255, 179, 92, 0.5);
    background: rgba(255, 255, 255, 0.1);
}

.header-pill:active {
    transform: translateY(1px) scale(0.98);
}

.player-card {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: center;
    padding: 11px 16px;
}

.player-badge {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.role-glow {
    width: 38px;
    height: 38px;
    border-radius: 14px;
    background: #4a4335;
    box-shadow: 0 0 0 6px rgba(255, 255, 255, 0.03);
    transition: background 200ms ease, box-shadow 200ms ease;
}

.role-glow.in-control {
    background: var(--accent);
    box-shadow: 0 0 0 6px rgba(255, 255, 255, 0.03), 0 0 22px var(--glow);
}

.role-name {
    font-size: 1.06rem;
    font-weight: 700;
}

.status-text,
.meta-value {
    color: var(--muted);
    font-size: 0.86rem;
}

.meta-box {
    text-align: right;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 6px;
}

.stat-card {
    border-radius: 14px;
    padding: 8px 9px;
    overflow: hidden;
}

.stat-card .meta-label {
    font-size: 0.6rem;
    letter-spacing: 0.12em;
}

.stat-card strong {
    display: block;
    margin-top: 4px;
    font-size: 0.98rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.map-shell {
    flex: 1 1 auto;
    min-height: 150px;
    padding: 10px 12px 8px;
    display: flex;
    flex-direction: column;
}

.map-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-bottom: 6px;
}

.map-hint {
    color: var(--muted);
    font-size: 0.76rem;
}

.map-stage {
    position: relative;
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.map-canvas {
    display: block;
    border-radius: 12px;
    background: rgba(4, 7, 13, 0.72);
}

.map-legend {
    display: flex;
    justify-content: center;
    gap: 12px;
    padding-top: 6px;
    color: var(--muted);
    font-size: 0.7rem;
}

.legend-chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

.legend-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: #fff;
}

.dot-you {
    background: #ffd166;
}

.dot-trail {
    background: rgba(127, 216, 255, 0.55);
}

.dot-exit {
    background: #7cffb4;
}

.controls-shell {
    flex: 0 0 auto;
    padding: 10px;
}

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

.pad-button {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    min-height: 74px;
    padding: 8px 6px;
    border: 1px solid rgba(255, 186, 110, 0.26);
    border-radius: 18px;
    color: var(--text);
    font: inherit;
    cursor: pointer;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    background: rgba(255, 255, 255, 0.06);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
    transition: background 100ms ease, transform 100ms ease, box-shadow 100ms ease;
}

.move-button {
    background: rgba(255, 179, 92, 0.18);
}

.back-button {
    grid-column: 2 / 3;
    min-height: 58px;
}

.pad-button.pressed {
    transform: translateY(1px) scale(0.98);
    background: rgba(255, 179, 92, 0.4);
    box-shadow: 0 0 22px var(--glow);
}

.pad-glyph {
    font-size: 1.5rem;
    line-height: 1;
}

.pad-label {
    color: var(--muted);
    font-size: 0.68rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.pad-button.pressed .pad-label {
    color: var(--text);
}

.pulse-banner {
    flex: 0 0 auto;
    border-radius: 14px;
    padding: 9px 14px;
    text-align: center;
    font-size: 0.92rem;
    font-weight: 700;
}

.pulse-banner.flash {
    animation: pulseFlash 220ms ease;
}

@keyframes pulseFlash {
    0% {
        transform: scale(0.98);
        box-shadow: 0 0 0 0 var(--glow);
    }

    100% {
        transform: scale(1);
        box-shadow: 0 0 0 14px rgba(255, 255, 255, 0);
    }
}

@media (max-height: 720px) {
    .topline h1 {
        font-size: 1.5rem;
    }

    .pad-button {
        min-height: 62px;
    }

    .back-button {
        min-height: 50px;
    }

    .map-legend {
        display: none;
    }
}

@media (max-width: 380px) {
    .header-actions {
        width: 100px;
    }

    .stat-card strong {
        font-size: 0.86rem;
    }
}

/* Legacy fallbacks for browsers without custom properties, grid or dvh units. */

html,
body {
    background: #05070d;
    color: #f3ecdf;
}

body {
    min-height: 100vh;
}

.shell {
    width: 460px;
    max-width: 100%;
    min-height: 100vh;
    height: 100vh;
}

.topline,
.player-card,
.stat-card,
.pulse-banner,
.controls-shell,
.map-shell {
    border: 1px solid rgba(255, 186, 110, 0.2);
    background: rgba(12, 18, 30, 0.9);
    color: #f3ecdf;
}

.eyebrow,
.meta-label {
    color: #7fd8ff;
}

.status-text,
.meta-value,
.map-hint,
.pad-label {
    color: #a1a8bd;
}

.role-glow.in-control {
    background: #ffb35c;
}

.reset-pill {
    color: #ffe2b4;
    background: rgba(255, 179, 92, 0.16);
}
