/*
  style.css — how the app looks (v0.3.0: full-screen, flat, few buttons).

  The colours are defined once as "variables" at the top and reused below.
  The names match the "Colours" variables in the Figma file. The second
  block swaps them for dark mode when the device is set to dark.
*/

:root {
  --page: #f6f5f1;
  --card: #ffffff;
  --ink: #1c1b19;
  --ink-muted: #6b6860;
  --line: #dcd9d0;
  --accent: #1f6f5c;
  --danger: #b3402e;
  --flash-green: #2fd16f;
  /* The "done today" part of the bars. Same green as the flash in light mode. */
  --today: #2fd16f;
  /* "Darker" in Figma: a see-through black that darkens whatever is behind. */
  --darker: rgba(0, 0, 0, 0.08);
  --dash: #747373;
  --on-green: #ffffff;
}

@media (prefers-color-scheme: dark) {
  :root {
    --page: #141513;
    --card: #1f211e;
    --ink: #f0eee8;
    --ink-muted: #a3a097;
    --line: #363933;
    --accent: #4fc3a1;
    --danger: #e8705c;
    --darker: rgba(255, 255, 255, 0.08);
    --dash: #8a8780;
    /* A deeper green, so the light text on top of it stays readable. */
    --today: #1e7a45;
  }
}

* {
  box-sizing: border-box;
}

/* The "hidden" attribute must always win, even over display rules below. */
[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  background: var(--page);
}

body {
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 17px;
  line-height: 1.45;
  /* Stops the grey flash phones draw on tapped elements; we draw our own. */
  -webkit-tap-highlight-color: transparent;
}

/* One phone-width column. On a phone it is the whole screen. */
main {
  max-width: 480px;
  margin: 0 auto;
}

.screen {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* For text only screen readers should hear. */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

button {
  font: inherit;
  color: inherit;
  /* Removes the short delay phones add while waiting to see if you double-tap. */
  touch-action: manipulation;
}

:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: -3px;
}

/* ---------- Shared: the exercise row look (home rows and the set top bar) ---------- */

.row-name,
.row-reps {
  /* "relative" lifts the text above the progress fill drawn behind it. */
  position: relative;
  font-size: 1.4rem;
  font-weight: 600;
  line-height: 1.2;
}

.row-name {
  min-width: 0;
  overflow-wrap: anywhere;
}

.row-reps {
  flex: none;
  font-variant-numeric: tabular-nums;
}

/* On home rows the number is a double-tap target, so give it a bigger area
   to hit (the padding grows it; the negative margin keeps the layout). */
.row-button .row-reps {
  padding: 24px 30px 24px 16px;
  margin: -24px -30px -24px -16px;
}

/* The two parts of a progress bar: grey = earlier this week, green = today. */
.bar-fill {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 0;
}

.bar-fill-week {
  background: var(--darker);
}

.bar-fill-today {
  background: var(--today);
}

/* ---------- Home ---------- */

.home-screen {
  padding-top: env(safe-area-inset-top);
}

.exercise-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

/* ---------- Superset line ---------- */

/* The dotted line with "↑ Superset": rows above it are the superset.
   It is a fair height so a dragged row has room to cross it. */
.superset-line {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 0 20px 0 18px;
  color: var(--ink-muted);
}

/* The dotted line itself fills the space after the label. */
.superset-line::after {
  content: "";
  flex: 1;
  border-top: 1.5px dashed var(--dash);
}

.superset-line-label {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.85rem;
}

.superset-line-label svg {
  width: 14px;
  height: 14px;
}

/* ---------- Drag handle ---------- */

.exercise-row {
  position: relative;
}

/* The six dots on the left of every row (and the bin in their place while
   a row is edited). */
.drag-handle {
  display: flex;
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 1;
  width: 56px;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--ink-muted);
  cursor: grab;
  /* A finger on the handle drags the row instead of scrolling the page. */
  touch-action: none;
}

.drag-handle svg {
  width: 22px;
  height: 22px;
}

.bin-button {
  color: var(--danger);
  cursor: pointer;
}

.exercise-row.is-dragging .row-button {
  background: var(--darker);
}

/* A set logged by double-tap: the row flashes green for a moment. */
.row-button.is-logged {
  animation: row-logged 1s ease-out;
}

/* A set taken back by triple-tap: a grey flash instead. */
.row-button.is-taken-back {
  animation: row-taken-back 1s ease-out;
}

@keyframes row-taken-back {
  0%,
  30% {
    background-color: var(--dash);
  }
  100% {
    background-color: transparent;
  }
}

@keyframes row-logged {
  0%,
  30% {
    background-color: var(--flash-green);
  }
  100% {
    background-color: transparent;
  }
}

