/* ===== CSS Variables & Theme ===== */
:root {
    --bg-main: #faf5ee;
    --bg-card: #ffffff;
    --bg-card-hover: #fffdfb;
    --bg-modal: #ffffff;
    --bg-overlay: rgba(0, 0, 0, 0.45);
    
    --text-primary: #2d1b0e;
    --text-secondary: #6b5744;
    --text-muted: #9c8b7a;
    --text-inverse: #ffffff;
    
    --color-red: #c41e3a;
    --color-red-light: #e84057;
    --color-red-dark: #8b1528;
    --color-gold: #d4a017;
    --color-gold-light: #f0c040;
    --color-gold-dark: #a07b10;
    --color-green: #2d8a4e;
    --color-blue: #3478c6;
    --color-orange: #e67e22;
    
    --shadow-sm: 0 1px 3px rgba(45, 27, 14, 0.06);
    --shadow-md: 0 4px 12px rgba(45, 27, 14, 0.08);
    --shadow-lg: 0 8px 30px rgba(45, 27, 14, 0.12);
    --shadow-xl: 0 16px 48px rgba(45, 27, 14, 0.16);
    
    --radius-sm: 10px;
    --radius-md: 16px;
    --radius-lg: 24px;
    --radius-full: 50%;
    
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-serif: 'Playfair Display', Georgia, serif;
    
    --transition-fast: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-smooth: 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-spring: 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

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

html {
    font-size: 16px;
    scroll-behavior: smooth;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

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

/* ===== Loading Overlay ===== */
.loading-overlay {
    position: fixed;
    inset: 0;
    background: var(--bg-main);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.4s ease;
}

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

.loading-spinner {
    text-align: center;
}

.loading-spinner span {
    font-size: 2.5rem;
    display: inline-block;
    animation: spinFlower 1.2s ease-in-out infinite;
}

.loading-spinner p {
    margin-top: 12px;
    font-size: 0.9rem;
    color: var(--text-muted);
    font-weight: 500;
}

@keyframes spinFlower {
    0%, 100% { transform: rotate(0deg) scale(1); }
    50% { transform: rotate(180deg) scale(1.15); }
}

/* ===== Falling Petals ===== */
#petals-container {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    overflow: hidden;
}

.petal {
    position: absolute;
    top: -40px;
    opacity: 0;
    animation: petalFall linear forwards;
    pointer-events: none;
    font-size: 1rem;
}

@keyframes petalFall {
    0% { opacity: 0; transform: translateX(0) rotate(0deg) scale(0.8); }
    10% { opacity: 0.7; }
    90% { opacity: 0.4; }
    100% { opacity: 0; transform: translateX(var(--drift)) rotate(var(--rotation)) scale(0.5); top: 105vh; }
}

/* ===== AUTH PAGE ===== */
.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    position: relative;
    z-index: 1;
}

.auth-page[hidden] {
    display: none;
}

.auth-container {
    width: 100%;
    max-width: 420px;
    animation: authAppear 0.8s ease-out;
}

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

.auth-brand {
    text-align: center;
    margin-bottom: 32px;
}

.auth-flowers {
    font-size: 1.6rem;
    margin-bottom: 12px;
    letter-spacing: 8px;
    animation: floatFlower 3s ease-in-out infinite;
}

.auth-title {
    font-family: var(--font-serif);
    font-size: 2.6rem;
    font-weight: 900;
    font-style: italic;
    color: var(--color-red);
    line-height: 1.15;
    text-shadow: 0 2px 12px rgba(196, 30, 58, 0.12);
}

.auth-subtitle {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 6px;
    font-weight: 500;
}

.auth-card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 32px;
    box-shadow: var(--shadow-lg);
    border: 1px solid rgba(0, 0, 0, 0.04);
}

.auth-card[hidden] {
    display: none;
}

.auth-card-title {
    font-size: 1.2rem;
    font-weight: 700;
    margin-bottom: 20px;
    color: var(--text-primary);
}

.auth-error {
    color: var(--color-red);
    font-size: 0.82rem;
    font-weight: 500;
    margin-bottom: 8px;
    min-height: 20px;
    line-height: 1.4;
}

.auth-switch {
    text-align: center;
    margin-top: 20px;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.auth-switch a {
    color: var(--color-red);
    text-decoration: none;
    font-weight: 600;
    transition: var(--transition-fast);
}

.auth-switch a:hover {
    text-decoration: underline;
}

.btn-full {
    width: 100%;
    justify-content: center;
    padding: 12px 24px;
    font-size: 0.95rem;
}

.btn-loader {
    animation: pulse 1s ease-in-out infinite;
}

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

/* ===== App Container ===== */
.app-container {
    position: relative;
    z-index: 1;
    max-width: 960px;
    margin: 0 auto;
    padding: 20px 24px 40px;
}

.app-container[hidden] {
    display: none;
}

/* ===== Header ===== */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    flex-wrap: wrap;
    gap: 12px;
}

