/* ===== elinor-fit - dark, warm, energetic ===== */

:root {
  --bg: #0e0c0a;
  --surface: #181410;
  --surface-2: #211b15;
  --surface-3: #2b231b;
  --border: rgba(255, 255, 255, 0.07);
  --text: #f6f0e9;
  --dim: #a99d8f;
  --faint: #6f655a;
  --accent: #ff5e3a;
  --accent-2: #ffb020;
  --accent-grad: linear-gradient(135deg, #ff5e3a 0%, #ff8a2b 55%, #ffb020 100%);
  --accent-soft: rgba(255, 108, 52, 0.14);
  --green: #4cd97b;
  --green-soft: rgba(76, 217, 123, 0.14);
  --red: #ff5a6e;
  --protein: #ff7a59;
  --carbs: #ffc24d;
  --fat: #7fb7ff;
  --radius: 20px;
  --radius-s: 14px;
  --tabbar-h: calc(64px + env(safe-area-inset-bottom, 0px));
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
  --spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html { height: 100%; }

body {
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Segoe UI", Rubik, Assistant, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  overscroll-behavior-y: none;
  -webkit-font-smoothing: antialiased;
}

button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }
input, select, textarea { font: inherit; color: inherit; }
img { max-width: 100%; display: block; }
[hidden] { display: none !important; }

/* ===== layout ===== */

.screen {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(16px + env(safe-area-inset-top, 0px)) 18px calc(var(--tabbar-h) + 24px);
  animation: screen-in 0.32s var(--ease);
}

@keyframes screen-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}

/* ===== tab bar ===== */

.tabbar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--tabbar-h);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  display: flex;
  background: rgba(14, 12, 10, 0.86);
  -webkit-backdrop-filter: blur(18px);
  backdrop-filter: blur(18px);
  border-top: 1px solid var(--border);
  z-index: 40;
}

.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--faint);
  font-size: 11.5px;
  font-weight: 600;
  min-height: 48px;
  transition: color 0.2s var(--ease), transform 0.2s var(--spring);
}

.tab svg { width: 25px; height: 25px; fill: currentColor; transition: transform 0.25s var(--spring); }
.tab[aria-selected="true"] { color: var(--accent); }
.tab[aria-selected="true"] svg { transform: translateY(-2px) scale(1.08); }
.tab:active svg { transform: scale(0.9); }

/* ===== typography ===== */

.greeting h1 { font-size: 26px; font-weight: 800; letter-spacing: -0.3px; }
.greeting .date { color: var(--dim); font-size: 14.5px; margin-top: 2px; }
.section-title {
  font-size: 17px; font-weight: 700; margin: 26px 0 12px;
  display: flex; align-items: center; justify-content: space-between;
}
.section-title .link { color: var(--accent); font-size: 14px; font-weight: 600; min-height: 48px; display: inline-flex; align-items: center; }

/* ===== cards ===== */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}

.card + .card { margin-top: 12px; }

.card.pressable { transition: transform 0.15s var(--ease), background 0.15s; }
.card.pressable:active { transform: scale(0.98); background: var(--surface-2); }

/* ===== calorie ring ===== */

