:root {
  --navy: #0A2E7A;
  --blue: #1E63D6;
  --blue-2: #3B8BF5;
  --sky: #E8F1FF;
  --sky-2: #D3E4FF;
  --bg: #F2F6FC;
  --surface: #FFFFFF;
  --surface-2: #F7FAFF;
  --text: #0D1B33;
  --text-2: #4A5B78;
  --muted: #8494AE;
  --line: #E1E8F3;
  --good: #12A36B;
  --good-bg: #E3F7EE;
  --warn: #D9822B;
  --danger: #D64545;
  --shadow: 0 1px 2px rgba(13, 38, 90, .06), 0 6px 20px rgba(13, 38, 90, .07);
  --radius: 18px;
  --header-h: 52px;
  --tab-h: 58px;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #06101F;
    --surface: #0E1C33;
    --surface-2: #12233F;
    --sky: #132B52;
    --sky-2: #1B3A6B;
    --text: #EAF2FF;
    --text-2: #A9BBD8;
    --muted: #6F84A6;
    --line: #1C2E4D;
    --blue: #4C93FF;
    --good: #2CC88A;
    --good-bg: #0F3328;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden; overscroll-behavior: none;
  background: var(--bg); color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Rubik, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%; text-size-adjust: 100%;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  touch-action: manipulation;
}
img, svg { -webkit-user-drag: none; pointer-events: none; }
input, textarea, select { -webkit-user-select: text; user-select: text; font: inherit; font-size: 17px; color: inherit; }
button { font: inherit; color: inherit; border: 0; background: none; padding: 0; cursor: pointer; touch-action: manipulation; }
a { color: inherit; text-decoration: none; }
.ltr { direction: ltr; unicode-bidi: isolate; }
.num { font-variant-numeric: tabular-nums; }

#app { position: fixed; inset: 0; display: flex; flex-direction: column; }

