/* --- Design Tokens --- */
:root {
    /* Dark Theme (Default) */
    --bg-main: #09090b;
    --bg-secondary: #18181b;
    --glass-bg: rgba(24, 24, 27, 0.7);
    --glass-border: rgba(255, 255, 255, 0.1);
    --text-primary: #ffffff;
    --text-secondary: #a1a1aa;
    --accent-primary: #8b5cf6; /* Purple */
    --accent-secondary: #06b6d4; /* Cyan */
    --accent-gradient: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    --square-empty: rgba(255, 255, 255, 0.1);
    --square-filled: #ffffff;
    --square-border: #3f3f46;
    --line-color: #f59e0b; /* Orange for visibility on dark */

    /* Sizing */
    --box-size: 8px; /* Slightly smaller for better fit on standard screens */
    --gap-size: 3px;
    --radius-md: 12px;
    --radius-lg: 24px;
}

body.light-mode {
    --bg-main: #ffffff;
    --bg-secondary: #f4f4f5;
    --glass-bg: rgba(255, 255, 255, 0.8);
    --glass-border: rgba(0, 0, 0, 0.08);
    --text-primary: #09090b;
    --text-secondary: #52525b;
    --square-empty: rgba(0, 0, 0, 0.05);
    --square-filled: #09090b;
    --square-border: #e4e4e7;
    --line-color: #ef4444; /* Red for light mode */
}

body.light-mode .background-overlay {
    background: radial-gradient(circle at 15% 15%, rgba(139, 92, 246, 0.05), transparent 40%),
                radial-gradient(circle at 85% 85%, rgba(6, 182, 212, 0.05), transparent 40%),
                #ffffff;
}

body.light-mode .floating-shapes {
    opacity: 0.3;
    filter: saturate(0.5);
}

/* --- Global Reset --- */
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-main) !important;
    color: var(--text-primary);
    min-height: 100vh;
    padding: 2rem 1rem;
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* --- Background Effects --- */
.background-overlay {
    position: fixed; inset: 0; z-index: -2;
    background: radial-gradient(circle at 15% 15%, rgba(139, 92, 246, 0.15), transparent 40%),
                radial-gradient(circle at 85% 85%, rgba(6, 182, 212, 0.15), transparent 40%);
}

/* --- Layout Container --- */
.app-container {
    max-width: 1300px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

/* --- Glass Card Standard --- */
.glass-card {
    background: var(--glass-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg);
    padding: 2rem;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
}

/* --- Typography & Inputs --- */
h1 {
    font-weight: 800;
    font-size: 2.5rem;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 0.5rem;
}
h2 { font-size: 1.25rem; margin-bottom: 1rem; font-weight: 600; }
p, li, label { color: var(--text-secondary); font-size: 0.95rem; line-height: 1.5; }

/* --- Specific Card Styles --- */
.hero-card { text-align: center; padding: 3rem 1rem; }

/* --- THE GRID --- */
.grid-layout {
    display: flex;
    gap: 1rem;
}

.week-markers {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    flex-shrink: 0;
}
.week-title {
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--text-secondary);
    /* **FIX**: This height + margin matches the space taken by the age labels */
    height: 1.1rem; /* Approx height of age labels */
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center; /* Center vertically in its own space */
}
/* **FIX**: This whole block is updated for alignment */
.week-label {
    height: var(--box-size); /* Set height to ONLY the box height */
    margin-bottom: var(--gap-size); /* Use margin for the gap */
    font-size: 0.6rem;
    color: var(--text-secondary);
    opacity: 0.7;
    display: flex; /* Use flexbox to center the text */
    align-items: center; /* This now perfectly centers text in the 8px box height */
}


.grid-scroll-area {
    flex-grow: 1;
    overflow-x: auto; /* Horizontal scroll for small screens */
    padding-bottom: 1rem;
}

#age-labels {
    display: grid;
    grid-template-rows: auto;
    /* columns set in JS */
    gap: var(--gap-size);
    margin-bottom: 0.5rem;
    height: 1.1rem; /* Give it an explicit height */
}
.age-label {
    font-size: 0.6rem;
    text-align: center;
    color: var(--text-secondary);
    width: var(--box-size);
}

