/* ==========================================================================
   ۱. پیکربندی پایه‌ای، متغیرهای سیستم و بومی‌سازی (Variables & Base)
   ========================================================================== */
:root {
    --bg-main: #04060d;
    --bg-card: rgba(10, 14, 26, 0.75);
    --bg-inner: #111728;
    --border-color: rgba(255, 255, 255, 0.06);
    
    /* پالت رنگی سایبرپانک سیستم فیکس */
    --primary: #3b82f6;
    --primary-glow: rgba(59, 130, 246, 0.35);
    --success: #10b981;
    --success-glow: rgba(16, 185, 129, 0.35);
    --warning: #f59e0b;
    --warning-glow: rgba(245, 158, 11, 0.35);
    --danger: #ef4444;
    --danger-glow: rgba(239, 68, 68, 0.35);
    
    /* پالت متون */
    --text-white: #f8fafc;
    --text-dim: #94a3b8;
    --text-muted: #475569;
    
    --font-main: 'Vazirmatn', sans-serif;
    --transition-smooth: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: var(--font-main);
    user-select: none;
}

body {
    background-color: var(--bg-main);
    color: var(--text-white);
    min-height: 100vh;
    padding: 20px;
    overflow-x: hidden;
    background-image: 
        radial-gradient(at 0% 0%, rgba(59, 130, 246, 0.05) 0px, transparent 50%),
        radial-gradient(at 100% 100%, rgba(16, 185, 129, 0.03) 0px, transparent 50%);
}

/* ==========================================================================
   ۲. ساختار کلی چیدمان و هدر (Layout & Header)
   ========================================================================== */
.main-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 25px;
    background: var(--bg-card);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    margin-bottom: 20px;
    box-shadow: 0 4px 30px rgba(0, 0, 0, 0.4);
}

.header-title h1 {
    font-size: 1.3rem;
    font-weight: 900;
    background: linear-gradient(90deg, #fff, var(--text-dim));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.header-brand a {
    color: var(--primary);
    text-decoration: none;
    font-weight: 700;
    letter-spacing: 0.5px;
    transition: var(--transition-smooth);
    font-size: 1.1rem;
}

.header-brand a:hover {
    text-shadow: 0 0 10px var(--primary-glow);
    color: #60a5fa;
}

/* سیستم گرید ۲ ستونه منعطف */
.app-layout {
    display: grid;
    grid-template-columns: 390px 1fr;
    gap: 20px;
    max-width: 1600px;
    margin: 0 auto;
}

@media (max-width: 1100px) {
    .app-layout {
        grid-template-columns: 1fr;
    }
}

/* ==========================================================================
   ۳. کامپوننت کارت‌ها و ابزار مانیتورینگ (Cards & Side Panels)
   ========================================================================== */
.card {
    background: var(--bg-card);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    transition: var(--transition-smooth);
}

.card-title {
    font-size: 1rem;
    font-weight: 700;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 12px;
    margin-bottom: 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.accent-primary { color: var(--primary); }
.accent-success { color: var(--success); }
.accent-warning { color: var(--warning); }

/* وضعیت‌های اتصال بدنه هوشمند */
body.disconnected .device-dependent {
    opacity: 0.35;
    pointer-events: none;
    filter: blur(0.5px);
}

/* نشانگرها و دکمه‌های سوئیچ API */
.status-badge {
    font-size: 0.75rem;
    padding: 4px 10px;
    border-radius: 20px;
    background: rgba(239, 68, 68, 0.15);
    color: var(--danger);
    border: 1px solid rgba(239, 68, 68, 0.3);
}

body.connected .status-badge {
    background: rgba(16, 185, 129, 0.15);
    color: var(--success);
    border: 1px solid rgba(16, 185, 129, 0.3);
}

.api-toggle-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    background: var(--bg-inner);
    padding: 4px;
    border-radius: 10px;
    margin-bottom: 15px;
}

.api-btn {
    background: transparent;
    border: none;
    color: var(--text-dim);
    padding: 8px;
    font-size: 0.85rem;
    font-weight: 700;
    cursor: pointer;
    border-radius: 8px;
    transition: var(--transition-smooth);
}

.api-btn.active {
    background: var(--primary);
    color: var(--text-white);
    box-shadow: 0 0 12px var(--primary-glow);
}

/* پنل خلاصه وضعیت */
.connection-brief-panel {
    background: var(--bg-inner);
    border-radius: 12px;
    padding: 12px 15px;
    margin-bottom: 15px;
}

.brief-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    font-size: 0.9rem;
    color: var(--text-dim);
}

