:root {
  --bg: #f6f6f4;
  --surface: #ffffff;
  --ink: #1c1c1e;
  --muted: #6e6e73;
  --line: #e4e4e0;
  --accent: #2457d6;
  --accent-ink: #ffffff;
  --fill: #eef2fb;
  --danger: #9f2d2d;
  color-scheme: light;
}

html[data-theme="dark"] {
  --bg: #141416;
  --surface: #1c1c1f;
  --ink: #f3f3f4;
  --muted: #a1a1a6;
  --line: #2d2d31;
  --accent: #6c93f0;
  --accent-ink: #101218;
  --fill: #232833;
  --danger: #e07a7a;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  min-height: var(--tg-viewport-stable-height, 100vh);
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

button { cursor: pointer; }

#app {
  max-width: 720px;
  margin: 0 auto;
  min-height: var(--tg-viewport-stable-height, 100vh);
  padding:
    calc(12px + max(env(safe-area-inset-top, 0px), var(--tg-content-safe-area-inset-top, 0px)))
    16px
    calc(72px + env(safe-area-inset-bottom, 0px) + var(--tg-content-safe-area-inset-bottom, 0px));
}

.top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 16px;
}

.brand {
  font-size: 13px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

h1 {
  font-size: 22px;
  font-weight: 600;
  margin: 0;
}

.muted { color: var(--muted); }
.small { font-size: 13px; }

.hero {
  margin: 8px 0 16px;
}

.hero b {
  display: block;
  font-size: 40px;
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 1.1;
}

.row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.pills { margin: 8px 0 16px; }

.pill, .seg button, .nav button, .choice, .ghost, .primary, .danger {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 8px;
  padding: 6px 10px;
}

.pill.on, .seg button.on, .choice.on, .nav button.on {
  background: var(--fill);
  border-color: var(--accent);
  color: var(--accent);
}

.primary {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
  padding: 12px 14px;
  width: 100%;
  font-weight: 600;
}

.ghost, .danger { background: transparent; }
.danger { color: var(--danger); border-color: transparent; padding-left: 0; }

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

.card h2, .section-title {
  margin: 0 0 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}

.bar {
  height: 6px;
  background: var(--fill);
  border-radius: 99px;
  overflow: hidden;
  margin-top: 8px;
}

.bar span {
  display: block;
  height: 100%;
  background: var(--accent);
}

.chart {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  height: 140px;
  margin-top: 12px;
}

.chart .col {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100%;
  justify-content: flex-end;
}

.chart .fill {
  width: 100%;
  max-width: 18px;
  background: var(--accent);
  border-radius: 3px 3px 0 0;
  min-height: 2px;
}

.chart .tick {
  margin-top: 4px;
  font-size: 11px;
  color: var(--muted);
}

label.field {
  display: block;
  margin: 10px 0;
}

label.field span, .field-name {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 13px;
}

input[type="text"], input[type="number"], input[type="time"], select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--bg);
  border-radius: 8px;
  padding: 10px;
}

textarea { min-height: 72px; resize: vertical; }

.check {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-top: 1px solid var(--line);
}

.scale { display: flex; gap: 6px; }
.scale button { flex: 1; padding: 10px 0; }

.member { margin-bottom: 12px; }
.member .track {
  height: 8px;
  background: var(--fill);
  border-radius: 99px;
  overflow: hidden;
  margin-top: 4px;
}
.member .track span { display: block; height: 100%; }

.nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  gap: 4px;
  justify-content: space-between;
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  background: var(--bg);
  border-top: 1px solid var(--line);
}

.nav button {
  flex: 1;
  font-size: 11px;
  padding: 8px 2px;
}

.error {
  color: var(--danger);
  margin: 8px 0;
}

.goal-head, .tracker-head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
}

.empty { color: var(--muted); margin: 8px 0 16px; }