.ring-card { display: flex; flex-direction: column; align-items: center; padding: 24px 18px 20px; }
.ring-wrap { position: relative; width: 210px; height: 210px; }
.ring-wrap svg { width: 100%; height: 100%; transform: rotate(-90deg) scaleY(-1); }
.ring-track { stroke: var(--surface-3); }
.ring-fill {
  stroke: url(#ringGrad);
  transition: stroke-dashoffset 0.9s var(--ease);
}
.ring-fill.over { stroke: var(--red); }
.ring-center {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center;
}
.ring-center .big { font-size: 40px; font-weight: 800; letter-spacing: -1px; line-height: 1.05; }
.ring-center .unit { font-size: 13px; color: var(--dim); font-weight: 600; }
.ring-center .left { font-size: 13.5px; color: var(--dim); margin-top: 6px; }
.ring-center .left b { color: var(--text); }

.macros { width: 100%; margin-top: 20px; display: grid; gap: 12px; }
.macro { display: grid; grid-template-columns: 64px 1fr auto; align-items: center; gap: 10px; font-size: 13px; }
.macro .name { color: var(--dim); font-weight: 600; }
.macro .bar { height: 7px; background: var(--surface-3); border-radius: 99px; overflow: hidden; }
.macro .bar i {
  display: block; height: 100%; border-radius: 99px;
  transform-origin: right center;
  transition: transform 0.8s var(--ease);
}
.macro .val { color: var(--dim); font-variant-numeric: tabular-nums; white-space: nowrap; }
.macro .val b { color: var(--text); }

/* ===== buttons ===== */

.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%;
  min-height: 54px;
  padding: 0 20px;
  border-radius: var(--radius-s);
  font-weight: 700;
  font-size: 16px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  transition: transform 0.15s var(--spring), filter 0.15s, opacity 0.15s;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; pointer-events: none; }

.btn.primary {
  background: var(--accent-grad);
  border: none;
  color: #1d0d05;
  box-shadow: 0 6px 22px rgba(255, 110, 50, 0.35);
}
.btn.primary:active { filter: brightness(1.08); }
.btn.ghost { background: transparent; border: 1px solid var(--border); color: var(--dim); }
.btn.danger { color: var(--red); }
.btn.small { min-height: 44px; font-size: 14.5px; width: auto; padding: 0 16px; }

.icon-btn {
  min-width: 48px; min-height: 48px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 14px; color: var(--dim);
  transition: transform 0.15s var(--spring), background 0.15s;
}
.icon-btn:active { transform: scale(0.9); background: var(--surface-2); }
.icon-btn svg { width: 22px; height: 22px; fill: currentColor; }

/* ===== segmented control ===== */

.segmented {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 4px;
  margin: 16px 0;
  position: relative;
}
.segmented button {
  min-height: 44px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 700;
  color: var(--dim);
  position: relative;
  z-index: 1;
  transition: color 0.2s;
}
.segmented button[aria-selected="true"] { color: #1d0d05; }
.seg-thumb {
  position: absolute;
  top: 4px; bottom: 4px;
  border-radius: 12px;
  background: var(--accent-grad);
  transition: right 0.28s var(--spring), width 0.28s var(--spring);
  z-index: 0;
}

/* ===== lists ===== */

.list-item {
  display: flex; align-items: center; gap: 13px;
  padding: 13px 4px;
  min-height: 60px;
  border-bottom: 1px solid var(--border);
  transition: background 0.15s;
}
.list-item:last-child { border-bottom: none; }
.list-item:active { background: var(--surface-2); }
.list-item .grow { flex: 1; min-width: 0; }
.list-item .title { font-weight: 700; font-size: 15.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-item .sub { color: var(--dim); font-size: 13px; margin-top: 1px; }
.list-item .end { color: var(--dim); font-size: 13.5px; font-variant-numeric: tabular-nums; text-align: left; white-space: nowrap; }
.list-item .end b { color: var(--text); font-size: 15px; }

.thumb {
  width: 52px; height: 52px; border-radius: 14px; object-fit: cover;
  background: var(--surface-3); flex-shrink: 0;
}
.thumb.ph {
  display: flex; align-items: center; justify-content: center;
  font-size: 22px;
}

.chip {
  display: inline-flex; align-items: center;
  padding: 3px 10px; border-radius: 99px;
  font-size: 12px; font-weight: 700;
  background: var(--accent-soft); color: var(--accent);
}
.chip.green { background: var(--green-soft); color: var(--green); }
.chip.dim { background: var(--surface-3); color: var(--dim); }

/* ===== empty states ===== */

.empty {
  text-align: center;
  padding: 44px 24px;
  color: var(--dim);
}
.empty .emoji { font-size: 44px; margin-bottom: 12px; }
.empty h3 { color: var(--text); font-size: 17px; margin-bottom: 6px; }
.empty p { font-size: 14px; max-width: 260px; margin: 0 auto 18px; }

/* ===== bottom sheet ===== */

.sheet-backdrop {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 60;
  opacity: 0;
  transition: opacity 0.25s var(--ease);
}
.sheet-backdrop.in { opacity: 1; }

.sheet {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  max-width: 560px;
  margin: 0 auto;
  background: var(--surface-2);
  border-radius: 24px 24px 0 0;
  border: 1px solid var(--border);
  border-bottom: none;
  z-index: 61;
  padding: 10px 20px calc(20px + env(safe-area-inset-bottom, 0px));
  max-height: 88vh;
  overflow-y: auto;
  transform: translateY(100%);
  transition: transform 0.34s var(--spring);
  box-shadow: var(--shadow);
}
.sheet.in { transform: none; }
.sheet .grab { width: 40px; height: 4px; border-radius: 99px; background: var(--surface-3); margin: 4px auto 14px; }
.sheet h2 { font-size: 19px; font-weight: 800; margin-bottom: 16px; }

/* ===== forms ===== */

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; font-weight: 700; color: var(--dim); margin-bottom: 6px; }
.field input, .field select, .field textarea {
  width: 100%;
  min-height: 50px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  padding: 12px 14px;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s;
  appearance: none;
}
.field textarea { min-height: 74px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); }
.field select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%23a99d8f'%3E%3Cpath d='M7 10l5 5 5-5z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: left 12px center;
  background-size: 20px;
}
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }

