:root {
  --bg: #16181b;
  --card: #202328;
  --line: #30343a;
  --text: #e8e6e3;
  --muted: #9a9ea5;
  --accent: #e0a458;
  --ok: #7fb685;
  --bad: #d9776b;
  --input: #2a2e34;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f4f2ee; --card: #ffffff; --line: #e0ddd6; --text: #1e1f21;
    --muted: #6b6e73; --accent: #b56d1c; --ok: #3f7d47; --bad: #b2463a; --input: #f0eee9;
    color-scheme: light;
  }
}
:root[data-theme="light"] {
  --bg: #f4f2ee; --card: #ffffff; --line: #e0ddd6; --text: #1e1f21;
  --muted: #6b6e73; --accent: #b56d1c; --ok: #3f7d47; --bad: #b2463a; --input: #f0eee9;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
h1 { font-size: 1.4rem; margin: 0 0 1rem; }
h2 { font-size: 1.05rem; margin: 1.4rem 0 .5rem; }
h3 { font-size: 1rem; margin: 0; }
p { margin: .4rem 0; }
.muted { color: var(--muted); font-size: .9rem; }
.err { color: var(--bad); min-height: 1.2em; }
[hidden] { display: none !important; }

.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; justify-content: space-between; align-items: center;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: var(--bg); border-bottom: 1px solid var(--line);
  font-weight: 600;
}
.net { font-size: .8rem; color: var(--bad); font-weight: 500; }

main { padding: 12px 16px calc(150px + env(safe-area-inset-bottom)); max-width: 640px; margin: 0 auto; }

.tabs {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs button {
  background: none; border: 0; padding: 14px 0; font-size: .82rem; color: var(--muted);
}
.tabs button.on { color: var(--accent); font-weight: 600; }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  padding: 12px; margin: 10px 0;
}
.row { display: flex; gap: 8px; align-items: center; }
.row.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }

button.btn, .btn {
  background: var(--input); border: 1px solid var(--line); border-radius: 8px;
  padding: 10px 14px; cursor: pointer;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #1a1209; font-weight: 600; }
.btn.small { padding: 6px 10px; font-size: .88rem; }
.btn.danger { color: var(--bad); }
.btn.full { width: 100%; }
.btn:disabled { opacity: .5; }

input[type=text], input[type=number], input[type=password], input[type=date], select, textarea {
  background: var(--input); border: 1px solid var(--line); border-radius: 8px;
  padding: 10px; width: 100%; min-width: 0;
}
textarea { min-height: 260px; font: 13px/1.35 ui-monospace, Menlo, Consolas, monospace; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.chips button {
  flex: none; background: var(--input); border: 1px solid var(--line); border-radius: 999px;
  padding: 6px 12px; font-size: .88rem;
}
.chips button.on { border-color: var(--accent); color: var(--accent); }

.note { border-left: 3px solid var(--accent); padding: 6px 10px; margin: 8px 0; font-size: .92rem; background: var(--card); border-radius: 0 8px 8px 0; }

/* entreno */
.ex h3 { font-size: 1rem; }
.ex .meta { color: var(--muted); font-size: .85rem; }
.ex .last { font-size: .85rem; color: var(--muted); margin: 4px 0 8px; }
.ex .hint { font-size: .85rem; color: var(--ok); margin: 4px 0; }
.set { display: grid; grid-template-columns: 26px 1fr 1fr 48px; gap: 6px; align-items: center; margin: 6px 0; }
.set .n { color: var(--muted); font-size: .85rem; text-align: center; }
.set input { padding: 9px 8px; text-align: center; font-size: 1rem; }
.set .done {
  height: 42px; border-radius: 8px; border: 1px solid var(--line); background: var(--input); font-size: 1.1rem;
}
.set .done.on { background: var(--ok); border-color: var(--ok); color: #fff; }
.set.extra .n { color: var(--accent); }

.timer {
  position: fixed; left: 0; right: 0; bottom: calc(49px + env(safe-area-inset-bottom)); z-index: 9;
  display: flex; gap: 10px; align-items: center; padding: 10px 16px;
  background: var(--accent); color: #1a1209;
}
.timer strong { font-size: 1.3rem; font-variant-numeric: tabular-nums; margin-right: auto; }
.timer button { background: rgba(0,0,0,.12); border: 0; border-radius: 6px; padding: 6px 10px; color: inherit; }
.timer.done { background: var(--ok); color: #fff; }

/* dieta */
.bar { height: 8px; background: var(--input); border-radius: 4px; overflow: hidden; margin: 4px 0 10px; }
.bar > i { display: block; height: 100%; background: var(--accent); }
.bar.ok > i { background: var(--ok); }
.meal { display: flex; gap: 10px; align-items: flex-start; }
.meal input[type=checkbox] { width: 24px; height: 24px; margin-top: 2px; accent-color: var(--ok); flex: none; }
.meal ul { margin: 4px 0 0; padding-left: 18px; color: var(--muted); font-size: .9rem; }
.meal.checked h3 { text-decoration: line-through; color: var(--muted); }
details { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin: 10px 0; }
details summary { font-weight: 600; cursor: pointer; }
details ul { padding-left: 18px; margin: 8px 0 0; }
details li { margin: 4px 0; }
.shop li { list-style: none; margin-left: -18px; }
.shop label { display: flex; gap: 8px; align-items: center; }
.extra-row { display: flex; justify-content: space-between; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--line); font-size: .92rem; }
.extra-row:last-child { border-bottom: 0; }
.x { background: none; border: 0; color: var(--bad); padding: 0 4px; }

/* horario */
.slot { display: grid; grid-template-columns: 96px 1fr; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.slot:last-child { border-bottom: 0; }
.slot .t { white-space: nowrap; font-size: .86rem !important; font-variant-numeric: tabular-nums; color: var(--muted); font-size: .92rem; }
.slot.now { background: color-mix(in srgb, var(--accent) 14%, transparent); margin: 0 -12px; padding: 9px 12px; border-radius: 6px; }
.slot.now .t { color: var(--accent); font-weight: 600; }
.slot.past { opacity: .5; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; background: var(--line); }
.dot.gym { background: var(--accent); }
.dot.comida { background: var(--ok); }
.dot.clase { background: #7a9cc6; }
.dot.bus { background: var(--muted); }

/* progreso */
svg.chart { width: 100%; height: 160px; display: block; }
svg.chart .ln { fill: none; stroke: var(--accent); stroke-width: 2; }
svg.chart .avg { fill: none; stroke: var(--ok); stroke-width: 2; stroke-dasharray: 4 3; }
svg.chart circle { fill: var(--accent); }
svg.chart text { fill: var(--muted); font-size: 10px; }
svg.chart .grid { stroke: var(--line); stroke-width: 1; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
td, th { text-align: left; padding: 6px 4px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 500; }
td.r, th.r { text-align: right; font-variant-numeric: tabular-nums; }

/* editor rutina */
.ed-ex { display: grid; grid-template-columns: 52px 76px 60px 1fr; gap: 6px; padding: 8px 0; border-top: 1px solid var(--line); }
.ed-ex input { padding: 8px 6px; font-size: .9rem; }
.ed-ex input[data-f=name] { grid-column: 1 / -1; }
.ed-ex .ctrls { display: flex; gap: 4px; justify-content: flex-end; }
.ed-head { display: grid; grid-template-columns: 52px 76px 60px 1fr; gap: 6px; font-size: .78rem; color: var(--muted); }

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login form { width: 100%; max-width: 320px; display: grid; gap: 10px; }
.login button { background: var(--accent); border: 0; border-radius: 8px; padding: 12px; font-weight: 600; color: #1a1209; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(120px + env(safe-area-inset-bottom));
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 8px; z-index: 20;
  font-size: .92rem; max-width: calc(100% - 32px);
}
.bar.over > i { background: var(--bad); }
