:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-2: #334155;
  --text: #f8fafc;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --accent-2: #22c55e;
  --danger: #ef4444;
  --radius: 18px;
  --shadow: 0 8px 24px rgba(0,0,0,0.35);
}

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

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  overflow-x: hidden;
  touch-action: pan-y;
}

body {
  display: flex;
  flex-direction: column;
  padding-bottom: 80px;
}

/* Top bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(15,23,42,0.92);
  backdrop-filter: blur(10px);
  padding: 12px 16px 8px;
  border-bottom: 1px solid var(--surface-2);
}

.topbar h1 {
  margin: 0 0 10px;
  font-size: 1.35rem;
  letter-spacing: -0.5px;
}

.datebar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.dategroup {
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.2;
}

.datelabel {
  font-weight: 700;
  font-size: 1.05rem;
}

.datesub {
  font-size: 0.8rem;
  color: var(--muted);
}

.iconbtn {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: none;
  background: var(--surface);
  color: var(--text);
  font-size: 1.6rem;
  line-height: 1;
  display: grid;
  place-items: center;
  cursor: pointer;
}

.save-status {
  position: absolute;
  top: 14px;
  right: 16px;
  font-size: 0.75rem;
  color: var(--muted);
  opacity: 0;
  transition: opacity 0.2s;
}
.save-status.show { opacity: 1; }

/* Main + tabs */
main { flex: 1; padding: 12px; }
.tab { display: none; }
.tab.active { display: block; }

.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 18px 16px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}

.card h2 {
  margin: 0;
  font-size: 1.1rem;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.progress-num {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--accent);
  background: rgba(56,189,248,0.12);
  padding: 4px 10px;
  border-radius: 999px;
}

.dateRef { color: var(--muted); font-weight: 400; }
.hint {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 0.9rem;
}

/* Today */
.today-card { padding-bottom: 14px; }
.today-card h2 { margin-bottom: 12px; }
.today-list, .habit-strip, .body-strip { margin-bottom: 10px; }
.today-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--surface-2);
  font-size: 0.95rem;
}
.today-item:last-child { border-bottom: none; }
.today-item.done { opacity: 0.55; text-decoration: line-through; }
.today-item input[type="checkbox"] {
  width: 22px;
  height: 22px;
  accent-color: var(--accent-2);
}
.habit-strip, .body-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.pill {
  background: var(--surface-2);
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 0.82rem;
  color: var(--text);
}
.pill.on {
  background: rgba(34,197,94,0.18);
  color: var(--accent-2);
}

.linkbtn {
  width: 100%;
  margin-top: 6px;
  padding: 10px;
  border-radius: 12px;
  border: 1px solid var(--surface-2);
  background: transparent;
  color: var(--accent);
  font-weight: 600;
  cursor: pointer;
}

/* Tasks */
.task-list { display: flex; flex-direction: column; gap: 12px; }
.task-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface-2);
  padding: 12px 14px;
  border-radius: 14px;
}
.task-row input[type="checkbox"] {
  width: 26px;
  height: 26px;
  accent-color: var(--accent-2);
  flex-shrink: 0;
}
.task-row input[type="text"] {
  flex: 1;
  background: transparent;
  border: none;
  border-bottom: 2px solid var(--surface-2);
  color: var(--text);
  font-size: 1rem;
  padding: 8px 2px;
}
.task-row input[type="text"]:focus {
  outline: none;
  border-bottom-color: var(--accent);
}
.task-row input[type="text"]::placeholder {
  color: var(--muted);
  opacity: 1;
}
.task-row.done input[type="text"] {
  text-decoration: line-through;
  opacity: 0.55;
}
.carry-badge {
  font-size: 0.7rem;
  color: var(--accent);
  white-space: nowrap;
}

/* Habits */
.habit-list { display: flex; flex-direction: column; gap: 10px; }
.habit-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface-2);
  padding: 14px;
  border-radius: 14px;
  cursor: pointer;
  user-select: none;
  transition: background 0.15s;
}
.habit-row.on {
  background: rgba(34,197,94,0.18);
}
.habit-row span { font-size: 0.95rem; }
.habit-check {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid var(--muted);
  display: grid;
  place-items: center;
  font-size: 0.85rem;
  transition: all 0.15s;
}
.habit-row.on .habit-check {
  background: var(--accent-2);
  border-color: var(--accent-2);
  color: #fff;
}

/* Body */
.body-form { display: flex; flex-direction: column; gap: 18px; }
.body-form label { display: flex; flex-direction: column; gap: 6px; }
.body-form label span { font-size: 0.9rem; color: var(--muted); }
.body-form input[type="number"],
.body-form textarea {
  background: var(--surface-2);
  border: 1px solid var(--surface-2);
  border-radius: 12px;
  padding: 12px;
  color: var(--text);
  font-size: 1rem;
}
.body-form textarea { resize: none; }
.energy-row {
  display: flex;
  align-items: center;
  gap: 12px;
}
.energy-row input[type="range"] {
  flex: 1;
  height: 10px;
  border-radius: 5px;
  accent-color: var(--accent);
}
.energy-row output {
  min-width: 30px;
  text-align: center;
  font-weight: 700;
  color: var(--accent);
}
.toggle-row {
  flex-direction: row !important;
  align-items: center;
  justify-content: space-between;
}
.big-check {
  width: 32px;
  height: 32px;
  accent-color: var(--accent-2);
  cursor: pointer;
}

.primary-btn {
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: 14px;
  background: var(--accent-2);
  color: #052e16;
  font-weight: 700;
  font-size: 1rem;
  cursor: pointer;
  margin-top: 6px;
}
.primary-btn:active { transform: scale(0.98); }

/* Weekly */
.weekly-summary { display: flex; flex-direction: column; gap: 10px; }
.week-card {
  background: var(--surface-2);
  border-radius: 14px;
  padding: 14px;
}
.week-card h3 { margin: 0 0 8px; font-size: 0.95rem; }
.week-card h3 small { color: var(--muted); font-weight: 400; }
.week-metrics { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.metric { text-align: center; }
.metric .num { font-size: 1.35rem; font-weight: 700; color: var(--accent); }
.metric .lbl { font-size: 0.75rem; color: var(--muted); }

/* Bottom nav */
.bottomnav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-around;
  align-items: center;
  background: rgba(15,23,42,0.96);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--surface-2);
  padding: 8px 0 calc(8px + env(safe-area-inset-bottom));
  z-index: 20;
}
.navbtn {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-size: 1.3rem;
  min-height: 56px;
  padding: 6px 0 calc(6px + env(safe-area-inset-bottom));
  cursor: pointer;
}
.navbtn span { font-size: 0.65rem; font-weight: 500; }
.navbtn.active { color: var(--accent); }
.navbtn:active { transform: scale(0.95); }

/* Helpers */
.empty-state {
  color: var(--muted);
  font-size: 0.9rem;
  padding: 12px 0;
}

@media (min-width: 600px) {
  body { max-width: 480px; margin: 0 auto; border-left: 1px solid var(--surface-2); border-right: 1px solid var(--surface-2); }
}
