:root {
    /* Basfärger */
    --bg-main: #121214;
    --bg-card: #1c1c1e;
    --bg-elevated: #2c2c2e;
    
    --text-primary: #ffffff;
    --text-secondary: #8e8e93;
    --text-tertiary: #48484a;

    /* Accentfärger (Soft Neon) */
    --accent-blue: #64d2ff;
    --accent-green: #30d158;
    --accent-indigo: #5e5ce6;
    --accent-orange: #ff9f0a;
    --accent-red: #ff453a;

    /* Zonfärger */
    --zone-1: #64d2ff; 
    --zone-2: #30d158; 
    --zone-3: #ffd60a; 
    --zone-4: #ff9f0a; 
    --zone-5: #ff453a; 

    --font-stack: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Inter", "Segoe UI", sans-serif;
    
    /* Layout Variables */
    --bottom-safe-area: env(safe-area-inset-bottom, 20px);
    --header-height: 60px;
}

* { box-sizing: border-box; user-select: none; -webkit-tap-highlight-color: transparent; }

body {
    background-color: var(--bg-main);
    color: var(--text-primary);
    font-family: var(--font-stack);
    margin: 0;
    overflow: hidden;
    height: 100vh;
    width: 100vw;
}

.lucide { width: 24px; height: 24px; stroke-width: 2px; }

/* --- SCREENS --- */
.screen {
    height: 100%;
    width: 100%;
    display: flex;
    flex-direction: column;
    opacity: 0;
    animation: fadeIn 0.4s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
    position: absolute;
    top: 0;
    left: 0;
    background: var(--bg-main);
}

@keyframes fadeIn { to { opacity: 1; } }

/* SCROLLABLE CONTENT AREA */
.scroll-content {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    padding-bottom: calc(100px + var(--bottom-safe-area)); /* Plats för flytande knapp */
    -webkit-overflow-scrolling: touch;
}

/* FIXED BOTTOM ACTION BAR */
.bottom-action-bar {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    padding: 20px 24px;
    padding-bottom: calc(20px + var(--bottom-safe-area));
    background: linear-gradient(to top, var(--bg-main) 85%, rgba(18,18,20,0));
    z-index: 50;
    display: flex;
    flex-direction: column;
    align-items: center;
    pointer-events: none; /* Let clicks pass through gradient area */
}

.bottom-action-bar > * {
    pointer-events: auto; /* Re-enable clicks on buttons */
}

/* SETUP SCREEN */
.setup-header { text-align: center; margin-top: 20px; margin-bottom: 40px; position: relative; }
.top-right-action { position: absolute; top: 0; right: 0; }

.logo-icon { 
    background: var(--bg-elevated); width: 80px; height: 80px; 
    border-radius: 24px; display: flex; align-items: center; justify-content: center; 
    margin: 0 auto 20px; color: var(--accent-green);
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
}
.logo-icon .lucide { width: 40px; height: 40px; }

.setup-header h1 { font-size: 2rem; font-weight: 700; margin: 0; letter-spacing: -0.5px; }
.subtitle { color: var(--text-secondary); margin-top: 5px; font-weight: 500; }

.setup-controls { width: 100%; max-width: 400px; margin: 0 auto; display: flex; flex-direction: column; gap: 32px; }

.control-group label { 
    display: block; color: var(--text-secondary); 
    font-size: 0.85rem; font-weight: 600; text-transform: uppercase; 
    letter-spacing: 1px; margin-bottom: 12px; 
}

/* Pill Selector */
.pill-selector { display: flex; background: var(--bg-card); padding: 4px; border-radius: 16px; }
.pill-selector button { 
    flex: 1; background: transparent; border: none; 
    color: var(--text-secondary); padding: 14px; 
    border-radius: 12px; font-weight: 600; font-size: 1rem; 
    transition: all 0.2s cubic-bezier(0.2, 0.8, 0.2, 1); cursor: pointer;
}
.pill-selector button.active { 
    background: #fff; color: #000; box-shadow: 0 2px 8px rgba(0,0,0,0.1); 
}

