:root {
    --font-display: 'Syne', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-body: 'DM Sans', system-ui, -apple-system, sans-serif;
    --gold: hsl(45, 90%, 55%);
    --gold-light: hsl(45, 95%, 70%);
    --gold-glow: hsla(45, 90%, 55%, 0.35);
    --cyan: hsl(195, 75%, 52%);
    --coral: hsl(15, 85%, 58%);
    --success: hsl(160, 80%, 45%);
    --danger: hsl(0, 75%, 55%);
    --bg-deep: hsl(225, 45%, 6%);
    --bg-surface: hsl(225, 35%, 11%);
    --text-primary: hsl(220, 25%, 94%);
    --text-secondary: hsl(220, 15%, 65%);
    --text-muted: hsl(220, 12%, 48%);
}

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

body {
    background: var(--bg-deep);
    font-family: var(--font-body);
    color: var(--text-primary);
    overflow: hidden;
    height: 100dvh;
    width: 100%;
    -webkit-tap-highlight-color: transparent;
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
}

.game-shell {
    position: relative;
    width: 100%;
    height: 100dvh;
    overflow: hidden;
}

#gameCanvas {
    width: 100%;
    height: 100%;
}

#gameCanvas canvas {
    display: block;
}

.ms-back-btn {
    position: absolute;
    top: clamp(12px, 3vw, 20px);
    left: clamp(12px, 3vw, 20px);
    z-index: 10;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 18px;
    font-family: var(--font-display);
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--text-primary);
    background: hsla(225, 35%, 10%, 0.75);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid hsla(220, 20%, 40%, 0.3);
    border-radius: 30px;
    text-decoration: none;
    transition: transform 0.2s, background 0.2s, border-color 0.2s;
    min-height: 44px;
}

.ms-back-btn:hover,
.ms-back-btn:active {
    background: hsla(225, 35%, 16%, 0.85);
    border-color: var(--gold);
    transform: translateX(-3px);
}

.hud-top {
    position: absolute;
    top: clamp(12px, 3vw, 20px);
    right: clamp(12px, 3vw, 20px);
    z-index: 10;
    display: flex;
    gap: 10px;
}

.hud-stat {
    font-family: var(--font-display);
    font-size: 0.85rem;
    font-weight: 700;
    padding: 10px 16px;
    background: hsla(225, 35%, 10%, 0.75);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid hsla(220, 20%, 40%, 0.3);
    border-radius: 30px;
    color: var(--text-primary);
    letter-spacing: 0.02em;
    min-height: 44px;
    display: flex;
    align-items: center;
}

.hud-bottom {
    position: absolute;
    bottom: clamp(16px, 4vw, 28px);
    right: clamp(12px, 3vw, 20px);
    z-index: 10;
    display: flex;
    gap: 8px;
}

.hud-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 1px solid hsla(220, 20%, 40%, 0.3);
    background: hsla(225, 35%, 10%, 0.75);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    color: var(--text-primary);
    font-size: 1.2rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.15s, background 0.15s, border-color 0.15s;
    -webkit-tap-highlight-color: transparent;
}

.hud-btn:hover,
.hud-btn:active {
    background: hsla(225, 35%, 18%, 0.85);
    border-color: var(--gold);
    transform: scale(1.08);
}

.controls-hint {
    position: absolute;
    bottom: clamp(16px, 4vw, 28px);
    left: 50%;
    transform: translateX(-50%);
    z-index: 10;
    font-family: var(--font-body);
    font-size: 0.78rem;
    font-weight: 500;
    padding: 8px 18px;
    background: hsla(225, 35%, 10%, 0.7);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid hsla(220, 20%, 40%, 0.2);
    border-radius: 20px;
    color: var(--text-secondary);
    text-align: center;
    pointer-events: none;
    transition: opacity 0.5s;
}

.overlay {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    background: hsla(225, 45%, 4%, 0.85);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    transition: opacity 0.35s;
}

.overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.overlay-card {
    background: linear-gradient(145deg, hsl(225, 35%, 13%), hsl(225, 40%, 9%));
    border: 1px solid hsla(220, 20%, 35%, 0.25);
    border-radius: 28px;
    padding: clamp(28px, 5vw, 44px);
    text-align: center;
    max-width: 380px;
    width: 90%;
    box-shadow: 0 20px 60px hsla(0, 0%, 0%, 0.5), 0 0 60px var(--gold-glow);
    display: flex;
    flex-direction: column;
    gap: 14px;
    animation: cardIn 0.4s ease-out;
}

