/* ========================================
   Base Styles - Reset & Foundation
   ======================================== */

/* Reset */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* Base HTML */
html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
    background: var(--color-bg-primary);
}

body {
    font-family: var(--font-family);
    font-size: var(--font-size-base);
    font-variant-numeric: tabular-nums;
    line-height: 1.5;
    color: var(--color-text-primary);
    background: transparent;
    min-height: 100vh;
    min-height: 100dvh;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Typography refinements */
h1, h2, h3, .header-title, .welcome-title, .ai-wizard-question,
.block-complete-title, .workout-complete-title, .rest-day-title,
.card-title, .modal-title, .empty-state-title, .auth-title,
.today-workout-name, .workout-day-name, .calendar-month-title,
.stat-value, .done-stat-value, .overview-stat-value,
.settings-section-title, .nav-label {
    font-family: var(--font-family-display);
    line-height: 1.2;
    letter-spacing: -0.01em;
}

.font-size-xs, .stat-label, .stat-trend, .setting-desc, .form-hint,
.badge, .badge-expert, .badge-custom, .exercise-type-badge,
.sub-current-label, .status-text {
    letter-spacing: 0.02em;
}

body::before {
    display: none;
}

.bg-image {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    object-fit: cover;
    object-position: center center;
    z-index: -1;
    pointer-events: none;
}

[data-theme="light"] .bg-image {
    filter: invert(1);
}


body::after {
    display: none;
}

/* Light theme bg swap handled in app.js applyTheme() */

/* App Container */
#app {
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    position: relative;
}

/* Grid wrapper — vignette mask: 100% at edges, 20% at center */
.grid-wrapper {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    z-index: 0;
    pointer-events: none;
    -webkit-mask-image: radial-gradient(ellipse at center, rgba(0,0,0,0.2) 0%, rgba(0,0,0,0.2) 20%, rgba(0,0,0,1) 70%);
    mask-image: radial-gradient(ellipse at center, rgba(0,0,0,0.2) 0%, rgba(0,0,0,0.2) 20%, rgba(0,0,0,1) 70%);
}

/* Grid overlay — thin lines + intersection nodes between bg and content */
.grid-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    z-index: 0;
    pointer-events: none;
    background-image:
        radial-gradient(circle, rgba(255, 255, 255, 0.08) 3px, transparent 3px),
        linear-gradient(rgba(255, 255, 255, 0.03) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, 0.03) 1px, transparent 1px);
    background-size: 60px 60px;
    background-position: -30px -30px, 0 0, 0 0;
}

[data-theme="light"] .grid-overlay {
    background-image:
        radial-gradient(circle, rgba(0, 0, 0, 0.08) 3px, transparent 3px),
        linear-gradient(rgba(0, 0, 0, 0.04) 1px, transparent 1px),
        linear-gradient(90deg, rgba(0, 0, 0, 0.04) 1px, transparent 1px);
}

/* Animated glow dots on grid */
.grid-glow-dot {
    position: absolute;
    width: 6px;
    height: 6px;
    margin-left: -3px;
    margin-top: -3px;
    border-radius: 50%;
    background: var(--color-primary);
    box-shadow: 0 0 8px 3px rgba(255, 107, 44, 0.4), 0 0 20px 6px rgba(255, 107, 44, 0.15);
    z-index: 0;
    pointer-events: none;
    opacity: 0;
    animation: gridGlow 8s ease-in-out infinite;
}

@keyframes gridGlow {
    0%, 100% { opacity: 0; }
    50% { opacity: 1; }
}

/* Positions set by JS — dots relocate after each fade cycle */

[data-theme="light"] .grid-glow-dot {
    background: var(--color-primary-dark);
    box-shadow: 0 0 8px 3px rgba(229, 90, 27, 0.3), 0 0 20px 6px rgba(229, 90, 27, 0.1);
}

/* Header */
.header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-height);
    background: var(--glass-bg-heavy);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    will-change: transform;
    border-bottom: 1px solid var(--glass-border-light);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 var(--space-md);
    z-index: var(--z-header);
}

.header-btn {
    width: 40px;
    height: 40px;
    background: transparent;
    border: none;
    color: var(--color-primary);
    border-radius: var(--radius-md);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--font-size-2xl);
    font-weight: var(--font-weight-bold);
    transition: background var(--transition-fast);
}

