:root {
  --bg: #0b0f14;
  --bg-2: #121821;
  --card: #161d28;
  --card-2: #1c2430;
  --line: #26303d;
  --text: #e8eef6;
  --muted: #8a97a8;
  --accent: #ff6b35;
  --accent-2: #ffa53c;
  --good: #35d07f;
  --bad: #ff5c6c;
  --radius: 16px;
  --tabbar-h: 62px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
body { display: flex; flex-direction: column; min-height: 100vh; }

button { font-family: inherit; color: inherit; cursor: pointer; }
.ico, svg.ico { display: inline-block; vertical-align: middle; flex: none; }
input, select, textarea {
  font-family: inherit; font-size: 16px; color: var(--text);
  background: var(--bg-2); border: 1px solid var(--line);
  border-radius: 12px; padding: 12px 14px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }

/* ---- App layout ---- */
#app { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.screen {
  padding: calc(var(--safe-t) + 14px) 16px calc(var(--tabbar-h) + var(--safe-b) + 24px);
  max-width: 640px; margin: 0 auto;
}

.h1 { font-size: 26px; font-weight: 800; letter-spacing: -0.5px; margin: 4px 0 2px; }
.sub { color: var(--muted); font-size: 14px; margin: 0 0 18px; }
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); margin: 22px 2px 10px; font-weight: 700; }

/* ---- Cards ---- */
.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px; margin-bottom: 12px;
}
.card.tap { transition: transform .08s ease; }
.card.tap:active { transform: scale(0.99); }
.row { display: flex; align-items: center; gap: 12px; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }

