:root {
  --bg: #0f1115;
  --card: #1a1d24;
  --card2: #22262f;
  --border: #2a2f3a;
  --text: #e8eaee;
  --muted: #9aa1ad;
  --green: #4ade80;
  --orange: #f97316;
  --red: #ef4444;
  --blue: #60a5fa;
}
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  min-height: 100%; overscroll-behavior-y: none;
  padding-top: env(safe-area-inset-top);
}
#app { max-width: 520px; margin: 0 auto; min-height: 100dvh; display: flex; flex-direction: column; }
#view { flex: 1; padding: 16px 16px calc(90px + env(safe-area-inset-bottom)); }
.hidden { display: none !important; }

/* Tab bar */
#tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 50;
  display: flex; justify-content: space-around;
  background: rgba(20, 23, 30, .92); backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  max-width: 520px; margin: 0 auto;
}
#tabbar a {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  color: var(--muted); text-decoration: none; font-size: 11px; font-weight: 600;
  padding: 6px 10px; border-radius: 12px; min-width: 56px; min-height: 44px;
}
#tabbar a span { font-size: 20px; }
#tabbar a.active { color: var(--green); }

/* Genéricos */
h1 { font-size: 24px; font-weight: 800; }
h2 { font-size: 18px; font-weight: 700; margin: 18px 0 10px; }
.muted { color: var(--muted); }
.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 16px; padding: 16px; margin-bottom: 12px;
}
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: none; border-radius: 14px; padding: 14px 20px;
  font-size: 16px; font-weight: 700; font-family: inherit; cursor: pointer;
  min-height: 48px; color: #0f1115; background: var(--green);
  transition: transform .08s, opacity .2s;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; }
.btn.secondary { background: var(--card2); color: var(--text); border: 1px solid var(--border); }
.btn.orange { background: var(--orange); color: #fff; }
.btn.danger { background: var(--red); color: #fff; }
.btn.block { width: 100%; }
.btn.small { padding: 8px 14px; min-height: 38px; font-size: 14px; border-radius: 10px; }
input, select, textarea {
  width: 100%; background: var(--card2); border: 1px solid var(--border);
  border-radius: 12px; padding: 13px 14px; color: var(--text);
  font-size: 16px; font-family: inherit; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--green); }
label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin: 12px 0 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  background: var(--card2); border: 1px solid var(--border);
  border-radius: 999px; padding: 5px 12px; font-size: 13px; font-weight: 600; color: var(--muted);
}
.chip.green { color: var(--green); border-color: rgba(74, 222, 128, .35); }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* Login */
.login-hero { text-align: center; padding: 60px 0 30px; }
.login-hero .logo { font-size: 64px; }
.login-hero h1 { margin-top: 8px; }
.login-hero p { color: var(--muted); margin-top: 6px; }

/* Toast */
#toast {
  position: fixed; bottom: 100px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--card2); border: 1px solid var(--border); color: var(--text);
  padding: 12px 20px; border-radius: 999px; font-weight: 600; font-size: 14px;
  opacity: 0; pointer-events: none; transition: all .25s; z-index: 100; max-width: 90vw; text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.error { border-color: var(--red); color: #fca5a5; }

/* Spinner / skeleton */
.spinner {
  width: 36px; height: 36px; border-radius: 50%;
  border: 3px solid var(--border); border-top-color: var(--green);
  animation: spin .8s linear infinite; margin: 40px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }
.center { text-align: center; }
.skeleton { background: var(--card); border-radius: 16px; min-height: 90px; margin-bottom: 12px; animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .55; } }
.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty .big { font-size: 48px; margin-bottom: 10px; }

/* Animación ejercicio */
.ex-anim {
  width: 100%; aspect-ratio: 1; max-height: 320px; object-fit: contain;
  background: #fff; border-radius: 16px;
}

