:root {
  color-scheme: dark;
  --bg: #0d0d0f;
  --surface: #17171b;
  --surface-2: #202027;
  --fg: #f2f2f4;
  --muted: #9a9aa5;
  --accent: #e0392b;
  --accent-dim: #7a1f18;
  --brand-yellow: #f4b400;
  --good: #35c07a;
  --warn: #e0a13a;
  --danger: #e05a5a;
  --radius: 14px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

#app { min-height: 100vh; min-height: 100dvh; }

.screen {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}
.hidden { display: none !important; }

/* Header */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.9rem 1rem;
  gap: 0.5rem;
  border-bottom: 1px solid rgba(255,255,255,0.07);
}
.app-header h1 { margin: 0; font-size: 1.15rem; font-weight: 600; flex: 1; text-align: center; }
.icon-btn {
  background: var(--surface-2); color: var(--fg); border: none;
  width: 40px; height: 40px; border-radius: 10px; font-size: 1.4rem; line-height: 1;
}
.link-btn { background: none; border: none; color: var(--accent); font-size: 1rem; padding: 0.4rem; }
.link-btn.strong { font-weight: 600; }

.app-main { flex: 1; padding: 1rem; padding-bottom: 2rem; }
.app-footer {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.75rem 1rem; gap: 1rem;
  border-top: 1px solid rgba(255,255,255,0.07);
}

/* Summary card */
.summary-card { background: var(--surface); border-radius: var(--radius); padding: 1.25rem; margin-bottom: 1.25rem; }
.protein-big { font-size: 2.4rem; font-weight: 700; line-height: 1; }
.protein-big .unit { font-size: 1rem; font-weight: 400; color: var(--muted); }
.bar { height: 8px; background: var(--surface-2); border-radius: 6px; overflow: hidden; margin: 0.9rem 0 0.5rem; }
.bar-fill { height: 100%; width: 0%; background: var(--accent); transition: width 0.3s ease; }
.bar-fill.done { background: var(--good); }
.protein-message { margin: 0.2rem 0 0; color: var(--muted); font-size: 0.95rem; }

.stats-row { display: flex; gap: 1rem; margin-top: 1.1rem; }
.stat { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 0.35rem; }
.stat-value { font-size: 1.5rem; font-weight: 600; }
.stat-label { font-size: 0.78rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }

