* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg: #0f1115;
  --card: #1a1d24;
  --text: #e8eaf0;
  --muted: #8b90a0;
  --accent: #4f6ef7;
  --accent-soft: #2a3450;
  --danger: #e05555;
  --radius: 16px;
}

html { -webkit-text-size-adjust: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  min-height: 100vh;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
  overflow-x: hidden;
}

header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: calc(16px + env(safe-area-inset-top)) 20px 8px;
}
header h1 { font-size: 22px; font-weight: 800; letter-spacing: -0.5px; }
#today-date { color: var(--muted); font-size: 14px; }

main { padding: 8px 16px; }

/* screens (tab pages) */
.screen { display: none; }
.screen.active { display: grid; gap: 14px; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 18px;
  min-width: 0; /* let grid shrink cards below their content's intrinsic width */
}
.card-title {
  font-size: 14px; font-weight: 700; color: var(--muted);
  margin-bottom: 12px; text-transform: uppercase; letter-spacing: 1px;
}
.card-title-row { display: flex; align-items: center; justify-content: space-between; }
.unit-toggle {
  min-width: 64px; min-height: 44px; padding: 0 8px; border-radius: 8px;
  color: var(--accent); font-size: 12px; text-transform: none; letter-spacing: 0;
  touch-action: manipulation;
}
.unit-toggle::after { content: " \21C4"; }

/* protein progress ring */
.ring-wrap { position: relative; width: 160px; margin: 4px auto 14px; }
.ring { width: 160px; height: 160px; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 10; }
.ring-bg { stroke: var(--accent-soft); }
.ring-fg {
  stroke: var(--accent);
  stroke-linecap: round;
  stroke-dasharray: 339.29;
  stroke-dashoffset: 339.29;
  transition: stroke-dashoffset 0.4s ease;
}
.ring-label {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
}
#protein-total { font-size: 36px; font-weight: 800; line-height: 1; }
.ring-goal { color: var(--muted); font-size: 14px; margin-top: 4px; }

/* buttons & inputs */
.preset-row { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; margin-bottom: 8px; }
button {
  font: inherit; border: none; border-radius: 12px;
  background: var(--accent-soft); color: var(--text);
  padding: 14px 0; font-size: 16px; font-weight: 700;
  cursor: pointer; -webkit-tap-highlight-color: transparent;
}
button:active { opacity: 0.7; }

.custom-row { display: flex; gap: 8px; }
.custom-row input {
  /* width:0 + flex-basis 0 kills the number input's intrinsic min width,
     which otherwise pushes the card past the viewport on iOS WebKit */
  flex: 1 1 0%; width: 0; min-width: 0;
  font: inherit; font-size: 16px;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--accent-soft); border-radius: 12px;
  padding: 12px 14px;
}
.custom-row button { padding: 12px 20px; background: var(--accent); }

#protein-entries { list-style: none; margin-top: 12px; }
#protein-entries li {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 4px; border-top: 1px solid #262a33;
  font-size: 15px;
}
.entry-time { color: var(--muted); font-size: 13px; margin-right: 10px; }
.entry-del { background: none; padding: 4px 10px; color: var(--danger); font-size: 15px; }

.link-btn {
  background: none; color: var(--muted);
  font-size: 13px; font-weight: 400;
  padding: 10px 0 0;
}
.muted { color: var(--muted); font-size: 14px; margin-top: 10px; }
#weight-latest { display: flex; align-items: center; justify-content: space-between; }
.center { text-align: center; }

/* workout */
.big-btn { width: 100%; background: var(--accent); padding: 16px 0; font-size: 18px; }
.danger-btn { background: #3a2028; color: var(--danger); padding: 12px 18px; }
.row-2 { display: flex; justify-content: space-between; align-items: center; margin-top: 14px; }

.session-timer {
  font-size: 44px; font-weight: 800; text-align: center;
  font-variant-numeric: tabular-nums;
  margin: 6px 0 12px;
}
.rest-banner {
  background: var(--accent-soft);
  border-radius: 12px;
  text-align: center;
  padding: 12px;
  margin-bottom: 12px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}
.rest-banner.rest-done { background: #1f3a2a; }
.rest-skip { color: var(--muted); font-size: 12px; font-weight: 400; }

.exercise-input {
  width: 100%;
  font: inherit; font-size: 16px;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--accent-soft); border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 8px;
}
.set-controls { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stepper { min-width: 0; }
.stepper-label { display: block; color: var(--muted); font-size: 12px; margin: 0 0 5px 2px; }
.stepper-row { display: grid; grid-template-columns: 44px minmax(0, 1fr) 44px; }
.stepper-row input {
  width: 100%; min-width: 0; max-width: 100%; min-height: 44px;
  border: 1px solid var(--accent-soft); border-radius: 0;
  background: var(--bg); color: var(--text); text-align: center;
  font: inherit; font-size: 16px; padding: 8px 2px;
  -moz-appearance: textfield;
}
.stepper-row input::-webkit-inner-spin-button,
.stepper-row input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.stepper-btn {
  width: 44px; min-height: 44px; padding: 0; border-radius: 0;
  font-size: 19px; touch-action: manipulation;
}
.stepper-btn:first-child { border-radius: 10px 0 0 10px; }
.stepper-btn:last-child { border-radius: 0 10px 10px 0; }
.set-add-btn { margin-top: 10px; padding: 13px 0; font-size: 16px; }

.exercise-group { margin-top: 14px; }
.exercise-name { font-weight: 700; font-size: 15px; margin-bottom: 4px; }
.set-line {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 4px; border-top: 1px solid #262a33;
  font-size: 15px;
  font-variant-numeric: tabular-nums;
}

.summary-title { font-size: 20px; font-weight: 800; text-align: center; margin: 8px 0 14px; }
.summary-row {
  display: flex; justify-content: space-between;
  padding: 10px 4px; border-top: 1px solid #262a33;
  font-size: 16px;
}
#workout-summary .big-btn { margin-top: 16px; }

/* trends */
.chart-wrap { position: relative; width: 100%; max-width: 100%; min-width: 0; height: 220px; overflow: hidden; }
.chart-wrap canvas { display: block; width: 100% !important; max-width: 100% !important; }
.plain-list { list-style: none; }
.plain-list li {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 4px; border-top: 1px solid #262a33;
  font-size: 15px;
}
.plain-list li:first-child { border-top: none; }
.pr-val { font-variant-numeric: tabular-nums; }

/* tab bar */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0;
  display: grid; grid-template-columns: 1fr 1fr 1fr;
  background: var(--card);
  border-top: 1px solid #262a33;
  padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  background: none; border-radius: 0;
  padding: 14px 0; font-size: 14px; color: var(--muted);
}
.tab.active { color: var(--accent); }

@media (max-width: 359px) {
  .set-controls { grid-template-columns: minmax(0, 1fr); }
}
