/* ===== CSS Custom Properties ===== */
:root {
    /* Colors */
    --color-bg-primary: #0a0e27;
    --color-bg-secondary: #151932;
    --color-surface: rgba(255, 255, 255, 0.05);
    --color-surface-hover: rgba(255, 255, 255, 0.08);
    --color-border: rgba(255, 255, 255, 0.1);
    
    /* Gradients */
    --gradient-primary: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --gradient-secondary: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    --gradient-success: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
    --gradient-background: radial-gradient(ellipse at top, #1a1f3a 0%, #0a0e27 100%);
    
    /* Text */
    --color-text-primary: #ffffff;
    --color-text-secondary: rgba(255, 255, 255, 0.7);
    --color-text-muted: rgba(255, 255, 255, 0.5);
    
    /* Spacing */
    --spacing-xs: 0.5rem;
    --spacing-sm: 1rem;
    --spacing-md: 1.5rem;
    --spacing-lg: 2rem;
    --spacing-xl: 3rem;
    
    /* Border Radius */
    --radius-sm: 0.5rem;
    --radius-md: 1rem;
    --radius-lg: 1.5rem;
    --radius-full: 9999px;
    
    /* Shadows */
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.2);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.3);
    --shadow-glow: 0 0 40px rgba(102, 126, 234, 0.3);
    
    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-base: 250ms ease;
    --transition-slow: 350ms ease;
    
    /* Typography */
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* ===== Light Theme ===== */
[data-theme="light"] {
    /* Colors */
    --color-bg-primary: #f5f7fa;
    --color-bg-secondary: #ffffff;
    --color-surface: rgba(255, 255, 255, 0.9);
    --color-surface-hover: rgba(255, 255, 255, 1);
    --color-border: rgba(0, 0, 0, 0.1);
    
    /* Gradients */
    --gradient-background: radial-gradient(ellipse at top, #e0e7ff 0%, #f5f7fa 100%);
    
    /* Text */
    --color-text-primary: #1a1f3a;
    --color-text-secondary: rgba(26, 31, 58, 0.7);
    --color-text-muted: rgba(26, 31, 58, 0.5);
    
    /* Shadows */
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.12);
    --shadow-glow: 0 0 40px rgba(102, 126, 234, 0.2);
}

[data-theme="light"] .background-gradient {
    background: var(--gradient-background);
}

[data-theme="light"] .timer-card {
    background: var(--color-surface);
    box-shadow: var(--shadow-md);
    border: 1px solid var(--color-border);
}

[data-theme="light"] .timer-card:hover {
    box-shadow: var(--shadow-lg);
    border-color: rgba(102, 126, 234, 0.2);
}

/* ===== Reset & Base Styles ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-family);
    background: var(--color-bg-primary);
    color: var(--color-text-primary);
    line-height: 1.6;
    min-height: 100vh;
    overflow-x: hidden;
    position: relative;
}

.background-gradient {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--gradient-background);
    z-index: -1;
}

/* ===== Typography ===== */
h1 {
    font-size: clamp(2rem, 5vw, 3rem);
    font-weight: 700;
    letter-spacing: -0.02em;
    margin: 0;
}

h2 {
    font-size: clamp(1.5rem, 3vw, 2rem);
    font-weight: 600;
    letter-spacing: -0.01em;
}

h3 {
    font-size: 1.25rem;
    font-weight: 600;
}

p {
    font-size: 1rem;
    color: var(--color-text-secondary);
}

/* ===== Header ===== */
header {
    text-align: center;
    padding: var(--spacing-xl) var(--spacing-md) var(--spacing-lg);
    animation: fadeInDown 0.6s ease;
}

.header-top {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-md);
    position: relative;
}

.theme-toggle {
    position: absolute;
    right: 0;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-full);
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all var(--transition-base);
    font-size: 1.5rem;
}

.theme-toggle:hover {
    background: var(--color-surface-hover);
    transform: scale(1.05);
}

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

.theme-icon {
    transition: transform var(--transition-base);
}

.theme-toggle:hover .theme-icon {
    transform: rotate(20deg);
}

.subtitle {
    margin-top: var(--spacing-xs);
    font-size: 1.125rem;
    color: var(--color-text-muted);
}

.current-time {
    margin-top: var(--spacing-md);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-sm);
    font-size: 1.5rem;
    font-weight: 500;
    color: var(--color-text-primary);
}

.timezone-badge {
    font-size: 0.875rem;
    padding: 0.25rem 0.75rem;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-full);
    color: var(--color-text-secondary);
    font-weight: 500;
}

