:root {
    --bg-color: #0d1117;
    --surface-color: #161b22;
    --surface-hover: #21262d;
    --surface-border: rgba(255, 255, 255, 0.1);
    --text-primary: #ffffff;
    --text-secondary: #8b949e;
    --text-muted: #6e7681;
    
    --primary-color: #3b82f6;
    --primary-gradient: linear-gradient(135deg, #3b82f6 0%, #8b5cf6 100%);
    --danger-color: #ef4444;
    --danger-hover: #dc2626;
    --success-color: #10b981;
    --trend-improving: #3b82f6;
    --trend-stable: #10b981;
    --trend-declining: #ef4444;
    
    --ring-bg: #21262d;
    
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 20px;
    --radius-full: 9999px;
    
    --shadow-sm: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 10px 15px -3px rgba(0, 0, 0, 0.2), 0 4px 6px -2px rgba(0, 0, 0, 0.1);
    --shadow-glow: 0 0 20px rgba(139, 92, 246, 0.3);
    
    --font-heading: 'Inter', sans-serif;
    --font-body: 'Inter', sans-serif;
}

/* Bright Theme for Stable Recovery */
.bright-theme {
    --bg-color: #f8fafc;
    --surface-color: #ffffff;
    --surface-hover: #f1f5f9;
    --surface-border: rgba(0, 0, 0, 0.1);
    --text-primary: #1e293b;
    --text-secondary: #475569;
    --text-muted: #64748b;
    
    --primary-color: #06b6d4;
    --primary-gradient: linear-gradient(135deg, #06b6d4 0%, #10b981 100%);
    --danger-color: #ef4444;
    --danger-hover: #dc2626;
    --success-color: #10b981;
    --trend-improving: #06b6d4; /* Cyan */
    --trend-stable: #10b981; /* Green */
    --trend-declining: #ef4444; /* Red */
    
    --ring-bg: #e2e8f0;
    
    --shadow-sm: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --shadow-glow: 0 0 20px rgba(6, 182, 212, 0.3);
}

.bright-theme .modal {
    background: rgba(0, 0, 0, 0.5);
}

.bright-theme .toast {
    background: var(--surface-color);
    border: 1px solid var(--surface-border);
}

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

html {
    height: 100%;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior-y: auto;
}

body {
    background-color: var(--bg-color);
    color: var(--text-primary);
    font-family: var(--font-body);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    height: 100%;
    min-height: 100%;
    margin: 0;
    padding: 0;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior-y: auto;
}

.material-symbols-rounded {
  font-variation-settings:
  'FILL' 0,
  'wght' 500,
  'GRAD' 0,
  'opsz' 24
}

.app-container {
    width: min(100%, 600px);
    max-width: 600px;
    margin: 0 auto;
    min-height: 100vh;
    min-height: 100svh;
    display: flex;
    flex-direction: column;
    padding: calc(20px + env(safe-area-inset-top, 0px)) 20px calc(20px + env(safe-area-inset-bottom, 0px));
    box-sizing: border-box;
    overflow: visible;
}

/* Header */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    min-height: 56px;
    padding: 10px 0 30px;
}

.title-group {
    display: flex;
    align-items: center;
    gap: 12px;
}

h1 {
    font-family: var(--font-heading);
    font-size: 1.5rem;
    font-weight: 800;
    line-height: 1.2;
    letter-spacing: -0.5px;
    background: var(--primary-gradient);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.version-badge {
    font-size: 0.75rem;
    background: var(--surface-color);
    padding: 2px 8px;
    border-radius: var(--radius-full);
    color: var(--text-secondary);
    border: 1px solid var(--surface-border);
}

.icon-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 8px;
    border-radius: var(--radius-full);
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.icon-btn:hover {
    background-color: var(--surface-hover);
    color: var(--text-primary);
}

/* Main Content */
main {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding-top: clamp(20px, 4svh, 32px);
    gap: 30px;
}

.stats-card {
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    width: 100%;
    gap: 12px;
    flex-shrink: 0;
}

.progress-ring-container {
    position: relative;
    width: 280px;
    height: 280px;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-shrink: 0;
    overflow: hidden;
}

.progress-ring {
    transform: rotate(-90deg);
    position: absolute;
    top: 0;
    left: 0;
}

.progress-ring__bg {
    stroke: var(--ring-bg);
}

.progress-ring__circle {
    transition: stroke-dashoffset 1s ease-in-out;
    stroke-width: 16;
}

.stats-center {
    position: absolute;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    z-index: 20;
    pointer-events: none;
}

.main-stat {
    font-size: 4rem;
    font-weight: 900;
    line-height: 1;
    letter-spacing: -2px;
    margin-bottom: 4px;
    text-shadow: 0 2px 8px rgba(0,0,0,0.4);
}

.sub-stat {
    font-size: 1rem;
    color: var(--text-primary);
    font-weight: 600;
    text-shadow: 0 1px 4px rgba(0,0,0,0.4);
}

.message-container {
    text-align: center;
    padding: 0 20px;
}

.status-message {
    font-size: 1.1rem;
    color: var(--text-secondary);
}

.highlight {
    color: var(--text-primary);
    font-weight: 600;
}

.actions {
    width: 100%;
    margin-top: 20px;
}

.app-objective {
    text-align: left;
    padding: 20px;
    margin-top: -1px;
    width: 100%;
    max-width: none;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    max-height: 500px;
    opacity: 1;
    background: var(--surface-color);
    border: 1px solid var(--surface-border);
    border-top: none;
    border-bottom-left-radius: var(--radius-lg);
    border-bottom-right-radius: var(--radius-lg);
}

.app-objective.hidden {
    max-height: 0;
    margin-top: 0;
    padding: 0 20px;
    opacity: 0;
    pointer-events: none;
    overflow: hidden;
    border: 1px solid transparent;
}

.how-it-works-container {
    width: 100%;
    display: flex;
    flex-direction: column;
}

.how-it-works-container.expanded #how-it-works-btn {
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
}

.how-it-works-container #how-it-works-btn {
    z-index: 1;
}