.brief-row:last-child { margin-bottom: 0; }

.status-text.disconnected { color: var(--danger); font-weight: 700; }
.status-text.connected { color: var(--success); font-weight: 700; }

.metric-font {
    font-family: monospace;
    font-weight: 700;
    font-size: 1rem;
}

.api-prompt-box {
    background: rgba(245, 158, 11, 0.08);
    border: 1px dashed rgba(245, 158, 11, 0.3);
    color: #fcd34d;
    padding: 12px;
    border-radius: 10px;
    font-size: 0.8rem;
    line-height: 1.6;
    margin-bottom: 15px;
}

/* ترمینال وقایع سیستم */
.terminal-box {
    background: #020408;
    border: 1px solid rgba(255, 255, 255, 0.03);
    font-family: monospace;
    font-size: 0.78rem;
    color: #34d399;
    padding: 12px;
    border-radius: 10px;
    height: 90px;
    overflow-y: auto;
    white-space: pre-wrap;
    line-height: 1.5;
    text-align: left;
    direction: ltr;
}

/* گرید نمایش اطلاعات پیشرفته فریمور درخواستی */
.info-section-title {
    font-size: 0.85rem;
    font-weight: 700;
    margin: 15px 0 8px 0;
    padding-bottom: 4px;
    border-bottom: 1px dashed rgba(255, 255, 255, 0.05);
}

.info-grid {
    display: flex;
    flex-direction: column;
    gap: 6px;
    background: var(--bg-inner);
    padding: 10px;
    border-radius: 10px;
    max-height: 240px;
    overflow-y: auto;
}

.info-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.8rem;
    padding: 4px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.02);
}

.info-row span:first-child {
    color: var(--text-dim);
    font-family: monospace;
}

.info-row span:last-child {
    color: var(--text-white);
    font-weight: 700;
    font-family: monospace;
}

/* ==========================================================================
   ۴. نقشه فیزیکی زنده کنترلر (Gamepad Visualizer & Mapping)
   ========================================================================== */
.gamepad-illustration-card {
    background: var(--bg-inner);
    border-radius: 14px;
    padding: 30px;
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 20px;
    border: 1px solid rgba(255, 255, 255, 0.02);
}

.gamepad-container {
    position: relative;
    width: 460px;
    height: 260px;
}

/* استایل عمومی کلیدهای شبیه‌ساز فیزیکی */
.g-btn, .shoulder-btn, .g-stick {
    position: absolute;
    background: #1e293b;
    border: 2px solid #475569;
    color: var(--text-dim);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 0.7rem;
    font-weight: 900;
    transition: background 0.1s, transform 0.1s, border-color 0.1s;
}

/* امضای فشرده شدن کلید سخت‌افزاری */
.g-btn.pressed, .shoulder-btn.pressed {
    background: var(--primary) !important;
    border-color: #93c5fd !important;
    color: white !important;
    transform: scale(0.92);
    box-shadow: 0 0 15px var(--primary-glow);
}

/* کالیبره کردن فیزیکی موقعیت کلیدها روی بدنه */
.shoulder-btn { width: 75px; height: 22px; border-radius: 6px; top: 0; }
.s-l1 { left: 40px; border-radius: 12px 6px 4px 4px; }
.s-r1 { right: 40px; border-radius: 6px 12px 4px 4px; }

/* مجموعه جهت‌های D-Pad */
.cluster-left { position: absolute; left: 35px; top: 75px; width: 90px; height: 90px; }
.cluster-left .g-btn { width: 28px; height: 28px; border-radius: 6px; }
.d-up { top: 0; left: 31px; }
.d-down { bottom: 0; left: 31px; }
.d-left { top: 31px; left: 0; }
.d-right { top: 31px; right: 0; }

