:root {
  --bg: #0b1220;
  --bg-elev: #131c2e;
  --bg-elev2: #1b2740;
  --line: #24314f;
  --text: #e7ecf5;
  --muted: #8ea0bf;
  --accent: #22d3ee;
  --accent2: #6366f1;
  --danger: #f87171;
  --ok: #34d399;
  --warn: #fbbf24;
  --radius: 16px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  min-height: 100dvh; overscroll-behavior-y: none;
  -webkit-user-select: none; user-select: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }
input, textarea { -webkit-user-select: text; user-select: text; }

.app { max-width: 620px; margin: 0 auto; min-height: 100dvh; display: flex; flex-direction: column; }

/* Top bar ----------------------------------------------------------------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  padding: calc(var(--safe-top) + 12px) 14px 10px;
  background: linear-gradient(180deg, rgba(11,18,32,.98), rgba(11,18,32,.88));
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 10px;
}
.topbar h1 { font-size: 19px; margin: 0; font-weight: 750; flex: 1; letter-spacing: .2px; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; background: var(--bg-elev);
  display: grid; place-items: center; color: var(--text); border: 1px solid var(--line); font-size: 18px;
}
.icon-btn.active { color: var(--accent); border-color: var(--accent); }
.icon-btn:active { transform: scale(.93); }

.content { flex: 1; padding: 12px 14px calc(var(--safe-bottom) + 28px); }

/* Week navigation --------------------------------------------------------- */
.weeknav { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.weeknav .nav { width: 38px; height: 38px; border-radius: 11px; background: var(--bg-elev); border: 1px solid var(--line); display: grid; place-items: center; font-size: 18px; }
.weeknav .nav:active { transform: scale(.9); }
.weeknav .label { flex: 1; text-align: center; }
.weeknav .label .range { font-weight: 700; font-size: 15px; }
.weeknav .label .today { font-size: 12px; color: var(--muted); }
.weeknav .this { font-size: 12px; color: var(--accent); background: rgba(34,211,238,.12); border: 1px solid rgba(34,211,238,.4); padding: 6px 10px; border-radius: 10px; }

/* Day selector ------------------------------------------------------------ */
.days { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin-bottom: 12px; }
.day {
  border: 1px solid var(--line); background: var(--bg-elev); border-radius: 12px;
  padding: 7px 0; text-align: center; position: relative;
}
.day .dow { font-size: 11px; color: var(--muted); }
.day .dnum { font-size: 16px; font-weight: 700; margin-top: 2px; }
.day.sel { background: linear-gradient(135deg, var(--accent2), var(--accent)); border-color: transparent; color: #061018; }
.day.sel .dow { color: rgba(6,16,24,.7); }
.day.today .dnum::after { content: ''; position: absolute; bottom: 5px; left: 50%; transform: translateX(-50%); width: 4px; height: 4px; border-radius: 50%; background: var(--accent); }
.day.sel.today .dnum::after { background: #061018; }
.day .dot { position: absolute; top: 4px; right: 6px; font-size: 9px; color: var(--ok); }

/* Program hint ------------------------------------------------------------ */
.program { display: flex; gap: 8px; margin-bottom: 14px; }
.pgm-card { flex: 1; border: 1px solid var(--line); background: var(--bg-elev); border-radius: 12px; padding: 8px 10px; font-size: 12px; }
.pgm-card .pt-row { display: flex; align-items: center; gap: 6px; margin-bottom: 3px; }
.pgm-card .pt { font-weight: 700; font-size: 12px; flex: 1; }
.grp-plus { font-size: 12px; font-weight: 700; padding: 5px 9px; border-radius: 9px; background: rgba(34,211,238,.14); color: var(--accent); border: 1px solid rgba(34,211,238,.4); white-space: nowrap; }
.pgm-card.B .grp-plus { background: rgba(99,102,241,.16); color: var(--accent2); border-color: rgba(99,102,241,.45); }
.grp-plus:active { transform: scale(.92); }
.pgm-card .pm { color: var(--muted); }
.pgm-card.A .pt { color: var(--accent); }
.pgm-card.B .pt { color: var(--accent2); }
.pgm-card:active { transform: scale(.99); }
.pgm-card.dim { opacity: .5; }

/* Muscle rows ------------------------------------------------------------- */
.muscle {
  background: var(--bg-elev); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px; margin-bottom: 10px;
}
.muscle .top { display: flex; align-items: center; gap: 8px; margin-bottom: 9px; }
.muscle .name { font-weight: 700; font-size: 16px; }
.muscle .tag { font-size: 10px; font-weight: 700; padding: 1px 6px; border-radius: 6px; }
.muscle .tag.A { color: var(--accent); background: rgba(34,211,238,.14); }
.muscle .tag.B { color: var(--accent2); background: rgba(99,102,241,.16); }
.muscle .wk { margin-left: auto; font-size: 14px; font-weight: 700; }
.muscle .wk small { color: var(--muted); font-weight: 500; font-size: 12px; }

.bar { height: 8px; border-radius: 6px; background: var(--bg-elev2); overflow: hidden; margin-bottom: 11px; }
.bar > i { display: block; height: 100%; border-radius: 6px; transition: width .25s ease; }
.lv-lo > i { background: linear-gradient(90deg, #ef4444, #f97316); }
.lv-mid > i { background: linear-gradient(90deg, #f59e0b, #fbbf24); }
.lv-hi > i { background: linear-gradient(90deg, #10b981, #34d399); }
.lv-over > i { background: linear-gradient(90deg, #22d3ee, #6366f1); }

.stepper { display: flex; align-items: center; gap: 12px; }
.stepper .lbl { font-size: 13px; color: var(--muted); flex: 1; }
.stepper .lbl b { color: var(--text); }
.step-btn { width: 46px; height: 46px; border-radius: 14px; display: grid; place-items: center; font-size: 26px; font-weight: 400; border: 1px solid var(--line); background: var(--bg-elev2); }
.step-btn.plus { background: linear-gradient(135deg, var(--accent2), var(--accent)); color: #061018; border: none; font-weight: 700; }
.step-btn:active { transform: scale(.9); }
.step-btn:disabled { opacity: .35; }
.stepper .cnt { min-width: 30px; text-align: center; font-size: 22px; font-weight: 800; }

.week-total-footer { text-align: center; color: var(--muted); font-size: 13px; margin: 6px 0 2px; }
.week-total-footer b { color: var(--text); }

/* Generic ----------------------------------------------------------------- */
.section-title { font-size: 13px; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: .5px; margin: 20px 4px 10px; }
.card { background: var(--bg-elev); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.banner { background: var(--bg-elev2); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; font-size: 13px; color: var(--muted); margin-bottom: 12px; }
.banner.warn { border-color: #7c5b16; color: #f5d492; background: #241d0e; }
.empty { text-align: center; color: var(--muted); padding: 50px 20px; }
.empty .big { font-size: 44px; margin-bottom: 10px; }
.spinner { text-align: center; color: var(--muted); padding: 60px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 13px 16px; border-radius: 13px; font-weight: 700; width: 100%; }
.btn.primary { background: linear-gradient(135deg, var(--accent2), var(--accent)); color: #061018; }
.btn.ghost { background: var(--bg-elev2); border: 1px solid var(--line); color: var(--text); }
.btn.danger { background: transparent; border: 1px solid #52303a; color: var(--danger); }
.btn:active { transform: scale(.98); }
.btn-row { display: flex; gap: 10px; }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; font-weight: 600; }
.input { width: 100%; background: var(--bg-elev2); border: 1px solid var(--line); border-radius: 12px; padding: 12px; color: var(--text); outline: none; }
.input:focus { border-color: var(--accent); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
select.input { appearance: none; }

/* Settings ---------------------------------------------------------------- */
.set-row { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.set-row:last-child { border-bottom: none; }
.set-row .nm { flex: 1; font-weight: 600; }
.goal-input { width: 64px; text-align: center; }
.chip-toggle { display: inline-flex; align-items: center; gap: 6px; padding: 8px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg-elev2); font-size: 14px; margin: 0 6px 6px 0; }
.chip-toggle.on { border-color: var(--accent); color: var(--accent); background: rgba(34,211,238,.1); }

/* Stats ------------------------------------------------------------------- */
.stat-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 8px; }
.stat-card { background: var(--bg-elev); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; }
.stat-card .v { font-size: 26px; font-weight: 800; }
.stat-card .k { font-size: 12px; color: var(--muted); margin-top: 2px; }
.stat-card .d { font-size: 12px; font-weight: 700; margin-top: 4px; }
.d.up { color: var(--ok); } .d.down { color: var(--danger); } .d.flat { color: var(--muted); }

.chart { display: flex; align-items: flex-end; gap: 6px; height: 120px; padding: 8px 2px 0; }
.chart .col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; justify-content: flex-end; cursor: pointer; }
.chart .col:active { transform: scale(.96); }
.chart .col .bwrap { width: 100%; display: flex; align-items: flex-end; justify-content: center; flex: 1; }
.chart .col .b { width: 66%; border-radius: 5px 5px 0 0; background: linear-gradient(180deg, var(--accent), var(--accent2)); min-height: 2px; }
.chart .col.cur .b { background: linear-gradient(180deg, #34d399, #10b981); }
.chart .col .cap { font-size: 10px; color: var(--muted); }
.chart .col .val { font-size: 10px; color: var(--muted); }

.mtable { width: 100%; overflow-x: auto; }
.mtable table { border-collapse: collapse; width: 100%; font-size: 13px; }
.mtable th, .mtable td { padding: 8px 6px; text-align: center; border-bottom: 1px solid var(--line); white-space: nowrap; }
.mtable th:first-child, .mtable td:first-child { text-align: left; position: sticky; left: 0; background: var(--bg); }
.mtable td.met { color: var(--ok); font-weight: 700; }
.mtable td.zero { color: #56637d; }
.mtable th.cur { color: var(--accent); }

/* Toast ------------------------------------------------------------------- */
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--safe-bottom) + 24px); background: #0b1220; color: var(--text); border: 1px solid var(--line); padding: 11px 18px; border-radius: 12px; z-index: 60; font-size: 14px; max-width: 90%; box-shadow: 0 8px 24px rgba(0,0,0,.45); opacity: 0; transition: opacity .2s, transform .2s; pointer-events: none; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(-4px); }
.toast.err { border-color: #52303a; color: #ffd7d7; }
.toast.ok { border-color: #2c5545; }

/* Modal ------------------------------------------------------------------- */
.modal-bg { position: fixed; inset: 0; background: rgba(3,7,15,.7); z-index: 70; display: flex; align-items: flex-end; justify-content: center; }
.modal { background: var(--bg-elev); border: 1px solid var(--line); border-radius: 20px 20px 0 0; width: 100%; max-width: 620px; padding: 18px 16px calc(var(--safe-bottom) + 18px); }
.modal h2 { margin: 2px 0 14px; font-size: 18px; }
