:root {
    /* Color Palette - AMOLED Optimized */
    --bg-color: #000000;
    --surface-color: #121212;
    --surface-color-light: #1E1E1E;
    --surface-color-lighter: #2C2C2E;
    --accent-color: #32D74B; 
    --accent-glow: rgba(50, 215, 75, 0.25);
    --text-primary: #FFFFFF;
    --text-secondary: #8E8E93;
    --text-tertiary: #636366;
    --danger-color: #FF453A;
    --warning-color: #FF9F0A;
    --info-color: #0A84FF;
    
    /* Glassmorphism */
    --glass-bg: rgba(18, 18, 18, 0.85);
    --glass-border: rgba(255, 255, 255, 0.08);
    --glass-blur: 24px;

    /* Mobile-first Spacing Scale */
    --spacing-xs: 4px;
    --spacing-sm: 8px;
    --spacing-md: 16px;
    --spacing-lg: 24px;
    --spacing-xl: 32px;
    --spacing-2xl: 48px;

    /* Radii */
    --border-radius-sm: 8px;
    --border-radius-md: 16px;
    --border-radius-lg: 24px;
    --border-radius-pill: 9999px;

    /* Typography */
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    
    /* Layout */
    --bottom-nav-height: 80px;
    --header-height: 60px;
    --max-content-width: 500px;
}

/* Base Reset */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent; /* Rely on custom ripples */
}

html, body {
    width: 100%;
    height: 100%;
    background-color: var(--bg-color);
    color: var(--text-primary);
    font-family: var(--font-family);
    overflow: hidden; 
    overscroll-behavior-y: none;
}

/* Typography */
h1 { font-size: 32px; font-weight: 800; letter-spacing: -0.8px; line-height: 1.2; }
h2 { font-size: 24px; font-weight: 700; letter-spacing: -0.5px; line-height: 1.3; }
h3 { font-size: 18px; font-weight: 600; line-height: 1.4; }
h4 { font-size: 14px; font-weight: 600; letter-spacing: 0.5px; text-transform: uppercase; color: var(--text-secondary); margin-bottom: 4px; }
p { font-size: 16px; line-height: 1.5; color: var(--text-secondary); }
.text-primary { color: var(--text-primary); }
.text-secondary { color: var(--text-secondary); }
.text-accent { color: var(--accent-color); }

/* Layout Structure */
#app {
    display: flex;
    flex-direction: column;
    height: 100%;
    width: 100%;
    max-width: var(--max-content-width);
    margin: 0 auto;
    position: relative;
    background-color: var(--bg-color);
    overflow: hidden; /* For page transitions */
}

/* Header */
.app-header {
    height: calc(var(--header-height) + env(safe-area-inset-top, 0px));
    padding-top: env(safe-area-inset-top, 0px);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-inline: var(--spacing-md);
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
    transition: transform 0.3s ease;
}

/* Main Content Area */
#app-content {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding-top: calc(var(--header-height) + env(safe-area-inset-top, 0px) + var(--spacing-md));
    padding-bottom: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom, 16px) + var(--spacing-2xl));
    padding-inline: var(--spacing-md);
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch; 
}
#app-content::-webkit-scrollbar { display: none; }
#app-content { -ms-overflow-style: none; scrollbar-width: none; }

/* Bottom Navigation */
.bottom-nav {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px);
    display: flex;
    justify-content: space-around;
    align-items: center;
    z-index: 100;
    border-top: 1px solid var(--glass-border);
    transition: transform 0.3s ease;
}

.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    color: var(--text-secondary);
    width: 64px;
    height: 64px;
    gap: 4px;
    transition: color 0.2s ease;
}
.nav-item span { font-size: 11px; font-weight: 500; }
.nav-item svg { transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275); }
.nav-item.active { color: var(--accent-color); }
.nav-item.active svg { transform: scale(1.15) translateY(-2px); }

/* Focus Mode (Hides Header & Nav) */
body.focus-mode .app-header {
    transform: translateY(-100%);
}
body.focus-mode .bottom-nav {
    transform: translateY(100%);
}
body.focus-mode #app-content {
    padding-top: 0;
    padding-bottom: 0;
    padding-inline: 0;
    display: flex;
    flex-direction: column;
}

/* Glassmorphism */
.glass {
    background: var(--glass-bg);
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));
}

.card {
    background-color: var(--surface-color);
    border-radius: var(--border-radius-lg);
    padding: var(--spacing-md);
    margin-bottom: var(--spacing-md);
    border: 1px solid var(--glass-border);
}

/* Buttons & Ripples */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 24px;
    min-height: 52px;
    border-radius: var(--border-radius-pill);
    font-size: 16px;
    font-weight: 700;
    border: none;
    cursor: pointer;
    text-decoration: none;
    width: 100%;
    gap: 8px;
    position: relative;
    overflow: hidden; /* For ripples */
}

