/* CSS Variables */
:root {
    --primary-color: #0ea5e9;
    --primary-dark: #0284c7;
    --primary-light: #7dd3fc;
    --secondary-color: #64748b;
    --success-color: #22c55e;
    --warning-color: #f59e0b;
    --background: #f0f9ff;
    --surface: #ffffff;
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    --border-color: #e2e8f0;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-full: 9999px;
}

/* Reset & Base */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: var(--background);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
}

/* App Container */
.app-container {
    max-width: 600px;
    margin: 0 auto;
    padding: 20px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
.app-header {
    text-align: center;
    padding: 20px 0 30px;
}

.logo-container {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
}

.logo {
    width: 48px;
    height: 48px;
    object-fit: contain;
}

.app-header h1 {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--primary-color);
}

.tagline {
    color: var(--text-secondary);
    margin-top: 8px;
    font-size: 1rem;
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* Card Component */
.card {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: var(--shadow-md);
}

.card h2 {
    font-size: 1.125rem;
    font-weight: 600;
    margin-bottom: 16px;
    color: var(--text-primary);
}

.section-description {
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin-top: -8px;
    margin-bottom: 16px;
}

/* Goal Section */
.goal-display {
    text-align: center;
    margin-bottom: 20px;
}

.goal-value {
    font-size: 4rem;
    font-weight: 700;
    color: var(--primary-color);
    line-height: 1;
}

.goal-unit {
    font-size: 1.25rem;
    color: var(--text-secondary);
    margin-left: 8px;
}

.goal-controls {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 12px;
}

.goal-info {
    text-align: center;
    font-size: 0.875rem;
    color: var(--text-muted);
}

/* Buttons */
.btn {
    background: var(--surface);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 10px 20px;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.btn:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
}

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

.btn-primary {
    background: var(--primary-color);
    border-color: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-dark);
    border-color: var(--primary-dark);
    color: white;
}

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

.btn-round {
    width: 44px;
    height: 44px;
    border-radius: var(--radius-full);
    padding: 0;
    font-size: 1.5rem;
    flex-shrink: 0;
}

.btn-small {
    padding: 6px 12px;
    font-size: 0.875rem;
    border-radius: var(--radius-sm);
}

.btn-large {
    padding: 14px 28px;
    font-size: 1.125rem;
}

/* Slider */
.slider {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 8px;
    background: var(--border-color);
    border-radius: var(--radius-full);
    outline: none;
    cursor: pointer;
}

.slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 24px;
    height: 24px;
    background: var(--primary-color);
    border-radius: var(--radius-full);
    cursor: pointer;
    box-shadow: var(--shadow-md);
    transition: transform 0.2s ease;
}

.slider::-webkit-slider-thumb:hover {
    transform: scale(1.1);
}

.slider::-moz-range-thumb {
    width: 24px;
    height: 24px;
    background: var(--primary-color);
    border-radius: var(--radius-full);
    cursor: pointer;
    border: none;
    box-shadow: var(--shadow-md);
}

/* Activity Section */
.activity-options {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    margin-bottom: 16px;
}

.activity-btn {
    background: var(--surface);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 16px 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: center;
}

.activity-btn:hover {
    border-color: var(--primary-light);
    background: var(--background);
}

.activity-btn.active {
    border-color: var(--primary-color);
    background: linear-gradient(135deg, rgba(14, 165, 233, 0.1), rgba(14, 165, 233, 0.05));
}

.activity-icon {
    font-size: 2rem;
    display: block;
    margin-bottom: 8px;
}

.activity-label {
    font-weight: 600;
    display: block;
    color: var(--text-primary);
    font-size: 0.9rem;
}

.activity-desc {
    font-size: 0.75rem;
    color: var(--text-muted);
    display: block;
    margin-top: 4px;
}

.adjusted-goal {
    text-align: center;
    padding: 12px;
    background: var(--background);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
}

.adjusted-goal strong {
    color: var(--primary-color);
    font-size: 1.25rem;
}

/* Reminder Section */
.frequency-display {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.frequency-value {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--background);
    padding: 8px 12px;
    border-radius: var(--radius-md);
}

#frequencyValue {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary-color);
    min-width: 50px;
    text-align: center;
}

.time-range {
    display: flex;
    gap: 16px;
    margin-bottom: 16px;
}

.time-input {
    flex: 1;
}

.time-input label {
    display: block;
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.time-input input {
    width: 100%;
    padding: 10px 12px;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 1rem;
    background: var(--surface);
}

.time-input input:focus {
    outline: none;
    border-color: var(--primary-color);
}

/* Toggle Switch */
.toggle-label {
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
}

.toggle-label input {
    display: none;
}

.toggle-switch {
    width: 52px;
    height: 28px;
    background: var(--border-color);
    border-radius: var(--radius-full);
    position: relative;
    transition: background 0.3s ease;
}

.toggle-switch::after {
    content: '';
    position: absolute;
    width: 22px;
    height: 22px;
    background: white;
    border-radius: var(--radius-full);
    top: 3px;
    left: 3px;
    transition: transform 0.3s ease;
    box-shadow: var(--shadow-sm);
}

.toggle-label input:checked + .toggle-switch {
    background: var(--primary-color);
}

.toggle-label input:checked + .toggle-switch::after {
    transform: translateX(24px);
}

/* Sound Section */
.sound-options {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    margin-bottom: 16px;
}

.sound-option {
    cursor: pointer;
}

.sound-option input {
    display: none;
}

.sound-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 16px;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    transition: all 0.2s ease;
}

