:root {
  --bg: #f3f6fb;
  --card: #ffffff;
  --text: #101827;
  --muted: #667085;
  --dark: #050816;
  --line: #e5e7eb;
  --soft: #f8fafc;
  --soft2: #eef2f7;
  --green: #166534;
  --red: #991b1b;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

a { color: inherit; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(243,246,251,.92);
  backdrop-filter: blur(10px);
  padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand {
  text-decoration: none;
  background: var(--dark);
  color: white;
  padding: 10px 13px;
  border-radius: 16px;
  font-weight: 900;
}

.topbar nav { display: flex; gap: 7px; flex-wrap: wrap; justify-content: flex-end; }
.topbar nav a {
  text-decoration: none;
  background: white;
  border: 1px solid var(--line);
  padding: 9px 11px;
  border-radius: 13px;
  font-size: 14px;
  font-weight: 800;
}

.container {
  width: min(1060px, 100%);
  margin: 0 auto;
  padding: 14px 14px 90px;
}

.footer {
  text-align: center;
  padding: 20px;
  color: var(--muted);
  font-size: 12px;
}

.hero, .workout-top {
  background: var(--dark);
  color: white;
  border-radius: 28px;
  padding: 24px;
  box-shadow: 0 16px 36px rgba(16,24,39,.18);
  margin-bottom: 14px;
}

.hero h1, .workout-top h1 {
  font-size: clamp(32px, 8vw, 64px);
  line-height: .95;
  margin: 6px 0 10px;
  letter-spacing: -0.05em;
}

.hero p, .workout-top p { color: #cbd5e1; }

.eyebrow {
  color: #94a3b8 !important;
  font-size: 12px;
  font-weight: 900;
  letter-spacing: .25em;
  text-transform: uppercase;
}

.hero-actions, .pill-row, .nav-row, .timer-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 16px;
}

.card, .auth-card, .timer-card {
  background: white;
  border-radius: 24px;
  padding: 18px;
  margin-bottom: 14px;
  box-shadow: 0 8px 28px rgba(16,24,39,.06);
}

.auth-card { margin-top: 16px; }
.auth-card.wide { max-width: 820px; }

h1, h2, h3 { letter-spacing: -0.03em; }
h1, h2 { margin-top: 0; }
h2 { font-size: 22px; }

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

.stack { display: grid; gap: 13px; }

.grid2, .cards3 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.cards3 { grid-template-columns: repeat(3, 1fr); }

.compact span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 5px;
}

.compact strong { font-size: 20px; }

label {
  display: grid;
  gap: 7px;
  color: #344054;
  font-weight: 850;
}

input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: #f9fafb;
  color: var(--text);
  border-radius: 16px;
  padding: 15px 14px;
  font: inherit;
  font-size: 16px;
  outline: none;
}

input:focus, select:focus, textarea:focus {
  border-color: #111827;
  box-shadow: 0 0 0 3px rgba(17,24,39,.12);
}

.btn {
  appearance: none;
  border: 0;
  border-radius: 16px;
  padding: 14px 18px;
  text-decoration: none;
  font-weight: 950;
  text-align: center;
  cursor: pointer;
  display: inline-flex;
  justify-content: center;
  align-items: center;
}

