:root {
  --bg: #070709;
  --bg-2: #0e0f14;
  --card: #181a22;
  --card-2: #20222b;
  --text: #f2f2f5;
  --muted: #9296a3;
  --line: #2c2f3a;
  --brand: #3b82f6;
  --danger: #3b82f6;
  --success: #2b7f51;
  --fs-xs: 12px;
  --fs-sm: 14px;
  --fs-md: 16px;
  --fs-lg: 20px;
  --fs-xl: 22px;
  --fw-regular: 400;
  --fw-medium: 500;
  --fw-semibold: 600;
  --fw-bold: 700;
}

* { box-sizing: border-box; }
html, body {
  overscroll-behavior-y: contain;
  touch-action: manipulation;
  -webkit-text-size-adjust: 100%;
}
body {
  margin: 0;
  background:
    radial-gradient(circle at 20% -10%, rgba(59, 130, 246, 0.16), transparent 35%),
    radial-gradient(circle at 80% 110%, rgba(59, 130, 246, 0.1), transparent 35%),
    linear-gradient(180deg, var(--bg) 0%, var(--bg-2) 100%);
  color: var(--text);
  font-family: "SF Pro Display", "Avenir Next", "Segoe UI", sans-serif;
}

.app-shell {
  max-width: 540px;
  margin: 0 auto;
  min-height: 100vh;
  padding-top: max(42px, calc(env(safe-area-inset-top) + 34px));
  padding-right: 14px;
  padding-left: 14px;
  padding-bottom: max(104px, calc(env(safe-area-inset-bottom) + 92px));
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  padding: 7px 2px 2px;
}

h1, h2, h3, p { margin: 0; }
h1 {
  font-size: var(--fs-xl);
  letter-spacing: 0.06em;
  color: var(--brand);
}
h2 { font-size: var(--fs-lg); margin-bottom: 10px; }
h3 { font-size: var(--fs-md); margin-bottom: 8px; }
.muted { color: var(--muted); }
.big { font-size: var(--fs-xl); font-weight: var(--fw-bold); margin-top: 6px; }

.card {
  background: var(--card);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 18px;
  padding: 14px;
  margin-bottom: 12px;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.35);
}

.row {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  flex-wrap: wrap;
}

button {
  border: none;
  background: var(--brand);
  color: white;
  padding: 10px 14px;
  border-radius: 999px;
  font-size: var(--fs-sm);
  font-weight: var(--fw-semibold);
  transition: transform 0.08s ease, opacity 0.2s ease;
  touch-action: manipulation;
}

button:active {
  transform: scale(0.98);
}

button.ghost {
  background: var(--card-2);
  color: #e6e8ef;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

button.danger { background: var(--danger); }
button.success { background: var(--success); }

.tabs {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 22px;
  background: rgba(18, 20, 28, 0.95);
  backdrop-filter: blur(6px);
  overflow: hidden;
}

.mini-close-btn {
  width: 46px;
  height: 46px;
  min-width: 46px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(18, 20, 28, 0.9);
  color: #b8bfd0;
  font-size: var(--fs-lg);
  line-height: 1;
  padding: 0;
  margin-left: 8px;
}

.bottom-nav {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: max(12px, calc(env(safe-area-inset-bottom) + 8px));
  width: calc(100% - 28px);
  max-width: 512px;
  display: flex;
  align-items: center;
  z-index: 11;
}

.tab {
  border-radius: 0;
  background: transparent;
  color: #a9afbe;
  border-right: 1px solid rgba(255, 255, 255, 0.06);
  padding: 14px 8px;
}

.tab:last-child {
  border-right: none;
}

.tab.active {
  background: rgba(59, 130, 246, 0.2);
  color: #dbeafe;
  font-weight: var(--fw-bold);
}

.view.hidden { display: none; }

.view h2 {
  margin-bottom: 10px;
}

#view-workout,
#view-history {
  padding: 4px 2px 0;
}