/* ===== toast ===== */

#toast-root {
  position: fixed;
  bottom: calc(var(--tabbar-h) + 14px);
  left: 0; right: 0;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  z-index: 80;
  pointer-events: none;
}
.toast {
  background: var(--surface-3);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 99px;
  padding: 11px 20px;
  font-size: 14px;
  font-weight: 600;
  box-shadow: var(--shadow);
  animation: toast-in 0.3s var(--spring);
}
.toast.error { color: var(--red); }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(12px) scale(0.94); }
  to { opacity: 1; transform: none; }
}
.toast.out { opacity: 0; transform: translateY(8px); transition: 0.25s var(--ease); }

/* ===== sync chip ===== */

.sync-chip {
  position: fixed;
  top: calc(10px + env(safe-area-inset-top, 0px));
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface-3);
  color: var(--accent-2);
  font-size: 12.5px;
  font-weight: 700;
  padding: 7px 14px;
  border-radius: 99px;
  border: 1px solid var(--border);
  z-index: 90;
  animation: toast-in 0.3s var(--spring);
}

/* ===== gym mode ===== */

.gym {
  position: fixed; inset: 0;
  background: var(--bg);
  z-index: 50;
  display: flex; flex-direction: column;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 0 env(safe-area-inset-bottom, 0px);
  animation: gym-in 0.35s var(--ease);
}
@keyframes gym-in { from { opacity: 0; transform: translateY(4%); } to { opacity: 1; transform: none; } }
.gym.closing { opacity: 0; transform: translateY(4%); transition: 0.28s var(--ease); }

