/* ===================================
   CSS Variables & Reset
   =================================== */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg-primary: #ffffff;
    --bg-secondary: #fafafa;
    --bg-tertiary: #f5f5f5;
    --text-primary: #000000;
    --text-secondary: #666666;
    --text-tertiary: #999999;
    --border: #e5e5e5;
    --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.08);
    --accent: #000000;
    --purple-accent: #8b5cf6;
    --purple-dark: #6d28d9;
    --purple-light: #a78bfa;
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-fast: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="dark"] {
    --bg-primary: #000000;
    --bg-secondary: #0a0a0a;
    --bg-tertiary: #1a1a1a;
    --text-primary: #ffffff;
    --text-secondary: #999999;
    --text-tertiary: #666666;
    --border: #2a2a2a;
    --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.4);
    --accent: #ffffff;
    --purple-accent: #a78bfa;
    --purple-dark: #8b5cf6;
    --purple-light: #c4b5fd;
}

/* ===================================
   Base Styles
   =================================== */

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    transition: var(--transition);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    position: relative;
    overflow-x: hidden;
}

/* Enhanced focus styles for accessibility */
*:focus {
    outline: 2px solid var(--purple-accent);
    outline-offset: 2px;
}

*:focus:not(:focus-visible) {
    outline: none;
}

*:focus-visible {
    outline: 2px solid var(--purple-accent);
    outline-offset: 2px;
}

/* Subtle noise texture */
.noise {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    opacity: 0.015;
    z-index: 1;
    background-image:
        repeating-linear-gradient(45deg, transparent, transparent 35px, rgba(128, 128, 128, 0.05) 35px, rgba(128, 128, 128, 0.05) 70px);
}

/* Audio-Reactive Purple Grain Animation */
.grain-animation {
    position: fixed;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    pointer-events: none;
    z-index: 0;
    opacity: 0;
    transition: opacity 1s ease-in-out, transform 0.1s ease-out;
    mix-blend-mode: screen;
    background: 
        radial-gradient(ellipse at center, var(--purple-accent) 0%, transparent 40%),
        radial-gradient(ellipse at top left, var(--purple-light) 0%, transparent 50%),
        radial-gradient(ellipse at bottom right, var(--purple-dark) 0%, transparent 50%);
    animation: grain 8s steps(10) infinite, pulse 4s ease-in-out infinite;
}

.grain-animation.active {
    opacity: 0.08;
}

[data-theme="dark"] .grain-animation.active {
    mix-blend-mode: plus-lighter;
    opacity: 0.06;
}

@keyframes grain {
    0%, 100% { transform: translate(0, 0) rotate(0deg); }
    10% { transform: translate(-5%, -10%) rotate(1deg); }
    20% { transform: translate(-15%, 5%) rotate(-1deg); }
    30% { transform: translate(7%, -25%) rotate(2deg); }
    40% { transform: translate(-5%, 25%) rotate(-2deg); }
    50% { transform: translate(-15%, 10%) rotate(1deg); }
    60% { transform: translate(15%, 0%) rotate(-1deg); }
    70% { transform: translate(0%, 15%) rotate(2deg); }
    80% { transform: translate(3%, 35%) rotate(-1deg); }
    90% { transform: translate(-10%, 10%) rotate(1deg); }
}

@keyframes pulse {
    0%, 100% { filter: blur(40px) brightness(1); }
    50% { filter: blur(60px) brightness(1.2); }
}

/* Enhanced Timer Card with potential glow */
.timer-card {
    background: var(--bg-secondary);
    border-radius: 32px;
    padding: 48px 32px;
    margin-bottom: 32px;
    box-shadow: var(--shadow-lg);
    animation: slideUp 0.8s ease 0.2s both;
    transition: box-shadow 0.3s ease, transform 0.3s ease;
    position: relative;
    z-index: 10;
}

.timer-card:hover {
    transform: translateY(-2px);
}

/* ===================================
   Theme Toggle
   =================================== */

.theme-toggle {
    position: fixed;
    top: 32px;
    left: 32px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    z-index: 100;
    box-shadow: var(--shadow-sm);
}

.theme-toggle:hover {
    box-shadow: var(--shadow-md);
    transform: scale(1.05);
}

.theme-toggle:active {
    transform: scale(0.95);
}

