/* ==========================================
   CARGOX ADVENTURES - DESIGN SYSTEM & STYLES
   ========================================== */

/* Design Tokens & Theme Variables */
:root {
    --font-title: 'Outfit', sans-serif;
    --font-body: 'Inter', sans-serif;

    /* Color Palette */
    --color-primary: #5cbf3a;      /* Emerald Green (CargoX theme / Documents) */
    --color-primary-dark: #3d9022;
    --color-secondary: #0284c7;    /* Ocean Blue (UI secondary / Sky) */
    --color-secondary-dark: #0369a1;
    --color-accent: #f59e0b;       /* Coin Gold */
    --color-danger: #ef4444;       /* Hurt / Error */
    
    /* Backgrounds & Panels */
    --color-bg-dark: #071930;      /* Midnight Deep Blue */
    --color-glass-bg: rgba(10, 25, 47, 0.75);
    --color-glass-border: rgba(255, 255, 255, 0.12);
    --color-glass-glow: rgba(92, 191, 58, 0.15);
    
    /* Transitions */
    --transition-fast: 0.15s ease;
    --transition-normal: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Reset and Base Rules */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
}

body, html {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: var(--color-bg-dark);
    font-family: var(--font-body);
    color: #ffffff;
}

/* Game Window Wrapper */
#game-container {
    position: relative;
    width: 100vw;
    height: 100vh;   /* fallback for older browsers */
    height: 100dvh;  /* dynamic viewport — excludes the mobile browser's URL/tool
                        bars so the bottom on-screen controls stay visible (100vh
                        counts the retracted-bar height → controls land off-screen
                        in-browser; in a PWA there's no chrome so 100vh was fine) */
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Game Canvas */
#game-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    display: block;
}

/* ==========================================
   UI OVERLAYS (GLASSMORPHISM)
   ========================================== */
.overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10;
    display: none;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(8px) saturate(120%);
    -webkit-backdrop-filter: blur(8px) saturate(120%);
    background: rgba(4, 15, 30, 0.65);
    opacity: 0;
    transition: opacity var(--transition-normal);
    overflow-y: auto;
    padding: 24px 0;
}

.overlay.active {
    display: flex;
    opacity: 1;
}

/* Glassmorphism Containers */
.menu-content, .tutorial-content {
    background: var(--color-glass-bg);
    border: 2px solid var(--color-glass-border);
    border-radius: 24px;
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.4), inset 0 1px 1px rgba(255,255,255,0.1);
    padding: 40px;
    width: 90%;
    max-width: 520px;
    text-align: center;
    animation: zoomIn var(--transition-normal);
    margin: auto;
}

.tutorial-content {
    max-width: 800px;
}