.app-objective p {
    font-size: 0.85rem;
    color: var(--text-secondary);
    line-height: 1.6;
    opacity: 0.9;
}

.app-objective strong {
    color: var(--text-primary);
    display: block;
    margin-bottom: 4px;
    font-size: 0.95rem;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px;
    border-radius: var(--radius-lg);
    font-family: var(--font-heading);
    font-weight: 600;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border: none;
    width: auto;
}

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

.btn-large {
    width: 100%;
    padding: 18px 24px;
    font-size: 1.1rem;
    box-shadow: var(--shadow-md);
}

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

.btn-primary:hover {
    filter: brightness(1.1);
    box-shadow: 0 0 30px rgba(139, 92, 246, 0.5);
}

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

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

.btn-danger {
    background: transparent;
    color: var(--danger-color);
    border: 1px solid var(--danger-color);
}

.btn-danger:hover {
    background: var(--danger-color);
    color: white;
}

.btn-block {
    width: 100%;
}

/* Trend Explanation */
.trend-explanation {
    margin: 20px 0;
}

.trend-item {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    margin: 16px 0;
    padding: 16px;
    background: var(--surface-color);
    border-radius: var(--radius-md);
    border: 1px solid var(--surface-border);
}

.trend-item .trend-arrow {
    font-size: 1.5rem;
    flex-shrink: 0;
    margin-top: 2px;
}

.trend-item strong {
    color: var(--text-primary);
    margin-bottom: 4px;
    display: block;
}

.trend-item p {
    color: var(--text-secondary);
    margin: 0;
    font-size: 0.9rem;
    line-height: 1.4;
}

.mt-lg {
    margin-top: 24px;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    opacity: 1;
    transition: opacity 0.3s ease;
}

.modal.hidden {
    opacity: 0;
    pointer-events: none;
}

.modal-content {
    background: var(--surface-color);
    width: 90%;
    max-width: 400px;
    border-radius: var(--radius-lg);
    border: 1px solid var(--surface-border);
    box-shadow: var(--shadow-md);
    display: flex;
    flex-direction: column;
    max-height: 90vh;
    transform: translateY(0);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.modal.hidden .modal-content {
    transform: translateY(20px);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    border-bottom: 1px solid var(--surface-border);
}

.modal-header h2 {
    font-size: 1.25rem;
    font-weight: 700;
}

.modal-body {
    padding: 20px;
    overflow-y: auto;
}

.modal-footer {
    padding: 20px;
    border-top: 1px solid var(--surface-border);
}

/* Forms */
.form-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.mt-xl {
    margin-top: 32px;
}

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

.hint {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.form-control {
    background: var(--bg-color);
    border: 1px solid var(--surface-border);
    color: var(--text-primary);
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 1rem;
    transition: border-color 0.2s;
    outline: none;
}

.form-control:focus {
    border-color: var(--primary-color);
}

/* Date input specific styles for better dark mode support */
input[type="date"]::-webkit-calendar-picker-indicator {
    cursor: pointer;
    filter: invert(0.5);
}

input[type="date"]:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

input[type="date"]::-webkit-datetime-edit-text {
    color: var(--text-primary);
}

input[type="date"]::-webkit-datetime-edit-month-field {
    color: var(--text-primary);
}

input[type="date"]::-webkit-datetime-edit-day-field {
    color: var(--text-primary);
}

input[type="date"]::-webkit-datetime-edit-year-field {
    color: var(--text-primary);
}

.add-lapse-group {
    display: flex;
    gap: 8px;
}

.add-lapse-group .form-control {
    flex: 1;
}

/* Lapses List */
.lapses-list {
    list-style: none;
    margin-top: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 200px;
    overflow-y: auto;
}

/* Styling scrollbars for webkit */
.lapses-list::-webkit-scrollbar {
    width: 6px;
}
.lapses-list::-webkit-scrollbar-track {
    background: transparent;
}
.lapses-list::-webkit-scrollbar-thumb {
    background-color: var(--surface-hover);
    border-radius: var(--radius-full);
}

.lapse-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg-color);
    padding: 10px 16px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--surface-border);
    font-size: 0.95rem;
}

.lapse-date {
    font-variant-numeric: tabular-nums;
}

.btn-remove {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    padding: 4px;
    border-radius: var(--radius-sm);
    transition: all 0.2s;
}

.btn-remove:hover {
    color: var(--danger-color);
    background: rgba(239, 68, 68, 0.1);
}

/* Toast */
.toast {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%) translateY(200px);
    background: var(--surface-hover);
    color: var(--text-primary);
    padding: 12px 24px;
    border-radius: var(--radius-full);
    font-weight: 500;
    box-shadow: var(--shadow-md);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    z-index: 1000;
    pointer-events: none;
    border: 1px solid var(--surface-border);
    visibility: hidden;
}

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

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

@keyframes celebrate {
    0% { transform: scale(1) rotate(0deg); }
    25% { transform: scale(1.02) rotate(1deg); }
    50% { transform: scale(1.05) rotate(-1deg); }
    75% { transform: scale(1.02) rotate(1deg); }
    100% { transform: scale(1) rotate(0deg); }
}

@keyframes gradient-slide {
    0% { background-position: 100% 0; }
    100% { background-position: 0% 0; }
}
