:root {
  --bg: #0a0e14;
  --surface: #131a24;
  --surface2: #1a2330;
  --border: #232f3e;
  --text: #e8edf4;
  --text-dim: #8a97a8;
  --accent: #00d68f;
  --accent2: #ff5c7c;
  --blue: #4da3ff;
  --amber: #ffb020;
  --radius: 16px;
  --shadow: 0 4px 20px rgba(0,0,0,0.4);
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* ── Login ── */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at top, #16212e 0%, var(--bg) 60%);
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 340px;
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 36px 28px;
  box-shadow: var(--shadow);
}
.login-logo { font-size: 52px; margin-bottom: 8px; }
.login-card h1 { font-size: 26px; font-weight: 800; letter-spacing: -0.5px; }
.login-sub { color: var(--text-dim); margin: 4px 0 24px; font-size: 14px; }
.login-card input {
  width: 100%;
  padding: 14px 16px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  font-size: 16px;
  margin-bottom: 12px;
  outline: none;
}
.login-card input:focus { border-color: var(--accent); }
.login-error { color: var(--accent2); font-size: 13px; margin-top: 10px; min-height: 18px; }

/* ── App shell ── */
.app { max-width: 520px; margin: 0 auto; min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px 8px;
  position: sticky;
  top: 0;
  background: rgba(10,14,20,0.9);
  backdrop-filter: blur(12px);
  z-index: 10;
}
.topbar-title { font-size: 20px; font-weight: 800; letter-spacing: -0.4px; }
.icon-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 15px;
  cursor: pointer;
}

.content { flex: 1; padding: 8px 20px 100px; }

.view { display: none; animation: fadeIn 0.25s ease; }
.view.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ── Hub ── */
.greeting h2 { font-size: 24px; font-weight: 800; }
.greeting p { color: var(--text-dim); font-size: 13px; margin-bottom: 16px; }

.hub-grid { display: flex; flex-direction: column; gap: 14px; }
.hub-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}
.hub-card-header { font-size: 14px; font-weight: 700; margin-bottom: 14px; color: var(--text-dim); }
.ring-wrap { display: flex; justify-content: center; margin: 6px 0; }
.ring {
  width: 120px; height: 120px;
  border-radius: 50%;
  background: conic-gradient(var(--accent) 0%, var(--surface2) 0%);
  display: flex; align-items: center; justify-content: center;
  position: relative;
}
.ring::before { content: ''; position: absolute; inset: 10px; background: var(--surface); border-radius: 50%; }
.ring span { position: relative; font-size: 22px; font-weight: 800; }
.hub-card-sub { text-align: center; color: var(--text-dim); font-size: 13px; margin: 8px 0 14px; }
.macro-bars { margin-top: 4px; }
.macro-bar { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; font-size: 12px; }
.macro-bar label { width: 60px; color: var(--text-dim); }
.macro-bar .bar { flex: 1; height: 8px; background: var(--surface2); border-radius: 4px; overflow: hidden; }
.macro-bar .bar-fill { height: 100%; background: var(--blue); border-radius: 4px; transition: width 0.4s; }
.macro-bar span { width: 44px; text-align: right; color: var(--text-dim); font-variant-numeric: tabular-nums; }

.stat-big { font-size: 34px; font-weight: 800; text-align: center; color: var(--amber); }
.stat-row { display: flex; gap: 10px; margin-top: 16px; }
.stat { flex: 1; text-align: center; background: var(--surface2); border-radius: 12px; padding: 12px 6px; }
.stat span { display: block; font-size: 20px; font-weight: 700; }
.stat label { font-size: 11px; color: var(--text-dim); }

.quick-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 16px; }
.quick-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 14px;
  padding: 16px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.quick-btn:active { background: var(--surface2); }

/* ── Section head ── */
.section-head { display: flex; align-items: center; justify-content: space-between; margin: 8px 0 16px; }
.section-head h2 { font-size: 20px; font-weight: 800; }
.week-nav { display: flex; align-items: center; gap: 10px; }
.week-nav span { font-size: 13px; color: var(--text-dim); }
.btn-small {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--accent);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.btn-primary {
  background: var(--accent);
  border: none;
  color: #04140d;
  border-radius: 12px;
  padding: 12px 20px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
}
.btn-back { background: none; border: none; color: var(--accent); font-size: 15px; cursor: pointer; padding: 4px 0 12px; }