.gym-head { display: flex; align-items: center; gap: 6px; padding: 0 12px; }
.gym-head .name { flex: 1; font-weight: 800; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.gym-progress { height: 5px; background: var(--surface-3); border-radius: 99px; margin: 10px 18px 0; overflow: hidden; }
.gym-progress i {
  display: block; height: 100%;
  background: var(--accent-grad);
  border-radius: 99px;
  transform-origin: right center;
  transition: transform 0.4s var(--ease);
}
.gym-progress-label { text-align: center; color: var(--dim); font-size: 12.5px; margin-top: 7px; font-weight: 600; }

.gym-body { flex: 1; overflow-y: auto; padding: 8px 18px 20px; }

.gym-exname { text-align: center; margin: 14px 0 4px; }
.gym-exname h2 { font-size: 27px; font-weight: 800; letter-spacing: -0.4px; }
.gym-exname .meta { color: var(--dim); font-size: 14px; margin-top: 3px; }

.gym-nav { display: flex; align-items: center; justify-content: center; gap: 14px; margin: 10px 0 16px; }
.gym-nav .pos { color: var(--dim); font-size: 13.5px; font-weight: 700; min-width: 84px; text-align: center; }
.gym-nav .icon-btn { background: var(--surface); border: 1px solid var(--border); }

.set-row {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 10px;
  transition: background 0.3s, border-color 0.3s, transform 0.15s;
}
.set-row.done { background: var(--green-soft); border-color: rgba(76, 217, 123, 0.35); }
.set-row .num {
  width: 34px; height: 34px; border-radius: 12px;
  background: var(--surface-3);
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 15px; color: var(--dim);
  flex-shrink: 0;
}
.set-row.done .num { background: var(--green); color: #06220f; }
.set-row .targets { flex: 1; min-width: 0; }
.set-row .targets .main { font-weight: 700; font-size: 16px; font-variant-numeric: tabular-nums; }
.set-row .targets .goal { color: var(--faint); font-size: 12px; margin-top: 1px; }

.done-btn {
  width: 56px; height: 56px;
  border-radius: 18px;
  background: var(--surface-3);
  color: var(--faint);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: transform 0.25s var(--spring), background 0.25s, color 0.25s;
}
.done-btn svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.done-btn:active { transform: scale(0.88); }
.set-row.done .done-btn { background: var(--green); color: #06220f; animation: pop 0.4s var(--spring); }
@keyframes pop {
  0% { transform: scale(0.7); }
  55% { transform: scale(1.14); }
  100% { transform: scale(1); }
}

.steppers { display: flex; gap: 8px; margin-top: 10px; }
.stepper {
  flex: 1;
  display: flex; align-items: center; justify-content: space-between;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
}
.stepper button {
  width: 48px; min-height: 48px;
  font-size: 22px; font-weight: 700; color: var(--accent);
  transition: background 0.12s;
}
.stepper button:active { background: var(--surface-3); }
.stepper .sval { text-align: center; font-variant-numeric: tabular-nums; }
.stepper .sval b { font-size: 16.5px; display: block; }
.stepper .sval span { font-size: 10.5px; color: var(--faint); font-weight: 700; }

/* rest timer */
.rest {
  position: fixed;
  left: 16px; right: 16px;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 16px);
  max-width: 528px;
  margin: 0 auto;
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 14px 18px;
  display: flex; align-items: center; gap: 14px;
  z-index: 55;
  animation: toast-in 0.35s var(--spring);
}
.rest.out { opacity: 0; transform: translateY(14px); transition: 0.25s var(--ease); }
.rest .t { font-size: 30px; font-weight: 800; font-variant-numeric: tabular-nums; min-width: 82px; }
.rest .lbl { flex: 1; color: var(--dim); font-size: 13.5px; font-weight: 600; }
.rest .bar { position: absolute; bottom: 0; right: 0; left: 0; height: 4px; border-radius: 0 0 20px 20px; overflow: hidden; }
.rest .bar i { display: block; height: 100%; background: var(--accent-grad); transform-origin: right center; }

/* finish summary */
.summary { text-align: center; padding: 30px 20px; }
.summary .emoji { font-size: 56px; animation: pop 0.6s var(--spring); }
.summary h2 { font-size: 24px; font-weight: 800; margin: 12px 0 4px; }
.summary p { color: var(--dim); }
.summary .stats { display: flex; justify-content: center; gap: 12px; margin: 24px 0; }
.summary .stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  min-width: 108px;
}
.summary .stat b { display: block; font-size: 24px; font-variant-numeric: tabular-nums; }
.summary .stat span { color: var(--dim); font-size: 12.5px; font-weight: 600; }

/* ===== nutrition ===== */

.day-nav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.day-nav .label { font-weight: 800; font-size: 17px; text-align: center; flex: 1; }
.day-nav .label .sub { display: block; font-size: 12.5px; color: var(--dim); font-weight: 600; }

.camera-btn {
  position: relative;
  width: 100%;
  min-height: 92px;
  border-radius: var(--radius);
  background: var(--accent-grad);
  color: #1d0d05;
  display: flex; align-items: center; justify-content: center; gap: 14px;
  font-size: 18px; font-weight: 800;
  box-shadow: 0 10px 30px rgba(255, 110, 50, 0.35);
  transition: transform 0.18s var(--spring);
  overflow: hidden;
}
.camera-btn:active { transform: scale(0.97); }
.camera-btn svg { width: 34px; height: 34px; fill: currentColor; }
.camera-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

.analyzing { text-align: center; padding: 34px 20px; }
.analyzing .plate {
  width: 92px; height: 92px; margin: 0 auto 18px;
  border-radius: 26px;
  object-fit: cover;
  animation: pulse-glow 1.6s ease-in-out infinite;
}
@keyframes pulse-glow {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 110, 50, 0.45); transform: scale(1); }
  50% { box-shadow: 0 0 0 16px rgba(255, 110, 50, 0); transform: scale(1.04); }
}
.analyzing h3 { font-size: 18px; font-weight: 800; }
.analyzing p { color: var(--dim); font-size: 14px; margin-top: 4px; min-height: 21px; transition: opacity 0.3s; }

