/* Black-and-white theme. Contrast against the backgrounds below (WCAG AA needs 4.5:1 for
   text and 3:1 for the edges of controls):
     --text    #ffffff  on --bg 19.8:1, on --surface 18.1:1, on --surface-2 15.5:1
     --muted   #a8a8a8  on --bg  8.3:1, on --surface  7.6:1, on --surface-2  6.5:1
     --control #767676  on --bg  4.4:1, on --surface  4.0:1, on --surface-2  3.4:1  (field edges)
     --danger  #ff6b6b  on --bg  7.1:1, on --surface  6.5:1           (destructive actions only) */
:root {
  --bg: #0a0a0a;
  --surface: #161616;
  --surface-2: #242424;
  --border: #333333;
  --control: #767676;
  --text: #ffffff;
  --muted: #a8a8a8;
  --accent: #ffffff;
  --accent-text: #0a0a0a;
  --danger: #ff6b6b;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html {
  /* Keep text the same size when the phone is rotated. */
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  /* No grey flash when something is tapped. */
  -webkit-tap-highlight-color: transparent;
}

/* No rubber-band bounce past the top or bottom of the page. The page scroller takes this
   from html; body is set too for older browsers. */
html,
body {
  overscroll-behavior: none;
}

/* No double-tap zoom and no tap delay on anything tappable. Pinch zoom still works. */
a,
button,
input,
select,
textarea,
label {
  touch-action: manipulation;
}

/* Controls and the header behave like app chrome: a long press doesn't select their text.
   Inputs and workout text stay selectable. */
button,
.btn,
.bar {
  -webkit-user-select: none;
  user-select: none;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

/* Stacking, lowest first: the pinned rest timer (1), the "Rest over" banner (2), the header
   and its menus (3), the number pad (5). The duration popup is a <dialog>, above them all. */
.bar {
  position: sticky;
  top: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: space-between;
  /* Clear the notch / status bar on top and the rounded corners in landscape. */
  padding: max(12px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 12px
    max(16px, env(safe-area-inset-left));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand {
  color: var(--text);
  font-size: 1.25rem;
  font-weight: 700;
  text-decoration: none;
}

main {
  max-width: 560px;
  margin: 0 auto;
  /* Bottom content clears the home bar; sides clear the notch in landscape. */
  padding: 16px max(16px, env(safe-area-inset-right)) calc(32px + env(safe-area-inset-bottom))
    max(16px, env(safe-area-inset-left));
}

h1 {
  margin: 0;
  font-size: 1.5rem;
  overflow-wrap: anywhere;
}

h2 {
  margin: 24px 0 8px;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

h3 {
  margin: 0;
  font-size: 1.1rem;
  overflow-wrap: anywhere;
}

.muted {
  color: var(--muted);
  font-size: 0.9rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 12px;
}

.row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.row > .grow {
  flex: 1;
  min-width: 0;
}

input {
  width: 100%;
  min-height: 44px;
  padding: 8px 12px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--control);
  border-radius: 8px;
}

/* iOS Safari zooms the page when a focused field's text is under 16px. Fields take the
   page's font but never the small size of a surrounding <label>. */
input,
select,
textarea {
  font: inherit;
  font-size: max(16px, 1rem);
}

input:focus-visible,
button:focus-visible,
a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

label {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
}

label input {
  margin-top: 4px;
}

.btn {
  min-height: 44px;
  padding: 8px 16px;
  background: var(--accent);
  color: var(--accent-text);
  border: 0;
  border-radius: 8px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.btn:disabled {
  opacity: 0.5;
  cursor: default;
}

.backup p {
  margin: 0 0 12px;
}

.backup .status {
  margin: 12px 0 0;
}

a.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

#header-actions {
  gap: 8px;
}

#auth {
  gap: 4px;
}

/* Icons inside buttons and links */
.icon {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
}

/* Dropdown menus: the header's ⋮ and profile menus and the menu on each exercise of the
   Exercise data page. The panel hangs under its button, lined up with the button's right
   edge (app.js moves it above the button when there is no room below). */
.dropdown {
  position: relative;
  display: flex;
  flex: none;
}

.menu-panel {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 10;
  width: max-content;
  min-width: 200px;
  max-width: min(280px, calc(100vw - 32px));
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--control);
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6);
}