#view-workout.no-session {
  padding-top: 0;
}

#view-history {
  padding-top: 0;
}

#view-history h2 {
  font-size: var(--fs-lg);
  margin-top: 2px;
  margin-bottom: 6px;
}

#view-history h2 + .list {
  margin-bottom: 12px;
}

.set-card {
  border: 1px solid rgba(59, 130, 246, 0.4);
  background: linear-gradient(180deg, rgba(59, 130, 246, 0.14), rgba(59, 130, 246, 0.06));
  border-radius: 14px;
  padding: 10px;
  margin: 10px 0;
}

.rest {
  margin: 0;
  display: inline-block;
  background: rgba(43, 127, 81, 0.2);
  border: 1px solid rgba(43, 127, 81, 0.45);
  color: #b7f2ca;
  padding: 8px 12px;
  border-radius: 999px;
  font-size: var(--fs-md);
  font-weight: var(--fw-regular);
}

.rest.inactive {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.14);
  color: #aeb4c3;
}

.control-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  margin-bottom: 8px;
}

.control-row.hidden {
  display: none !important;
}

.control-row .action-row {
  display: flex;
  gap: 8px;
  margin-top: 0;
}

.control-row .action-row.hidden {
  display: none !important;
}

.icon-btn {
  width: 42px;
  height: 42px;
  min-width: 42px;
  border-radius: 50%;
  padding: 0;
  font-size: var(--fs-lg);
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.icon-btn.danger {
  background: #dc2626;
}

.icon-btn.finish-icon {
  font-size: var(--fs-lg);
}

.icon-btn.cancel-icon {
  font-size: var(--fs-lg);
  transform: translateY(-1px);
}

.hidden {
  display: none !important;
}

.exercise-list {
  display: grid;
  gap: 10px;
  margin-top: 10px;
  margin-bottom: 14px;
}

#workoutStartActions.hidden {
  display: none !important;
}

#workoutStartActions {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: max(84px, calc(env(safe-area-inset-bottom) + 78px));
  width: calc(100% - 34px);
  max-width: 420px;
  margin-top: 0;
  z-index: 9;
}

#workoutStartActions button {
  width: 100%;
  padding-top: 13px;
  padding-bottom: 13px;
  font-size: var(--fs-sm);
}

.exercise-item {
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  padding: 10px;
  background: rgba(255, 255, 255, 0.02);
}

.exercise-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  color: #d6dae4;
  font-size: var(--fs-sm);
}

.set-chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  max-width: 360px;
  margin: 0 auto;
}

.set-chip {
  border-radius: 999px;
  flex: 0 1 calc(33.333% - 10px);
  min-width: 96px;
  padding: 12px 14px;
  font-size: var(--fs-sm);
  font-weight: var(--fw-semibold);
  background: var(--card-2);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: #d7dbe6;
}

.set-chip.done {
  background: rgba(59, 130, 246, 0.22);
  border-color: rgba(59, 130, 246, 0.48);
  color: #dbeafe;
}

.set-chip.under {
  background: rgba(239, 68, 68, 0.2);
  border-color: rgba(239, 68, 68, 0.52);
  color: #fee2e2;
}

.set-chip.next {
  box-shadow: 0 0 0 1px rgba(59, 130, 246, 0.9) inset;
  animation: nextSetPulse 1.15s ease-in-out infinite;
  transform-origin: center;
}

@keyframes nextSetPulse {
  0% {
    box-shadow: 0 0 0 1px rgba(59, 130, 246, 0.9) inset, 0 0 0 0 rgba(59, 130, 246, 0.28);
    transform: scale(1);
  }
  50% {
    box-shadow: 0 0 0 1px rgba(59, 130, 246, 1) inset, 0 0 0 8px rgba(59, 130, 246, 0.08);
    transform: scale(1.02);
  }
  100% {
    box-shadow: 0 0 0 1px rgba(59, 130, 246, 0.9) inset, 0 0 0 0 rgba(59, 130, 246, 0);
    transform: scale(1);
  }
}

