/* ===== RESET & BASE ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

:root {
    --bg-primary: #0f0f23;
    --bg-secondary: #1a1a2e;
    --bg-card: #16213e;
    --accent: #e94560;
    --accent-light: #ff6b81;
    --text-primary: #ffffff;
    --text-secondary: #a0a0b8;
    --text-muted: #6c6c80;
    --success: #4ecdc4;
    --warning: #f9ca24;
    --border: #2a2a4a;
    --shadow: rgba(0, 0, 0, 0.3);
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
    user-select: none;
}

#app {
    height: 100%;
    position: relative;
    overflow: hidden;
}

/* ===== SCREENS ===== */
.screen {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: none;
    flex-direction: column;
    overflow: hidden;
    transform: translateX(100%);
    transition: transform 0.3s ease;
}

.screen.active {
    display: flex;
    transform: translateX(0);
}

/* ===== HEADERS ===== */
.main-header {
    text-align: center;
    padding: calc(var(--safe-top) + 20px) 20px 15px;
    background: linear-gradient(180deg, var(--bg-secondary) 0%, transparent 100%);
}

.main-header .logo {
    margin-bottom: 8px;
}

.main-header h1 {
    font-size: 28px;
    font-weight: 800;
    background: linear-gradient(135deg, var(--accent), var(--accent-light));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.main-header .subtitle {
    color: var(--text-secondary);
    font-size: 14px;
    margin-top: 4px;
}

.sub-header {
    display: flex;
    align-items: center;
    padding: calc(var(--safe-top) + 12px) 16px 12px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    gap: 12px;
    min-height: 60px;
    flex-shrink: 0;
}

.sub-header h2 {
    flex: 1;
    font-size: 18px;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.back-btn {
    background: none;
    border: none;
    color: var(--accent);
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.back-btn:active {
    background: rgba(233, 69, 96, 0.1);
}

.header-icon {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.step-counter {
    background: var(--accent);
    color: white;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 13px;
    font-weight: 600;
    flex-shrink: 0;
}

/* ===== CATEGORY GRID ===== */
.category-grid {
    flex: 1;
    overflow-y: auto;
    padding: 10px 16px;
    padding-bottom: calc(70px + var(--safe-bottom));
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    align-content: start;
    -webkit-overflow-scrolling: touch;
}

.category-card {
    background: var(--bg-card);
    border-radius: 16px;
    padding: 18px 14px;
    text-align: center;
    cursor: pointer;
    border: 1px solid var(--border);
    transition: transform 0.15s ease, box-shadow 0.15s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.category-card:active {
    transform: scale(0.96);
    box-shadow: 0 0 20px rgba(233, 69, 96, 0.15);
}

.category-card .card-icon {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
}

.category-card .card-title {
    font-size: 14px;
    font-weight: 600;
    line-height: 1.3;
}

.category-card .card-count {
    font-size: 11px;
    color: var(--text-muted);
}

/* ===== EXERCISE LIST ===== */
.exercise-list {
    flex: 1;
    overflow-y: auto;
    padding: 12px 16px;
    padding-bottom: calc(20px + var(--safe-bottom));
    -webkit-overflow-scrolling: touch;
}

.exercise-card {
    background: var(--bg-card);
    border-radius: 14px;
    padding: 16px;
    margin-bottom: 10px;
    cursor: pointer;
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 14px;
    transition: transform 0.15s ease;
}

.exercise-card:active {
    transform: scale(0.98);
}

.exercise-card .mini-figure {
    width: 52px;
    height: 52px;
    background: rgba(233, 69, 96, 0.1);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.exercise-card .exercise-info-brief {
    flex: 1;
    min-width: 0;
}

.exercise-card .exercise-name {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 4px;
}

.exercise-card .exercise-meta {
    font-size: 12px;
    color: var(--text-secondary);
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.exercise-card .exercise-meta span {
    display: flex;
    align-items: center;
    gap: 4px;
}

.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 8px;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
}

.badge-band {
    background: rgba(78, 205, 196, 0.15);
    color: var(--success);
}

.badge-body {
    background: rgba(233, 69, 96, 0.15);
    color: var(--accent-light);
}

.badge-yoga {
    background: rgba(249, 202, 36, 0.15);
    color: var(--warning);
}

.badge-easy {
    background: rgba(78, 205, 196, 0.15);
    color: #4ecdc4;
}

.badge-medium {
    background: rgba(249, 202, 36, 0.15);
    color: #f9ca24;
}

.badge-hard {
    background: rgba(233, 69, 96, 0.2);
    color: #ff6b81;
}

/* ===== EXERCISE DETAIL ===== */
.exercise-detail {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    padding-bottom: calc(20px + var(--safe-bottom));
    -webkit-overflow-scrolling: touch;
}

.figure-container {
    background: var(--bg-card);
    border-radius: 20px;
    padding: 20px;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 280px;
    border: 1px solid var(--border);
    position: relative;
    overflow: hidden;
}

.figure-container svg {
    max-width: 100%;
    max-height: 260px;
}

.step-description {
    background: var(--bg-card);
    border-radius: 14px;
    padding: 16px;
    margin-bottom: 16px;
    border-left: 3px solid var(--accent);
}

.step-description h3 {
    font-size: 16px;
    font-weight: 700;
    margin-bottom: 8px;
    color: var(--accent-light);
}

.step-description p {
    font-size: 14px;
    line-height: 1.6;
    color: var(--text-secondary);
}

.step-description .tip {
    margin-top: 10px;
    padding: 10px;
    background: rgba(249, 202, 36, 0.08);
    border-radius: 8px;
    font-size: 13px;
    color: var(--warning);
    display: flex;
    align-items: flex-start;
    gap: 8px;
}

.step-description .tip::before {
    content: "💡";
    flex-shrink: 0;
}

/* ===== STEP NAVIGATION ===== */
.step-navigation {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    gap: 10px;
}

.step-btn {
    background: var(--bg-card);
    color: var(--accent);
    border: 1px solid var(--border);
    padding: 10px 16px;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.15s ease;
    white-space: nowrap;
}

.step-btn:active {
    background: var(--accent);
    color: white;
}

.step-btn:disabled {
    opacity: 0.3;
    pointer-events: none;
}

.step-dots {
    display: flex;
    gap: 6px;
    justify-content: center;
    flex-wrap: wrap;
}

.step-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--border);
    transition: all 0.2s ease;
}

.step-dot.active {
    background: var(--accent);
    width: 20px;
    border-radius: 4px;
}

/* ===== EXERCISE INFO ===== */
.exercise-info {
    background: var(--bg-card);
    border-radius: 14px;
    padding: 16px;
    border: 1px solid var(--border);
}

.exercise-info .info-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
}

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

.exercise-info .info-label {
    font-size: 13px;
    color: var(--text-muted);
}

.exercise-info .info-value {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
}

.muscles-worked {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 10px;
}

.muscle-tag {
    background: rgba(233, 69, 96, 0.12);
    color: var(--accent-light);
    padding: 4px 10px;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 500;
}

/* ===== BOTTOM NAV ===== */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
    display: flex;
    padding: 6px 0 calc(6px + var(--safe-bottom));
    z-index: 100;
}

.nav-btn {
    flex: 1;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 8px;
    font-size: 11px;
    transition: color 0.2s ease;
}

.nav-btn.active {
    color: var(--accent);
}

/* ===== ROUTINES ===== */
.routine-list {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    padding-bottom: calc(20px + var(--safe-bottom));
    -webkit-overflow-scrolling: touch;
}

.routine-card {
    background: var(--bg-card);
    border-radius: 16px;
    padding: 20px;
    margin-bottom: 12px;
    cursor: pointer;
    border: 1px solid var(--border);
    transition: transform 0.15s ease;
}

.routine-card:active {
    transform: scale(0.98);
}

.routine-card .routine-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.routine-card .routine-name {
    font-size: 17px;
    font-weight: 700;
}

.routine-card .routine-duration {
    font-size: 13px;
    color: var(--accent);
    font-weight: 600;
}

.routine-card .routine-desc {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 12px;
    line-height: 1.4;
}

.routine-card .routine-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.routine-tag {
    background: rgba(233, 69, 96, 0.1);
    color: var(--accent-light);
    padding: 3px 10px;
    border-radius: 8px;
    font-size: 11px;
    font-weight: 500;
}

/* ===== ACTIVE ROUTINE ===== */
.active-routine-content {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    padding-bottom: calc(20px + var(--safe-bottom));
    -webkit-overflow-scrolling: touch;
}

.timer {
    font-size: 16px;
    font-weight: 700;
    color: var(--accent);
    font-variant-numeric: tabular-nums;
}

.active-exercise-item {
    background: var(--bg-card);
    border-radius: 14px;
    padding: 14px 16px;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 12px;
    border: 1px solid var(--border);
    transition: all 0.2s ease;
    cursor: pointer;
}

.active-exercise-item.current {
    border-color: var(--accent);
    background: rgba(233, 69, 96, 0.08);
}

.active-exercise-item.done {
    opacity: 0.5;
}

.active-exercise-item .exercise-number {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 700;
    flex-shrink: 0;
}

.active-exercise-item.current .exercise-number {
    background: var(--accent);
}

.active-exercise-item.done .exercise-number {
    background: var(--success);
}

.active-exercise-item .exercise-reps {
    font-size: 12px;
    color: var(--text-secondary);
}

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar {
    width: 3px;
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

/* ===== ANIMATIONS ===== */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.category-card, .exercise-card, .routine-card {
    animation: fadeInUp 0.3s ease both;
}

.category-card:nth-child(2) { animation-delay: 0.05s; }
.category-card:nth-child(3) { animation-delay: 0.1s; }
.category-card:nth-child(4) { animation-delay: 0.15s; }
.category-card:nth-child(5) { animation-delay: 0.2s; }
.category-card:nth-child(6) { animation-delay: 0.25s; }
.category-card:nth-child(7) { animation-delay: 0.3s; }
.category-card:nth-child(8) { animation-delay: 0.35s; }
.category-card:nth-child(9) { animation-delay: 0.4s; }
.category-card:nth-child(10) { animation-delay: 0.45s; }

/* ===== MULTI-FIGURE LAYOUT ===== */
.figure-multi {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
}

.figure-multi .figure-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 0;
}

.figure-multi .figure-panel svg {
    max-width: 100%;
    max-height: 220px;
}

.figure-multi .figure-panel.prev-step {
    opacity: 0.4;
    flex: 0.7;
}

.figure-multi .figure-panel.current-step {
    flex: 1;
}

.figure-multi .figure-arrow {
    color: var(--warning);
    font-size: 24px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
}

.figure-label {
    font-size: 10px;
    color: var(--text-muted);
    text-align: center;
    margin-top: 4px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* ===== RESPONSIVE ===== */
@media (min-width: 400px) {
    .figure-container {
        min-height: 320px;
    }
}

/* iPhone Pro Max / Large phones (414px-430px+) */
@media (min-width: 414px) {
    .main-header h1 {
        font-size: 32px;
    }

    .main-header .subtitle {
        font-size: 16px;
    }

    .category-card {
        padding: 22px 16px;
        border-radius: 18px;
        gap: 12px;
    }

    .category-card .card-icon {
        width: 64px;
        height: 64px;
        font-size: 32px;
    }

    .category-card .card-title {
        font-size: 16px;
    }

    .category-card .card-count {
        font-size: 12px;
    }

    .exercise-card {
        padding: 18px;
        gap: 16px;
    }

    .exercise-card .mini-figure {
        width: 60px;
        height: 60px;
    }

    .exercise-card .exercise-name {
        font-size: 17px;
    }

    .exercise-card .exercise-meta {
        font-size: 13px;
    }

    .figure-container {
        min-height: 360px;
        padding: 24px;
        border-radius: 24px;
    }

    .figure-container svg {
        max-height: 320px;
    }

    .figure-multi .figure-panel svg {
        max-height: 280px;
    }

    .step-description h3 {
        font-size: 18px;
    }

    .step-description p {
        font-size: 16px;
        line-height: 1.7;
    }

    .step-description .tip {
        font-size: 14px;
        padding: 12px;
    }

    .step-btn {
        padding: 12px 20px;
        font-size: 15px;
        border-radius: 14px;
        min-height: 48px;
    }

    .step-counter {
        font-size: 14px;
        padding: 5px 12px;
    }

    .sub-header {
        min-height: 64px;
        padding-left: 20px;
        padding-right: 20px;
    }

    .sub-header h2 {
        font-size: 20px;
    }

    .back-btn {
        padding: 10px;
    }

    .exercise-info .info-row {
        padding: 10px 0;
    }

    .exercise-info .info-label {
        font-size: 14px;
    }

    .exercise-info .info-value {
        font-size: 15px;
    }

    .muscle-tag {
        font-size: 13px;
        padding: 5px 12px;
    }

    .routine-card .routine-name {
        font-size: 19px;
    }

    .routine-card .routine-desc {
        font-size: 14px;
    }

    .nav-btn {
        font-size: 12px;
        padding: 10px;
    }

    .figure-label {
        font-size: 11px;
    }

    .figure-multi .figure-arrow {
        font-size: 28px;
    }
}

/* Extra tall phones (iPhone Pro Max height) */
@media (min-height: 800px) and (min-width: 400px) {
    .figure-container {
        min-height: 400px;
    }

    .figure-container svg {
        max-height: 360px;
    }

    .figure-multi .figure-panel svg {
        max-height: 300px;
    }

    .exercise-detail {
        padding: 20px;
    }

    .step-description {
        padding: 20px;
    }
}

@media (min-width: 600px) {
    .category-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}
