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

:root {
    --teal-dark:  #8C5BAF;
    --teal-mid:   #B48FC0;
    --teal-light: #F4EEF8;
    --near-black: #271A35;
    --bg:         #FAF7FC;
    --surface:    #FFFFFF;
    --surface-2:  #F6F0FA;
    --border:     #E2D4EE;
    --text:       #271A35;
    --muted:      #B89EC8;
}

body {
    font-family: 'Inter', sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    position: relative;
}

/* ── LUXURY BACKGROUND LAYER ────────────────────────────── */
body::before {
    content: '';
    position: fixed; inset: 0;
    z-index: 9999; pointer-events: none;
    opacity: 0.05;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
    background-size: 200px 200px;
}

#bg-orb {
    position: fixed;
    top: -200px; right: -150px;
    width: 620px; height: 620px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(140,91,175,0.22) 0%, rgba(180,143,192,0.09) 42%, transparent 70%);
    pointer-events: none; z-index: 0;
    animation: orbBreath 9s ease-in-out infinite;
}

@keyframes orbBreath {
    0%, 100% { transform: scale(1);    opacity: 1;    }
    50%       { transform: scale(1.1); opacity: 0.70; }
}

/* ── PIN SCREEN ─────────────────────────────────────── */
#pin-screen {
    position: fixed; inset: 0;
    background: var(--bg);
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    z-index: 100; gap: 28px;
}
.pin-brand { font-size: 11px; font-weight: 700; letter-spacing: 0.18em; color: var(--teal-mid); text-transform: uppercase; }
.pin-title { font-size: 24px; font-weight: 800; color: var(--text); text-align: center; }
.pin-dots  { display: flex; gap: 14px; }
.pin-dot {
    width: 13px; height: 13px; border-radius: 50%;
    background: var(--border); border: 2px solid var(--border);
    transition: all 0.12s;
}
.pin-dot.filled { background: var(--teal-dark); border-color: var(--teal-dark); }
.pin-dot.error  { background: #D95555; border-color: #D95555; }
.pin-error { font-size: 13px; color: #D95555; height: 16px; text-align: center; }
.pin-numpad { display: grid; grid-template-columns: repeat(3, 70px); gap: 11px; }
.pin-btn {
    width: 70px; height: 70px; border-radius: 50%;
    border: 1.5px solid var(--border);
    background: var(--surface); color: var(--text);
    font-family: 'Inter', sans-serif; font-size: 20px; font-weight: 500;
    cursor: pointer; display: flex; align-items: center; justify-content: center;
    transition: all 0.1s;
}
.pin-btn:hover  { background: var(--surface-2); border-color: var(--teal-dark); }
.pin-btn:active { transform: scale(0.93); }
.pin-btn.del   { font-size: 17px; color: var(--muted); }
.pin-btn.ghost { background: transparent; border-color: transparent; cursor: default; pointer-events: none; }

/* ── MAIN APP ────────────────────────────────────────── */
#app { display: none; max-width: 460px; margin: 0 auto; padding: 28px 18px 64px; position: relative; z-index: 1; }

.app-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 30px; padding-bottom: 20px;
    border-bottom: 1px solid var(--border);
}
.header-left .brand { font-size: 10px; font-weight: 700; letter-spacing: 0.17em; color: var(--teal-mid); text-transform: uppercase; margin-bottom: 5px; }
.header-left .date-str { font-size: 21px; font-weight: 600; color: var(--text); font-family: 'Cormorant Garamond', Georgia, serif; font-style: italic; letter-spacing: 0.01em; }
.streak-pill {
    display: flex; flex-direction: column; align-items: center;
    background: rgba(255,255,255,0.80); border: 1px solid rgba(226,212,238,0.65);
    border-radius: 18px; padding: 11px 18px;
    box-shadow: 0 2px 8px rgba(140,91,175,0.08), inset 0 1px 0 rgba(255,255,255,0.9);
    backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.streak-pill .num   { font-size: 26px; font-weight: 800; color: var(--teal-dark); line-height: 1; }
.streak-pill .label { font-size: 9px; font-weight: 700; letter-spacing: 0.12em; color: var(--muted); text-transform: uppercase; margin-top: 3px; }

.sec-label { font-size: 10px; font-weight: 700; letter-spacing: 0.14em; color: var(--teal-mid); text-transform: uppercase; margin-bottom: 12px; }

/* Today card */
.today-card {
    background: rgba(255,255,255,0.82); border: 1px solid rgba(226,212,238,0.7);
    border-radius: 18px; padding: 6px 18px 18px; margin-bottom: 18px;
    box-shadow: 0 2px 12px rgba(140,91,175,0.08), inset 0 1px 0 rgba(255,255,255,0.9);
    backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
    transition: box-shadow 0.5s ease;
}

.today-card.all-done {
    border-color: rgba(180,143,192,0.55);
    box-shadow: 0 2px 12px rgba(140,91,175,0.10), inset 0 1px 0 rgba(255,255,255,0.9),
                0 0 0 1px rgba(140,91,175,0.32), 0 0 30px rgba(140,91,175,0.20);
    animation: cardGlow 2.8s ease-in-out infinite;
}
.habit-row {
    display: flex; align-items: center; gap: 14px;
    padding: 15px 0; border-bottom: 1px solid var(--border);
    cursor: pointer; transition: opacity 0.12s; user-select: none;
}
.habit-row:last-of-type { border-bottom: none; }
.habit-row:active { opacity: 0.65; }
.hbox {
    width: 24px; height: 24px; border-radius: 9px;
    border: 2px solid var(--border);
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0; transition: all 0.14s;
}
.hbox.on { background: var(--teal-dark); border-color: var(--teal-dark); }
.hbox svg { display: none; }
.hbox.on svg { display: block; }
.habit-row .hname { font-size: 15px; font-weight: 600; color: var(--text); margin-bottom: 2px; transition: color 0.14s; cursor: text; }
.habit-row .hname:hover { text-decoration: underline; text-decoration-style: dotted; text-decoration-color: var(--muted); }
.habit-row .hdesc { font-size: 12px; color: var(--muted); }
.habit-row.done .hname { color: var(--teal-dark); }
.hname-hint { font-size: 10px; color: var(--muted); margin-top: 1px; }
.hname-input {
    font-size: 15px; font-weight: 600; color: var(--text);
    font-family: 'Inter', sans-serif;
    background: transparent; border: none;
    border-bottom: 2px solid var(--teal-dark);
    outline: none; width: 100%; padding: 0; margin-bottom: 2px;
}

/* Score */
.score-wrap { border-top: 1px solid var(--border); padding: 18px 0 2px; }
.score-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.score-top .slabel { font-size: 15px; font-weight: 600; color: var(--text); }
.score-top .sval   { font-size: 24px; font-weight: 800; color: var(--teal-dark); }
.score-display { display: flex; align-items: center; gap: 8px; }
.score-emoji   { font-size: 22px; line-height: 1; }
.score-denom   { font-size: 14px; font-weight: 500; color: var(--muted); }
input[type="range"] {
    width: 100%; -webkit-appearance: none; appearance: none;
    height: 5px; border-radius: 3px; outline: none; cursor: pointer;
    background: linear-gradient(to right,
        var(--teal-dark) 0%,
        var(--teal-mid) var(--fill, 66.7%),
        var(--border)   var(--fill, 66.7%),
        var(--border)   100%);
}
input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none; width: 22px; height: 22px; border-radius: 50%;
    background: var(--teal-dark); cursor: pointer;
    box-shadow: 0 0 0 5px rgba(140,91,175,0.12);
}
input[type="range"]::-moz-range-thumb {
    width: 22px; height: 22px; border-radius: 50%;
    background: var(--teal-dark); cursor: pointer; border: none;
}


/* Save button */
.save-btn {
    width: 100%; padding: 15px;
    background: var(--teal-dark); color: #fff;
    border: none; border-radius: 50px;
    font-family: 'Inter', sans-serif; font-size: 15px; font-weight: 700;
    cursor: pointer; margin-top: 16px;
    transition: all 0.14s; letter-spacing: 0.02em;
    position: relative; overflow: hidden;
}

.save-btn::after {
    content: '';
    position: absolute; top: 0; left: -120%;
    width: 60%; height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.38), transparent);
    transform: skewX(-20deg);
    pointer-events: none;
}

