:root {
  --bg: #0a1428;
  --bg-2: #0f1c38;
  --bg-rest: #0d2434;
  --surface: #142340;
  --surface-2: #1c2c4d;
  --surface-3: #243759;
  --border: #2c3f63;
  --border-strong: #3a4f78;
  --text: #e8edf7;
  --muted: #8a96b3;
  --primary: #f0a574;
  --primary-hover: #e89255;
  --accent: #f7c994;
  --accent-soft: rgba(240, 165, 116, 0.16);
  --danger: #ff7a8a;
  --gradient: linear-gradient(135deg, #f0a574, #e89255);
  --shadow-card: 0 1px 0 rgba(255, 255, 255, 0.03), 0 14px 30px -18px rgba(0, 0, 0, 0.7);
  --radius: 16px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  color: var(--text);
  font-family: "Avenir Next", Avenir, "Nunito Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 17px;
  line-height: 1.5;
  min-height: 100vh;
  min-height: 100dvh;
  background-color: var(--bg);
  background-image:
    radial-gradient(900px 600px at 85% -10%, rgba(240, 165, 116, 0.08), transparent 65%),
    radial-gradient(700px 500px at -10% 110%, rgba(76, 130, 220, 0.10), transparent 65%);
  background-attachment: fixed;
  transition: background-color 300ms ease;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body.is-rest {
  background-color: var(--bg-rest);
}

.app {
  max-width: 720px;
  margin: 0 auto;
  padding: 20px 20px 60px;
}

.topbar {
  display: flex;
  align-items: stretch;
  gap: 8px;
  margin-bottom: 20px;
}

.tabs {
  display: flex;
  gap: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 5px;
  flex: 1;
  box-shadow: var(--shadow-card);
}

.icon-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 12px;
  width: 46px;
  height: 46px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: color 150ms ease, border-color 150ms ease, background 150ms ease;
  flex: none;
}

.icon-btn--small {
  width: 36px;
  height: 36px;
  border-radius: 10px;
}

.icon-btn.is-paused {
  color: var(--primary);
  border-color: rgba(240, 165, 116, 0.4);
}

.active__top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-btn:active {
  transform: scale(0.97);
}

@media (hover: hover) {
  .icon-btn:hover {
    color: var(--text);
    border-color: var(--border-strong);
  }
}

.modal[hidden] {
  display: none;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(4px);
}

.modal__card {
  position: relative;
  background: linear-gradient(180deg, var(--surface), var(--bg-2));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  max-width: 460px;
  width: 100%;
  box-shadow: 0 30px 60px -20px rgba(0, 0, 0, 0.7);
}

.modal__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.modal__title {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

body.modal-open {
  overflow: hidden;
}

.tab {
  flex: 1;
  background: transparent;
  border: 0;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  padding: 9px 12px;
  border-radius: 9px;
  cursor: pointer;
  min-height: 38px;
  transition: color 150ms ease, background 150ms ease;
}

.tab--active {
  background: var(--surface-3);
  color: var(--text);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.04);
}

.tab-panel.hidden {
  display: none;
}

.app__header {
  margin-bottom: 22px;
}

.app__header h1 {
  margin: 0 0 4px;
  font-size: 30px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
}

.app__subtitle {
  margin: 0;
  color: var(--muted);
  font-size: 15px;
}

.screen.hidden {
  display: none;
}

.card {
  background: linear-gradient(180deg, var(--surface), var(--bg-2));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-card);
}

.label {
  font-size: 13px;
  color: var(--muted);
  display: block;
  margin-bottom: 4px;
}

.hint {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 14px;
}

.hint code {
  background: var(--surface-2);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 13px;
}

.textarea {
  width: 100%;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  padding: 12px 14px;
  font-size: 15px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  resize: vertical;
  min-height: 180px;
  transition: border-color 150ms ease, box-shadow 150ms ease;
}

.textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(124, 92, 255, 0.18);
}

.row {
  display: flex;
  gap: 10px;
}

.row--actions {
  margin-top: 12px;
  justify-content: space-between;
}