/* Upgrade shop */
.shop-content {
    max-width: 560px;
}
.shop-wallet {
    font-family: var(--font-title);
    font-size: 18px;
    font-weight: 800;
    color: #fbbf24;
    margin: 4px 0 16px 0;
    letter-spacing: 0.02em;
}
.shop-list {
    list-style: none;
    margin: 0 0 20px 0;
    padding: 0;
    max-height: 56vh;
    overflow-y: auto;
    text-align: left;
}
.shop-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--color-glass-border);
    margin-bottom: 8px;
}
.shop-icon {
    flex: 0 0 38px;
    font-size: 26px;
    text-align: center;
    line-height: 1;
}
.shop-meta {
    flex: 1;
    min-width: 0;
    font-family: 'Inter', sans-serif;
    font-size: 14px;
    color: #fff;
    line-height: 1.35;
}
.shop-desc {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.6);
}
.shop-lvl {
    font-size: 11px;
    font-weight: 700;
    color: var(--color-primary);
    margin-left: 6px;
    vertical-align: middle;
}
.shop-buy {
    flex: 0 0 auto;
    font-family: var(--font-title);
    font-size: 13px;
    font-weight: 700;
    white-space: nowrap;
    padding: 8px 12px;
    border: none;
    border-radius: 10px;
    color: #042311;
    background: linear-gradient(135deg, #7cd15a, var(--color-primary));
    cursor: pointer;
    transition: transform var(--transition-fast), filter var(--transition-fast);
}
.shop-buy:hover:not(:disabled) {
    transform: translateY(-1px);
    filter: brightness(1.08);
}
.shop-buy:disabled {
    background: rgba(255, 255, 255, 0.12);
    color: rgba(255, 255, 255, 0.45);
    cursor: not-allowed;
}

/* Logo Design */
.logo-container {
    margin-bottom: 25px;
}

.logo-title {
    font-family: var(--font-title);
    font-size: 52px;
    font-weight: 900;
    letter-spacing: -0.02em;
    line-height: 1.1;
    text-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
}

.highlight-cargo {
    color: #ffffff;
}

.highlight-x {
    color: var(--color-primary);
    background: linear-gradient(135deg, #7cd15a, #3d9022);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    padding-left: 2px;
}

.logo-subtitle {
    font-family: var(--font-title);
    font-size: 18px;
    font-weight: 700;
    letter-spacing: 0.28em;
    color: var(--color-primary);
    margin-top: -2px;
    text-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

/* Character Preview in Menu */
.menu-character-preview {
    position: relative;
    width: 100px;
    height: 100px;
    margin: 0 auto 30px auto;
    animation: floatCharacter 4s ease-in-out infinite;
}

.preview-body {
    width: 70px;
    height: 70px;
    background: var(--color-primary);
    border: 3px solid #2f6b1a;
    border-radius: 12px;
    position: absolute;
    bottom: 5px;
    left: 15px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.3);
}

.preview-cap {
    width: 60px;
    height: 25px;
    background: var(--color-secondary-dark);
    border: 3px solid #0c4a6e;
    border-radius: 20px 20px 0 0;
    position: absolute;
    top: 5px;
    left: 12px;
    z-index: 2;
}

.preview-cap::after {
    content: '';
    width: 30px;
    height: 8px;
    background: var(--color-secondary);
    border: 3px solid #0c4a6e;
    border-radius: 0 10px 10px 0;
    position: absolute;
    right: -25px;
    bottom: -3px;
}

/* Skins for character preview */
.menu-character-preview.skin_gold .preview-body {
    background: linear-gradient(180deg, #fbbf24, #d97706);
    border-color: #78350f;
}
.menu-character-preview.skin_gold .preview-cap {
    background: #f59e0b;
    border-color: #78350f;
}
.menu-character-preview.skin_gold .preview-cap::after {
    background: #b45309;
    border-color: #78350f;
}

.menu-character-preview.skin_carbon .preview-body {
    background: linear-gradient(180deg, #374151, #111827);
    border-color: #09090b;
}
.menu-character-preview.skin_carbon .preview-cap {
    background: #ef4444;
    border-color: #991b1b;
}
.menu-character-preview.skin_carbon .preview-cap::after {
    background: #991b1b;
    border-color: #991b1b;
}

.menu-character-preview.skin_neon .preview-body {
    background: linear-gradient(180deg, #06b6d4, #0891b2);
    border-color: #083344;
}
.menu-character-preview.skin_neon .preview-cap {
    background: #ec4899;
    border-color: #9d174d;
}
.menu-character-preview.skin_neon .preview-cap::after {
    background: #be185d;
    border-color: #9d174d;
}

.preview-eyes {
    display: flex;
    gap: 8px;
    margin-top: 5px;
}

.preview-eye {
    width: 12px;
    height: 16px;
    background: #ffffff;
    border-radius: 50%;
    position: relative;
}

.preview-pupil {
    width: 6px;
    height: 8px;
    background: #000000;
    border-radius: 50%;
    position: absolute;
    top: 4px;
    left: 3px;
}

.preview-mouth {
    width: 16px;
    height: 8px;
    border-bottom: 3px solid #000000;
    border-radius: 0 0 10px 10px;
    margin-top: 4px;
}

.preview-text {
    font-family: var(--font-title);
    font-size: 8px;
    font-weight: 900;
    color: #ffffff;
    margin-top: 4px;
    letter-spacing: 0.5px;
}

/* Buttons */
.menu-buttons {
    display: flex;
    flex-direction: column;
    gap: 15px;
    max-width: 320px;
    margin: 0 auto;
}

.btn {
    font-family: var(--font-title);
    font-size: 18px;
    font-weight: 700;
    padding: 14px 28px;
    border-radius: 14px;
    border: none;
    cursor: pointer;
    transition: all var(--transition-fast);
    outline: none;
    letter-spacing: 0.5px;
}

.btn-primary {
    background: linear-gradient(135deg, var(--color-primary), var(--color-primary-dark));
    color: #ffffff;
    box-shadow: 0 4px 14px rgba(92, 191, 58, 0.4);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(92, 191, 58, 0.6);
}

.btn-primary:active {
    transform: translateY(1px);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: #ffffff;
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.15);
    transform: translateY(-2px);
}

.btn-danger {
    background: linear-gradient(135deg, var(--color-danger), #b91c1c);
    color: #ffffff;
}

.btn-danger:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(239, 68, 68, 0.4);
}

.btn-glow {
    position: relative;
    overflow: hidden;
}

.btn-glow::after {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: linear-gradient(45deg, transparent, rgba(255,255,255,0.2), transparent);
    transform: rotate(45deg);
    transition: all 0.5s;
    animation: shineEffect 3s infinite linear;
}

/* Credits */
.credits {
    font-size: 11px;
    color: #64748b;
    margin-top: 35px;
}

/* ==========================================
   TUTORIAL SCREEN
   ========================================== */
#tutorial-screen h2 {
    font-family: var(--font-title);
    font-size: 32px;
    font-weight: 800;
    margin-bottom: 8px;
    color: #ffffff;
}

.tutorial-lead {
    color: #94a3b8;
    font-size: 16px;
    margin-bottom: 30px;
}

.tutorial-steps {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 20px;
    margin-bottom: 35px;
    text-align: left;
}

.tutorial-step {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 16px;
    padding: 20px;
    position: relative;
    transition: background var(--transition-fast);
}

.tutorial-step:hover {
    background: rgba(255, 255, 255, 0.06);
}

.step-badge {
    background: var(--color-secondary);
    color: #ffffff;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-family: var(--font-title);
    margin-bottom: 12px;
}

.tutorial-step h3 {
    font-family: var(--font-title);
    font-size: 16px;
    font-weight: 700;
    margin-bottom: 8px;
    color: var(--color-primary);
}

.tutorial-step p {
    font-size: 13px;
    line-height: 1.5;
    color: #cbd5e1;
}

.tutorial-step span {
    background: rgba(255, 255, 255, 0.15);
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: bold;
    font-family: monospace;
    font-size: 11px;
}

/* ==========================================
   HEADS-UP DISPLAY (HUD)
   ========================================== */
.hud-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 5;
    pointer-events: none; /* Let clicks pass to the canvas unless on buttons */
    display: none;
    flex-direction: column;
    justify-content: space-between;
    padding: 20px;
}

.hud-container.active {
    display: flex;
}

/* HUD Top Bar */
.hud-top-bar {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.hud-logo-section {
    font-family: var(--font-title);
    font-weight: 900;
    font-size: 24px;
    text-shadow: 0 2px 4px rgba(0,0,0,0.4);
    cursor: pointer;
    transition: opacity 0.15s;
}
.hud-logo-section:hover { opacity: 0.82; }

.hud-logo-cargo {
    color: #ffffff;
}

.hud-logo-x {
    color: var(--color-primary);
}

.hud-logo-sub {
    display: block;
    font-size: 9px;
    letter-spacing: 0.28em;
    color: var(--color-primary);
    margin-top: -5px;
    font-weight: 700;
}

.hud-stats-group {
    display: flex;
    gap: 12px;
}

.hud-stat-box {
    background: rgba(9, 21, 39, 0.85);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 12px;
    padding: 6px 14px;
    display: flex;
    align-items: center;
    gap: 10px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.25);
    pointer-events: auto; /* Clickable */
}

.hud-stat-icon {
    font-size: 20px;
}

.hud-stat-labels {
    display: flex;
    flex-direction: column;
}

.hud-stat-title {
    font-family: var(--font-title);
    font-size: 9px;
    font-weight: 800;
    color: #94a3b8;
    letter-spacing: 0.05em;
    line-height: 1;
    margin-bottom: 2px;
}

.hud-stat-value {
    font-family: var(--font-body);
    font-size: 16px;
    font-weight: 800;
    color: #ffffff;
    line-height: 1.1;
}

/* Coin animation pulse */
.coin-pulse {
    animation: coinPulseAnim 2s infinite ease-in-out;
}

.hud-right-group {
    display: flex;
    align-items: center;
    gap: 15px;
}

.hud-lives {
    display: flex;
    gap: 4px;
    background: rgba(9, 21, 39, 0.85);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 12px;
    padding: 8px 12px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.25);
}

.hud-lives .heart {
    font-size: 16px;
    filter: drop-shadow(0 2px 2px rgba(0,0,0,0.3));
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.hud-lives .heart.hurt {
    transform: scale(0);
    opacity: 0.3;
    filter: grayscale(100%);
}

/* Active-perk icons (shield/magnet/jump/×2) — sits between lives and pause. */
.hud-perks {
    display: flex;
    gap: 4px;
    align-items: center;
}
.hud-perks:empty {
    display: none;
}
.hud-perks .hud-perk {
    font-size: 15px;
    line-height: 1;
    background: rgba(9, 21, 39, 0.85);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 10px;
    padding: 7px 8px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.25);
    filter: drop-shadow(0 2px 2px rgba(0,0,0,0.3));
    animation: perkPop 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
@keyframes perkPop {
    from { transform: scale(0.4); opacity: 0; }
    to   { transform: scale(1);   opacity: 1; }
}

.hud-pause-btn {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    background: rgba(9, 21, 39, 0.85);
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: #ffffff;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 10px rgba(0,0,0,0.25);
    pointer-events: auto;
    transition: all var(--transition-fast);
}

.hud-pause-btn:hover {
    background: rgba(92, 191, 58, 0.2);
    border-color: var(--color-primary);
    transform: scale(1.05);
}

.hud-pause-btn:active {
    transform: scale(0.95);
}

/* Floating Goal Panel (Top Right) */
.hud-goal-panel {
    position: absolute;
    top: 85px;
    right: 20px;
    width: 220px;
    background: rgba(9, 21, 39, 0.85);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 14px;
    padding: 12px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
    z-index: 4;
}

.goal-header {
    font-family: var(--font-title);
    font-size: 10px;
    font-weight: 900;
    color: var(--color-primary);
    letter-spacing: 0.1em;
    margin-bottom: 4px;
}

.goal-desc {
    font-size: 11px;
    color: #cbd5e1;
    line-height: 1.3;
    margin-bottom: 8px;
}

.goal-progress-container {
    width: 100%;
    height: 6px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
    overflow: hidden;
    margin-bottom: 4px;
}

.goal-progress-bar {
    height: 100%;
    background: linear-gradient(90deg, #7cd15a, var(--color-primary));
    border-radius: 3px;
    transition: width 0.3s ease;
}

.goal-progress-text {
    font-size: 10px;
    color: #94a3b8;
    text-align: right;
}

/* Level Progress Tracker (Bottom Center) */
.hud-level-progress {
    width: 100%;
    max-width: 460px;
    margin: 0 auto 10px auto;
    background: rgba(9, 21, 39, 0.85);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 14px;
    padding: 10px 18px;
    box-shadow: 0 8px 20px rgba(0,0,0,0.3);
}

.progress-bar-track {
    display: flex;
    align-items: center;
    gap: 10px;
}

.progress-ship-icon {
    font-size: 16px;
}

.progress-line {
    flex-grow: 1;
    height: 4px;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 2px;
    position: relative;
}

.progress-fill {
    height: 100%;
    background: var(--color-primary);
    border-radius: 2px;
    transition: width 0.1s linear;
}

.progress-player-pin {
    position: absolute;
    top: -9px;
    transform: translateX(-50%);
    font-size: 15px;
    transition: left 0.1s linear;
    z-index: 3;
}

.progress-checkpoints {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.checkpoint-dot {
    position: absolute;
    width: 8px;
    height: 8px;
    background: #091527;
    border: 2px solid #ffffff;
    border-radius: 50%;
    top: -2px;
    transform: translateX(-50%);
    z-index: 2;
    transition: border-color 0.3s;
}

.checkpoint-dot.reached {
    border-color: var(--color-primary);
    background: var(--color-primary);
}

/* ==========================================
   MOBILE TOUCH CONTROLS
   ========================================== */
#mobile-controls {
    display: none; /* Shown dynamically on touch devices */
    width: 100%;
    justify-content: space-between;
    align-items: flex-end;
    pointer-events: none; /* Let canvas draw behind */
    margin-top: auto;
    margin-bottom: 10px;
    padding-bottom: env(safe-area-inset-bottom, 0px); /* clear iOS home indicator */
}

.control-group-left {
    display: flex;
    gap: 15px;
    pointer-events: auto;
}

.control-group-right {
    pointer-events: auto;
}

.touch-btn {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    background: rgba(9, 21, 39, 0.65);
    border: 2px solid rgba(255, 255, 255, 0.3);
    color: #ffffff;
    font-size: 32px;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.3);
    cursor: pointer;
    transition: transform 0.05s, background-color 0.1s, border-color 0.1s;
    user-select: none;
    -webkit-user-select: none;
}

.touch-btn:active {
    transform: scale(0.88);
    background: rgba(92, 191, 58, 0.3);
    border-color: var(--color-primary);
}

.touch-btn span {
    pointer-events: none;
    display: block;
    margin-top: -6px; /* Align arrow characters */
}

.jump-btn {
    width: 80px;
    height: 80px;
    background: rgba(92, 191, 58, 0.2);
    border-color: rgba(92, 191, 58, 0.5);
}

.jump-btn:active {
    background: rgba(92, 191, 58, 0.5);
    border-color: #7cd15a;
}

/* ==========================================
   GAME STATE OTHER SCREENS
   ========================================== */
.stats-summary {
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 16px;
    padding: 20px;
    margin: 20px auto 30px auto;
    max-width: 320px;
}

.stat-summary-row {
    display: flex;
    justify-content: space-between;
    font-size: 15px;
    padding: 8px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    color: #cbd5e1;
}

.stat-summary-row:last-child {
    border-bottom: none;
}

.stat-summary-row strong {
    color: #ffffff;
    font-size: 16px;
}

/* Game Over Title details */
.game-over-title {
    font-family: var(--font-title);
    font-size: 42px;
    color: var(--color-danger);
    font-weight: 900;
    text-shadow: 0 4px 10px rgba(0, 0, 0, 0.5);
}

.game-over-subtitle {
    color: #94a3b8;
    margin-bottom: 20px;
}

/* Win Title details */
.win-title {
    font-family: var(--font-title);
    font-size: 38px;
    color: var(--color-primary);
    font-weight: 900;
    text-shadow: 0 4px 10px rgba(0, 0, 0, 0.5);
}

.win-subtitle {
    color: #94a3b8;
    margin-bottom: 20px;
}

/* Victory Title details */
.victory-title {
    font-family: var(--font-title);
    font-size: 44px;
    color: #fbbf24;
    font-weight: 900;
    text-shadow: 0 4px 15px rgba(251, 191, 36, 0.3);
}

.victory-subtitle {
    color: #e2e8f0;
}

.victory-medal {
    font-size: 72px;
    margin: 20px 0;
    animation: bounceMedal 2s infinite ease-in-out;
}

/* ==========================================
   ANIMATIONS & KEYFRAMES
   ========================================== */
@keyframes zoomIn {
    from {
        transform: scale(0.95);
        opacity: 0;
    }
    to {
        transform: scale(1);
        opacity: 1;
    }
}

@keyframes floatCharacter {
    0%, 100% {
        transform: translateY(0px) rotate(0deg);
    }
    50% {
        transform: translateY(-8px) rotate(2deg);
    }
}

@keyframes shineEffect {
    0% {
        left: -100%;
    }
    100% {
        left: 100%;
    }
}

@keyframes coinPulseAnim {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.15);
        filter: drop-shadow(0 0 4px var(--color-accent));
    }
}

