/* --- CSS Variables & Theme --- */
:root {
    --bg-dark: #0a1128;
    --primary: #0077b6;
    --primary-hover: #023e8a;
    --accent-gold: #ffd700;
    --accent-gold-glow: rgba(255, 215, 0, 0.4);
    --text-light: #f8f9fa;
    --text-muted: #94a3b8;
    --card-bg: rgba(10, 17, 40, 0.85);
    --card-border: rgba(255, 215, 0, 0.25);
    --radius-lg: 20px;
    --radius-md: 12px;
    --font-family: 'Tajawal', -apple-system, BlinkMacSystemFont, sans-serif;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}

body, html {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: var(--bg-dark);
    font-family: var(--font-family);
    color: var(--text-light);
    direction: rtl;
}

#game-container {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    z-index: 1;
}

canvas {
    display: block;
    width: 100%;
    height: 100%;
}

/* --- UI Layer --- */
#ui-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10;
    pointer-events: none;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

/* Header HUD */
.hud-top {
    display: flex;
    justify-content: center;
    gap: 16px;
    padding: 20px;
    pointer-events: auto;
}

.hud-card {
    background: var(--card-bg);
    border: 1px solid rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    padding: 10px 20px;
    border-radius: var(--radius-md);
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 100px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.hud-card.highlight {
    border-color: var(--accent-gold);
    box-shadow: 0 0 15px var(--accent-gold-glow);
}

.hud-label {
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 700;
}

.hud-value {
    font-size: 22px;
    font-weight: 900;
    color: var(--accent-gold);
}

/* Overlay Screens */
.overlay-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(10, 17, 40, 0.85);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    pointer-events: auto;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

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

.overlay-screen.active {
    opacity: 1;
    visibility: visible;
}

.card-panel {
    background: var(--card-bg);
    border: 2px solid var(--card-border);
    border-radius: var(--radius-lg);
    padding: 36px 28px;
    max-width: 440px;
    width: 100%;
    text-align: center;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5), 0 0 20px var(--accent-gold-glow);
}

.game-title {
    font-size: 32px;
    font-weight: 900;
    color: var(--accent-gold);
    margin-bottom: 8px;
    text-shadow: 0 2px 10px rgba(255, 215, 0, 0.3);
}

.game-subtitle {
    font-size: 15px;
    color: var(--text-muted);
    margin-bottom: 24px;
    line-height: 1.6;
}

.game-over-title {
    font-size: 30px;
    font-weight: 900;
    color: #ef4444;
    margin-bottom: 20px;
}

/* Controls Guide */
.controls-guide {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 28px;
    text-align: right;
    background: rgba(255, 255, 255, 0.03);
    padding: 16px;
    border-radius: var(--radius-md);
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.guide-item {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 14px;
    color: var(--text-light);
}

.guide-item svg {
    width: 20px;
    height: 20px;
    color: var(--accent-gold);
    flex-shrink: 0;
}

/* Results Grid */
.results-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 28px;
}

.res-item {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    padding: 14px;
    border-radius: var(--radius-md);
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.res-item.full {
    grid-column: span 2;
    background: rgba(255, 215, 0, 0.08);
    border-color: var(--accent-gold);
}

.res-item span {
    font-size: 13px;
    color: var(--text-muted);
}

.res-item strong {
    font-size: 20px;
    color: var(--accent-gold);
}

/* Buttons */
.btn-primary {
    width: 100%;
    height: 52px;
    background: linear-gradient(135deg, var(--accent-gold) 0%, #d4af37 100%);
    color: #0a1128;
    border: none;
    border-radius: var(--radius-md);
    font-family: var(--font-family);
    font-size: 18px;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
    box-shadow: 0 4px 15px rgba(255, 215, 0, 0.3);
}

.btn-primary:active {
    transform: scale(0.98);
}

.btn-primary svg {
    width: 22px;
    height: 22px;
    stroke-width: 2.5;
}

/* Touch Controls */
#touch-controls {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    padding: 24px 20px;
    pointer-events: auto;
    width: 100%;
}

#joystick-zone {
    width: 120px;
    height: 120px;
    display: flex;
    align-items: center;
    justify-content: center;
}

#joystick-base {
    width: 100px;
    height: 100px;
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid rgba(255, 215, 0, 0.4);
    border-radius: 50%;
    position: relative;
    touch-action: none;
    display: flex;
    align-items: center;
    justify-content: center;
}

#joystick-stick {
    width: 44px;
    height: 44px;
    background: var(--accent-gold);
    border-radius: 50%;
    box-shadow: 0 0 10px var(--accent-gold-glow);
    pointer-events: none;
    transition: transform 0.05s linear;
}

#touch-buttons {
    display: flex;
    gap: 16px;
}

.touch-action-btn {
    width: 70px;
    height: 70px;
    border-radius: 50%;
    background: rgba(0, 119, 182, 0.6);
    border: 2px solid var(--accent-gold);
    color: var(--accent-gold);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    touch-action: manipulation;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}

.touch-action-btn:active {
    background: var(--primary);
    transform: scale(0.92);
}

.touch-action-btn svg {
    width: 32px;
    height: 32px;
    pointer-events: none;
}

/* Responsive adjustments */
@media (min-width: 769px) {
    #touch-controls {
        display: none;
    }
}