.row-button {
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  width: 100%;
  min-height: 109px;
  /* The extra room on the left is for the drag handle. */
  padding: 0 30px 0 60px;
  border: 0;
  background: transparent;
  text-align: left;
  cursor: pointer;
  /* Holding a row edits it, so stop the phone selecting text or opening its own menu. */
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

/* Feedback while a finger is down on a row. */
.row-button.is-pressing,
.row-button:active {
  background: var(--darker);
}

.row-add {
  color: var(--ink-muted);
}

.row-add .row-name {
  opacity: 0.5;
}

/* The white card used to add or edit an exercise. The left padding leaves
   the handle's column free for the bin. */
.edit-row {
  position: relative;
  padding: 20px 10px 20px 56px;
}

.edit-card {
  display: flex;
  align-items: center;
  gap: 16px;
  min-height: 109px;
  padding: 0 20px;
  background: var(--card);
  border-radius: 10px;
}

.edit-card:focus-within {
  box-shadow: 0 0 0 2px var(--accent);
}

.edit-card input {
  min-width: 0;
  padding: 8px 0;
  border: 0;
  outline: none;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 1.4rem;
  font-weight: 600;
}

.edit-card input::placeholder {
  color: var(--ink-muted);
  opacity: 0.5;
}

.edit-name {
  flex: 1;
}

.edit-reps {
  width: 4.5em;
  text-align: right;
}

.home-footer {
  margin-top: auto;
  padding: 24px 16px calc(16px + env(safe-area-inset-bottom));
  color: var(--ink-muted);
}

.home-footer p {
  margin: 0;
}

.version,
.sync-status {
  font-size: 0.85rem;
}

/* An empty status line takes no room (before the first check finishes). */
.sync-status:empty {
  display: none;
}

/* ---------- Set screen ---------- */

/*
  The set screen is exactly one screen tall, so the fill below can be sized
  as a percentage of it. "relative" makes it the reference for the fill and
  the dashed line, which are placed on top of it ("absolute").
*/
.set-screen {
  position: relative;
  overflow: hidden;
  background: var(--page);
  height: 100vh;
  height: 100dvh;
  -webkit-user-select: none;
  user-select: none;
}

.set-fill {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 0;
  background: var(--darker);
  /* Rises smoothly from one rep to the next. */
  transition: height 0.35s ease-out;
}

/* While listening the fill is a live mic meter: no smoothing, or it lags. */
.set-fill.is-meter {
  transition: none;
}

/*
  Each heard noise or counted rep: the whole background turns green, holds
  for a moment, then fades back. app.js sets --pulse-duration to suit the pace.
  The text turns dark for the moment it sits on green, so it stays readable
  in dark mode too.
*/
.set-screen.is-pulsing {
  animation: background-pulse var(--pulse-duration, 1.4s) ease-out;
}

@keyframes background-pulse {
  0%,
  35% {
    background-color: var(--flash-green);
    color: #0d2316;
  }
  100% {
    background-color: var(--page);
    color: var(--ink);
  }
}

/* Set finished: the whole screen is green. */
.set-fill.is-done {
  background: var(--flash-green);
}

/*
  The dashed line. The element itself is a tall, invisible strip so it is
  easy to grab with a finger; ::before draws the thin dashed line in its middle.
*/
.threshold-line {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 50%;
  height: 44px;
  margin-bottom: -22px;
  z-index: 2;
  cursor: ns-resize;
  /* Lets a finger drag the line without the page scrolling instead. */
  touch-action: none;
}

.threshold-line::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  border-top: 1px dashed var(--dash);
}

.top-bar {
  position: relative;
  z-index: 1;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  width: 100%;
  min-height: 109px;
  /* Left padding matches the home rows, leaving room for the back triangle. */
  padding: calc(30px + env(safe-area-inset-top)) 30px 30px 60px;
  border: 0;
  background: transparent;
  text-align: left;
  cursor: pointer;
}

/* The back triangle, in the same column as the drag handle on the home
   screen. "top" skips the progress strip so it centres on the name. */
.top-bar-back {
  position: absolute;
  left: 17px;
  top: calc(30px + env(safe-area-inset-top));
  bottom: 30px;
  width: 22px;
  height: 22px;
  /* With top and bottom both set, an automatic margin centres it between them. */
  margin: auto 0;
  color: var(--ink-muted);
}

/* The thin progress strip across the top of the top bar. */
.top-bar-strip {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: calc(30px + env(safe-area-inset-top));
}

.stage {
  position: relative;
  z-index: 1;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0 16px;
  border: 0;
  background: transparent;
  cursor: pointer;
}

.stage-label {
  min-height: 1.45em;
  font-size: 1.3rem;
  color: var(--ink-muted);
  text-align: center;
}

/* The number has to be readable from the floor, mid push-up. */
.stage-number {
  font-size: clamp(7rem, 42vw, 10.3rem);
  font-weight: 300;
  line-height: 1;
  /* Every digit the same width, so the number does not jiggle as it counts. */
  font-variant-numeric: tabular-nums;
}

.stage-icon {
  width: 122px;
  height: 122px;
  margin: 21px 0;
}

.stage-icon-on-green {
  color: var(--on-green);
}

.bottom-bar {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
}

.round-button {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 52px;
  height: 52px;
  padding: 0;
  border: 2px solid var(--line);
  border-radius: 12px;
  background: transparent;
  font-size: 1.5rem;
  font-weight: 600;
  cursor: pointer;
}

.round-button svg {
  width: 24px;
  height: 24px;
}

.pace-display {
  min-width: 3.5em;
  font-weight: 600;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.bar-spacer {
  flex: 1;
}
