:root {
  --bg: #f3f6f5;
  --card: #ffffff;
  --ink: #17302c;
  --muted: #5b6f6b;
  --line: #dfe7e5;
  --primary: #0f766e;
  --primary-ink: #ffffff;
  --primary-soft: #e0f2ef;
  --good: #15803d;
  --good-soft: #dcfce7;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --danger: #b91c1c;
  --danger-soft: #fee2e2;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(16, 40, 36, .06), 0 4px 14px rgba(16, 40, 36, .06);
  --font: 'Noto Sans Malayalam', 'Nirmala UI', 'Kartika', system-ui, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1716; --card: #152321; --ink: #e5efed; --muted: #9bb0ac; --line: #26403c;
    --primary: #2dd4bf; --primary-ink: #04201d; --primary-soft: #123b36;
    --good: #4ade80; --good-soft: #12301f; --warn: #fbbf24; --warn-soft: #33270b;
    --danger: #f87171; --danger-soft: #3a1414;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font); font-size: 17px; line-height: 1.6; -webkit-text-size-adjust: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--primary); }

/* ---- App shell ---- */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 10px; padding: 10px 16px; background: var(--card); border-bottom: 1px solid var(--line); }
.topbar .brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 1.1rem; flex: 1; min-width: 0; }
.topbar .brand img { width: 30px; height: 30px; }
.icon-btn { border: 0; background: transparent; font-size: 1.35rem; width: 44px; height: 44px; border-radius: 12px; cursor: pointer; }
.icon-btn:hover { background: var(--primary-soft); }
.sos { border: 0; background: var(--danger); color: #fff; font-weight: 700; border-radius: 999px; padding: 8px 14px; cursor: pointer; }
main { max-width: 760px; margin: 0 auto; padding: 16px 16px 110px; }
.bottomnav { position: fixed; bottom: 0; left: 0; right: 0; z-index: 20; display: grid; grid-template-columns: repeat(5, 1fr); background: var(--card); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.bottomnav a { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 2px 10px; text-decoration: none; color: var(--muted); font-size: .78rem; }
.bottomnav a span { font-size: 1.4rem; line-height: 1.2; }
.bottomnav a.active { color: var(--primary); font-weight: 700; }

/* ---- Building blocks ---- */
h1 { font-size: 1.45rem; margin: 4px 0 12px; }
h2 { font-size: 1.15rem; margin: 0 0 10px; }
h3 { font-size: 1rem; margin: 0 0 6px; }
.muted { color: var(--muted); font-size: .92rem; }
.small { font-size: .85rem; }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px; border: 1px solid var(--line); }
.card.tint { background: var(--primary-soft); border-color: transparent; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
@media (max-width: 420px) { .grid3 { grid-template-columns: 1fr 1fr; } }
.stack > * + * { margin-top: 10px; }
.tabs { display: flex; gap: 6px; overflow-x: auto; margin: 0 -16px 14px; padding: 0 16px; scrollbar-width: none; }
.tabs button { flex: none; border: 1px solid var(--line); background: var(--card); padding: 8px 14px; border-radius: 999px; cursor: pointer; white-space: nowrap; }
.tabs button.active { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); font-weight: 700; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 0; border-radius: 12px; padding: 12px 18px; min-height: 48px; background: var(--primary); color: var(--primary-ink); font-weight: 700; cursor: pointer; text-decoration: none; }
.btn.secondary { background: var(--primary-soft); color: var(--primary); }
.btn.ghost { background: transparent; color: var(--primary); border: 1px solid var(--line); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.block { width: 100%; }
.btn.sm { min-height: 38px; padding: 6px 12px; font-size: .9rem; border-radius: 10px; }
.btn:disabled { opacity: .55; cursor: wait; }

label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: .9rem; color: var(--muted); margin-bottom: 4px; }
input[type=text], input[type=number], input[type=password], input[type=date], input[type=time], input[type=tel], select, textarea {
  width: 100%; padding: 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); min-height: 48px;
}
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: 1px; }