/* ---------- header ---------- */
.header {
  flex: none; padding-top: var(--sat);
  background: linear-gradient(180deg, var(--navy) 0%, #12409E 100%);
  color: #fff; position: relative; z-index: 5;
}
.header-row { min-height: var(--header-h); display: flex; align-items: center; gap: 8px; padding: 10px 16px 12px; }
.header h1 { font-size: 24px; font-weight: 800; line-height: 1.15; margin: 0; flex: 1; letter-spacing: -.2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.header .sub { font-size: 13.5px; opacity: .75; font-weight: 600; letter-spacing: 0; margin-top: 1px; }
.hbtn { height: 36px; min-width: 36px; padding: 0 12px; border-radius: 12px; background: rgba(255,255,255,.16); color: #fff; font-weight: 600; font-size: 15px; display: inline-flex; align-items: center; justify-content: center; gap: 4px; }
.hbtn:active { background: rgba(255,255,255,.3); }
.hbtn.solid { background: #fff; color: var(--navy); }
.hbtn svg { width: 20px; height: 20px; }

/* ---------- scrolling content ---------- */
.scroll {
  flex: 1; overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
  padding: 14px 14px calc(var(--tab-h) + var(--sab) + 24px);
}
.scroll.no-tabs { padding-bottom: calc(var(--sab) + 110px); }

/* ---------- tab bar ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  height: calc(var(--tab-h) + var(--sab)); padding-bottom: var(--sab);
  display: flex; background: color-mix(in srgb, var(--surface) 88%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(18px); backdrop-filter: saturate(180%) blur(18px);
  border-top: .5px solid var(--line);
}
.tab { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; color: var(--muted); font-size: 10.5px; font-weight: 600; }
.tab svg { width: 25px; height: 25px; }
.tab.on { color: var(--blue); }

/* ---------- cards ---------- */
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 12px; }
.card.tight { padding: 12px 14px; }
.section-title { font-size: 13px; font-weight: 700; color: var(--muted); margin: 18px 6px 8px; letter-spacing: .2px; }
.row { display: flex; align-items: center; gap: 10px; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--muted); }
.text-2 { color: var(--text-2); }
.small { font-size: 13px; }
.tiny { font-size: 11.5px; }
.bold { font-weight: 700; }

.hero {
  background: linear-gradient(140deg, var(--blue-2) 0%, var(--blue) 45%, var(--navy) 100%);
  color: #fff; border-radius: 24px; padding: 20px 18px 18px; margin-bottom: 14px; position: relative; overflow: hidden;
  box-shadow: 0 10px 30px rgba(20, 70, 170, .35);
}
.hero::after { content: ""; position: absolute; width: 220px; height: 220px; border-radius: 50%; background: rgba(255,255,255,.08); top: -90px; left: -60px; }
.hero .kicker { font-size: 13px; font-weight: 600; opacity: .85; }
.hero .big { font-size: 30px; font-weight: 800; letter-spacing: -.5px; margin: 2px 0 4px; }
.hero .meta { font-size: 14px; opacity: .85; }
.hero .btn { margin-top: 16px; }

.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%;
  height: 52px; border-radius: 15px; font-size: 17px; font-weight: 700;
  background: var(--blue); color: #fff; transition: transform .12s ease, opacity .12s;
}
.btn:active { transform: scale(.97); opacity: .9; }
.btn.white { background: #fff; color: var(--navy); }
.btn.soft { background: var(--sky); color: var(--blue); }
.btn.ghost { background: transparent; color: var(--blue); }
.btn.danger { background: transparent; color: var(--danger); }
.btn.good { background: var(--good); }
.btn.sm { height: 40px; font-size: 15px; border-radius: 12px; }
.btn[disabled] { opacity: .45; }
.btn svg { width: 20px; height: 20px; }

.chip { display: inline-flex; align-items: center; gap: 4px; height: 28px; padding: 0 10px; border-radius: 999px; background: var(--sky); color: var(--blue); font-size: 13px; font-weight: 600; white-space: nowrap; }
.chip.good { background: var(--good-bg); color: var(--good); }
.chip.gray { background: var(--surface-2); color: var(--text-2); border: 1px solid var(--line); }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 6px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.seg { display: flex; background: var(--sky); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { flex: 1; height: 34px; border-radius: 9px; font-weight: 600; font-size: 14px; color: var(--text-2); }
.seg button.on { background: var(--surface); color: var(--blue); box-shadow: 0 1px 3px rgba(0,0,0,.1); }

/* list rows */
.list { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; margin-bottom: 12px; }
.li { display: flex; align-items: center; gap: 12px; padding: 14px 16px; min-height: 56px; position: relative; }
.li + .li::before { content: ""; position: absolute; top: 0; right: 16px; left: 0; border-top: .5px solid var(--line); }
.li:active { background: var(--surface-2); }
.li .ico { width: 34px; height: 34px; border-radius: 10px; background: var(--sky); color: var(--blue); display: grid; place-items: center; flex: none; }
.li .ico svg { width: 19px; height: 19px; }
.chev { color: var(--muted); width: 18px; height: 18px; flex: none; transform: scaleX(-1); }

/* exercise preview (home) */
.ex-prev { padding: 12px 0; display: flex; gap: 12px; align-items: flex-start; }
.ex-prev + .ex-prev { border-top: .5px solid var(--line); }
.ex-idx { width: 26px; height: 26px; border-radius: 8px; background: var(--sky); color: var(--blue); font-weight: 700; font-size: 13px; display: grid; place-items: center; flex: none; margin-top: 1px; }
.ex-name { font-weight: 700; font-size: 16px; direction: ltr; text-align: right; unicode-bidi: plaintext; }
.ex-name .alt { display: block; font-weight: 600; color: var(--text-2); font-size: 14px; }
.presc { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.last { margin-top: 7px; font-size: 13.5px; color: var(--text-2); display: flex; gap: 6px; align-items: baseline; flex-wrap: wrap; }
.last b { color: var(--text); font-weight: 700; }
.last .src { color: var(--muted); font-size: 12px; }

/* ---------- workout mode ---------- */
.wo-ex { padding: 0; overflow: hidden; }
.wo-ex .top { padding: 14px 16px 10px; }
.wo-ex.done .top { background: linear-gradient(0deg, transparent, var(--good-bg)); }
.notes { margin-top: 8px; font-size: 13.5px; color: var(--text-2); background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 7px 10px; direction: ltr; text-align: right; unicode-bidi: plaintext; }
.link-btn { display: inline-flex; align-items: center; gap: 5px; color: var(--blue); font-weight: 600; font-size: 14px; margin-top: 8px; }
.link-btn svg { width: 17px; height: 17px; }
.sets { padding: 4px 10px 10px; }
.set-head, .set { display: grid; grid-template-columns: 30px 1fr 1.25fr 44px; gap: 8px; align-items: center; }
.set-head { font-size: 11.5px; color: var(--muted); font-weight: 700; padding: 4px 6px; text-align: center; }
.set { padding: 5px 6px; border-radius: 14px; transition: background .2s; }
.set.done { background: var(--good-bg); }
.set .n { font-weight: 800; color: var(--muted); text-align: center; font-size: 15px; }
.set.done .n { color: var(--good); }
.stepper { direction: ltr; display: flex; align-items: center; background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; height: 44px; overflow: hidden; }
.stepper button { width: 36px; height: 100%; font-size: 22px; font-weight: 500; color: var(--blue); flex: none; }
.stepper button:active { background: var(--sky); }
.stepper input { width: 100%; min-width: 0; text-align: center; border: 0; background: transparent; font-weight: 700; font-size: 18px; outline: none; padding: 0; }
.wfield { height: 44px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface-2); padding: 0 10px; width: 100%; font-weight: 600; font-size: 16.5px; direction: ltr; text-align: center; outline: none; }
.wfield:focus, .stepper:focus-within { border-color: var(--blue); background: var(--surface); }
.check { width: 44px; height: 44px; border-radius: 13px; border: 2px solid var(--sky-2); display: grid; place-items: center; color: transparent; transition: all .15s; }
.check svg { width: 22px; height: 22px; }
.set.done .check { background: var(--good); border-color: var(--good); color: #fff; }
.set-actions { display: flex; gap: 8px; padding: 4px 6px 4px; }
.set-actions .btn { height: 36px; font-size: 14px; }

.bottom-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 12;
  padding: 10px 14px calc(var(--sab) + 10px);
  background: color-mix(in srgb, var(--surface) 90%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(18px); backdrop-filter: saturate(180%) blur(18px);
  border-top: .5px solid var(--line);
}

/* rest timer */
.timer {
  display: flex; align-items: center; gap: 12px; margin-bottom: 10px;
  background: linear-gradient(135deg, var(--blue-2), var(--navy)); color: #fff;
  border-radius: 18px; padding: 10px 12px; box-shadow: 0 8px 24px rgba(20, 70, 170, .35);
  animation: pop .25s ease;
}
.timer.ended { background: linear-gradient(135deg, #2CC88A, #0E8A5B); }
.timer .ring { width: 52px; height: 52px; position: relative; flex: none; }
.timer .ring svg { width: 52px; height: 52px; transform: rotate(-90deg); }
.timer .ring .t { position: absolute; inset: 0; display: grid; place-items: center; font-weight: 800; font-size: 14px; }
.timer .time { font-size: 30px; font-weight: 800; letter-spacing: -.5px; line-height: 1; }
.timer .lbl { font-size: 12.5px; opacity: .85; margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 150px; }
.timer .tb { height: 38px; min-width: 44px; padding: 0 8px; border-radius: 11px; background: rgba(255,255,255,.18); color: #fff; font-weight: 700; font-size: 14px; }
.timer .tb:active { background: rgba(255,255,255,.32); }
@keyframes pop { from { transform: translateY(12px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- sheets / dialogs ---------- */
.backdrop { position: fixed; inset: 0; background: rgba(5, 15, 35, .45); z-index: 50; animation: fade .2s ease; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 51; max-height: 88%;
  background: var(--surface); border-radius: 22px 22px 0 0; padding: 8px 16px calc(var(--sab) + 16px);
  overflow-y: auto; animation: up .28s cubic-bezier(.2,.9,.3,1);
}
.sheet .grab { width: 38px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 12px; }
.sheet h2 { margin: 4px 0 6px; font-size: 20px; }
.sheet p { margin: 0 0 14px; color: var(--text-2); }
.sheet .btn + .btn { margin-top: 8px; }
@keyframes up { from { transform: translateY(100%); } to { transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

#toast {
  position: fixed; left: 50%; top: calc(var(--sat) + 10px); transform: translate(-50%, -150%); z-index: 100;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 14px; font-weight: 600; font-size: 15px;
  transition: transform .3s cubic-bezier(.2,.9,.3,1), opacity .2s, visibility 0s .3s; max-width: 90%; text-align: center; pointer-events: none;
  opacity: 0; visibility: hidden;
}
#toast.show { transform: translate(-50%, 0); opacity: 1; visibility: visible; transition: transform .3s cubic-bezier(.2,.9,.3,1), opacity .2s; }

/* forms */
.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: 13px; color: var(--text-2); font-weight: 600; margin: 0 4px 6px; }
.input { width: 100%; height: 48px; border-radius: 13px; border: 1px solid var(--line); background: var(--surface-2); padding: 0 14px; outline: none; }
.input:focus { border-color: var(--blue); }
select.input { -webkit-appearance: none; appearance: none; }
.switch { position: relative; width: 51px; height: 31px; flex: none; }
.switch input { opacity: 0; position: absolute; inset: 0; margin: 0; z-index: 1; }
.switch span { position: absolute; inset: 0; border-radius: 99px; background: var(--line); transition: .2s; }
.switch span::after { content: ""; position: absolute; top: 2px; right: 2px; width: 27px; height: 27px; border-radius: 50%; background: #fff; box-shadow: 0 2px 4px rgba(0,0,0,.2); transition: .2s; }
.switch input:checked + span { background: var(--good); }
.switch input:checked + span::after { right: 22px; }

/* login */
.login { flex: 1; display: flex; flex-direction: column; justify-content: center; padding: 30px 26px calc(var(--sab) + 30px); background: linear-gradient(160deg, var(--blue-2), var(--navy)); color: #fff; }
.login img { width: 96px; height: 96px; border-radius: 22px; box-shadow: 0 12px 30px rgba(0,0,0,.3); margin-bottom: 20px; }
.login h1 { font-size: 30px; margin: 0 0 6px; }
.login p { margin: 0 0 26px; opacity: .85; }
.login .input { background: rgba(255,255,255,.15); border-color: rgba(255,255,255,.25); color: #fff; height: 54px; font-size: 18px; }
.login .input::placeholder { color: rgba(255,255,255,.6); }
.login .err { color: #FFD0D0; min-height: 22px; margin: 8px 4px; font-weight: 600; }

/* tables (program view / reference) */
.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.tbl td, .tbl th { padding: 8px 6px; border-bottom: .5px solid var(--line); vertical-align: top; text-align: right; }
.tbl th { color: var(--muted); font-size: 11.5px; font-weight: 700; }
.tbl .en { direction: ltr; text-align: right; unicode-bidi: plaintext; }

/* progress */
.bar { height: 8px; border-radius: 5px; background: var(--sky); overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 5px; background: linear-gradient(90deg, var(--blue-2), var(--blue)); }
.spark { width: 84px; height: 30px; flex: none; }
.chart-wrap { position: relative; }
.chart-wrap svg { width: 100%; height: auto; display: block; pointer-events: auto; }
.chart-tip { position: absolute; pointer-events: none; background: var(--text); color: var(--bg); border-radius: 10px; padding: 6px 9px; font-size: 12.5px; white-space: nowrap; transform: translate(-50%, -110%); opacity: 0; transition: opacity .12s; }
.chart-tip.on { opacity: 1; }
.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 12px; }
.stat { background: var(--surface); border-radius: 16px; box-shadow: var(--shadow); padding: 12px; text-align: center; }
.stat .v { font-size: 24px; font-weight: 800; color: var(--blue); }
.stat .k { font-size: 12px; color: var(--muted); font-weight: 600; }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; }
.searchbox { position: relative; margin-bottom: 12px; }
.searchbox input { padding-right: 40px; }
.searchbox svg { position: absolute; right: 13px; top: 14px; width: 20px; height: 20px; color: var(--muted); }

.week-head { display: flex; align-items: center; gap: 10px; padding: 14px 16px; }
.week-badge { width: 40px; height: 40px; border-radius: 12px; background: var(--sky); color: var(--blue); font-weight: 800; display: grid; place-items: center; flex: none; }
.week-badge.done { background: var(--good-bg); color: var(--good); }
.week-badge.cur { background: var(--blue); color: #fff; }
.wo-pill { flex: 1; border-radius: 14px; padding: 10px; background: var(--surface-2); border: 1px solid var(--line); text-align: center; }
.wo-pill.done { background: var(--good-bg); border-color: transparent; }
.wo-pill.next { border: 2px solid var(--blue); }
.wo-pill b { display: block; font-size: 16px; }
.offline { background: var(--warn); color: #fff; text-align: center; font-size: 13px; font-weight: 600; padding: 4px; }
.fade-in { animation: fade .18s ease; }
