/* ── lifelog · mobile-first ─────────────────────────────── */
:root {
  --bg: #0d0f14;
  --card: #161a22;
  --card-2: #1c212c;
  --line: #262c3a;
  --text: #e8ebf1;
  --muted: #8b93a7;
  --accent: #6ee7b7;       /* mint */
  --accent-dim: #6ee7b722;
  --warn: #fbbf24;
  --bad: #f87171;
  --radius: 18px;
  --ease-spring: cubic-bezier(.34, 1.4, .44, 1);
}

* { box-sizing: border-box; margin: 0; -webkit-tap-highlight-color: transparent; }

html { color-scheme: dark; }

body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 -apple-system, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  min-height: 100dvh;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}

/* top bar */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; justify-content: space-between; align-items: center;
  padding: calc(12px + env(safe-area-inset-top)) 20px 12px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}
.brand { font-weight: 700; letter-spacing: .04em; color: var(--accent); }
.topbar .date { color: var(--muted); font-size: 13px; }

main {
  max-width: 560px; margin: 0 auto; padding: 8px 16px 24px;
  animation: pagein .28s var(--ease-spring);
}
@keyframes pagein {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: none; }
}

h2 {
  font-size: 13px; text-transform: uppercase; letter-spacing: .12em;
  color: var(--muted); margin: 22px 4px 10px;
}

/* cards */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  animation: cardin .35s var(--ease-spring) backwards;
}
.card:nth-child(2) { animation-delay: .04s; }
.card:nth-child(3) { animation-delay: .08s; }
.card:nth-child(4) { animation-delay: .12s; }
@keyframes cardin {
  from { opacity: 0; transform: translateY(14px) scale(.985); }
  to   { opacity: 1; transform: none; }
}

/* forms */
label { display: block; font-size: 13px; color: var(--muted); margin: 12px 0 6px; }
input[type=text], input[type=number], input[type=date], textarea, select {
  width: 100%;
  background: var(--card-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--text);
  padding: 12px 14px;
  font-size: 16px;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}
textarea { min-height: 76px; resize: vertical; }

button, .btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--accent);
  color: #08281c;
  border: 0; border-radius: 12px;
  padding: 12px 18px;
  font-size: 15px; font-weight: 650;
  cursor: pointer;
  transition: transform .12s var(--ease-spring), filter .15s;
}
button:active, .btn:active { transform: scale(.95); }
button.ghost {
  background: transparent; color: var(--muted);
  border: 1px solid var(--line); font-weight: 500;
}
button.ghost:active { color: var(--text); }

/* segmented pickers (mood, yes/no) */
.seg { display: flex; gap: 8px; }
.seg input { display: none; }
.seg label {
  flex: 1; margin: 0; text-align: center;
  background: var(--card-2); border: 1px solid var(--line);
  border-radius: 12px; padding: 11px 0;
  font-size: 18px; color: var(--muted);
  cursor: pointer;
  transition: all .18s var(--ease-spring);
}
.seg input:checked + label {
  background: var(--accent-dim); border-color: var(--accent);
  color: var(--text); transform: scale(1.06);
}

