@font-face {
  font-family: "Vazirmatn";
  font-weight: 100 900;
  font-display: swap;
  src: url("/fonts/vazirmatn-arabic-wght-normal.woff2") format("woff2-variations");
  unicode-range: U+0600-06FF, U+0750-077F, U+FB50-FDFF, U+FE70-FEFC, U+200C-200F;
}
@font-face {
  font-family: "Vazirmatn";
  font-weight: 100 900;
  font-display: swap;
  src: url("/fonts/vazirmatn-latin-wght-normal.woff2") format("woff2-variations");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  --bg: #0b0f14;
  --surface: #131a23;
  --surface-2: #1b2531;
  --line: #243142;
  --text: #f3f6fa;
  --muted: #8b9bb0;
  --accent: #b6f23a;
  --accent-2: #22d98a;
  --accent-grad: linear-gradient(135deg, #b6f23a 0%, #22d98a 100%);
  --on-accent: #0b1a05;
  --energy: #ff8a3d;
  --cool: #4cc9f0;
  --danger: #ff6b6b;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --radius: 20px;
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f2f5f9;
    --surface: #ffffff;
    --surface-2: #eef2f7;
    --line: #dde5ee;
    --text: #0e1621;
    --muted: #60718a;
    --accent: #5fb800;
    --accent-2: #12b76a;
    --accent-grad: linear-gradient(135deg, #8fdc1c 0%, #12b76a 100%);
    --on-accent: #06210f;
    --energy: #ef6c14;
    --cool: #0b8fb8;
    --danger: #e03131;
    --shadow: 0 10px 30px rgba(20, 40, 70, 0.1);
    color-scheme: light;
  }
}

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

html { background: var(--bg); }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.7 "Vazirmatn", Tahoma, "Segoe UI", system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
}

#app {
  max-width: 640px;
  margin: 0 auto;
  padding: 18px 16px calc(110px + env(safe-area-inset-bottom));
}