/* کلیدهای اکشن سمت راست */
.cluster-right { position: absolute; right: 35px; top: 75px; width: 90px; height: 90px; }
.cluster-right .g-btn { width: 28px; height: 28px; border-radius: 50%; }
.b-triangle { top: 0; left: 31px; background: rgba(16, 185, 129, 0.1); border-color: rgba(16, 185, 129, 0.4); color: var(--success); }
.b-cross { bottom: 0; left: 31px; background: rgba(59, 130, 246, 0.1); border-color: rgba(59, 130, 246, 0.4); color: var(--primary); }
.b-square { top: 31px; left: 0; background: rgba(245, 158, 11, 0.1); border-color: rgba(245, 158, 11, 0.4); color: var(--warning); }
.b-circle { top: 31px; right: 0; background: rgba(239, 68, 68, 0.1); border-color: rgba(239, 68, 68, 0.4); color: var(--danger); }

/* کلیدهای مرکزی */
.b-share { left: 155px; top: 40px; width: 40px; height: 16px; border-radius: 20px; font-size: 0.5rem; }
.b-options { right: 155px; top: 40px; width: 40px; height: 16px; border-radius: 20px; font-size: 0.5rem; }
.b-ps { left: 213px; top: 110px; width: 34px; height: 34px; border-radius: 50%; font-size: 0.6rem; background: #0f172a; }

/* استیک‌های آنالوگ */
.g-stick { width: 64px; height: 64px; border-radius: 50%; bottom: 40px; background: #0f172a; border: 2px dashed #334155; }
.g-stick.pressed { border-color: var(--primary); background: rgba(59, 130, 246, 0.1); }
.g-stick-left { left: 145px; }
.g-stick-right { right: 145px; }

.g-thumb {
    width: 36px;
    height: 36px;
    background: radial-gradient(circle, #475569 0%, #1e293b 100%);
    border: 2px solid #64748b;
    border-radius: 50%;
    position: absolute;
    box-shadow: 0 4px 10px rgba(0,0,0,0.5);
    transition: transform 0.05s linear;
}

/* ==========================================================================
   ۵. داشبورد وکتورها و کانواس استیک‌ها (Sticks Dashboard)
   ========================================================================== */
.sticks-dashboard {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

@media (max-width: 650px) {
    .sticks-dashboard { grid-template-columns: 1fr; }
}

.canvas-container {
    background: var(--bg-inner);
    border-radius: 12px;
    padding: 15px;
    border: 1px solid rgba(255, 255, 255, 0.02);
}

.canvas-label {
    font-size: 0.8rem;
    color: var(--text-dim);
    margin-bottom: 12px;
    text-align: center;
    font-weight: 700;
}

.canvas-frame {
    display: flex;
    justify-content: center;
    margin-bottom: 12px;
}

canvas {
    background: #070a13;
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    width: 170px;
    height: 170px;
}

.metric-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.metric-item {
    background: rgba(255, 255, 255, 0.02);
    padding: 8px;
    border-radius: 8px;
    font-size: 0.75rem;
    color: var(--text-dim);
    text-align: center;
}

.metric-num {
    font-family: monospace;
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--text-white);
    margin-top: 4px;
}

.error-green { color: var(--success); }
.error-warning { color: var(--warning); }
.error-danger { color: var(--danger); }

/* ==========================================================================
   ۶. جادوگر کالیبراسیون هوشمند ۴ مرحله‌ای (Wizard Engine UI)
   ========================================================================== */
.wizard-steps-header {
    display: flex;
    justify-content: space-between;
    position: relative;
    margin-bottom: 25px;
    padding: 0 10px;
}

/* خط اتصال فیزیکی گره‌ها */
.wizard-steps-header::before {
    content: '';
    position: absolute;
    top: 15px;
    left: 40px;
    right: 40px;
    height: 2px;
    background: var(--text-muted);
    z-index: 1;
}

.step-node {
    position: relative;
    z-index: 2;
    display: flex;
    flex-direction: column;
    align-items: center;
    font-size: 0.8rem;
    color: var(--text-dim);
    font-weight: 700;
    gap: 6px;
    transition: var(--transition-smooth);
}

.step-badge {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--bg-inner);
    border: 2px solid var(--text-muted);
    display: flex;
    justify-content: center;
    align-items: center;
    color: var(--text-dim);
    font-weight: 900;
    font-size: 0.85rem;
    transition: var(--transition-smooth);
}

/* وضعیت‌های پویای جادوگر در جاوااسکریپت */
.step-node.active { color: var(--warning); }
.step-node.active .step-badge {
    border-color: var(--warning);
    background: #251b05;
    color: var(--warning);
    box-shadow: 0 0 12px var(--warning-glow);
}

.step-node.completed { color: var(--success); }
.step-node.completed .step-badge {
    border-color: var(--success);
    background: #041a12;
    color: var(--success);
    box-shadow: 0 0 12px var(--success-glow);
}

/* پیکربندی بدنه جادوگر */
.wizard-body {
    background: var(--bg-inner);
    border-radius: 12px;
    padding: 20px;
    display: grid;
    grid-template-columns: 1fr 220px;
    gap: 20px;
    margin-bottom: 20px;
    border: 1px solid rgba(255, 255, 255, 0.02);
}

@media (max-width: 650px) {
    .wizard-body { grid-template-columns: 1fr; }
}

.wizard-text-content h3 {
    font-size: 1.05rem;
    font-weight: 700;
    margin-bottom: 10px;
}

.wizard-text-content p {
    font-size: 0.88rem;
    color: var(--text-dim);
    line-height: 1.7;
}

.wizard-status-panel {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 10px;
    padding: 15px;
    border: 1px dashed rgba(255, 255, 255, 0.04);
}

.wizard-graphic-feedback {
    font-size: 2.2rem;
    margin-bottom: 10px;
    height: 55px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.correctness-indicator.waiting { animation: pulse 1.5s infinite ease-in-out; }

.validation-status {
    font-size: 0.78rem;
    font-weight: 700;
    text-align: center;
}

.status-warning { color: var(--warning); }
.status-success { color: var(--success); }

/* ابزار پایش هوشمند زوایا و جهات ۳۶۰ درجه (فاز ۳ جادوگر) */
.angle-tracker-ui {
    display: none; /* پیش‌فرض مخفی، با JS در گام سوم فعال می‌شود */
    gap: 20px;
}

.tracker-stick-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

.tracker-stick-box span {
    font-size: 0.7rem;
    color: var(--text-dim);
}

.direction-indicators {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 5px;
}

.dir-dot {
    width: 20px;
    height: 20px;
    border-radius: 4px;
    background: #1e293b;
    border: 1px solid #475569;
    font-size: 0.65rem;
    font-weight: 700;
    display: flex;
    justify-content: center;
    align-items: center;
    color: var(--text-muted);
    transition: var(--transition-smooth);
}

/* زمان تکمیل ماتریس چرخش هر جهت جغرافیایی */
.dir-dot.done {
    background: rgba(16, 185, 129, 0.2);
    border-color: var(--success);
    color: var(--success);
    box-shadow: 0 0 8px var(--success-glow);
}

/* المان‌های تعاملی و دکمه‌های اکشن */
.wizard-actions {
    display: flex;
    justify-content: flex-end;
}

.btn-action {
    background: var(--primary);
    color: var(--text-white);
    border: none;
    padding: 12px 24px;
    border-radius: 10px;
    font-size: 0.9rem;
    font-weight: 700;
    cursor: pointer;
    transition: var(--transition-smooth);
    width: 100%;
}

.btn-action:hover:not(:disabled) {
    background: #2563eb;
    box-shadow: 0 0 15px var(--primary-glow);
}

.btn-action:disabled {
    background: var(--text-muted);
    color: var(--text-dim);
    cursor: not-allowed;
    opacity: 0.5;
}

/* انیمیشن تپش قلب برای المان‌های در حال انتظار */
@keyframes pulse {
    0% { transform: scale(1); opacity: 0.6; }
    50% { transform: scale(1.1); opacity: 1; }
    100% { transform: scale(1); opacity: 0.6; }
}