/* Cards */
.card-selector { display: flex; gap: 16px; }
.card { 
    flex: 1; background: var(--bg-card); padding: 20px; 
    border-radius: 20px; cursor: pointer; transition: 0.2s; 
    display: flex; flex-direction: column; align-items: center; gap: 10px;
    border: 2px solid transparent;
}
.card.active { 
    background: var(--bg-elevated); border-color: var(--accent-green); 
    color: var(--accent-green); 
}

/* Select */
.minimal-select { 
    width: 100%; padding: 16px; background: var(--bg-card); 
    border: none; color: white; border-radius: 16px; 
    font-size: 1rem; font-weight: 500; appearance: none;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
    background-repeat: no-repeat; background-position: right 16px center; background-size: 20px;
}

/* Action Button */
.btn-primary-fab { 
    width: 72px; height: 72px; border-radius: 50%; 
    background: var(--accent-green); border: none; 
    color: #000; display: flex; align-items: center; justify-content: center; 
    box-shadow: 0 8px 24px rgba(48, 209, 88, 0.3); 
    transition: transform 0.1s; cursor: pointer; 
}
.btn-primary-fab:active { transform: scale(0.95); }
.action-label { font-size: 0.9rem; font-weight: 600; color: var(--text-secondary); margin-top: 10px; }

/* PREVIEW SCREEN */
.preview-header { 
    display: flex; justify-content: space-between; align-items: center; 
    padding: 24px; padding-top: calc(10px + env(safe-area-inset-top)); 
    background: var(--bg-main); z-index: 10;
}
.btn-icon { background: var(--bg-card); border: none; color: white; cursor: pointer; padding: 10px; border-radius: 50%; width: 40px; height: 40px; display: flex; align-items: center; justify-content: center; }

.visualizer-container { padding: 20px; background: var(--bg-card); border-radius: 24px; margin-bottom: 20px; }
.workout-visualizer { height: 120px; display: flex; align-items: flex-end; gap: 4px; }
.preview-bar { flex: 1; border-radius: 4px; opacity: 0.8; }
.preview-bar.zone-1 { background: var(--zone-1); }
.preview-bar.zone-2 { background: var(--zone-2); }
.preview-bar.zone-3 { background: var(--zone-3); }
.preview-bar.zone-4 { background: var(--zone-4); }
.preview-bar.zone-5 { background: var(--zone-5); }