.draft-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.draft-item .grow { flex: 1; min-width: 0; }
.draft-item .nm { font-weight: 700; font-size: 14.5px; }
.draft-item .qt { color: var(--dim); font-size: 12.5px; }
.draft-item input.mini {
  width: 74px;
  min-height: 44px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  text-align: center;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  outline: none;
}
.draft-item input.mini:focus { border-color: var(--accent); }

.totals-bar {
  display: flex; justify-content: space-between;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  padding: 12px 16px;
  margin: 14px 0;
  font-size: 13px;
}
.totals-bar div { text-align: center; }
.totals-bar b { display: block; font-size: 16.5px; font-variant-numeric: tabular-nums; }
.totals-bar span { color: var(--dim); font-size: 11.5px; font-weight: 700; }

/* ===== history chart ===== */

.chart-card svg { width: 100%; height: auto; display: block; }
.chart-empty { color: var(--dim); font-size: 13.5px; text-align: center; padding: 18px 0; }

/* ===== skeleton ===== */

.skel {
  background: linear-gradient(90deg, var(--surface) 25%, var(--surface-2) 50%, var(--surface) 75%);
  background-size: 200% 100%;
  animation: skel 1.3s infinite linear;
  border-radius: var(--radius);
}
@keyframes skel { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* ===== routine builder ===== */

.builder-item {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  padding: 10px 12px;
  margin-bottom: 8px;
}
.builder-item .grow { flex: 1; min-width: 0; }
.builder-item .nm { font-weight: 700; font-size: 15px; }
.builder-item .meta { color: var(--dim); font-size: 12.5px; }
.builder-item .ord { display: flex; flex-direction: column; }
.builder-item .ord button {
  min-width: 40px; min-height: 30px;
  color: var(--dim); font-size: 15px;
  border-radius: 8px;
}
.builder-item .ord button:active { background: var(--surface-3); color: var(--accent); }

/* back header for sub-views */
.subhead { display: flex; align-items: center; gap: 4px; margin-bottom: 12px; }
.subhead h1 { font-size: 21px; font-weight: 800; flex: 1; }

/* ===== reduced motion ===== */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
