:root {
  --blue: #1e88ff; --blue-d: #1470d6; --bg: #ffffff; --card: #f2f4f8; --line: #e1e5ec;
  --text: #121826; --muted: #6b7385; --ok: #19a463; --danger: #d93a3a; --warn: #fff0a8;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
body { padding-bottom: calc(76px + env(safe-area-inset-bottom)); }
#app { max-width: 560px; margin: 0 auto; padding: 16px 16px 24px; }
h1 { font-size: 28px; margin: 8px 0 16px; }
h2 { font-size: 20px; margin: 22px 0 10px; }
h3 { font-size: 17px; margin: 0 0 4px; }
a { color: var(--blue); text-decoration: none; }
.muted { color: var(--muted); font-size: 14px; }
.row { display: flex; align-items: center; gap: 10px; }
.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.topbar h1 { margin: 0; font-size: 22px; }
.back { background: none; border: 0; font-size: 28px; line-height: 1; padding: 4px 8px 4px 0; cursor: pointer; color: var(--text); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 0; border-radius: 12px; padding: 13px 18px; font-size: 16px; font-weight: 600; cursor: pointer; background: var(--card); color: var(--text); font-family: inherit; }
.btn.primary { background: var(--blue); color: #fff; }
.btn.primary:active { background: var(--blue-d); }
.btn.danger { background: #fdeaea; color: var(--danger); }
.btn.block { width: 100%; }
.btn.small { padding: 8px 12px; font-size: 14px; border-radius: 10px; }
.btn:disabled { opacity: .5; }

.card { background: #fff; border: 1px solid var(--line); border-radius: 16px; padding: 16px; margin-bottom: 12px; }
.card.flat { background: var(--card); border-color: transparent; }
.card.warn { background: var(--warn); border-color: transparent; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { background: var(--card); border-radius: 14px; padding: 12px; }
.stat b { display: block; font-size: 22px; }
.stat span { color: var(--muted); font-size: 13px; }

label { display: block; font-size: 14px; color: var(--muted); margin: 12px 0 4px; }
input, select { width: 100%; font-size: 16px; padding: 12px; border-radius: 12px; border: 1px solid var(--line); background: #fff; font-family: inherit; color: var(--text); }
input:focus, select:focus { outline: 2px solid var(--blue); border-color: transparent; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 9px 14px; font-size: 14px; cursor: pointer; font-family: inherit; color: var(--text); }
.chip.on { background: var(--blue); color: #fff; border-color: var(--blue); }
.error { color: var(--danger); font-size: 14px; margin: 10px 0 0; min-height: 18px; }

/* exercício */
.thumb { width: 52px; height: 52px; border-radius: 10px; background: #fff; border: 1px solid var(--line); object-fit: cover; flex: none; }
.ex-link { color: var(--blue); font-weight: 600; font-size: 17px; }
.loop { position: relative; width: 100%; aspect-ratio: 4 / 3; background: #fff; border: 1px solid var(--line); border-radius: 16px; overflow: hidden; }
.loop img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.loop { cursor: pointer; -webkit-tap-highlight-color: transparent; }
.loop img + img { animation: loopfade 3.6s ease-in-out infinite; }
.loop img:first-child { animation: none; }
@keyframes loopfade { 0%, 28% { opacity: 0; } 42%, 78% { opacity: 1; } 92%, 100% { opacity: 0; } }
.cap { position: absolute; left: 10px; bottom: 10px; padding: 4px 10px; border-radius: 999px; background: rgba(0,0,0,.65); color: #fff; font-size: 13px; font-weight: 600; opacity: 0; }
.cap.c1 { animation: capa 3.6s ease-in-out infinite; }
.cap.c2 { animation: capb 3.6s ease-in-out infinite; }
@keyframes capa { 0%, 24% { opacity: 1; } 34%, 88% { opacity: 0; } 96%, 100% { opacity: 1; } }
@keyframes capb { 0%, 34% { opacity: 0; } 44%, 76% { opacity: 1; } 88%, 100% { opacity: 0; } }
.loopico { position: absolute; right: 10px; top: 10px; width: 30px; height: 30px; border-radius: 50%; background: rgba(0,0,0,.5); color: #fff; font-size: 13px; display: flex; align-items: center; justify-content: center; }
.loop.paused img, .loop.paused .cap { animation-play-state: paused; }
.video { position: relative; display: block; width: 100%; aspect-ratio: 16 / 9; padding: 0; border: 0; border-radius: 16px; overflow: hidden; background: #000; cursor: pointer; }
.video img, .video iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; object-fit: cover; }
video.video { aspect-ratio: auto; max-height: 68vh; height: auto; margin: 0 auto; object-fit: contain; cursor: default; }
.playbtn { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: 64px; height: 64px; border-radius: 50%; background: rgba(0,0,0,.65); color: #fff; font-size: 28px; display: flex; align-items: center; justify-content: center; padding-left: 5px; }
.noimg { display: flex; align-items: center; justify-content: center; font-size: 56px; background: var(--card); aspect-ratio: 4 / 3; border-radius: 16px; }
ol.steps { padding-left: 22px; margin: 8px 0; line-height: 1.5; }
ol.steps li { margin-bottom: 8px; }
ul.tips { padding-left: 20px; line-height: 1.5; margin: 6px 0; }
.tag { display: inline-block; background: var(--card); border-radius: 8px; padding: 4px 10px; font-size: 13px; margin: 0 6px 6px 0; }
.tag.main { background: #e6f1ff; color: var(--blue-d); }

/* rotinas */
.routine { display: block; color: inherit; }
.routine p { margin: 4px 0 12px; }
.item { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.item:first-child { border-top: 0; }

/* treino ativo */
.sticky { position: sticky; top: 0; background: #fff; z-index: 5; padding: 10px 0; border-bottom: 1px solid var(--line); margin: 0 -16px 8px; padding-left: 16px; padding-right: 16px; }
.sets { width: 100%; border-collapse: collapse; margin: 6px 0; }
.sets th { font-size: 12px; color: var(--muted); font-weight: 500; text-align: center; padding: 4px; }
.sets td { padding: 4px; text-align: center; }
.sets input { text-align: center; padding: 9px 4px; }
.sets .num { background: var(--card); border-radius: 10px; font-weight: 700; padding: 9px 0; }
.sets .prev { color: var(--muted); font-size: 13px; }
.chk { width: 100%; border: 0; background: var(--card); border-radius: 10px; padding: 9px 0; font-size: 18px; color: #9aa3b5; cursor: pointer; }
.chk.on { background: var(--ok); color: #fff; }
tr.done td .num { background: #d8f3e5; }
.rest { position: fixed; left: 0; right: 0; bottom: calc(66px + env(safe-area-inset-bottom)); max-width: 560px; margin: 0 auto; background: #121826; color: #fff; padding: 12px 16px; display: flex; align-items: center; gap: 12px; z-index: 20; border-radius: 14px 14px 0 0; }
.rest b { font-size: 20px; }

/* navegação */
#nav { position: fixed; bottom: 0; left: 0; right: 0; background: #fff; border-top: 1px solid var(--line); display: flex; justify-content: space-around; padding: 8px 0 calc(8px + env(safe-area-inset-bottom)); z-index: 30; }
#nav[hidden] { display: none; }
#nav a { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 12px; color: var(--text); padding: 4px 18px; border-radius: 14px; }
#nav svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
#nav a.on { color: var(--blue); background: #e8f2ff; }

#modal .overlay { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
#modal .sheet { background: #fff; width: 100%; max-width: 560px; max-height: 88vh; border-radius: 20px 20px 0 0; padding: 16px; display: flex; flex-direction: column; }
#modal .sheet .list { overflow: auto; margin-top: 10px; flex: 1; }
#toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); background: #121826; color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px; opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 60; max-width: 90%; }
#toast.show { opacity: 1; }
.center { text-align: center; }
.logo { font-size: 44px; text-align: center; margin: 24px 0 0; }
.tabs { display: flex; background: var(--card); border-radius: 12px; padding: 4px; margin: 14px 0; }
.tabs button { flex: 1; border: 0; background: none; padding: 10px; border-radius: 9px; font-size: 15px; font-weight: 600; font-family: inherit; color: var(--muted); cursor: pointer; }
.tabs button.on { background: #fff; color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
