:root {
    --bg: #1a202c;
    --bg-2: #0f141c;
    --text: #e2e8f0;
    --muted: #a0aec0;
    --gold: #f6e05e;
    --gold-deep: #f1c40f;
    --btn: #4a5568;
    --btn-hover: #2d3748;
    --danger: #e74c3c;
    --danger-hover: #c0392b;
    --shadow: 0 10px 24px rgba(0, 0, 0, 0.35);
    --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);
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    min-height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: "Press Start 2P", system-ui, sans-serif;
    -webkit-tap-highlight-color: transparent;
    overscroll-behavior: none;
}

body {
    min-height: 100dvh;
}

img {
    max-width: 100%;
    display: block;
}

a {
    color: inherit;
}

button,
.btn {
    font-family: inherit;
}

.btn {
    background: var(--btn);
    border: none;
    color: white;
    padding: 0.95rem 1.4rem;
    text-align: center;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.95rem;
    line-height: 1.35;
    cursor: pointer;
    border-radius: 8px;
    transition: background-color 0.2s ease, transform 0.1s ease;
    box-shadow: var(--shadow);
}

.btn:hover {
    background: var(--btn-hover);
}

.btn:active {
    transform: scale(0.97);
}

.btn:disabled {
    background: var(--btn-hover);
    cursor: not-allowed;
    opacity: 0.5;
}

.btn-danger {
    background: var(--danger);
}

.btn-danger:hover {
    background: var(--danger-hover);
}

.icon-btn {
    background: var(--btn);
    color: white;
    border: none;
    border-radius: 9999px;
    width: 2.75rem;
    height: 2.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    cursor: pointer;
    z-index: 20;
    box-shadow: var(--shadow);
    font-size: 1.15rem;
    line-height: 1;
    padding: 0;
}

.icon-btn:hover {
    background: var(--btn-hover);
}

.brand {
    color: var(--muted);
    font-size: clamp(0.55rem, 2.4vw, 0.8rem);
    letter-spacing: 0.04em;
    margin: 0;
}

.flash {
    animation: flash-animation 0.9s infinite;
}

@keyframes flash-animation {
    0%,
    100% { opacity: 1; }
    50% { opacity: 0.35; }
}

.hidden {
    display: none !important;
}

/* ----- Hub ----- */
.hub-body {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: calc(1.25rem + var(--safe-top)) calc(1rem + var(--safe-right)) calc(1.25rem + var(--safe-bottom)) calc(1rem + var(--safe-left));
}

.hub-wrap {
    width: min(36rem, 100%);
    text-align: center;
}

.hub-brand {
    position: absolute;
    top: calc(0.9rem + var(--safe-top));
    left: 50%;
    transform: translateX(-50%);
}

.hub-floyd {
    width: min(5.75rem, 24vw);
    height: auto;
    display: block;
    margin: 0 auto 0.75rem;
}

.hub-title {
    color: var(--gold);
    font-size: clamp(1.15rem, 6vw, 2.1rem);
    line-height: 1.45;
    margin: 0 0 1.75rem;
}

.hub-links {
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
    align-items: stretch;
}

.hub-links .btn {
    font-size: clamp(0.85rem, 4vw, 1.25rem);
    min-height: 3.25rem;
}

/* ----- Shared game chrome ----- */
.game-body {
    height: 100dvh;
    overflow: hidden;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
}

.game-shell {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.game-shell canvas {
    display: block;
    background: #87ceeb;
}

.hellcat-body .game-shell canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    background: #1b1145;
}

.poc3d-body .game-shell canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    background: #9ec7e6;
    cursor: grab;
}

.poc3d-body .game-shell canvas:active {
    cursor: grabbing;
}

.poc-tag {
    position: absolute;
    bottom: calc(0.8rem + var(--safe-bottom));
    right: calc(0.85rem + var(--safe-right));
    font-size: 0.5rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.6);
    text-shadow: 1px 1px 0 #000;
    z-index: 20;
    pointer-events: none;
}

.top-left-stack {
    position: absolute;
    top: calc(0.7rem + var(--safe-top));
    left: calc(0.7rem + var(--safe-left));
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
    z-index: 30;
}

.hud-score {
    position: absolute;
    top: calc(0.85rem + var(--safe-top));
    left: 50%;
    transform: translateX(-50%);
    font-size: clamp(1.1rem, 5vw, 2rem);
    color: #fff;
    text-shadow: 3px 3px 0 #000;
    z-index: 25;
    pointer-events: none;
}