@media (prefers-reduced-motion: reduce) {
  .set-chip.next {
    animation: none;
  }
}

.list {
  display: grid;
  gap: 8px;
}

.list-item {
  background: var(--card);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 14px;
  padding: 10px;
}

#noWorkoutPreview {
  margin-top: 8px;
  margin-bottom: 8px;
}

#noWorkoutPreview .detail-grid {
  gap: 14px;
}

#noWorkoutPreview,
#previousWorkoutPreview {
  touch-action: pan-x;
}

#nextWorkoutHeading {
  font-size: var(--fs-lg);
  margin-top: 8px;
  margin-bottom: 6px;
}

#previousWorkoutHeading {
  font-size: var(--fs-lg);
  margin-top: 8px;
  margin-bottom: 6px;
}

#view-workout.no-session #nextWorkoutHeading,
#view-workout.no-session #previousWorkoutHeading {
  margin-top: 6px;
}

#view-workout.no-session #noWorkoutPreview,
#view-workout.no-session #previousWorkoutPreview {
  margin-top: 4px;
}

.subdued-heading {
  color: #97a0b1;
}

.subdued-card {
  background: rgba(255, 255, 255, 0.04);
  border-color: rgba(255, 255, 255, 0.08);
  color: #b4bccb;
}

.subdued-card strong {
  color: #c2cad8;
}

.subdued-card .metric-pill {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.1);
  color: #bfc7d6;
}

.prev-meta {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  align-items: center;
}

.prev-meta .metric-pill {
  text-align: center;
}

.prev-meta .metric-pill:first-child {
  text-align: left;
}

.prev-meta .metric-pill:last-child {
  text-align: right;
}

.pb-line {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto auto;
  align-items: center;
  gap: 10px;
}

.pb-line .pb-ex {
  color: #d6dae4;
  font-weight: var(--fw-semibold);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pb-line .pb-val,
.pb-line .pb-date {
  color: #c9cfdd;
  font-size: var(--fs-xs);
  white-space: nowrap;
}

.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(3, 5, 10, 0.62);
  z-index: 30;
  padding: 18px;
}

.overlay-card {
  width: min(420px, 100%);
  background: var(--card);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 16px;
  padding: 16px;
}

.overlay-card h3 {
  margin-bottom: 10px;
}

.overlay-card p + p {
  margin-top: 6px;
}

.overlay-card button {
  width: 100%;
  margin-top: 14px;
  padding-top: 12px;
  padding-bottom: 12px;
  font-size: var(--fs-sm);
}

#historyList .history-entry {
  margin-bottom: 8px;
}

.history-row {
  width: 100%;
  text-align: left;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.08);
  padding: 10px;
}

.history-details {
  margin-top: 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  padding-top: 10px;
}

.plan-box {
  max-height: 280px;
  overflow: auto;
  background: #10131b;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  padding: 10px;
  white-space: pre-wrap;
  color: #d8dce8;
}

textarea {
  width: 100%;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: #0f1218;
  color: #eceff8;
  border-radius: 10px;
  padding: 10px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

textarea::placeholder {
  color: #778093;
}

input[type="number"] {
  flex: 1;
  min-width: 110px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: #0f1218;
  color: #eceff8;
  border-radius: 999px;
  padding: 10px 12px;
  font-size: var(--fs-sm);
}

.action-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.action-row.hidden {
  display: none !important;
}

.action-row button {
  width: 100%;
  padding-top: 12px;
  padding-bottom: 12px;
  font-size: var(--fs-sm);
}

.detail-grid {
  display: grid;
  gap: 8px;
}

.detail-metrics {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.metric-pill {
  border-radius: 999px;
  padding: 6px 10px;
  font-size: var(--fs-xs);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.warn-pill {
  background: rgba(59, 130, 246, 0.2);
  border-color: rgba(59, 130, 246, 0.45);
  color: #dbeafe;
}