@keyframes bounceMedal {
    0%, 100% {
        transform: translateY(0) scale(1);
    }
    50% {
        transform: translateY(-10px) scale(1.05);
        filter: drop-shadow(0 0 15px rgba(251, 191, 36, 0.5));
    }
}

/* Media Queries for Responsive adjustments */
@media (max-width: 768px) {
    .menu-content {
        padding: 30px 20px;
    }
    
    .logo-title {
        font-size: 38px;
    }
    
    .logo-subtitle {
        font-size: 14px;
    }
    
    .hud-logo-section {
        display: none; /* Hide brand logo on small screens to save space */
    }
    
    .hud-stat-box {
        padding: 4px 8px;
        gap: 6px;
    }
    
    .hud-stat-icon {
        font-size: 16px;
    }
    
    .hud-stat-title {
        font-size: 8px;
    }
    
    .hud-stat-value {
        font-size: 12px;
    }
    
    .hud-goal-panel {
        top: 70px;
        right: 15px;
        width: 180px;
    }
    
    .hud-lives {
        padding: 6px 10px;
    }
}

/* Helper Class to force touch controls display */
.touch-enabled #mobile-controls {
    display: flex;
}

/* Touch devices (phones/tablets, incl. installed PWA): always show the on-screen
   controls — covers the case before any interaction and is a CSS-level fallback
   to the JS toggle above. */