.menu-panel[hidden] {
  display: none;
}

.menu-panel.above {
  top: auto;
  bottom: calc(100% + 6px);
}

/* Name and email above the profile menu's options; selectable, unlike the rest of the header. */
.menu-head {
  margin-bottom: 6px;
  padding: 8px 10px 10px;
  border-bottom: 1px solid var(--border);
  -webkit-user-select: text;
  user-select: text;
}

.menu-head strong,
.menu-head .muted {
  display: block;
  overflow-wrap: anywhere;
}

.menu {
  display: grid;
  gap: 2px;
}

.menu-item {
  display: flex;
  align-items: center;
  width: 100%;
  min-height: 44px;
  padding: 8px 10px;
  background: transparent;
  color: var(--text);
  border: 0;
  border-radius: 8px;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.menu-item:hover {
  background: var(--surface-2);
}

.menu-item:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.menu-item.destructive {
  color: var(--danger);
}

.menu-item:disabled {
  background: transparent;
  opacity: 0.5;
  cursor: default;
}

/* A header button whose menu is open, and the gear while Settings is showing. */
.icon-btn[aria-expanded='true'],
.icon-btn[aria-pressed='true'] {
  color: var(--text);
  background: var(--surface-2);
}

/* Profile picture button */
.avatar-btn {
  width: 44px;
  height: 44px;
  padding: 4px;
  background: transparent;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
}

.avatar {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  overflow: hidden;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--control);
  border-radius: 50%;
  font-weight: 600;
}

.avatar img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.avatar-btn[aria-expanded='true'] .avatar {
  border-color: var(--text);
}

#notice {
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 528px;
  margin: 12px auto 0;
  padding: 8px 8px 8px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
}

#notice[hidden] {
  display: none;
}

#notice span {
  flex: 1;
}

#notice.error {
  border-color: var(--text);
  font-weight: 600;
}

@media (max-width: 560px) {
  #notice {
    margin-left: 16px;
    margin-right: 16px;
  }
}

.signin {
  margin-top: 16px;
}

.signin p,
.account p {
  margin: 8px 0 14px;
}

.signin .local-note,
.signin .error {
  margin: 14px 0 0;
}

.btn.small {
  min-height: 36px;
  padding: 4px 12px;
}

.btn.secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}

/* Destructive actions are the only place the danger colour is used. */
.btn.danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--danger);
}

.btn.block {
  width: 100%;
}

/* Icon-only buttons and links: 44px touch target, and each has an aria-label. */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  flex: none;
  background: transparent;
  color: var(--muted);
  border: 0;
  border-radius: 8px;
  font-size: 1.3rem;
  line-height: 1;
  text-decoration: none;
  cursor: pointer;
}

.icon-btn:hover {
  color: var(--text);
  background: var(--surface-2);
}

.icon-btn.destructive:hover {
  color: var(--danger);
}

.back {
  display: inline-block;
  margin-bottom: 12px;
  color: var(--muted);
  text-decoration: none;
}

/* Home and History */

h1 + .workout-link,
h1 + p {
  margin-top: 12px;
}

.workout-link {
  display: block;
  color: inherit;
  text-decoration: none;
}

.workout-link strong {
  display: block;
  font-size: 1.05rem;
  overflow-wrap: anywhere;
}

.badge {
  flex: none;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--text);
  color: var(--text);
  font-size: 0.75rem;
  font-weight: 600;
}

.start-workout {
  min-height: 56px;
  margin-top: 8px;
  font-size: 1.1rem;
}

