/* IvanGym – mobile-first, modo claro */

:root {
  --bg: #f5f6f8;
  --card: #fff;
  --card-2: #eef1f4;
  --line: #dde2e8;
  --text: #1c2127;
  --muted: #5f6b78;
  --accent: #ffb020;
  --accent-text: #b45309;
  --accent-ink: #1a1200;
  --ok: #2f9e5f;
  --danger: #d63c3c;
  --radius: 14px;
  --tabbar-h: 64px;
  color-scheme: light;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px);
}

h1, h2, h3, h4, p {
  margin: 0;
}

h2 {
  font-size: 1.6rem;
}

h3 {
  font-size: 1.08rem;
}

h4 {
  margin: 18px 0 6px;
  font-size: 0.95rem;
}

a {
  color: var(--accent-text);
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

.muted {
  color: var(--muted);
}

.small-text {
  font-size: 0.85rem;
  margin-top: 12px;
}

/* ---------- Estructura ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: rgba(245, 246, 248, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}

.brand {
  font-size: 1.25rem;
  letter-spacing: 0.02em;
}

.brand span {
  color: var(--accent-text);
}

.topbar-date {
  color: var(--muted);
  font-size: 0.9rem;
}

.view {
  max-width: 640px;
  margin: 0 auto;
  padding: 12px 12px 0;
  outline: none;
}

.page-head {
  margin: 8px 4px 12px;
}

.back {
  display: inline-block;
  margin-bottom: 6px;
  text-decoration: none;
  font-weight: 600;
}

.tabbar {
  position: fixed;
  inset: auto 0 0;
  z-index: 10;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: #fff;
  border-top: 1px solid var(--line);
}

.tabbar a {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--muted);
  font-size: 0.75rem;
  text-decoration: none;
}

.tabbar a span {
  font-size: 1.35rem;
  filter: grayscale(1);
  opacity: 0.7;
}

.tabbar a.active {
  color: var(--accent-text);
  font-weight: 600;
}

.tabbar a.active span {
  filter: none;
  opacity: 1;
}

/* ---------- Componentes ---------- */

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

.card > h3 {
  margin-bottom: 8px;
}

.card > .btn {
  margin-top: 12px;
}

.eyebrow {
  color: var(--muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 8px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 48px;
  padding: 10px 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card-2);
  font-weight: 600;
  text-decoration: none;
  color: var(--text);
  cursor: pointer;
  width: 100%;
}

.btn:active {
  transform: scale(0.98);
}

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.btn.big {
  min-height: 60px;
  font-size: 1.1rem;
  flex-direction: column;
  gap: 0;
}

.btn.big small {
  font-weight: 500;
  font-size: 0.8rem;
  opacity: 0.8;
}

.btn.small {
  min-height: 40px;
  padding: 6px 12px;
  font-size: 0.9rem;
  width: auto;
}

.btn.ghost {
  background: transparent;
}

.btn.danger {
  background: transparent;
  border-color: var(--danger);
  color: var(--danger);
}

.btn:disabled {
  opacity: 0.4;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  flex: none;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  font-size: 1.2rem;
  text-decoration: none;
  cursor: pointer;
}

.actions {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}

.hint {
  color: var(--muted);
  font-size: 0.88rem;
  margin-top: 12px;
}

.badge {
  display: inline-grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 8px;
  font-weight: 800;
  font-size: 0.9rem;
  color: #111;
  background: var(--rc, var(--muted));
  vertical-align: middle;
}

.routine-title {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 4px;
}

.routine-desc {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.85rem;
}

.routine-title .badge {
  width: 40px;
  height: 40px;
  font-size: 1.2rem;
}

.chips {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  overflow-x: auto;
}

.chip {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 52px;
  padding: 6px 10px;
  border-radius: 12px;
  border: 1px solid var(--line);
  border-top: 3px solid var(--line);
  background: var(--card-2);
  font-weight: 600;
  font-size: 0.9rem;
  white-space: nowrap;
  cursor: pointer;
}

.chip small {
  color: var(--muted);
  font-weight: 400;
  font-size: 0.75rem;
}

.chip[style] { border-top-color: var(--rc); }

.chip.active {
  background: #fff3d6;
  outline: 2px solid var(--accent);
}

/* ---------- Splash con mensaje motivador ---------- */

.splash {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 24px;
  background: linear-gradient(160deg, #fff4d6, #efe8ff);
  text-align: center;
  cursor: pointer;
  animation: splash-in 0.3s ease-out;
  transition: opacity 0.4s ease;
}

.splash.out {
  opacity: 0;
  pointer-events: none;
}

.splash-box {
  max-width: 420px;
}

.splash .brand {
  font-size: 2.2rem;
  font-weight: 800;
}

.splash-quote {
  margin: 28px 0;
  font-size: 1.35rem;
  font-weight: 700;
  line-height: 1.35;
}

@keyframes splash-in {
  from { opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .splash {
    animation: none;
    transition: none;
  }
}

/* ---------- Ejercicios ---------- */

.ex-card {
  padding: 14px 12px;
}

.ex-card.complete {
  border-color: var(--ok);
}

.ex-head {
  display: flex;
  gap: 14px;
}

.gif-btn {
  flex: none;
  padding: 0;
  border: 0;
  border-radius: 10px;
  overflow: hidden;
  background: #fff;
  cursor: zoom-in;
  align-self: flex-start;
}

.ex-gif {
  display: block;
  width: 104px;
  height: auto;
  aspect-ratio: 116 / 167;
  object-fit: cover;
}

.ex-info {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.ex-info h3 {
  line-height: 1.25;
}

.muscles {
  font-size: 0.88rem;
}

.presc {
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--accent-text);
}

.ex-tip,
.ex-last {
  margin-top: 10px;
  font-size: 0.88rem;
}

.ex-last {
  color: var(--muted);
}

.ex-note {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
}

.ex-note textarea {
  flex: 1;
  min-width: 0;
  min-height: 42px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card-2);
  font: inherit;
  font-size: 1rem;
  color: inherit;
  resize: none;
  field-sizing: content;
}

.ex-note textarea:placeholder-shown {
  border-style: dashed;
}

.ex-next {
  margin-top: 4px;
  font-size: 0.88rem;
}

.ex-next.next-up strong {
  color: var(--ok);
}

.ex-next.next-down strong {
  color: var(--danger);
}

.sets {
  margin-top: 10px;
}

.set-head,
.set-row {
  display: grid;
  grid-template-columns: 14px 1.3fr 1fr 38px;
  align-items: center;
  gap: 4px;
}

.set-head {
  color: var(--muted);
  font-size: 0.7rem;
  text-align: center;
  text-transform: uppercase;
}

.set-row {
  padding: 6px 0;
  border-top: 1px solid var(--line);
}

.set-n {
  color: var(--muted);
  font-weight: 700;
  text-align: center;
}

.stepper {
  display: flex;
  align-items: center;
  background: var(--card-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}

.stepper button {
  flex: none;
  width: 24px;
  padding: 0;
  height: 40px;
  border: 0;
  background: transparent;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--accent-text);
  cursor: pointer;
}

.stepper button:active {
  background: #e2e7ec;
}

.stepper input {
  flex: 1;
  width: 100%;
  min-width: 0;
  height: 40px;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--text);
  -webkit-appearance: none;
  appearance: none;
  text-align: center;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -0.02em;
}

.check {
  width: 38px;
  height: 40px;
  border-radius: 10px;
  border: 2px solid var(--line);
  background: transparent;
  color: transparent;
  font-size: 1.4rem;
  font-weight: 900;
  cursor: pointer;
}

.set-row.done .check {
  background: var(--ok);
  border-color: var(--ok);
  color: #fff;
}

.set-row.done .stepper {
  border-color: #9fd8b6;
}

.set-tools {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 8px;
}

.feel {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.feel-q {
  flex: none;
  font-weight: 600;
  font-size: 0.9rem;
}

.feel-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-height: 52px;
  padding: 6px 4px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card-2);
  color: var(--text);
  font: inherit;
  font-size: 0.8rem;
  cursor: pointer;
}

