/* ---- Theme tokens ---- */
:root {
  --bg: #0b0f14;
  --bg-elev: #131a23;
  --bg-elev2: #1b2430;
  --line: #243140;
  --text: #e7eef6;
  --muted: #8aa0b4;
  --accent: #2dd4bf;     /* teal */
  --accent-2: #38bdf8;   /* sky */
  --good: #34d399;
  --bad: #f87171;
  --radius: 16px;
  --tabbar-h: 64px;
}

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

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  /* dvh keeps layout correct under the iPhone toolbar */
  min-height: 100dvh;
}

body {
  max-width: 560px;
  margin: 0 auto;
  /* leave room for top bar + bottom tab bar (incl. iPhone home indicator) */
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
}

/* ---- Top bar ---- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 12px) 16px 12px;
  background: linear-gradient(180deg, var(--bg) 70%, transparent);
  backdrop-filter: blur(6px);
}
.brand { font-weight: 800; letter-spacing: .5px; font-size: 18px; }

.icon-btn {
  background: var(--bg-elev); border: 1px solid var(--line); color: var(--text);
  width: 38px; height: 38px; border-radius: 12px; font-size: 18px; cursor: pointer;
}
.icon-btn:active { transform: scale(.94); }

/* ---- Views ---- */
.view { padding: 8px 16px 24px; }
h1 { font-size: 22px; margin: 4px 0 2px; }
h2 { font-size: 16px; margin: 0; }
h3 { font-size: 14px; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; margin: 24px 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.center { text-align: center; }

.card {
  background: var(--bg-elev); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px; margin-bottom: 12px;
}

/* ---- Buttons / inputs ---- */
.btn {
  display: block; width: 100%; padding: 13px 16px; margin: 8px 0;
  background: var(--bg-elev2); color: var(--text);
  border: 1px solid var(--line); border-radius: 12px;
  font-size: 15px; font-weight: 600; cursor: pointer; text-align: center;
}
.btn:active { transform: scale(.99); }
.btn.primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #04141a; border: none; }
.btn.danger { color: var(--bad); border-color: #5b2b2b; }
.btn.ghost { background: transparent; }
.row { display: flex; gap: 8px; align-items: center; }
.row > * { flex: 1; }

input, select {
  width: 100%; padding: 11px 12px; font-size: 15px;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--line); border-radius: 10px;
}

/* ---- Streak + heatmap (Today) ---- */
.streak { display: flex; align-items: baseline; gap: 10px; }
.streak .num { font-size: 40px; font-weight: 800; line-height: 1; }
.streak .fire { font-size: 30px; }

.habit-item { border-bottom: 1px solid var(--line); }
.habit-item:last-child { border-bottom: none; }
.habit { display: flex; align-items: center; gap: 8px; padding: 12px 4px; }
.habit-main { display: flex; align-items: center; gap: 12px; flex: 1; cursor: pointer; user-select: none; min-width: 0; }
.chev { background: none; border: none; color: var(--muted); font-size: 15px; padding: 6px 10px; cursor: pointer; flex: none; }
.note-dot { font-size: 12px; opacity: .8; flex: none; }
.habit-details { padding: 2px 4px 12px; }
textarea.notes { width: 100%; resize: vertical; font-family: inherit; font-size: 14px; padding: 10px 12px; background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 10px; }
.habit .check {
  width: 26px; height: 26px; border-radius: 8px; border: 2px solid var(--line);
  display: grid; place-items: center; font-size: 16px; flex: none;
}
.habit.done .check { background: var(--accent); border-color: var(--accent); color: #04141a; }
.habit.done .label { color: var(--muted); text-decoration: line-through; }
.habit .emoji { font-size: 18px; flex: none; }
.habit .label { flex: 1; font-size: 15px; }

.heatmap { display: grid; grid-auto-flow: column; grid-template-rows: repeat(7, 1fr); gap: 3px; overflow-x: auto; padding-bottom: 4px; }
.heatmap .cell { width: 14px; height: 14px; border-radius: 3px; background: var(--bg-elev2); }

/* ---- Photos ---- */
.cat-tabs { display: flex; gap: 8px; margin: 4px 0 14px; }
.cat-tabs button { flex: 1; padding: 9px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg-elev); color: var(--muted); font-weight: 600; }
.cat-tabs button.active { background: var(--bg-elev2); color: var(--text); border-color: var(--accent); }

.thumb-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.thumb { position: relative; aspect-ratio: 3/4; border-radius: 10px; overflow: hidden; background: var(--bg-elev2); cursor: pointer; }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb .date { position: absolute; left: 4px; bottom: 4px; font-size: 10px; background: rgba(0,0,0,.55); padding: 2px 5px; border-radius: 6px; }

/* before/after slider */
.ba { position: relative; width: 100%; aspect-ratio: 3/4; border-radius: 12px; overflow: hidden; background: #000; touch-action: none; }
.ba img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.ba .before { z-index: 2; clip-path: inset(0 calc(100% - var(--pos, 50%)) 0 0); }
.ba .after  { z-index: 1; }
.ba .handle { position: absolute; top: 0; bottom: 0; left: var(--pos, 50%); width: 2px; background: #fff; z-index: 3; transform: translateX(-1px); }
.ba .handle::after { content: "⇆"; position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%); width: 30px; height: 30px; background: #fff; color: #000; border-radius: 50%; display: grid; place-items: center; font-size: 14px; }
.ba .tag { position: absolute; top: 8px; padding: 3px 8px; font-size: 11px; border-radius: 6px; background: rgba(0,0,0,.6); z-index: 4; }
.ba .tag.l { left: 8px; } .ba .tag.r { right: 8px; }

/* fullscreen camera + photo viewer */
.overlay { position: fixed; inset: 0; z-index: 50; background: #000; display: flex; flex-direction: column; }
.overlay video, .overlay .full { flex: 1; width: 100%; object-fit: contain; background: #000; }
.overlay .ghost { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: .35; pointer-events: none; }
.cam-wrap { position: relative; flex: 1; overflow: hidden; }
.cam-wrap video { position: absolute; inset: 0; height: 100%; width: 100%; object-fit: cover; }
.cam-controls { display: flex; align-items: center; justify-content: space-around; padding: 18px 18px calc(18px + env(safe-area-inset-bottom)); background: #000; }
.shutter { width: 68px; height: 68px; border-radius: 50%; background: #fff; border: 4px solid #888; }
.cam-controls .icon-btn { background: #1c1c1c; border-color: #333; }

/* ---- Metrics ---- */
.stat { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 6px; }
.stat .v { font-size: 26px; font-weight: 800; }
.stat .delta.up { color: var(--bad); } .stat .delta.down { color: var(--good); }
.chart { width: 100%; height: auto; }
.entry { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.entry button { background: none; border: none; color: var(--muted); font-size: 16px; cursor: pointer; }

/* ---- Tab bar ---- */
.tabbar {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: 0;
  width: 100%; max-width: 560px; z-index: 30;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: flex; background: var(--bg-elev); border-top: 1px solid var(--line);
}
.tab { flex: 1; background: none; border: none; color: var(--muted); font-size: 22px; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.tab span { font-size: 11px; font-weight: 600; }
.tab.active { color: var(--accent); }

/* ---- Settings sheet ---- */
.sheet { position: fixed; inset: 0; z-index: 60; background: rgba(0,0,0,.6); display: flex; align-items: flex-end; }
.sheet.hidden { display: none; }
.sheet-inner { width: 100%; max-width: 560px; margin: 0 auto; background: var(--bg-elev); border-radius: 20px 20px 0 0; padding: 16px 16px calc(24px + env(safe-area-inset-bottom)); border: 1px solid var(--line); }
.sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
hr { border: none; border-top: 1px solid var(--line); margin: 16px 0; }

.empty { text-align: center; color: var(--muted); padding: 40px 0; }
.hidden { display: none; }
