/* EntrainBrain Web App - Mobile-First Design */

/* ============================================
   CSS Variables
   ============================================ */
:root {
    /* Light theme */
    --bg-primary: #ffffff;
    --bg-secondary: #f0f0f5;
    --bg-card: #ffffff;
    --bg-elevated: #fafafa;
    --text-primary: #111111;
    --text-secondary: #555555;
    --text-hint: #888888;
    --border-color: #d0d0d0;
    --shadow-color: rgba(0, 0, 0, 0.12);

    /* Accent */
    --accent: #5b4cdb;
    --accent-light: #7c6fe8;
    --accent-bg: rgba(91, 76, 219, 0.12);

    /* Gradients */
    --gradient-primary: linear-gradient(135deg, #5b4cdb 0%, #8b5cf6 100%);
    --gradient-premium: linear-gradient(135deg, #f59e0b 0%, #ef4444 100%);
    --gradient-pro: linear-gradient(135deg, #8b5cf6 0%, #3b82f6 100%);

    /* Typography - LARGE for mobile */
    --font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', Roboto, sans-serif;
    --font-xs: 13px;
    --font-sm: 15px;
    --font-base: 17px;
    --font-lg: 19px;
    --font-xl: 22px;
    --font-2xl: 26px;

    /* Spacing */
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 12px;
    --space-lg: 16px;
    --space-xl: 20px;
    --space-2xl: 28px;

    /* Radius */
    --radius-sm: 10px;
    --radius-md: 14px;
    --radius-lg: 18px;
    --radius-xl: 22px;
    --radius-full: 9999px;
}

/* Dark theme */
[data-theme="dark"] {
    --bg-primary: #0d0d12;
    --bg-secondary: #18181f;
    --bg-card: #1f1f28;
    --bg-elevated: #28283a;
    --text-primary: #ffffff;
    --text-secondary: #b0b0b8;
    --text-hint: #707078;
    --border-color: #333340;
    --shadow-color: rgba(0, 0, 0, 0.4);
    --accent-bg: rgba(91, 76, 219, 0.2);
}

/* ============================================
   Reset
   ============================================ */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: var(--font-family);
    font-size: var(--font-base);
    font-weight: 400;
    line-height: 1.5;
    color: var(--text-primary);
    background: var(--bg-primary);
    min-height: 100vh;
    overflow-x: hidden;
    transition: background 0.3s, color 0.3s;
}

/* ============================================
   App Container
   ============================================ */
.app {
    max-width: 500px;
    margin: 0 auto;
    padding: var(--space-lg);
    padding-bottom: 120px;
}

/* ============================================
   Header
   ============================================ */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-sm) 0;
    margin-bottom: var(--space-xl);
}

.header-left {
    display: flex;
    align-items: center;
}

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

.logo-icon {
    font-size: 28px;
}

.logo-text {
    font-size: var(--font-lg);
    font-weight: 700;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

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

/* Theme Toggle Button */
.theme-toggle {
    width: 44px;
    height: 44px;
    border: none;
    border-radius: var(--radius-full);
    background: var(--bg-secondary);
    color: var(--text-primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    -webkit-appearance: none;
    appearance: none;
}

.theme-toggle:active {
    transform: scale(0.9);
    background: var(--accent-bg);
}

.theme-toggle svg {
    width: 24px;
    height: 24px;
    fill: currentColor;
    pointer-events: none;
}

/* Theme toggle icons visibility */
.theme-toggle .icon-sun {
    display: none;
}

.theme-toggle .icon-moon {
    display: block;
}

[data-theme="dark"] .theme-toggle .icon-sun {
    display: block;
}

[data-theme="dark"] .theme-toggle .icon-moon {
    display: none;
}

/* User Status */
.user-status {
    padding: var(--space-xs) var(--space-md);
    border-radius: var(--radius-full);
    font-size: var(--font-xs);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    background: var(--bg-secondary);
    color: var(--text-secondary);
    border: 2px solid var(--border-color);
}

.user-status.trial,
.user-status.premium {
    background: var(--gradient-premium);
    color: white;
    border: none;
}

.user-status.pro {
    background: var(--gradient-pro);
    color: white;
    border: none;
}

/* ============================================
   Visualizer
   ============================================ */
.visualizer-container {
    position: relative;
    width: 100%;
    height: 160px;
    background: var(--bg-secondary);
    border-radius: var(--radius-xl);
    overflow: hidden;
    margin-bottom: var(--space-xl);
    border: 2px solid var(--border-color);
}

#visualizer {
    width: 100%;
    height: 100%;
}

.wave-info {
    position: absolute;
    bottom: var(--space-md);
    left: var(--space-md);
    display: flex;
    flex-direction: column;
    gap: 2px;
    background: var(--bg-card);
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
}

.wave-type {
    font-size: var(--font-sm);
    font-weight: 700;
    color: var(--accent);
}

.wave-freq {
    font-size: var(--font-xs);
    color: var(--text-secondary);
    font-weight: 500;
}

/* ============================================
   Player
   ============================================ */
.player {
    background: var(--bg-card);
    border-radius: var(--radius-xl);
    padding: var(--space-xl);
    margin-bottom: var(--space-2xl);
    border: 2px solid var(--border-color);
    box-shadow: 0 4px 20px var(--shadow-color);
}

.now-playing {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    margin-bottom: var(--space-lg);
}

.preset-icon {
    font-size: 40px;
}

.preset-name {
    font-size: var(--font-lg);
    font-weight: 700;
    color: var(--text-primary);
}

/* Progress */
.progress-container {
    margin-bottom: var(--space-lg);
}

.progress-bar {
    width: 100%;
    height: 10px;
    background: var(--bg-secondary);
    border-radius: var(--radius-full);
    overflow: hidden;
    cursor: pointer;
}

.progress-fill {
    width: 0%;
    height: 100%;
    background: var(--gradient-primary);
    border-radius: var(--radius-full);
    transition: width 0.1s linear;
}

.time-display {
    display: flex;
    justify-content: space-between;
    margin-top: var(--space-sm);
    font-size: var(--font-sm);
    font-weight: 600;
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
}

/* Controls */
.controls {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: var(--space-2xl);
}

.control-btn {
    width: 56px;
    height: 56px;
    border: none;
    border-radius: var(--radius-full);
    background: var(--bg-secondary);
    color: var(--text-primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
    -webkit-appearance: none;
}

.control-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.control-btn:not(:disabled):active {
    transform: scale(0.9);
    background: var(--accent-bg);
}

.control-btn svg {
    width: 28px;
    height: 28px;
    fill: currentColor;
}

.play-btn {
    width: 72px;
    height: 72px;
    background: var(--gradient-primary);
    color: white;
    box-shadow: 0 6px 20px rgba(91, 76, 219, 0.4);
}

.play-btn:not(:disabled):active {
    transform: scale(0.92);
    background: var(--gradient-primary);
}

.play-btn svg {
    width: 36px;
    height: 36px;
}

.play-btn .icon-pause {
    display: none;
}

.play-btn.playing .icon-play {
    display: none;
}

.play-btn.playing .icon-pause {
    display: block;
}

/* ============================================
   Presets
   ============================================ */
.presets-section {
    margin-bottom: var(--space-2xl);
}

.section-title {
    font-size: var(--font-xl);
    font-weight: 700;
    margin-bottom: var(--space-lg);
    color: var(--text-primary);
}

.presets-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-md);
}

