/* === RESET & BASE === */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --black: #000;
  --surface: #111;
  --surface-2: #1a1a1a;
  --surface-3: #222;
  --neon: #ADFF2F;
  --neon-dim: rgba(173, 255, 47, 0.15);
  --white: #fff;
  --text-primary: #fff;
  --text-secondary: #888;
  --border: #2a2a2a;
  --protein: #5B8DEF;
  --carbs: #FFB74D;
  --fat: #EF5B5B;
  --water: #4FC3F7;
  --radius: 12px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
  --font-num: 'SF Mono', 'Menlo', 'Courier New', monospace;
}

html, body {
  font-family: var(--font);
  background: var(--black);
  color: var(--text-primary);
  height: 100%;
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.screen { display: none; width: 100%; height: 100%; flex-direction: column; }
.screen.active { display: flex; }

/* === HEADER === */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--surface);
  min-height: 56px;
  border-bottom: 1px solid var(--border);
}

.match-title {
  font-size: 14px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 3px;
  color: var(--neon);
}

.btn-icon {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 8px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}
.btn-icon:active { background: var(--surface-2); }

/* === SETTINGS === */
.settings-panel {
  flex: 0 0 auto;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  max-height: 1600px;
  overflow: hidden;
  transition: max-height 0.3s ease, opacity 0.3s ease;
  opacity: 1;
}
.settings-inner {
  padding: 8px 20px 16px;
}
.settings-panel.collapsed {
  max-height: 0;
  opacity: 0;
  overflow: hidden;
  pointer-events: none;
  border-bottom-color: transparent;
}
.settings-panel.collapsed .settings-inner {
  padding-top: 0;
  padding-bottom: 0;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
}
.setting-row label {
  font-size: 14px;
  color: var(--text-secondary);
}

.setting-input {
  width: 100px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--white);
  font-size: 15px;
  font-family: var(--font-num);
  text-align: right;
  outline: none;
}
.setting-input:focus { border-color: var(--neon); }

/* === DAILY SUMMARY === */
#today.screen.active {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.daily-summary {
  flex: 0 0 auto;
  overflow: visible;
  padding: 20px 16px;
}

.summary-main {
  display: flex;
  gap: 20px;
  align-items: center;
  margin-bottom: 20px;
}

.calorie-ring {
  position: relative;
  width: 120px;
  height: 120px;
  flex-shrink: 0;
}
.calorie-ring svg { width: 100%; height: 100%; }
.calorie-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.cal-number {
  font-family: var(--font-num);
  font-size: 24px;
  font-weight: 700;
  color: var(--neon);
}
.cal-label {
  font-size: 11px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.macro-bars { flex: 1; display: flex; flex-direction: column; gap: 14px; }

.macro-bar { }
.macro-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 6px;
}
.macro-name { font-size: 13px; font-weight: 600; }
.macro-values { font-size: 12px; color: var(--text-secondary); font-family: var(--font-num); }

.bar-track {
  height: 8px;
  background: var(--surface-3);
  border-radius: 4px;
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.4s ease;
  width: 0;
}
.protein-fill { background: var(--protein); }
.carbs-fill { background: var(--carbs); }
.fat-fill { background: var(--fat); }

/* === WATER TRACKER === */
.water-tracker {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 20px;
}
.water-header {
  display: flex;
  justify-content: space-between;
  font-size: 14px;
  margin-bottom: 10px;
}
.water-header span:last-child { color: var(--text-secondary); font-family: var(--font-num); }
.water-buttons { display: flex; gap: 8px; }
.water-btn {
  flex: 1;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--water);
  font-size: 13px;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  transition: all 0.15s;
}
.water-btn:active { background: rgba(79, 195, 247, 0.15); border-color: var(--water); }

/* === MEAL SECTION === */
.meal-section { margin-bottom: 20px; }
.meal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}
.meal-header h3 { font-size: 18px; font-weight: 700; }
.btn-add {
  padding: 8px 16px;
  background: var(--neon);
  color: #000;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 700;
  font-family: var(--font);
  cursor: pointer;
}
.btn-add:active { opacity: 0.85; }

.meal-list { display: flex; flex-direction: column; gap: 8px; }
.meal-empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-secondary);
  font-size: 14px;
}
.meal-empty.hidden { display: none; }

.meal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.meal-info { flex: 1; }
.meal-name {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 4px;
}
.meal-time {
  font-size: 12px;
  color: var(--text-secondary);
}
.meal-macros {
  display: flex;
  gap: 12px;
  font-family: var(--font-num);
  font-size: 12px;
  color: var(--text-secondary);
}
.meal-macros span { min-width: 40px; text-align: right; }
.meal-cal {
  font-size: 18px;
  font-weight: 700;
  font-family: var(--font-num);
  color: var(--neon);
  margin-left: 16px;
}
.meal-edit {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 16px;
  cursor: pointer;
  padding: 4px 6px;
  margin-left: 8px;
  opacity: 0.5;
}
.meal-edit:active { opacity: 1; color: var(--neon); }
.meal-delete {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 18px;
  cursor: pointer;
  padding: 4px 8px;
  margin-left: 2px;
  opacity: 0.5;
}
.meal-delete:active { opacity: 1; color: var(--fat); }