.save-btn.shimmer-sweep::after {
    animation: saveSweep 0.6s ease-out forwards;
}
.save-btn:hover  { background: var(--teal-mid); }
.save-btn:active { transform: scale(0.98); }
.save-btn.saved  { background: var(--surface-2); color: var(--teal-dark); cursor: default; border: 1.5px solid var(--border); }
.save-btn:disabled { opacity: 0.6; cursor: default; }

/* Stats row */
.stats-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 18px; }
.stat-card { background: rgba(255,255,255,0.80); border: 1px solid rgba(226,212,238,0.65); border-radius: 16px; padding: 14px 10px; text-align: center; box-shadow: 0 1px 6px rgba(140,91,175,0.07), inset 0 1px 0 rgba(255,255,255,0.9); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); }
.stat-card .snum { font-size: 22px; font-weight: 800; color: var(--teal-dark); line-height: 1; margin-bottom: 5px; }
.stat-card .slbl { font-size: 9px; font-weight: 700; letter-spacing: 0.1em; color: var(--muted); text-transform: uppercase; }

/* Heatmap */
.heatmap-card { background: rgba(255,255,255,0.82); border: 1px solid rgba(226,212,238,0.7); border-radius: 18px; padding: 18px; box-shadow: 0 2px 12px rgba(140,91,175,0.08), inset 0 1px 0 rgba(255,255,255,0.9); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); }
.hm-day-headers { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; margin-bottom: 5px; }
.hm-day-header  { text-align: center; font-size: 9px; font-weight: 700; letter-spacing: 0.06em; color: var(--muted); text-transform: uppercase; }
.hm-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; }
.hm-cell { aspect-ratio: 1; border-radius: 4px; background: var(--border); transition: opacity 0.1s; }
.hm-cell.hm-filler { background: transparent; }
.hm-cell.partial { background: #DCCAEE; }
.hm-cell.full    { background: var(--teal-mid); }
.hm-cell.full.hi { background: var(--teal-dark); }
.hm-cell.today   { outline: 2px solid var(--teal-dark); outline-offset: 1px; }
.hm-legend { display: flex; align-items: center; gap: 8px; margin-top: 13px; font-size: 10px; color: var(--muted); }
.hm-legend-cells { display: flex; gap: 4px; }
.hm-legend-cell  { width: 11px; height: 11px; border-radius: 3px; }

/* View All button */
.view-all-btn {
    display: flex; align-items: center; justify-content: center; gap: 5px;
    margin-top: 13px; background: none; border: none;
    font-family: 'Inter', sans-serif; font-size: 11px; font-weight: 700;
    letter-spacing: 0.07em; color: var(--teal-dark); cursor: pointer;
    padding: 10px; width: 100%; border-radius: 10px;
    text-transform: uppercase; transition: background 0.12s;
}
.view-all-btn:hover { background: var(--surface-2); }

/* Status */
.status-msg { font-size: 12px; color: var(--muted); text-align: center; margin-top: 10px; min-height: 16px; }

/* Shimmer */
.shimmer { animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }

/* ── HISTORY OVERLAY ─────────────────────────────────── */
#hist-overlay {
    position: fixed; inset: 0;
    background: var(--bg); z-index: 200;
    display: none; overflow-y: auto;
}
.hist-inner { max-width: 460px; margin: 0 auto; padding: 28px 18px 64px; }
.hist-back {
    background: none; border: none; color: var(--teal-dark);
    font-family: 'Inter', sans-serif; font-size: 14px; font-weight: 600;
    cursor: pointer; padding: 0; margin-bottom: 26px;
    display: flex; align-items: center; gap: 5px;
}
.hist-back:hover { color: var(--teal-mid); }
.hist-brand { font-size: 10px; font-weight: 700; letter-spacing: 0.17em; color: var(--teal-mid); text-transform: uppercase; margin-bottom: 5px; }
.hist-title { font-size: 22px; font-weight: 800; color: var(--text); margin-bottom: 20px; }
.all-stats  { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 14px; }
.chart-card { background: rgba(255,255,255,0.82); border: 1px solid rgba(226,212,238,0.7); border-radius: 18px; padding: 18px; margin-bottom: 14px; box-shadow: 0 2px 12px rgba(140,91,175,0.08), inset 0 1px 0 rgba(255,255,255,0.9); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); }
.chart-lbl  { font-size: 10px; font-weight: 700; letter-spacing: 0.14em; color: var(--teal-mid); text-transform: uppercase; margin-bottom: 14px; }
.chart-loading { font-size: 13px; color: var(--muted); text-align: center; padding: 36px 0; }
.habit-bars { display: flex; flex-direction: column; gap: 13px; }
.hbar-row   { }
.hbar-top   { display: flex; justify-content: space-between; font-size: 12px; font-weight: 600; color: var(--text); margin-bottom: 5px; }
.hbar-top span { font-weight: 400; color: var(--muted); }
.hbar-track { height: 7px; background: var(--border); border-radius: 4px; overflow: hidden; }
.hbar-fill  { height: 100%; background: var(--teal-dark); border-radius: 4px; transition: width 0.5s ease; }