.creatine-btn {
  background: var(--surface-2); color: var(--fg); border: 1px solid transparent;
  border-radius: 10px; padding: 0.5rem 0.9rem; font-size: 0.95rem; font-weight: 600;
}
.creatine-btn[aria-pressed="true"] { background: var(--good); color: #062915; border-color: var(--good); }

/* Buttons */
.btn { border: none; border-radius: var(--radius); font-size: 1rem; font-weight: 600; padding: 0.85rem 1rem; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-secondary { background: var(--surface-2); color: var(--fg); border: 1px solid rgba(255,255,255,0.12); }
.btn-big { width: 100%; font-size: 1.15rem; padding: 1.1rem; margin-bottom: 1.5rem; }
.btn:active { filter: brightness(0.92); }

.action-row { display: flex; gap: 0.75rem; margin-bottom: 1.5rem; }
.action-row .btn { flex: 1; font-size: 1.05rem; padding: 1rem; }

/* Meal list */
.section-title { font-size: 0.95rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; margin: 0.5rem 0 0.75rem; display: flex; align-items: center; gap: 0.6rem; }
.meal-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.6rem; }
.meal-item { background: var(--surface); border-radius: var(--radius); padding: 0.85rem 1rem; display: flex; align-items: center; gap: 0.8rem; }
.meal-item .meal-main { flex: 1; min-width: 0; }
.meal-item .meal-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.meal-item .meal-sub { font-size: 0.82rem; color: var(--muted); margin-top: 0.15rem; }
.meal-item .meal-macros { text-align: right; font-size: 0.9rem; white-space: nowrap; }
.meal-item .meal-macros strong { color: var(--accent); }
.badge { font-size: 0.68rem; padding: 0.1rem 0.4rem; border-radius: 6px; background: var(--surface-2); color: var(--muted); margin-left: 0.4rem; }
.badge.high { color: var(--good); }
.badge.low { color: var(--warn); }
.meal-del { background: none; border: none; color: var(--danger); font-size: 1.2rem; padding: 0.3rem 0.4rem; }

/* Fields */
.field { display: flex; flex-direction: column; gap: 0.35rem; margin-bottom: 1rem; }
.field > span { font-size: 0.85rem; color: var(--muted); }
.field-row { display: flex; gap: 0.8rem; }
.field-row .field { flex: 1; }
input[type="text"], input[type="number"], input[type="password"],
input[type="datetime-local"], input[type="time"] {
  background: var(--surface); color: var(--fg); border: 1px solid rgba(255,255,255,0.1);
  border-radius: 10px; padding: 0.75rem; font-size: 1rem; width: 100%;
}
input:focus { outline: 2px solid var(--accent-dim); border-color: var(--accent); }

/* Items editor */
.item-edit { background: var(--surface); border-radius: var(--radius); padding: 0.75rem; margin-bottom: 0.7rem; }
.item-edit .item-top { display: flex; gap: 0.5rem; align-items: center; margin-bottom: 0.5rem; }
.item-edit .item-name { flex: 1; }
.item-edit .item-macros { display: flex; gap: 0.5rem; }
.item-edit .item-macros label { flex: 1; font-size: 0.75rem; color: var(--muted); }
.item-edit input { font-size: 0.92rem; padding: 0.55rem; }
.item-del { background: none; border: none; color: var(--danger); font-size: 1.2rem; }
.mini-btn { background: var(--surface-2); color: var(--accent); border: none; border-radius: 8px; padding: 0.2rem 0.55rem; font-size: 0.8rem; }

.warning { background: rgba(224,161,58,0.12); border: 1px solid rgba(224,161,58,0.3); color: var(--warn); border-radius: 10px; padding: 0.7rem 0.9rem; font-size: 0.9rem; margin: 0 0 1.1rem; }
.alert { background: rgba(224,161,58,0.15); border: 1px solid rgba(224,161,58,0.35); color: var(--warn); border-radius: 10px; padding: 0.7rem 0.9rem; margin-bottom: 1rem; font-size: 0.92rem; }

.muted { color: var(--muted); font-size: 0.9rem; }
.error { color: var(--danger); }
.hint { color: var(--muted); font-size: 0.72rem; text-align: right; flex: 1; }

/* Login */
.login-box { margin: auto; width: 100%; max-width: 320px; padding: 2rem 1.25rem; display: flex; flex-direction: column; gap: 1rem; align-items: center; }
.login-box h1 { text-align: center; margin: 0; }
.login-box input, .login-box .btn { width: 100%; }
.login-mascot { width: 150px; height: 150px; object-fit: contain; }

/* Modal (descripción manual) */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.6); display: flex; align-items: center; justify-content: center; z-index: 55; padding: 1rem; }
.modal-box { background: var(--surface); border-radius: var(--radius); padding: 1.25rem; width: 100%; max-width: 420px; }
.modal-box h2 { margin: 0 0 0.9rem; font-size: 1.05rem; }
.modal-box textarea {
  width: 100%; background: var(--surface-2); color: var(--fg); border: 1px solid rgba(255,255,255,0.1);
  border-radius: 10px; padding: 0.75rem; font-size: 1rem; font-family: inherit; resize: vertical;
}
.modal-actions { display: flex; justify-content: flex-end; align-items: center; gap: 0.75rem; margin-top: 1rem; }

/* Loading + toast */
.loading { position: fixed; inset: 0; background: rgba(0,0,0,0.6); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1rem; z-index: 50; }
.spinner { width: 42px; height: 42px; border: 4px solid rgba(255,255,255,0.2); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast { position: fixed; left: 50%; bottom: calc(2rem + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--surface-2); color: var(--fg); padding: 0.7rem 1.1rem; border-radius: 10px; z-index: 60; font-size: 0.9rem; box-shadow: 0 4px 20px rgba(0,0,0,0.4); }