/* === MODAL === */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.9);
  z-index: 100;
  display: flex;
  align-items: flex-end;
  animation: fadeIn 0.2s ease;
}
.modal.hidden { display: none; }

.modal-content {
  width: 100%;
  max-height: 90vh;
  background: var(--surface);
  border-top-left-radius: 20px;
  border-top-right-radius: 20px;
  padding: 24px;
  overflow-y: auto;
  animation: slideUp 0.3s ease;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}
.modal-header h3 { font-size: 20px; font-weight: 700; }

.input-group { margin-bottom: 16px; }
.input-group label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 6px;
}
.input-group input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--white);
  font-size: 16px;
  font-family: var(--font);
  outline: none;
}
.input-group input:focus { border-color: var(--neon); }
.input-group input::placeholder { color: #444; }

.macro-inputs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 20px;
}
.input-group.compact { margin-bottom: 0; }
.input-group.compact input {
  font-family: var(--font-num);
  font-size: 18px;
  text-align: center;
}

.quick-adds { margin-bottom: 20px; }
.quick-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 10px;
}
.quick-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.quick-btn {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--white);
  font-size: 13px;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  text-align: left;
  transition: all 0.15s;
}
.quick-btn:active {
  background: var(--neon-dim);
  border-color: var(--neon);
}

.btn-primary {
  width: 100%;
  padding: 16px;
  border: none;
  border-radius: var(--radius);
  background: var(--neon);
  color: #000;
  font-size: 17px;
  font-weight: 800;
  font-family: var(--font);
  cursor: pointer;
  letter-spacing: 1px;
  text-transform: uppercase;
}
.btn-primary:active { opacity: 0.85; }

/* === HISTORY === */
.history-list {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px;
}
.history-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  gap: 8px;
}
.history-empty.hidden { display: none; }
.empty-icon { font-size: 48px; opacity: 0.4; }

.history-day {
  margin-bottom: 20px;
}
.history-day-header {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 2px;
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.history-day-summary {
  display: flex;
  gap: 16px;
  margin-bottom: 10px;
  font-family: var(--font-num);
  font-size: 13px;
}
.history-day-summary .hs-cal { color: var(--neon); font-weight: 700; font-size: 16px; }
.history-day-summary .hs-macro { color: var(--text-secondary); }

.history-meal {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}
.history-meal:last-child { border-bottom: none; }
.history-meal-name { font-size: 14px; }
.history-meal-cal {
  font-family: var(--font-num);
  font-size: 14px;
  color: var(--neon);
  font-weight: 600;
}

/* === ANIMATIONS === */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }

