/* ============================================
   Home Fitness - App-like RTL Mobile UI
   ============================================ */

/* Vazirmatn (Google Fonts) - hosted locally as a variable font.
   Source: https://github.com/rastikerdar/vazirmatn (SIL OFL 1.1) */
@font-face {
    font-family: 'Vazirmatn';
    src: url('../assets/fonts/Vazirmatn-Variable.woff2') format('woff2-variations'),
         url('../assets/fonts/Vazirmatn-Variable.woff2') format('woff2');
    font-weight: 100 900;
    font-style: normal;
    font-display: swap;
}

:root {
    --bg-0: #0b1020;
    --bg-1: #121935;
    --bg-2: #1a2348;
    --surface: #1e2a55;
    --surface-2: #283466;
    --border: #2c3a72;

    --text: #f1f4ff;
    --text-2: #b8c0e0;
    --text-3: #6f7aa8;

    --accent: #5b8cff;
    --accent-2: #8b6cff;
    --accent-grad: linear-gradient(135deg, #5b8cff 0%, #8b6cff 100%);
    --success: #2ddc8a;
    --warn: #ffb547;
    --danger: #ff5e7e;

    --shadow-md: 0 6px 24px rgba(0, 0, 0, 0.35);
    --shadow-lg: 0 14px 48px rgba(0, 0, 0, 0.5);
    --radius-sm: 12px;
    --radius-md: 18px;
    --radius-lg: 28px;

    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: 'Vazirmatn', 'Segoe UI', 'Tahoma', sans-serif;
    background: var(--bg-0);
    color: var(--text);
    direction: rtl;
    -webkit-font-smoothing: antialiased;
    overscroll-behavior: none;
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
}

/* Background gradient */
body::before {
    content: '';
    position: fixed;
    inset: 0;
    background:
        radial-gradient(80% 50% at 80% 0%, rgba(91, 140, 255, 0.18), transparent 60%),
        radial-gradient(60% 40% at 0% 100%, rgba(139, 108, 255, 0.16), transparent 60%),
        var(--bg-0);
    z-index: -1;
}

/* ============================================ Screens ============================================ */
.screen {
    position: fixed;
    inset: 0;
    display: none;
    flex-direction: column;
    overflow: hidden;
}

.screen.active {
    display: flex;
    animation: fadeIn 0.25s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ============================================ Header ============================================ */
.app-header {
    padding: calc(var(--safe-top) + 16px) 18px 14px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.header-content {
    flex: 1;
}

.header-title {
    flex: 1;
    text-align: center;
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--text);
}

.header-spacer {
    width: 42px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand-logo {
    width: 46px;
    height: 46px;
    border-radius: 14px;
    background: var(--accent-grad);
    display: grid;
    place-items: center;
    color: white;
    box-shadow: var(--shadow-md);
}

.brand-logo svg {
    width: 26px;
    height: 26px;
}

.brand h1 {
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: -0.01em;
}

.subtitle {
    font-size: 0.78rem;
    color: var(--text-3);
    margin-top: 2px;
}

/* ============================================ Buttons ============================================ */
.icon-btn {
    width: 42px;
    height: 42px;
    border-radius: 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    display: grid;
    place-items: center;
    cursor: pointer;
    transition: transform 0.12s, background 0.18s;
}

.icon-btn:active {
    transform: scale(0.94);
    background: var(--surface-2);
}

.icon-btn svg {
    width: 22px;
    height: 22px;
}

.icon-btn.glass {
    background: rgba(15, 22, 50, 0.55);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-color: rgba(255, 255, 255, 0.08);
}

.primary-btn,
.secondary-btn {
    border: none;
    border-radius: 16px;
    padding: 14px 22px;
    font-family: inherit;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    transition: transform 0.12s, opacity 0.18s;
    color: var(--text);
}

.primary-btn {
    background: var(--accent-grad);
    box-shadow: 0 8px 24px rgba(91, 140, 255, 0.35);
}

.primary-btn.large {
    padding: 18px 28px;
    font-size: 1.05rem;
    border-radius: 20px;
}

.secondary-btn {
    background: var(--surface);
    border: 1px solid var(--border);
}

.primary-btn:active,
.secondary-btn:active {
    transform: scale(0.97);
    opacity: 0.92;
}

.primary-btn svg,
.secondary-btn svg {
    width: 20px;
    height: 20px;
}

/* ============================================ Home Screen ============================================ */
.home-main {
    flex: 1;
    overflow-y: auto;
    padding: 6px 18px calc(var(--safe-bottom) + 30px);
    -webkit-overflow-scrolling: touch;
}

.section-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: 18px 4px 14px;
}

.section-title h2 {
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--text);
}

.badge {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text-2);
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 600;
}

