:root {
  --bg: #0d1014;
  --surface: #161a20;
  --surface-2: #1e232b;
  --line: #2a3039;
  --text: #eef1f5;
  --muted: #8b95a3;
  --accent: #c6f432;
  --accent-ink: #12160a;
  --danger: #ff6b6b;

  --caminhar: #4da3ff;
  --trotar: #ffb340;
  --correr: #3ee08f;
  --tiro: #ff5470;

  --radius: 16px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  min-height: 100dvh;
  padding: calc(var(--safe-t) + 8px) 0 calc(76px + var(--safe-b));
  overscroll-behavior-y: none;
}
main { max-width: 560px; margin: 0 auto; padding: 8px 16px 24px; }
h1 { font-size: 30px; line-height: 1.1; letter-spacing: -0.02em; margin: 12px 0 18px; font-weight: 800; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin: 26px 0 10px; font-weight: 700; }
h3 { font-size: 18px; margin: 0 0 4px; letter-spacing: -0.01em; }
p { margin: 0 0 10px; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.num { font-variant-numeric: tabular-nums; }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.spread { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 10px; }
.hidden { display: none !important; }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin-bottom: 12px;
}
.card.hero { background: linear-gradient(160deg, #1b2130, var(--surface) 60%); }
.card.link { display: block; color: inherit; text-decoration: none; }
.card.link:active { transform: scale(0.99); }
.card.warn { border-color: #5a4a1c; background: #1f1b10; }

.btn {
  appearance: none; border: 1px solid var(--line); background: var(--surface-2); color: var(--text);
  font: inherit; font-weight: 650; padding: 12px 16px; border-radius: 12px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-decoration: none;
  min-height: 46px;
}
.btn:active { transform: scale(0.98); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.danger { color: var(--danger); }
.btn.ghost { background: transparent; }
.btn.block { width: 100%; }
.btn.big { font-size: 19px; min-height: 58px; border-radius: 16px; }
.btn.sm { min-height: 34px; padding: 6px 10px; font-size: 14px; border-radius: 10px; }
.btn[disabled] { opacity: 0.5; }

.badge {
  display: inline-block; font-size: 12px; font-weight: 700; padding: 3px 8px; border-radius: 99px;
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); white-space: nowrap;
}
.badge.on { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.badges { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }

.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 12px; scrollbar-width: none; }
.chip {
  border: 1px solid var(--line); background: transparent; color: var(--text); font: inherit; font-size: 14px;
  padding: 7px 13px; border-radius: 99px; white-space: nowrap; cursor: pointer;
}
.chip.on { background: var(--text); color: var(--bg); border-color: var(--text); font-weight: 650; }

/* barra de segmentos */
.segbar { display: flex; height: 10px; border-radius: 6px; overflow: hidden; gap: 1px; background: var(--bg); margin: 10px 0 6px; }
.segbar > i { display: block; min-width: 2px; }
.t-caminhar { background: var(--caminhar); } .t-trotar { background: var(--trotar); }
.t-correr { background: var(--correr); } .t-tiro { background: var(--tiro); }
.c-caminhar { color: var(--caminhar); } .c-trotar { color: var(--trotar); }
.c-correr { color: var(--correr); } .c-tiro { color: var(--tiro); }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.legend span::before { content: ''; display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 5px; background: currentColor; }

.progress { height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--accent); border-radius: 99px; }

/* formulários */
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 5px; font-weight: 600; }
input, select, textarea {
  width: 100%; font: inherit; font-size: 16px; color: var(--text); background: var(--bg);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; min-height: 44px;
}
textarea { min-height: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.switch:first-child { border-top: 0; }
.switch input { width: 50px; min-height: 0; height: 30px; appearance: none; background: var(--surface-2); border-radius: 99px; position: relative; flex: none; padding: 0; border: 1px solid var(--line); }
.switch input::after { content: ''; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: var(--muted); transition: .15s; }
.switch input:checked { background: var(--accent); }
.switch input:checked::after { left: 23px; background: var(--accent-ink); }
.days { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin: 8px 0 12px; }
.days button { min-height: 40px; padding: 0; }

/* lista de semanas */
details.week { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 10px; }
details.week > summary { list-style: none; padding: 14px 16px; cursor: pointer; display: flex; justify-content: space-between; align-items: center; font-weight: 700; }
details.week > summary::-webkit-details-marker { display: none; }
details.week[open] > summary { border-bottom: 1px solid var(--line); }
.workout { padding: 14px 16px; border-top: 1px solid var(--line); }
.workout:first-of-type { border-top: 0; }
.workout.done h3::after { content: ' ✓'; color: var(--accent); }
.summary { font-size: 13px; color: var(--muted); }

/* editor */
.seg-row { display: grid; grid-template-columns: 6px minmax(0,1.25fr) 64px minmax(0,1fr) 22px; gap: 6px; align-items: center; margin-bottom: 8px; }
.seg-row .dot { width: 8px; height: 36px; border-radius: 4px; }
.seg-row input, .seg-row select { min-height: 38px; padding: 6px 6px; font-size: 16px; }
.seg-row select { padding-right: 2px; }
.icon-btn { appearance: none; border: 0; background: transparent; color: var(--muted); font-size: 20px; cursor: pointer; padding: 0; min-height: 34px; }
.repeat-box { background: var(--bg); border: 1px dashed var(--line); border-radius: 12px; padding: 12px; margin: 10px 0; }

/* treino ativo */
body.running { padding-bottom: var(--safe-b); }
body.running #tabs { display: none; }
.run { min-height: calc(100dvh - var(--safe-t) - 16px); display: flex; flex-direction: column; padding-bottom: 12px; }
.run-top { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.run-stage {
  flex: 1; display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center;
  border-radius: 28px; margin: 14px 0; padding: 24px 16px; transition: background .3s;
  background: radial-gradient(circle at 50% 30%, color-mix(in srgb, var(--cur) 32%, transparent), transparent 70%), var(--surface);
  border: 2px solid color-mix(in srgb, var(--cur) 60%, transparent);
}
.run-verb { font-size: clamp(44px, 14vw, 76px); font-weight: 900; letter-spacing: -0.03em; line-height: 1; color: var(--cur); text-transform: uppercase; }
.run-clock { font-size: clamp(76px, 26vw, 140px); font-weight: 800; line-height: 1; letter-spacing: -0.04em; font-variant-numeric: tabular-nums; margin: 12px 0 6px; }
.run-label { font-size: 17px; color: var(--muted); min-height: 1.4em; }
.run-next { margin-top: 18px; font-size: 17px; padding: 8px 14px; border-radius: 99px; background: var(--bg); }
.run-meta { display: grid; grid-template-columns: repeat(3, 1fr); text-align: center; gap: 8px; margin-bottom: 10px; }
.run-meta b { display: block; font-size: 22px; font-variant-numeric: tabular-nums; }
.run-meta span { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.run .segbar { height: 14px; position: relative; }
.marker { position: relative; height: 0; }
.marker > i { position: absolute; top: -26px; width: 3px; height: 22px; background: var(--text); border-radius: 2px; transform: translateX(-1px); }
.run-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; }
.paused .run-clock { opacity: .45; animation: blink 1.2s infinite; }
@keyframes blink { 50% { opacity: .2; } }
.finish-screen { text-align: center; padding-top: 12vh; }
.finish-screen .big-emoji { font-size: 72px; }

/* navegação */
#tabs {
  position: fixed; left: 0; right: 0; bottom: 0; display: flex; justify-content: space-around;
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line); padding: 6px 4px calc(6px + var(--safe-b)); z-index: 10;
}
#tabs a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; color: var(--muted); text-decoration: none; padding: 4px 0; font-weight: 600; }
#tabs svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
#tabs a.on { color: var(--accent); }

#toast {
  position: fixed; left: 50%; bottom: calc(90px + var(--safe-b)); transform: translateX(-50%) translateY(20px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-weight: 600; font-size: 14px;
  opacity: 0; pointer-events: none; transition: .2s; max-width: calc(100% - 32px); z-index: 20;
}
#toast.show { opacity: 1; transform: translateX(-50%); }
#toast.err { background: var(--danger); color: #fff; }

table.preview { width: 100%; border-collapse: collapse; font-size: 13px; }
table.preview td { padding: 6px 4px; border-top: 1px solid var(--line); vertical-align: top; }
table.preview td:first-child { color: var(--muted); white-space: nowrap; width: 1%; padding-right: 10px; }
.empty { text-align: center; padding: 30px 16px; }

/* ── v3: registro, evolução ── */
.rpe { display: grid; grid-template-columns: repeat(10, 1fr); gap: 4px; margin: 6px 0 4px; }
.rpe .chip { padding: 8px 0; text-align: center; font-variant-numeric: tabular-nums; }
.moods { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 6px; }
.moods .chip { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0; border-radius: 12px; }
.moods .chip span { font-size: 24px; line-height: 1; }
.moods .chip small { font-size: 11px; }

.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.tile b { display: block; font-size: 26px; font-weight: 800; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.tile span { font-size: 12px; color: var(--muted); }

.chart-title { font-weight: 700; }
.chart-plot { position: relative; margin: 10px 0 4px; }
.chart svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .grid.base { stroke: #3a414c; }
.chart .ax { fill: var(--muted); font-size: 10px; font-variant-numeric: tabular-nums; }
.chart .mark { fill: var(--accent); }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .dot { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }
.chart .hit { fill: transparent; cursor: pointer; }
.chart rect.hit.on { fill: rgba(255,255,255,0.06); }
.chart .tip {
  position: absolute; top: -6px; transform: translate(-50%, -100%); white-space: nowrap; pointer-events: none;
  background: var(--text); color: var(--bg); font-size: 12px; font-weight: 600; padding: 6px 9px; border-radius: 8px; z-index: 2;
}
.chart details { margin-top: 6px; }

/* ── v5: academia ── */
#tabs a[hidden] { display: none; }
.ex-edit { border-top: 1px solid var(--line); padding: 12px 0; margin-top: 10px; }
.ex-edit .row { margin-bottom: 8px; }
.gym-ex .set-head, .gym-ex .set-row { display: grid; grid-template-columns: 34px 1fr 1fr 52px; gap: 8px; align-items: center; }
.gym-ex .set-head { margin: 10px 0 4px; }
.gym-ex .set-row { margin-bottom: 6px; }
.gym-ex .set-row input { min-height: 42px; text-align: center; font-variant-numeric: tabular-nums; }
.gym-ex .set-row.done input { border-color: color-mix(in srgb, var(--accent) 50%, transparent); color: var(--accent); }
.gym-ex .set-row .btn { min-height: 42px; padding: 0; }
.rest-bar {
  position: fixed; left: 12px; right: 12px; bottom: calc(12px + var(--safe-b)); z-index: 15;
  display: flex; align-items: center; gap: 8px; padding: 12px 14px; border-radius: 16px;
  background: var(--surface-2); border: 2px solid var(--accent); box-shadow: 0 8px 30px rgba(0,0,0,.5);
}
.rest-bar b { font-size: 28px; font-weight: 800; }
.rest-bar.ending { border-color: var(--tiro); }
.rest-bar.ending b { color: var(--tiro); }
body.running .rest-bar { bottom: calc(12px + var(--safe-b)); }
