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

:root {
    --teal-dark:  #7B5E48;
    --teal-mid:   #A8927E;
    --teal-light: #F5F0EB;
    --near-black: #1C1410;
    --bg:         #F0EDE8;
    --surface:    #FFFFFF;
    --surface-2:  #F8F5F0;
    --border:     #DDD8D2;
    --text:       #1C1410;
    --muted:      #B8A898;
    --on-primary: #FFFFFF;

    --font-display: 'Fraunces', Georgia, serif;
    --shadow-card: 0 1px 2px rgba(28,20,16,0.04), 0 6px 20px rgba(28,20,16,0.05);

    --chart-score:   #7B5E48;
    --chart-anxiety: #C8916A;
    --chart-grid:    #EDE8E0;
    --heatmap-partial: #C8916A;
    --el-status-partial: #D4BBA8;
    --pin-error: #D95555;
}

@media (prefers-color-scheme: dark) {
    :root {
        --teal-dark:  #C1A183;
        --teal-mid:   #8A7360;
        --teal-light: #2A231D;
        --near-black: #EDE6DF;
        --bg:         #171310;
        --surface:    #201B17;
        --surface-2:  #262019;
        --border:     #352C25;
        --text:       #EDE6DF;
        --muted:      #8A7A6C;
        --on-primary: #1C1410;

        --shadow-card: 0 1px 2px rgba(0,0,0,0.3), 0 6px 20px rgba(0,0,0,0.25);

        --chart-score:   #C1A183;
        --chart-anxiety: #D9A97E;
        --chart-grid:    #2A231D;
        --heatmap-partial: #A87A54;
        --el-status-partial: #6B5643;
        --pin-error: #E07A7A;
    }
}

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

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation: none !important;
        transition: none !important;
    }
}

/* ── 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-family: var(--font-display); font-size: 26px; font-weight: 600; 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: var(--pin-error); border-color: var(--pin-error); }
.pin-error { font-size: 13px; color: var(--pin-error); 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; }

.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-family: var(--font-display); font-size: 22px; font-weight: 600; color: var(--text); }
.streak-pill {
    display: flex; flex-direction: column; align-items: center;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: 14px; padding: 11px 18px;
    box-shadow: var(--shadow-card);
}
.streak-pill .num   { font-family: var(--font-display); font-variant-numeric: tabular-nums; font-size: 26px; font-weight: 700; 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: var(--surface); border: 1px solid var(--border);
    border-radius: 16px; padding: 6px 18px 18px; margin-bottom: 18px;
    box-shadow: var(--shadow-card);
}
.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: 7px;
    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; }
.hbox svg path { stroke: var(--on-primary); }
.habit-row .hname { font-size: 15px; font-weight: 600; color: var(--text); margin-bottom: 2px; transition: color 0.14s; }
.habit-row .hdesc { font-size: 12px; color: var(--muted); }
.habit-row.done .hname { color: var(--teal-dark); }

/* 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-family: var(--font-display); font-variant-numeric: tabular-nums; font-size: 24px; font-weight: 700; color: var(--teal-dark); }
input[type="range"] {
    width: 100%; -webkit-appearance: none; appearance: none;
    height: 5px; border-radius: 3px; background: var(--border); outline: none; cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none; width: 22px; height: 22px; border-radius: 50%;
    background: var(--teal-dark); cursor: pointer; border: 2px solid var(--surface);
    box-shadow: 0 0 0 5px rgba(123,94,72,0.12);
}
input[type="range"]::-moz-range-thumb {
    width: 22px; height: 22px; border-radius: 50%;
    background: var(--teal-dark); cursor: pointer; border: 2px solid var(--surface);
}

/* Anxiety word label */
.anxiety-word { font-size: 13px; font-weight: 500; color: var(--muted); }