.btn-primary {
    background-color: var(--accent-color);
    color: #000000;
}
.btn-secondary {
    background-color: var(--surface-color-light);
    color: var(--text-primary);
    border: 1px solid var(--glass-border);
}

.icon-btn {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--surface-color-light);
    border: 1px solid var(--glass-border);
    color: var(--text-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    position: relative;
    overflow: hidden;
}

/* Ripple Animation */
.ripple {
    position: absolute;
    border-radius: 50%;
    transform: scale(0);
    animation: ripple-anim 0.6s linear;
    background-color: rgba(255, 255, 255, 0.3);
    pointer-events: none;
}
.btn-primary .ripple { background-color: rgba(0, 0, 0, 0.2); }

@keyframes ripple-anim {
    to { transform: scale(4); opacity: 0; }
}

/* UI Components & Utilities */
.hidden { display: none !important; }
.badge {
    display: inline-flex; align-items: center; justify-content: center;
    padding: 6px 10px; border-radius: var(--border-radius-pill);
    font-size: 12px; font-weight: 600; letter-spacing: 0.3px;
}
.badge-primary { background-color: rgba(50, 215, 75, 0.15); color: var(--accent-color); }
.badge-secondary { background-color: var(--surface-color-light); color: var(--text-secondary); border: 1px solid var(--glass-border); }

.glass-input {
    background: var(--surface-color-light);
    border: 1px solid var(--glass-border);
    border-radius: var(--border-radius-md);
    color: var(--text-primary);
    padding: 0 16px;
    min-height: 48px;
    font-size: 18px; /* Larger for easy typing */
    font-weight: 700;
    width: 100%;
    text-align: center;
    transition: border-color 0.2s, background 0.2s;
}
.glass-input:focus { outline: none; border-color: var(--accent-color); background: var(--surface-color-lighter); }
input[type=number]::-webkit-inner-spin-button, input[type=number]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }

/* Range Slider */
.range-slider {
    -webkit-appearance: none; width: 100%; height: 6px;
    background: var(--surface-color-light); border-radius: 3px; outline: none; margin: 20px 0;
}
.range-slider::-webkit-slider-thumb {
    -webkit-appearance: none; appearance: none;
    width: 28px; height: 28px; border-radius: 50%;
    background: var(--accent-color); cursor: pointer; box-shadow: 0 0 12px var(--accent-glow);
}

/* Animations */
.slide-in-right { animation: slideInRight 0.3s cubic-bezier(0.2, 0.8, 0.2, 1) forwards; }
.slide-out-left { animation: slideOutLeft 0.3s cubic-bezier(0.2, 0.8, 0.2, 1) forwards; }
.fade-in { animation: fadeIn 0.3s cubic-bezier(0.2, 0.8, 0.2, 1) forwards; }

