:root {
  --bg: #0b1220;
  --surface: #131c2e;
  --surface-2: #1b2640;
  --line: #2a3756;
  --text: #eef2f8;
  --muted: #9aa7bf;
  --accent: #2dd4bf;
  --accent-ink: #062b27;
  --accent-soft: rgba(45, 212, 191, .16);
  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, .14);
  --ok: #4ade80;
  --warn: #fbbf24;
  --fig: #2a3756;
  --fig-mus: #3b4a6d;
  --radius: 16px;
  --tabbar-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f2f4f8;
    --surface: #ffffff;
    --surface-2: #eef1f6;
    --line: #d7dde8;
    --text: #0f172a;
    --muted: #55627a;
    --accent: #0f9488;
    --accent-ink: #ffffff;
    --accent-soft: rgba(15, 148, 136, .12);
    --danger: #dc2626;
    --danger-soft: rgba(220, 38, 38, .1);
    --ok: #16a34a;
    --fig: #d5dbe6;
    --fig-mus: #bcc5d5;
    color-scheme: light;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  min-height: 100vh;
}
body.sheet-open { overflow: hidden; }
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.2; margin: 0; }
p { margin: 0 0 12px; }
svg { display: block; }

/* Barra superior */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 8px;
  padding: calc(8px + var(--safe-t)) 12px 8px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
  min-height: 56px;
}
.topbar h1 { flex: 1; font-size: 20px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 44px; height: 44px; border-radius: 12px; border: 0;
  background: transparent; color: var(--text); cursor: pointer; text-decoration: none;
  font-size: 22px; flex: none;
}
.icon-btn svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn:active { background: var(--surface-2); }

main {
  padding: 16px 16px calc(var(--tabbar-h) + var(--safe-b) + 96px);
  max-width: 680px; margin: 0 auto; outline: none;
}
.loading { color: var(--muted); text-align: center; padding: 40px 0; }

/* Barra de abas */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(4, 1fr);
  padding-bottom: var(--safe-b);
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  height: var(--tabbar-h); color: var(--muted); text-decoration: none; font-size: 12px; font-weight: 600;
}
.tabbar svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tabbar a.active { color: var(--accent); }

/* Cartões e listas */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin-bottom: 14px;
}
.hero h2 { font-size: 26px; margin: 6px 0 6px; }
.hero .meta { color: var(--muted); margin-bottom: 14px; }
.date-line { color: var(--muted); font-weight: 600; margin-bottom: 12px; text-transform: none; }
.section-title { font-size: 15px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 22px 4px 10px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 22px 4px 10px; }
.section-head .section-title { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.badge {
  display: inline-block; font-size: 12px; font-weight: 700; padding: 3px 8px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent); vertical-align: middle;
}
.badge.gray { background: var(--surface-2); color: var(--muted); }
.ex-preview { margin: 0 0 16px; padding-left: 22px; color: var(--muted); }
.ex-preview li { margin: 2px 0; }

.list { display: flex; flex-direction: column; gap: 10px; }
.item {
  display: flex; align-items: stretch; gap: 4px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  color: var(--text); text-decoration: none; min-height: 64px;
}
.item-main {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 12px; padding: 10px 12px;
  background: none; border: 0; color: inherit; text-align: left; font: inherit; text-decoration: none; cursor: pointer;
}
.item-main > span:last-child, .item-text { min-width: 0; display: flex; flex-direction: column; }
.item strong { font-weight: 650; overflow-wrap: anywhere; }
.item small { color: var(--muted); font-size: 14px; }
.item-actions { display: flex; align-items: center; padding-right: 4px; }
.item-actions .icon-btn { width: 40px; height: 44px; font-size: 18px; color: var(--muted); }
.thumb {
  flex: none; width: 52px; height: 52px; border-radius: 12px; overflow: hidden; background: var(--surface-2);
  display: flex; align-items: center; justify-content: center;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb .body-svg { width: 52px; height: 52px; }

/* Botões */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 50px; padding: 12px 18px; border-radius: 14px; border: 1px solid var(--line);
  background: var(--surface-2); color: var(--text); font: inherit; font-weight: 650;
  text-decoration: none; cursor: pointer; text-align: center;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { background: var(--danger-soft); border-color: transparent; color: var(--danger); }
.btn.ghost { background: transparent; }
.btn.block { display: flex; width: 100%; }
.btn.big { min-height: 58px; font-size: 19px; width: 100%; }
.btn.small { min-height: 40px; padding: 8px 12px; font-size: 15px; border-radius: 11px; }
.btn[disabled] { opacity: .45; pointer-events: none; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 10px; }
.btn-row > .btn { flex: 1 1 140px; }
.stack { display: flex; flex-direction: column; gap: 10px; }

/* Formulários */
label.field, .field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 14px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
input[type=text], input[type=search], input[type=number], input[type=date], input:not([type]), select, textarea {
  width: 100%; min-height: 50px; padding: 12px 14px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface-2); color: var(--text);
  font: inherit; font-size: 17px; appearance: none; -webkit-appearance: none;
}
textarea { min-height: 84px; resize: vertical; }
select { background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 20px) 22px, calc(100% - 14px) 22px; background-size: 6px 6px; background-repeat: no-repeat; padding-right: 36px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 10px; margin: 0 -16px; padding-left: 16px; padding-right: 16px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; min-height: 40px; padding: 8px 14px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); font: inherit; font-size: 15px; font-weight: 600; cursor: pointer;
}
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.check-line { display: flex; gap: 12px; align-items: flex-start; padding: 12px; border-radius: 12px; background: var(--surface-2); margin: 12px 0; cursor: pointer; }
.check-line input { width: 24px; height: 24px; flex: none; margin: 0; accent-color: var(--accent); }