/* habit grid */
.habit-row {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 0; border-bottom: 1px solid var(--line);
}
.habit-row:last-child { border-bottom: 0; }
.habit-name { flex: 1; min-width: 0; }
.habit-name .nm { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.habit-name .sub { font-size: 12px; color: var(--muted); }
.dots { display: flex; gap: 6px; }
.dot {
  width: 30px; height: 30px; border-radius: 10px;
  background: var(--card-2); border: 1px solid var(--line);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 13px; color: var(--muted);
  cursor: pointer; user-select: none;
  transition: all .2s var(--ease-spring);
}
.dot.done {
  background: var(--accent); border-color: var(--accent); color: #08281c;
  animation: pop .3s var(--ease-spring);
}
.dot.small { width: 22px; height: 22px; border-radius: 7px; font-size: 10px; pointer-events: none; }
@keyframes pop {
  0% { transform: scale(.6); }
  60% { transform: scale(1.15); }
  100% { transform: scale(1); }
}

/* goals */
.goal {
  display: flex; flex-direction: column; gap: 6px;
  padding: 12px 0; border-bottom: 1px solid var(--line);
}
.goal:last-child { border-bottom: 0; }
.goal .meta { font-size: 12px; color: var(--muted); display: flex; gap: 10px; flex-wrap: wrap; }
.badge {
  font-size: 11px; padding: 2px 9px; border-radius: 99px;
  background: var(--card-2); border: 1px solid var(--line); color: var(--muted);
}
.badge.weekly  { color: var(--accent); border-color: var(--accent-dim); }
.badge.overdue { color: var(--bad); }
.goal .notes { font-size: 13px; color: var(--muted); padding-left: 10px; border-left: 2px solid var(--line); }
.goal form.inline { display: flex; gap: 8px; margin-top: 6px; }
.goal form.inline input { flex: 1; padding: 9px 12px; font-size: 14px; }
.goal form.inline button { padding: 9px 14px; font-size: 14px; }
.goal-actions { display: flex; gap: 8px; }
.goal-actions button { padding: 7px 12px; font-size: 13px; }

/* recap */
.recap-text { white-space: pre-wrap; line-height: 1.65; }
.recap-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 10px; }
.recap-head .when { font-weight: 650; }
.statline { display: flex; gap: 14px; flex-wrap: wrap; font-size: 13px; color: var(--muted); margin-top: 12px; }
.statline b { color: var(--text); }

/* saved flash */
.flash {
  color: var(--accent); font-size: 13px; font-weight: 600;
  animation: flash 1.6s ease forwards;
}
@keyframes flash { 0% {opacity: 0;} 12% {opacity: 1;} 75% {opacity: 1;} 100% {opacity: 0;} }

/* htmx swap transitions */
.htmx-swapping { opacity: 0; transition: opacity .12s; }
.htmx-added { animation: cardin .3s var(--ease-spring); }
.htmx-request button[type=submit] { opacity: .6; pointer-events: none; }

/* bottom tab bar */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  display: flex;
  background: color-mix(in srgb, var(--card) 88%, transparent);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 10px 0 8px;
  color: var(--muted); text-decoration: none; font-size: 11px;
  transition: color .15s;
}
.tabbar a svg { width: 22px; height: 22px; fill: currentColor; transition: transform .2s var(--ease-spring); }
.tabbar a.on { color: var(--accent); }
.tabbar a.on svg { transform: translateY(-2px) scale(1.12); }
.tabbar a:active svg { transform: scale(.85); }

/* streak */
.topright { display: inline-flex; align-items: center; gap: 10px; }
.streak-chip {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 13px; font-weight: 700; color: var(--muted);
  background: var(--card); border: 1px solid var(--line);
  border-radius: 99px; padding: 3px 10px;
  filter: grayscale(.8); opacity: .7;
  transition: all .25s var(--ease-spring);
}
.streak-chip.lit {
  color: #fbbf24; border-color: #f59e0b55; background: #f59e0b14;
  filter: none; opacity: 1;
  box-shadow: 0 0 14px #f59e0b22;
}
.streak-chip.bump { animation: chipbump .7s var(--ease-spring); }
@keyframes chipbump {
  0% { transform: scale(1); }
  35% { transform: scale(1.35) rotate(5deg); }
  65% { transform: scale(.95) rotate(-2deg); }
  100% { transform: scale(1); }
}

