:root {
  --bg: #0a0a0a;
  --bg-surface: #141414;
  --bg-elevated: #1d1d1d;
  --bg-soft: #111827;

  --text: #ffffff;
  --text-secondary: #a3a3a3;
  --text-muted: #737373;

  --amber: #4ade80;
  --amber-light: #86efac;
  --amber-soft: rgba(74, 222, 128, 0.16);
  --purple: #a855f7;
  --purple-soft: rgba(168, 85, 247, 0.18);
  --green: #4ade80;
  --green-soft: rgba(74, 222, 128, 0.2);

  --border: rgba(255, 255, 255, 0.12);
  --border-strong: rgba(255, 255, 255, 0.2);

  --radius-xl: 24px;
  --radius-lg: 18px;
  --radius-md: 14px;
  --radius-sm: 10px;

  --shadow-soft: 0 20px 50px rgba(0, 0, 0, 0.35);
  --shadow-glow: 0 12px 40px rgba(245, 158, 11, 0.25);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  min-height: 100%;
}

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

/* ── Background ── */

.bg-gradient {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(1200px 520px at 50% -12%, rgba(245, 158, 11, 0.28), transparent 65%),
    radial-gradient(800px 450px at 85% 10%, rgba(168, 85, 247, 0.18), transparent 70%);
  pointer-events: none;
  z-index: -2;
}

.bg-noise {
  position: fixed;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 220 220' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.82' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  opacity: 0.035;
  pointer-events: none;
  z-index: -1;
}

/* ── Topbar ── */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  background: rgba(10, 10, 10, 0.72);
}

.topbar-inner {
  max-width: 1320px;
  margin: 0 auto;
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand {
  text-decoration: none;
  color: var(--text);
  font-size: 1.45rem;
  font-weight: 900;
  letter-spacing: -0.03em;
  flex-shrink: 0;
}

.brand-accent {
  color: var(--amber);
}

.topbar-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.auth-row {
  display: flex;
  gap: 6px;
  align-items: center;
}

.auth-row input {
  width: 180px;
  padding: 8px 10px;
  font-size: 0.82rem;
}

.auth-state {
  font-size: 0.78rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.local-hint {
  text-align: center;
  font-size: 0.85rem;
  color: #fcd34d;
  margin: 0 0 8px;
}

/* ── Page ── */

.page {
  max-width: 1320px;
  margin: 0 auto;
  padding: 0 24px 60px;
}

/* ── Hero ── */

.hero {
  text-align: center;
  padding: 60px 0 40px;
}

.hero h1 {
  margin: 0;
  font-size: clamp(2.2rem, 5vw, 3.6rem);
  line-height: 1.05;
  letter-spacing: -0.04em;
  font-weight: 900;
}

.highlight {
  background: linear-gradient(135deg, var(--amber), var(--amber-light));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.hero-sub {
  color: var(--text-secondary);
  font-size: clamp(1rem, 2.4vw, 1.2rem);
  margin: 16px auto 0;
  max-width: 520px;
  line-height: 1.5;
}

.status {
  min-height: 20px;
  margin: 12px 0 0;
  font-weight: 600;
  font-size: 0.88rem;
  color: var(--green);
}

/* ── Builder Layout (side-by-side) ── */

.builder-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 32px;
  align-items: start;
}

.builder-panel {
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0.02));
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 20px;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.catalog-scroll {
  max-height: 60vh;
  overflow-y: auto;
  display: grid;
  gap: 10px;
  padding-right: 4px;
}

.catalog-scroll::-webkit-scrollbar {
  width: 6px;
}

.catalog-scroll::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.16);
  border-radius: 999px;
}

/* ── Step Sections ── */

.step-section {
  margin-bottom: 32px;
}

.step-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}

.step-number {
  display: inline-flex;
  width: 32px;
  height: 32px;
  border-radius: 10px;
  align-items: center;
  justify-content: center;
  background: var(--amber-soft);
  color: var(--amber);
  font-weight: 800;
  font-size: 0.9rem;
  flex-shrink: 0;
}

h2 {
  margin: 0;
  font-size: 1.2rem;
  letter-spacing: -0.02em;
  font-weight: 700;
}

h3 {
  margin: 0;
  font-size: 1.02rem;
  letter-spacing: -0.02em;
}

/* ── Config Row ── */

.config-row {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  align-items: flex-end;
}

.config-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.config-field-grow {
  flex: 1;
  min-width: 180px;
}

.config-field-sm {
  min-width: 100px;
}

.config-field > label {
  font-size: 0.82rem;
  color: var(--text-secondary);
  font-weight: 600;
}

/* ── Pills (Workout Type) ── */