.feel-btn span {
  font-size: 1.3rem;
}

.feel-btn[aria-pressed="true"] {
  background: #fff3d6;
  border-color: var(--accent);
  outline: 2px solid var(--accent);
  font-weight: 700;
}

/* ---------- Actividades ---------- */

.activities {
  list-style: none;
  margin: 0;
  padding: 0;
}

.activities li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}

.activities li > div {
  flex: 1;
}

.act-icon {
  font-size: 1.5rem;
}

.tips ul {
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
  font-size: 0.9rem;
}

.tips li + li {
  margin-top: 4px;
}

.finish {
  margin: 16px 0 8px;
  text-align: center;
}

.done-msg {
  color: var(--ok);
  font-weight: 700;
  margin-bottom: 10px;
}

/* ---------- Historial ---------- */

.cal-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  font-size: 1.05rem;
}

.cal-nav .icon-btn {
  font-size: 1.8rem;
  color: var(--accent-text);
}

.cal {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}

.cal-dow {
  text-align: center;
  font-size: 0.75rem;
  color: var(--muted);
  padding-bottom: 4px;
}

.cal-cell {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  aspect-ratio: 1;
  border-radius: 10px;
  background: var(--card-2);
  color: var(--text);
  text-decoration: none;
  font-weight: 600;
  line-height: 1.1;
}

