/* ==========================================================
   Workout Tracker styles
   Dark, minimal theme: flat surfaces, thin borders, one accent.
   Mobile-first: the base styles are for a phone. The only
   "bigger screen" rule is the max-width on the content column.
   ========================================================== */

/* ---------- Variables: change colors and sizes in one place ---------- */
:root {
  /* The one accent color. Used sparingly: the Save button, the active
     tab and focus outlines. Change it here to re-color the whole app. */
  --accent: #60a5fa;
  --accent-text: #0b0c0e;   /* text on top of the accent */

  --bg: #0b0c0e;          /* page background, tab bar */
  --surface: #131518;     /* cards */
  --field: #1a1d21;       /* inside of inputs and quiet buttons */
  --text: #ececee;
  --muted: #868b94;
  --border: #25282e;      /* the thin lines around cards and inputs */
  --error: #f87171;       /* error messages and "remove" actions */

  --touch: 52px;        /* minimum height for anything you tap */
  --radius: 12px;       /* inputs and buttons */
  --radius-card: 16px;  /* cards */
  --tab-bar-height: 64px;

  /* Tells the browser the page is dark, so its own bits (the dropdown
     list, scrollbars, the keyboard on some phones) are drawn dark too. */
  color-scheme: dark;
}

/* ---------- Base ---------- */
* {
  box-sizing: border-box;   /* padding and border count toward an element's width */
}

/* Make sure "hidden" always wins, even on elements we give a display to */
[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 17px;
  line-height: 1.45;
  /* Leave room so the fixed tab bar never covers the last bit of content */
  padding-bottom: calc(var(--tab-bar-height) + env(safe-area-inset-bottom) + 24px);
  /* No grey flash when tapping things on a phone */
  -webkit-tap-highlight-color: transparent;
}

/* Inputs and buttons don't inherit the page font by default */
input,
select,
button {
  font: inherit;
  color: inherit;
}

h1, h2, h3 {
  margin: 0;
}

/* ---------- Back link ---------- */

/* "← Robert Naanos": a quiet link back to the main site, above the
   screen heading. The padding makes the tap target taller than the text. */
.back {
  display: inline-block;
  padding: 10px 12px 10px 0;
  color: var(--muted);
  font-size: 14px;
  text-decoration: none;
}

.back:hover,
.back:active {
  color: var(--text);
}

/* ---------- Screens ---------- */
main {
  max-width: 520px;   /* keeps the layout phone-shaped on a laptop */
  margin: 0 auto;
  /* env(...) keeps the top clear of the notch on newer phones */
  padding: calc(14px + env(safe-area-inset-top)) 16px 16px;
}