@keyframes slideInRight { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes slideOutLeft { from { transform: translateX(0); opacity: 1; } to { transform: translateX(-100%); opacity: 0; } }
@keyframes fadeIn { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }

/* Utils */
.flex-row { display: flex; align-items: center; }
.flex-col { display: flex; flex-direction: column; }
.justify-between { justify-content: space-between; }
.justify-center { justify-content: center; }
.gap-sm { gap: var(--spacing-sm); }
.gap-md { gap: var(--spacing-md); }
.mt-sm { margin-top: var(--spacing-sm); }
.mt-md { margin-top: var(--spacing-md); }
.mt-lg { margin-top: var(--spacing-lg); }
.mb-sm { margin-bottom: var(--spacing-sm); }
.mb-md { margin-bottom: var(--spacing-md); }
.mb-lg { margin-bottom: var(--spacing-lg); }
.pb-lg { padding-bottom: var(--spacing-lg); }
.mr-xs { margin-right: 4px; }
.px-sm { padding-left: var(--spacing-sm); padding-right: var(--spacing-sm); }
.text-center { text-align: center; }
.font-bold { font-weight: 700; }
.block { display: block; }
.w-full { width: 100%; }

/* --- FOCUS MODE STYLES (Single Exercise) --- */

.focus-container {
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.focus-media {
    position: sticky;
    top: 0;
    height: 42vh;
    background: #000;
    z-index: 10;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
}

.media-element {
    width: 100%;
    height: 100%;
    object-fit: contain; /* Prevents 9:16 videos from being heavily cropped */
}

.switch-angle-btn {
    position: absolute;
    bottom: 16px;
    right: 16px;
    background: rgba(0, 0, 0, 0.6);
    border: 1px solid var(--glass-border);
    color: var(--text-primary);
    padding: 8px 14px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: bold;
    z-index: 20;
    backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s ease;
}

.switch-angle-btn:active {
    transform: scale(0.95);
    background: rgba(255, 255, 255, 0.1);
}

/* Overlay gradient for text on top of media if needed, or just clean top nav */
.focus-top-nav {
    position: absolute;
    top: env(safe-area-inset-top, 16px);
    left: var(--spacing-md);
    right: var(--spacing-md);
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 20;
}
.focus-top-nav .icon-btn {
    background: rgba(0,0,0,0.5);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: none;
}

.focus-progress-bar {
    position: absolute;
    top: 0;
    left: 0;
    height: 4px;
    background: var(--accent-color);
    z-index: 30;
    transition: width 0.3s ease;
}

.focus-scrollable {
    flex: 1;
    overflow-y: auto;
    padding: var(--spacing-lg) var(--spacing-md) 120px var(--spacing-md);
    -webkit-overflow-scrolling: touch;
}
.focus-scrollable::-webkit-scrollbar { display: none; }

/* Sets */
.set-row {
    margin-bottom: var(--spacing-md); /* more breathing room */
    background: var(--surface-color-light);
    border-radius: var(--border-radius-md);
    padding: 16px;
    border: 2px solid transparent;
    transition: border-color 0.2s, background-color 0.2s;
}
.set-row.completed {
    background: rgba(50, 215, 75, 0.05);
    border-color: var(--accent-color);
}
.set-number {
    width: 24px; font-weight: 700; color: var(--text-secondary); font-size: 16px;
}
.set-row.completed .set-number { color: var(--accent-color); }
.set-inputs { flex: 1; margin: 0 var(--spacing-md); }

/* Big Checkbox */
.check-btn {
    width: 56px; /* Huge touch target */
    height: 56px;
    border-radius: 16px;
    background: var(--surface-color);
    border: 2px solid var(--glass-border);
    color: var(--text-tertiary);
    transition: all 0.2s;
}
.set-row.completed .check-btn {
    background: var(--accent-color); border-color: var(--accent-color); color: #000;
    transform: scale(1.05);
}

/* Floating Action Area in Focus Mode */
.focus-bottom-action {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    padding: var(--spacing-md);
    padding-bottom: calc(var(--spacing-md) + env(safe-area-inset-bottom, 0px));
    background: linear-gradient(to top, var(--bg-color) 80%, transparent);
    z-index: 600;
}

/* Modal Overlay & Rest Timer */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    z-index: 999;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.modal-overlay.active {
    opacity: 1;
    pointer-events: all;
}

.modal-content {
    background: var(--surface-color);
    padding: var(--spacing-xl);
    border-radius: var(--border-radius-lg);
    border: 1px solid var(--glass-border);
    width: 90%;
    max-width: 400px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.5);
    transform: translateY(20px);
    transition: transform 0.3s ease;
}

.modal-overlay.active .modal-content {
    transform: translateY(0);
}

/* Ring Timer */
.ring-container { position: relative; }
.ring-svg { transform: rotate(-90deg); width: 100%; height: 100%; }
.ring-bg { fill: none; stroke: var(--surface-color-light); stroke-width: 6; }
.ring-progress { 
    fill: none; 
    stroke: var(--accent-color); 
    stroke-width: 6; 
    stroke-linecap: round; 
    transition: stroke-dashoffset 1s linear; 
}
.ring-text { 
    position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); 
    font-size: 28px; font-weight: 800; color: var(--text-primary); 
}

/* Statistics Dashboard Components */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--spacing-md);
    margin-bottom: var(--spacing-lg);
}

.kpi-card {
    background: var(--surface-color);
    border: 1px solid var(--glass-border);
    border-radius: var(--border-radius-lg);
    padding: 16px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.muscle-split-item {
    margin-bottom: var(--spacing-sm);
}

.muscle-bar-track {
    width: 100%;
    height: 8px;
    background: var(--surface-color-light);
    border-radius: 4px;
    overflow: hidden;
    margin-top: 6px;
}

.muscle-bar-fill {
    height: 100%;
    background: var(--accent-color);
    border-radius: 4px;
    transition: width 0.6s ease;
}

.pr-card {
    background: var(--surface-color-light);
    border: 1px solid var(--glass-border);
    border-radius: var(--border-radius-md);
    padding: 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--spacing-sm);
}

/* Desktop Scaling */
@media (min-width: 501px) {
    body { display: flex; align-items: center; justify-content: center; }
    #app { height: 90vh; border-radius: var(--border-radius-lg); border: 1px solid var(--glass-border); }
    .focus-media { border-top-left-radius: var(--border-radius-lg); border-top-right-radius: var(--border-radius-lg); }
}