/* ===== Main Content ===== */
main {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 var(--spacing-md) var(--spacing-xl);
}

/* ===== Controls ===== */
.controls {
    display: flex;
    justify-content: center;
    margin-bottom: var(--spacing-lg);
    animation: fadeIn 0.6s ease 0.2s backwards;
}

/* ===== Buttons ===== */
.btn {
    font-family: var(--font-family);
    font-size: 1rem;
    font-weight: 500;
    padding: 0.875rem 1.75rem;
    border: none;
    border-radius: var(--radius-full);
    cursor: pointer;
    transition: all var(--transition-base);
    display: inline-flex;
    align-items: center;
    gap: var(--spacing-xs);
    position: relative;
    overflow: hidden;
}

.btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.1);
    opacity: 0;
    transition: opacity var(--transition-fast);
}

.btn:hover::before {
    opacity: 1;
}

.btn:active {
    transform: scale(0.98);
}

.btn-primary {
    background: var(--gradient-primary);
    color: var(--color-text-primary);
    box-shadow: var(--shadow-md), var(--shadow-glow);
}

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

.btn-icon {
    font-size: 1.5rem;
    line-height: 1;
}

.btn-small {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
}

.btn-secondary {
    background: var(--color-surface);
    color: var(--color-text-primary);
    border: 1px solid var(--color-border);
}

.btn-secondary:hover {
    background: var(--color-surface-hover);
}

.btn-danger {
    background: var(--gradient-secondary);
    color: var(--color-text-primary);
}

/* ===== Timers Grid ===== */
.timers-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: var(--spacing-md);
    animation: fadeIn 0.6s ease 0.3s backwards;
}

/* ===== Timer Card ===== */
.timer-card {
    background: var(--color-surface);
    backdrop-filter: blur(20px);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: var(--spacing-lg);
    box-shadow: var(--shadow-md);
    transition: all var(--transition-base);
    animation: scaleIn 0.4s ease;
}

.timer-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
    border-color: rgba(255, 255, 255, 0.2);
}

.timer-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--spacing-md);
}

.timer-title {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.timer-title-input {
    font-family: var(--font-family);
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--color-text-primary);
    background: var(--color-surface-hover);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    padding: 0.25rem 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    transition: all var(--transition-base);
    width: 150px;
}

.timer-title-input:focus {
    outline: none;
    border-color: rgba(102, 126, 234, 0.5);
    background: var(--color-surface);
}

.timer-title-editable {
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    border-radius: var(--radius-sm);
    transition: background var(--transition-fast);
}

.timer-title-editable:hover {
    background: var(--color-surface-hover);
}

.timer-delete {
    background: transparent;
    border: none;
    color: var(--color-text-muted);
    cursor: pointer;
    font-size: 1.25rem;
    padding: 0.25rem;
    transition: all var(--transition-fast);
    border-radius: var(--radius-sm);
}

.timer-delete:hover {
    color: #f5576c;
    background: rgba(245, 87, 108, 0.1);
}

/* ===== Timer Display ===== */
.timer-display {
    text-align: center;
    margin-bottom: var(--spacing-md);
}

.timer-time {
    font-size: clamp(3rem, 8vw, 4.5rem);
    font-weight: 700;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: -0.02em;
    line-height: 1.2;
}

.timer-time.active {
    background: var(--gradient-success);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    animation: pulse 2s ease-in-out infinite;
}

.timer-phase {
    font-size: 0.875rem;
    color: var(--color-text-secondary);
    margin-top: var(--spacing-xs);
    font-weight: 500;
}

.timer-session {
    font-size: 0.75rem;
    color: var(--color-text-muted);
    margin-top: 0.25rem;
}

/* ===== Timer Metadata ===== */
.timer-meta {
    margin-bottom: var(--spacing-sm);
    padding-bottom: var(--spacing-sm);
    border-bottom: 1px solid var(--color-border);
}

.timer-created {
    font-size: 0.75rem;
    color: var(--color-text-muted);
    font-style: italic;
}

/* ===== Timer Mode Toggle ===== */
.timer-mode-toggle {
    margin-top: var(--spacing-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-sm);
}

.toggle-switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 26px;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--color-surface-hover);
    border: 1px solid var(--color-border);
    transition: var(--transition-base);
    border-radius: var(--radius-full);
}

.toggle-slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background: var(--color-text-muted);
    transition: var(--transition-base);
    border-radius: 50%;
}

.toggle-switch input:checked + .toggle-slider {
    background: var(--gradient-primary);
    border-color: transparent;
}

.toggle-switch input:checked + .toggle-slider:before {
    transform: translateX(24px);
    background: white;
}