/* Cannabis quick-log */
.weed-section    { border-top: 1px solid var(--border); padding: 14px 0 8px; }
.el-weed-section { border-top: 1px solid var(--border); padding: 12px 0 8px; }
.weed-lbl { font-size: 10px; font-weight: 700; letter-spacing: 0.12em; color: var(--muted); text-transform: uppercase; margin-bottom: 10px; }
.weed-methods { display: flex; gap: 8px; flex-wrap: wrap; }
.method-pill {
    padding: 6px 14px; border-radius: 20px;
    border: 1.5px solid var(--border); background: var(--bg); color: var(--text);
    font-family: 'Inter', sans-serif; font-size: 13px; font-weight: 600;
    cursor: pointer; transition: all 0.14s;
}
.method-pill:active { transform: scale(0.95); }
.method-pill.on { background: var(--teal-dark); border-color: var(--teal-dark); color: var(--on-primary); }
.weed-add-controls { display: flex; align-items: center; gap: 8px; margin-top: 10px; }
.weed-add-btn {
    padding: 8px 14px; border-radius: 9px; white-space: nowrap;
    border: 1.5px solid var(--teal-dark); background: transparent; color: var(--teal-dark);
    font-family: 'Inter', sans-serif; font-size: 13px; font-weight: 700;
    cursor: pointer; transition: all 0.14s;
}
.weed-add-btn:hover  { background: var(--teal-dark); color: var(--on-primary); }
.weed-add-btn:active { transform: scale(0.97); }
.weed-log-list { display: flex; flex-direction: column; gap: 5px; margin-top: 10px; }
.weed-log-entry {
    display: flex; align-items: center; gap: 8px;
    padding: 8px 10px; background: var(--bg); border-radius: 8px;
    border: 1px solid var(--border);
}
.wle-method { font-size: 13px; font-weight: 600; color: var(--text); flex: 1; }
.wle-time   { font-size: 12px; color: var(--muted); }
.wle-remove {
    background: none; border: none; color: var(--muted); padding: 2px 4px;
    font-family: 'Inter', sans-serif; font-size: 12px; border-radius: 4px;
    cursor: pointer; transition: color 0.12s;
}
.wle-remove:hover { color: #C85555; }
/* Save button */
.save-btn {
    width: 100%; padding: 15px;
    background: var(--teal-dark); color: var(--on-primary);
    border: none; border-radius: 12px;
    font-family: 'Inter', sans-serif; font-size: 15px; font-weight: 700;
    cursor: pointer; margin-top: 16px;
    transition: all 0.14s; letter-spacing: 0.02em;
}
.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: var(--surface); border: 1px solid var(--border); border-radius: 13px; padding: 14px 10px; text-align: center; box-shadow: var(--shadow-card); }
.stat-card .snum { font-family: var(--font-display); font-variant-numeric: tabular-nums; font-size: 22px; font-weight: 700; 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: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 18px; box-shadow: var(--shadow-card); }
.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: var(--heatmap-partial); }
.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-family: var(--font-display); font-size: 26px; font-weight: 600; color: var(--text); margin-bottom: 20px; }
.all-stats  { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 14px; }
.chart-card { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 18px; margin-bottom: 14px; box-shadow: var(--shadow-card); }
.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: var(--el-status-partial); }
.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-family: var(--font-display); font-variant-numeric: tabular-nums; font-size: 20px; font-weight: 700; color: var(--teal-dark); }

/* ── WEEKLY REVIEW OVERLAY ───────────────────────────── */
#wr-overlay {
    position: fixed; inset: 0;
    background: var(--bg); z-index: 200;
    display: none; overflow-y: auto;
}

.wr-week-nav {
    display: flex; align-items: center; gap: 12px;
    margin-bottom: 14px;
}

.wr-nav-btn {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: 8px; padding: 8px 16px;
    font-family: 'Inter', sans-serif; font-size: 16px; font-weight: 600;
    color: var(--teal-dark); cursor: pointer; transition: all 0.12s; flex-shrink: 0;
}
.wr-nav-btn:hover:not(:disabled) { border-color: var(--teal-dark); }
.wr-nav-btn:disabled { color: var(--muted); cursor: default; }

.wr-week-label {
    flex: 1; text-align: center;
    font-size: 15px; font-weight: 700; color: var(--text);
}

.wr-field { margin-bottom: 16px; }
.wr-field:last-of-type { margin-bottom: 0; }

.wr-field-label {
    font-size: 10px; font-weight: 700; letter-spacing: 0.12em;
    color: var(--teal-mid); text-transform: uppercase; margin-bottom: 8px;
}

.wr-textarea {
    width: 100%; min-height: 90px; padding: 12px 14px;
    border: 1px solid var(--border); border-radius: 10px;
    background: var(--teal-light); color: var(--text);
    font-family: 'Inter', sans-serif; font-size: 14px; line-height: 1.55;
    resize: vertical; outline: none; transition: border-color 0.14s;
    display: block;
}
.wr-textarea:focus { border-color: var(--teal-mid); }
.wr-textarea::placeholder { color: var(--muted); }

.wr-past-toggle { cursor: pointer; user-select: none; }

.wr-past-content {
    padding: 14px 14px 2px;
    background: var(--teal-light);
    border-top: 1px solid var(--border);
}

.wr-past-section { margin-bottom: 12px; }
.wr-past-section-label {
    font-size: 10px; font-weight: 700; letter-spacing: 0.1em;
    color: var(--muted); text-transform: uppercase; margin-bottom: 5px;
}
.wr-past-section-text {
    font-size: 13px; color: var(--text); line-height: 1.55; white-space: pre-wrap;
}

/* ── MOTION ──────────────────────────────────────────── */
@keyframes hboxPop {
    0%   { transform: scale(1); }
    50%  { transform: scale(1.12); }
    100% { transform: scale(1); }
}
.hbox.on { animation: hboxPop 0.18s ease; }

@keyframes fadeUp {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}
.app-header   { animation: fadeUp 0.4s ease both; }
.today-card   { animation: fadeUp 0.4s ease 0.06s both; }
.stats-row    { animation: fadeUp 0.4s ease 0.12s both; }
.heatmap-card { animation: fadeUp 0.4s ease 0.18s both; }

@keyframes streakPulse {
    0%   { transform: scale(1); }
    40%  { transform: scale(1.08); }
    100% { transform: scale(1); }
}
.streak-pill.pulse { animation: streakPulse 0.5s ease; }

@keyframes cardGlow {
    0%   { box-shadow: var(--shadow-card); }
    40%  { box-shadow: 0 0 0 3px rgba(200,145,106,0.35), var(--shadow-card); }
    100% { box-shadow: var(--shadow-card); }
}
.today-card.celebrate { animation: cardGlow 0.7s ease; }

