/* Asteroid Dodge — Retro Arcade Space Style */

* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
    /* Палітра */
    --bg-deep:      #0a0e2e;
    --bg-mid:       #131744;
    --bg-soft:      #1d2160;
    --nebula-teal:  #28b4c8;
    --nebula-mag:   #b14bff;

    --neon-orange:  #ff8a2a;
    --neon-amber:   #ffd166;
    --hot-yellow:   #fff2a8;

    --crystal-blue:   #4dd6ff;
    --crystal-purple: #b14bff;
    --crystal-pink:   #ff5fb6;

    --text-white:   #eaf6ff;
    --text-muted:   #6a7ab0;
    --text-soft:    #94a3d4;

    --danger:       #ff3c50;
    --win:          #4ade80;

    /* Layout */
    --container-max: 31.25rem; /* 500px */
    --radius-md: 0.75rem;
    --radius-lg: 1rem;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    -webkit-tap-highlight-color: transparent;
}

body {
    display: flex;
    justify-content: center;
    align-items: stretch;
    background:
        radial-gradient(ellipse at 25% 10%, rgba(40,180,200,0.15) 0%, transparent 55%),
        radial-gradient(ellipse at 80% 90%, rgba(177,75,255,0.18) 0%, transparent 55%),
        radial-gradient(ellipse at 50% 50%, var(--bg-mid) 0%, var(--bg-deep) 100%);
    color: var(--text-white);
    min-height: calc(100dvh - 3.5rem);
    user-select: none;
    -webkit-user-select: none;
}

/* ============ SCREENS ============ */
.screen {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background: var(--bg-deep);
    color: var(--text-white);
    z-index: 1000;
}

.hidden { display: none !important; }

.loading-spinner {
    width: 3.25rem;
    height: 3.25rem;
    border: 0.1875rem solid rgba(127,217,255,0.15);
    border-top-color: var(--neon-orange);
    border-radius: 50%;
    animation: spinAnim 1s linear infinite;
}

@keyframes spinAnim { to { transform: rotate(360deg); } }

#loading-screen p {
    margin-top: 1rem;
    color: var(--neon-amber);
    font-size: 0.9375rem;
    letter-spacing: 0.0625rem;
}

.login-content { text-align: center; padding: 1.5rem; }
.login-icon { font-size: 3.5rem; margin-bottom: 1rem; }
.login-content h2 { color: var(--neon-orange); margin-bottom: 0.5rem; }
.login-content p { color: var(--text-muted); }

/* ============ GAME CONTAINER ============ */
#game-container {
    width: 100%;
    max-width: var(--container-max);
    height: 100%;
    max-height: 56.25rem;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    padding: 0.5rem 0.75rem;
    position: relative;
    z-index: 1;
}

/* ============ HEADER ============ */
#game-header {
    width: 100%;
    display: flex;
    justify-content: center;
    padding: 0.375rem 0;
}

.balance-display {
    background: linear-gradient(180deg, rgba(255,138,42,0.10) 0%, rgba(177,75,255,0.06) 100%);
    border: 1px solid rgba(255,138,42,0.35);
    border-radius: 1.25rem;
    padding: 0.4375rem 1.25rem;
    display: flex;
    align-items: center;
    gap: 0.4375rem;
    box-shadow: 0 0 1rem rgba(255,138,42,0.15);
}

.balance-label {
    color: var(--text-muted);
    font-size: 0.75rem;
    letter-spacing: 0.03125rem;
}

#balance-value {
    color: var(--neon-amber);
    font-size: 1.25rem;
    font-weight: 700;
    min-width: 4.375rem;
    text-align: right;
    text-shadow: 0 0 0.625rem rgba(255,209,102,0.45);
}

.balance-currency {
    color: var(--crystal-purple);
    font-size: 0.6875rem;
}

/* ============ STATS BAR ============ */
.stats-bar {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    margin-top: 0.25rem;
    background:
        linear-gradient(180deg, #0a0820 0%, #120e36 100%) padding-box,
        linear-gradient(90deg, var(--neon-orange), var(--crystal-purple), var(--crystal-blue)) border-box;
    border: 1px solid transparent;
    border-radius: var(--radius-md);
}

.stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.125rem;
    flex: 1;
}

.stat-label {
    color: var(--text-muted);
    font-size: 0.625rem;
    font-weight: 700;
    letter-spacing: 0.0625rem;
    text-transform: uppercase;
}

.stat-lives {
    color: var(--danger);
    font-size: 1rem;
    letter-spacing: 0.125rem;
    text-shadow: 0 0 0.5rem rgba(255,60,80,0.55);
}