.theme-icon {
    color: var(--text-primary);
    position: absolute;
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.sun-icon {
    opacity: 1;
    transform: scale(1) rotate(0deg);
}

.moon-icon {
    opacity: 0;
    transform: scale(0.8) rotate(180deg);
}

[data-theme="dark"] .sun-icon {
    opacity: 0;
    transform: scale(0.8) rotate(180deg);
}

[data-theme="dark"] .moon-icon {
    opacity: 1;
    transform: scale(1) rotate(0deg);
}

/* ===================================
   Container & Layout
   =================================== */

.container {
    flex: 1;
    width: 100%;
    max-width: 480px;
    margin: 0 auto;
    padding: 100px 24px 40px;
    position: relative;
    z-index: 2;
}

/* ===================================
   Header
   =================================== */

.app-header {
    text-align: center;
    margin-bottom: 48px;
    animation: fadeIn 0.8s ease;
}

.app-title {
    font-size: 36px;
    font-weight: 200;
    letter-spacing: 12px;
    margin-bottom: 16px;
    opacity: 0.9;
    background: linear-gradient(135deg, var(--text-primary), var(--purple-accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.session-dots {
    display: flex;
    justify-content: center;
    gap: 12px;
    height: 20px;
}

.session-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--border);
    transition: var(--transition);
}

.session-dot.completed {
    background: var(--text-tertiary);
    transform: scale(1.2);
    box-shadow: 0 0 8px var(--text-tertiary);
}

.session-dot.current {
    background: var(--accent);
    animation: sessionPulse 2s ease-in-out infinite;
}

@keyframes sessionPulse {
    0%, 100% { 
        transform: scale(1.2); 
        opacity: 1; 
    }
    50% { 
        transform: scale(1.4); 
        opacity: 0.7; 
    }
}

/* ===================================
   Timer Section
   =================================== */

.timer-wrapper {
    margin-bottom: 40px;
}

/* Circular Timer */
.circular-timer {
    position: relative;
    width: 280px;
    height: 280px;
    margin: 0 auto;
}

.timer-svg {
    width: 100%;
    height: 100%;
    transform: rotate(-90deg);
}

.timer-circle-bg {
    fill: none;
    stroke: var(--bg-tertiary);
    stroke-width: 8;
}

.timer-circle-progress {
    fill: none;
    stroke: var(--accent);
    stroke-width: 8;
    stroke-linecap: round;
    stroke-dasharray: 816.8;
    stroke-dashoffset: 816.8;
    transition: stroke-dashoffset 1s linear;
    filter: drop-shadow(0 0 4px var(--accent));
}

.timer-content {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    width: 100%;
}

.timer-label {
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 3px;
    text-transform: uppercase;
    color: var(--text-tertiary);
    margin-bottom: 8px;
}

.timer-time {
    font-size: 64px;
    font-weight: 200;
    font-variant-numeric: tabular-nums;
    line-height: 1;
    margin-bottom: 16px;
    transition: transform 0.3s ease;
    background: linear-gradient(135deg, var(--text-primary), var(--purple-accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.timer-time.breathing {
    animation: breathe 4s ease-in-out infinite;
}

@keyframes breathe {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.02); }
}

.timer-task {
    padding: 0 20px;
}

.task-input {
    width: 100%;
    background: transparent;
    border: none;
    text-align: center;
    font-size: 14px;
    color: var(--text-secondary);
    padding: 8px;
    transition: var(--transition);
    border-radius: 8px;
}

.task-input:focus {
    outline: none;
    color: var(--text-primary);
    background: var(--bg-tertiary);
}

.task-input::placeholder {
    color: var(--text-tertiary);
}

/* ===================================
   Controls
   =================================== */

.controls {
    margin-bottom: 32px;
}

.btn {
    width: 100%;
    padding: 18px 32px;
    border: none;
    border-radius: 16px;
    font-size: 14px;
    font-weight: 600;
    letter-spacing: 2px;
    text-transform: uppercase;
    cursor: pointer;
    transition: var(--transition);
    position: relative;
    overflow: hidden;
}

.btn::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    transition: width 0.3s ease, height 0.3s ease;
}

.btn:active::before {
    width: 300px;
    height: 300px;
}

.btn-primary {
    background: var(--accent);
    color: var(--bg-primary);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.btn-primary:active {
    transform: translateY(0);
}

/* Mode Tabs */
.mode-tabs {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    background: var(--bg-tertiary);
    padding: 4px;
    border-radius: 12px;
}

.mode-tab {
    padding: 12px;
    border: none;
    background: transparent;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-tertiary);
    cursor: pointer;
    transition: var(--transition);
}

.mode-tab.active {
    background: var(--bg-primary);
    color: var(--text-primary);
    box-shadow: var(--shadow-sm);
    transform: translateY(-1px);
}

.mode-tab:not(.active):hover {
    color: var(--text-secondary);
    background: var(--bg-secondary);
}

/* ===================================
   Stats Row
   =================================== */

.stats-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    margin-bottom: 32px;
    animation: slideUp 0.8s ease 0.4s both;
}

.stat-item {
    text-align: center;
    padding: 20px;
    background: var(--bg-secondary);
    border-radius: 16px;
    border: 1px solid var(--border);
    transition: var(--transition);
}

.stat-item:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.stat-icon {
    color: var(--text-tertiary);
    margin-bottom: 8px;
    opacity: 0.6;
}

.stat-value {
    font-size: 24px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.stat-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-tertiary);
}

