/* ═══════════════════════════════════════════════════════════
   AgriVerse — Smart Agriculture Metaverse Styles
   Premium dark glassmorphism UI — RTL optimized
   ═══════════════════════════════════════════════════════════ */

:root {
    --bg-dark: #0a0e17;
    --bg-card: rgba(15, 23, 42, 0.85);
    --bg-glass: rgba(15, 23, 42, 0.65);
    --border: rgba(99, 179, 130, 0.2);
    --border-hover: rgba(99, 179, 130, 0.5);
    --accent: #4ade80;
    --accent-glow: rgba(74, 222, 128, 0.3);
    --accent-2: #38bdf8;
    --accent-3: #f59e0b;
    --text: #e2e8f0;
    --text-dim: #94a3b8;
    --text-bright: #f8fafc;
    --danger: #f43f5e;
    --success: #22c55e;
    --warning: #f59e0b;
    --radius: 12px;
    --radius-sm: 8px;
    --font: 'IBM Plex Sans Arabic', 'Noto Kufi Arabic', -apple-system, sans-serif;
    --mono: 'JetBrains Mono', monospace;
    --shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    --shadow-glow: 0 0 30px rgba(74, 222, 128, 0.15);
    /* Safe area insets for notched devices */
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-right: env(safe-area-inset-right, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
}

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

html {
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
}

body {
    font-family: var(--font);
    background: var(--bg-dark);
    color: var(--text);
    overflow: hidden;
    cursor: crosshair;
    -webkit-user-select: none;
    user-select: none;
    touch-action: none;
    overscroll-behavior: none;
}

/* ── Loading Screen ─────────────────────────────────────── */

#loading-screen {
    position: fixed;
    inset: 0;
    z-index: 10000;
    background: linear-gradient(135deg, #0a0e17 0%, #0f1a2e 50%, #0a1628 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.8s ease, visibility 0.8s ease;
}

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

.loader-content {
    text-align: center;
}

.loader-icon {
    font-size: 64px;
    animation: pulse 1.5s ease-in-out infinite;
    margin-bottom: 16px;
}

.loader-content h1 {
    font-size: 42px;
    font-weight: 800;
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: -1px;
    margin-bottom: 8px;
}

.loader-content p {
    color: var(--text-dim);
    font-size: 14px;
    margin-bottom: 24px;
}

.loader-bar {
    width: 240px;
    height: 4px;
    border-radius: 4px;
    background: rgba(255,255,255,0.1);
    margin: 0 auto;
    overflow: hidden;
}

.loader-fill {
    height: 100%;
    width: 0%;
    border-radius: 4px;
    background: linear-gradient(90deg, var(--accent), var(--accent-2));
    animation: loadFill 2.5s ease-in-out forwards;
}

@keyframes loadFill {
    0% { width: 0%; }
    60% { width: 70%; }
    100% { width: 100%; }
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.15); }
}

/* ── Canvas ─────────────────────────────────────────────── */

#metaverse-canvas {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    touch-action: none;
}

/* ── Crosshair ──────────────────────────────────────────── */

#crosshair {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: rgba(255, 255, 255, 0.3);
    font-size: 20px;
    font-weight: 300;
    pointer-events: none;
    z-index: 50;
    text-shadow: 0 0 4px rgba(0,0,0,0.5);
}

/* ── Top HUD ────────────────────────────────────────────── */

#hud-top {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    padding-top: calc(12px + var(--safe-top));
    background: linear-gradient(180deg, rgba(10, 14, 23, 0.9) 0%, transparent 100%);
    pointer-events: none;
    direction: rtl; /* Force RTL for the HUD */
}

#hud-top > * { pointer-events: auto; }

/* RTL: Logo on the RIGHT side */
.hud-left {
    order: 1;
    display: flex;
    align-items: center;
}

/* RTL: Badges in CENTER */
.hud-center {
    order: 2;
    display: flex;
    flex-direction: row-reverse;
    gap: 8px;
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
}

/* RTL: Buttons on the LEFT side */
.hud-right {
    order: 3;
    display: flex;
    flex-direction: row-reverse;
    gap: 6px;
}