/* Hoy */
.greeting { margin: 8px 0 18px; }
.greeting h1 { font-size: 26px; }
.greeting p { color: var(--muted); margin-top: 4px; text-transform: capitalize; }
.meal-mini { display: flex; align-items: center; gap: 12px; }
.meal-mini .emoji { font-size: 34px; }
.meal-mini .info { flex: 1; min-width: 0; }
.meal-mini .info b { display: block; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Entreno ejecución */
.player-top { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.progress-bar { flex: 1; height: 6px; background: var(--card2); border-radius: 999px; overflow: hidden; }
.progress-bar > div { height: 100%; background: var(--green); border-radius: 999px; transition: width .3s; }
.set-row {
  display: flex; align-items: center; gap: 12px;
  background: var(--card2); border: 1px solid var(--border);
  border-radius: 14px; padding: 10px 14px; margin-bottom: 8px;
}
.set-row.done { border-color: rgba(74, 222, 128, .5); background: rgba(74, 222, 128, .08); }
.set-check {
  width: 44px; height: 44px; border-radius: 50%; flex-shrink: 0;
  border: 2px solid var(--border); background: transparent; color: transparent;
  font-size: 20px; cursor: pointer;
}
.set-row.done .set-check { background: var(--green); border-color: var(--green); color: #0f1115; }
.set-row input { width: 64px; padding: 8px; text-align: center; font-size: 14px; }
.rest-overlay {
  position: fixed; inset: 0; z-index: 80; background: rgba(15, 17, 21, .96);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px;
  padding-top: env(safe-area-inset-top);
}
.rest-time { font-size: 96px; font-weight: 800; font-variant-numeric: tabular-nums; color: var(--green); }

/* Onboarding */
.ob-card { position: relative; border: 2px solid var(--border); }
.ob-card.ob-on { border-color: var(--green); background: rgba(74, 222, 128, .1); }
.ob-check {
  position: absolute; top: 6px; right: 6px; width: 24px; height: 24px;
  border-radius: 50%; background: var(--green); color: #0f1115;
  font-weight: 800; font-size: 14px; display: flex; align-items: center; justify-content: center;
}
.ob-card:not(.ob-on) .ob-check { background: transparent; border: 2px solid var(--border); color: transparent; }

.del-item { background: none; border: none; color: var(--muted); font-size: 14px; cursor: pointer; padding: 6px; }

/* Mazo de tarjetas (swipe) */
.deck-area { position: relative; height: 480px; margin: 14px 0; touch-action: none; }
.deck-card {
  position: absolute; inset: 0; background: var(--card); border: 1px solid var(--border);
  border-radius: 20px; padding: 22px; overflow-y: auto; user-select: none;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .35);
  will-change: transform;
}
.deck-card .emoji { font-size: 72px; text-align: center; display: block; margin: 6px 0 10px; }
.deck-card h2 { text-align: center; margin: 0 0 4px; font-size: 21px; }
.deck-card .cuisine { text-align: center; color: var(--muted); font-size: 14px; text-transform: capitalize; margin-bottom: 12px; }
.deck-actions { display: flex; justify-content: space-between; gap: 10px; padding: 0 6px 10px; }
.deck-actions button {
  flex: 1; border: none; border-radius: 16px; min-height: 56px;
  font-size: 13px; font-weight: 700; font-family: inherit; cursor: pointer; line-height: 1.15;
}
.deck-actions .no { background: rgba(239, 68, 68, .15); color: #fca5a5; border: 1px solid rgba(239, 68, 68, .4); }
.deck-actions .pass { background: var(--card2); color: var(--text); border: 1px solid var(--border); }
.deck-actions .yes { background: var(--green); color: #0f1115; }
.deck-hint { text-align: center; color: var(--muted); font-size: 12px; }

/* Semana comidas */
.day-block { margin-bottom: 14px; }
.day-block h3 { font-size: 14px; color: var(--muted); text-transform: capitalize; margin-bottom: 6px; }
.slot-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.slot-cell {
  background: var(--card); border: 1px solid var(--border); border-radius: 12px;
  min-height: 74px; padding: 6px; font-size: 11px; text-align: center;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  cursor: pointer; overflow: hidden;
}
.slot-cell .e { font-size: 24px; }
.slot-cell.empty-slot { color: var(--muted); border-style: dashed; font-size: 18px; }
.slot-cell .n { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; line-height: 1.2; }

/* Compra */
.aisle-head {
  display: flex; align-items: center; gap: 10px; width: 100%;
  background: var(--card); border: 1px solid var(--border); border-radius: 14px;
  padding: 14px 16px; margin-bottom: 6px; font-size: 16px; font-weight: 700;
  color: var(--text); cursor: pointer; font-family: inherit; text-align: left;
}
.aisle-items { padding: 4px 0 10px 8px; }
.buy-item { display: flex; align-items: center; gap: 12px; padding: 10px 8px; border-bottom: 1px solid var(--border); }
.buy-item:last-child { border-bottom: none; }
.buy-item .cbx { width: 32px; height: 32px; border-radius: 10px; border: 2px solid var(--border); background: transparent; color: transparent; font-size: 16px; cursor: pointer; flex-shrink: 0; }
.buy-item.checked .cbx { background: var(--green); border-color: var(--green); color: #0f1115; }
.buy-item .nm { flex: 1; font-size: 15px; }
.buy-item.checked .nm { text-decoration: line-through; color: var(--muted); }
.buy-item .qt { color: var(--muted); font-size: 13px; }
.week-nav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.week-nav button { background: var(--card2); border: 1px solid var(--border); color: var(--text); border-radius: 12px; width: 44px; height: 44px; font-size: 18px; cursor: pointer; }
.week-nav b { font-size: 15px; }

/* Más */
.menu-item {
  display: flex; align-items: center; gap: 14px; width: 100%;
  background: var(--card); border: 1px solid var(--border); border-radius: 14px;
  padding: 16px; margin-bottom: 10px; color: var(--text); font-size: 16px; font-weight: 600;
  cursor: pointer; font-family: inherit; text-align: left;
}
.menu-item .ic { font-size: 22px; }
.equip-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.equip-card {
  background: var(--card); border: 1px solid var(--border); border-radius: 14px;
  padding: 14px 8px; text-align: center; cursor: pointer;
}
.equip-card .ic { font-size: 34px; }
.equip-card img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 10px; }
.equip-card .nm { font-size: 12px; font-weight: 600; margin-top: 6px; line-height: 1.25; }
.fab {
  position: fixed; bottom: calc(96px + env(safe-area-inset-bottom)); right: max(16px, calc(50vw - 244px));
  width: 58px; height: 58px; border-radius: 50%; border: none;
  background: var(--green); color: #0f1115; font-size: 28px; cursor: pointer;
  box-shadow: 0 6px 20px rgba(74, 222, 128, .35); z-index: 40;
}

/* Sheet modal */
.sheet-bg { position: fixed; inset: 0; background: rgba(0, 0, 0, .6); z-index: 90; display: flex; align-items: flex-end; justify-content: center; }
.sheet {
  background: var(--card); border: 1px solid var(--border); border-bottom: none;
  border-radius: 22px 22px 0 0; width: 100%; max-width: 520px; max-height: 86dvh;
  overflow-y: auto; padding: 20px 20px calc(24px + env(safe-area-inset-bottom));
  animation: rise .25s ease-out;
}
@keyframes rise { from { transform: translateY(60px); opacity: .5; } }
.sheet .grab { width: 40px; height: 4px; background: var(--border); border-radius: 999px; margin: 0 auto 16px; }

/* Sub-pestañas */
.subtabs { display: flex; background: var(--card); border: 1px solid var(--border); border-radius: 14px; padding: 4px; margin-bottom: 14px; }
.subtabs button {
  flex: 1; border: none; background: transparent; color: var(--muted);
  padding: 10px; border-radius: 10px; font-weight: 700; font-size: 14px; cursor: pointer; font-family: inherit;
}
.subtabs button.active { background: var(--card2); color: var(--green); }

.back-link { background: none; border: none; color: var(--muted); font-size: 15px; font-weight: 600; cursor: pointer; padding: 8px 0; font-family: inherit; }
details { margin-top: 10px; }
summary { cursor: pointer; color: var(--muted); font-weight: 600; font-size: 14px; padding: 6px 0; }
ol.steps { padding-left: 20px; margin-top: 8px; }
ol.steps li { margin-bottom: 6px; font-size: 14px; line-height: 1.45; }
.ing-list { font-size: 14px; color: var(--muted); line-height: 1.6; margin-top: 6px; }