.streak-pop {
  position: relative; overflow: hidden;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  margin-bottom: 14px; padding: 14px;
  border-radius: 14px;
  background: linear-gradient(135deg, #f59e0b1f, #f43f5e12);
  border: 1px solid #f59e0b44;
  animation: streakpop .7s var(--ease-spring);
}
@keyframes streakpop {
  0% { opacity: 0; transform: scale(.5) translateY(14px); }
  60% { transform: scale(1.05) translateY(-2px); }
  100% { opacity: 1; transform: none; }
}
.streak-pop .flame {
  font-size: 26px; transform-origin: 50% 90%;
  animation: flick .9s ease-in-out infinite alternate;
}
@keyframes flick {
  from { transform: scale(1) rotate(-4deg); }
  to   { transform: scale(1.12) rotate(4deg); }
}
.streak-num {
  font-size: 27px; font-weight: 800; color: #fbbf24;
  animation: numpop .9s var(--ease-spring);
}
@keyframes numpop {
  0% { transform: scale(0); }
  65% { transform: scale(1.35); }
  100% { transform: scale(1); }
}
.streak-word { color: var(--muted); font-weight: 600; }
.streak-pop i {
  position: absolute; bottom: -8px; width: 6px; height: 6px; border-radius: 50%;
  background: #fbbf24; opacity: 0; pointer-events: none;
  animation: ember 1.5s ease-out 2;
}
.streak-pop i:nth-of-type(1) { left: 18%; animation-delay: .15s; }
.streak-pop i:nth-of-type(2) { left: 50%; animation-delay: .4s; background: #f43f5e; }
.streak-pop i:nth-of-type(3) { left: 79%; animation-delay: .6s; }
@keyframes ember {
  0% { transform: translateY(0) scale(1); opacity: 0; }
  15% { opacity: .9; }
  100% { transform: translateY(-64px) scale(.25); opacity: 0; }
}

/* spark tiles */
.tiles { display: flex; gap: 10px; margin: 4px 0 14px; }
.tile {
  flex: 1; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 12px 14px 8px;
  display: flex; flex-direction: column; gap: 2px;
  animation: cardin .35s var(--ease-spring) backwards;
}
.tile:nth-child(2) { animation-delay: .05s; }
.tile-k { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.tile-v { font-size: 24px; font-weight: 700; line-height: 1.2; }
.spark { width: 100%; height: 36px; margin-top: 4px; }

/* day navigation */
.daynav {
  display: flex; justify-content: space-between; align-items: center;
  margin: 4px 2px 10px;
}
.daybtn {
  display: inline-block;
  color: var(--muted); text-decoration: none; font-size: 13px;
  border: 1px solid var(--line); border-radius: 10px; padding: 6px 12px;
  background: var(--card);
  transition: transform .12s var(--ease-spring), color .15s;
}
.daybtn:active { transform: scale(.93); color: var(--text); }
.daybtn.off { opacity: .25; pointer-events: none; }

/* charts */
.chart { width: 100%; height: auto; margin-top: 10px; display: block; }
.gridline { stroke: var(--line); stroke-width: 1; }
.chart-label { fill: var(--text); font-size: 11px; font-weight: 600; }
.chart-tick { fill: var(--muted); font-size: 8.5px; }
.chart polyline { animation: draw .7s ease; }
@keyframes draw { from { opacity: 0; } to { opacity: 1; } }

/* diary */
.searchbar { margin: 4px 0 14px; }
.searchbar input { border-radius: 14px; }
.diary-day { padding: 0; overflow: hidden; }
.diary-day summary {
  list-style: none; cursor: pointer;
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 16px;
  transition: background .15s;
}
.diary-day summary::-webkit-details-marker { display: none; }
.diary-day summary:active { background: var(--card-2); }
.diary-date { font-weight: 600; }
.diary-glance { display: flex; align-items: center; gap: 8px; font-size: 15px; }
.diary-body {
  padding: 0 16px 14px;
  animation: cardin .25s var(--ease-spring);
}
.diary-habits { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.diary-note {
  margin-top: 10px; white-space: pre-wrap; font-size: 14px;
  color: var(--text); padding-left: 10px; border-left: 2px solid var(--accent-dim);
}
.diary-body .daybtn { margin-top: 12px; }

/* entry buttons */
.btn-row { display: flex; gap: 10px; margin-top: 14px; }
.btn-row button { flex: 1; margin: 0; }
form.stack .btn-row button { margin-top: 0; }

/* misc */
.muted { color: var(--muted); font-size: 14px; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
form.stack > button { margin-top: 14px; width: 100%; }

@media (min-width: 700px) {
  .tabbar { max-width: 560px; margin: 0 auto;
            border-radius: 18px 18px 0 0; border: 1px solid var(--line); border-bottom: 0; }
}