.options { display: flex; flex-direction: column; gap: 8px; margin-bottom: 18px; }
.options legend { font-weight: 700; margin-bottom: 8px; padding: 0; }
fieldset { border: 0; padding: 0; margin: 0 0 6px; min-width: 0; }
.option {
  display: flex; align-items: center; gap: 12px; padding: 14px; min-height: 54px;
  border: 1px solid var(--line); border-radius: 14px; background: var(--surface); cursor: pointer;
}
.option input { width: 22px; height: 22px; margin: 0; accent-color: var(--accent); flex: none; }
.option:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }

/* Semana */
.day-row {
  width: 100%; display: flex; align-items: center; gap: 12px; text-align: left;
  padding: 12px 14px; min-height: 66px; margin-bottom: 8px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  color: var(--text); font: inherit; cursor: pointer;
}
.day-row.today { border-color: var(--accent); box-shadow: inset 4px 0 0 var(--accent); }
.day-name { width: 82px; flex: none; font-weight: 700; }
.day-value { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.day-value small { color: var(--muted); font-size: 14px; }
.day-value .rest { color: var(--muted); }
.chev { color: var(--muted); font-size: 22px; }

.week-strip { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.week-strip .d {
  border-radius: 12px; background: var(--surface); border: 1px solid var(--line); padding: 8px 2px; text-align: center;
  font-size: 12px; color: var(--muted); min-height: 64px; display: flex; flex-direction: column; align-items: center; gap: 4px;
}
.week-strip .d b { color: var(--text); font-size: 13px; }
.week-strip .d.today { border-color: var(--accent); }
.week-strip .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--line); }
.week-strip .dot.w { background: var(--accent); }
.week-strip .dot.r { background: transparent; border: 2px solid var(--muted); }
.week-strip .dot.ok { background: var(--ok); }