.pill-group {
  display: flex;
  gap: 4px;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 3px;
}

.pill {
  border: none;
  background: transparent;
  color: var(--text-secondary);
  padding: 7px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.84rem;
  font-weight: 600;
  transition: all 0.15s ease;
}

.pill.active {
  background: linear-gradient(145deg, var(--amber) 0%, var(--amber-light) 100%);
  color: #000;
  box-shadow: 0 2px 8px rgba(245, 158, 11, 0.3);
}

.pill:not(.active):hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
}

/* ── Rest Chip ── */

.rest-chip {
  display: flex;
  align-items: center;
  gap: 6px;
}

.rest-chip input {
  width: 70px;
}

.rest-chip span {
  font-size: 0.82rem;
  color: var(--text-muted);
}

/* ── Inputs ── */

label {
  display: grid;
  gap: 6px;
  font-size: 0.84rem;
  color: var(--text-secondary);
  font-weight: 600;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: rgba(0, 0, 0, 0.3);
  color: var(--text);
  padding: 11px 12px;
  font-size: 0.94rem;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: rgba(245, 158, 11, 0.8);
  box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.18);
}

/* ── Filter Bar ── */

.filter-bar {
  display: flex;
  gap: 10px;
  margin-bottom: 14px;
  align-items: center;
}

.search-input {
  flex: 1;
}

/* ── Chip Filters ── */

.chip-filters {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 18px;
}

.chip-group {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.chip-label {
  font-size: 0.76rem;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-right: 4px;
}

.chip {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  padding: 5px 12px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 500;
  transition: all 0.15s ease;
}

.chip:hover {
  border-color: var(--border-strong);
  color: var(--text);
}

.chip.active {
  background: var(--amber-soft);
  border-color: var(--amber);
  color: var(--amber-light);
}

/* ── Exercise Grid ── */

.exercise-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

/* ── Exercise Card ── */

.exercise-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.07), rgba(255, 255, 255, 0.02));
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.exercise-card:hover {
  transform: translateY(-4px);
  border-color: var(--border-strong);
  box-shadow: var(--shadow-soft);
}

.exercise-card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}

.exercise-card h4 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 700;
  line-height: 1.3;
}

.exercise-card-meta {
  color: var(--text-muted);
  font-size: 0.78rem;
  line-height: 1.4;
}

.exercise-card-source {
  display: inline-block;
  padding: 2px 8px;
  font-size: 0.68rem;
  font-weight: 600;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.36);
  border: 1px solid var(--border);
}

.exercise-card-source.community {
  background: var(--purple-soft);
  border-color: rgba(168, 85, 247, 0.4);
}

.add-btn {
  width: 36px;
  height: 36px;
  min-width: 36px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.3);
  color: var(--amber);
  font-size: 1.2rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}

.add-btn:hover {
  background: var(--amber);
  color: #000;
  border-color: var(--amber);
}

.vote-row {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.vote-score {
  font-size: 0.76rem;
  color: var(--text-muted);
}

/* ── Workout List ── */

.workout-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 12px;
  padding-bottom: 12px;
  max-height: 60vh;
  overflow-y: auto;
  padding-right: 4px;
}

.workout-list::-webkit-scrollbar {
  width: 6px;
}

.workout-list::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.16);
  border-radius: 999px;
}

.workout-item {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.07), rgba(255, 255, 255, 0.02));
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.workout-item.dragging {
  opacity: 0.5;
}

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

.workout-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
}

.workout-sub {
  margin: 2px 0 0;
  color: var(--text-secondary);
  font-size: 0.82rem;
}

.group-badge {
  display: inline-block;
  margin-top: 6px;
  font-size: 0.72rem;
  color: #000;
  background: var(--purple);
  border-radius: 999px;
  padding: 3px 8px;
  font-weight: 600;
}

.item-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.set-list {
  margin-top: 10px;
  display: grid;
  gap: 6px;
}

.set-row-header {
  display: grid;
  grid-template-columns: 40px 1fr 1fr 1fr auto;
  gap: 6px;
  font-size: 0.72rem;
  color: var(--text-muted);
  font-weight: 600;
  padding: 0 0 2px;
}

.set-row {
  display: grid;
  grid-template-columns: 40px 1fr 1fr 1fr auto;
  gap: 6px;
  align-items: center;
}

.notes {
  margin-top: 8px;
}

/* ── Workout Actions ── */

.workout-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

/* ── Empty State ── */

.empty-state {
  text-align: center;
  padding: 32px 20px;
  color: var(--text-muted);
  font-size: 0.92rem;
  line-height: 1.5;
  grid-column: 1 / -1;
}

/* ── Count Badge ── */