.cal-cell small {
  font-size: 0.62rem;
  font-weight: 800;
}

.cal-cell.empty {
  background: transparent;
}

.cal-cell.future {
  opacity: 0.35;
}

.cal-cell.today {
  outline: 2px solid var(--accent);
}

.cal-cell.strength {
  color: #111;
  background: var(--rc, var(--accent));
}

.cal-cell.activity {
  background: #b7e4c7;
}

.cal-cell .dot,
.legend .dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--ok);
}

.cal-cell .dot {
  position: absolute;
  top: 4px;
  right: 4px;
  box-shadow: 0 0 0 1.5px #fff;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  margin: 12px 0 6px;
  font-size: 0.82rem;
  color: var(--muted);
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.sw {
  width: 14px;
  height: 14px;
  border-radius: 4px;
}

.sw.strength {
  background: var(--accent);
}

.sw.activity {
  background: #b7e4c7;
}

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(72px, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 12px 6px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.stat strong {
  font-size: 1.6rem;
  color: var(--accent-text);
}

.stat span {
  font-size: 0.75rem;
  color: var(--muted);
}

.session-list,
.progress-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.session-list a,
.progress-list a {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
  color: var(--text);
  text-decoration: none;
}

.session-list .date {
  font-weight: 600;
  white-space: nowrap;
}

.session-list a > span:last-child {
  text-align: right;
  font-size: 0.9rem;
  color: var(--muted);
}

/* ---------- Progreso ---------- */

.progress-list img {
  flex: none;
  width: 40px;
  height: 58px;
  object-fit: cover;
  border-radius: 6px;
  background: #fff;
}

.progress-list .name {
  flex: 1;
  display: flex;
  flex-direction: column;
  font-weight: 600;
}

.progress-list .name small {
  font-weight: 400;
}

.progress-list .kg {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  font-weight: 800;
  white-space: nowrap;
}

.up {
  color: var(--ok);
  font-weight: 700;
}

.chart {
  display: block;
  width: 100%;
  height: auto;
  margin: 4px 0 8px;
}

.chart text {
  fill: var(--muted);
  font-size: 11px;
}

.chart text.small {
  font-size: 9px;
}

.chart .grid {
  stroke: var(--line);
  stroke-dasharray: 4 4;
}

.chart .line {
  fill: none;
  stroke: var(--accent);
  stroke-width: 3;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.chart circle {
  fill: var(--bg);
  stroke: var(--accent);
  stroke-width: 2.5;
}

.chart .bar {
  fill: #cfd6de;
}

.chart .bar.current {
  fill: var(--accent);
}

/* ---------- Ajustes ---------- */

.video-field {
  display: block;
  margin-top: 10px;
  font-size: 0.9rem;
}

.video-field input,
.form input,
.form select {
  display: block;
  width: 100%;
  margin-top: 4px;
  min-height: 46px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card-2);
}

.video-field input {
  font-size: 0.85rem;
}

.card.danger {
  border-color: #f0b4b4;
}

.actions .btn {
  flex: 1;
  width: auto;
  white-space: nowrap;
  font-size: 0.95rem;
}

/* ---------- Diálogo y toast ---------- */

.dialog {
  width: min(94vw, 560px);
  max-height: 90vh;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--card);
  color: var(--text);
}

.dialog::backdrop {
  background: rgba(0, 0, 0, 0.45);
}

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

.form label {
  font-size: 0.9rem;
  color: var(--muted);
}

.row2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.video-box h3,
.summary h3 {
  margin-bottom: 12px;
}

.video-box h3 small {
  display: block;
  margin-top: 2px;
  font-size: 0.8rem;
}

.dialog:has(.video-box) {
  width: min(96vw, 720px);
  padding: 12px;
}

.video-box .actions {
  margin-top: 12px;
}

.video-box .actions .btn {
  min-width: 0;
}

.video-frame {
  position: relative;
  width: min(100%, calc((100dvh - 240px) * 16 / 9));
  margin: 0 auto;
  aspect-ratio: 16 / 9;
  border-radius: 10px;
  overflow: hidden;
  background: #000;
}

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

.zoom-box {
  text-align: center;
  cursor: zoom-out;
}

.zoom-box img {
  width: 100%;
  max-height: 72vh;
  object-fit: contain;
  border-radius: 10px;
  background: #fff;
}

.zoom-box p {
  margin-top: 8px;
}

.summary ul {
  padding-left: 18px;
}

.summary li {
  margin: 4px 0;
}

.quote-inline {
  margin-top: 12px;
  padding: 12px;
  border-radius: 10px;
  background: #fff4d6;
  font-weight: 600;
}

.toast {
  position: fixed;
  left: 50%;
  top: calc(64px + env(safe-area-inset-top));
  z-index: 20;
  width: max-content;
  max-width: 90vw;
  padding: 12px 18px;
  border-radius: 999px;
  background: #1c2127;
  color: #fff;
  font-weight: 600;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.2);
  opacity: 0;
  transform: translate(-50%, -12px);
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  text-align: center;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (min-width: 560px) {
  .ex-gif {
    width: 130px;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
}

.nowrap {
  white-space: nowrap;
}

.video-btns {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.video-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
}

.video-field > span {
  font-weight: 600;
}

.video-field label {
  display: block;
  margin-top: 6px;
}

@media (max-height: 500px) {
  .video-box h3 {
    margin-bottom: 6px;
  }

  .video-box h3 small {
    display: inline;
    margin-left: 6px;
  }

  .video-tabs {
    margin-bottom: 6px;
  }

  .video-frame {
    width: min(100%, calc((100dvh - 190px) * 16 / 9));
  }

  .video-box .actions {
    margin-top: 8px;
  }

  .video-box .actions .btn {
    min-height: 40px;
    padding-block: 6px;
  }
}

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

.body-map {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(0, 1fr));
  gap: 4px;
}

.body-map.labeled {
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 12px;
}

.body-view {
  margin: 0;
  text-align: center;
}

.body-view svg {
  display: block;
  width: 100%;
  height: auto;
  margin: 0 auto;
}

.body-view.labeled svg {
  max-width: 420px;
}

.body-view figcaption {
  font-size: 0.8rem;
  color: var(--muted);
}

.body-view .bone {
  fill: #e3e7ec;
}

.body-view .m polygon {
  fill: #f6dcd5;
  transition: fill 0.15s;
}

.body-view .m.sec polygon {
  fill: #ffa8a8;
}

.body-view .m.pri polygon {
  fill: #e03131;
}

.body-view [data-muscle] {
  cursor: pointer;
}

.body-view .m[data-muscle]:hover polygon {
  fill: var(--accent);
}

.body-view .lbl text {
  font-size: 7px;
  fill: var(--text);
}

.body-view .lbl.pri text,
.body-view .lbl.sec text {
  font-weight: 700;
}

.body-view .lbl.pri text {
  fill: #c92a2a;
}

.body-view .lbl polyline {
  fill: none;
  stroke: #9aa5b1;
  stroke-width: 0.4;
}

.body-view .lbl circle {
  fill: #495057;
}

.muscles {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.muscles .body-map {
  flex: none;
  width: 52px;
  gap: 0;
}

.muscles .body-view figcaption {
  display: none;
}

.mu-legend {
  margin: 4px 0;
  font-size: 0.9rem;
}

.mu-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  margin-right: 6px;
  border-radius: 50%;
  vertical-align: baseline;
}

.mu-dot.pri {
  background: #e03131;
}

.mu-dot.sec {
  background: #ffa8a8;
}

.dialog .body-map {
  margin: 10px 0;
}

.dialog h4 {
  margin-top: 14px;
}

.mu-routines {
  display: flex;
  gap: 4px;
}

.muscle-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 8px;
  margin: 10px 0 0;
  padding: 0;
  list-style: none;
}

.muscle-list button {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card-2);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
}

.muscle-list small {
  font-weight: 400;
  font-size: 0.75rem;
}

.dialog .body-map:not(.labeled) {
  max-width: 160px;
  margin: 10px auto;
}

.dialog p + p {
  margin-top: 6px;
}