.sound-option input:checked + .sound-card {
    border-color: var(--primary-color);
    background: linear-gradient(135deg, rgba(14, 165, 233, 0.1), rgba(14, 165, 233, 0.05));
}

.sound-icon {
    font-size: 2rem;
    margin-bottom: 8px;
}

.sound-name {
    font-size: 0.875rem;
    font-weight: 500;
}

#testSound {
    width: 100%;
    margin-bottom: 16px;
}

.volume-control {
    display: flex;
    align-items: center;
    gap: 12px;
}

.volume-control label {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.volume-control .slider {
    flex: 1;
}

#volumeValue {
    font-size: 0.875rem;
    color: var(--text-secondary);
    min-width: 40px;
}

/* Progress Section */
.progress-circle-container {
    display: flex;
    justify-content: center;
    margin-bottom: 24px;
}

.progress-circle {
    position: relative;
    width: 180px;
    height: 180px;
}

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

.progress-bg {
    fill: none;
    stroke: var(--border-color);
    stroke-width: 8;
}

.progress-bar {
    fill: none;
    stroke: var(--primary-color);
    stroke-width: 8;
    stroke-linecap: round;
    stroke-dasharray: 283;
    stroke-dashoffset: 283;
    transition: stroke-dashoffset 0.5s ease;
}

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

.progress-current {
    font-size: 3rem;
    font-weight: 700;
    color: var(--primary-color);
    line-height: 1;
}

.progress-separator {
    font-size: 1.5rem;
    color: var(--text-muted);
    margin: 0 4px;
}

.progress-total {
    font-size: 1.5rem;
    color: var(--text-secondary);
}

.progress-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
    margin-bottom: 16px;
}

.quick-log {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 20px;
}

.quick-log span {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.streak-info {
    display: flex;
    justify-content: center;
    gap: 40px;
    padding-top: 16px;
    border-top: 1px solid var(--border-color);
}

.streak-item {
    text-align: center;
}

.streak-value {
    display: block;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary-color);
}

.streak-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* History Section */
.weekly-chart {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    height: 150px;
    padding: 16px 0;
    margin-bottom: 16px;
}

.chart-bar {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex: 1;
    gap: 8px;
}

.bar-container {
    width: 100%;
    max-width: 40px;
    height: 100px;
    background: var(--border-color);
    border-radius: var(--radius-sm);
    position: relative;
    overflow: hidden;
}

.bar-fill {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(to top, var(--primary-color), var(--primary-light));
    border-radius: var(--radius-sm);
    transition: height 0.3s ease;
}

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

.bar-value {
    font-size: 0.7rem;
    color: var(--text-muted);
}

#resetProgress {
    width: 100%;
}

/* Toast Notification */
.toast {
    position: fixed;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--surface);
    padding: 16px 24px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    gap: 12px;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    z-index: 1000;
    max-width: calc(100% - 40px);
}

.toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
    visibility: visible;
}

.toast-icon {
    font-size: 1.5rem;
}

.toast-message {
    flex: 1;
    font-weight: 500;
}

.toast-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0;
    line-height: 1;
}

/* Footer */
.app-footer {
    text-align: center;
    padding: 24px 0;
    margin-top: auto;
}

.app-footer p {
    font-size: 0.875rem;
    color: var(--text-muted);
}

.app-footer a {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 500;
}

.app-footer a:hover {
    text-decoration: underline;
}

/* Mobile Responsive */
@media (max-width: 480px) {
    .app-container {
        padding: 16px;
    }

    .card {
        padding: 20px;
    }

    .app-header h1 {
        font-size: 1.5rem;
    }

    .goal-value {
        font-size: 3rem;
    }

    .activity-options {
        grid-template-columns: 1fr;
    }

    .sound-options {
        grid-template-columns: 1fr;
    }

    .progress-circle {
        width: 150px;
        height: 150px;
    }

    .progress-current {
        font-size: 2.5rem;
    }

    .progress-actions {
        flex-direction: column;
    }

    .progress-actions .btn {
        width: 100%;
    }

    .time-range {
        flex-direction: column;
        gap: 12px;
    }

    .streak-info {
        gap: 24px;
    }

    .frequency-display {
        flex-direction: column;
        gap: 8px;
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    :root {
        --background: #0f172a;
        --surface: #1e293b;
        --text-primary: #f1f5f9;
        --text-secondary: #94a3b8;
        --text-muted: #64748b;
        --border-color: #334155;
    }

    .slider {
        background: var(--border-color);
    }

    .time-input input {
        background: var(--background);
        color: var(--text-primary);
    }
}

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

.btn-primary:focus {
    animation: pulse 0.3s ease;
}

/* Goal achieved celebration */
.goal-achieved .progress-bar {
    stroke: var(--success-color);
}

.goal-achieved .progress-current {
    color: var(--success-color);
}