.preset-card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: var(--space-lg);
    cursor: pointer;
    transition: all 0.15s;
    position: relative;
    border: 2px solid var(--border-color);
}

.preset-card:active {
    transform: scale(0.97);
    border-color: var(--accent);
}

.preset-card.locked {
    opacity: 0.55;
}

.preset-card.locked::after {
    content: '🔒';
    position: absolute;
    top: var(--space-sm);
    right: var(--space-sm);
    font-size: 16px;
}

.preset-card.active {
    border-color: var(--accent);
    background: var(--accent-bg);
}

.preset-card-icon {
    font-size: 36px;
    margin-bottom: var(--space-sm);
}

.preset-card-name {
    font-size: var(--font-base);
    font-weight: 700;
    margin-bottom: var(--space-xs);
    color: var(--text-primary);
}

.preset-card-desc {
    font-size: var(--font-sm);
    color: var(--text-secondary);
    line-height: 1.4;
    font-weight: 500;
}

.preset-card-badge {
    position: absolute;
    top: var(--space-sm);
    right: var(--space-sm);
    font-size: 10px;
    font-weight: 800;
    padding: 3px 8px;
    border-radius: var(--radius-sm);
    text-transform: uppercase;
}

.preset-card-badge.premium {
    background: var(--gradient-premium);
    color: white;
}

.preset-card-badge.pro {
    background: var(--gradient-pro);
    color: white;
}

/* ============================================
   Modals
   ============================================ */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: var(--space-xl);
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--bg-card);
    border-radius: var(--radius-xl);
    padding: var(--space-2xl);
    width: 100%;
    max-width: 340px;
    text-align: center;
    border: 2px solid var(--border-color);
}

.modal-content h3 {
    margin-bottom: var(--space-xl);
    font-size: var(--font-xl);
    font-weight: 700;
    color: var(--text-primary);
}

.duration-options {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--space-sm);
    margin-bottom: var(--space-xl);
}

.duration-btn {
    padding: var(--space-md);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    background: transparent;
    color: var(--text-primary);
    font-size: var(--font-base);
    font-weight: 700;
    cursor: pointer;
    transition: all 0.15s;
    -webkit-appearance: none;
}

.duration-btn:active {
    border-color: var(--accent);
    background: var(--accent-bg);
}

.modal-close {
    width: 100%;
    padding: var(--space-lg);
    border: none;
    border-radius: var(--radius-md);
    background: var(--bg-secondary);
    color: var(--text-secondary);
    font-size: var(--font-base);
    font-weight: 600;
    cursor: pointer;
    -webkit-appearance: none;
}

.locked-icon {
    font-size: 56px;
    margin-bottom: var(--space-md);
}

.modal-content p {
    color: var(--text-secondary);
    font-size: var(--font-base);
    margin-bottom: var(--space-xl);
    font-weight: 500;
}

.btn-primary {
    width: 100%;
    padding: var(--space-lg);
    border: none;
    border-radius: var(--radius-md);
    background: var(--gradient-primary);
    color: white;
    font-size: var(--font-base);
    font-weight: 700;
    cursor: pointer;
    margin-bottom: var(--space-md);
    -webkit-appearance: none;
}

/* ============================================
   Animations
   ============================================ */
@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

.preset-card.active .preset-card-icon {
    animation: pulse 1.5s ease-in-out infinite;
}

/* ============================================
   Safe Area
   ============================================ */
@supports (padding: env(safe-area-inset-top)) {
    .app {
        padding-top: max(var(--space-lg), env(safe-area-inset-top));
        padding-bottom: max(120px, calc(env(safe-area-inset-bottom) + 100px));
    }
}