.count {
  display: inline-flex;
  width: 28px;
  height: 28px;
  border-radius: 999px;
  align-items: center;
  justify-content: center;
  background: var(--amber);
  color: #000;
  font-weight: 800;
  font-size: 0.82rem;
  box-shadow: var(--shadow-glow);
  margin-left: auto;
}

/* ── Buttons ── */

.btn {
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 11px 20px;
  cursor: pointer;
  font-weight: 700;
  font-size: 0.88rem;
  transition: transform 0.16s ease, box-shadow 0.16s ease, border-color 0.16s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn-primary {
  background: linear-gradient(145deg, var(--amber) 0%, var(--amber-light) 100%);
  color: #000;
  box-shadow: var(--shadow-glow);
}

.btn-primary:hover {
  box-shadow: 0 16px 45px rgba(245, 158, 11, 0.35);
}

.btn-secondary {
  background: rgba(0, 0, 0, 0.32);
  color: var(--text);
  border-color: var(--border);
}

.btn-secondary:hover {
  border-color: var(--border-strong);
}

.btn-sm {
  padding: 7px 12px;
  font-size: 0.82rem;
  border-radius: 10px;
}

.btn-ghost {
  background: rgba(0, 0, 0, 0.2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 8px;
  cursor: pointer;
  font-size: 0.82rem;
}

.btn-danger {
  background: rgba(239, 68, 68, 0.16);
  border: 1px solid rgba(239, 68, 68, 0.44);
  color: #fecaca;
  border-radius: 8px;
  padding: 6px 8px;
  cursor: pointer;
  font-size: 0.82rem;
}

/* ── Modals ── */

.modal {
  position: fixed;
  inset: 0;
  display: none;
  background: rgba(0, 0, 0, 0.62);
  z-index: 30;
}

.modal.open {
  display: grid;
  place-items: center;
}

.modal-card {
  width: min(760px, calc(100vw - 24px));
  max-height: calc(100vh - 24px);
  overflow: auto;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 20px;
  box-shadow: var(--shadow-soft);
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.icon-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  width: 32px;
  height: 32px;
  cursor: pointer;
}

.modal-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px 12px;
  margin-top: 10px;
}

.form-full {
  grid-column: 1 / -1;
}

.form-half {
  grid-column: span 1;
}

.check-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 2px;
  max-height: 140px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  background: rgba(0, 0, 0, 0.24);
}

.check-item {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.9rem;
  color: var(--text);
  font-weight: 500;
  padding: 6px 2px;
}

.check-item input[type="checkbox"] {
  width: 16px;
  height: 16px;
  min-width: 16px;
  margin: 0;
  flex: 0 0 auto;
  accent-color: var(--amber);
}

.check-item span {
  line-height: 1.2;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* ── Magic Link Notice ── */

.magic-link-notice {
  margin: 20px auto 0;
  max-width: 480px;
  padding: 24px;
  background: linear-gradient(160deg, rgba(74, 222, 128, 0.14), rgba(74, 222, 128, 0.04));
  border: 1px solid rgba(74, 222, 128, 0.4);
  border-radius: var(--radius-xl);
  text-align: center;
  animation: fadeSlideIn 0.3s ease;
}

.magic-link-notice-icon {
  font-size: 2.4rem;
  margin-bottom: 8px;
}

.magic-link-notice-title {
  margin: 0 0 8px;
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--green);
}

.magic-link-notice-text {
  margin: 0 0 16px;
  font-size: 0.92rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

.magic-link-notice-text strong {
  color: var(--text);
}

@keyframes fadeSlideIn {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ── Responsive ── */

@media (max-width: 980px) {
  .builder-layout {
    grid-template-columns: 1fr;
  }

  .catalog-scroll {
    max-height: none;
  }

  .workout-list {
    max-height: none;
  }
}

@media (max-width: 640px) {
  .topbar-inner {
    flex-wrap: wrap;
  }

  .auth-row input {
    width: 140px;
  }

  .config-row {
    flex-direction: column;
  }

  .config-field-grow {
    min-width: 0;
    width: 100%;
  }

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

  .filter-bar {
    flex-direction: column;
  }

  .set-row-header {
    grid-template-columns: 30px 1fr 1fr 1fr auto;
  }

  .set-row {
    grid-template-columns: 30px 1fr 1fr 1fr auto;
  }

  .modal-form {
    grid-template-columns: 1fr;
  }

  .form-half,
  .form-full {
    grid-column: 1 / -1;
  }

  .hero {
    padding: 40px 0 24px;
  }

  .workout-actions {
    flex-direction: column;
  }

  .workout-actions .btn {
    width: 100%;
  }
}