.button {
  border: 0;
  border-radius: 10px;
  padding: 11px 18px;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
  cursor: pointer;
  min-height: 46px;
  transition: transform 80ms ease, box-shadow 150ms ease, background 150ms ease, border-color 150ms ease;
}

.button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.button--primary {
  background: var(--primary);
  color: #1a1108;
  box-shadow: 0 6px 18px -10px rgba(240, 165, 116, 0.55);
}

.button--ghost {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}

.button:active:not(:disabled) {
  transform: scale(0.97);
}

.button--primary:active:not(:disabled) {
  background: var(--primary-hover);
}

.link-btn {
  background: none;
  border: 0;
  color: var(--muted);
  font-size: 14px;
  cursor: pointer;
  padding: 6px 8px;
}

@media (hover: hover) {
  .button--primary:hover:not(:disabled) {
    background: var(--primary-hover);
  }

  .button--ghost:hover:not(:disabled) {
    border-color: var(--border-strong);
    background: var(--surface-3);
  }

  .link-btn:hover {
    color: var(--text);
  }

  .tab:hover:not(.tab--active) {
    color: var(--text);
  }
}

.summary {
  margin: 14px 0 0;
  color: var(--accent);
  font-weight: 600;
  font-size: 14px;
}

.summary:empty {
  display: none;
}

.equipment {
  margin: 12px 0 0;
  padding: 10px 14px;
  background: var(--accent-soft);
  border: 1px solid rgba(240, 165, 116, 0.30);
  border-radius: 12px;
  color: var(--accent);
  font-size: 14px;
  font-weight: 500;
}

.equipment:empty {
  display: none;
}

.preview {
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.preview__item {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 9px 12px;
  font-size: 15px;
  color: var(--muted);
}

.active__top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--muted);
  font-size: 14px;
  margin-bottom: 24px;
}

.active__bar {
  height: 6px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 14px;
  border: 1px solid var(--border);
}

.active__bar-fill {
  height: 100%;
  background: var(--primary);
  width: 0%;
  transition: width 0.95s linear;
  box-shadow: 0 0 12px rgba(240, 165, 116, 0.35);
}

.active__exercise {
  font-size: clamp(28px, 6vw, 44px);
  font-weight: 700;
  text-align: center;
  margin: 12px 0 4px;
  text-transform: capitalize;
  word-break: break-word;
}

.active__subtext {
  text-align: center;
  color: var(--muted);
  font-size: 16px;
  margin: 0 0 6px;
  min-height: 1em;
}

.active__subtext:empty {
  display: none;
}

.active__description {
  text-align: center;
  color: var(--text);
  font-size: 19px;
  line-height: 1.55;
  max-width: 540px;
  margin: 0 auto 14px;
  padding: 0 6px;
  white-space: pre-line;
}

.active__description:empty {
  display: none;
}

.timer-wrap {
  position: relative;
  width: clamp(220px, 60vw, 300px);
  aspect-ratio: 1;
  margin: 8px auto 12px;
  display: grid;
  place-items: center;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  outline: none;
}

body.mode-reps .timer-wrap {
  cursor: pointer;
  border-radius: 50%;
  transition: transform 80ms ease, box-shadow 150ms ease;
}

body.mode-reps .timer-wrap:active:not([aria-disabled="true"]) {
  transform: scale(0.97);
}

body.mode-reps .timer-wrap:focus-visible {
  box-shadow: 0 0 0 4px rgba(240, 165, 116, 0.25);
}