/* ── EDIT LOG ────────────────────────────────────────── */
.el-month-group { margin-bottom: 2px; }

.el-month-row {
    display: flex; align-items: center; justify-content: space-between;
    padding: 13px 0; border-bottom: 1px solid var(--border);
    cursor: pointer; user-select: none; transition: color 0.12s;
}
.el-month-row:hover .el-row-label { color: var(--teal-dark); }

.el-week-row {
    display: flex; align-items: center; justify-content: space-between;
    padding: 11px 0 11px 14px; border-bottom: 1px solid var(--border);
    cursor: pointer; user-select: none; transition: background 0.1s;
}
.el-week-row:hover { background: var(--surface-2); }

.el-day-row {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 0 10px 28px; border-bottom: 1px solid var(--border);
    cursor: pointer; user-select: none; transition: background 0.1s;
}
.el-day-row:hover { background: var(--teal-light); }

.el-row-label { font-size: 14px; font-weight: 600; color: var(--text); transition: color 0.12s; }
.el-row-meta  { font-size: 11px; color: var(--muted); display: flex; align-items: center; gap: 7px; }
.el-day-label { font-size: 13px; font-weight: 500; color: var(--text); flex: 1; }

.el-chevron {
    display: inline-block; font-size: 13px; color: var(--muted);
    transition: transform 0.18s ease; line-height: 1;
}