/* === RESPONSIVE === */
/* === SEARCH === */
.search-row {
  display: flex;
  gap: 8px;
}
.search-row input {
  flex: 1;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--white);
  font-size: 15px;
  font-family: var(--font);
  outline: none;
}
.search-row input:focus { border-color: var(--neon); }
.search-row input::placeholder { color: #444; }

.btn-search {
  padding: 12px 18px;
  background: var(--neon);
  color: #000;
  border: none;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 700;
  font-family: var(--font);
  cursor: pointer;
  white-space: nowrap;
}
.btn-search:active { opacity: 0.85; }

.search-loading {
  text-align: center;
  padding: 16px;
  color: var(--text-secondary);
  font-size: 13px;
}
.search-loading.hidden { display: none; }

.search-results {
  max-height: 320px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  margin-bottom: 12px;
}
.search-heading {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--text-secondary);
  margin: 10px 0 6px;
}
.search-note {
  text-align: center;
  padding: 8px 12px 12px;
  color: var(--text-secondary);
  font-size: 13px;
}
.more-foods {
  width: 100%;
  margin: 4px 0 10px;
  padding: 10px 12px;
  border: 1px solid var(--neon);
  border-radius: 10px;
  background: transparent;
  color: var(--neon);
  font-family: var(--font);
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
}
.star-btn {
  border: 0;
  background: transparent;
  color: var(--neon);
  font-size: 18px;
  line-height: 1;
  padding: 0 8px 0 0;
  cursor: pointer;
}
.search-item-hint {
  font-size: 10px;
  color: var(--neon);
  opacity: 0.7;
}
.food-credit {
  margin: 12px 0 0;
  font-size: 11px;
  line-height: 1.45;
  color: var(--text-secondary);
}
.food-credit a { color: var(--neon); }
.history-tools {
  flex: 0 0 auto;
  margin: 12px 16px 8px;
}
.nutri-account,
.sync-offer {
  margin: 12px 0 0;
  padding: 12px 0 0;
  background: transparent;
  border: 0;
  border-top: 1px solid var(--border);
  border-radius: 0;
}
.nutri-account .search-row {
  flex-direction: column;
  align-items: stretch;
  margin-top: 10px;
}
.nutri-account .search-row input,
.nutri-account .btn-search {
  width: 100%;
  min-width: 0;
  min-height: 44px;
}
.account-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 12px;
}
.account-actions-row {
  display: flex;
  gap: 8px;
}
.account-actions-row .account-btn {
  width: auto;
  flex: 1 1 0;
  min-width: 0;
}
.account-btn {
  flex: 1;
  width: 100%;
  min-height: 44px;
  margin: 0;
  padding: 10px 12px;
  border: 1px solid var(--neon);
  border-radius: 10px;
  background: transparent;
  color: var(--neon);
  font-family: var(--font);
  font-size: 14px;
  font-weight: 700;
  line-height: 1.2;
  cursor: pointer;
}
.account-btn-danger {
  flex: none;
  border-color: rgba(239, 91, 91, 0.7);
  color: var(--fat);
  font-weight: 600;
}
.export-row, .week-nav { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 8px; }
.export-row .more-foods, .week-nav .more-foods { width: auto; flex: 1; margin: 0; min-height: 44px; }
#week-label { font-size: 13px; color: var(--text-secondary); min-width: 0; text-align: center; }
.trend { width: 100%; height: 72px; display: block; }
@media (max-width: 430px) {
  .week-nav { align-items: stretch; }
  #week-label { flex: 1 0 100%; order: -1; padding: 2px 0 4px; }
  .history-tools .export-row { flex-direction: column; align-items: stretch; }
  .week-nav .more-foods { width: auto; flex: 1 1 0; min-width: 0; }
  .history-tools .export-row .more-foods { width: 100%; flex: 1 1 auto; }
}
.search-results.hidden { display: none; }

.search-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  margin-bottom: 6px;
  cursor: pointer;
  transition: all 0.15s;
}
.search-item:active {
  background: var(--neon-dim);
  border-color: var(--neon);
}
.search-item-info { flex: 1; }
.search-item-name {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 2px;
}
.search-item-brand {
  font-size: 11px;
  color: var(--text-secondary);
}
.search-item-macros {
  font-family: var(--font-num);
  font-size: 11px;
  color: var(--text-secondary);
  text-align: right;
}
.search-item-cal {
  font-size: 16px;
  font-weight: 700;
  color: var(--neon);
  font-family: var(--font-num);
}

.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 20px 0 16px;
  color: var(--text-secondary);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
}
.divider::before, .divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.portion-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  margin-bottom: 16px;
}
.portion-row .input-group { margin-bottom: 0; }
.portion-btn {
  width: 48px;
  height: 48px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--neon);
  font-size: 24px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  padding-bottom: 2px;
}
.portion-btn:active {
  background: var(--neon-dim);
  border-color: var(--neon);
}

@media (min-width: 768px) {
  .summary-main { gap: 32px; }
  .calorie-ring { width: 160px; height: 160px; }
  .cal-number { font-size: 32px; }
}

.weight-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 4px 16px 12px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.weight-latest { font-size: 22px; font-weight: 700; color: var(--neon); line-height: 1.2; }
#weight.screen.active { overflow-y: auto; -webkit-overflow-scrolling: touch; }
.weight-wrap { padding: 16px; }
.weight-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.weight-stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  min-width: 0;
}
.weight-stat span { display: block; color: var(--text-secondary); font-size: 12px; }
.weight-stat b { display: block; color: var(--neon); font-size: 18px; margin-top: 4px; }
.range-row { display: flex; gap: 6px; margin: 12px 0; }
.range-row button {
  flex: 1 1 0;
  min-width: 0;
  min-height: 40px;
  padding: 8px 2px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  font: 700 12px var(--font);
}
.range-row button.active { background: var(--neon); color: #000; border-color: var(--neon); }
.weight-chart { width: 100%; height: 180px; display: block; background: var(--surface); border-radius: 12px; }
.weight-form, .weight-goal { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }
.weight-form label, .weight-goal label { font-size: 13px; color: var(--text-secondary); }
.weight-inputs { display: flex; gap: 8px; }
.weight-inputs label { flex: 1; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.weight-form input, .weight-inputs input {
  width: 100%;
  min-width: 0;
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--white);
  font: 16px var(--font-num);
}
#weight-unit { width: 118px; text-align: left; }
.weight-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 8px;
  align-items: center;
  padding: 10px 0;
  border-top: 1px solid var(--border);
}
.weight-row small { display: block; color: var(--text-secondary); }
.weight-row .account-btn { width: auto; min-height: 36px; padding: 8px 10px; }