.exercise-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    margin-bottom: 18px;
}

.exercise-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 16px 14px;
    text-align: right;
    cursor: pointer;
    transition: transform 0.15s, background 0.2s, border-color 0.2s;
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-height: 158px;
    color: var(--text);
    font-family: inherit;
}

.exercise-card:active {
    transform: scale(0.97);
    background: var(--surface-2);
}

.exercise-card .card-icon {
    width: 46px;
    height: 46px;
    border-radius: 14px;
    background: rgba(91, 140, 255, 0.16);
    color: var(--accent);
    display: grid;
    place-items: center;
}

.exercise-card .card-icon svg {
    width: 26px;
    height: 26px;
}

.exercise-card[data-color="purple"] .card-icon { background: rgba(139, 108, 255, 0.18); color: var(--accent-2); }
.exercise-card[data-color="green"]  .card-icon { background: rgba(45, 220, 138, 0.16); color: var(--success); }
.exercise-card[data-color="orange"] .card-icon { background: rgba(255, 181, 71, 0.18); color: var(--warn); }
.exercise-card[data-color="pink"]   .card-icon { background: rgba(255, 94, 126, 0.16); color: var(--danger); }
.exercise-card[data-color="cyan"]   .card-icon { background: rgba(80, 200, 220, 0.16); color: #50c8dc; }

.exercise-card .card-title {
    font-size: 1.02rem;
    font-weight: 700;
    color: #ffffff;
}

.exercise-card .card-desc {
    font-size: 0.78rem;
    color: var(--text-3);
    line-height: 1.5;
    flex: 1;
}

.exercise-card .card-cta {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--accent);
    font-size: 0.85rem;
    font-weight: 600;
    margin-top: 4px;
}

.exercise-card .card-cta svg {
    width: 14px;
    height: 14px;
}

.info-card {
    display: flex;
    gap: 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 14px;
    align-items: flex-start;
}

.info-icon {
    width: 36px;
    height: 36px;
    border-radius: 12px;
    background: rgba(91, 140, 255, 0.16);
    color: var(--accent);
    display: grid;
    place-items: center;
    flex-shrink: 0;
}

.info-icon svg { width: 20px; height: 20px; }

.info-card strong {
    display: block;
    font-size: 0.92rem;
    margin-bottom: 4px;
}

.info-card p {
    font-size: 0.82rem;
    color: var(--text-2);
    line-height: 1.6;
}

/* ============================================ Permission Screen ============================================ */
.permission-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 24px 26px calc(var(--safe-bottom) + 30px);
    gap: 22px;
}

.permission-illustration {
    width: 160px;
    height: 160px;
    color: var(--accent);
    margin-bottom: 8px;
}

.permission-illustration svg {
    width: 100%;
    height: 100%;
}

.permission-title {
    font-size: 1.45rem;
    font-weight: 700;
    line-height: 1.4;
}

.permission-text {
    font-size: 0.95rem;
    color: var(--text-2);
    line-height: 1.85;
    max-width: 380px;
}

.permission-text strong {
    color: var(--success);
}

.permission-error {
    color: var(--danger);
    font-size: 0.88rem;
    line-height: 1.6;
    background: rgba(255, 94, 126, 0.12);
    border: 1px solid rgba(255, 94, 126, 0.3);
    padding: 12px 16px;
    border-radius: 12px;
    max-width: 380px;
}

/* ============================================ Workout Screen ============================================ */
.workout-screen {
    background: #000;
}

.camera-stage {
    position: relative;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: #000;
}

#videoEl {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transform: scaleX(-1);
    background: #000;
}

#overlayEl {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

/* Loading */
.loading-overlay {
    position: absolute;
    inset: 0;
    background: rgba(11, 16, 32, 0.92);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 18px;
    z-index: 20;
}