.el-status-dot {
    width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; transition: background 0.2s;
}
.el-status-empty   { background: var(--border); }
.el-status-partial { background: #C9A8D8; }
.el-status-full    { background: var(--teal-dark); }

.el-day-form { overflow: hidden; }

.el-form-inner {
    padding: 14px 18px 18px 28px;
    background: var(--teal-light);
    border-bottom: 1px solid var(--border);
}

.el-habit-row {
    display: flex; align-items: center; gap: 12px;
    padding: 11px 0; border-bottom: 1px solid var(--border);
    cursor: pointer; user-select: none; transition: opacity 0.12s;
}
.el-habit-row:last-of-type { border-bottom: none; }
.el-habit-row:active { opacity: 0.65; }
.el-habit-row .hname { font-size: 14px; font-weight: 600; color: var(--text); transition: color 0.14s; }
.el-habit-row.done .hname { color: var(--teal-dark); }

.el-score-wrap { padding: 14px 0 8px; border-top: 1px solid var(--border); }
.el-score-top  { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.el-score-top .slabel { font-size: 13px; font-weight: 600; color: var(--text); }
.el-score-top .sval   { font-size: 20px; font-weight: 800; color: var(--teal-dark); }

/* ── ANIMATIONS ─────────────────────────────────────────── */
@keyframes fadeSlideUp {
    from { opacity: 0; transform: translateY(18px); }
    to   { opacity: 1; transform: translateY(0); }
}
@keyframes hboxPop {
    0%   { transform: scale(1); }
    35%  { transform: scale(1.38); }
    65%  { transform: scale(0.86); }
    100% { transform: scale(1); }
}
@keyframes floatUp {
    0%   { opacity: 1;   transform: translateY(0)     scale(1);   }
    70%  { opacity: 0.7; transform: translateY(-110px) scale(0.9); }
    100% { opacity: 0;   transform: translateY(-170px) scale(0.5); }
}

/* App reveal stagger — each direct child fades+slides up in sequence */
#app.animating > *:nth-child(1) { animation: fadeSlideUp 0.5s cubic-bezier(0.22,1,0.36,1) both; animation-delay:   0ms; }
#app.animating > *:nth-child(2) { animation: fadeSlideUp 0.5s cubic-bezier(0.22,1,0.36,1) both; animation-delay:  60ms; }
#app.animating > *:nth-child(3) { animation: fadeSlideUp 0.5s cubic-bezier(0.22,1,0.36,1) both; animation-delay: 120ms; }
#app.animating > *:nth-child(4) { animation: fadeSlideUp 0.5s cubic-bezier(0.22,1,0.36,1) both; animation-delay: 180ms; }
#app.animating > *:nth-child(5) { animation: fadeSlideUp 0.5s cubic-bezier(0.22,1,0.36,1) both; animation-delay: 240ms; }
#app.animating > *:nth-child(6) { animation: fadeSlideUp 0.5s cubic-bezier(0.22,1,0.36,1) both; animation-delay: 300ms; }
#app.animating > *:nth-child(7) { animation: fadeSlideUp 0.5s cubic-bezier(0.22,1,0.36,1) both; animation-delay: 360ms; }
#app.animating > *:nth-child(8) { animation: fadeSlideUp 0.5s cubic-bezier(0.22,1,0.36,1) both; animation-delay: 420ms; }

/* Checkbox spring pop */
.hbox-pop { animation: hboxPop 0.32s cubic-bezier(0.34,1.56,0.64,1) both; }

/* Checkbox glow pulse after spring pop */
.hbox-glow { animation: hboxGlow 0.55s ease-out both; }

@keyframes hboxGlow {
    0%   { box-shadow: 0 0 0 0    rgba(140,91,175,0);    }
    40%  { box-shadow: 0 0 0 8px  rgba(140,91,175,0.28); }
    100% { box-shadow: 0 0 0 13px rgba(140,91,175,0);    }
}

/* Card completion glow */
@keyframes cardGlow {
    0%, 100% { box-shadow: 0 2px 12px rgba(140,91,175,0.10), inset 0 1px 0 rgba(255,255,255,0.9), 0 0 0 1px rgba(140,91,175,0.32), 0 0 30px rgba(140,91,175,0.20); }
    50%       { box-shadow: 0 2px 12px rgba(140,91,175,0.10), inset 0 1px 0 rgba(255,255,255,0.9), 0 0 0 1px rgba(140,91,175,0.50), 0 0 48px rgba(140,91,175,0.38); }
}

/* Save button shimmer sweep */
@keyframes saveSweep {
    0%   { left: -120%; }
    100% { left: 160%;  }
}

/* Floating hearts/blossoms */
.heart-particle {
    position: fixed; pointer-events: none; z-index: 999;
    font-size: 22px; line-height: 1; user-select: none;
    animation: floatUp 1.5s ease-out forwards;
}

/* ── MILESTONE MODAL ──────────────────────────────────────── */
#milestone-modal {
    position: fixed; inset: 0; z-index: 400;
    background: rgba(39,26,53,0.5);
    display: none; align-items: center; justify-content: center;
    padding: 24px;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
}
#milestone-modal.open { display: flex; }
.milestone-card {
    background: rgba(255,255,255,0.90); border-radius: 26px;
    padding: 40px 28px 30px; text-align: center;
    max-width: 320px; width: 100%;
    box-shadow: 0 12px 40px rgba(140,91,175,0.28), inset 0 1px 0 rgba(255,255,255,0.95);
    backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
    animation: fadeSlideUp 0.4s cubic-bezier(0.22,1,0.36,1) both;
}
.milestone-emoji { font-size: 56px; margin-bottom: 14px; line-height: 1; }
.milestone-days  { font-size: 11px; font-weight: 700; letter-spacing: 0.16em; color: var(--teal-mid); text-transform: uppercase; margin-bottom: 8px; }
.milestone-title { font-size: 22px; font-weight: 800; color: var(--text); margin-bottom: 10px; }
.milestone-msg   { font-size: 14px; color: var(--muted); line-height: 1.6; margin-bottom: 26px; }

/* ── REMINDERS ──────────────────────────────────────────── */
.reminder-section {
    border-top: 1px solid var(--border);
    padding: 14px 0 4px;
    margin-top: 4px;
}
.reminder-row {
    display: flex; align-items: center; gap: 10px;
}
.reminder-icon { font-size: 15px; flex-shrink: 0; }
.reminder-label { font-size: 12px; color: var(--muted); flex: 1; }
.reminder-label strong { color: var(--text); font-weight: 600; }
.reminder-setup { display: flex; align-items: center; gap: 8px; }
.reminder-time-input {
    font-family: 'Inter', sans-serif; font-size: 12px;
    border: 1px solid var(--border); border-radius: 8px;
    padding: 5px 8px; color: var(--text); background: var(--surface-2);
    outline: none; cursor: pointer;
}
.reminder-time-input:focus { border-color: var(--teal-mid); }
.reminder-enable-btn {
    font-family: 'Inter', sans-serif; font-size: 11px; font-weight: 700;
    background: var(--teal-dark); color: white;
    border: none; border-radius: 8px; padding: 6px 14px; cursor: pointer;
    transition: background 0.12s;
}
.reminder-enable-btn:hover { background: var(--teal-mid); }
.reminder-clear-btn {
    background: none; border: none; color: var(--muted);
    font-size: 18px; cursor: pointer; padding: 2px 6px;
    line-height: 1; transition: color 0.12s; flex-shrink: 0;
}
.reminder-clear-btn:hover { color: var(--text); }

