/* ========================================
   Intervaly — Mobile-First PWA Styles
   ======================================== */
:root {
    --bg-primary: #0f0f1a;
    --bg-secondary: #1a1a2e;
    --bg-card: #222240;
    --text-primary: #f0f0f5;
    --text-secondary: #8888aa;
    --accent-work: #00d4ff;
    --accent-rest: #ff6b35;
    --accent-reps: #a855f7;
    --accent-green: #22c55e;
    --ring-bg: #2a2a45;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; overflow: hidden; }
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, sans-serif;
    background: var(--bg-primary); color: var(--text-primary);
    -webkit-font-smoothing: antialiased; user-select: none;
}

/* ---- Screens ---- */
.screen {
    position: absolute; inset: 0; display: flex; flex-direction: column;
    opacity: 0; pointer-events: none;
    transition: opacity 0.3s ease, transform 0.3s ease;
    transform: translateY(10px);
    padding-top: var(--safe-top); padding-bottom: var(--safe-bottom);
}
.screen.active { opacity: 1; pointer-events: auto; transform: translateY(0); }

/* ======== WELCOME OVERLAY (unauthenticated) ======== */
.welcome-overlay {
    position: fixed; inset: 0; z-index: 500;
    background: var(--bg-primary);
    display: flex; align-items: center; justify-content: center;
    padding: 24px;
    animation: fadeIn 0.4s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.welcome-card {
    width: 100%; max-width: 400px; text-align: center;
    animation: fadeUp 0.6s ease;
}
@keyframes fadeUp {
    from { opacity: 0; transform: translateY(20px); }
    to   { opacity: 1; transform: translateY(0); }
}
.welcome-logo {
    height: 80px; width: auto; max-width: 300px; object-fit: contain;
    margin-bottom: 12px;
    filter: drop-shadow(0 0 24px rgba(0,212,255,0.35));
}
.welcome-tagline {
    font-size: 1rem; color: var(--text-secondary); font-weight: 500;
    margin-bottom: 48px;
}
.welcome-features {
    display: flex; flex-direction: column; gap: 12px;
    margin-bottom: 48px; text-align: left;
}
.welcome-feature {
    display: flex; align-items: center; gap: 14px;
    padding: 14px 16px;
    background: rgba(255,255,255,0.03);
    border: 1px solid rgba(255,255,255,0.05);
    border-radius: 14px;
}
.welcome-feature-icon { font-size: 1.5rem; flex-shrink: 0; }
.welcome-feature-text { font-size: 0.85rem; color: #aaa; line-height: 1.4; }
.welcome-feature-text strong { color: var(--text-primary); }
.welcome-signin-btn {
    display: flex; align-items: center; justify-content: center; gap: 10px;
    width: 100%; padding: 16px; border: none; border-radius: 14px;
    font-size: 1rem; font-weight: 700; color: #fff; cursor: pointer;
    background: linear-gradient(135deg, #00d4ff, #0090cc);
    box-shadow: 0 4px 24px rgba(0,212,255,0.25);
    transition: transform 0.15s, box-shadow 0.15s;
    text-decoration: none;
}
.welcome-signin-btn:active { transform: scale(0.97); }
.welcome-signin-btn:hover { box-shadow: 0 6px 32px rgba(0,212,255,0.35); }
.welcome-footer {
    margin-top: 28px; font-size: 0.72rem; color: #555; line-height: 1.5;
}

/* ======== HOME SCREEN ======== */
.app-topbar {
    display: flex; align-items: center; justify-content: space-between;
    padding: 16px 16px 0;
}
.home-logo {
    text-align: center; padding: 24px 20px 28px;
}
.logo-banner {
    height: 100px; width: auto; max-width: 80vw; object-fit: contain;
    filter: drop-shadow(0 0 28px rgba(0, 212, 255, 0.45));
}

/* ---- User Profile ---- */
.user-profile { position: relative; }
.user-chip {
    background: transparent; border: none;
    color: var(--text-primary); cursor: pointer;
    padding: 4px; border-radius: 28px;
    display: flex; align-items: center; gap: 10px;
    transition: opacity 0.2s;
}
.user-chip:hover { opacity: 0.85; }
.user-chip-name {
    font-size: 0.92rem; font-weight: 600; color: var(--text-secondary);
    max-width: 160px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.user-avatar { width: 36px; height: 36px; border-radius: 50%; object-fit: cover; flex-shrink: 0; }
.user-icon-fallback { width: 36px; height: 36px; flex-shrink: 0; color: var(--text-secondary); }

.profile-dropdown {
    display: none; position: absolute; top: 48px; right: 0; width: 260px;
    background: var(--bg-secondary); border: 1px solid rgba(255,255,255,0.08);
    border-radius: 16px; padding: 16px; z-index: 200;
    box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}
.profile-dropdown.open { display: block; animation: ddIn 0.2s ease; }
@keyframes ddIn { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: translateY(0); } }
.profile-info { display: flex; align-items: center; gap: 12px; }
.dropdown-avatar { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; background: var(--bg-card); }
.profile-details { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.profile-name { font-size: 0.9rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.profile-email { font-size: 0.75rem; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.profile-divider { border: none; border-top: 1px solid rgba(255,255,255,0.06); margin: 12px 0; }
.profile-action {
    display: flex; align-items: center; gap: 10px; padding: 10px 8px;
    border-radius: 10px; color: var(--text-secondary); text-decoration: none;
    font-size: 0.85rem; font-weight: 500; transition: background 0.2s, color 0.2s;
}
.profile-action:hover { background: var(--bg-card); color: #ef4444; }

/* ---- Home Content ---- */
.home-content { flex: 1; overflow-y: auto; padding: 8px 20px 20px; -webkit-overflow-scrolling: touch; }

/* ---- Action Cards ---- */
.action-cards { display: flex; flex-direction: column; gap: 12px; margin-bottom: 28px; }
.action-card {
    display: flex; align-items: center; gap: 14px;
    background: var(--bg-secondary); border: 1px solid rgba(255,255,255,0.04);
    border-radius: 16px; padding: 18px 16px; cursor: pointer;
    transition: transform 0.15s, background 0.15s;
    text-align: left; color: var(--text-primary); width: 100%;
}
.action-card:active { transform: scale(0.98); }
.action-card:hover { background: var(--bg-card); }
.action-icon { font-size: 2rem; flex-shrink: 0; }
.action-text { flex: 1; }
.action-text h2 { font-size: 1rem; font-weight: 700; margin-bottom: 2px; }
.action-text p { font-size: 0.78rem; color: var(--text-secondary); }
.action-arrow { color: var(--text-secondary); flex-shrink: 0; }
.running-card { border-left: 3px solid var(--accent-work); }
.hiit-card { border-left: 3px solid var(--accent-rest); }

/* ---- Saved Workouts ---- */
.section-title { font-size: 0.8rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-secondary); margin-bottom: 12px; }
.saved-list { display: flex; flex-direction: column; gap: 10px; }
.empty-state { text-align: center; padding: 32px 20px; color: var(--text-secondary); }
.empty-state p:first-child { font-size: 0.95rem; }
.empty-hint { font-size: 0.78rem; margin-top: 4px; opacity: 0.6; }

.saved-card {
    display: flex; align-items: center; gap: 12px;
    background: var(--bg-secondary); border-radius: 14px; padding: 14px 12px;
    border: 1px solid rgba(255,255,255,0.04);
}
.saved-card-icon { font-size: 1.4rem; flex-shrink: 0; }
.saved-card-body { flex: 1; min-width: 0; cursor: pointer; }
.saved-card-name { font-size: 0.92rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.saved-card-desc { font-size: 0.75rem; color: var(--text-secondary); margin-top: 2px; }
.saved-card-actions { display: flex; gap: 6px; flex-shrink: 0; }
.saved-action-btn {
    width: 36px; height: 36px; border-radius: 50%; border: none; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: transform 0.15s, background 0.15s;
}
.saved-action-btn:active { transform: scale(0.9); }
.saved-play-btn { background: rgba(0,212,255,0.15); color: var(--accent-work); }
.saved-del-btn { background: rgba(239,68,68,0.1); color: #ef4444; font-size: 1.1rem; }

/* ======== SETUP SCREENS (shared) ======== */
.setup-header {
    display: flex; align-items: center; gap: 12px;
    padding: 16px 20px 8px;
}
.setup-title { font-size: 1.05rem; font-weight: 700; }
.setup-content { flex: 1; overflow-y: auto; padding: 8px 20px 0; -webkit-overflow-scrolling: touch; }
.setup-footer { padding: 10px 20px 20px; display: flex; flex-direction: column; gap: 10px; }

.icon-btn {
    background: none; border: none; color: var(--text-secondary);
    cursor: pointer; padding: 8px; border-radius: 50%; transition: background 0.2s;
}
.icon-btn:hover { background: var(--bg-secondary); }

/* ---- Buttons ---- */
.primary-btn {
    width: 100%; padding: 15px; border: none; border-radius: 14px;
    font-size: 1rem; font-weight: 700; color: #fff; cursor: pointer;
    background: linear-gradient(135deg, var(--accent-work), #0090cc);
    box-shadow: 0 4px 20px rgba(0,212,255,0.2);
    transition: transform 0.15s;
}
.primary-btn:active { transform: scale(0.97); }
.secondary-btn {
    width: 100%; padding: 13px; border: 1px solid rgba(255,255,255,0.08);
    border-radius: 14px; font-size: 0.9rem; font-weight: 600;
    color: var(--text-secondary); background: transparent; cursor: pointer;
    transition: background 0.2s;
}
.secondary-btn:hover { background: var(--bg-secondary); }

/* ---- Field Groups ---- */
.field-group { margin-bottom: 20px; }
.field-label {
    display: flex; align-items: center; gap: 8px;
    font-size: 0.8rem; font-weight: 600; text-transform: uppercase;
    letter-spacing: 0.06em; color: var(--text-secondary); margin-bottom: 10px;
}
.dot { width: 8px; height: 8px; border-radius: 50%; }
.work-dot { background: var(--accent-work); }
.rest-dot { background: var(--accent-rest); }
.reps-dot { background: var(--accent-reps); }

/* ---- Time Stepper ---- */
.time-stepper {
    display: flex; align-items: center; justify-content: center; gap: 6px;
    background: var(--bg-secondary); border-radius: 14px; padding: 14px 12px;
}
.stepper-unit {
    display: flex; flex-direction: column; align-items: center; gap: 4px;
}
.stepper-sep {
    font-size: 1.6rem; font-weight: 700; color: var(--text-secondary);
    margin: 0 2px; align-self: flex-start; margin-top: 6px;
}
.stepper-btn {
    width: 40px; height: 40px; border-radius: 50%; border: none;
    background: var(--bg-card); color: var(--text-primary);
    font-size: 1.3rem; font-weight: 600; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: background 0.15s, transform 0.1s;
    touch-action: manipulation;
}
.stepper-btn:active { transform: scale(0.9); background: rgba(255,255,255,0.1); }
.stepper-val {
    font-size: 2rem; font-weight: 800; font-variant-numeric: tabular-nums;
    min-width: 52px; text-align: center; line-height: 1;
}
.stepper-lbl { font-size: 0.65rem; text-transform: uppercase; color: var(--text-secondary); letter-spacing: 0.08em; }

/* ---- Number Stepper ---- */
.num-stepper {
    display: flex; align-items: center; justify-content: center; gap: 20px;
    background: var(--bg-secondary); border-radius: 14px; padding: 16px;
}
.num-stepper .stepper-val { font-size: 2.4rem; min-width: 60px; }

/* ---- Workout Summary ---- */
.workout-summary {
    display: flex; align-items: center; justify-content: center;
    gap: 24px; padding: 16px 0 8px;
}
.summary-item { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.summary-label { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-secondary); }
.summary-value { font-size: 1.4rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.summary-divider { width: 1px; height: 36px; background: var(--bg-card); }

/* ======== HIIT EXERCISE LIST ======== */
.exercise-list { display: flex; flex-direction: column; gap: 12px; margin-bottom: 16px; }
.exercise-card {
    background: var(--bg-secondary); border-radius: 14px; padding: 14px;
    border: 1px solid rgba(255,255,255,0.04);
}
.exercise-header { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.exercise-num {
    width: 28px; height: 28px; border-radius: 50%; background: var(--accent-rest);
    color: #fff; font-size: 0.8rem; font-weight: 700;
    display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.exercise-name-input {
    flex: 1; background: var(--bg-card); border: 1px solid rgba(255,255,255,0.06);
    border-radius: 10px; padding: 10px 12px; color: var(--text-primary);
    font-size: 0.92rem; font-weight: 500; outline: none;
    transition: border-color 0.2s;
}
.exercise-name-input:focus { border-color: var(--accent-rest); }
.exercise-name-input::placeholder { color: var(--text-secondary); opacity: 0.6; }
.exercise-delete-btn {
    width: 32px; height: 32px; border-radius: 50%; border: none;
    background: rgba(239,68,68,0.1); color: #ef4444;
    font-size: 1.2rem; cursor: pointer; display: flex;
    align-items: center; justify-content: center; flex-shrink: 0;
    transition: background 0.15s;
}
.exercise-delete-btn:active { background: rgba(239,68,68,0.25); }
.exercise-timers { display: flex; gap: 10px; }
.exercise-timer-group { flex: 1; }
.exercise-timer-label {
    font-size: 0.7rem; text-transform: uppercase; color: var(--text-secondary);
    letter-spacing: 0.06em; margin-bottom: 6px; display: flex; align-items: center; gap: 5px;
}
.exercise-timer-label .dot { width: 6px; height: 6px; }

/* Compact stepper inside exercise cards */
.exercise-card .time-stepper { padding: 8px 6px; }
.exercise-card .stepper-btn { width: 32px; height: 32px; font-size: 1.1rem; }
.exercise-card .stepper-val { font-size: 1.3rem; min-width: 36px; }
.exercise-card .stepper-sep { font-size: 1.2rem; margin-top: 2px; }
.exercise-card .stepper-lbl { font-size: 0.58rem; }

.add-exercise-btn {
    width: 100%; padding: 14px; border: 2px dashed rgba(255,255,255,0.1);
    border-radius: 14px; background: transparent; color: var(--text-secondary);
    font-size: 0.9rem; font-weight: 600; cursor: pointer;
    transition: border-color 0.2s, color 0.2s;
}
.add-exercise-btn:hover { border-color: var(--accent-rest); color: var(--accent-rest); }

/* ======== TIMER SCREEN ======== */
.timer-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 16px 20px 0;
}
.timer-phase {
    font-size: 0.85rem; font-weight: 700; text-transform: uppercase;
    letter-spacing: 0.12em; transition: color 0.3s; text-align: center;
}
.timer-phase.work { color: var(--accent-work); }
.timer-phase.rest { color: var(--accent-rest); }
.timer-phase.ready { color: var(--accent-reps); }
.timer-exercise-name {
    font-size: 0.75rem; color: var(--text-secondary); text-align: center;
    margin-top: 2px; font-weight: 500;
}
.timer-interval-info { font-size: 0.82rem; color: var(--text-secondary); font-weight: 600; font-variant-numeric: tabular-nums; }

.timer-content {
    flex: 1; display: flex; flex-direction: column;
    align-items: center; justify-content: center; gap: 32px; padding: 0 20px;
}

/* ---- Progress Ring ---- */
.progress-ring-container { position: relative; width: 260px; height: 260px; }
.progress-ring { width: 100%; height: 100%; transform: rotate(-90deg); }
.progress-ring-bg { fill: none; stroke: var(--ring-bg); stroke-width: 8; }
.progress-ring-fill {
    fill: none; stroke: var(--accent-work); stroke-width: 8; stroke-linecap: round;
    stroke-dasharray: 753.98; stroke-dashoffset: 0;
    transition: stroke 0.4s ease, stroke-dashoffset 0.15s linear;
}
.progress-ring-fill.rest { stroke: var(--accent-rest); }
.progress-ring-fill.ready { stroke: var(--accent-reps); }
.progress-ring-fill.warning { animation: ringPulse 1s ease-in-out infinite; }
@keyframes ringPulse { 0%,100% { stroke-width: 8; opacity: 1; } 50% { stroke-width: 12; opacity: 0.8; } }

.timer-display { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.timer-time { font-size: 4rem; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1; transition: color 0.3s; }
.timer-time.warning { color: #fbbf24; animation: timePulse 1s ease-in-out infinite; }
@keyframes timePulse { 0%,100% { opacity: 1; } 50% { opacity: 0.6; } }
.timer-subtext { font-size: 0.75rem; color: var(--text-secondary); margin-top: 6px; text-transform: uppercase; letter-spacing: 0.06em; transition: color 0.3s; }
.timer-subtext.warning { color: #fbbf24; }

/* ---- Round Dots ---- */
.round-dots { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; max-width: 280px; }
.round-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--ring-bg); transition: background 0.3s, transform 0.3s; }
.round-dot.done { background: var(--accent-green); transform: scale(1.15); }
.round-dot.active { background: var(--accent-work); transform: scale(1.3); box-shadow: 0 0 8px rgba(0,212,255,0.5); }

/* ---- Timer Controls ---- */
.timer-footer { display: flex; align-items: center; justify-content: center; gap: 24px; padding: 16px 20px 28px; }
.control-btn {
    width: 64px; height: 64px; border-radius: 50%; border: none;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; transition: transform 0.15s;
}
.control-btn:active { transform: scale(0.92); }
.pause-btn { background: var(--bg-card); color: var(--text-primary); box-shadow: 0 2px 12px rgba(0,0,0,0.3); }
.stop-btn { background: rgba(239,68,68,0.15); color: #ef4444; }

/* ======== COMPLETE SCREEN ======== */
.complete-content {
    flex: 1; display: flex; flex-direction: column;
    align-items: center; justify-content: center; gap: 24px; padding: 20px;
}
.complete-icon { font-size: 4rem; animation: bounce 0.6s ease; }
@keyframes bounce { 0%,100% { transform: translateY(0); } 40% { transform: translateY(-20px); } 60% { transform: translateY(-8px); } }
.complete-content h2 { font-size: 1.6rem; font-weight: 800; }
.complete-stats { display: flex; gap: 40px; }
.stat { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.stat-value { font-size: 2rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.stat-label { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-secondary); }
#done-btn { margin-top: 16px; max-width: 280px; }

/* ======== SAVE MODAL ======== */
.modal-overlay {
    display: none; position: fixed; inset: 0; z-index: 300;
    background: rgba(0,0,0,0.6); backdrop-filter: blur(4px);
    align-items: center; justify-content: center; padding: 20px;
}
.modal-overlay.open { display: flex; }
.modal-card {
    background: var(--bg-secondary); border-radius: 20px; padding: 24px;
    width: 100%; max-width: 340px;
    animation: ddIn 0.2s ease;
}
.modal-card h3 { font-size: 1.1rem; font-weight: 700; margin-bottom: 16px; }
.modal-input {
    width: 100%; padding: 12px 14px; background: var(--bg-card);
    border: 1px solid rgba(255,255,255,0.08); border-radius: 12px;
    color: var(--text-primary); font-size: 0.95rem; outline: none;
    margin-bottom: 16px; transition: border-color 0.2s;
}
.modal-input:focus { border-color: var(--accent-work); }
.modal-input::placeholder { color: var(--text-secondary); opacity: 0.5; }
.modal-actions { display: flex; gap: 10px; }
.modal-actions .secondary-btn { flex: 1; }
.modal-actions .primary-btn { flex: 1; }

/* ======== RESPONSIVE ======== */
@media (min-width: 480px) {
    .home-content, .setup-content, .timer-content { max-width: 420px; margin: 0 auto; }
}
@supports (padding: max(0px)) {
    .app-header, .setup-header, .timer-header { padding-top: max(16px, var(--safe-top)); }
    .setup-footer, .timer-footer { padding-bottom: max(20px, calc(var(--safe-bottom) + 12px)); }
}

/* ======== LOADING OVERLAY ======== */
.loading-overlay {
    position: fixed; inset: 0; background: var(--bg-primary);
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    z-index: 1000; transition: opacity 0.4s ease;
}
.loading-overlay.hidden { opacity: 0; pointer-events: none; }
.spinner {
    width: 52px; height: 52px;
    border: 4px solid var(--ring-bg);
    border-top-color: var(--accent-work);
    border-right-color: var(--accent-reps);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text {
    margin-top: 20px; font-size: 0.95rem; font-weight: 600;
    color: var(--text-secondary); letter-spacing: 0.1em;
}