/* ---- Buttons ---- */
.btn {
  border: none; border-radius: 12px; padding: 14px 16px; font-size: 16px; font-weight: 700;
  background: var(--card-2); color: var(--text); width: 100%;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn:active { filter: brightness(1.1); }
.btn.primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #1a0f06; }
.btn.ghost { background: transparent; border: 1px solid var(--line); }
.btn.danger { background: transparent; border: 1px solid var(--bad); color: var(--bad); }
.btn.sm { padding: 9px 12px; font-size: 14px; width: auto; }
.btn.icon { width: 40px; height: 40px; padding: 0; border-radius: 10px; flex: none; }
.btn-row { display: flex; gap: 10px; margin-top: 6px; }

.pill { display: inline-flex; align-items: center; gap: 6px; padding: 6px 11px; border-radius: 999px; font-size: 13px; font-weight: 700; background: var(--card-2); border: 1px solid var(--line); }
.pill.on { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #1a0f06; border-color: transparent; }

/* ---- Streak hero ---- */
.hero {
  background: radial-gradient(120% 120% at 0% 0%, rgba(255,107,53,.22), transparent 60%), var(--card);
  border: 1px solid var(--line); border-radius: 20px; padding: 20px; margin-bottom: 14px;
}
.streak-num { font-size: 54px; font-weight: 900; line-height: 1; letter-spacing: -2px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px; text-align: center; }
.stat .n { font-size: 24px; font-weight: 800; }
.stat .l { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* ---- Weekday selector ---- */
.days { display: flex; gap: 6px; }
.day-dot { flex: 1; text-align: center; padding: 10px 0; border-radius: 10px; background: var(--bg-2); border: 1px solid var(--line); font-size: 13px; font-weight: 700; color: var(--muted); }
.day-dot.on { background: var(--accent); color: #1a0f06; border-color: transparent; }

/* ---- Exercise / log rows ---- */
.ex { border: 1px solid var(--line); border-radius: 14px; padding: 12px; margin-bottom: 10px; background: var(--card); }
.ex .name { font-weight: 700; }
.mode-badge { color: var(--muted); display: inline-flex; }
.link-btn { width: 34px; height: 34px; border-radius: 10px; background: var(--card-2); border: 1px solid var(--line); display: inline-flex; align-items: center; justify-content: center; color: var(--accent-2); flex: none; }
.set-row { display: grid; grid-template-columns: 34px 1fr 44px; gap: 8px; align-items: center; margin-top: 8px; }
.set-row.head { color: var(--muted); }
.set-row.timed { grid-template-columns: 30px 1fr auto 44px; }
.set-row .idx { text-align: center; color: var(--muted); font-weight: 700; }
.set-row input { padding: 10px; text-align: center; }
.set-row.done { background: rgba(53,208,127,.06); border-radius: 10px; }
.timer-disp { font-variant-numeric: tabular-nums; font-size: 21px; font-weight: 800; text-align: center; letter-spacing: .5px; }
.set-row.timed.done .timer-disp { color: var(--good); }
.timer-controls { display: flex; gap: 6px; }
.done-check { width: 28px; height: 28px; border-radius: 8px; border: 2px solid var(--line); background: var(--bg-2); display: inline-flex; align-items: center; justify-content: center; flex: none; color: #06210f; }
.done-check.on { background: var(--good); border-color: var(--good); }

/* ---- Icon buttons ---- */
.btn.icon.sm { width: 34px; height: 34px; border-radius: 10px; }
.pill.mode { display: inline-flex; align-items: center; gap: 6px; }

/* ---- Calendar heatmap ---- */
.heat-wrap { display: flex; gap: 6px; }
.heat-labels { display: grid; grid-template-rows: repeat(7, 14px); gap: 3px; flex: none; padding-top: 0; }
.heat-labels span { font-size: 9px; color: var(--muted); line-height: 14px; text-align: right; }
.heat { display: grid; grid-auto-flow: column; grid-template-rows: repeat(7, 14px); gap: 3px; overflow-x: auto; padding-bottom: 4px; }
.heat .cell { width: 14px; height: 14px; border-radius: 3px; background: var(--bg-2); border: 1px solid var(--line); }
.cell.on { background: var(--accent); border-color: transparent; }
.heat .cell.today { border: 2px solid var(--text); }
.heat-legend { display: flex; align-items: center; gap: 6px; }
.heat-legend .cell { width: 12px; height: 12px; border-radius: 3px; }

/* ---- Nudge banner ---- */
.nudge {
  position: fixed; left: 12px; right: 12px; top: calc(var(--safe-t) + 10px); z-index: 50;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #1a0f06;
  padding: 13px 16px; border-radius: 14px; font-weight: 700; box-shadow: 0 8px 24px rgba(0,0,0,.4);
  display: flex; align-items: center; gap: 10px;
}
.nudge { align-items: center; }
.nudge .x { margin-left: auto; background: rgba(0,0,0,.18); border: none; border-radius: 8px; width: 26px; height: 26px; color: #1a0f06; display: flex; align-items: center; justify-content: center; flex: none; }

/* ---- Tab bar ---- */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 40;
  height: calc(var(--tabbar-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  display: flex; background: rgba(11,15,20,.86); backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
}
.tab { flex: 1; background: none; border: none; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; color: var(--muted); font-size: 11px; font-weight: 600; padding: 0; }
.tab .ic { display: flex; opacity: .7; transition: .15s; }
.tab .ic svg { width: 22px; height: 22px; }
.tab.active { color: var(--text); }
.tab.active .ic { opacity: 1; transform: translateY(-1px); }

/* ---- Misc ---- */
.hidden { display: none !important; }
.empty { text-align: center; color: var(--muted); padding: 40px 16px; }
.empty .big { font-size: 40px; margin-bottom: 8px; }
.chip { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 700; background: var(--card-2); border: 1px solid var(--line); color: var(--muted); }
.chip.good { color: var(--good); border-color: rgba(53,208,127,.4); }
.divider { height: 1px; background: var(--line); margin: 16px 0; }
label.field { display: block; margin: 12px 0; }
.time-shell { display: flex; }
.time-shell input { flex: 1; min-width: 0; width: 100%; }
label.field .lab { font-size: 13px; color: var(--muted); font-weight: 700; margin-bottom: 6px; display: block; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.spark { width: 100%; height: 120px; }
.link { color: var(--accent-2); font-weight: 700; background: none; border: none; padding: 0; }

/* Modal sheet */
.sheet-wrap { position: fixed; inset: 0; z-index: 60; display: none; }
.sheet-wrap.open { display: block; }
.sheet-bg { position: absolute; inset: 0; background: rgba(0,0,0,.5); }
.sheet { position: absolute; left: 0; right: 0; bottom: 0; background: var(--bg-2); border-radius: 20px 20px 0 0; padding: 18px 16px calc(20px + var(--safe-b)); max-height: 88vh; overflow-y: auto; border-top: 1px solid var(--line); }
.sheet h3 { margin: 4px 0 14px; font-size: 20px; }
.grab { width: 42px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 12px; }