.hud-logo {
    font-size: 20px;
    font-weight: 800;
    display: flex;
    align-items: center;
    gap: 8px;
}

.hud-logo span {
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.hud-badge {
    display: flex;
    flex-direction: row-reverse;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    background: var(--bg-glass);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border);
    border-radius: 20px;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.3s ease;
    direction: rtl;
}

.hud-badge:hover {
    border-color: var(--border-hover);
    box-shadow: var(--shadow-glow);
}

.hud-btn {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--bg-glass);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    font-size: 16px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    -webkit-tap-highlight-color: transparent;
}

.hud-btn:hover {
    background: rgba(74, 222, 128, 0.15);
    border-color: var(--accent);
    transform: scale(1.05);
}

.hud-btn.active {
    background: rgba(74, 222, 128, 0.2);
    border-color: var(--accent);
    box-shadow: 0 0 12px var(--accent-glow);
}

.hud-btn-label {
    width: auto;
    padding: 0 14px;
    font-size: 12px;
    font-weight: 600;
    font-family: var(--font);
    color: var(--text);
    letter-spacing: 0.2px;
    direction: rtl;
}

/* ── Mobile Hamburger Menu ──────────────────────────────── */

#mobile-menu-toggle {
    display: none;
    width: 38px;
    height: 38px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--bg-glass);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    font-size: 18px;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    -webkit-tap-highlight-color: transparent;
    color: var(--text);
    transition: all 0.2s ease;
}

#mobile-menu-toggle:hover,
#mobile-menu-toggle.active {
    background: rgba(74, 222, 128, 0.15);
    border-color: var(--accent);
}

#mobile-menu-dropdown {
    display: none;
    position: fixed;
    top: 60px;
    left: 16px;
    right: 16px;
    z-index: 250;
    background: var(--bg-card);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
    box-shadow: var(--shadow);
    flex-direction: column;
    gap: 6px;
    animation: menuSlideDown 0.25s ease;
}

#mobile-menu-dropdown.show {
    display: flex;
}

@keyframes menuSlideDown {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

#mobile-menu-dropdown .mobile-menu-item {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.03);
    color: var(--text);
    font-family: var(--font);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    text-align: right;
    text-decoration: none;
    display: block;
    -webkit-tap-highlight-color: transparent;
    transition: all 0.2s ease;
}

#mobile-menu-dropdown .mobile-menu-item:active {
    background: rgba(74, 222, 128, 0.15);
    border-color: var(--accent);
}

/* ── Zone Bar ───────────────────────────────────────────── */

#zone-bar {
    position: fixed;
    top: 64px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 100;
    padding: 6px 18px;
    background: var(--bg-glass);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border);
    border-radius: 20px;
    font-size: 13px;
    transition: all 0.3s ease;
    opacity: 0.9;
    white-space: nowrap;
}

/* ── Minimap — Satellite Style ──────────────────────────── */

#minimap {
    position: fixed;
    bottom: 80px;
    left: 16px;
    z-index: 100;
    width: 240px;
    height: 240px;
    border-radius: 16px;
    border: 2px solid rgba(74, 222, 128, 0.25);
    background: rgba(10, 15, 28, 0.95);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    overflow: hidden;
    box-shadow:
        0 8px 40px rgba(0, 0, 0, 0.6),
        0 0 30px rgba(74, 222, 128, 0.08),
        inset 0 1px 0 rgba(255,255,255,0.05);
    transition: all 0.3s ease;
}

#minimap.hidden { display: none; }

#minimap-canvas {
    width: 100%;
    height: 100%;
}

#minimap-label {
    position: absolute;
    top: 8px;
    right: 10px;
    font-size: 9px;
    text-transform: uppercase;
    letter-spacing: 2px;
    color: var(--accent);
    font-weight: 700;
    opacity: 0.8;
    text-shadow: 0 0 8px rgba(74, 222, 128, 0.4);
}

/* Minimap compass */
#minimap-compass {
    position: absolute;
    top: 8px;
    left: 10px;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 8px;
    font-weight: 800;
    color: var(--danger);
    background: rgba(0,0,0,0.5);
    border-radius: 50%;
    border: 1px solid rgba(255,255,255,0.1);
}

