:root {
  --bg: #131f24;
  --card: #1f2e35;
  --card2: #253a44;
  --line: #37464f;
  --text: #f1f7fb;
  --dim: #8fa6b2;
  --green: #58cc02;
  --green-d: #3f9c00;
  --gold: #ffc800;
  --gold-d: #c99e00;
  --red: #ff4b4b;
  --blue: #1cb0f6;
  --blue-d: #1587bd;
  --purple: #ce82ff;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }

html { color-scheme: dark; }

body { -webkit-user-select: none; user-select: none; }
input, textarea { -webkit-user-select: text; user-select: text; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: ui-rounded, -apple-system, "SF Pro Rounded", "Segoe UI", Roboto, sans-serif;
  max-width: 540px;
  margin: 0 auto;
  min-height: 100vh;
}

/* ---------- header ---------- */
#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(14px + env(safe-area-inset-top)) 16px 6px;
}
.logo { font-weight: 800; font-size: 20px; letter-spacing: .3px; }
.hstats { display: flex; gap: 10px; }
.hstat {
  background: var(--card);
  border: 2px solid var(--line);
  border-radius: 12px;
  padding: 5px 12px;
  font-size: 14px;
  font-weight: 700;
}
.hstat b { color: var(--gold); }
.hstat:first-child b { color: #ff9600; }

#levelbar { padding: 4px 16px 10px; }
.level-label { font-size: 12px; font-weight: 700; color: var(--dim); margin-bottom: 4px; }
.level-label span:first-child { color: var(--purple); }

.bar {
  height: 14px;
  background: var(--card);
  border-radius: 99px;
  overflow: hidden;
  border: 2px solid var(--line);
}
.bar.slim { height: 10px; margin: 6px 0 4px; }
.bar .fill {
  height: 100%;
  background: var(--green);
  border-radius: 99px;
  transition: width .5s cubic-bezier(.22, 1.2, .36, 1);
  min-width: 0;
}
.bar .fill.gold { background: linear-gradient(90deg, var(--gold), #ff9600); }
.bar .fill.blue { background: var(--blue); }

/* ---------- main ---------- */
#view { padding: 6px 14px 96px; }

.pagetitle { font-size: 22px; font-weight: 800; margin: 10px 2px 12px; }

.card {
  background: var(--card);
  border: 2px solid var(--line);
  border-radius: 16px;
  padding: 14px;
  margin-bottom: 12px;
}
.card h3 { font-size: 15px; font-weight: 800; }
.card p { font-size: 13px; color: var(--dim); margin-top: 2px; }
.card.row, .card.ex, .card.cardio { display: flex; align-items: center; gap: 12px; }
.grow { flex: 1; min-width: 0; }

.day-head { display: flex; align-items: center; gap: 14px; background: linear-gradient(135deg, var(--card), var(--card2)); }
.day-emoji { font-size: 40px; }
.day-emoji.sm { font-size: 26px; }
.day-info { flex: 1; }
.day-info h2 { font-size: 20px; font-weight: 800; }
.day-info p { color: var(--dim); font-size: 13px; margin-top: 1px; }
.pct { font-size: 12px; color: var(--dim); font-weight: 700; }

.warmup ul, .plan-day ul { margin: 8px 0 2px 18px; }
.warmup li, .plan-day li { font-size: 13px; color: var(--dim); padding: 2px 0; }

/* exercise cards */
.card.ex { cursor: pointer; transition: transform .1s, border-color .15s; }
.card.ex:active { transform: scale(.98); }
.card.ex:hover { border-color: var(--blue); }

.anim { display: flex; align-items: center; justify-content: center; }
.anim.mini {
  width: 58px; height: 58px;
  flex: 0 0 58px;
  background: var(--bg);
  border-radius: 12px;
  font-size: 26px;
  overflow: hidden;
}
.anim.big {
  width: 100%;
  height: 230px;
  background: var(--bg);
  border-radius: 16px;
  margin-bottom: 12px;
  font-size: 60px;
  overflow: hidden;
}
.anim svg { width: 100%; height: 100%; display: block; }

.dots { display: flex; gap: 5px; }
.dots i {
  width: 11px; height: 11px;
  border-radius: 50%;
  background: var(--line);
  display: block;
}
.dots i.on { background: var(--green); box-shadow: 0 0 6px rgba(88, 204, 2, .6); }

/* cardio card */
.card.cardio { cursor: pointer; }
.card.cardio .check {
  width: 34px; height: 34px;
  border-radius: 50%;
  border: 2px solid var(--line);
  display: flex; align-items: center; justify-content: center;
  font-weight: 800;
  color: var(--bg);
  flex: 0 0 34px;
}
.card.cardio.done { border-color: var(--green); }
.card.cardio.done .check { background: var(--green); border-color: var(--green); }

/* buttons */
.btn {
  font-family: inherit;
  font-weight: 800;
  font-size: 15px;
  color: var(--text);
  background: var(--card2);
  border: 0;
  border-radius: 14px;
  padding: 12px 18px;
  cursor: pointer;
  box-shadow: 0 4px 0 var(--line);
  transition: transform .05s;
}
.btn:active { transform: translateY(4px); box-shadow: none; }
.btn.primary { background: var(--green); color: #0d2000; box-shadow: 0 4px 0 var(--green-d); }
.btn.big { display: block; width: 100%; padding: 15px; font-size: 17px; margin: 14px 0; text-transform: uppercase; letter-spacing: .5px; }
.btn.small { padding: 8px 14px; font-size: 13px; border-radius: 11px; box-shadow: 0 3px 0 var(--line); }
.btn.ghost { background: transparent; box-shadow: none; border: 2px solid var(--line); color: var(--dim); }

.finished-banner {
  background: linear-gradient(135deg, #2c4c11, #1e3a10);
  border: 2px solid var(--green);
  border-radius: 16px;
  padding: 16px;
  text-align: center;
  font-weight: 800;
  margin: 14px 0;
}

.note { font-size: 12.5px; color: var(--dim); padding: 2px 6px 12px; text-align: center; }
.plan-day .note { text-align: left; padding: 8px 0 4px; }

/* mini forms */
.mini-form { display: flex; gap: 8px; align-items: center; }
.mini-form.center { justify-content: center; margin-top: 12px; flex-wrap: wrap; }
input[type="number"] {
  font-family: inherit;
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  background: var(--bg);
  border: 2px solid var(--line);
  border-radius: 11px;
  padding: 8px 10px;
  width: 92px;
}
input[type="number"]:focus { outline: none; border-color: var(--blue); }

/* rest day */
.resty { text-align: center; padding: 30px 16px; }
.resty .big { font-size: 54px; margin-bottom: 8px; }

/* ---------- plan view ---------- */
.plan-day summary {
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  list-style: none;
}
.plan-day summary::-webkit-details-marker { display: none; }
.plan-day summary h3 { font-size: 15px; }
.plan-day summary p { font-size: 12.5px; color: var(--dim); }
.plan-day.today { border-color: var(--green); }
.plan-day h4 { font-size: 12px; text-transform: uppercase; color: var(--dim); margin-top: 12px; letter-spacing: .5px; }
.plan-day .btn { margin-top: 12px; }

/* ---------- progress ---------- */
.wstats { display: flex; justify-content: space-between; margin-bottom: 10px; }
.wstats > div { text-align: center; flex: 1; }
.wstats small { display: block; color: var(--dim); font-size: 11px; text-transform: uppercase; letter-spacing: .5px; }
.wstats b { font-size: 20px; font-weight: 800; }
.wstats b.good { color: var(--green); }
.wstats b.bad { color: var(--red); }

#weightChart { width: 100%; height: 220px; margin: 6px 0; }

.sbars { display: flex; gap: 8px; justify-content: space-between; margin-top: 12px; height: 110px; }
.sbar { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 5px; }
.scol {
  width: 100%;
  max-width: 34px;
  flex: 1;
  background: var(--bg);
  border-radius: 8px;
  display: flex;
  align-items: flex-end;
  overflow: hidden;
}
.sfill { width: 100%; background: var(--blue); border-radius: 8px 8px 0 0; min-height: 2px; }
.sfill.hit { background: var(--green); }
.sbar small { font-size: 11px; color: var(--dim); font-weight: 700; }

.statsgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; text-align: center; }
.statsgrid > div { background: var(--bg); border-radius: 12px; padding: 14px 8px; }
.statsgrid b { font-size: 24px; font-weight: 800; display: block; color: var(--gold); }
.statsgrid small { color: var(--dim); font-size: 12px; }

/* ---------- awards ---------- */
.badges { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.badge {
  background: var(--card);
  border: 2px solid var(--line);
  border-radius: 16px;
  padding: 14px 8px;
  text-align: center;
}
.badge .bicon { font-size: 34px; margin-bottom: 6px; }
.badge b { display: block; font-size: 12.5px; margin-bottom: 3px; }
.badge small { font-size: 10.5px; color: var(--dim); line-height: 1.3; display: block; }
.badge.locked { opacity: .38; filter: grayscale(1); }
.badge.on { border-color: var(--gold); background: linear-gradient(160deg, var(--card), #33301a); }

/* ---------- tabs ---------- */
#tabs {
  position: fixed;
  bottom: 0; left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 540px;
  display: flex;
  background: var(--card);
  border-top: 2px solid var(--line);
  padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
  z-index: 20;
}
#tabs button {
  flex: 1;
  background: none;
  border: 0;
  color: var(--dim);
  font-family: inherit;
  font-size: 11px;
  font-weight: 800;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 0;
  border-radius: 12px;
  cursor: pointer;
}
#tabs button .ico { font-size: 21px; }
#tabs button.active { color: var(--green); background: rgba(88, 204, 2, .1); }

/* ---------- modal ---------- */
#modal, #picker {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .65);
  z-index: 30;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
#modal.hidden, #picker.hidden { display: none; }
#modal .sheet, #picker .sheet {
  background: var(--bg);
  border: 2px solid var(--line);
  border-bottom: 0;
  border-radius: 24px 24px 0 0;
  width: 100%;
  max-width: 540px;
  max-height: 88vh;
  overflow-y: auto;
  padding: 18px 18px 30px;
  position: relative;
  animation: sheetup .25s cubic-bezier(.22, 1.2, .36, 1);
}
@keyframes sheetup { from { transform: translateY(60%); } to { transform: translateY(0); } }
#modal .sheet .anim.big { background: var(--card); }
#modal .close, #picker .close {
  position: absolute;
  top: 12px; right: 12px;
  width: 34px; height: 34px;
  border-radius: 50%;
  border: 2px solid var(--line);
  background: var(--card);
  color: var(--dim);
  font-size: 15px;
  cursor: pointer;
  z-index: 2;
}
#modal h2, #picker h2 { font-size: 20px; font-weight: 800; }
.muscle { color: var(--blue); font-size: 13px; font-weight: 700; margin: 2px 0 8px; }
.tip {
  background: var(--card);
  border: 2px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 13px;
  color: var(--dim);
  margin-bottom: 14px;
}
.weight-row { display: flex; align-items: center; justify-content: center; gap: 16px; margin-bottom: 14px; }
.wval { min-width: 110px; text-align: center; }
.wval b { font-size: 30px; font-weight: 800; }
.wval span { color: var(--dim); font-weight: 700; font-size: 14px; margin-left: 4px; }
.lastw { font-size: 12px; color: var(--dim); text-align: center; margin: -8px 0 12px; }

.btn.round {
  width: 54px; height: 54px;
  border-radius: 50%;
  padding: 0;
  font-size: 26px;
  line-height: 1;
  flex: 0 0 54px;
}
[data-hold] { -webkit-touch-callout: none; }

/* ---------- ruler picker ---------- */
.picker-value { text-align: center; margin: 14px 0 6px; }
.picker-value b { font-size: 44px; font-weight: 800; }
.picker-value span { color: var(--dim); font-weight: 700; font-size: 16px; margin-left: 6px; }
.ruler-wrap { position: relative; margin: 8px -18px 14px; }
.ruler {
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  -webkit-mask-image: linear-gradient(90deg, transparent 0, #000 18%, #000 82%, transparent 100%);
  mask-image: linear-gradient(90deg, transparent 0, #000 18%, #000 82%, transparent 100%);
}
.ruler::-webkit-scrollbar { display: none; }
.ruler canvas { display: block; }
.ruler-wrap .needle {
  position: absolute;
  left: 50%;
  top: 2px;
  height: 40px;
  width: 3px;
  margin-left: -1.5px;
  border-radius: 3px;
  background: var(--green);
  pointer-events: none;
  box-shadow: 0 0 8px rgba(88, 204, 2, .6);
}
.fine-row { display: flex; justify-content: center; gap: 24px; margin-bottom: 16px; }

.set-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.setbtn {
  font-family: inherit;
  font-weight: 800;
  font-size: 15px;
  color: var(--text);
  background: var(--card);
  border: 2px solid var(--line);
  border-radius: 14px;
  padding: 14px 6px;
  cursor: pointer;
  box-shadow: 0 4px 0 var(--line);
  display: flex;
  flex-direction: column;
  gap: 2px;
  align-items: center;
}
.setbtn small { font-size: 11px; color: var(--dim); font-weight: 700; }
.setbtn:active { transform: translateY(3px); box-shadow: none; }
.setbtn.on { background: var(--green); border-color: var(--green-d); box-shadow: 0 4px 0 var(--green-d); color: #0d2000; font-size: 19px; }
.setbtn.on small { color: #2c5d00; }

/* ---------- toasts & confetti ---------- */
#toasts {
  position: fixed;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
  width: max-content;
  max-width: 90vw;
}
.toast {
  background: var(--card2);
  border: 2px solid var(--gold);
  color: var(--text);
  font-weight: 800;
  font-size: 14px;
  padding: 10px 18px;
  border-radius: 99px;
  animation: pop .25s cubic-bezier(.22, 1.6, .36, 1);
  box-shadow: 0 6px 20px rgba(0, 0, 0, .4);
}
.toast.out { opacity: 0; transform: translateY(-10px); transition: all .4s; }
@keyframes pop { from { transform: scale(.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }

#confetti {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 99;
}