#score-value {
    color: var(--crystal-blue);
    font-size: 1.0625rem;
    font-weight: 700;
    text-shadow: 0 0 0.5rem rgba(77,214,255,0.45);
}

#time-value {
    color: var(--neon-amber);
    font-size: 1.0625rem;
    font-weight: 700;
    text-shadow: 0 0 0.5rem rgba(255,209,102,0.45);
}

/* ============ GAME AREA ============ */
.game-area {
    flex: 1;
    position: relative;
    margin-top: 0.5rem;
    border-radius: var(--radius-lg);
    overflow: hidden;
    background:
        linear-gradient(180deg, #050624 0%, #0a0e2e 100%) padding-box,
        linear-gradient(135deg, var(--neon-orange) 0%, var(--crystal-purple) 50%, var(--crystal-blue) 100%) border-box;
    border: 2px solid transparent;
    box-shadow:
        0 0 0 1px rgba(0,0,0,0.5),
        0 0 1.75rem rgba(255,138,42,0.18),
        0 0 3rem rgba(177,75,255,0.12),
        inset 0 1px 0 rgba(255,255,255,0.04);
    display: flex;
    flex-direction: column;
    align-items: stretch;
    min-height: 18rem;
}

#game-canvas {
    flex: 1;
    width: 100%;
    height: 100%;
    display: block;
    cursor: pointer;
    touch-action: none;
}

/* ============ INSTRUCTION ============ */
.instruction {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(10,14,46,0.92);
    color: var(--neon-amber);
    padding: 0.625rem 1.25rem;
    border-radius: 0.5rem;
    font-size: 0.875rem;
    font-weight: 700;
    letter-spacing: 0.0625rem;
    border: 1px solid rgba(255,209,102,0.45);
    animation: instructionPulse 1.2s ease infinite;
    z-index: 15;
    white-space: nowrap;
    pointer-events: none;
}

@keyframes instructionPulse {
    0%, 100% { transform: translate(-50%, -50%) scale(1);    opacity: 0.95; }
    50%      { transform: translate(-50%, -50%) scale(1.04); opacity: 1; }
}

/* ============ HIT FLASH (DOM-варіант) ============ */
.hit-flash {
    position: absolute;
    inset: 0;
    pointer-events: none;
    background: rgba(255, 60, 80, 0);
    z-index: 10;
}

.hit-flash.active {
    animation: hitFlash 0.4s ease-out;
}

@keyframes hitFlash {
    0%   { background: rgba(255, 60, 80, 0.4); }
    100% { background: rgba(255, 60, 80, 0); }
}

/* ============ RESULT ============ */
.result-display {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    z-index: 20;
    background: linear-gradient(160deg, rgba(8,8,32,0.97) 0%, rgba(20,12,48,0.97) 100%);
    padding: 1.5rem 2rem;
    border-radius: var(--radius-lg);
    border: 1px solid var(--neon-orange);
    box-shadow:
        0 0 0 1px rgba(255,138,42,0.2),
        0 0 3rem rgba(255,138,42,0.45),
        inset 0 1px 0 rgba(255,255,255,0.06);
    animation: resultIn 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    min-width: 12rem;
}

@keyframes resultIn {
    0%   { transform: translate(-50%, -50%) scale(0.5); opacity: 0; }
    100% { transform: translate(-50%, -50%) scale(1);   opacity: 1; }
}

.result-icon {
    font-size: 2.75rem;
    margin-bottom: 0.4rem;
    line-height: 1;
}

.result-title {
    font-size: 1.25rem;
    font-weight: 800;
    margin-bottom: 0.375rem;
    letter-spacing: 0.0625rem;
}

.result-title.win  { color: var(--win); text-shadow: 0 0 0.625rem rgba(74,222,128,0.5); }
.result-title.lose { color: var(--text-muted); }

.result-score {
    font-size: 0.8125rem;
    color: var(--text-soft);
    margin-bottom: 0.5rem;
}

.result-multiplier {
    font-size: 1.75rem;
    font-weight: 800;
    color: var(--neon-amber);
    margin-bottom: 0.25rem;
    text-shadow: 0 0 0.875rem rgba(255,209,102,0.6);
}

.result-amount {
    font-size: 1.125rem;
    font-weight: 700;
    color: var(--win);
}

/* ============ CONTROLS ============ */
.controls {
    margin-top: 0.5rem;
    padding: 0.5rem 0.75rem 0.625rem;
    background: rgba(0,0,0,0.28);
    border-radius: var(--radius-md);
    border: 1px solid rgba(255,138,42,0.15);
}