/* ── Meal plan ── */
.day-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 14px; overflow: hidden; }
.day-header { padding: 12px 16px; font-weight: 700; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.day-header .date { color: var(--text-dim); font-size: 12px; font-weight: 400; }
.meal-row { padding: 10px 16px; display: flex; align-items: center; gap: 10px; border-bottom: 1px solid var(--border); }
.meal-row:last-child { border-bottom: none; }
.meal-label { width: 72px; font-size: 12px; color: var(--text-dim); font-weight: 600; }
.meal-recipe { flex: 1; font-size: 14px; }
.meal-recipe.empty { color: var(--text-dim); font-style: italic; font-size: 13px; }
.meal-recipe select { width: 100%; background: var(--surface2); color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: 8px; font-size: 13px; }

/* ── Food log ── */
.food-summary { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.food-summary .fs-row { display: flex; justify-content: space-between; margin-bottom: 8px; font-size: 14px; }
.food-summary .fs-row .val { font-weight: 700; font-variant-numeric: tabular-nums; }
.food-meal { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 12px; }
.food-meal h3 { font-size: 15px; margin-bottom: 8px; }
.food-meal .eaten-toggle { display: flex; gap: 8px; margin-top: 10px; }
.toggle-btn { flex: 1; padding: 10px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface2); color: var(--text-dim); cursor: pointer; font-size: 13px; font-weight: 600; }
.toggle-btn.on { background: var(--accent); color: #04140d; border-color: var(--accent); }
.food-meal textarea { width: 100%; margin-top: 8px; background: var(--surface2); border: 1px solid var(--border); border-radius: 8px; color: var(--text); padding: 8px; font-size: 13px; }

/* ── Lists ── */
.list { list-style: none; }
.list li {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 12px 16px; margin-bottom: 8px;
}
.list li .check { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--border); cursor: pointer; flex-shrink: 0; }
.list li .check.done { background: var(--accent); border-color: var(--accent); }
.list li .name { flex: 1; font-size: 14px; }
.list li .name.done { text-decoration: line-through; color: var(--text-dim); }
.list li .qty { color: var(--text-dim); font-size: 13px; }
.list li .del { background: none; border: none; color: var(--accent2); cursor: pointer; font-size: 16px; }

/* ── Recipes ── */
.recipe-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; cursor: pointer; }
.recipe-card h3 { font-size: 16px; margin-bottom: 4px; }
.recipe-card .meta { color: var(--text-dim); font-size: 12px; }
.recipe-macros { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.macro-pill { background: var(--surface2); border-radius: 8px; padding: 4px 10px; font-size: 12px; }
.macro-pill b { color: var(--accent); }

#recipeDetail h2 { font-size: 22px; margin-bottom: 8px; }
#recipeDetail .inst { white-space: pre-wrap; color: var(--text-dim); font-size: 14px; line-height: 1.6; margin-top: 12px; }
.ing-table { margin-top: 12px; }
.ing-table .ing-row { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 14px; }

/* ── Training ── */
.phase-label {
  display: inline-block;
  background: var(--surface2);
  color: var(--amber);
  font-size: 12px;
  font-weight: 700;
  padding: 4px 12px;
  border-radius: 20px;
  margin: -4px 0 14px;
  letter-spacing: 0.3px;
}
.routine-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; }
.routine-card h3 { font-size: 16px; margin-bottom: 2px; }
.routine-card .focus { color: var(--accent); font-size: 12px; font-weight: 600; }
.routine-card .actions { display: flex; gap: 8px; margin-top: 12px; }

.exercise-item { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; margin-bottom: 10px; }
.exercise-item h4 { font-size: 15px; margin-bottom: 2px; }
.exercise-item .group { color: var(--accent); font-size: 12px; }
.exercise-item .technique { color: var(--text-dim); font-size: 13px; line-height: 1.5; margin-top: 8px; }

/* Live training */
.live-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.live-exercise { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.live-exercise h3 { font-size: 17px; margin-bottom: 4px; }
.live-exercise .target { color: var(--text-dim); font-size: 13px; margin-bottom: 12px; }
.set-row { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.set-row .set-num { width: 34px; color: var(--text-dim); font-size: 13px; }
.set-row input { flex: 1; background: var(--surface2); border: 1px solid var(--border); border-radius: 8px; color: var(--text); padding: 10px; font-size: 15px; min-width: 0; }
.set-row .input-label { font-size: 11px; color: var(--text-dim); }
.add-set-btn { width: 100%; background: var(--surface2); border: 1px dashed var(--border); color: var(--accent); border-radius: 10px; padding: 12px; cursor: pointer; font-size: 14px; }

/* History */
.hist-item { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; margin-bottom: 10px; }
.hist-item .date { color: var(--text-dim); font-size: 12px; }
.hist-item .summary { display: flex; gap: 14px; margin-top: 6px; font-size: 13px; }

/* ── Bottom nav ── */
.bottomnav {
  position: fixed; bottom: 0; left: 0; right: 0;
  max-width: 520px; margin: 0 auto;
  display: flex;
  background: rgba(19,26,36,0.95);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  z-index: 20;
}
.nav-btn {
  flex: 1;
  background: none; border: none;
  color: var(--text-dim);
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 20px; cursor: pointer; padding: 6px 0;
}
.nav-btn span { font-size: 10px; font-weight: 600; }
.nav-btn.active { color: var(--accent); }

/* ── Forms (modal) ── */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.7); z-index: 30; display: flex; align-items: flex-end; justify-content: center; }
.modal { background: var(--surface); border-radius: 20px 20px 0 0; padding: 24px 20px; width: 100%; max-width: 520px; max-height: 85vh; overflow-y: auto; }
.modal h3 { font-size: 18px; margin-bottom: 16px; }
.modal input, .modal select, .modal textarea {
  width: 100%; background: var(--surface2); border: 1px solid var(--border);
  border-radius: 10px; color: var(--text); padding: 12px; font-size: 14px; margin-bottom: 10px; outline: none;
}
.modal .form-row { display: flex; gap: 8px; }
.modal .form-row > * { flex: 1; }

@media (min-width: 520px) {
  .hub-grid { flex-direction: row; }
  .hub-grid > * { flex: 1; }
}