@keyframes cardIn {
    from { opacity: 0; transform: scale(0.9) translateY(20px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

.overlay-title {
    font-family: var(--font-display);
    font-size: 1.8rem;
    font-weight: 800;
    background: linear-gradient(135deg, var(--gold), var(--gold-light));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.overlay-subtitle {
    font-family: var(--font-body);
    font-size: 1rem;
    color: var(--text-secondary);
    line-height: 1.5;
}

.overlay-rank {
    font-family: var(--font-display);
    font-size: 1.1rem;
    font-weight: 700;
    padding: 8px 20px;
    background: hsla(225, 35%, 15%, 0.8);
    border-radius: 20px;
    display: inline-block;
    align-self: center;
    margin-top: 4px;
}

.overlay-rank.god { color: var(--gold); border: 1px solid var(--gold-glow); }
.overlay-rank.expert { color: var(--cyan); border: 1px solid hsla(195, 75%, 52%, 0.3); }
.overlay-rank.good { color: var(--success); border: 1px solid hsla(160, 80%, 45%, 0.3); }
.overlay-rank.beginner { color: var(--text-secondary); border: 1px solid hsla(220, 20%, 40%, 0.2); }

.btn-primary,
.btn-secondary {
    display: block;
    width: 100%;
    padding: 14px;
    border: none;
    border-radius: 30px;
    font-family: var(--font-display);
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    text-decoration: none;
    text-align: center;
    transition: transform 0.15s, box-shadow 0.15s;
    min-height: 48px;
}

.btn-primary {
    background: linear-gradient(135deg, var(--gold), var(--coral));
    color: var(--bg-deep);
    box-shadow: 0 4px 20px var(--gold-glow);
}

.btn-primary:hover,
.btn-primary:active {
    transform: translateY(-2px);
    box-shadow: 0 6px 28px var(--gold-glow);
}

.btn-secondary {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid hsla(220, 20%, 35%, 0.35);
}

.btn-secondary:hover,
.btn-secondary:active {
    background: hsla(220, 20%, 35%, 0.1);
    color: var(--text-primary);
    transform: translateY(-2px);
}

.how-to-steps {
    display: flex;
    flex-direction: column;
    gap: 12px;
    text-align: left;
}

.how-to-step {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 10px 14px;
    background: hsla(225, 35%, 12%, 0.6);
    border-radius: 14px;
    border: 1px solid hsla(220, 20%, 30%, 0.15);
}

.how-to-step .step-icon {
    font-size: 1.2rem;
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: hsla(45, 90%, 55%, 0.12);
    border-radius: 50%;
}

.how-to-step p {
    font-family: var(--font-body);
    font-size: 0.92rem;
    color: var(--text-secondary);
    line-height: 1.5;
    margin: 0;
}

@media (max-width: 640px) {
    .ms-back-btn {
        padding: 8px 14px;
        font-size: 0.78rem;
        gap: 4px;
    }

    .hud-stat {
        font-size: 0.75rem;
        padding: 8px 12px;
    }

    .controls-hint {
        font-size: 0.7rem;
        padding: 6px 14px;
    }

    .overlay-card {
        padding: 24px 20px;
        gap: 10px;
        border-radius: 22px;
    }

    .overlay-title { font-size: 1.4rem; }
    .overlay-subtitle { font-size: 0.9rem; }
}

@media (max-width: 380px) {
    .hud-stat { padding: 6px 10px; font-size: 0.7rem; }
    .hud-btn { width: 38px; height: 38px; font-size: 1rem; }
    .ms-back-btn { font-size: 0.72rem; padding: 6px 12px; }
}

@media (max-height: 500px) and (orientation: landscape) {
    .hud-top { top: 6px; right: 6px; gap: 6px; }
    .hud-stat { font-size: 0.7rem; padding: 5px 10px; min-height: 32px; }
    .hud-bottom { bottom: 6px; right: 6px; }
    .hud-btn { width: 34px; height: 34px; font-size: 0.9rem; }
    .ms-back-btn { top: 6px; left: 6px; font-size: 0.7rem; padding: 5px 10px; min-height: 32px; }
    .controls-hint { bottom: 6px; font-size: 0.65rem; padding: 4px 10px; }
    .overlay-card { padding: 16px; gap: 6px; }
    .overlay-title { font-size: 1.1rem; }
    .overlay-subtitle { font-size: 0.75rem; }
    .btn-primary, .btn-secondary { padding: 10px; min-height: 36px; font-size: 0.85rem; }
}