.hud-best {
    position: absolute;
    top: calc(0.85rem + var(--safe-top));
    right: calc(0.85rem + var(--safe-right));
    font-size: clamp(0.55rem, 2.6vw, 0.8rem);
    color: var(--gold-deep);
    text-shadow: 2px 2px 0 #000;
    z-index: 25;
    pointer-events: none;
    text-align: right;
}

.screen {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: calc(4.5rem + var(--safe-top)) 1rem 1.5rem;
}

.screen-title {
    color: var(--gold);
    font-size: clamp(1.1rem, 5.5vw, 2rem);
    text-align: center;
    margin: 0 0 0.75rem;
}

#char-select-screen .brand {
    margin-bottom: 1.35rem;
}

#char-select-screen .screen-title {
    line-height: 1.55;
    margin-bottom: 1.35rem;
}

.screen-sub {
    font-size: clamp(0.7rem, 3.2vw, 1.1rem);
    margin: 0 0 1.4rem;
    text-align: center;
}

#char-select-screen .screen-sub {
    line-height: 1.7;
    margin-bottom: 1.85rem;
}

#char-select-screen .character-btn {
    line-height: 2;
}

.char-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.75rem;
    width: min(36rem, 100%);
}

.character-btn {
    flex-direction: column;
    gap: 0.45rem;
    padding: 0.7rem;
    border: 3px solid transparent;
    min-height: 0;
    width: 100%;
    font-size: 0.58rem;
    line-height: 1.35;
}

.character-btn:hover,
.character-btn:focus-visible {
    border-color: var(--gold);
}

.character-thumb {
    width: 100%;
    aspect-ratio: 1;
    object-fit: contain;
    border-radius: 8px;
    background: #718096;
    border: 2px solid #2d3748;
}

.play-screen {
    padding: 0;
    position: relative;
}

.play-screen canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border-radius: 0;
    outline: none;
}

.overlay-card {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.86);
    color: white;
    padding: 1.4rem 1.25rem 1.3rem;
    border-radius: 12px;
    text-align: center;
    border: 4px solid var(--gold-deep);
    box-shadow: 0 0 30px rgba(0, 0, 0, 0.8);
    z-index: 40;
    width: min(22rem, calc(100% - 1.5rem));
    pointer-events: auto;
}

.overlay-card h1,
.overlay-card h2 {
    margin: 0 0 0.7rem;
    color: var(--gold-deep);
    font-style: italic;
    font-size: clamp(1.1rem, 6vw, 1.8rem);
    text-transform: uppercase;
    line-height: 1.3;
}

.overlay-card p {
    margin: 0.35rem 0;
    font-size: clamp(0.55rem, 2.8vw, 0.72rem);
    line-height: 1.55;
    color: #f7fafc;
}

.overlay-card .btn {
    margin-top: 1rem;
    width: 100%;
}

.hint-mobile { display: none; }

.touch-controls {
    display: none;
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    padding: 0.65rem calc(0.65rem + var(--safe-right)) calc(0.8rem + var(--safe-bottom)) calc(0.65rem + var(--safe-left));
    gap: 0.55rem;
    z-index: 35;
    pointer-events: none;
}

.touch-controls button {
    pointer-events: auto;
    flex: 1;
    min-height: 3.4rem;
    border: 2px solid rgba(255, 255, 255, 0.35);
    border-radius: 12px;
    background: rgba(26, 32, 44, 0.72);
    color: #fff;
    font-size: 0.85rem;
    font-weight: 700;
    letter-spacing: 0.04em;
}

.touch-controls button:active,
.touch-controls button.is-held {
    background: rgba(241, 196, 15, 0.85);
    color: #1a202c;
}

.touch-controls .jump-btn {
    flex: 1.35;
}

.desktop-hint {
    position: absolute;
    bottom: calc(0.8rem + var(--safe-bottom));
    left: 0;
    right: 0;
    text-align: center;
    color: rgba(255, 255, 255, 0.55);
    font-size: 0.58rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    pointer-events: none;
    z-index: 20;
    padding: 0 0.75rem;
}

@media (min-width: 720px) {
    .char-grid {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }

    .character-btn {
        font-size: 0.62rem;
    }
}

@media (pointer: coarse) {
    .hint-desktop { display: none; }
    .hint-mobile { display: inline; }

    .touch-controls {
        display: flex;
    }

    .desktop-hint {
        display: none;
    }

    .game-body.hellcat-body .hud-score {
        left: auto;
        right: calc(0.85rem + var(--safe-right));
        transform: none;
        font-size: 1rem;
    }
}

@media (max-width: 480px) {
    .hub-floyd {
        margin-top: 1.8rem;
    }
}
