:root {
  --brand: #0F4C5C;
  --brand-soft: #D4E4E1;
  --ink: #1c2420;
  --muted: #66716b;
  --bg: #f5f6f2;
  --card: #ffffff;
  --line: #e2e5df;
  --danger: #a3271f;
  --radius: 14px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }

h1 { font-size: 1.35rem; margin: 0 0 4px; }
h2 { font-size: 1.05rem; margin: 0 0 10px; }
h3 { font-size: 0.8rem; margin: 14px 0 6px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
p { margin: 0 0 8px; }
small { color: var(--muted); font-size: 0.82rem; }
.muted { color: var(--muted); font-size: 0.9rem; }
.note { color: var(--brand); font-size: 0.9rem; margin: 10px 0 0; }

.topbar {
  padding: calc(env(safe-area-inset-top) + 12px) 16px 10px;
  background: var(--brand);
  color: #fff;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}
.brand { font-weight: 700; letter-spacing: 0.02em; }
.tagline { font-size: 0.8rem; opacity: 0.85; }

main {
  max-width: 520px;
  margin: 0 auto;
  padding: 12px 16px calc(env(safe-area-inset-bottom) + 90px);
}

/* Date bar */
.datebar { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.datebar > button {
  width: 44px; height: 44px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--card); font-size: 1.4rem; line-height: 1;
}
.datebar > button:disabled { opacity: 0.35; }
.datepick {
  position: relative; flex: 1; height: 44px; display: grid; place-items: center;
  border: 1px solid var(--line); border-radius: 22px; background: var(--card); font-weight: 600;
}
.datepick input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; }

/* Cards */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin-bottom: 12px;
}
.mission { display: flex; align-items: center; gap: 16px; }
.mission p { margin: 0; color: var(--muted); }
.xp { color: var(--brand) !important; font-weight: 700; }
.xp.big { font-size: 1.8rem; }

.ring {
  --pct: 0;
  width: 84px; height: 84px; border-radius: 50%; flex: none;
  background: conic-gradient(var(--brand) calc(var(--pct) * 1%), var(--brand-soft) 0);
  display: grid; place-items: center;
}
.ring span {
  width: 64px; height: 64px; border-radius: 50%; background: var(--card);
  display: grid; place-items: center; font-weight: 700;
}

