:root {
  --bg: #F7F4EF;
  --surface: #FFFFFF;
  --surface-2: #F0EBE3;
  --ink: #1C2B24;
  --ink-muted: #5A6B62;
  --brand: #2F4A3E;
  --brand-soft: #3D5C4E;
  --accent: #C4A574;
  --accent-soft: #E8D5B5;
  --success: #3D6B55;
  --warn: #A67C3D;
  --danger: #8B3A3A;
  --danger-bg: #F8EDED;
  --border: #E2DAD0;
  --shadow: 0 8px 28px rgba(28, 43, 36, 0.08);
  --radius: 18px;
  --nav-h: 72px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  min-height: 100%;
  background: #1C2B24;
  font-family: var(--font);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }
a { color: var(--brand); }

.app-shell {
  max-width: 390px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  position: relative;
  box-shadow: 0 0 0 1px rgba(255,255,255,0.05), 0 20px 60px rgba(0,0,0,0.35);
  display: flex;
  flex-direction: column;
}

.topbar {
  padding: 18px 20px 12px;
  background: linear-gradient(180deg, #2F4A3E 0%, #3A5748 100%);
  color: #F7F4EF;
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.brand-mark {
  display: flex; align-items: center; gap: 10px;
}
.brand-mark img { width: 36px; height: 36px; border-radius: 10px; }
.brand-text strong { display: block; font-size: 14px; letter-spacing: 0.02em; }
.brand-text span { display: block; font-size: 11px; opacity: 0.78; margin-top: 2px; }
.pill {
  font-size: 11px;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(232,213,181,0.18);
  color: var(--accent-soft);
  border: 1px solid rgba(232,213,181,0.28);
}

.main {
  flex: 1;
  padding: 16px 16px calc(var(--nav-h) + var(--safe-b) + 16px);
  overflow-y: auto;
}

.screen { display: none; animation: fadeIn 0.25s ease; }
.screen.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

h1 { font-size: 24px; line-height: 1.2; letter-spacing: -0.02em; margin-bottom: 6px; }
h2 { font-size: 18px; margin-bottom: 10px; }
h3 { font-size: 15px; margin-bottom: 8px; }
.lede { color: var(--ink-muted); font-size: 14px; line-height: 1.45; margin-bottom: 16px; }
.muted { color: var(--ink-muted); font-size: 13px; }
.tiny { font-size: 11px; color: var(--ink-muted); line-height: 1.4; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 12px;
}
.card.soft { background: var(--surface-2); box-shadow: none; }
.card.accent {
  background: linear-gradient(135deg, #2F4A3E, #456355);
  color: #F7F4EF;
  border: none;
}
.card.accent .muted { color: rgba(247,244,239,0.75); }
.card-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }

.chip, .quick-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 12px;
  color: var(--ink);
}
.quick-link {
  width: 100%;
  justify-content: center;
  padding: 14px 10px;
  border-radius: 14px;
  flex-direction: column;
  text-align: center;
  background: var(--surface);
  font-weight: 600;
  font-size: 12px;
}
.quick-link span { font-size: 20px; line-height: 1; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: 48px;
  padding: 12px 16px;
  border-radius: 14px;
  font-weight: 600;
  font-size: 14px;
  transition: transform 0.12s ease, opacity 0.12s ease;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--brand); color: #F7F4EF; }
.btn-secondary { background: var(--surface); border: 1px solid var(--border); color: var(--brand); }
.btn-ghost { background: transparent; color: var(--brand); border: 1px dashed var(--border); }
.btn-danger { background: var(--danger-bg); color: var(--danger); border: 1px solid #E8C8C8; }
.btn-row { display: grid; gap: 8px; margin-top: 12px; }
.btn-row.inline { grid-template-columns: 1fr 1fr; }

.field { margin-bottom: 12px; }
.field label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--ink);
}
.field input, .field select, .field textarea {
  width: 100%;
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 12px;
  padding: 12px 14px;
  outline: none;
}
.field textarea { min-height: 88px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--brand-soft);
  box-shadow: 0 0 0 3px rgba(47,74,62,0.12);
}

.check-grid { display: grid; gap: 8px; }
.check-item {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fff;
}
.check-item input { margin-top: 2px; accent-color: var(--brand); }