.screen h2 {
  margin-top: 8px;
  margin-bottom: 24px;
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

/* ---------- Cards ---------- */
.card {
  padding: 20px 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
}

/* ---------- Log screen ---------- */

/* Small uppercase labels, also used for the Set / Reps / Weight headings */
.field-label,
.set-header {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

.field-label {
  display: block;
  margin-bottom: 10px;
}

.text-input,
.number-input {
  width: 100%;
  min-height: var(--touch);
  padding: 0 14px;
  background: var(--field);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  /* 16px or larger stops iOS Safari from zooming in when an input is tapped */
  font-size: 18px;
  font-weight: 500;
}

.number-input {
  padding: 0 6px;
  font-size: 20px;
  text-align: center;
}

.text-input::placeholder,
.number-input::placeholder {
  color: var(--muted);
  font-weight: 400;
  opacity: 0.6;
}

/* The only change on focus is the border turning the accent color */
.text-input:focus,
.number-input:focus {
  outline: none;
  border-color: var(--accent);
}

/* The dropdown: hide the browser's own arrow and draw a chevron instead */
.select-input {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 44px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23868b94' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 20px;
  cursor: pointer;
}

.sets {
  margin: 28px 0 4px;
}

/* One set = a 5-column grid: set number | reps | × | weight | remove button */
.set-row {
  display: grid;
  grid-template-columns: 32px 1fr 16px 1fr 44px;
  gap: 8px;
  align-items: center;
  margin-bottom: 10px;
}

.set-header {
  margin-bottom: 10px;
  text-align: center;
}

/* Cardio = the same look with fewer columns: duration | distance */
.cardio-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  align-items: center;
  margin-bottom: 10px;
}

/* The set number: just a quiet number, no badge behind it */
.set-number {
  width: 30px;
  height: 30px;
  color: var(--muted);
  font-size: 15px;
  font-weight: 500;
  line-height: 30px;
  text-align: center;
}

.times {
  text-align: center;
  color: var(--muted);
}

/* The × that removes a set row. The symbol is small, but the button
   fills its grid cell so it's still easy to hit. */
.remove-set {
  min-height: var(--touch);
  padding: 0;
  background: none;
  border: none;
  border-radius: var(--radius);
  color: var(--muted);
  font-size: 22px;
  font-weight: 300;
  cursor: pointer;
}

.remove-set:active {
  color: var(--error);
}

/* ---------- Buttons ---------- */
.button {
  display: block;
  width: 100%;
  min-height: var(--touch);
  border: none;
  border-radius: var(--radius);
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.1s;
}

/* A slight dim when tapped */
.button:active {
  opacity: 0.75;
}

/* "+ Add set": an outline only, so it stays in the background */
.button-secondary {
  margin-top: 6px;
  background: none;
  border: 1px solid var(--border);
  color: var(--text);
  font-weight: 500;
}

/* "Save workout": the one solid, accent-colored thing on the screen */
.button-primary {
  min-height: 60px;   /* the main action gets the biggest target */
  margin-top: 20px;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 18px;
}

/* A clear ring when moving around with a keyboard */
button:focus-visible,
summary:focus-visible,
a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- Save message ---------- */
.message {
  min-height: 1.45em;   /* reserves the space so the page doesn't jump */
  margin: 16px 0 0;
  text-align: center;
  font-size: 15px;
  color: var(--muted);
}

.message.error {
  color: var(--error);
}

/* ---------- History screen ---------- */
.empty-message {
  margin: 56px 16px;
  text-align: center;
  color: var(--muted);
}

/* Each workout is a card (same look as .card above) */
.workout {
  margin-bottom: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
}

/* The tappable row that opens and closes a workout */
.workout summary {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 64px;
  padding: 0 18px;
  border-radius: var(--radius-card);
  cursor: pointer;
  list-style: none;   /* hide the browser's default triangle... */
}

.workout summary::-webkit-details-marker {
  display: none;      /* ...Safari needs this to hide it too */
}

/* Our own arrow: two borders of a small square, rotated into a chevron */
.workout summary::after {
  content: "";
  width: 8px;
  height: 8px;
  margin-top: -4px;
  border-right: 1.5px solid var(--muted);
  border-bottom: 1.5px solid var(--muted);
  transform: rotate(45deg);
  transition: transform 0.15s;
}

/* Flip the chevron to point up when the card is open */
.workout[open] summary::after {
  margin-top: 4px;
  transform: rotate(-135deg);
}

.workout-date {
  flex: 1;   /* pushes the count and chevron to the right edge */
  font-weight: 600;
}

.workout-summary {
  font-size: 14px;
  color: var(--muted);
}

.workout-body {
  padding: 4px 18px 20px;
  border-top: 1px solid var(--border);
}

.workout-body h3 {
  margin-top: 18px;
  font-size: 15px;
  font-weight: 600;
}

/* Sets are shown as a row of outlined pills, in the order they were done */
.set-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 10px 0 0;
  padding: 0;
  list-style: none;
}

.set-list li {
  padding: 5px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 14px;
  color: var(--muted);
}

/* "Upload my existing history": same outline button as "+ Add set" */
.upload-history {
  margin: 0 0 16px;
}

/* ---------- Sync status ---------- */

/* One small, quiet line under each screen */
.sync-status {
  margin: 24px 0 0;
  text-align: center;
  font-size: 13px;
  color: var(--muted);
}

/* "Enter API key": looks like a text link */
.link-button {
  padding: 10px 6px;
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
}

/* ---------- Bottom tab bar ---------- */
.tab-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  background: var(--bg);
  border-top: 1px solid var(--border);
  /* Keeps the tabs above the home-indicator bar on newer iPhones */
  padding-bottom: env(safe-area-inset-bottom);
}

.tab {
  flex: 1;   /* the two tabs split the width evenly */
  /* Icon on top, label underneath */
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: var(--tab-bar-height);
  background: none;
  border: none;
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.04em;
  cursor: pointer;
}

.tab-icon {
  width: 24px;
  height: 24px;
  /* Icons are line drawings that take the tab's text color */
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.tab.active {
  color: var(--accent);
}