.header-btn:hover {
    background: var(--color-bg-tertiary);
}

.header-btn:empty {
    visibility: hidden;
}

.user-avatar {
    width: 32px;
    height: 32px;
    background: linear-gradient(135deg, rgba(255, 107, 44, 0.12) 0%, rgba(255, 107, 44, 0.03) 50%, rgba(255, 107, 44, 0.10) 100%);
    border: 1.5px solid rgba(255, 107, 44, 0.15);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-bold);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    box-shadow: 0 0 12px rgba(255, 107, 44, 0.05), inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.header-center {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.header-logo {
    width: 40px;
    height: auto;
    color: var(--color-text-primary);
}

.header-title {
    font-size: var(--font-size-lg);
    font-weight: var(--font-weight-semibold);
    color: var(--color-text-primary);
}

/* Main Content */
.main-content {
    flex: 1;
    margin-top: var(--header-height);
    margin-bottom: var(--nav-height);
    padding: var(--space-md);
    max-width: var(--max-width);
    width: 100%;
    margin-left: auto;
    margin-right: auto;
    overflow-y: auto;
    /* Page transitions */
    transition: opacity 0.25s ease-out, transform 0.25s ease-out;
}

.main-content.fade-out {
    opacity: 0;
    transform: translateY(-10px);
}

.main-content.fade-in {
    animation: fadeInPage 0.35s ease-out;
}

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

/* Glass card entrance — hides blur pop-in */
@keyframes cardReveal {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Staggered card entrance */
.dashboard > *,
.progress-page > *,
.settings-page > *,
.splits-page .program-card-list > * {
    animation: cardReveal 0.25s ease-out both;
}

.dashboard > :nth-child(1), .progress-page > :nth-child(1), .settings-page > :nth-child(1), .splits-page .program-card-list > :nth-child(1) { animation-delay: 0.03s; }
.dashboard > :nth-child(2), .progress-page > :nth-child(2), .settings-page > :nth-child(2), .splits-page .program-card-list > :nth-child(2) { animation-delay: 0.06s; }
.dashboard > :nth-child(3), .progress-page > :nth-child(3), .settings-page > :nth-child(3), .splits-page .program-card-list > :nth-child(3) { animation-delay: 0.09s; }
.dashboard > :nth-child(4), .progress-page > :nth-child(4), .settings-page > :nth-child(4), .splits-page .program-card-list > :nth-child(4) { animation-delay: 0.12s; }
.dashboard > :nth-child(5), .settings-page > :nth-child(5), .splits-page .program-card-list > :nth-child(5) { animation-delay: 0.15s; }
.dashboard > :nth-child(6), .settings-page > :nth-child(6), .splits-page .program-card-list > :nth-child(6) { animation-delay: 0.18s; }
.dashboard > :nth-child(7), .splits-page .program-card-list > :nth-child(7) { animation-delay: 0.21s; }
.dashboard > :nth-child(8), .splits-page .program-card-list > :nth-child(8) { animation-delay: 0.24s; }
.dashboard > :nth-child(9), .splits-page .program-card-list > :nth-child(9) { animation-delay: 0.27s; }
.dashboard > :nth-child(10), .splits-page .program-card-list > :nth-child(10) { animation-delay: 0.30s; }

/* Bottom Navigation */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--nav-height);
    background: var(--glass-bg-heavy);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    will-change: transform;
    border-top: 1px solid var(--glass-border-light);
    display: flex;
    justify-content: space-around;
    align-items: center;
    padding: var(--space-sm) 0;
    padding-bottom: max(var(--space-sm), env(safe-area-inset-bottom));
    z-index: var(--z-nav);
}

.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-xs);
    padding: var(--space-xs) var(--space-sm);
    background: none;
    border: none;
    color: var(--color-text-secondary);
    cursor: pointer;
    transition: color var(--transition-fast);
    min-width: 60px;
}

.nav-item:hover,
.nav-item.active {
    color: rgba(255, 107, 44, 0.45);
}

.nav-icon {
    width: 24px;
    height: 24px;
}