.date-badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: var(--bg-card);
    padding: 8px 18px;
    border-radius: 40px;
    font-size: 0.85rem;
    color: var(--text-secondary);
    box-shadow: var(--shadow-sm);
    border: 1px solid rgba(196, 30, 58, 0.08);
}

.date-icon { font-size: 1rem; }
.date-divider { color: var(--text-muted); opacity: 0.4; }

.user-profile {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--bg-card);
    padding: 6px 14px 6px 6px;
    border-radius: 40px;
    box-shadow: var(--shadow-sm);
    border: 1px solid rgba(196, 30, 58, 0.08);
    transition: var(--transition-fast);
}

.user-profile:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}

.user-avatar {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-full);
    background: linear-gradient(135deg, #ffecd2, #fcb69f);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
}

.user-name {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-primary);
    max-width: 140px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.btn-icon {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    border-radius: var(--radius-full);
    transition: var(--transition-fast);
    display: flex;
    align-items: center;
}

.btn-icon:hover {
    color: var(--color-red);
    background: rgba(196, 30, 58, 0.06);
}

/* ===== Hero ===== */
.hero {
    text-align: center;
    padding: 24px 0 32px;
}

.hero-title {
    font-family: var(--font-serif);
    font-size: clamp(2.4rem, 6vw, 3.8rem);
    font-weight: 900;
    font-style: italic;
    color: var(--color-red);
    line-height: 1.15;
    letter-spacing: -0.02em;
    text-shadow: 0 2px 12px rgba(196, 30, 58, 0.12);
    animation: titleAppear 1s ease-out;
}

.hero-subtitle {
    font-size: 0.8rem;
    font-weight: 600;
    letter-spacing: 0.2em;
    color: var(--text-muted);
    margin-top: 8px;
    text-transform: uppercase;
}

@keyframes titleAppear {
    from { opacity: 0; transform: translateY(16px) scale(0.96); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

/* ===== Section ===== */
.section { margin-bottom: 28px; }

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    flex-wrap: wrap;
    gap: 10px;
}

.section-title {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--color-red);
    display: flex;
    align-items: center;
    gap: 8px;
}

.section-icon { font-size: 1.2rem; }

.btn-edit {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 0.82rem;
    font-family: var(--font-sans);
    cursor: pointer;
    padding: 6px 12px;
    border-radius: 20px;
    transition: var(--transition-fast);
}

.btn-edit:hover {
    color: var(--color-red);
    background: rgba(196, 30, 58, 0.06);
}

/* ===== Goals Grid ===== */
.goals-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 16px;
}

.goal-card {
    background: var(--bg-card);
    border-radius: var(--radius-md);
    padding: 24px;
    box-shadow: var(--shadow-sm);
    border: 1px solid rgba(0, 0, 0, 0.04);
    display: flex;
    align-items: center;
    gap: 20px;
    transition: var(--transition-smooth);
    animation: cardAppear 0.6s ease-out backwards;
}

.goal-card:nth-child(1) { animation-delay: 0.1s; }
.goal-card:nth-child(2) { animation-delay: 0.2s; }
.goal-card:nth-child(3) { animation-delay: 0.3s; }
.goal-card:nth-child(4) { animation-delay: 0.4s; }

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

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

/* Progress Ring */
.progress-ring-container { position: relative; flex-shrink: 0; }
.progress-ring { transform: rotate(-90deg); }
.progress-ring-bg { fill: none; stroke: #f0ebe4; stroke-width: 5; }
.progress-ring-fill {
    fill: none;
    stroke-width: 5;
    stroke-linecap: round;
    transition: stroke-dashoffset 1.2s cubic-bezier(0.4, 0, 0.2, 1);
}
.progress-percent {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--text-secondary);
}

/* Goal Info */
.goal-info { flex: 1; min-width: 0; }
.goal-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--text-muted);
    margin-bottom: 6px;
}
.goal-label-icon { font-size: 1rem; }
.goal-value { font-size: 1.6rem; font-weight: 700; color: var(--text-primary); line-height: 1.2; }
.goal-value .goal-current { color: var(--color-red); }
.goal-value .goal-separator { color: var(--text-muted); font-weight: 400; font-size: 1rem; margin: 0 2px; }
.goal-value .goal-target { color: var(--text-muted); font-size: 1rem; font-weight: 500; }
.goal-unit { font-size: 0.8rem; color: var(--text-muted); font-weight: 400; margin-left: 4px; }

