:root {
  --bg: #f8fbff;
  --text: #172034;
  --card: #ffffff;
  --muted: #5f6f8d;
  --primary: #ff5f6d;
  --primary-2: #ffc371;
  --success: #16a34a;
  --warn: #f59e0b;
  --rest: #6366f1;
  --pending: #d7deea;
  --border: #e8edf7;
  --glow: rgba(255, 95, 109, .22);
}

body.dark {
  --bg: #090f1d;
  --text: #ebf2ff;
  --card: #111a2f;
  --muted: #94a3c2;
  --border: #263252;
  --pending: #314267;
  --primary: #ff6f91;
  --primary-2: #ffbf69;
  --glow: rgba(255, 111, 145, .3);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Inter, Segoe UI, system-ui, sans-serif;
  background:
    radial-gradient(circle at top right, rgba(255, 195, 113, .15), transparent 40%),
    radial-gradient(circle at top left, rgba(255, 95, 109, .14), transparent 35%),
    var(--bg);
  color: var(--text);
}

body.modal-open {
  overflow: hidden;
}

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: color-mix(in oklab, var(--card) 92%, #fff 8%);
  position: sticky;
  top: 0;
  z-index: 20;
}

h1, h2 { margin: 0; }
h1 { font-size: clamp(1rem, 2.5vw, 1.2rem); }
h2 { font-size: 1rem; margin-bottom: .75rem; }

.container {
  max-width: 900px;
  margin: 1rem auto;
  padding: 0 1rem 5.5rem;
  display: grid;
  gap: 1rem;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1rem;
  box-shadow: 0 10px 28px -22px var(--glow);
}

.row {
  display: flex;
  gap: .5rem;
  align-items: center;
  flex-wrap: wrap;
}
.row.between { justify-content: space-between; }

.btn {
  border: 0;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  color: #fff;
  border-radius: 10px;
  padding: .65rem .9rem;
  min-height: 44px;
  cursor: pointer;
  font-weight: 600;
}
.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}
.btn-success { background: linear-gradient(135deg, #22c55e, #16a34a); }
.btn-small { padding: .45rem .6rem; font-size: .85rem; }
.select, input[type="time"] {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  border-radius: 10px;
  padding: .45rem .6rem;
}

textarea {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  border-radius: 10px;
  padding: .55rem .65rem;
  width: 100%;
  resize: vertical;
}

.progress-wrap {
  width: 100%;
  height: 12px;
  border-radius: 999px;
  background: var(--pending);
  overflow: hidden;
}
.progress-bar {
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--primary-2));
  transition: width .25s ease;
}

.motivation-text {
  margin: 0 0 .75rem;
  color: var(--muted);
  font-weight: 600;
}

.badge-list {
  display: flex;
  gap: .45rem;
  flex-wrap: wrap;
  margin: .2rem 0 .85rem;
}

.badge-chip {
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: .28rem .55rem;
  font-size: .78rem;
  color: var(--text);
  background: color-mix(in oklab, var(--card) 86%, #fff 14%);
}

.badge-chip.empty {
  color: var(--muted);
}

.achievement-toast {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(1rem + env(safe-area-inset-bottom));
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  color: #fff;
  padding: .7rem 1rem;
  border-radius: 12px;
  box-shadow: 0 12px 26px -14px var(--glow);
  z-index: 60;
  font-weight: 600;
}

.workout-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: .6rem;
}

.section-content.is-hidden {
  display: none;
}
.workout-item {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: .65rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: .75rem;
}
.workout-item.done { border-color: #6ee7b7; }
.item-title { display: block; }
.item-sub {
  margin: .2rem 0 0;
  color: var(--muted);
  font-size: .9rem;
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(10, minmax(0, 1fr));
  gap: .4rem;
}
.day-cell {
  border: 1px solid var(--border);
  border-radius: 8px;
  text-align: center;
  padding: .4rem .2rem;
  font-size: .82rem;
  display: grid;
  gap: .1rem;
}
.day-cell small {
  font-size: .65rem;
  color: var(--muted);
}
.day-cell.complete { background: rgba(34, 197, 94, .2); }
.day-cell.cardio { background: rgba(245, 158, 11, .25); }
.day-cell.rest { background: rgba(99, 102, 241, .25); }
.day-cell.pending { background: transparent; }

.legend {
  margin-top: .75rem;
  display: flex;
  flex-wrap: wrap;
  gap: .9rem;
  color: var(--muted);
}
.dot {
  width: .75rem;
  height: .75rem;
  border-radius: 999px;
  display: inline-block;
}
.dot.complete { background: var(--success); }
.dot.cardio { background: var(--warn); }
.dot.rest { background: var(--rest); }
.dot.pending { background: var(--pending); }

.settings-grid {
  display: grid;
  gap: .75rem;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: .6rem;
  margin-bottom: .75rem;
}

.stat-box {
  margin: 0;
  padding: .65rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: color-mix(in oklab, var(--card) 90%, #fff 10%);
}

.stat-box p {
  margin: 0;
  color: var(--muted);
  font-size: .8rem;
}

.stat-box strong {
  font-size: 1.05rem;
}

#authStatus {
  color: var(--muted);
  margin-top: 0;
}

#reminderStatus {
  color: var(--muted);
  margin: 0;
}

#monthProgressText {
  color: var(--muted);
  margin: .6rem 0 0;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .55);
  display: grid;
  place-items: center;
  padding: 1rem;
  z-index: 40;
}

.modal[hidden] {
  display: none;
}

.modal-card {
  width: min(900px, 100%);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: .9rem;
}

.modal-head {
  margin-bottom: .75rem;
}

.video-wrap {
  position: relative;
  width: 100%;
  padding-top: 56.25%;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--border);
  margin-bottom: .75rem;
}

.video-wrap iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
}

.mobile-bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: none;
  gap: .5rem;
  padding: .6rem .75rem calc(.6rem + env(safe-area-inset-bottom));
  background: color-mix(in oklab, var(--card) 90%, #fff 10%);
  border-top: 1px solid var(--border);
  z-index: 35;
}

.nav-btn {
  flex: 1;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  border-radius: 10px;
  min-height: 42px;
  font-weight: 600;
}

.nav-btn.active {
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  color: #fff;
  border-color: transparent;
}

@media (max-width: 700px) {
  .app-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .container {
    margin: .75rem auto;
    padding: 0 .75rem 6.2rem;
  }

  .card {
    padding: .85rem;
    border-radius: 12px;
  }

  .row.between {
    align-items: flex-start;
    gap: .65rem;
  }

  .select {
    width: 100%;
  }

  .calendar-grid {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }

  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .workout-item {
    flex-direction: column;
    align-items: stretch;
  }

  .workout-item .row {
    justify-content: stretch;
  }

  .workout-item .btn {
    flex: 1;
  }

  .modal {
    padding: .5rem;
  }

  .modal-card {
    padding: .7rem;
  }

  .mobile-bottom-nav {
    display: flex;
  }
}