#bet-controls {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding-bottom: 0.5rem;
    flex-wrap: wrap;
}

.bet-label {
    color: var(--text-muted);
    font-size: 0.6875rem;
    font-weight: 700;
    letter-spacing: 0.0625rem;
    text-transform: uppercase;
}

.bet-buttons {
    display: flex;
    gap: 0.375rem;
}

.bet-btn {
    width: 3rem;
    height: 2rem;
    background: rgba(255,255,255,0.04);
    border: 1px solid rgba(255,138,42,0.25);
    border-radius: 0.375rem;
    color: rgba(234,246,255,0.65);
    font-size: 0.8125rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.15s ease;
    font-family: inherit;
}

.bet-btn:hover:not(:disabled) {
    border-color: var(--neon-orange);
    color: var(--text-white);
    background: rgba(255,138,42,0.08);
}

.bet-btn.active {
    background: linear-gradient(160deg, var(--neon-orange) 0%, var(--neon-amber) 100%);
    color: #2a1700;
    border-color: var(--hot-yellow);
    box-shadow: 0 0.125rem 0.75rem rgba(255,138,42,0.45);
}

.bet-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

/* ============ ACTION BUTTON ============ */
#action-button {
    width: 100%;
    height: 3.25rem;
    background: linear-gradient(160deg, var(--neon-orange) 0%, var(--neon-amber) 55%, #ffb547 100%);
    border: 1px solid rgba(255,242,168,0.5);
    border-radius: 1.625rem;
    cursor: pointer;
    box-shadow:
        0 0.25rem 1.375rem rgba(255,138,42,0.45),
        0 1px 0 rgba(255,255,255,0.2) inset;
    transition: all 0.18s ease;
    font-family: inherit;
}

#action-button:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 0.5rem 1.875rem rgba(255,209,102,0.6);
}

#action-button:active:not(:disabled) {
    transform: translateY(0);
    box-shadow: 0 0.125rem 0.625rem rgba(255,138,42,0.3);
}

#action-button:disabled {
    background: linear-gradient(160deg, #1e1e34 0%, #14141f 100%);
    border-color: rgba(255,255,255,0.08);
    box-shadow: none;
    cursor: not-allowed;
}

#action-button.playing {
    background: linear-gradient(160deg, #3a3a55 0%, #20203a 100%);
    border-color: rgba(127,217,255,0.2);
}

#action-button.pulse {
    animation: buttonPulse 2s ease-in-out infinite;
}

@keyframes buttonPulse {
    0%, 100% { box-shadow: 0 0.25rem 1.375rem rgba(255,138,42,0.45); }
    50%      { box-shadow: 0 0.25rem 2.5rem rgba(255,95,182,0.7); }
}

#action-text {
    color: #2a1700;
    font-size: 1.1875rem;
    font-weight: 800;
    letter-spacing: 0.1875rem;
}

#action-button:disabled #action-text { color: #666; }
#action-button.playing #action-text { color: var(--text-soft); }

/* ============ GAME TITLE ============ */
.game-title {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.25rem 0 0.4rem;
}

.title-prefix {
    color: rgba(234,246,255,0.35);
    font-size: 0.875rem;
}

.title-main {
    color: var(--neon-orange);
    font-size: 0.875rem;
    font-weight: 800;
    letter-spacing: 0.1875rem;
    text-transform: uppercase;
    text-shadow: 0 0 0.625rem rgba(255,138,42,0.5);
}

/* ============ MESSAGE ============ */
#message-display {
    position: fixed;
    bottom: 5rem;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(6,6,24,0.94);
    padding: 0.5rem 1.375rem;
    border-radius: 0.5rem;
    border: 1px solid rgba(255,138,42,0.4);
    z-index: 100;
    white-space: nowrap;
    box-shadow: 0 0 1.5rem rgba(255,138,42,0.25);
}

#message-text {
    color: var(--text-white);
    font-size: 0.8125rem;
    font-weight: 600;
}

/* ============ RESPONSIVE ============ */
@media (max-width: 25rem) {
    .stat-label  { font-size: 0.5625rem; }
    .stat-lives  { font-size: 0.875rem; }
    #score-value, #time-value { font-size: 0.9375rem; }
    .bet-btn { width: 2.625rem; height: 1.875rem; font-size: 0.75rem; }
    #action-button { height: 2.875rem; }
    #action-text { font-size: 1.0625rem; letter-spacing: 0.125rem; }
}

@media (max-height: 43.75rem) {
    .stats-bar { padding: 0.375rem 0.625rem; }
    .controls  { padding: 0.4rem 0.625rem 0.5rem; }
    #action-button { height: 2.875rem; }
}