/* A saved outline: the whole card is the button that starts a workout from it. */
.outline-start {
  display: block;
  width: 100%;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.outline-start strong,
.outline-start .muted {
  display: block;
  overflow-wrap: anywhere;
}

.outline-start strong {
  font-size: 1.05rem;
}

/* Elapsed time at the top of a workout in progress */
.timer {
  margin-bottom: 4px;
  font-size: 2.25rem;
  font-weight: 700;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

/* Focused from code only, when Skip goes away under the focus. */
.workout-clock:focus {
  outline: none;
}

/* While resting: "REST 02:29" with -15s, +15s and Skip, pinned under the header and as wide
   as the screen, so the page scrolls cleanly underneath it. */
.workout-clock.resting {
  position: sticky;
  top: var(--bar-height, 0px);
  z-index: 1;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 0 calc(-1 * max(16px, env(safe-area-inset-right))) 8px calc(-1 * max(16px, env(safe-area-inset-left)));
  padding: 8px max(16px, env(safe-area-inset-right)) 8px max(16px, env(safe-area-inset-left));
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

/* A little smaller than the elapsed time, so the digits and the three buttons fit on one
   line on a 360px wide phone. */
.workout-clock.resting .timer {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin: 0;
  font-size: 2rem;
}

.rest-word {
  font-size: 0.9rem;
  letter-spacing: 0.08em;
}

.rest-controls {
  display: flex;
  gap: 4px;
  margin-left: auto;
}

.rest-controls .btn {
  min-width: 52px;
  padding: 8px;
  font-variant-numeric: tabular-nums;
}

/* "Rest timer 2m 30s ✎" and its switch: the one rest timer, near the top of a workout */
.rest-row {
  display: flex;
  align-items: center;
  gap: 4px;
  color: var(--muted);
  font-size: 0.9rem;
}

/* Under the "In progress" / lb-kg row, above the first exercise. */
.workout-rest {
  margin: -8px 0 8px;
}

.rest-row .switch {
  margin-left: auto;
}

/* The length, with a pencil: opens the "Rest timer duration" popup. */
.rest-length {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 8px;
  background: transparent;
  color: var(--text);
  border: 0;
  border-radius: 8px;
  font: inherit;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}

.rest-length:hover {
  background: var(--surface-2);
}

.rest-length .icon {
  width: 16px;
  height: 16px;
  color: var(--muted);
}

.rest-row.off .rest-length {
  color: var(--muted);
}

/* On/off switch: a 44px tall button with the track and knob drawn inside it. */
.switch {
  position: relative;
  flex: none;
  width: 52px;
  height: 44px;
  padding: 0;
  background: transparent;
  border: 0;
  border-radius: 999px;
  cursor: pointer;
}

.switch::before {
  content: '';
  position: absolute;
  top: 7px;
  left: 0;
  width: 52px;
  height: 30px;
  box-sizing: border-box;
  background: var(--surface-2);
  border: 1px solid var(--control);
  border-radius: 999px;
  transition: background-color 0.15s, border-color 0.15s;
}

.switch-knob {
  position: absolute;
  top: 11px;
  left: 4px;
  width: 22px;
  height: 22px;
  background: var(--muted);
  border-radius: 50%;
  transition: transform 0.15s, background-color 0.15s;
}

.switch[aria-checked='true']::before {
  background: var(--accent);
  border-color: var(--accent);
}

.switch[aria-checked='true'] .switch-knob {
  transform: translateX(22px);
  background: var(--accent-text);
}

@media (prefers-reduced-motion: reduce) {
  .switch::before,
  .switch-knob {
    transition: none;
  }
}

/* "Rest over", just under the header on any screen */
#rest-banner {
  position: fixed;
  top: calc(var(--bar-height, 68px) + 8px);
  left: 50%;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 8px;
  width: min(528px, calc(100% - 32px));
  padding: 6px 6px 6px 16px;
  background: var(--accent);
  color: var(--accent-text);
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6);
  font-weight: 700;
  transform: translateX(-50%);
  animation: banner-in 0.2s ease-out;
}

#rest-banner[hidden] {
  display: none;
}

