* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

:root {
  --bg: var(--tg-theme-bg-color, #EDEBE4);
  --card: var(--tg-theme-secondary-bg-color, #FFFFFF);
  --text: var(--tg-theme-text-color, #1A1F2E);
  --muted: var(--tg-theme-hint-color, #6B7280);
  --accent: #2F66C9;
  --tint: rgba(47, 102, 201, 0.12);
  --green: #18A47C;
  --amber: #F5933E;
  --amber-text: #985B17;
}

html, body { height: 100%; }
body {
  font-family: -apple-system, 'SF Pro Display', Roboto, 'Segoe UI', sans-serif;
  background: var(--bg); color: var(--text); font-size: 15px;
}

#app { max-width: 520px; margin: 0 auto; min-height: 100%; display: flex; flex-direction: column; }
.view { flex: 1; padding: 8px 14px 78px; }
.view-chat { display: flex; flex-direction: column; padding-bottom: 70px; }

.center-fill { flex: 1; display: flex; align-items: center; justify-content: center; min-height: 60vh; }
.spinner { width: 28px; height: 28px; border: 3px solid var(--tint); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.header { padding: 10px 2px 12px; display: flex; justify-content: space-between; align-items: center; }
h1 { font-size: 24px; font-weight: 700; }
h2 { font-size: 18px; font-weight: 700; margin-bottom: 8px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.accent-text { color: var(--accent); font-weight: 600; }
.card-title { font-weight: 600; font-size: 14px; }

.card { background: var(--card); border-radius: 18px; padding: 14px; margin-bottom: 12px; box-shadow: 0 3px 12px rgba(26,31,46,0.06); }
.row-center { display: flex; align-items: center; gap: 14px; }
.row2 { display: flex; gap: 10px; }
.row2 .field { flex: 1; }

.input {
  width: 100%; border: none; background: var(--bg); color: var(--text);
  border-radius: 12px; padding: 12px; font-size: 15px; margin: 6px 0; outline: none;
}
.field-label { font-size: 12px; font-weight: 600; color: var(--muted); margin-top: 10px; }

.btn { width: 100%; border: none; border-radius: 14px; padding: 14px; font-size: 15px; font-weight: 600; cursor: pointer; }
.btn-primary { background: var(--accent); color: #fff; }
.btn:disabled { opacity: 0.6; }
.btn-round { width: 42px; height: 42px; border-radius: 50%; border: none; background: var(--accent); color: #fff; font-size: 18px; cursor: pointer; flex: none; }

.seg { display: flex; gap: 6px; margin: 6px 0; }
.seg-btn { flex: 1; border: 1.5px solid var(--tint); background: transparent; color: var(--text); border-radius: 12px; padding: 10px 4px; font-size: 13px; cursor: pointer; }
.seg-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }

.bar-block { margin-bottom: 9px; }
.bar-head { display: flex; justify-content: space-between; font-size: 12px; margin-bottom: 4px; }
.bar { height: 6px; background: var(--tint); border-radius: 4px; overflow: hidden; }
.bar-fill { height: 100%; width: 0; border-radius: 4px; transition: width 0.4s; }

.ring-big { font-size: 19px; font-weight: 700; fill: var(--text); }
.ring-sub { font-size: 10px; fill: var(--muted); }

.chip-row { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { border: none; background: var(--tint); color: var(--accent); font-weight: 600; font-size: 13px; border-radius: 18px; padding: 8px 14px; cursor: pointer; }
.active-chip { outline: 2px solid var(--accent); }
.mission-row { display: flex; align-items: center; gap: 8px; padding: 7px 0; }
.mission-row input { width: 18px; height: 18px; accent-color: var(--accent); }
.reminder-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.reminder-row .check-row { flex: 1; margin: 0; }
.time-input { width: 112px; margin: 0; }
.cycle-date-input { width: 150px; margin: 0; }

.food-item { display: flex; justify-content: space-between; align-items: center; background: var(--card); border-radius: 14px; padding: 11px 13px; margin-top: 8px; cursor: pointer; }
.food-item .small { margin-top: 2px; }

#chat { flex: 1; overflow-y: auto; padding: 4px 0; }
.msg { max-width: 82%; border-radius: 14px; padding: 10px 12px; margin: 5px 0; font-size: 14px; line-height: 1.45; white-space: pre-wrap; }
.msg-user { background: var(--accent); color: #fff; margin-left: auto; border-bottom-right-radius: 4px; }
.msg-ai { background: var(--card); border-bottom-left-radius: 4px; }
.chat-input-row { display: flex; gap: 8px; align-items: center; padding: 8px 0; }

.btn-outline { background: transparent; border: 1.5px solid var(--accent); color: var(--accent); }
.avatar { width: 36px; height: 36px; border-radius: 50%; border: none; background: linear-gradient(135deg, var(--accent), var(--green)); color: #fff; font-weight: 700; font-size: 15px; cursor: pointer; }
.avatar-lg { width: 52px; height: 52px; font-size: 20px; display: flex; align-items: center; justify-content: center; flex: none; }
.link-btn { border: none; background: none; color: var(--accent); font-size: 13px; font-weight: 600; cursor: pointer; padding: 2px 4px; }
.back-btn { border: none; background: none; color: var(--text); font-size: 26px; cursor: pointer; padding: 0 10px 0 0; line-height: 1; }
.check-row { display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 600; margin-top: 8px; cursor: pointer; }
.check-row input { width: 18px; height: 18px; accent-color: var(--accent); }
.nav-row { display: flex; justify-content: space-between; align-items: center; font-weight: 600; font-size: 14px; cursor: pointer; }
.banner { border-radius: 14px; padding: 11px 13px; font-size: 12px; line-height: 1.4; margin-bottom: 10px; background: var(--tint); color: var(--accent); font-weight: 600; }
.banner.warn { background: rgba(245,147,62,0.15); color: var(--amber-text); }
.hero-card { background: linear-gradient(135deg, var(--accent), var(--green)); color: #fff; border-radius: 18px; padding: 14px; margin-bottom: 12px; }
.hero-card .muted, .hero-card .small { color: rgba(255,255,255,0.85); }
.score-circle { width: 46px; height: 46px; border-radius: 50%; background: var(--tint); color: var(--accent); font-weight: 700; display: flex; align-items: center; justify-content: center; flex: none; }
.row3 { display: flex; gap: 8px; margin-bottom: 12px; }
.row3 .card { flex: 1; text-align: center; margin: 0; padding: 10px 6px; }
.ach-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.ach { background: var(--card); border-radius: 14px; padding: 10px 6px; text-align: center; font-size: 11px; line-height: 1.25; }
.ach .ach-ico { font-size: 22px; margin-bottom: 4px; }
.ach.locked { opacity: 0.45; }
.set-row { display: flex; gap: 6px; align-items: center; margin-top: 6px; }
.set-row .input { margin: 0; padding: 9px; text-align: center; }
.set-row .set-num { width: 34px; font-size: 12px; color: var(--muted); flex: none; }
.set-done-btn { width: 40px; height: 38px; border-radius: 10px; border: none; background: var(--tint); color: var(--accent); font-size: 16px; cursor: pointer; flex: none; }
.set-done-btn.done { background: var(--green); color: #fff; }
.ex-card { background: var(--card); border-radius: 14px; padding: 12px; margin-bottom: 10px; }
.delta-chip { background: rgba(245,147,62,0.15); color: var(--amber-text); border-radius: 12px; font-size: 11px; font-weight: 700; padding: 3px 8px; }

#tabs {
  position: fixed; bottom: 0; left: 0; right: 0; max-width: 520px; margin: 0 auto;
  display: flex; background: var(--card); border-top: 0.5px solid rgba(128,128,128,0.2);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab { flex: 1; border: none; background: none; padding: 8px 0 9px; font-size: 19px; color: var(--muted); cursor: pointer; }
.tab span { display: block; font-size: 10px; margin-top: 1px; }
.tab.active { color: var(--accent); font-weight: 600; }