#life-grid-container {
    position: relative; /* Anchor for the red line */
    display: inline-block; /* Shrink to fit grid content */
}

#life-grid {
    display: grid;
    grid-auto-flow: column;
    grid-template-rows: repeat(52, var(--box-size));
    gap: var(--gap-size);
}

.square {
    width: var(--box-size);
    height: var(--box-size);
    background-color: var(--square-empty);
    border: 1px solid var(--square-border);
    border-radius: 2px;
}
.square.filled {
    background-color: var(--square-filled);
    border-color: var(--square-filled);
}

.week-line {
    position: absolute;
    left: 0;
    width: 100%;
    height: 2px;
    pointer-events: none;
    opacity: 0.6;
    z-index: 2;
    transition: top 0.5s ease, background-color 0.3s ease;
}
.week-line.active {
    opacity: 1;
    height: 2px;
    z-index: 3;
}

/* --- Footer Stats & Settings --- */
.settings-stats-card {
    display: grid;
    grid-template-columns: 1.2fr 1fr;
    gap: 2rem;
}

.people-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-bottom: 2rem;
    min-height: 40px;
}

.person-tag {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: var(--bg-secondary);
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--glass-border);
    font-size: 0.85rem;
    animation: fadeIn 0.3s ease;
}

.person-color-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
}

.person-actions {
    display: flex;
    gap: 0.25rem;
    margin-left: 0.5rem;
}

.edit-person, .remove-person {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 1rem;
    line-height: 1;
    padding: 2px;
    transition: color 0.2s;
}
.edit-person:hover { color: var(--accent-primary); }
.remove-person:hover { color: #ef4444; }

.add-person-form {
    background: rgba(255, 255, 255, 0.03);
    padding: 1.5rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--glass-border);
    transition: border-color 0.3s ease;
}
.add-person-form.editing {
    border-color: var(--accent-primary);
    box-shadow: 0 0 15px rgba(139, 92, 246, 0.1);
}

.add-person-form h3 {
    font-size: 1rem;
    margin-bottom: 1rem;
    color: var(--text-primary);
}

.input-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-bottom: 1.25rem;
}

.input-wrap { display: flex; flex-direction: column; gap: 0.5rem; }

input {
    width: 100%;
    padding: 0.6rem 0.75rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--glass-border);
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.9rem;
}
input[type="color"] {
    height: 38px;
    padding: 2px;
    cursor: pointer;
}
input:focus { outline: 2px solid var(--accent-primary); }

.button-group {
    display: flex;
    gap: 0.75rem;
}

.primary-button, .secondary-button, #theme-toggle {
    width: 100%;
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: var(--radius-md);
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s ease, opacity 0.2s ease, background 0.2s;
}
.primary-button {
    background: var(--accent-gradient);
    color: white;
}
.primary-button:hover { opacity: 0.9; transform: translateY(-2px); }

.secondary-button {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--glass-border);
}
.secondary-button:hover { background: rgba(255, 255, 255, 0.05); }

.stats-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}
.stats-header h2 { margin-bottom: 0; }

#stats-person-select {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-md);
    padding: 0.4rem 0.75rem;
    font-family: inherit;
    font-size: 0.85rem;
    cursor: pointer;
}

.stats-group ul { list-style: none; display: flex; flex-direction: column; gap: 0.75rem; }
.stats-group li {
    background: var(--bg-secondary);
    padding: 0.75rem 1rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--glass-border);
    font-weight: 500;
}
.stats-group li.primary-stat {
    font-size: 1.1rem;
    font-weight: 700;
    border-color: var(--accent-primary);
    background: rgba(139, 92, 246, 0.05);
}

.theme-toggle-wrapper {
    grid-column: 1 / -1;
    display: flex;
    justify-content: center;
    margin-top: 1rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--glass-border);
}
#theme-toggle { 
    max-width: 300px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--glass-border);
}

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

/* --- Mobile Responsiveness --- */
@media (max-width: 768px) {
    .settings-stats-card { grid-template-columns: 1fr; gap: 2rem; }
    .hero-card h1 { font-size: 2rem; }
    .input-grid { grid-template-columns: 1fr; }
    .glass-card { padding: 1.5rem; }
}