/* Minimap coordinates */
#minimap-coords {
    position: absolute;
    bottom: 6px;
    left: 10px;
    font-size: 8px;
    font-family: var(--mono);
    color: var(--text-dim);
    opacity: 0.7;
}

/* Minimap scale legend */
#minimap-scale {
    position: absolute;
    bottom: 6px;
    right: 10px;
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 7px;
    font-family: var(--mono);
    color: var(--text-dim);
    opacity: 0.7;
}

#minimap-scale .scale-bar {
    width: 20px;
    height: 2px;
    background: var(--text-dim);
    border-radius: 1px;
}

/* ── Panels (shared) — RTL: right side ──────────────────── */

.panel {
    position: fixed;
    z-index: 200;
    width: 340px;
    max-height: 80vh;
    background: var(--bg-card);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    transition: all 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}

.panel.hidden {
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    pointer-events: none;
}

.panel-large {
    position: fixed;
    z-index: 200;
    width: 520px;
    max-height: 85vh;
    background: var(--bg-card);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow-y: auto;
    transition: all 0.35s cubic-bezier(0.16, 1, 0.3, 1);
    /* RTL: panels on the right */
    right: 16px;
    top: 64px;
}

.panel-large.hidden {
    opacity: 0;
    transform: translateX(-40px);
    pointer-events: none;
}

/* RTL: Position panels on right side (natural reading side) */
#sensor-panel { right: 16px; left: auto; top: 100px; }
#prediction-panel { right: 16px; left: auto; top: 100px; }
#help-panel { right: 16px; left: auto; top: 64px; width: 280px; }

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
}

.panel-header h3 {
    font-size: 15px;
    font-weight: 700;
}

.panel-close {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-dim);
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    -webkit-tap-highlight-color: transparent;
}

.panel-close:hover {
    background: rgba(244, 63, 94, 0.15);
    border-color: var(--danger);
    color: var(--danger);
}

/* ── Sensor Panel ───────────────────────────────────────── */

#sensor-panel-body {
    padding: 14px 18px;
    max-height: 350px;
    overflow-y: auto;
}

.sensor-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.sensor-card {
    padding: 10px 12px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: var(--radius-sm);
    transition: all 0.2s;
}

.sensor-card:hover {
    background: rgba(74, 222, 128, 0.05);
    border-color: rgba(74, 222, 128, 0.2);
}

.sensor-card .sensor-label {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-dim);
    margin-bottom: 4px;
    font-weight: 600;
}

.sensor-card .sensor-value {
    font-size: 20px;
    font-weight: 700;
    font-family: var(--mono);
    color: var(--text-bright);
}

.sensor-card .sensor-unit {
    font-size: 12px;
    color: var(--text-dim);
    margin-inline-start: 2px;
}

.sensor-card .sensor-status {
    font-size: 10px;
    margin-top: 4px;
}

.sensor-card .sensor-status.normal { color: var(--success); }
.sensor-card .sensor-status.anomaly { color: var(--danger); }
.sensor-card .sensor-status.missing { color: var(--warning); }

#sensor-panel-footer {
    padding: 12px 18px;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 8px;
}

/* ── Buttons ────────────────────────────────────────────── */

.btn-primary {
    flex: 1;
    padding: 8px 14px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--accent);
    background: rgba(74, 222, 128, 0.15);
    color: var(--accent);
    font-family: var(--font);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    -webkit-tap-highlight-color: transparent;
}

.btn-primary:hover {
    background: rgba(74, 222, 128, 0.25);
    box-shadow: 0 0 20px var(--accent-glow);
}

.btn-secondary {
    flex: 1;
    padding: 8px 14px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.05);
    color: var(--text);
    font-family: var(--font);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    -webkit-tap-highlight-color: transparent;
}

.btn-secondary:hover {
    background: rgba(56, 189, 248, 0.15);
    border-color: var(--accent-2);
    color: var(--accent-2);
}

/* ── Prediction Panel ───────────────────────────────────── */

#prediction-body {
    padding: 18px;
}