.segmented {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}
.segmented label {
  text-align: center;
  padding: 10px 0;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #fff;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.segmented input { display: none; }
.segmented input:checked + span,
.segmented label:has(input:checked) {
  background: var(--brand);
  color: #fff;
  border-color: var(--brand);
}

.progress {
  height: 10px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
  margin: 10px 0;
}
.progress > span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--brand));
  border-radius: inherit;
  width: 0%;
  transition: width 0.4s ease;
}

.stat {
  text-align: center;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
}
.stat strong { display: block; font-size: 22px; color: var(--brand); }
.stat span { font-size: 11px; color: var(--ink-muted); }

.list { display: grid; gap: 8px; }
.list-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 14px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 14px;
}
.list-item button {
  color: var(--danger);
  font-size: 12px;
  font-weight: 600;
}

.tip-card {
  cursor: pointer;
  transition: transform 0.12s ease;
}
.tip-card:active { transform: scale(0.99); }
.tip-tag {
  display: inline-block;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--brand);
  background: rgba(47,74,62,0.08);
  padding: 4px 8px;
  border-radius: 999px;
  margin-bottom: 8px;
}

.symptom-btn {
  width: 100%;
  text-align: left;
  padding: 14px 16px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 14px;
  margin-bottom: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 600;
  font-size: 14px;
}
.symptom-btn span { color: var(--ink-muted); font-weight: 400; }

.red-flag {
  background: var(--danger-bg);
  border: 1px solid #E8C8C8;
  border-radius: 14px;
  padding: 14px;
  margin: 12px 0;
}
.red-flag strong { color: var(--danger); display: block; margin-bottom: 6px; }
.red-flag ul { padding-left: 18px; font-size: 13px; color: var(--ink); }
.red-flag li { margin: 4px 0; }

.disclaimer {
  margin-top: 16px;
  padding: 12px;
  background: var(--surface-2);
  border-radius: 12px;
  font-size: 11px;
  color: var(--ink-muted);
  line-height: 1.45;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-h) + var(--safe-b) + 16px);
  transform: translateX(-50%) translateY(20px);
  max-width: 340px;
  width: calc(100% - 32px);
  background: var(--ink);
  color: #fff;
  padding: 12px 16px;
  border-radius: 14px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: all 0.25s ease;
  z-index: 50;
  text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.bottom-nav {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 0;
  width: 100%;
  max-width: 390px;
  height: calc(var(--nav-h) + var(--safe-b));
  padding: 8px 6px calc(8px + var(--safe-b));
  background: rgba(255,255,255,0.94);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  z-index: 30;
}
.nav-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-size: 9px;
  color: var(--ink-muted);
  font-weight: 600;
  border-radius: 12px;
}
.nav-btn .ico { font-size: 18px; line-height: 1; }
.nav-btn.active { color: var(--brand); background: rgba(47,74,62,0.08); }

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(28,43,36,0.45);
  z-index: 40;
  display: none;
  align-items: flex-end;
  justify-content: center;
}
.modal-backdrop.open { display: flex; }
.modal {
  width: 100%;
  max-width: 390px;
  max-height: 88vh;
  overflow: auto;
  background: var(--bg);
  border-radius: 24px 24px 0 0;
  padding: 20px 16px calc(24px + var(--safe-b));
}
.modal-handle {
  width: 40px; height: 4px; border-radius: 999px;
  background: var(--border); margin: 0 auto 14px;
}

.empty {
  text-align: center;
  padding: 24px 12px;
  color: var(--ink-muted);
  font-size: 13px;
}

.chart {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  height: 120px;
  padding: 8px 0;
}
.chart .bar {
  flex: 1;
  background: linear-gradient(180deg, var(--accent-soft), var(--brand));
  border-radius: 8px 8px 4px 4px;
  min-height: 8px;
  position: relative;
}
.chart .bar span {
  position: absolute;
  top: -18px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 9px;
  color: var(--ink-muted);
  white-space: nowrap;
}

@media (min-width: 420px) {
  body { padding: 24px 0; }
  .app-shell { min-height: calc(100vh - 48px); border-radius: 28px; overflow: hidden; }
  .bottom-nav { border-radius: 0 0 28px 28px; }
}