/* ===================================
   Ambient Sound Selector
   =================================== */

.ambient-selector {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin-bottom: 24px;
    animation: slideUp 0.8s ease 0.6s both;
}

.ambient-btn {
    padding: 12px 4px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 12px;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    color: var(--text-secondary);
    position: relative;
    overflow: hidden;
}

.ambient-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.1), transparent);
    transition: left 0.5s ease;
}

.ambient-btn:hover::before {
    left: 100%;
}

.ambient-btn.active {
    background: var(--accent);
    color: var(--bg-primary);
    border-color: var(--accent);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.ambient-btn:not(.active):hover {
    border-color: var(--purple-accent);
    background: var(--bg-tertiary);
    color: var(--text-primary);
    transform: translateY(-1px);
}

.ambient-btn:active {
    transform: translateY(0);
}

.ambient-icon {
    width: 20px;
    height: 20px;
}

.ambient-label {
    font-size: 10px;
    font-weight: 500;
    text-align: center;
}

/* ===================================
   Audio Controls
   =================================== */

.audio-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    margin-bottom: 32px;
    animation: slideUp 0.8s ease 0.7s both;
}

.mute-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    color: var(--text-secondary);
}

.mute-btn:hover {
    color: var(--text-primary);
    border-color: var(--text-tertiary);
    transform: scale(1.05);
}

.mute-btn:active {
    transform: scale(0.95);
}

.mute-icon {
    width: 20px;
    height: 20px;
}

.volume-slider {
    -webkit-appearance: none;
    appearance: none;
    width: 120px;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    outline: none;
    transition: var(--transition);
}

.volume-slider:hover {
    background: var(--text-tertiary);
}

.volume-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    background: var(--text-primary);
    cursor: pointer;
    border-radius: 50%;
    transition: var(--transition);
    box-shadow: var(--shadow-sm);
}

.volume-slider::-moz-range-thumb {
    width: 16px;
    height: 16px;
    background: var(--text-primary);
    cursor: pointer;
    border-radius: 50%;
    border: none;
    transition: var(--transition);
    box-shadow: var(--shadow-sm);
}

.volume-slider:hover::-webkit-slider-thumb {
    background: var(--purple-accent);
    transform: scale(1.2);
    box-shadow: 0 0 12px var(--purple-accent);
}

.volume-slider:hover::-moz-range-thumb {
    background: var(--purple-accent);
    transform: scale(1.2);
    box-shadow: 0 0 12px var(--purple-accent);
}

/* ===================================
   Settings
   =================================== */

.settings-row {
    position: relative;
    display: flex;
    justify-content: center;
    margin-bottom: 32px;
    animation: slideUp 0.8s ease 0.8s both;
}

.setting-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    color: var(--text-secondary);
}

.setting-btn:hover {
    color: var(--text-primary);
    border-color: var(--text-tertiary);
    transform: rotate(45deg) scale(1.05);
}

.setting-btn:active {
    transform: rotate(45deg) scale(0.95);
}

.settings-panel {
    position: absolute;
    bottom: 60px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 20px;
    box-shadow: var(--shadow-lg);
    display: none;
    gap: 16px;
    min-width: 280px;
    z-index: 50;
}

.settings-panel.active {
    display: flex;
    flex-direction: column;
    animation: fadeIn 0.3s ease, slideUp 0.3s ease;
}

.setting-item {
    display: flex;
    align-items: center;
    gap: 12px;
}

.setting-item label {
    flex: 1;
    font-size: 13px;
    color: var(--text-secondary);
    font-weight: 500;
}

.setting-item input {
    width: 60px;
    padding: 8px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
    text-align: center;
    color: var(--text-primary);
    transition: var(--transition);
}

.setting-item input:focus {
    outline: none;
    border-color: var(--purple-accent);
    box-shadow: 0 0 8px var(--purple-accent);
}

.setting-item input:hover {
    border-color: var(--text-tertiary);
}