.prediction-result {
    text-align: center;
    padding: 20px 0;
}

.prediction-value {
    font-size: 48px;
    font-weight: 800;
    font-family: var(--mono);
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.prediction-label {
    font-size: 12px;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 1.5px;
    margin-top: 4px;
}

.prediction-recommendation {
    margin-top: 16px;
    padding: 12px 16px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    line-height: 1.5;
}

.prediction-confidence {
    margin-top: 8px;
    font-size: 11px;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 1px;
}

/* ── Dashboard Panel ────────────────────────────────────── */

#dashboard-body { padding: 14px 18px; }

.dash-zone-tabs {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
    margin-bottom: 14px;
}

.dash-tab {
    padding: 6px 8px;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-dim);
    font-family: var(--font);
    font-size: 11px;
    font-weight: 600;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    -webkit-tap-highlight-color: transparent;
}

.dash-tab:hover, .dash-tab.active {
    background: rgba(74, 222, 128, 0.15);
    border-color: var(--accent);
    color: var(--accent);
}

.dash-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.dash-card {
    padding: 12px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: var(--radius-sm);
}

.dash-card .dash-label {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-dim);
    font-weight: 600;
    margin-bottom: 6px;
}

.dash-card .dash-value {
    font-size: 22px;
    font-weight: 700;
    font-family: var(--mono);
    color: var(--text-bright);
}

.dash-card .dash-bar {
    margin-top: 8px;
    height: 4px;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.08);
    overflow: hidden;
}

.dash-card .dash-bar-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.6s ease;
}

/* ── Help Panel ─────────────────────────────────────────── */

.help-body { padding: 14px 18px; }

.help-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 0;
    font-size: 13px;
    color: var(--text-dim);
    border-bottom: 1px solid rgba(255,255,255,0.04);
}

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

kbd {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 26px;
    height: 24px;
    padding: 0 6px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 5px;
    font-family: var(--mono);
    font-size: 11px;
    color: var(--text);
    font-weight: 500;
}

/* ── Bottom HUD ─────────────────────────────────────────── */

#hud-bottom {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 12px 20px;
    padding-bottom: calc(12px + var(--safe-bottom));
    background: linear-gradient(0deg, rgba(10, 14, 23, 0.9) 0%, transparent 100%);
    pointer-events: none;
}

#hud-bottom > * { pointer-events: auto; }

.time-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 12px;
    background: var(--bg-glass);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border);
    border-radius: 20px;
}

.time-btn {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    border: none;
    background: transparent;
    font-size: 14px;
    cursor: pointer;
    transition: background 0.2s;
    -webkit-tap-highlight-color: transparent;
}

.time-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

#time-speed-label {
    font-size: 12px;
    font-weight: 600;
    font-family: var(--mono);
    color: var(--accent);
    min-width: 28px;
    text-align: center;
}

.zone-quick-nav {
    display: flex;
    gap: 4px;
}

.zone-btn {
    padding: 6px 12px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--bg-glass);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    color: var(--text);
    font-family: var(--font);
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    -webkit-tap-highlight-color: transparent;
}

.zone-btn:hover {
    border-color: var(--accent);
    background: rgba(74, 222, 128, 0.12);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(74, 222, 128, 0.15);
}

.zone-btn.active {
    border-color: var(--accent);
    background: rgba(74, 222, 128, 0.2);
    box-shadow: 0 0 12px var(--accent-glow);
}

/* ── Notifications — RTL: right side ───────────────────── */

#notifications {
    position: fixed;
    bottom: 80px;
    right: 16px;
    left: auto;
    z-index: 300;
    display: flex;
    flex-direction: column-reverse;
    gap: 8px;
    direction: rtl;
}

.notification {
    padding: 10px 16px;
    background: var(--bg-card);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 500;
    max-width: 320px;
    animation: notifIn 0.35s cubic-bezier(0.16, 1, 0.3, 1);
    box-shadow: var(--shadow);
}

/* RTL: border on right side for notifications */
.notification.success { border-inline-start: 3px solid var(--success); }
.notification.warning { border-inline-start: 3px solid var(--warning); }
.notification.error { border-inline-start: 3px solid var(--danger); }
.notification.info { border-inline-start: 3px solid var(--accent-2); }

