:root {
  --bg: #0f1115;
  --card: #181b22;
  --card2: #20242d;
  --text: #e8ecf1;
  --muted: #8a93a3;
  --accent: #ff6b35;
  --accent-soft: #ff6b3533;
  --ok: #4ade80;
  --warn: #fbbf24;
  --bad: #f87171;
  --line: #2a2f3a;
}

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

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Microsoft YaHei", Roboto, "Helvetica Neue", sans-serif;
  font-size: 16px;
  min-height: 100vh;
  overscroll-behavior-y: contain;
}

body {
  padding-bottom: 84px;
  padding-top: env(safe-area-inset-top);
}

.hidden { display: none !important; }
[hidden] { display: none !important; }

.view {
  padding: 16px;
  max-width: 640px;
  margin: 0 auto;
}

h2, h3 { margin: 0 0 12px; font-weight: 600; }
h3 { font-size: 1.05rem; }

/* ========== pledge top bar ========== */
.pledge-bar {
  background: var(--bad);
  color: #fff;
  text-align: center;
  padding: 8px 16px;
  font-size: 0.9rem;
  font-weight: 500;
}

/* ========== streak hero ========== */
.streak-hero {
  text-align: center;
  padding: 20px 12px 8px;
}
.fire {
  font-size: 54px;
  line-height: 1;
  filter: drop-shadow(0 0 12px var(--accent-soft));
  transition: filter 0.4s, opacity 0.4s;
}
.fire.dead {
  filter: grayscale(1) brightness(0.6);
  opacity: 0.5;
}
.streak-num {
  font-size: 72px;
  font-weight: 800;
  line-height: 1.05;
  background: linear-gradient(180deg, #ff9d5c 0%, #ff6b35 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  margin: 4px 0;
}
.streak-label {
  color: var(--muted);
  font-size: 0.88rem;
}
.motivation {
  margin-top: 10px;
  font-style: italic;
  color: var(--muted);
  font-size: 0.92rem;
  min-height: 1.2em;
}

/* ========== progress ========== */
.progress-row { margin: 16px 0 20px; }
.progress-bar {
  height: 8px;
  background: var(--card2);
  border-radius: 4px;
  overflow: hidden;
}
#progressFill {
  height: 100%;
  background: linear-gradient(90deg, #ff9d5c, #ff6b35);
  width: 0%;
  transition: width 0.5s;
}
.progress-text {
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
  margin-top: 6px;
}

/* ========== card ========== */
.card {
  background: var(--card);
  border-radius: 14px;
  padding: 16px;
  margin-bottom: 14px;
  border: 1px solid var(--line);
}
.card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}
.card-head h3 { margin: 0; }
.status {
  font-size: 0.8rem;
  color: var(--muted);
  padding: 3px 10px;
  background: var(--card2);
  border-radius: 999px;
}
.status.ok { color: var(--ok); }

.muted-card { opacity: 0.75; }
.note { font-size: 0.85rem; color: var(--muted); margin: 6px 0 10px; }

