:root {
  --bg: #0b0d12;
  --bg2: #141925;
  --card: #1a2130;
  --card2: #222b3d;
  --line: #2a3346;
  --txt: #eef2f8;
  --mut: #8b96aa;
  --acc: #4f8cff;
  --acc2: #36d399;
  --warn: #ffb454;
  --danger: #ff5c6c;
  --tabh: 64px;
  --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(--txt);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  overscroll-behavior-y: contain;
}

body { padding-bottom: calc(var(--tabh) + var(--safe-b)); }

.view {
  padding: calc(var(--safe-t) + 14px) 16px 18px;
  max-width: 720px;
  margin: 0 auto;
  min-height: 60vh;
}

h1 { font-size: 26px; margin: 4px 0 16px; font-weight: 800; letter-spacing: -0.5px; }
h2 { font-size: 18px; margin: 22px 0 10px; font-weight: 700; }
.mut { color: var(--mut); }
.center { text-align: center; }

/* --- Tab bar --- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0;
  height: calc(var(--tabh) + var(--safe-b));
  padding-bottom: var(--safe-b);
  display: flex;
  background: rgba(15, 19, 28, 0.92);
  backdrop-filter: saturate(140%) blur(14px);
  border-top: 1px solid var(--line);
  z-index: 50;
}
.tabbar a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; text-decoration: none; color: var(--mut); font-size: 11px; font-weight: 600;
}
.tabbar a .ic { font-size: 22px; line-height: 1; filter: grayscale(0.4) opacity(0.7); }
.tabbar a.active { color: var(--acc); }
.tabbar a.active .ic { filter: none; }

/* --- Cards / lists --- */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 16px;
  padding: 14px; margin-bottom: 12px;
}
.row { display: flex; align-items: center; gap: 12px; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.ell { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag {
  display: inline-block; font-size: 11px; padding: 3px 8px; border-radius: 999px;
  background: var(--card2); color: var(--mut); margin-right: 6px; text-transform: capitalize;
}

/* --- Buttons --- */
button, .btn {
  font: inherit; font-weight: 700; border: none; border-radius: 12px; padding: 13px 16px;
  background: var(--acc); color: #fff; cursor: pointer; touch-action: manipulation;
}
button:active, .btn:active { transform: scale(0.98); }
button.sec { background: var(--card2); color: var(--txt); }
button.ghost { background: transparent; color: var(--acc); padding: 8px; }
button.danger { background: transparent; color: var(--danger); }
button.full { width: 100%; }
button.sm { padding: 8px 12px; font-size: 14px; border-radius: 10px; }
button:disabled { opacity: 0.4; }
.fab {
  position: fixed; right: 18px; bottom: calc(var(--tabh) + var(--safe-b) + 16px);
  width: 58px; height: 58px; border-radius: 50%; font-size: 30px; padding: 0;
  box-shadow: 0 8px 24px rgba(79,140,255,0.4); z-index: 40;
}

/* --- Inputs --- */
input, select, textarea {
  font: inherit; background: var(--bg2); color: var(--txt); border: 1px solid var(--line);
  border-radius: 10px; padding: 11px 12px; width: 100%;
}
input[type=number] { -moz-appearance: textfield; }
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 13px; color: var(--mut); margin-bottom: 5px; }
.inline-inputs { display: flex; gap: 8px; }
.inline-inputs > * { flex: 1; }

.empty { text-align: center; color: var(--mut); padding: 40px 10px; }
.empty .big { font-size: 48px; margin-bottom: 8px; }

/* --- Library --- */
.searchbar { position: sticky; top: 0; z-index: 5; padding: 6px 0 10px; background: var(--bg); }
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 6px; -webkit-overflow-scrolling: touch; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto; padding: 7px 13px; border-radius: 999px; background: var(--card);
  border: 1px solid var(--line); color: var(--mut); font-size: 13px; font-weight: 600;
}
.chip.on { background: var(--acc); color: #fff; border-color: var(--acc); }
.ex-item { display: flex; gap: 12px; align-items: center; padding: 10px; }
.ex-thumb {
  width: 56px; height: 56px; border-radius: 12px; object-fit: cover; background: var(--card2);
  flex: 0 0 auto;
}
.ex-name { font-weight: 700; }
.ex-sub { font-size: 12px; color: var(--mut); text-transform: capitalize; }

/* --- Exercise detail --- */
.ex-hero { width: 100%; border-radius: 16px; background: var(--card2); aspect-ratio: 4/3; object-fit: cover; }
.instr { counter-reset: step; padding: 0; margin: 0; list-style: none; }
.instr li { position: relative; padding: 10px 0 10px 34px; border-bottom: 1px solid var(--line); }
.instr li::before {
  counter-increment: step; content: counter(step);
  position: absolute; left: 0; top: 10px; width: 24px; height: 24px; border-radius: 50%;
  background: var(--acc); color: #fff; font-size: 13px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.yt-frame { width: 100%; aspect-ratio: 16/9; border: none; border-radius: 14px; margin-top: 10px; }

/* --- Active workout / sets --- */
.set-row { display: grid; grid-template-columns: 28px 1fr 1fr 44px; gap: 8px; align-items: center; margin-bottom: 8px; }
.set-row .idx { color: var(--mut); text-align: center; font-weight: 700; }
.set-row input { text-align: center; padding: 11px 6px; }
.set-row.done input { color: var(--acc2); border-color: var(--acc2); }
.set-check { background: var(--card2); border-radius: 10px; height: 44px; font-size: 18px; }
.set-row.done .set-check { background: var(--acc2); }
.prev-hint { font-size: 12px; color: var(--mut); margin: 2px 0 8px 36px; }
.timer-bar { display:flex; gap:8px; margin-top:8px; }
.timer-bar button { flex:1; }

/* --- Stat tiles --- */
.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px 10px; text-align: center; }
.tile .v { font-size: 22px; font-weight: 800; }
.tile .l { font-size: 11px; color: var(--mut); margin-top: 2px; }
canvas { max-width: 100%; }

/* --- Rest timer overlay --- */
.rest-timer {
  position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center;
  background: rgba(6,8,12,0.82); backdrop-filter: blur(8px);
}
.rest-timer.hidden { display: none; }
.rt-card { text-align: center; width: 280px; }
.rt-label { color: var(--mut); font-weight: 700; letter-spacing: 2px; text-transform: uppercase; font-size: 13px; }
.rt-time { font-size: 64px; font-weight: 800; font-variant-numeric: tabular-nums; margin: 4px 0; }
.rt-ring { position: relative; width: 0; height: 0; }
.rest-timer .rt-ring svg { display:none; }
.rt-presets, .rt-quick { display: flex; gap: 8px; justify-content: center; margin-top: 14px; }
.rt-quick button { flex:1; }
.rt-presets button { background: var(--card2); }
.rt-actions { margin-top: 16px; }
.rt-skip { width: 100%; background: var(--danger); }
.rest-timer.rt-done .rt-time { color: var(--acc2); }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabh) + var(--safe-b) + 20px); transform: translateX(-50%);
  background: var(--card2); color: var(--txt); padding: 11px 18px; border-radius: 999px;
  border: 1px solid var(--line); z-index: 200; font-weight: 600; box-shadow: 0 6px 20px rgba(0,0,0,0.4);
}
.spinner { text-align:center; padding:60px 0; color: var(--mut); }