@media (pointer: coarse) {
    #mobile-controls {
        display: flex;
    }
}

/* Language Selector styling */
.lang-selector {
    position: absolute;
    top: 20px;
    right: 20px;
    z-index: 100;
    display: flex;
    gap: 6px;
    background: rgba(9, 21, 39, 0.7);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 12px;
    padding: 4px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.lang-btn {
    background: transparent;
    border: none;
    color: #94a3b8;
    padding: 6px 12px;
    font-family: var(--font-title);
    font-weight: 700;
    font-size: 13px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.lang-btn:hover {
    color: #ffffff;
    background: rgba(255, 255, 255, 0.08);
}

.lang-btn.active {
    color: #ffffff;
    background: var(--color-primary);
    box-shadow: 0 2px 8px rgba(92, 191, 58, 0.4);
}

body.state-playing .lang-selector {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

/* Back-to-site link — top-left, visible only on the start menu. */
.game-back-link {
    position: absolute;
    top: 20px;
    left: 20px;
    z-index: 100;
    display: none;
    align-items: center;
    gap: 6px;
    background: rgba(9, 21, 39, 0.7);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 12px;
    padding: 8px 14px;
    color: #e6edf3;
    text-decoration: none;
    font-family: var(--font-title);
    font-weight: 700;
    font-size: 13px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    transition: color 0.2s ease, border-color 0.2s ease;
}
.game-back-link:hover {
    color: #ffffff;
    border-color: var(--color-primary);
}
body.state-menu .game-back-link {
    display: inline-flex;
}

/* Start Menu buttons arrangement for mobile landscape */
.menu-buttons-row {
    display: flex;
    gap: 12px;
    width: 100%;
}
.menu-buttons-row .btn {
    flex: 1;
    min-width: 0;            /* allow the flex item to shrink below content width */
    margin: 0;
    white-space: nowrap;
    /* Secondary row buttons are smaller than PLAY GAME and trimmed enough that
       the longest localized labels (e.g. SL "ZVOK: IZKLOPLJEN", DE "BESTENLISTE")
       fit on one line inside half the menu width — no text clipping. */
    font-size: 15px;
    padding: 13px 10px;
    letter-spacing: 0.2px;
}

/* Responsive button scaling on small mobile screens */
@media (max-width: 580px) {
    /* Tighter menu padding frees up horizontal room for the row buttons. */
    .menu-content {
        padding: 28px 20px;
    }
    .menu-buttons {
        gap: 10px;
    }
    .menu-buttons .btn {
        font-size: 14px;
        padding: 11px 8px;
        border-radius: 10px;
    }
    .menu-buttons .btn-primary {
        font-size: 16px;
        padding: 12px 24px;
        border-radius: 12px;
    }
    .menu-buttons-row {
        gap: 8px;
    }
    .menu-buttons-row .btn {
        font-size: 13px;
        padding: 11px 6px;
        letter-spacing: 0;
    }
}