.track-item { display: flex; align-items: center; gap: 16px; padding: 12px 0; border-bottom: 1px solid var(--bg-elevated); }
.track-item img { width: 48px; height: 48px; border-radius: 12px; background: var(--bg-card); object-fit: cover; }
.track-info { flex: 1; min-width: 0; }
.track-title { font-weight: 600; font-size: 1rem; margin-bottom: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.track-meta { font-size: 0.85rem; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.btn-primary-wide { 
    width: 100%; padding: 18px; background: white; color: black; 
    border: none; border-radius: 100px; font-weight: 700; font-size: 1.1rem; 
    cursor: pointer; box-shadow: 0 4px 15px rgba(255,255,255,0.15);
}

.btn-secondary-icon {
    width: 56px; height: 56px; border-radius: 16px; 
    background: var(--bg-elevated); border: none; 
    color: var(--text-primary); display: flex; align-items: center; justify-content: center; 
    cursor: pointer; transition: 0.2s;
}
.btn-secondary-icon:active { transform: scale(0.95); background: var(--bg-card); }

/* SAVED WORKOUTS LIST */
.saved-list { display: flex; flex-direction: column; gap: 12px; }
.saved-item { 
    background: var(--bg-card); padding: 16px; border-radius: 16px; 
    display: flex; justify-content: space-between; align-items: center;
    cursor: pointer; transition: background 0.2s;
}
.saved-item:active { background: var(--bg-elevated); }
.saved-info h3 { margin: 0 0 4px 0; font-size: 1rem; }
.saved-meta { color: var(--text-secondary); font-size: 0.85rem; }
.saved-actions { opacity: 0.5; }

/* ACTIVE SCREEN */
.active-screen { padding: 0; }
.active-content { 
    padding: 24px; padding-top: calc(20px + env(safe-area-inset-top)); 
    display: flex; flex-direction: column; height: 100%;
}

.zone-indicator { position: absolute; top: 0; left: 0; width: 100%; height: 6px; transition: background 0.3s; }
.zone-indicator.zone-1 { background: var(--zone-1); box-shadow: 0 0 20px var(--zone-1); }
.zone-indicator.zone-2 { background: var(--zone-2); box-shadow: 0 0 20px var(--zone-2); }
.zone-indicator.zone-3 { background: var(--zone-3); box-shadow: 0 0 20px var(--zone-3); }
.zone-indicator.zone-4 { background: var(--zone-4); box-shadow: 0 0 20px var(--zone-4); }
.zone-indicator.zone-5 { background: var(--zone-5); box-shadow: 0 0 20px var(--zone-5); }

.top-bar { display: flex; justify-content: space-between; margin-bottom: 20px; }
.metric .label { font-size: 0.8rem; font-weight: 700; color: var(--text-secondary); display: block; }
.metric .val { font-size: 2rem; font-weight: 700; font-variant-numeric: tabular-nums; }

.center-stage { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; position: relative; }
.ring-container { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%) rotate(-90deg); z-index: 0; }
.bg-ring { stroke: var(--bg-elevated); }
.progress-ring__circle { transition: stroke-dashoffset 0.5s linear, stroke 0.3s; stroke: var(--zone-1); }

.timer-display { font-size: 5rem; font-weight: 800; font-variant-numeric: tabular-nums; z-index: 10; letter-spacing: -3px; line-height: 1; }
.segment-meta { z-index: 10; text-align: center; margin-top: 10px; max-width: 80%; }
.segment-meta h2 { font-size: 1.6rem; margin: 0; font-weight: 600; }
.segment-meta p { color: var(--text-secondary); margin-top: 6px; font-size: 1.1rem; }

.bottom-controls { margin-top: auto; padding-bottom: var(--bottom-safe-area); display: flex; flex-direction: column; gap: 16px; }

.next-pill { 
    background: var(--bg-card); padding: 12px 20px; border-radius: 12px; 
    display: flex; justify-content: space-between; font-weight: 600; 
}
.music-pill { 
    background: rgba(255,255,255,0.08); padding: 12px 20px; border-radius: 12px; 
    display: flex; align-items: center; gap: 12px; color: var(--accent-blue);
}
.track-info-scroll { flex: 1; overflow: hidden; white-space: nowrap; position: relative; }
.track-info-scroll span { display: inline-block; padding-left: 100%; animation: marquee 15s linear infinite; }
@keyframes marquee { 0% { transform: translateX(0); } 100% { transform: translateX(-100%); } }

.btn-fab-small { 
    align-self: center; width: 64px; height: 64px; border-radius: 50%; 
    background: var(--text-primary); border: none; color: black; 
    display: flex; align-items: center; justify-content: center; cursor: pointer;
    box-shadow: 0 4px 12px rgba(255,255,255,0.2);
}

/* BRIEFING OVERLAY */
.briefing-overlay { 
    position: fixed; top: 0; left: 0; width: 100%; height: 100%; 
    background: var(--bg-main); z-index: 100; padding: 40px;
    display: flex; flex-direction: column; justify-content: center; align-items: center; 
}
.progress-line-container { width: 100%; height: 4px; background: var(--bg-elevated); border-radius: 2px; overflow: hidden; margin-bottom: 40px; }
.progress-line-fill { height: 100%; background: white; width: 0%; transition: width 0.1s linear; }

/* SPINNER */
.loading-state { display: flex; flex-direction: column; align-items: center; gap: 16px; padding: 40px; color: var(--text-secondary); }
.spinner-minimal { width: 32px; height: 32px; border: 3px solid var(--bg-elevated); border-top-color: var(--accent-green); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