.notification.fade-out {
    animation: notifOut 0.3s ease forwards;
}

@keyframes notifIn {
    from { opacity: 0; transform: translateX(30px); }
    to { opacity: 1; transform: translateX(0); }
}

@keyframes notifOut {
    from { opacity: 1; transform: translateX(0); }
    to { opacity: 0; transform: translateX(30px); }
}

/* ── Scrollbar ──────────────────────────────────────────── */

::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.25); }

/* ── Mobile Virtual Joystick ───────────────────────────── */

#mobile-joystick-zone {
    display: none;
    position: fixed;
    bottom: 80px;
    left: 16px;
    z-index: 150;
    width: 130px;
    height: 130px;
    border-radius: 50%;
    background: rgba(15, 23, 42, 0.4);
    border: 2px solid rgba(74, 222, 128, 0.15);
    -webkit-tap-highlight-color: transparent;
    touch-action: none;
}

#mobile-joystick-base {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

#mobile-joystick-thumb {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(74, 222, 128, 0.5) 0%, rgba(74, 222, 128, 0.2) 100%);
    border: 2px solid rgba(74, 222, 128, 0.4);
    box-shadow: 0 0 15px rgba(74, 222, 128, 0.2);
    transition: transform 0.05s linear;
}

/* Mobile action buttons (right side) */
#mobile-action-buttons {
    display: none;
    position: fixed;
    bottom: 90px;
    left: 16px;
    z-index: 150;
    flex-direction: column;
    gap: 8px;
}

.mobile-action-btn {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--bg-glass);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    color: var(--text);
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    transition: all 0.2s;
}

.mobile-action-btn:active {
    background: rgba(74, 222, 128, 0.25);
    border-color: var(--accent);
    transform: scale(0.92);
}

/* ── Mobile Controls (legacy d-pad) ───────────────────────── */

#mobile-controls {
    display: none;
    position: fixed;
    bottom: 70px;
    left: 16px;
    z-index: 150;
    gap: 6px;
    flex-direction: column;
    align-items: center;
}

.mobile-btn {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--bg-glass);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    color: var(--text);
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.mobile-btn:active {
    background: rgba(74, 222, 128, 0.25);
    border-color: var(--accent);
    transform: scale(0.92);
}

.mobile-dpad {
    display: grid;
    grid-template-columns: 48px 48px 48px;
    grid-template-rows: 48px 48px 48px;
    gap: 3px;
}

.mobile-dpad .mobile-btn:nth-child(1) { grid-column: 2; grid-row: 1; }
.mobile-dpad .mobile-btn:nth-child(2) { grid-column: 1; grid-row: 2; }
.mobile-dpad .mobile-btn:nth-child(3) { grid-column: 3; grid-row: 2; }
.mobile-dpad .mobile-btn:nth-child(4) { grid-column: 2; grid-row: 3; }

/* ═══════════════════════════════════════════════════════════
   RESPONSIVE BREAKPOINTS
   ═══════════════════════════════════════════════════════════ */

/* ── Large Tablets / Small Laptops ──────────────────────── */
@media (max-width: 1200px) {
    .hud-center { gap: 4px; }
    .hud-badge { padding: 5px 10px; font-size: 12px; }
    .hud-btn-label { padding: 0 10px; font-size: 11px; }
    .zone-btn { padding: 5px 8px; font-size: 10px; }
    #minimap { width: 200px; height: 200px; }
}

/* ── Tablets & Small Screens ───────────────────────────── */
@media (max-width: 1024px) {
    .hud-center { gap: 4px; }
    .hud-badge { padding: 5px 10px; font-size: 12px; }
    .hud-btn-label { padding: 0 10px; font-size: 11px; }
    .zone-btn { padding: 5px 8px; font-size: 10px; }
    #minimap { width: 180px; height: 180px; }

    .panel-large {
        width: 440px;
    }
}

