:root {
  --bg: #0e1116;
  --card: #171b22;
  --card-2: #1f242d;
  --line: #2a303a;
  --text: #e8ebf0;
  --muted: #8b93a1;
  --accent: #b6f36a;
  --accent-ink: #14200a;
  --blue: #6aa8f3;
  --orange: #f3b36a;
  --pink: #f36aa8;
  --red: #f36a6a;
  --green: #6af3a0;
  --r: 16px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  padding: calc(var(--safe-t) + 8px) 16px calc(var(--safe-b) + 96px);
  max-width: 560px; margin: 0 auto; overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
h1 { font-size: 26px; margin: 8px 0 12px; letter-spacing: -0.02em; }
h2 { font-size: 17px; margin: 22px 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; align-items: center; gap: 10px; }
.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.center { text-align: center; }

.card { background: var(--card); border-radius: var(--r); padding: 16px; margin-bottom: 12px; }
.card.tight { padding: 12px 14px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 0; border-radius: 12px; padding: 12px 16px; background: var(--card-2);
  font-weight: 600; min-height: 46px;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.danger { background: transparent; color: var(--red); border: 1px solid #3a2226; }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.block { width: 100%; }
.btn.big { min-height: 58px; font-size: 17px; border-radius: 14px; }
.btn:disabled { opacity: .5; }
.btns { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.btns .span2 { grid-column: span 2; }

input, select, textarea {
  background: var(--card-2); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; width: 100%; min-height: 44px; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { min-height: 80px; resize: vertical; }
label { display: block; font-size: 13px; color: var(--muted); margin: 10px 0 4px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.field-row.three { grid-template-columns: 1fr 1fr 1fr; }

/* date bar */
.datebar { display: flex; align-items: center; justify-content: space-between; margin: 4px 0 12px; }
.datebar button { background: var(--card); border: 0; width: 44px; height: 44px; border-radius: 12px; font-size: 22px; }
.datebar .title { font-weight: 700; font-size: 20px; text-align: center; }
.datebar .sub { font-size: 12px; color: var(--muted); font-weight: 400; }

/* summary */
.summary { display: flex; gap: 16px; align-items: center; }
.ring { width: 118px; height: 118px; flex: none; position: relative; }
.ring svg { transform: rotate(-90deg); }
.ring .inner { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.ring .big { font-size: 24px; font-weight: 800; letter-spacing: -0.02em; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; flex: 1; }
.stat .v { font-size: 18px; font-weight: 700; }
.stat .l { font-size: 12px; color: var(--muted); }
.pos { color: var(--green); }
.neg { color: var(--red); }

.macros { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: 14px; }
.macro .top { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); }
.macro .top b { color: var(--text); font-weight: 600; }
.bar { height: 6px; border-radius: 3px; background: var(--card-2); overflow: hidden; margin-top: 5px; }
.bar i { display: block; height: 100%; border-radius: 3px; }

/* meals */
.meal { display: flex; gap: 12px; align-items: center; padding: 10px; background: var(--card); border-radius: 14px; margin-bottom: 8px; width: 100%; border: 0; text-align: left; }
.meal .thumb { width: 56px; height: 56px; border-radius: 10px; background: var(--card-2) center/cover; flex: none; display: grid; place-content: center; font-size: 22px; }
.meal .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meal .kcal { font-weight: 700; font-size: 17px; text-align: right; }
.pfc { font-size: 12px; color: var(--muted); }
.pfc .p { color: var(--blue); } .pfc .c { color: var(--orange); } .pfc .f { color: var(--pink); }
.empty { color: var(--muted); text-align: center; padding: 26px 10px; }

/* item editor */
.item { background: var(--card-2); border-radius: 12px; padding: 10px; margin-bottom: 8px; }
.item .nums { display: grid; grid-template-columns: 1.3fr 1fr 1fr 1fr; gap: 6px; margin-top: 6px; }
.item .nums label { margin: 0 0 2px; font-size: 11px; }
.item input { min-height: 38px; padding: 6px 8px; }
.x { background: none; border: 0; color: var(--muted); font-size: 20px; width: 36px; height: 36px; flex: none; }

/* templates grid */
.tgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tcard { background: var(--card); border: 0; border-radius: var(--r); padding: 0; text-align: left; display: flex; flex-direction: column; overflow: hidden; }
.thero { height: 104px; background: var(--card-2) center 30% / cover; display: flex; align-items: flex-end; padding: 10px 14px 4px; }
.tcard .tname { font-size: 21px; font-weight: 800; text-shadow: 0 1px 8px rgba(0,0,0,.7); }
.tbody { padding: 4px 14px 14px; flex: 1; display: flex; flex-direction: column; }
.tcard .tlist { font-size: 12px; color: var(--muted); flex: 1; }
.tcard .tlast { font-size: 12px; color: var(--accent); margin-top: 8px; }

/* active workout */
.wo-head { position: sticky; top: 0; z-index: 5; background: var(--bg); padding: calc(var(--safe-t) + 6px) 0 8px; margin-top: calc(-1 * var(--safe-t) - 8px); }
.elapsed { font-variant-numeric: tabular-nums; color: var(--accent); font-weight: 700; }
.ex { background: var(--card); border-radius: var(--r); padding: 14px; margin-bottom: 12px; }
.ex-title { font-weight: 700; font-size: 17px; }
.ex-last { font-size: 12px; color: var(--muted); margin: 2px 0 8px; }
.set { display: grid; grid-template-columns: 28px 1fr 14px 1fr 54px; gap: 6px; align-items: center; margin-bottom: 6px; }
.set.cardio { grid-template-columns: 1fr 1fr 1fr 54px; }
.set .no { color: var(--muted); font-weight: 700; text-align: center; }
.set .times { color: var(--muted); text-align: center; }
.set input { text-align: center; font-size: 18px; font-weight: 600; min-height: 48px; padding: 6px; font-variant-numeric: tabular-nums; }
.set .unit { font-size: 10px; color: var(--muted); text-align: center; margin-top: 2px; }
.tick { height: 48px; border-radius: 12px; border: 2px solid var(--line); background: transparent; font-size: 22px; color: var(--muted); }
.set.done .tick { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.set.done input { border-color: #3d5226; background: #1c2416; }
.set-labels { display: grid; grid-template-columns: 28px 1fr 14px 1fr 54px; gap: 6px; font-size: 11px; color: var(--muted); text-align: center; margin-bottom: 4px; }
.set-labels.cardio { grid-template-columns: 1fr 1fr 1fr 54px; }
.set.cardio.incl, .set-labels.cardio.incl { grid-template-columns: 1fr 1fr 1fr 1fr 50px; gap: 5px; }
.set.cardio.incl input { font-size: 16px; padding: 4px; }
.ex-actions { display: flex; gap: 8px; margin-top: 8px; }
.ex-actions .btn { flex: 1; min-height: 40px; padding: 8px; font-size: 14px; }

/* template editor */
.seg { display: flex; background: var(--card); border-radius: 12px; padding: 4px; margin-bottom: 12px; }
.seg button { flex: 1; border: 0; background: transparent; padding: 10px 4px; border-radius: 9px; font-weight: 600; color: var(--muted); }
.seg button.on { background: var(--card-2); color: var(--text); }
.te { background: var(--card); border-radius: 14px; padding: 10px; margin-bottom: 8px; }
.te .nums { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: 6px; }
.te .nums.two { grid-template-columns: 1fr 1fr; }
.te .nums label { margin: 0 0 2px; font-size: 11px; }
.te input { min-height: 40px; }
.te .ord { display: flex; gap: 2px; }

/* history */
.chart { display: flex; align-items: center; height: 140px; gap: 2px; position: relative; }
.chart .col { flex: 1; height: 100%; display: flex; flex-direction: column; }
.chart .up, .chart .down { flex: 1; display: flex; }
.chart .up { align-items: flex-end; }
.chart .down { align-items: flex-start; }
.chart .up i, .chart .down i { display: block; width: 100%; border-radius: 3px; }
.chart .up i { background: var(--green); }
.chart .down i { background: var(--red); }
.chart::after { content: ""; position: absolute; left: 0; right: 0; top: 50%; border-top: 1px dashed var(--line); }
.day { display: flex; align-items: center; gap: 10px; padding: 12px 4px; border-bottom: 1px solid var(--line); background: none; border-left: 0; border-right: 0; border-top: 0; width: 100%; text-align: left; }
.tag { display: inline-block; font-size: 11px; padding: 2px 7px; border-radius: 99px; background: var(--card-2); color: var(--accent); margin-right: 4px; }

/* tabs */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; justify-content: space-around; background: rgba(14, 17, 22, .92);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line); padding: 6px 8px calc(var(--safe-b) + 6px);
}
.tabs button { background: none; border: 0; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; padding: 4px 12px; min-width: 64px; }
.tabs button svg { width: 24px; height: 24px; fill: currentColor; }
.tabs button.on { color: var(--accent); }

/* rest timer */
.rest {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--safe-b) + 72px); z-index: 21;
  background: var(--card-2); border: 1px solid var(--line); border-radius: 99px; padding: 8px 8px 8px 18px;
  display: flex; align-items: center; gap: 10px; box-shadow: 0 8px 30px rgba(0,0,0,.5);
}
.rest b { font-variant-numeric: tabular-nums; font-size: 18px; }
.rest button { background: var(--card); border: 0; border-radius: 99px; padding: 6px 12px; color: var(--muted); }
.rest.go { background: var(--accent); color: var(--accent-ink); }

/* sheet */
.sheet { position: fixed; inset: 0; z-index: 30; background: rgba(0,0,0,.6); display: flex; align-items: flex-end; justify-content: center; }
.sheet-body {
  background: var(--card); width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto;
  border-radius: 20px 20px 0 0; padding: 18px 16px calc(var(--safe-b) + 18px);
  animation: up .2s ease-out;
}
.sheet-body h2 { margin-top: 0; }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
.preview { width: 100%; max-height: 260px; object-fit: cover; border-radius: 14px; display: block; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); top: calc(var(--safe-t) + 12px); z-index: 40;
  background: var(--card-2); border: 1px solid var(--line); padding: 10px 16px; border-radius: 12px; max-width: 90vw;
}
.toast.err { border-color: var(--red); color: #ffb3b3; }

.spinner { width: 34px; height: 34px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; margin: 20px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

.login { min-height: 80vh; display: grid; place-content: center; gap: 14px; text-align: center; }
.login .logo { font-size: 34px; font-weight: 900; letter-spacing: -0.03em; }
.login .logo span { color: var(--accent); }
.switch { display: flex; align-items: center; justify-content: space-between; padding: 8px 0; }
.switch input { width: 48px; min-height: 28px; accent-color: var(--accent); }

/* photos */
.ex-head { display: flex; gap: 12px; align-items: center; margin-bottom: 8px; }
.ex-head .ex-last { margin: 2px 0 0; }
.ex-thumb, .te-thumb { flex: none; border: 0; border-radius: 12px; background: var(--card-2) center / cover; color: var(--muted); font-size: 20px; }
.ex-thumb { width: 64px; height: 64px; }
.te-thumb { width: 44px; height: 44px; }
.ex-thumb.none, .te-thumb.none { border: 1px dashed var(--line); }
.ex-imgs { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }
.ex-imgs figure, figure.ref { margin: 0; }
.ex-imgs img { width: 100%; aspect-ratio: 3 / 2; object-fit: cover; border-radius: 12px; display: block; background: var(--card-2); }
figcaption { font-size: 11px; color: var(--muted); margin-top: 4px; text-align: center; }
figure.ref { margin-top: 10px; }
.chip { display: inline-block; font-size: 12px; padding: 3px 9px; border-radius: 99px; background: var(--card-2); color: var(--muted); margin: 0 4px 4px 0; text-transform: capitalize; }
.chip.on { color: var(--accent-ink); background: var(--accent); }
details summary { cursor: pointer; font-weight: 600; padding: 6px 0; }
.howto { padding-left: 20px; margin: 6px 0 0; font-size: 14px; color: #c9ced6; }
.howto li { margin-bottom: 6px; }
.pick-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.pick { background: var(--card-2); border: 0; border-radius: 12px; padding: 0; overflow: hidden; text-align: left; }
.pick-img { aspect-ratio: 3 / 2; background: #0b0d11 center / cover; }
.pick-name { font-size: 12px; padding: 6px 8px 8px; line-height: 1.3; }