/* ========== form ========== */
label {
  display: block;
  margin: 10px 0;
  color: var(--muted);
  font-size: 0.85rem;
}
input, select {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 10px 12px;
  background: var(--card2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 1rem;
  font-family: inherit;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -2px; }

.row { display: flex; gap: 10px; }
.row label { flex: 1; }

button {
  display: block;
  width: 100%;
  padding: 12px 18px;
  background: var(--card2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 1rem;
  font-family: inherit;
  cursor: pointer;
  margin-top: 10px;
  font-weight: 500;
}
button:disabled { opacity: 0.4; cursor: not-allowed; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:active { background: #e55a2b; }
button.secondary { background: var(--card2); }
button.danger { background: transparent; color: var(--bad); border-color: var(--bad); }

.file-btn {
  display: block;
  text-align: center;
  padding: 12px;
  background: var(--card2);
  border: 1px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
  margin: 10px 0;
  color: var(--text);
  font-size: 1rem;
}

/* ========== exercise photo ========== */
.photo-label {
  display: block;
  background: var(--card2);
  border: 1.5px dashed var(--line);
  border-radius: 10px;
  padding: 20px;
  text-align: center;
  cursor: pointer;
  color: var(--muted);
  margin: 12px 0;
  font-size: 0.9rem;
}
.photo-label:active { background: #262a34; }
.preview {
  display: block;
  width: 100%;
  max-height: 280px;
  object-fit: cover;
  border-radius: 10px;
  margin: 10px 0;
}
.done-box { text-align: center; }
.done-box p { color: var(--muted); font-size: 0.92rem; }

/* ========== meals ========== */
.meal-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}
.meal {
  background: var(--card2);
  border-radius: 10px;
  padding: 10px 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.meal-label { font-size: 0.9rem; color: var(--muted); }
.meal-btns { display: flex; gap: 6px; }
.meal-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--card);
  font-size: 20px;
  cursor: pointer;
  padding: 0;
  margin: 0;
  line-height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.meal-btn.selected { border-color: var(--accent); background: var(--accent-soft); }

/* ========== weight ========== */
.weight-row { display: flex; gap: 10px; align-items: flex-end; }
.weight-row input { margin-top: 0; }
.weight-row button { margin-top: 0; width: auto; padding: 10px 18px; flex-shrink: 0; }
.weight-hint { color: var(--muted); font-size: 0.85rem; margin-top: 8px; }

/* ========== trend / heatmap ========== */
.summary {
  margin-top: 12px;
  padding: 12px;
  background: var(--card2);
  border-radius: 10px;
  font-size: 0.9rem;
  line-height: 1.7;
}
.heatmap {
  display: grid;
  grid-template-columns: repeat(15, 1fr);
  gap: 3px;
  margin: 8px 0;
}
.heatmap > div {
  aspect-ratio: 1;
  background: var(--card2);
  border-radius: 2px;
}
.heatmap .d1 { background: #8a5a2a; }
.heatmap .d2 { background: var(--accent); }
.heatmap .d3 { background: var(--bad); opacity: 0.55; }
.legend {
  font-size: 0.8rem;
  color: var(--muted);
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: center;
  margin-top: 6px;
}
.legend .dot {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 2px;
  margin-right: 4px;
  vertical-align: middle;
}
.legend .d0 { background: var(--card2); }
.legend .d1 { background: #8a5a2a; }
.legend .d2 { background: var(--accent); }
.legend .d3 { background: var(--bad); opacity: 0.55; }

/* ========== pledge ========== */
.pledge-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  text-align: center;
  margin-bottom: 8px;
}
.pledge-stats .big { font-size: 2rem; font-weight: 700; color: var(--accent); }
.pledge-stats > div:last-child .big { color: var(--ok); }
.pledge-stats .small { font-size: 0.8rem; color: var(--muted); }
.pledge-item {
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.9rem;
}
.pledge-item:last-child { border-bottom: 0; }
.pledge-item .paid { color: var(--ok); font-size: 0.85rem; }
.pledge-item button { width: auto; padding: 6px 12px; margin: 0; font-size: 0.85rem; }

/* ========== tab bar ========== */
.tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--card);
  border-top: 1px solid var(--line);
  display: flex;
  padding: 6px 0 calc(6px + env(safe-area-inset-bottom));
  z-index: 20;
}
.tab {
  flex: 1;
  background: none;
  border: 0;
  padding: 10px 0;
  color: var(--muted);
  font-size: 0.82rem;
  margin: 0;
  border-radius: 0;
  font-weight: 500;
}
.tab.active { color: var(--accent); }

/* ========== modal ========== */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
}
.modal-card {
  background: var(--card);
  padding: 24px;
  border-radius: 14px;
  max-width: 400px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
}
.modal-card.danger { border: 1px solid var(--bad); }
.big-emoji { font-size: 60px; text-align: center; }