.toggle-switch input:focus + .toggle-slider {
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.2);
}

.toggle-label {
    font-size: 0.875rem;
    color: var(--color-text-secondary);
    font-weight: 500;
    min-width: 80px;
}

.timer-duration-input {
    margin-top: var(--spacing-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-xs);
}

.timer-duration-input label {
    font-size: 0.75rem;
    color: var(--color-text-secondary);
    font-weight: 500;
}

.timer-duration-input input {
    font-family: var(--font-family);
    width: 70px;
    padding: 0.5rem 0.75rem;
    font-size: 1rem;
    font-weight: 600;
    background: var(--color-surface-hover);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    color: var(--color-text-primary);
    text-align: center;
    transition: all var(--transition-base);
    cursor: pointer;
}

.timer-duration-input input:hover {
    border-color: rgba(102, 126, 234, 0.3);
    background: var(--color-surface);
}

.timer-duration-input input:focus {
    outline: none;
    border-color: rgba(102, 126, 234, 0.6);
    background: var(--color-surface);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

/* Enhanced spinner arrows */
.timer-duration-input input::-webkit-inner-spin-button,
.timer-duration-input input::-webkit-outer-spin-button {
    opacity: 1;
    width: 20px;
    height: 20px;
    margin-left: 8px;
    cursor: pointer;
}

/* Firefox spinner styling */
.timer-duration-input input[type="number"] {
    -moz-appearance: textfield;
    appearance: textfield;
}

.timer-duration-input input[type="number"]::-webkit-inner-spin-button,
.timer-duration-input input[type="number"]::-webkit-outer-spin-button {
    -webkit-appearance: inner-spin-button;
    appearance: inner-spin-button;
}

.timer-duration-input span {
    font-size: 0.875rem;
    color: var(--color-text-secondary);
    font-weight: 500;
}

/* ===== Timer Controls ===== */
.timer-controls {
    display: flex;
    gap: var(--spacing-sm);
    justify-content: center;
}

.timer-controls .btn {
    flex: 1;
    justify-content: center;
}

/* ===== Empty State ===== */
.empty-state {
    text-align: center;
    padding: var(--spacing-xl);
    animation: fadeIn 0.6s ease;
}

.empty-state.hidden {
    display: none;
}

.empty-icon {
    font-size: 4rem;
    margin-bottom: var(--spacing-md);
    opacity: 0.5;
}

.empty-state h2 {
    margin-bottom: var(--spacing-sm);
    color: var(--color-text-primary);
}

.empty-state p {
    color: var(--color-text-muted);
}

/* ===== Footer ===== */
footer {
    text-align: center;
    padding: var(--spacing-lg) var(--spacing-md);
    color: var(--color-text-muted);
    font-size: 0.875rem;
}

/* ===== Animations ===== */
@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes fadeInDown {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes scaleIn {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.8;
    }
}

/* ===== Responsive Design ===== */
@media (max-width: 768px) {
    :root {
        --spacing-xl: 2rem;
        --spacing-lg: 1.5rem;
    }
    
    .timers-grid {
        grid-template-columns: 1fr;
    }
    
    .timer-controls {
        flex-direction: column;
    }
    
    .timer-controls .btn {
        width: 100%;
    }
}

@media (max-width: 480px) {
    header {
        padding: var(--spacing-lg) var(--spacing-md);
    }
    
    .timer-card {
        padding: var(--spacing-md);
    }
    
    .btn {
        padding: 0.75rem 1.5rem;
    }
}

/* ===== Accessibility ===== */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Focus styles for keyboard navigation */
.btn:focus-visible,
.timer-delete:focus-visible,
.theme-toggle:focus-visible {
    outline: 2px solid var(--color-text-primary);
    outline-offset: 2px;
}

/* ===== Modal ===== */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.2s ease;
}

.modal.hidden {
    display: none;
}

.modal-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
}

.modal-content {
    position: relative;
    background: var(--color-bg-secondary);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: var(--spacing-lg);
    max-width: 400px;
    width: 90%;
    box-shadow: var(--shadow-lg);
    animation: scaleIn 0.3s ease;
    z-index: 1001;
}

.modal-content h3 {
    margin-bottom: var(--spacing-sm);
    color: var(--color-text-primary);
}

.modal-content p {
    margin-bottom: var(--spacing-lg);
    color: var(--color-text-secondary);
}

.modal-buttons {
    display: flex;
    gap: var(--spacing-sm);
    justify-content: flex-end;
}

.modal-buttons .btn {
    flex: 1;
}