.loading-overlay[hidden] { display: none; }

.spinner {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    border: 3px solid rgba(255, 255, 255, 0.1);
    border-top-color: var(--accent);
    animation: spin 0.9s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-overlay p {
    font-size: 0.95rem;
    color: var(--text-2);
}

/* HUD top */
.hud-top {
    position: absolute;
    top: calc(var(--safe-top) + 14px);
    left: 14px;
    right: 14px;
    display: flex;
    align-items: center;
    gap: 10px;
    z-index: 10;
}

.hud-title {
    flex: 1;
    text-align: center;
    padding: 10px 16px;
    border-radius: 14px;
    font-weight: 700;
    font-size: 0.95rem;
}

.glass {
    background: rgba(15, 22, 50, 0.55);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border: 1px solid rgba(255, 255, 255, 0.08);
    color: var(--text);
}

/* Center counter */
.hud-counter {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 138px;
    height: 138px;
    border-radius: 50%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 5;
    transition: transform 0.18s, box-shadow 0.18s;
}

.hud-counter.pulse {
    transform: translate(-50%, -50%) scale(1.12);
    box-shadow: 0 0 0 8px rgba(91, 140, 255, 0.25), 0 0 40px rgba(91, 140, 255, 0.4);
}

.counter-value {
    font-size: 3.4rem;
    font-weight: 800;
    line-height: 1;
    color: var(--text);
    font-variant-numeric: tabular-nums;
}

.counter-label {
    margin-top: 6px;
    font-size: 0.85rem;
    color: var(--text-2);
}

/* HUD bottom */
.hud-bottom {
    position: absolute;
    left: 14px;
    right: 14px;
    bottom: calc(var(--safe-bottom) + 16px);
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 10;
}

.hint {
    padding: 12px 16px;
    border-radius: 14px;
    text-align: center;
    font-size: 0.92rem;
    color: var(--text);
    line-height: 1.5;
}

.workout-stats {
    display: flex;
    align-items: center;
    padding: 12px 18px;
    border-radius: 16px;
    gap: 12px;
}

.stat {
    flex: 1;
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.stat-label {
    font-size: 0.75rem;
    color: var(--text-3);
}

.stat-value {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--text);
    font-variant-numeric: tabular-nums;
}

.stat-divider {
    width: 1px;
    height: 28px;
    background: rgba(255, 255, 255, 0.12);
}

/* ============================================ Summary Screen ============================================ */
.summary-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 18px 26px calc(var(--safe-bottom) + 30px);
    gap: 18px;
    overflow-y: auto;
}

.trophy {
    width: 112px;
    height: 112px;
    border-radius: 50%;
    background: var(--accent-grad);
    display: grid;
    place-items: center;
    color: white;
    box-shadow: 0 14px 36px rgba(91, 140, 255, 0.45);
    margin-bottom: 6px;
}

.trophy svg { width: 60px; height: 60px; }

.summary-title {
    font-size: 1.4rem;
    font-weight: 700;
}

.summary-subtitle {
    color: var(--text-2);
    font-size: 0.95rem;
}

.summary-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    width: 100%;
    max-width: 420px;
    margin: 16px 0;
}

.summary-stat {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 18px 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

.summary-stat-value {
    font-size: 1.6rem;
    font-weight: 800;
    color: var(--accent);
    font-variant-numeric: tabular-nums;
}

.summary-stat-label {
    font-size: 0.78rem;
    color: var(--text-2);
}

.summary-actions {
    display: flex;
    gap: 10px;
    width: 100%;
    max-width: 420px;
}

.summary-actions button {
    flex: 1;
    padding: 14px 18px;
    font-size: 0.95rem;
}

/* ============================================ Responsive ============================================ */
@media (min-width: 600px) {
    .exercise-grid {
        grid-template-columns: repeat(3, 1fr);
    }
    .home-main { padding: 6px 28px calc(var(--safe-bottom) + 30px); }
}

@media (min-width: 900px) {
    .exercise-card {
        min-height: 180px;
    }
    .home-main { max-width: 920px; margin: 0 auto; width: 100%; }
}

/* Prevent text selection on UI but allow on inputs */
button, .exercise-card { user-select: none; }