h1 { font-size: 1.55rem; font-weight: 800; margin: 6px 0 2px; line-height: 1.4; }
h2 { font-size: 1.05rem; font-weight: 700; margin: 0 0 12px; line-height: 1.5; }
h3 { font-size: 0.95rem; font-weight: 700; margin: 16px 0 6px; color: var(--accent); }
p { margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.center { text-align: center; }
.error { color: var(--danger); }
.num { font-feature-settings: "tnum"; }

/* ---------- cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  margin: 14px 0;
}

.hero {
  position: relative;
  overflow: hidden;
  border-radius: 28px;
  padding: 20px;
  margin: 14px 0;
  background:
    radial-gradient(120% 90% at 0% 0%, rgba(182, 242, 58, 0.22), transparent 55%),
    radial-gradient(90% 90% at 100% 100%, rgba(34, 217, 138, 0.18), transparent 60%),
    var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}
.hero .row { align-items: center; gap: 18px; }

.topbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 4px; }
.topbar .date { color: var(--muted); font-size: 0.9rem; }
.avatar {
  width: 44px; height: 44px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--accent-grad); color: var(--on-accent);
  font-weight: 800; font-size: 1.1rem; flex: none;
}

/* ---------- progress ring ---------- */
.ring { position: relative; width: 128px; height: 128px; flex: none; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); direction: ltr; }
.ring .track { fill: none; stroke: var(--surface-2); stroke-width: 11; }
.ring .bar { fill: none; stroke: url(#ringGrad); stroke-width: 11; stroke-linecap: round; transition: stroke-dashoffset 0.6s ease; }
.ring .bar.over { stroke: var(--energy); }
.ring .label { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; line-height: 1.25; }
.ring .big { font-size: 1.5rem; font-weight: 800; }
.ring .cap { font-size: 0.72rem; color: var(--muted); }

/* ---------- stat tiles ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin: 12px 0; }
.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 14px;
}
.stat .ico { font-size: 1.3rem; }
.stat .label { color: var(--muted); font-size: 0.78rem; margin-top: 2px; }
.stat .value { font-size: 1.05rem; font-weight: 700; line-height: 1.5; }
.stat .hint { color: var(--muted); font-size: 0.8rem; }
.stat .btn { margin-top: 8px; }

/* ---------- layout helpers ---------- */
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.spread { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 10px; }

/* ---------- forms ---------- */
label { display: block; font-size: 0.85rem; color: var(--muted); margin: 12px 0 5px; }
input, select, textarea {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: var(--surface-2);
  border: 1.5px solid transparent;
  border-radius: 14px;
  padding: 11px 14px;
  min-height: 46px;
}
input.ltr, input[name="username"], input[name="password"], input[name="invite"] { direction: ltr; text-align: right; }
.stop-a { stop-color: var(--accent); }
.stop-b { stop-color: var(--accent-2); }
::placeholder { color: var(--muted); opacity: 0.8; }
textarea { resize: vertical; min-height: 78px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }

.btn {
  font: inherit;
  font-weight: 700;
  border: 0;
  border-radius: 14px;
  padding: 11px 18px;
  min-height: 46px;
  background: var(--accent-grad);
  color: var(--on-accent);
  cursor: pointer;
  transition: transform 0.12s, opacity 0.12s;
}
.btn:active:not(:disabled) { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn:focus-visible, #nav button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn.secondary { background: var(--surface-2); color: var(--text); }
.btn.small { min-height: 38px; padding: 6px 14px; font-size: 0.85rem; border-radius: 12px; }
.btn.block { width: 100%; }
.btn.big { min-height: 54px; font-size: 1.05rem; border-radius: 16px; }
.icon-btn {
  font: inherit;
  background: none;
  border: 0;
  color: var(--muted);
  cursor: pointer;
  width: 36px; height: 36px;
  border-radius: 10px;
  flex: none;
}
.icon-btn:hover { color: var(--danger); background: var(--surface-2); }

/* ---------- lists ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; gap: 10px; align-items: flex-start; padding: 11px 0; border-top: 1px solid var(--line); }
.list li:first-child { border-top: 0; }
.tag {
  flex: none;
  min-width: 74px;
  text-align: center;
  font-size: 0.74rem;
  font-weight: 700;
  color: var(--accent);
  background: rgba(182, 242, 58, 0.12);
  border-radius: 999px;
  padding: 2px 10px;
  margin-top: 2px;
}
.step {
  flex: none;
  width: 28px; height: 28px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--surface-2);
  color: var(--accent);
  font-weight: 800; font-size: 0.85rem;
}
.badge {
  display: inline-block;
  background: var(--accent-grad);
  color: var(--on-accent);
  font-weight: 700;
  font-size: 0.78rem;
  padding: 2px 12px;
  border-radius: 999px;
}

/* ---------- chips (gym days) ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { position: relative; }
.chip input { position: absolute; opacity: 0; inset: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; min-height: 0; }
.chip span {
  display: block;
  padding: 9px 16px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.9rem;
  border: 1.5px solid transparent;
}
.chip input:checked + span { background: var(--accent-grad); color: var(--on-accent); font-weight: 700; }
.chip input:focus-visible + span { border-color: var(--accent); }

.banner {
  background: linear-gradient(135deg, rgba(182, 242, 58, 0.14), rgba(34, 217, 138, 0.1));
  border: 1px solid var(--accent);
  border-radius: 18px;
  padding: 14px 16px;
  margin: 14px 0;
}
.banner p:last-child { margin-bottom: 0; }

.tabs { display: flex; gap: 8px; margin: 14px 0 4px; background: var(--surface); padding: 5px; border-radius: 16px; border: 1px solid var(--line); }
.tabs button { flex: 1; min-height: 42px; }
.tabs .btn.secondary { background: transparent; color: var(--muted); }

details.plan { margin: 10px 0; }
details.plan summary { cursor: pointer; color: var(--accent); font-weight: 700; padding: 4px 0; }

.day h2 { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.day .sub { color: var(--muted); font-weight: 500; font-size: 0.88rem; }

/* ---------- chart ---------- */
svg.chart { width: 100%; height: auto; display: block; direction: ltr; }
svg.chart .grid-line { stroke: var(--line); stroke-width: 1; stroke-dasharray: 3 4; }
svg.chart .line { fill: none; stroke: url(#lineGrad); stroke-width: 3; stroke-linejoin: round; stroke-linecap: round; }
svg.chart .area { fill: url(#areaGrad); }
svg.chart .dot { fill: var(--bg); stroke: var(--accent); stroke-width: 2; }
svg.chart text { fill: var(--muted); font-size: 11px; font-family: inherit; }

/* ---------- bottom navigation ---------- */
#nav {
  position: fixed;
  inset-inline: 12px;
  bottom: calc(12px + env(safe-area-inset-bottom));
  max-width: 616px;
  margin: 0 auto;
  display: flex;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--line);
  border-radius: 26px;
  padding: 6px;
  box-shadow: var(--shadow);
}
#nav button {
  flex: 1;
  font: inherit;
  font-size: 0.75rem;
  background: none;
  border: 0;
  color: var(--muted);
  padding: 8px 4px;
  border-radius: 20px;
  cursor: pointer;
  display: grid;
  justify-items: center;
  gap: 2px;
}
#nav button svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
#nav button[aria-current="page"] { background: var(--accent-grad); color: var(--on-accent); font-weight: 700; }

/* ---------- toast ---------- */
#toast {
  position: fixed;
  left: 50%;
  bottom: calc(104px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: min(92vw, 480px);
  background: var(--text);
  color: var(--bg);
  padding: 12px 18px;
  border-radius: 14px;
  font-size: 0.92rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  z-index: 10;
}
#toast.show { opacity: 1; }
#toast.bad { background: var(--danger); color: #fff; }

/* ---------- sign-in ---------- */
.auth { padding-top: 5vh; }
.auth .card .row { margin-top: 20px; }
.auth .logo {
  width: 84px; height: 84px; margin: 0 auto 10px;
  border-radius: 26px;
  display: grid; place-items: center;
  background: var(--accent-grad);
  font-size: 2.6rem;
  box-shadow: 0 12px 30px rgba(34, 217, 138, 0.3);
}
.auth h1 { text-align: center; font-size: 1.9rem; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* ---------- plan day picker, segmented choices, activity form ---------- */
.chip-row { display: flex; gap: 8px; overflow-x: auto; padding: 4px 2px 10px; scroll-snap-type: x proximity; }
.chip-btn {
  flex: none;
  scroll-snap-align: start;
  display: grid;
  gap: 0;
  min-width: 74px;
  padding: 8px 12px;
  border-radius: 16px;
  border: 1.5px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  font: inherit;
  text-align: center;
  cursor: pointer;
}
.chip-btn b { font-size: 0.9rem; font-weight: 700; }
.chip-btn small { font-size: 0.75rem; }
.chip-btn.on { background: var(--accent-grad); color: var(--on-accent); border-color: transparent; }

.seg { display: flex; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: 14px; margin: 4px 0 8px; }
.seg button {
  flex: 1;
  font: inherit;
  font-size: 0.85rem;
  color: var(--muted);
  background: none;
  border: 0;
  border-radius: 11px;
  padding: 9px 6px;
  min-height: 40px;
  cursor: pointer;
}
.seg button.on { background: var(--accent-grad); color: var(--on-accent); font-weight: 700; }
.seg.small { margin: 0 0 12px; }
.seg.small button { min-height: 34px; padding: 6px 4px; font-size: 0.8rem; }

.badge.rest { background: var(--surface-2); color: var(--muted); }

details.more { margin: 10px 0; }
details.more summary { cursor: pointer; color: var(--accent); font-weight: 600; font-size: 0.9rem; padding: 4px 0; }
details.more .row { margin-top: 8px; }

a.btn { display: block; text-align: center; text-decoration: none; line-height: 1.7; }
.stack > a.btn, .stack > button.btn { width: 100%; }

/* inline editing of meals and activities */
.list li.editing { display: block; }
.edit-form { width: 100%; }
.edit-form .tag { display: inline-block; }