#rest-banner span {
  flex: 1;
  min-width: 0;
  overflow-wrap: anywhere;
}

#rest-banner .icon-btn {
  color: var(--accent-text);
}

#rest-banner .icon-btn:hover {
  background: rgba(0, 0, 0, 0.1);
}

#rest-banner .icon-btn:focus-visible {
  outline-color: var(--accent-text);
}

@keyframes banner-in {
  from {
    opacity: 0;
    transform: translate(-50%, -8px);
  }
}

@media (prefers-reduced-motion: reduce) {
  #rest-banner {
    animation: none;
  }
}

/* "Rest timer duration" popup with minute and second wheels */
.picker {
  width: min(360px, calc(100vw - 32px));
  padding: 0;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--control);
  border-radius: 16px;
}

.picker::backdrop {
  background: rgba(0, 0, 0, 0.7);
}

/* The page behind the popup stays still. */
body:has(.picker[open]) {
  overflow: hidden;
}

.picker form {
  display: grid;
  gap: 16px;
  padding: 20px;
}

.picker-title {
  margin: 0;
  color: var(--text);
  font-size: 1.15rem;
  letter-spacing: normal;
  text-transform: none;
}

.picker-hint {
  margin: -8px 0 0;
  text-align: center;
}

.picker-hint:empty {
  display: none;
}

/* Five rows show; the middle one is the choice, on a lighter band. */
.wheels {
  --wheel-row: 40px;
  position: relative;
  display: flex;
  justify-content: center;
  gap: 24px;
  isolation: isolate;
}

.wheels::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 0;
  right: 0;
  z-index: -1;
  height: var(--wheel-row);
  background: var(--surface-2);
  border-radius: 8px;
  transform: translateY(-50%);
}

.wheel-column {
  display: flex;
  align-items: center;
  gap: 6px;
}

