:root {
  --bg: #fbf7f2;
  --card: #ffffff;
  --soft: #f3ece3;
  --line: #e8dfd3;
  --text: #2a2420;
  --muted: #7d7268;
  --accent: #e2672d;
  --accent-soft: #fde9dd;
  --ok: #2e9b5f;
  --ok-soft: #e2f4ea;
  --train: #e2672d;
  --rest: #4f7fbf;
  --rest-soft: #e4edf8;
  --radius: 16px;
  --tabs-h: 66px;
  color-scheme: light;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 17px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 24px);
  min-height: 100vh;
}
a { color: inherit; text-decoration: none; }
h1 { font-size: 1.45rem; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 1.2rem; margin: 0; }
.muted { color: var(--muted); }
.small { font-size: .88rem; }
.row { display: flex; align-items: center; gap: 10px; }
.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.center { text-align: center; }

#topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; justify-content: space-between; align-items: center;
  padding: calc(env(safe-area-inset-top) + 8px) 16px 8px;
  background: rgba(251,247,242,.94); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 1.15rem; color: var(--accent); }
#who { color: var(--muted); font-size: .95rem; }

main { max-width: 640px; margin: 0 auto; padding: 14px 14px 0; }

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

button, .btn {
  font: inherit; border: 0; border-radius: 14px; cursor: pointer;
  padding: 12px 16px; background: var(--soft); color: var(--text);
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 48px; font-weight: 600;
}
button:active, .btn:active { transform: scale(.98); }
button:disabled { opacity: .5; }
.primary { background: var(--accent); color: #fff; }
.okbtn { background: var(--ok); color: #fff; }
.ghost { background: transparent; border: 1.5px solid var(--line); }
.block { width: 100%; }
.link { background: none; min-height: 0; padding: 4px 6px; color: var(--accent); font-weight: 600; }
.iconbtn { width: 48px; padding: 0; font-size: 1.4rem; background: var(--card); border: 1px solid var(--line); }

input {
  font: inherit; width: 100%; padding: 14px; border-radius: 14px;
  border: 1.5px solid var(--line); background: #fff; color: var(--text);
}
input:focus { outline: 2px solid var(--accent); border-color: transparent; }
label { display: block; font-weight: 600; margin: 12px 0 6px; }

/* Login */
.login { max-width: 380px; margin: 8vh auto 0; }
.login .logo { display: block; margin: 0 auto 10px; }
.login h1 { text-align: center; font-size: 2rem; color: var(--accent); }
.err { color: #c0392b; min-height: 1.4em; margin: 10px 0 0; font-weight: 600; }

/* Cabecera del día */
.dayhead { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.dayhead .title { flex: 1; text-align: center; }
.dayhead .title h1 { font-size: 1.3rem; }
.dayhead .title h1::first-letter, .dayrow .dname::first-letter { text-transform: uppercase; }
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 12px; border-radius: 999px; font-weight: 700; font-size: .9rem;
}
.badge.entreno { background: var(--accent-soft); color: var(--train); }
.badge.descanso { background: var(--rest-soft); color: var(--rest); }
.todaypill { font-size: .8rem; background: var(--text); color: #fff; border-radius: 999px; padding: 2px 8px; margin-left: 4px; }

.banner {
  border-radius: var(--radius); padding: 14px; margin-bottom: 12px;
  background: var(--accent-soft); border: 1px solid #f6cdb4;
}
.banner.info { background: var(--rest-soft); border-color: #c9daf0; }
.banner b { display: block; margin-bottom: 4px; }
.banner .btn { margin-top: 10px; }

.progress { height: 10px; background: var(--soft); border-radius: 99px; overflow: hidden; margin-top: 8px; }
.progress > div { height: 100%; background: var(--ok); border-radius: 99px; transition: width .3s; }
.big { font-size: 1.5rem; font-weight: 800; }

/* Comidas */
.meal { margin: 22px 0 8px; }
.meal-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.meal-head h2 { font-size: 1.3rem; }
.meal-head .state { font-size: .9rem; font-weight: 600; }
.state.done { color: var(--ok); }
.state.todo { color: var(--muted); }

.opt { position: relative; }
.opt .opt-top { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.opt .num { font-size: .8rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.opt .name { font-weight: 700; font-size: 1.08rem; margin-top: 2px; }
.opt .kcal { font-weight: 800; white-space: nowrap; }
.opt .kcal small { font-weight: 500; color: var(--muted); }
.opt ul { list-style: none; padding: 0; margin: 10px 0 0; }
.opt li { display: flex; align-items: baseline; gap: 10px; padding: 7px 0; border-top: 1px dashed var(--line); }
.opt li b { width: 62px; flex: none; }
.opt li .ik { color: var(--muted); font-size: .85rem; white-space: nowrap; }
.opt .sups { margin-top: 8px; font-size: .88rem; color: var(--muted); }
.opt .macros { display: flex; gap: 14px; margin-top: 8px; font-size: .85rem; color: var(--muted); }
.opt .macros span b { color: var(--text); }
.opt .actions { margin-top: 12px; display: flex; gap: 8px; }
.opt.chosen { border: 2px solid var(--ok); background: #fbfffc; }
.chosen-tag {
  display: inline-flex; align-items: center; gap: 6px; background: var(--ok-soft); color: var(--ok);
  font-weight: 700; font-size: .9rem; border-radius: 999px; padding: 4px 10px; margin-bottom: 8px;
}
.opt.compact ul, .opt.compact .sups, .opt.compact .macros { display: none; }

/* Semana */
.weekhead { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.weekhead .title { flex: 1; text-align: center; }
.chips { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin-top: 10px; }
.chip {
  min-height: 64px; padding: 6px 0; border-radius: 12px; flex-direction: column; gap: 2px;
  background: var(--rest-soft); color: var(--rest); font-size: .85rem;
}
.chip .ic { font-size: 1.2rem; }
.chip.on { background: var(--accent); color: #fff; }
.chip[disabled] { opacity: 1; cursor: default; }
.legend { display: flex; gap: 14px; justify-content: center; margin-top: 8px; font-size: .85rem; color: var(--muted); }

.dayrow { display: block; }
.dayrow .top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.dayrow .dname { font-weight: 800; display: inline-block; }
.dayrow .m { display: flex; gap: 8px; padding: 4px 0; font-size: .95rem; }
.dayrow .m .k { color: var(--muted); width: 92px; flex: none; }
.dayrow .m .v.none { color: #b8ab9d; font-style: italic; }
.dayrow.today { border: 2px solid var(--text); }

/* Pestañas */
#tabs {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  display: flex; justify-content: space-around;
  height: calc(var(--tabs-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: rgba(255,255,255,.96); backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
}
#tabs a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: .8rem; color: var(--muted); font-weight: 600; }
#tabs a .ic { font-size: 1.45rem; line-height: 1.2; }
#tabs a.active { color: var(--accent); }

#toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 14px); z-index: 30;
  background: var(--text); color: #fff; padding: 12px 18px; border-radius: 14px; font-weight: 600;
  box-shadow: 0 6px 24px rgba(0,0,0,.2); max-width: 90vw; text-align: center;
}
.loading { text-align: center; color: var(--muted); padding: 40px 0; }