.btn.primary { background: var(--dark); color: white; }
.btn.secondary { background: #eef2f7; color: var(--text); }
.btn.danger, .danger { background: #fee2e2; color: var(--red); }
.btn.big { width: 100%; font-size: 20px; padding: 18px; }

.success {
  background: #dcfce7;
  color: var(--green);
  padding: 13px;
  border-radius: 16px;
  font-weight: 800;
  margin-bottom: 14px;
}

.alert {
  background: #fee2e2;
  color: var(--red);
  padding: 13px;
  border-radius: 16px;
  font-weight: 800;
  margin-bottom: 14px;
}

.pill {
  background: rgba(255,255,255,.12);
  color: inherit;
  border: 1px solid rgba(255,255,255,.16);
  padding: 9px 12px;
  border-radius: 999px;
  font-weight: 850;
  font-size: 14px;
}

.card .pill {
  background: #f3f4f6;
  color: var(--text);
  border-color: var(--line);
}

.small-link {
  color: #cbd5e1;
  font-weight: 850;
  text-decoration: none;
}

/* Exercise demo area */
.exercise-hero {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(260px, 360px);
  gap: 22px;
  align-items: center;
}

.exercise-hero-text { min-width: 0; }

.exercise-hero-media {
  min-height: 240px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.exercise-demo {
  width: 100%;
  max-width: 340px;
  aspect-ratio: 1 / 1;
  object-fit: contain;
  border-radius: 24px;
  background: rgba(255,255,255,.06);
  border: 1px solid rgba(255,255,255,.12);
  padding: 8px;
}

.exercise-placeholder {
  width: 100%;
  max-width: 340px;
  aspect-ratio: 1 / 1;
  border-radius: 24px;
  background: rgba(255,255,255,.06);
  border: 1px dashed rgba(255,255,255,.22);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  color: #cbd5e1;
  text-align: center;
  padding: 18px;
}

.exercise-placeholder strong {
  color: #ffffff;
  font-size: 18px;
}

.exercise-placeholder span {
  font-size: 12px;
  opacity: .75;
  word-break: break-all;
}

.timer-card {
  background: #111827;
  color: white;
  text-align: center;
  position: sticky;
  top: 74px;
  z-index: 9;
}

#timerDisplay {
  font-size: clamp(54px, 18vw, 92px);
  line-height: 1;
  font-weight: 1000;
  letter-spacing: -0.07em;
  margin: 6px 0 10px;
}

.hidden { display: none !important; }

.set-form input {
  font-size: 22px;
  font-weight: 900;
  text-align: center;
}

.set-row, .log-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}

.set-row:last-child, .log-row:last-child { border-bottom: 0; }

.set-row span, .log-row span {
  color: var(--muted);
  font-weight: 700;
}

.flash { animation: flash .8s ease; }

@keyframes flash {
  0% { background: #dcfce7; }
  100% { background: transparent; }
}

ul { padding-left: 20px; }

/* Plan page UI */
.plan-hero {
  margin-bottom: 18px;
}

.plan-settings-card,
.add-workout-card {
  border: 1px solid rgba(16,24,39,.04);
}

.large-summary {
  cursor: pointer;
  list-style: none;
  font-size: 22px;
  font-weight: 1000;
  letter-spacing: -0.03em;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.large-summary::-webkit-details-marker { display: none; }

.large-summary::after {
  content: "+";
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 12px;
  background: var(--soft2);
  font-size: 24px;
  line-height: 1;
}

details[open] > .large-summary::after {
  content: "–";
}

.plan-form-space {
  margin-top: 16px;
}

.plan-day-grid {
  display: grid;
  gap: 18px;
}

.plan-day-card {
  padding: 22px;
  border: 1px solid rgba(16,24,39,.04);
}

.plan-day-header {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 12px;
}

.day-badge {
  width: 54px;
  height: 54px;
  border-radius: 18px;
  background: var(--dark);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  font-weight: 1000;
  flex: 0 0 auto;
}

.mini-label {
  margin: 0 0 2px;
  text-transform: uppercase;
  font-size: 12px;
  letter-spacing: .18em;
  color: var(--muted);
  font-weight: 900;
}

.plan-day-header h2 {
  margin: 0;
  font-size: clamp(24px, 3vw, 34px);
}

.plan-day-notes {
  color: #53627c;
  background: var(--soft);
  border: 1px solid var(--line);
  padding: 14px;
  border-radius: 18px;
  line-height: 1.5;
}

.editor-box,
.exercise-card {
  border: 1px solid var(--line);
  border-radius: 18px;
  background: #fbfdff;
  margin: 12px 0;
  overflow: hidden;
}

.editor-box > summary {
  cursor: pointer;
  padding: 15px 16px;
  font-weight: 950;
  list-style: none;
}

.editor-box > summary::-webkit-details-marker { display: none; }

.editor-box > summary::before {
  content: "›";
  display: inline-block;
  margin-right: 8px;
  transform: rotate(0deg);
  transition: transform .15s ease;
}

.editor-box[open] > summary::before {
  transform: rotate(90deg);
}

.editor-box form,
.exercise-edit-form {
  padding: 0 16px 16px;
}

.exercise-card-list {
  display: grid;
  gap: 10px;
  margin: 16px 0;
}

.exercise-card {
  margin: 0;
  background: #ffffff;
}

.exercise-card-summary {
  cursor: pointer;
  list-style: none;
  padding: 14px;
  display: grid;
  grid-template-columns: 42px 1fr;
  gap: 12px;
  align-items: center;
}

.exercise-card-summary::-webkit-details-marker { display: none; }

.exercise-number {
  width: 42px;
  height: 42px;
  border-radius: 14px;
  background: var(--soft2);
  color: #111827;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 1000;
}

.exercise-main {
  min-width: 0;
}

.exercise-main strong {
  display: block;
  font-size: 18px;
  line-height: 1.2;
}

.exercise-main span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 800;
}

.exercise-note {
  margin: -2px 14px 14px 68px;
  color: #64748b;
  font-size: 14px;
  line-height: 1.45;
}

.exercise-edit-form {
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.delete-form {
  padding: 0 16px 16px;
  margin-top: 0;
}

.workout-delete-form {
  padding: 0;
  margin-top: 14px;
}

.add-exercise-box {
  background: #f8fafc;
}

.section-head {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: flex-start;
}

@media (max-width: 900px) {
  .container { width: min(820px, 100%); }

  .exercise-hero {
    grid-template-columns: 1fr;
  }

  .exercise-hero-media {
    min-height: auto;
    order: -1;
  }

  .exercise-demo,
  .exercise-placeholder {
    max-width: 240px;
  }

  .workout-top h1 {
    font-size: clamp(34px, 11vw, 56px);
  }
}

@media (max-width: 700px) {
  .cards3 { grid-template-columns: 1fr; }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
    gap: 8px;
  }

  .topbar nav {
    width: 100%;
    justify-content: flex-start;
  }

  .plan-day-card {
    padding: 16px;
  }

  .plan-day-header {
    align-items: flex-start;
  }

  .day-badge {
    width: 46px;
    height: 46px;
    border-radius: 15px;
    font-size: 20px;
  }

  .exercise-note {
    margin-left: 14px;
  }
}

@media (max-width: 520px) {
  .grid2 { grid-template-columns: 1fr 1fr; }

  .topbar nav a {
    font-size: 12px;
    padding: 8px;
  }

  .hero, .workout-top {
    border-radius: 24px;
    padding: 20px;
  }

  .exercise-demo,
  .exercise-placeholder {
    max-width: 220px;
  }

  .exercise-card-summary {
    grid-template-columns: 36px 1fr;
    padding: 12px;
  }

  .exercise-number {
    width: 36px;
    height: 36px;
    border-radius: 12px;
  }

  .exercise-main strong {
    font-size: 16px;
  }

  .exercise-main span {
    font-size: 13px;
  }
}

@media (max-width: 390px) {
  .grid2 { grid-template-columns: 1fr; }
}