.nav-label {
    font-size: 0.625rem;
    font-weight: var(--font-weight-medium);
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--color-border);
    border-radius: var(--radius-full);
}

::-webkit-scrollbar-thumb:hover {
    background: var(--color-border-light);
}

/* Focus States */
:focus {
    outline: none;
}

:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}

/* Selection */
::selection {
    background: var(--color-primary);
    color: white;
}

/* Links */
a {
    color: var(--color-primary);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

/* Images */
img {
    max-width: 100%;
    height: auto;
}

/* ========================================
   Page-Specific Colors
   ======================================== */

/* Dashboard */
body[data-page="dashboard"] .header {
    border-bottom-color: rgba(255, 107, 44, 0.25);
}
body[data-page="dashboard"] .header-btn {
    color: var(--color-page-dashboard-accent);
}
body[data-page="dashboard"] .nav-item.active {
    color: var(--color-page-dashboard-accent);
}

/* Workout */
body[data-page="workout"] .header {
    border-bottom-color: rgba(255, 107, 44, 0.25);
}
body[data-page="workout"] .header-btn {
    color: var(--color-page-workout-accent);
}
body[data-page="workout"] .nav-item.active {
    color: var(--color-page-workout-accent);
}

/* Library */
body[data-page="library"] .header {
    border-bottom-color: rgba(255, 107, 44, 0.25);
}
body[data-page="library"] .header-btn {
    color: var(--color-page-library-accent);
}
body[data-page="library"] .nav-item.active {
    color: var(--color-page-library-accent);
}

/* Progress */
body[data-page="progress"] .header {
    border-bottom-color: rgba(255, 107, 44, 0.25);
}
body[data-page="progress"] .header-btn {
    color: var(--color-page-progress-accent);
}
body[data-page="progress"] .nav-item.active {
    color: var(--color-page-progress-accent);
}

/* Settings */
body[data-page="settings"] .header {
    border-bottom-color: rgba(142, 142, 154, 0.2);
}
body[data-page="settings"] .header-btn {
    color: var(--color-page-settings-accent);
}
body[data-page="settings"] .nav-item.active {
    color: var(--color-page-settings-accent);
}

/* Programs/Splits */
body[data-page="splits"] .header {
    border-bottom-color: rgba(255, 107, 44, 0.25);
}
body[data-page="splits"] .header-btn {
    color: var(--color-page-splits-accent);
}
body[data-page="splits"] .nav-item.active {
    color: var(--color-page-splits-accent);
}

/* Editor */
body[data-page="editor"] .header {
    border-bottom-color: rgba(255, 107, 44, 0.25);
}
body[data-page="editor"] .header-btn {
    color: var(--color-page-editor-accent);
}
body[data-page="editor"] .nav-item.active {
    color: var(--color-page-editor-accent);
}

/* Blob icons — inline icon images */
.blob-icon {
    display: inline-block;
    width: 1.8em;
    height: 1.8em;
    vertical-align: -0.3em;
    object-fit: contain;
    filter:
        drop-shadow(1px 0 0 rgba(232, 135, 46, 0.5))
        drop-shadow(-1px 0 0 rgba(232, 135, 46, 0.5))
        drop-shadow(0 1px 0 rgba(232, 135, 46, 0.5))
        drop-shadow(0 -1px 0 rgba(232, 135, 46, 0.5));
}

/* Hero-sized blob icons — welcome logos, auth logos, empty states, rest day, block complete */
.welcome-logo .blob-icon,
.auth-logo .blob-icon,
.empty-state-icon .blob-icon,
.rest-day-icon .blob-icon,
.block-complete-icon .blob-icon,
.workout-summary-icon .blob-icon {
    width: 7.5rem;
    height: 7.5rem;
    vertical-align: middle;
}

[data-theme="light"] .blob-icon {
    filter: invert(1)
        drop-shadow(1px 0 0 rgba(232, 135, 46, 0.5))
        drop-shadow(-1px 0 0 rgba(232, 135, 46, 0.5))
        drop-shadow(0 1px 0 rgba(232, 135, 46, 0.5))
        drop-shadow(0 -1px 0 rgba(232, 135, 46, 0.5));
}

/* Hidden utility */
.hidden {
    display: none !important;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}