.goal-progress-bar { margin-top: 10px; height: 4px; border-radius: 4px; background: #f0ebe4; overflow: hidden; }
.goal-progress-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 1.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ===== Countdown ===== */
.countdown-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 16px;
}

.countdown-card {
    background: var(--bg-card);
    border-radius: var(--radius-md);
    padding: 28px;
    box-shadow: var(--shadow-sm);
    border: 1px solid rgba(0, 0, 0, 0.04);
    transition: var(--transition-smooth);
    animation: cardAppear 0.6s ease-out backwards;
    position: relative;
    overflow: hidden;
}
.countdown-card:nth-child(1) { animation-delay: 0.3s; }
.countdown-card:nth-child(2) { animation-delay: 0.45s; }
.countdown-card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }

.countdown-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 3px;
    border-radius: 3px 3px 0 0;
}
.countdown-card.solar::before { background: linear-gradient(90deg, var(--color-orange), var(--color-gold)); }
.countdown-card.lunar::before { background: linear-gradient(90deg, var(--color-red), var(--color-red-light)); }

.countdown-header { display: flex; align-items: flex-start; gap: 8px; margin-bottom: 20px; }
.countdown-emoji { font-size: 1.3rem; line-height: 1; }
.countdown-title { font-size: 1.1rem; font-weight: 700; color: var(--text-primary); line-height: 1.3; }
.countdown-date {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-top: 2px;
}

.countdown-body { display: flex; align-items: center; gap: 20px; }
.countdown-main { flex: 1; }
.countdown-remaining { margin-bottom: 16px; }
.countdown-big { font-size: 1.5rem; font-weight: 700; line-height: 1.3; }
.countdown-big .num { font-size: 2.2rem; font-weight: 800; }
.countdown-card.solar .countdown-big { color: var(--color-orange); }
.countdown-card.lunar .countdown-big { color: var(--color-red); }
.countdown-days-total { font-size: 0.85rem; color: var(--text-muted); font-weight: 500; margin-top: 2px; }

.countdown-clock { display: flex; gap: 12px; align-items: flex-end; }
.clock-unit { text-align: center; }
.clock-value {
    font-size: 1.6rem;
    font-weight: 800;
    color: var(--text-primary);
    background: var(--bg-main);
    width: 48px; height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    position: relative;
    overflow: hidden;
}
.clock-value::after {
    content: '';
    position: absolute;
    top: 50%; left: 0; right: 0;
    height: 1px;
    background: rgba(0, 0, 0, 0.04);
}
.clock-label {
    font-size: 0.65rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-top: 4px;
}

/* Countdown Progress */
.countdown-progress { position: relative; flex-shrink: 0; }
.countdown-progress-ring { transform: rotate(-90deg); }
.countdown-progress-bg { fill: none; stroke: #f0ebe4; stroke-width: 6; }
.countdown-progress-fill {
    fill: none;
    stroke-width: 6;
    stroke-linecap: round;
    transition: stroke-dashoffset 1.2s cubic-bezier(0.4, 0, 0.2, 1);
}
.countdown-card.solar .countdown-progress-fill { stroke: var(--color-gold); }
.countdown-card.lunar .countdown-progress-fill { stroke: var(--color-red); }

.countdown-progress-text {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}
.countdown-progress-percent { font-size: 1.1rem; font-weight: 800; color: var(--text-primary); }
.countdown-progress-label { font-size: 0.55rem; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }
.countdown-progress-sub { font-size: 0.6rem; color: var(--text-muted); margin-top: 2px; }

/* ===== Footer ===== */
.footer { text-align: center; padding: 28px 0 12px; }

.footer-flowers {
    display: flex;
    justify-content: center;
    gap: 16px;
    margin-bottom: 12px;
    font-size: 1.4rem;
    animation: floatFlower 3s ease-in-out infinite;
}
.footer-flowers span:nth-child(2) { animation-delay: 0.5s; }
.footer-flowers span:nth-child(3) { animation-delay: 1s; }

@keyframes floatFlower {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-6px); }
}

.footer-quote {
    font-family: var(--font-serif);
    font-style: italic;
    font-size: 1.05rem;
    color: var(--text-secondary);
}

