:root {
    --bg: #0d0d12;
    --panel: rgba(8, 8, 14, 0.85);
    --gold: #FFD700;
    --gold-hot: #FF8C00;
    --red: #E63946;
    --green: #00FF7F;
    --blue: #00BFFF;
    --text: #F2F2F5;
    --dim: #8b8ba0;
}

* { box-sizing: border-box; }

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

body {
    font-family: 'Press Start 2P', monospace;
    background:
        radial-gradient(circle at 50% 0%, #1d1d2b 0%, var(--bg) 60%);
    color: var(--text);
    overflow: hidden;
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.game-container {
    position: relative;
    width: 100%;
    height: 100%;
    padding:
        env(safe-area-inset-top) env(safe-area-inset-right)
        env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.screen {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1.1rem;
    text-align: center;
    padding: 1rem;
}

.hidden { display: none !important; }

/* ---------- Typography ---------- */

h1 {
    margin: 0;
    font-size: clamp(1.4rem, 6vw, 2.6rem);
    line-height: 1.4;
    color: var(--gold);
    text-shadow: 0 0 18px rgba(255, 215, 0, 0.35);
}

h1 .amp { color: var(--red); margin: 0 0.15em; }
h1.win { color: var(--green); text-shadow: 0 0 18px rgba(0, 255, 127, 0.35); }
h1.lose { color: var(--red); text-shadow: 0 0 18px rgba(230, 57, 70, 0.4); }

.tagline {
    margin: 0;
    font-size: clamp(0.55rem, 2.4vw, 0.8rem);
    color: var(--dim);
    line-height: 1.8;
}

.stats { margin: 0; font-size: clamp(0.6rem, 2.6vw, 0.85rem); line-height: 1.9; }
.stats.dim { color: var(--dim); font-size: clamp(0.5rem, 2.2vw, 0.7rem); }

.records {
    display: flex;
    gap: clamp(0.75rem, 4vw, 2rem);
    flex-wrap: wrap;
    justify-content: center;
    font-size: clamp(0.5rem, 2.2vw, 0.7rem);
    color: var(--dim);
}
.records b { color: var(--text); }

.controls {
    list-style: none;
    margin: 0;
    padding: 0;
    font-size: clamp(0.45rem, 2vw, 0.62rem);
    color: var(--dim);
    line-height: 2.2;
}
.controls b { color: var(--gold); }

.legend { display: flex; gap: 0.5rem; flex-wrap: wrap; justify-content: center; }

.chip {
    font-size: clamp(0.4rem, 1.8vw, 0.55rem);
    padding: 0.45rem 0.7rem;
    border-radius: 999px;
    border: 1px solid currentColor;
}
.chip-shield { color: var(--green); }
.chip-light  { color: var(--blue); }
.chip-freeze { color: #FF4500; }

/* ---------- HUD ---------- */

.ui {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: clamp(0.4rem, 2vw, 1.2rem);
    flex-wrap: wrap;
    padding: 0.6rem 0.8rem;
    background: var(--panel);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    font-size: clamp(0.42rem, 1.9vw, 0.65rem);
    color: var(--dim);
}

.ui b { color: var(--text); }
.bonus-slot b { color: var(--gold); }

.icon-button {
    padding: 0.3rem 0.6rem;
    font-size: 0.6rem;
    font-family: inherit;
    background: transparent;
    color: var(--dim);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 4px;
    cursor: pointer;
}
.icon-button:hover { color: var(--gold); border-color: var(--gold); }

/* ---------- Stage ---------- */

.stage {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 3.2rem 0.5rem 0.5rem;
}

canvas {
    /* Keep the 640x416 aspect ratio — never stretch the pixels. */
    width: 100%;
    height: 100%;
    object-fit: contain;
    aspect-ratio: 640 / 416;
    display: block;
    background: #12121a;
    border: 2px solid rgba(230, 57, 70, 0.6);
    border-radius: 4px;
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.8);
    image-rendering: pixelated;
}

/* ---------- Overlay ---------- */

.overlay {
    position: absolute;
    inset: 0;
    z-index: 30;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    background: rgba(5, 5, 10, 0.85);
    backdrop-filter: blur(2px);
}
.overlay p { margin: 0; font-size: clamp(1rem, 5vw, 1.8rem); color: var(--gold); }
.overlay small { font-size: clamp(0.45rem, 2vw, 0.6rem); color: var(--dim); }

/* ---------- Joystick ---------- */

.joystick {
    position: fixed;
    width: 120px;
    height: 120px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.07);
    border: 2px solid rgba(255, 255, 255, 0.18);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 20;
    pointer-events: none;
}

.joystick-stick {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: rgba(255, 215, 0, 0.75);
    box-shadow: 0 0 16px rgba(255, 215, 0, 0.5);
    transition: transform 0.04s linear;
}

/* ---------- Buttons ---------- */

.button-row { display: flex; gap: 0.75rem; flex-wrap: wrap; justify-content: center; }

button {
    padding: clamp(0.65rem, 2.4vw, 0.9rem) clamp(1.1rem, 4vw, 1.8rem);
    font-family: inherit;
    font-size: clamp(0.55rem, 2.4vw, 0.8rem);
    color: #1a1a1a;
    background: var(--gold);
    border: none;
    border-radius: 6px;
    cursor: pointer;
    touch-action: manipulation;
    box-shadow: 0 4px 0 #b39700;
    transition: transform 0.08s ease, background 0.15s ease;
}

button:hover { background: var(--gold-hot); }
button:active { transform: translateY(3px); box-shadow: 0 1px 0 #b39700; }

button.ghost {
    background: transparent;
    color: var(--dim);
    border: 1px solid rgba(255, 255, 255, 0.2);
    box-shadow: none;
}
button.ghost:hover { color: var(--gold); border-color: var(--gold); }

@media (max-width: 480px) {
    .ui { gap: 0.35rem 0.7rem; }
    .stage { padding-top: 4.2rem; }
}