/* ── Mobile / Landscape Phones ─────────────────────────── */
@media (max-width: 768px) {
    #hud-top {
        padding: 8px 12px;
        padding-top: calc(8px + var(--safe-top));
    }

    /* Show hamburger, hide desktop buttons */
    .hud-right .hud-btn-label { display: none; }
    #mobile-menu-toggle { display: flex; }

    .hud-logo { font-size: 16px; }
    .hud-center { gap: 4px; }
    .hud-badge { padding: 4px 8px; font-size: 10px; border-radius: 14px; }

    /* Hide zone bar on small screens (keep bottom bar) */
    #zone-bar { font-size: 10px; padding: 4px 12px; top: 55px; }

    /* Zone quick nav hidden on mobile */
    .zone-quick-nav { display: none; }

    /* Panels take full width */
    .panel, .panel-large {
        width: calc(100% - 24px);
        right: 12px !important;
        left: 12px !important;
        margin: 0 auto;
        max-height: 65vh;
    }

    #sensor-panel, #prediction-panel { top: auto; bottom: 70px; }
    #help-panel { top: auto; bottom: 70px; }
    .panel-large { top: 70px; }

    /* Minimap smaller and repositioned */
    #minimap {
        width: 130px;
        height: 130px;
        bottom: 70px;
        left: 12px;
        border-radius: 12px;
    }

    #hud-bottom {
        padding: 8px 12px;
        padding-bottom: calc(8px + var(--safe-bottom));
        gap: 8px;
    }

    .time-controls { padding: 3px 8px; }

    /* Touch-friendly close buttons */
    .panel-close { width: 36px; height: 36px; font-size: 16px; }

    /* Show mobile joystick */
    #mobile-joystick-zone { display: block; }
    #mobile-action-buttons { display: flex; }

    /* Hide crosshair on mobile */
    #crosshair { display: none; }
}

/* ── Small Phones ──────────────────────────────────────── */
@media (max-width: 480px) {
    #hud-top {
        padding: 6px 8px;
        padding-top: calc(6px + var(--safe-top));
    }

    .hud-logo { font-size: 14px; }
    .hud-center { gap: 2px; }
    .hud-badge { padding: 3px 6px; font-size: 9px; gap: 3px; }
    
    #zone-bar { font-size: 9px; padding: 3px 10px; }

    #minimap { width: 110px; height: 110px; bottom: 65px; }

    .panel, .panel-large {
        width: calc(100% - 16px);
        right: 8px !important;
        left: 8px !important;
        max-height: 55vh;
    }

    .sensor-grid { grid-template-columns: 1fr; }
    .dash-grid { grid-template-columns: 1fr; }

    .sensor-card .sensor-value { font-size: 16px; }
    .dash-card .dash-value { font-size: 18px; }

    .prediction-value { font-size: 36px; }

    #mobile-joystick-zone {
        width: 110px;
        height: 110px;
        bottom: 70px;
    }

    #mobile-joystick-thumb {
        width: 40px;
        height: 40px;
    }

    .mobile-action-btn {
        width: 42px;
        height: 42px;
        font-size: 16px;
    }
}

/* ── Very Small Phones ─────────────────────────────────── */
@media (max-width: 360px) {
    .hud-badge { display: none; }
    .hud-badge:first-child { display: flex; } /* Only show weather */
    
    #minimap { width: 90px; height: 90px; }
    
    .panel, .panel-large {
        max-height: 50vh;
    }
}

/* ── Landscape Mobile ──────────────────────────────────── */
@media (max-height: 500px) and (orientation: landscape) {
    #hud-top { padding: 4px 12px; }
    .hud-badge { padding: 3px 8px; font-size: 10px; }
    
    #zone-bar { display: none; }
    
    .panel, .panel-large {
        max-height: 80vh;
        width: 320px;
    }

    #minimap { width: 120px; height: 120px; bottom: 60px; }

    #hud-bottom { padding: 4px 12px; gap: 8px; }

    #mobile-joystick-zone {
        width: 100px;
        height: 100px;
        bottom: 52px;
    }
}

/* ── High DPI / Retina adjustments ─────────────────────── */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .loader-bar { height: 3px; }
    .dash-card .dash-bar { height: 3px; }
}