.chip { display: inline-flex; align-items: center; gap: 4px; padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--card); cursor: pointer; margin: 0 6px 8px 0; user-select: none; }
.chip.on { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .8rem; font-weight: 700; }
.badge.good { background: var(--good-soft); color: var(--good); }
.badge.limit, .badge.moderate, .badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.avoid, .badge.danger, .badge.high, .badge.low { background: var(--danger-soft); color: var(--danger); }
.badge.normal { background: var(--good-soft); color: var(--good); }
.badge.unknown { background: var(--line); color: var(--muted); }

.alert { border-radius: 12px; padding: 12px 14px; margin: 10px 0; font-weight: 600; }
.alert.danger { background: var(--danger-soft); color: var(--danger); border-left: 5px solid var(--danger); }
.alert.warn { background: var(--warn-soft); color: var(--warn); border-left: 5px solid var(--warn); }
.alert.good { background: var(--good-soft); color: var(--good); border-left: 5px solid var(--good); }

.stat { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px; }
.stat .k { font-size: .82rem; color: var(--muted); }
.stat .v { font-size: 1.35rem; font-weight: 800; line-height: 1.3; }
.stat .s { font-size: .8rem; color: var(--muted); }
.meter { height: 10px; background: var(--line); border-radius: 99px; overflow: hidden; margin-top: 6px; }
.meter > i { display: block; height: 100%; background: var(--primary); border-radius: 99px; }
.meter.over > i { background: var(--danger); }

.list-item { display: flex; gap: 12px; align-items: flex-start; padding: 12px 0; border-bottom: 1px solid var(--line); }
.list-item:last-child { border-bottom: 0; }
.list-item .grow { flex: 1; min-width: 0; }
.emoji { font-size: 1.6rem; line-height: 1.2; }

.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.tile { display: flex; flex-direction: column; gap: 4px; padding: 14px; border-radius: 14px; background: var(--card); border: 1px solid var(--line); cursor: pointer; text-align: left; box-shadow: var(--shadow); }
.tile .emoji { font-size: 1.8rem; }
.tile b { font-size: 1rem; }
.tile small { color: var(--muted); }

table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; }