.setting-item span {
    font-size: 12px;
    color: var(--text-tertiary);
    font-weight: 500;
}

/* ===================================
   Footer
   =================================== */

.footer {
    text-align: center;
    padding: 32px 24px;
    font-size: 13px;
    color: var(--text-tertiary);
    animation: fadeIn 1s ease 1s both;
    border-top: 1px solid var(--border);
    margin-top: 40px;
}

.footer p {
    margin-bottom: 8px;
}

.footer p:last-child {
    margin-bottom: 0;
}

.footer a {
    color: var(--text-secondary);
    text-decoration: none;
    transition: var(--transition);
}

.footer a:hover {
    color: var(--purple-accent);
}

.footer kbd {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 2px 6px;
    font-size: 11px;
    font-weight: 500;
    color: var(--text-secondary);
}

/* ===================================
   Notification
   =================================== */

.notification {
    position: fixed;
    bottom: 32px;
    right: 32px;
    background: var(--accent);
    color: var(--bg-primary);
    padding: 16px 24px;
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    transform: translateY(100px);
    opacity: 0;
    transition: var(--transition);
    z-index: 1000;
    font-size: 14px;
    font-weight: 500;
    pointer-events: none;
    max-width: 300px;
    line-height: 1.4;
}

.notification.show {
    transform: translateY(0);
    opacity: 1;
    pointer-events: auto;
    animation: slideIn 0.4s ease, fadeOut 0.3s ease 3.7s;
}

@keyframes slideIn {
    from {
        transform: translateY(100px) scale(0.9);
        opacity: 0;
    }
    to {
        transform: translateY(0) scale(1);
        opacity: 1;
    }
}

@keyframes fadeOut {
    to {
        opacity: 0;
        transform: translateY(-10px);
    }
}

/* ===================================
   Animations
   =================================== */

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

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

/* ===================================
   Responsive Design
   =================================== */

@media (max-width: 640px) {
    .container {
        padding: 80px 16px 32px;
    }

    .theme-toggle {
        top: 20px;
        left: 20px;
        width: 40px;
        height: 40px;
    }

    .app-title {
        font-size: 28px;
        letter-spacing: 8px;
    }

    .timer-card {
        padding: 32px 20px;
    }

    .circular-timer {
        width: 240px;
        height: 240px;
    }

    .timer-time {
        font-size: 48px;
    }

    .ambient-selector {
        grid-template-columns: repeat(3, 1fr);
        gap: 6px;
    }

    .ambient-btn {
        padding: 10px 4px;
    }

    .audio-controls {
        flex-direction: column;
        gap: 12px;
    }

    .settings-panel {
        left: 16px;
        right: 16px;
        transform: none;
        min-width: auto;
    }

    .notification {
        bottom: 20px;
        right: 16px;
        left: 16px;
        max-width: none;
    }

    .stats-row {
        gap: 12px;
    }

    .stat-item {
        padding: 16px 12px;
    }

    .stat-value {
        font-size: 20px;
    }
}

@media (max-width: 400px) {
    .ambient-selector {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .app-title {
        font-size: 24px;
        letter-spacing: 6px;
    }

    .circular-timer {
        width: 200px;
        height: 200px;
    }

    .timer-time {
        font-size: 40px;
    }
}

/* ===================================
   Dark Mode Enhancements
   =================================== */

[data-theme="dark"] .timer-card {
    background: linear-gradient(145deg, var(--bg-secondary), var(--bg-tertiary));
}

[data-theme="dark"] .stat-item:hover {
    background: var(--bg-tertiary);
}

[data-theme="dark"] .ambient-btn:not(.active):hover {
    background: var(--bg-tertiary);
}

/* ===================================
   High Contrast Mode Support
   =================================== */

@media (prefers-contrast: high) {
    :root {
        --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.2);
        --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.3);
        --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.4);
    }
    
    .timer-circle-progress {
        stroke-width: 10;
    }
    
    .btn-primary {
        border: 2px solid var(--accent);
    }
}

/* ===================================
   Reduced Motion Support
   =================================== */

@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
    
    .timer-time.breathing {
        animation: none;
    }
    
    .session-dot.current {
        animation: none;
    }
    
    .grain-animation {
        animation: none;
    }
}

/* ===================================
   Print Styles
   =================================== */

@media print {
    .theme-toggle,
    .ambient-selector,
    .audio-controls,
    .settings-row,
    .grain-animation,
    .noise {
        display: none;
    }
    
    .container {
        padding: 20px;
    }
    
    .timer-card {
        box-shadow: none;
        border: 2px solid #000;
    }
}