.wheel {
  width: 64px;
  height: calc(var(--wheel-row) * 5);
  overflow-y: auto;
  overscroll-behavior: contain;
  scroll-snap-type: y mandatory;
  scrollbar-width: none;
  border-radius: 8px;
  -webkit-mask-image: linear-gradient(transparent, #000 30%, #000 70%, transparent);
  mask-image: linear-gradient(transparent, #000 30%, #000 70%, transparent);
}

.wheel::-webkit-scrollbar {
  display: none;
}

/* The fade would clip a ring drawn on the wheel itself, so the ring goes around its column. */
.wheel:focus-visible {
  outline: none;
}

.wheel-column {
  border-radius: 8px;
}

.wheel-column:has(.wheel:focus-visible) {
  outline: 2px solid var(--accent);
  outline-offset: 4px;
}

.wheel-spacer {
  height: calc(var(--wheel-row) * 2);
}

.wheel-item {
  height: var(--wheel-row);
  line-height: var(--wheel-row);
  color: var(--muted);
  font-size: 1.4rem;
  font-variant-numeric: tabular-nums;
  text-align: center;
  scroll-snap-align: center;
  cursor: pointer;
}

.wheel-item.selected {
  color: var(--text);
  font-weight: 700;
}

.wheel-unit {
  width: 2.2em;
  color: var(--muted);
}

/* Workout completed */

.done-when {
  margin: 4px 0 16px;
}

.total-time span,
.total-time strong {
  display: block;
}

.total-time strong {
  font-size: 2rem;
  line-height: 1.2;
}

.improved {
  list-style: none;
  padding: 4px 14px;
}

.improved li {
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.improved li:last-child {
  border-bottom: 0;
}

.improved .badge {
  display: inline-block;
  margin-left: 8px;
}

.save-outline {
  margin-bottom: 0;
}

.save-outline p {
  margin: 0 0 12px;
  overflow-wrap: anywhere;
}

.actions .status {
  margin: 0;
}

/* Outlines in Settings */

.outline-edit {
  margin-bottom: 12px;
}

.outline-edit p {
  margin: 10px 0 0;
  overflow-wrap: anywhere;
}

.exercise .planned {
  margin: 8px 0 0;
}

/* Exercise data */

.exercise-intro {
  margin: 8px 0 12px;
}

/* Safari draws search boxes its own way; keep the look of the other fields. */
input[type='search'] {
  -webkit-appearance: none;
  appearance: none;
}

.exercise-status {
  margin: 12px 0 0;
}

.exercise-status:empty {
  margin: 0;
}

.exercise-data-list {
  margin: 12px 0 0;
  padding: 0;
  list-style: none;
}

.stats {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 2px 12px;
  margin: 6px 0 0;
  font-variant-numeric: tabular-nums;
}

.stats dt {
  color: var(--muted);
}

.stats dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.stats .edited {
  font-size: 0.85rem;
}

.stats-editor {
  display: grid;
  gap: 14px;
  margin-top: 10px;
}

.stats-editor p {
  margin: 0;
}

.stat-fields {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.stat-fields legend {
  margin-bottom: 4px;
  padding: 0;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.stat-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.stat-row label {
  flex: 1;
  min-width: 0;
}

/* "Logged in: lb / kg" under the weight and reps, its hint, and once the unit has been
   switched, the result in both units. */
.unit-line {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-top: 10px;
  color: var(--muted);
  font-size: 0.9rem;
}

.stat-fields .unit-hint {
  margin: 6px 0 0;
  font-size: 0.8rem;
}

.stat-fields .unit-result {
  margin: 6px 0 0;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.stat-fields .unit-result:empty {
  margin: 0;
}

/* The heading is focused from code (after an exercise is removed); it needs no ring. */
h1[tabindex='-1']:focus {
  outline: none;
}

/* lb / kg switch */

.unit-toggle {
  display: inline-flex;
  flex: none;
  overflow: hidden;
  border: 1px solid var(--control);
  border-radius: 8px;
}

.unit-option {
  min-width: 48px;
  min-height: 44px;
  padding: 0 12px;
  background: transparent;
  color: var(--muted);
  border: 0;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.unit-option[aria-pressed='true'] {
  background: var(--accent);
  color: var(--accent-text);
}

/* The switch clips its children, so draw the focus ring inside the button. */
.unit-option:focus-visible {
  outline-offset: -4px;
}

.unit-option[aria-pressed='true']:focus-visible {
  outline-color: var(--accent-text);
}

.workout-meta {
  margin: 8px 0 14px;
}

.workout-meta p {
  margin: 0;
}

.units p {
  margin: 12px 0 0;
}

/* Workout */

.sets {
  list-style: none;
  margin: 8px 0;
  padding: 0;
}

.sets li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 0;
  border-bottom: 1px solid var(--border);
}

.set-n {
  width: 1.5em;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.set-v {
  flex: 1;
  font-variant-numeric: tabular-nums;
}

.add-set {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  margin-top: 10px;
}

.add-set label {
  flex: 1;
  min-width: 0;
}

.add-set .cancel-set {
  height: 44px;
}

.open-set {
  margin-top: 10px;
}

/* "Last 135 lb × 8   Max 155 lb × 5" above the set row. One line when both fit; otherwise
   Max wraps under Last, and the labels' fixed width lines the two values up in a column. */

.set-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 2px 24px;
  margin: 10px 0 0;
  font-size: 0.95rem;
  font-variant-numeric: tabular-nums;
}

.set-stat {
  display: flex;
  gap: 8px;
  min-width: 0;
}

.set-stat dt {
  flex: none;
  min-width: 2.4em;
  color: var(--muted);
}

.set-stat dd {
  margin: 0;
  min-width: 0;
  overflow-wrap: anywhere;
}

/* Read by screen readers, not shown. */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* "Add exercise" suggestions */

.exercise-list {
  list-style: none;
  margin: 10px 0 0;
  padding: 0;
  /* About six rows; the rest scroll. */
  max-height: min(40vh, 270px);
  overflow-y: auto;
  overscroll-behavior: contain;
  border: 1px solid var(--control);
  border-radius: 8px;
}

.exercise-list[hidden] {
  display: none;
}

.exercise-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  overflow-wrap: anywhere;
  cursor: pointer;
}

.exercise-list li:last-child {
  border-bottom: 0;
}

.exercise-list li > .grow {
  flex: 1;
  min-width: 0;
}

.exercise-list li > .muted {
  flex: none;
  font-size: 0.8rem;
}

.exercise-list li:hover {
  background: var(--surface-2);
}

/* The option the arrow keys are on. */
.exercise-list li.active {
  background: var(--surface-2);
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

/* While the list is open, leave room so it can scroll above the phone keyboard. */
body.exercise-list-open main {
  padding-bottom: 50vh;
}

/* In-app number pad for the weight and reps fields */

#keypad {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 5;
  /* Clears the home bar, and the notch side in landscape. */
  padding: 8px max(8px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom))
    max(8px, env(safe-area-inset-left));
  background: var(--surface);
  border-top: 1px solid var(--border);
  /* Closed: slid off the bottom, and out of reach of Tab and screen readers. */
  transform: translateY(100%);
  visibility: hidden;
  transition: transform 0.18s ease, visibility 0s linear 0.18s;
  -webkit-user-select: none;
  user-select: none;
}

#keypad.open {
  transform: none;
  visibility: visible;
  transition: transform 0.18s ease;
}

@media (prefers-reduced-motion: reduce) {
  #keypad,
  #keypad.open {
    transition: none;
  }
}

.pad-keys {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  max-width: 528px;
  margin: 0 auto;
}

.pad-key {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 56px;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  font: inherit;
  font-size: 1.4rem;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}

.pad-key:active {
  background: var(--border);
}

.pad-key:disabled {
  opacity: 0.35;
  cursor: default;
}

/* Bottom row: "Hide keypad" in the first column, the action key across the other two. */
.pad-action {
  grid-column: 2 / -1;
  background: var(--accent);
  color: var(--accent-text);
  border: 0;
  font-size: 1.1rem;
  font-weight: 600;
}

.pad-action:active {
  background: var(--accent);
  filter: brightness(0.9);
}

/* Short, wide screens (a phone on its side): put the action key in a fourth column so the
   pad is four rows tall instead of five. */
@media (orientation: landscape) and (max-height: 520px) {
  .pad-keys {
    grid-template-columns: repeat(4, 1fr);
  }

  .pad-action {
    grid-column: 4;
    grid-row: 1 / span 3;
  }

  .pad-hide {
    grid-column: 4;
    grid-row: 4;
  }

  /* There isn't room for a pinned header, the field and the pad; let the header scroll,
     and the rest timer with it. */
  body.pad-open .bar,
  body.pad-open .workout-clock.resting {
    position: static;
  }
}

/* The field the pad is typing into. */
input.pad-active {
  border-color: var(--accent);
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* "Add set" was pressed with nothing usable in the field. */
input.pad-invalid {
  outline-style: dashed;
}

/* While the pad is up, leave room so the last fields can scroll above it. */
body.pad-open main {
  padding-bottom: calc(var(--pad-height, 320px) + 24px);
}

.actions {
  display: grid;
  gap: 8px;
  margin-top: 24px;
}

/* Problems are shown in bold white with a bar, not in the danger colour. */
.error {
  padding-left: 10px;
  border-left: 3px solid var(--text);
  color: var(--text);
  font-weight: 600;
}