/* ---- Chat ---- */
.chat { display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 88%; padding: 10px 14px; border-radius: 16px; white-space: pre-wrap; word-wrap: break-word; }
.msg.user { align-self: flex-end; background: var(--primary); color: var(--primary-ink); border-bottom-right-radius: 4px; }
.msg.assistant { align-self: flex-start; background: var(--card); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg .tools { margin-top: 6px; display: flex; gap: 6px; }
.composer { position: fixed; left: 0; right: 0; bottom: 64px; z-index: 15; background: var(--bg); padding: 8px 16px; border-top: 1px solid var(--line); }
.composer .inner { max-width: 760px; margin: 0 auto; display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { min-height: 48px; max-height: 140px; flex: 1; }
.typing::after { content: '▍'; animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: 0; } }

/* ---- Breathing ---- */
.breath-wrap { display: grid; place-items: center; padding: 20px 0; }
.breath-circle { width: 200px; height: 200px; border-radius: 50%; background: radial-gradient(circle, var(--primary-soft), var(--primary)); display: grid; place-items: center; color: var(--primary-ink); font-weight: 800; font-size: 1.2rem; text-align: center; transform: scale(.6); transition-property: transform; transition-timing-function: ease-in-out; }
.timer { font-size: 3rem; font-weight: 800; text-align: center; font-variant-numeric: tabular-nums; }

/* ---- Charts ---- */
.chart { width: 100%; height: auto; display: block; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .line { fill: none; stroke: var(--primary); stroke-width: 2.5; }
.chart .line2 { fill: none; stroke: var(--warn); stroke-width: 2.5; }
.chart .band { fill: var(--good-soft); }
.chart text { fill: var(--muted); font-size: 11px; font-family: system-ui, sans-serif; }
.chart circle { fill: var(--card); stroke: var(--primary); stroke-width: 2; }
.chart circle.bad { stroke: var(--danger); fill: var(--danger); }

/* ---- Exercise demo figures ---- */
.demo { display: block; background: var(--primary-soft); border-radius: 14px; flex: none; }
.demo .fig polyline { fill: none; stroke: var(--primary); stroke-width: 7; stroke-linecap: round; stroke-linejoin: round; }
.demo .fig polyline.far { opacity: .45; }
.demo .fig circle { fill: var(--primary); }
.demo .prop path { fill: none; stroke: var(--muted); stroke-width: 4; stroke-linecap: round; opacity: .55; }
.demo-big { display: grid; place-items: center; margin: 8px 0; }

/* ---- Voice assistant ---- */
.voice-fab { position: fixed; right: 16px; bottom: 80px; z-index: 25; width: 60px; height: 60px; border-radius: 50%; border: 0; background: var(--primary); color: var(--primary-ink); font-size: 1.7rem; box-shadow: 0 6px 18px rgba(0,0,0,.25); cursor: pointer; }
body.on-advisor .voice-fab { bottom: 150px; }
.voice-screen { position: fixed; inset: 0; z-index: 70; background: linear-gradient(180deg, #0b3b37, #072523); color: #e7fffb; display: flex; flex-direction: column; align-items: center; justify-content: space-between; padding: 28px 20px calc(28px + env(safe-area-inset-bottom)); text-align: center; }
.voice-orb { width: 170px; height: 170px; border-radius: 50%; background: radial-gradient(circle at 35% 35%, #5eead4, #0f766e 60%, #064e47); box-shadow: 0 0 60px rgba(94, 234, 212, .35); transition: transform .3s; }
.voice-screen[data-state="listening"] .voice-orb { animation: pulse 1.4s ease-in-out infinite; }
.voice-screen[data-state="thinking"] .voice-orb { animation: spin 2.2s linear infinite; background: conic-gradient(#5eead4, #0f766e, #a7f3d0, #5eead4); }
.voice-screen[data-state="speaking"] .voice-orb { animation: talk .5s ease-in-out infinite alternate; }
@keyframes pulse { 50% { transform: scale(1.12); box-shadow: 0 0 90px rgba(94,234,212,.6); } }
@keyframes talk { to { transform: scale(1.06); } }
.voice-state { font-size: 1.3rem; font-weight: 800; margin-top: 18px; }
.voice-text { max-width: 560px; max-height: 32vh; overflow: auto; font-size: 1.05rem; opacity: .92; white-space: pre-wrap; }
.voice-heard { opacity: .7; font-style: italic; min-height: 1.6em; }
.voice-screen .btn { min-width: 160px; }

/* ---- Modal ---- */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.modal { background: var(--card); width: 100%; max-width: 760px; max-height: 92vh; overflow: auto; border-radius: 20px 20px 0 0; padding: 20px 16px calc(20px + env(safe-area-inset-bottom)); }
@media (min-width: 700px) { .modal-bg { align-items: center; } .modal { border-radius: 20px; } }

.toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 12px; z-index: 60; max-width: 90vw; }
.spinner { width: 22px; height: 22px; border: 3px solid var(--primary-soft); border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }
.preview-img { max-width: 100%; max-height: 260px; border-radius: 12px; display: block; margin: 8px 0; }
.md p { margin: 0 0 8px; } .md ul { margin: 0 0 8px; padding-left: 20px; } .md h3, .md h4 { margin: 10px 0 4px; }

@media print {
  .topbar, .bottomnav, .composer, .no-print, .voice-fab { display: none !important; }
  body:has(.modal-bg) main { display: none; }
  .modal-bg { position: static; background: none; display: block; }
  .modal { max-height: none; overflow: visible; border-radius: 0; }
  main { padding: 0; } .card { box-shadow: none; }
}