/* ===== Modal ===== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: var(--bg-overlay);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: var(--transition-smooth);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    padding: 20px;
}
.modal-overlay.active { opacity: 1; visibility: visible; }

.modal {
    background: var(--bg-modal);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 520px;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: var(--shadow-xl);
    transform: translateY(20px) scale(0.96);
    transition: var(--transition-spring);
}
.modal-overlay.active .modal { transform: translateY(0) scale(1); }

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px 0;
}
.modal-header h3 { font-size: 1.15rem; font-weight: 700; }

.btn-close {
    width: 32px; height: 32px;
    border-radius: var(--radius-full);
    border: none;
    background: var(--bg-main);
    font-size: 1.3rem;
    color: var(--text-muted);
    cursor: pointer;
    transition: var(--transition-fast);
    display: flex;
    align-items: center;
    justify-content: center;
}
.btn-close:hover { color: var(--color-red); background: rgba(196, 30, 58, 0.08); }

.modal-body { padding: 20px 24px; }
.modal-footer { display: flex; justify-content: flex-end; gap: 10px; padding: 0 24px 20px; }

/* Settings Sections */
.settings-section { margin-bottom: 24px; }
.settings-section h4 {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--text-secondary);
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
}

.form-group { margin-bottom: 12px; }
.form-group label {
    display: block;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
.form-group input,
.form-group select {
    width: 100%;
    padding: 10px 14px;
    border: 1.5px solid rgba(0, 0, 0, 0.08);
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-family: var(--font-sans);
    color: var(--text-primary);
    background: var(--bg-main);
    transition: var(--transition-fast);
    outline: none;
}
.form-group input:focus,
.form-group select:focus {
    border-color: var(--color-red);
    box-shadow: 0 0 0 3px rgba(196, 30, 58, 0.1);
}
.form-group input::placeholder { color: var(--text-muted); }

/* Goal Settings */
.goal-setting-group {
    background: var(--bg-main);
    border-radius: var(--radius-sm);
    padding: 14px;
    margin-bottom: 10px;
    border: 1px solid rgba(0, 0, 0, 0.04);
}
.goal-setting-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}
.goal-setting-title { font-size: 0.82rem; font-weight: 700; color: var(--text-secondary); }
.btn-remove-goal {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1rem;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 4px;
    transition: var(--transition-fast);
}
.btn-remove-goal:hover { color: var(--color-red); background: rgba(196, 30, 58, 0.08); }
.goal-setting-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.goal-setting-row.full { grid-template-columns: 1fr; }

/* Buttons */
.btn-primary {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: linear-gradient(135deg, var(--color-red), var(--color-red-light));
    color: var(--text-inverse);
    border: none;
    padding: 10px 24px;
    border-radius: var(--radius-sm);
    font-size: 0.88rem;
    font-weight: 600;
    font-family: var(--font-sans);
    cursor: pointer;
    transition: var(--transition-fast);
}
.btn-primary:hover { opacity: 0.9; transform: translateY(-1px); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }

.btn-secondary {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--bg-main);
    color: var(--text-secondary);
    border: 1.5px solid rgba(0, 0, 0, 0.1);
    padding: 10px 20px;
    border-radius: var(--radius-sm);
    font-size: 0.88rem;
    font-weight: 600;
    font-family: var(--font-sans);
    cursor: pointer;
    transition: var(--transition-fast);
}
.btn-secondary:hover { background: #f0ebe4; }

.btn-add-goal {
    display: block;
    width: 100%;
    padding: 10px;
    border: 2px dashed rgba(0, 0, 0, 0.1);
    border-radius: var(--radius-sm);
    background: none;
    color: var(--text-muted);
    font-size: 0.85rem;
    font-weight: 600;
    font-family: var(--font-sans);
    cursor: pointer;
    transition: var(--transition-fast);
}
.btn-add-goal:hover { border-color: var(--color-red); color: var(--color-red); background: rgba(196, 30, 58, 0.03); }

/* Toast */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--text-primary);
    color: var(--text-inverse);
    padding: 12px 24px;
    border-radius: 40px;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.88rem;
    font-weight: 500;
    box-shadow: var(--shadow-lg);
    z-index: 2000;
    opacity: 0;
    transition: var(--transition-spring);
}
.toast.active { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ===== Responsive ===== */
@media (max-width: 720px) {
    .app-container { padding: 16px 16px 32px; }
    .header { flex-direction: column; align-items: center; }
    .goals-grid { grid-template-columns: 1fr; }
    .countdown-grid { grid-template-columns: 1fr; }
    .countdown-body { flex-direction: column-reverse; align-items: flex-start; }
    .countdown-progress { align-self: flex-end; }
    .hero-title { font-size: 2rem; }
    .goal-card { padding: 18px; }
    .countdown-card { padding: 22px; }
    .auth-title { font-size: 2rem; }
    .auth-card { padding: 24px; }
}

@media (max-width: 400px) {
    .countdown-clock { gap: 8px; }
    .clock-value { width: 40px; height: 40px; font-size: 1.3rem; }
    .date-badge { font-size: 0.78rem; padding: 6px 14px; }
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(0, 0, 0, 0.12); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(0, 0, 0, 0.2); }

::selection { background: rgba(196, 30, 58, 0.15); color: var(--color-red-dark); }