.ring {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.ring__bg,
.ring__fg {
  fill: none;
  stroke-width: 4.5;
}

.ring__bg {
  stroke: var(--surface-3);
}

.ring__fg {
  stroke: var(--primary);
  stroke-linecap: round;
  stroke-dasharray: 100;
  stroke-dashoffset: 0;
  transition: stroke-dashoffset 0.95s linear;
  filter: drop-shadow(0 0 10px rgba(240, 165, 116, 0.40));
}

body.mode-reps .ring {
  display: none;
}

.active__timer {
  position: relative;
  z-index: 1;
  font-size: clamp(64px, 18vw, 120px);
  font-weight: 800;
  text-align: center;
  font-variant-numeric: tabular-nums;
  letter-spacing: -2px;
  line-height: 1;
  margin: 0;
  color: var(--text);
}

body.mode-reps .active__timer {
  color: var(--primary);
}

body.is-rest .active__timer {
  color: var(--accent);
  text-shadow: 0 0 24px rgba(240, 165, 116, 0.30);
}

body.mode-time .active__timer {
  color: var(--primary);
}

.active__next {
  text-align: center;
  color: var(--muted);
  font-size: 16px;
  min-height: 1.5em;
}

.active__eta {
  text-align: center;
  color: var(--muted);
  font-size: 15px;
  margin-bottom: 32px;
  min-height: 1.2em;
}

.active__actions {
  display: grid;
  grid-template-columns: 1fr 2fr 1fr;
  gap: 8px;
}

.active__actions .button {
  width: 100%;
}

.done {
  text-align: center;
  padding: 60px 20px;
}

.done__title {
  font-size: 56px;
  font-weight: 800;
  color: var(--accent);
  margin-bottom: 8px;
}

.done__subtitle {
  color: var(--muted);
  margin: 0 0 28px;
}

.today-plan {
  margin: 14px 0 0;
  padding: 10px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--muted);
  font-size: 14px;
}

.link-btn--inline {
  color: var(--primary);
  font-weight: 600;
  padding: 0;
  font-size: inherit;
  font-family: inherit;
  line-height: inherit;
  vertical-align: baseline;
}

@media (hover: hover) {
  .link-btn--inline:hover {
    color: var(--primary-hover);
  }
}

/* History calendar */

.cal__nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.cal__nav .link-btn {
  font-size: 22px;
  padding: 4px 14px;
  color: var(--text);
}

.cal__title {
  font-weight: 600;
  font-size: 15px;
}

.cal__dow,
.cal__grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}

.cal__dow {
  margin-bottom: 4px;
}

.cal__dow span {
  text-align: center;
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.cal__day {
  position: relative;
  aspect-ratio: 1;
  background: var(--surface-2);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  color: var(--muted);
}

.cal__day--empty {
  background: transparent;
}

.cal__day--today {
  outline: 2px solid var(--primary);
}

.cal__day--done {
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid rgba(240, 165, 116, 0.30);
}

.cal__num {
  position: absolute;
  top: 3px;
  left: 5px;
  font-size: 11px;
  font-weight: 600;
}

.cal__x {
  font-size: clamp(20px, 6vw, 30px);
  font-weight: 800;
  color: var(--accent);
  line-height: 1;
}

/* Weekly plan */

.plan {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.plan__day {
  display: flex;
  flex-direction: column;
}

.plan__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.plan__label {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}

.plan__head .link-btn {
  font-size: 13px;
  padding: 4px 8px;
}

.plan__textarea {
  min-height: 90px;
}

.plan__status {
  margin-top: 12px;
  text-align: right;
}

.gen {
  margin-bottom: 14px;
}

.gen[open] {
  padding-bottom: 18px;
}

.gen__summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 16px;
  list-style: none;
  padding: 4px 0;
}

.gen__summary::-webkit-details-marker {
  display: none;
}

.gen__summary::before {
  content: "▸";
  display: inline-block;
  margin-right: 8px;
  color: var(--muted);
  transition: transform 150ms ease;
}

.gen[open] .gen__summary::before {
  transform: rotate(90deg);
}

.gen__input {
  margin-bottom: 10px;
  min-height: 44px;
  font-family: inherit;
}

.gen__check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--muted);
  margin: 4px 0 6px;
}

.gen__status {
  align-self: center;
  margin: 0 0 0 8px;
}

@media (max-width: 540px) {
  .app {
    padding: 16px 14px 40px;
  }

  .textarea {
    font-size: 16px; /* avoid iOS zoom-on-focus */
  }

  .tab {
    font-size: 13px;
  }

  .cal__day {
    font-size: 12px;
  }
}

.muscles {
  margin-top: 16px;
}

.muscles:empty {
  display: none;
}

.muscles__head {
  font-size: 13px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 8px;
}

.muscles__list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.muscle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 13px;
  color: var(--text);
  text-transform: capitalize;
}

.muscle__count {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
  border-radius: 999px;
  padding: 1px 7px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
