/* Todas as cores vêm de css/theme.css (custom properties). Nenhum hex aqui. */

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.6;
  -webkit-tap-highlight-color: transparent;
}

body {
  padding-bottom: env(safe-area-inset-bottom);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------- Cabeçalho: lista de exercícios ---------- */

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: max(14px, env(safe-area-inset-top)) 16px 14px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.app-title {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.routine-picker {
  flex: 0 1 auto;
  min-width: 0;
  max-width: 50%;
}

.routine-picker select {
  width: 100%;
  min-width: 0;
  font-size: 15px;
  padding: 10px 12px;
  min-height: var(--tap-min);
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}

/* ---------- Cabeçalho: detalhe do exercício (sticky) ---------- */

.detail-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: max(10px, env(safe-area-inset-top)) 16px 10px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.detail-header[hidden] {
  display: none;
}

.back-button {
  flex: 0 0 auto;
  width: var(--tap-min);
  height: var(--tap-min);
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  font-size: 20px;
  cursor: pointer;
  padding: 0;
}

.detail-header-name {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 17px;
  font-weight: 600;
}

.view-root {
  padding: 16px;
  max-width: 640px;
  margin: 0 auto;
  width: 100%;
}

.view[hidden] {
  display: none;
}

/* ---------- Lista de exercícios ---------- */

.exercise-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.exercise-item {
  width: 100%;
  min-width: 0;
}

.exercise-button {
  width: 100%;
  min-width: 0;
  min-height: 64px;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  color: var(--text);
  font-size: 16px;
  font-family: inherit;
  text-align: left;
  cursor: pointer;
}

.exercise-button:active {
  background: var(--bg);
}

.exercise-order {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--chip-on-primary-text);
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
}

.exercise-info {
  flex: 1 1 auto;
  min-width: 0;
}

.exercise-name {
  font-weight: 600;
  display: block;
  overflow-wrap: break-word;
}

.exercise-sets {
  display: block;
  color: var(--text-muted);
  font-size: 13px;
  margin-top: 2px;
}

/* ---------- Detalhe do exercício ---------- */

.detail-meta {
  margin: 4px 0 16px;
  color: var(--text-muted);
  font-size: 13px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.detail-meta .meta-badge {
  color: var(--accent-text);
  font-weight: 600;
  border: 1px solid var(--accent-text);
  border-radius: 999px;
  padding: 1px 8px;
  font-size: 12px;
}

.section-label {
  margin: 0 0 10px;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.02em;
  color: var(--text-muted);
}

.detail-o-que-faz {
  margin: 0 0 20px;
  font-size: 16px;
  line-height: 1.6;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  margin-bottom: 14px;
}

.detail-dicas {
  margin: 0;
  padding-left: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 16px;
}

.detail-dicas li {
  padding-left: 2px;
}

/* ---------- Chips de músculo ---------- */

.muscle-chip-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 14px;
}

.chip-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip-list:empty {
  display: none;
}

.muscle-chip {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.2;
}

.muscle-chip.primary {
  background: var(--muscle-primary);
  color: var(--chip-on-primary-text);
}

.muscle-chip.secondary {
  background: var(--muscle-secondary);
  color: var(--chip-on-secondary-text);
}

/* ---------- Mapa muscular ---------- */

.bodymap-wrap {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.bodymap-views {
  display: flex;
  gap: 12px;
  min-width: 0;
}

.bodymap-view {
  flex: 1 1 50%;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.bodymap-view-label {
  color: var(--text-muted);
  font-size: 13px;
  letter-spacing: 0.02em;
}

.bodymap-container {
  width: 100%;
  max-width: 160px;
}

.bodymap-container svg.rbh {
  width: 100%;
  height: auto;
  display: block;
}

.bodymap-legend {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  gap: 16px;
  font-size: 13px;
  color: var(--text-muted);
}

.bodymap-legend li {
  display: flex;
  align-items: center;
  gap: 6px;
}

.legend-swatch {
  flex: 0 0 auto;
  width: 12px;
  height: 12px;
  border-radius: 4px;
}

.legend-swatch.primary {
  background: var(--muscle-primary);
}

.legend-swatch.secondary {
  background: var(--muscle-secondary);
}

/* ---------- Vídeo ---------- */

.video-container {
  display: flex;
  min-width: 0;
}

.video-button {
  width: 100%;
  min-width: 0;
  min-height: 52px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--accent);
  color: var(--chip-on-primary-text);
  font-size: 16px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
}

.video-frame-wrap {
  position: relative;
  width: 100%;
  max-width: calc(70vh * 9 / 16);
  aspect-ratio: 9 / 16;
  max-height: 70vh;
  margin: 0 auto;
  border-radius: 12px;
  overflow: hidden;
  background: #000;
}

.video-frame-wrap iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
}

.video-unavailable {
  color: var(--text-muted);
  font-size: 14px;
  margin: 0;
}

.video-error-link {
  color: var(--accent-text);
  font-weight: 600;
}

.empty-message {
  color: var(--text-muted);
  text-align: center;
  margin-top: 40px;
}

/* ---------- Navegação sequencial (rodapé, tela de detalhe) ---------- */

.sequence-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px max(10px, env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--border);
}

.sequence-nav[hidden] {
  display: none;
}

.sequence-button {
  flex: 0 0 auto;
  width: var(--tap-min);
  height: var(--tap-min);
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  color: var(--text);
  font-size: 20px;
  cursor: pointer;
  padding: 0;
}

.sequence-button:disabled {
  opacity: 0.4;
  cursor: default;
}

.sequence-indicator {
  flex: 1 1 auto;
  text-align: center;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-muted);
}

/* Espaço para a barra de navegação fixa não cobrir o conteúdo */
body.has-sequence-nav .view-root {
  padding-bottom: calc(var(--tap-min) + 20px + env(safe-area-inset-bottom));
}

@media (min-width: 480px) {
  html, body {
    font-size: 17px;
  }
}