/* Biblioteca */
.figure { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; margin-bottom: 12px; }
.figure img { width: 100%; max-height: 420px; object-fit: contain; border-radius: 10px; display: block; }
.figure .body-svg { width: 100%; max-height: 300px; }
.body-svg .body { fill: var(--fig); }
.body-svg .mus { fill: var(--fig-mus); }
.body-svg .mus.on { fill: var(--accent); }
.body-svg text { fill: var(--muted); font-size: 11px; font-family: inherit; }
.tags { display: flex; gap: 6px; flex-wrap: wrap; margin: 8px 0 14px; }
.tag { font-size: 14px; padding: 4px 10px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.instructions { font-size: 18px; }

/* Sessão de treino */
.session-top { position: sticky; top: calc(56px + var(--safe-t)); z-index: 10; background: var(--bg); padding: 4px 0 10px; }
.progress { height: 10px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--accent); border-radius: 999px; transition: width .25s; }
.session-top .row { display: flex; justify-content: space-between; color: var(--muted); font-size: 14px; margin-bottom: 6px; }
.ex-card { padding: 14px 12px; }
.ex-card.complete { border-color: color-mix(in srgb, var(--ok) 60%, var(--line)); }
.ex-head { display: flex; gap: 12px; align-items: flex-start; margin-bottom: 10px; }
.ex-head h3 { font-size: 19px; margin-bottom: 2px; }
.ex-head small { display: block; color: var(--muted); font-size: 14px; }
.ex-head .last { color: var(--accent); }
.ex-head > div { flex: 1; min-width: 0; }
.ex-notes { font-size: 14px; color: var(--muted); background: var(--surface-2); border-radius: 10px; padding: 8px 10px; margin-bottom: 10px; }
.set-grid { display: grid; grid-template-columns: 40px 1fr 1fr 60px; gap: 8px; align-items: center; }
.set-grid .hdr { font-size: 12px; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: .04em; text-align: center; }
.set-row { display: contents; }
.set-n { text-align: center; font-weight: 700; color: var(--muted); }
.set-grid input { text-align: center; font-size: 20px; font-weight: 650; min-height: 54px; padding: 8px 4px; }
.set-row.done input { border-color: color-mix(in srgb, var(--ok) 60%, var(--line)); background: color-mix(in srgb, var(--ok) 12%, var(--surface-2)); }
.check {
  width: 60px; height: 54px; border-radius: 14px; border: 2px solid var(--line); background: var(--surface-2);
  color: var(--muted); font-size: 26px; font-weight: 800; cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.check[aria-pressed="true"] { background: var(--ok); border-color: var(--ok); color: #05230f; }
.ex-actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.ex-actions .btn { flex: 1 1 auto; }

/* Cronômetro de descanso */
.timer {
  position: fixed; left: 10px; right: 10px; z-index: 40;
  bottom: calc(var(--tabbar-h) + var(--safe-b) + 10px);
  max-width: 660px; margin: 0 auto;
  background: var(--surface); border: 2px solid var(--accent); border-radius: 18px;
  padding: 10px 12px; box-shadow: 0 10px 30px rgba(0,0,0,.35);
}
.timer .t-row { display: flex; align-items: center; gap: 10px; }
.timer .t-clock { font-size: 34px; font-weight: 800; font-variant-numeric: tabular-nums; min-width: 104px; }
.timer .t-label { flex: 1; min-width: 0; font-size: 14px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.timer .t-label b { color: var(--text); }
.timer .t-row .t-label b { display: block; font-size: 15px; }
.timer .t-row .btn { min-width: 54px; }
.timer .btn { min-height: 46px; padding: 8px 10px; }
.timer .progress { height: 6px; margin-top: 8px; }
.timer.finished { border-color: var(--ok); }

/* Histórico */
.seg { display: grid; grid-template-columns: 1fr 1fr; background: var(--surface-2); border-radius: 14px; padding: 4px; margin-bottom: 16px; }
.seg button { min-height: 44px; border: 0; border-radius: 11px; background: transparent; color: var(--muted); font: inherit; font-weight: 700; cursor: pointer; }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.date-box { flex: none; width: 52px; height: 52px; border-radius: 12px; background: var(--accent-soft); color: var(--accent); display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.05; }
.date-box b { font-size: 20px; }
.date-box small { color: var(--accent) !important; font-size: 12px !important; }
.load-big { margin-left: auto; text-align: right; flex: none; padding-left: 8px; }
.load-big b { display: block; font-size: 18px; }
table.sets { width: 100%; border-collapse: collapse; font-size: 16px; }
table.sets th { text-align: left; color: var(--muted); font-size: 13px; font-weight: 600; padding: 4px 6px; }
table.sets td { padding: 8px 6px; border-top: 1px solid var(--line); }
table.sets tr.undone td { color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; }
.empty .btn { margin-top: 14px; }

/* Avisos */
.notice { background: var(--accent-soft); border-radius: 14px; padding: 14px; font-size: 15px; margin-bottom: 16px; }
.notice.warn { background: color-mix(in srgb, var(--warn) 15%, transparent); }
.notice.danger { background: var(--danger-soft); }
.notice ul { margin: 6px 0 0; padding-left: 20px; }
.kv { display: flex; justify-content: space-between; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); font-size: 15px; }
.kv:first-child { border-top: 0; }
.kv span:last-child { text-align: right; font-weight: 600; }

/* Folha inferior (modal) */
#sheet-root { position: fixed; inset: 0; z-index: 60; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, .55); animation: fade .15s ease-out; }
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0; max-height: 92vh; max-height: 92dvh;
  display: flex; flex-direction: column;
  background: var(--bg); border-radius: 22px 22px 0 0; border-top: 1px solid var(--line);
  max-width: 680px; margin: 0 auto; animation: up .2s ease-out;
}
.sheet-head { display: flex; align-items: center; gap: 8px; padding: 14px 12px 8px 18px; }
.sheet-head h2 { flex: 1; font-size: 20px; }
.sheet-body { overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 6px 16px calc(24px + var(--safe-b)); }
.sheet-list { display: flex; flex-direction: column; gap: 8px; }
.sheet-list .btn { justify-content: flex-start; text-align: left; }
.sheet-list .btn.selected { border-color: var(--accent); background: var(--accent-soft); }
@keyframes up { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes fade { from { opacity: 0; } }

#toast {
  position: fixed; left: 50%; top: calc(64px + var(--safe-t)); transform: translateX(-50%) translateY(-20px);
  z-index: 80; background: var(--text); color: var(--bg); padding: 12px 18px; border-radius: 14px;
  font-weight: 650; font-size: 15px; opacity: 0; pointer-events: none; transition: .2s; max-width: calc(100% - 32px); text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.banner {
  position: fixed; left: 10px; right: 10px; top: calc(64px + var(--safe-t)); z-index: 70; max-width: 660px; margin: 0 auto;
  display: flex; gap: 10px; align-items: center; background: var(--surface); border: 1px solid var(--accent); border-radius: 14px; padding: 10px 12px;
}
.banner p { margin: 0; flex: 1; font-size: 15px; }

@media (min-width: 700px) {
  main { padding-top: 24px; }
}