/* Checkpoint list */
.group { margin: 16px 4px 8px; font-size: 0.8rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; }
.list { display: grid; gap: 8px; margin-bottom: 12px; }
.cp {
  display: flex; align-items: center; gap: 12px; width: 100%; min-height: 60px;
  padding: 10px 14px; text-align: left;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
}
.cp.stacked { display: block; }
.cp-head { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.cp.done { border-color: var(--brand); background: var(--brand-soft); }
.cp-text { flex: 1; display: grid; }
.tick {
  width: 26px; height: 26px; flex: none; border-radius: 50%;
  border: 2px solid var(--line); display: grid; place-items: center;
  font-size: 0.9rem; font-weight: 700; color: #fff;
}
.done .tick { background: var(--brand); border-color: var(--brand); }
.go { color: var(--muted); font-size: 1.4rem; }

/* Option buttons */
.options { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.options.four { grid-template-columns: repeat(4, 1fr); }
.options.three { grid-template-columns: repeat(3, 1fr); margin-bottom: 12px; }
.option {
  min-height: 44px; padding: 8px 10px; display: grid; place-items: center; text-align: center;
  border: 1px solid var(--line); border-radius: 10px; background: var(--card); font-size: 0.92rem; cursor: pointer;
}
.option.selected { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
.option:disabled { opacity: 0.4; }

/* Forms */
input[type="number"], input[type="search"], input:not([type]), input[type="text"], select {
  width: 100%; min-height: 44px; padding: 8px 12px;
  border: 1px solid var(--line); border-radius: 10px; background: #fff;
}
.weight-input { width: 96px !important; flex: none; text-align: right; }
.form { display: grid; gap: 10px; }
.form h1, .form h2, .form p { margin-bottom: 0; }
.fields { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.fields label { display: grid; gap: 4px; font-size: 0.82rem; color: var(--muted); }
.inline { display: flex; align-items: center; gap: 8px; font-size: 0.92rem; }
.inline input { width: 20px; height: 20px; }
.row { display: flex; align-items: center; gap: 10px; }
.row.spread { justify-content: space-between; margin-bottom: 8px; }

.primary, .danger, .plain {
  min-height: 44px; padding: 10px 16px; border-radius: 10px; border: 1px solid transparent; font-weight: 600;
}
.primary { background: var(--brand); color: #fff; flex: 1; }
.plain { background: none; color: var(--brand); padding-left: 0; }
.danger { background: none; border-color: var(--danger); color: var(--danger); width: 100%; }

/* Nutrition */
.macro { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; margin-bottom: 10px; font-size: 0.92rem; }
.bar { grid-column: 1 / -1; height: 6px; border-radius: 3px; background: var(--brand-soft); overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--brand); }
.item { display: flex; align-items: center; gap: 4px; border-top: 1px solid var(--line); }
.item-main {
  flex: 1; display: grid; text-align: left; padding: 10px 0; min-height: 44px;
  background: none; border: 0; min-width: 0;
}
.item-main strong { overflow-wrap: anywhere; }
.item-main.history { width: 100%; border-top: 1px solid var(--line); }
.icon { width: 44px; height: 44px; flex: none; background: none; border: 0; font-size: 1.3rem; color: var(--muted); }

.results { max-height: 320px; overflow-y: auto; }
.results h3 { margin-top: 8px; }
.meal-head { margin: 10px 0 0; }
.meal-head h3 { margin: 0; }
.meal-head .plain { min-height: 36px; padding: 4px 0; font-size: 0.85rem; }
.results:empty { display: none; }
.results .item-main { width: 100%; border-top: 1px solid var(--line); }
.picked { display: grid; gap: 8px; padding: 10px 12px; border-radius: 10px; background: var(--brand-soft); }
.picked .row { margin: 0; font-size: 0.92rem; }

/* Barcode scanner: full screen over the app */
.scanner {
  position: fixed; inset: 0; z-index: 30; background: #000; color: #fff;
  display: grid; grid-template-rows: auto 1fr auto; gap: 12px; align-items: center;
  padding: calc(env(safe-area-inset-top) + 16px) 16px calc(env(safe-area-inset-bottom) + 16px);
}
.scanner p { margin: 0; text-align: center; font-weight: 600; }
#scan-view { width: 100%; }
#scan-view video { width: 100%; border-radius: 12px; }

/* Progress */
.chart { width: 100%; height: auto; display: block; }
.chart polyline { fill: none; stroke: var(--brand); stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.chart-range { display: flex; justify-content: space-between; font-size: 0.78rem; color: var(--muted); }
.photos { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
/* Runs almost to the card's edges so the two photos are as large as the screen allows. */
.photos.compare { grid-template-columns: 1fr 1fr; gap: 4px; margin: 10px -12px 0; }
.photos.compare figcaption { justify-content: center; padding-top: 4px; font-weight: 600; }
.no-photo {
  aspect-ratio: 3 / 4; display: grid; place-items: center; text-align: center; padding: 8px;
  border: 1px dashed var(--line); border-radius: 10px; color: var(--muted); font-size: 0.85rem;
}
.photos figure { margin: 0; }
.photos img { width: 100%; aspect-ratio: 3 / 4; object-fit: cover; border-radius: 10px; display: block; }
.photos figcaption { display: flex; align-items: center; justify-content: space-between; font-size: 0.82rem; color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { min-height: 36px; padding: 6px 12px; border-radius: 18px; border: 1px solid var(--line); background: var(--card); font-size: 0.85rem; }
.chip.selected { background: var(--brand); border-color: var(--brand); color: #fff; }
.scroll { overflow-x: auto; }
table { border-collapse: collapse; font-size: 0.85rem; width: 100%; }
th, td { padding: 6px 10px 6px 0; text-align: left; white-space: nowrap; border-top: 1px solid var(--line); }
th { color: var(--muted); font-weight: 600; border-top: 0; }
.rules td:last-child { text-align: right; font-weight: 700; color: var(--brand); padding-right: 0; }
.rules td { white-space: normal; }

/* Training and achievements */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; text-align: center; }
.stats div { display: grid; padding: 10px 2px; border-radius: 10px; background: var(--brand-soft); }
.stats strong { font-size: 1.4rem; color: var(--brand); }
.stats span { font-size: 0.75rem; color: var(--muted); }
.badge { display: grid; gap: 4px; padding: 10px 0; border-top: 1px solid var(--line); }
.badge.earned strong { color: var(--brand); }

/* Monthly plan */
.calendar { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; margin-bottom: 10px; }
.dow { text-align: center; font-size: 0.72rem; color: var(--muted); }
.day {
  position: relative; aspect-ratio: 1; min-height: 40px; padding: 0;
  border: 1px solid var(--line); border-radius: 10px; background: var(--card); font-size: 0.92rem;
}
.day.gym { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 700; }
.day.rest { background: var(--brand-soft); border-color: var(--brand); }
.day.today { outline: 2px solid var(--ink); outline-offset: 1px; }
.day i { position: absolute; right: 3px; bottom: 1px; font-size: 0.62rem; font-style: normal; }
.legend { display: flex; gap: 14px; font-size: 0.8rem; color: var(--muted); margin-bottom: 6px; }
.legend span { display: flex; align-items: center; gap: 5px; }
.swatch { width: 14px; height: 14px; border-radius: 4px; border: 1px solid var(--brand); }
.swatch.gym { background: var(--brand); }
.swatch.rest { background: var(--brand-soft); }

/* Bottom tabs */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(6, 1fr);
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--card); border-top: 1px solid var(--line);
}
.tabs button {
  display: grid; justify-items: center; gap: 2px; padding: 8px 0 6px; min-height: 54px;
  background: none; border: 0; font-size: 0.66rem; color: var(--muted);
}
.tabs svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabs button[aria-current="page"] { color: var(--brand); font-weight: 700; }
