:root {
  --bg: #0f141b;
  --bg-2: #151c25;
  --surface: #1a222d;
  --surface-2: #212b37;
  --line: #2c3947;
  --text: #f2f5f7;
  --muted: #96a4b3;
  --accent: #c8f04d;
  --accent-ink: #17200a;
  --coral: #ff6b4a;
  --cyan: #43c8e8;
  --yellow: #ffd166;
  --danger: #ff5d5d;
  --radius: 8px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.28);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Segoe UI", sans-serif;
  line-height: 1.45;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

button {
  font: inherit;
  color: inherit;
  border: 0;
  cursor: pointer;
  touch-action: manipulation;
}

button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

img {
  display: block;
  max-width: 100%;
}

.hidden {
  display: none !important;
}

#app {
  max-width: 640px;
  margin: 0 auto;
  min-height: 100dvh;
}

#topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 640px;
  margin: 0 auto;
  padding: calc(10px + var(--safe-top)) 16px 10px;
  background: rgba(15, 20, 27, 0.94);
  border-bottom: 1px solid rgba(44, 57, 71, 0.6);
  backdrop-filter: blur(14px);
}

#brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 16px;
  font-weight: 900;
  letter-spacing: 0;
}

#brand h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 800;
  letter-spacing: 0;
}

#brand-sub {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
}

.streak-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 38px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--yellow);
  font-weight: 800;
}

.streak-chip svg {
  width: 17px;
  height: 17px;
}

#view {
  padding: calc(74px + var(--safe-top)) 16px calc(84px + var(--safe-bottom));
}

#tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  max-width: 640px;
  margin: 0 auto;
  padding: 6px 8px calc(6px + var(--safe-bottom));
  background: rgba(15, 20, 27, 0.95);
  border-top: 1px solid rgba(44, 57, 71, 0.7);
  backdrop-filter: blur(14px);
}

.tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  min-height: 52px;
  padding: 6px 4px;
  border-radius: var(--radius);
  background: transparent;
  color: var(--muted);
  font-size: 11px;
}

.tab svg {
  width: 22px;
  height: 22px;
}

.tab.active {
  color: var(--accent);
  background: rgba(200, 240, 77, 0.08);
}

.view-title {
  margin: 4px 0 14px;
  font-size: 26px;
  font-weight: 900;
  letter-spacing: 0;
}

.view-sub {
  margin: -8px 0 16px;
  color: var(--muted);
  font-size: 14px;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 22px 0 10px;
}

.section-head h2 {
  margin: 0;
  font-size: 17px;
  font-weight: 800;
  letter-spacing: 0;
}

.section-head button {
  background: transparent;
  color: var(--cyan);
  font-size: 13px;
  font-weight: 700;
}

.primary-btn,
.secondary-btn,
.ghost-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 0 18px;
  border-radius: var(--radius);
  font-weight: 800;
  font-size: 15px;
}

.primary-btn {
  background: var(--accent);
  color: var(--accent-ink);
  box-shadow: 0 8px 22px rgba(200, 240, 77, 0.18);
}

.primary-btn svg,
.secondary-btn svg,
.ghost-btn svg {
  width: 19px;
  height: 19px;
}

.secondary-btn {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--line);
}

.ghost-btn {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
}

.block {
  width: 100%;
}

.today-band {
  position: relative;
  padding: 20px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--line);
  overflow: hidden;
}

.today-band::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 4px;
  background: var(--accent);
}

.today-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.day-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
}

.day-label svg {
  width: 16px;
  height: 16px;
}

.today-band h2 {
  margin: 0;
  font-size: 24px;
  font-weight: 900;
  letter-spacing: 0;
}

.today-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 14px 0 18px;
}

.meta-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.meta-pill svg {
  width: 14px;
  height: 14px;
}

.intensity-high {
  color: var(--coral);
}

.intensity-low {
  color: var(--cyan);
}

.week-strip {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
  margin-top: 14px;
}

.week-day {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-height: 56px;
  padding: 6px 2px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 11px;
}

.week-day .wd-num {
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: var(--surface-2);
  font-weight: 800;
}

.week-day.active {
  border-color: var(--accent);
  color: var(--text);
}

.week-day.active .wd-num {
  background: var(--accent);
  color: var(--accent-ink);
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 16px 0;
}

.stat-tile {
  min-height: 86px;
  padding: 12px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--line);
}

.stat-tile strong {
  display: block;
  font-size: 24px;
  font-weight: 900;
  letter-spacing: 0;
  color: var(--accent);
}

.stat-tile span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.workout-card {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 92px;
  margin-bottom: 10px;
  padding: 14px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--line);
  text-align: left;
}

.workout-card .day-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--accent);
  font-weight: 900;
}

.workout-card h3 {
  margin: 6px 0 3px;
  font-size: 16px;
  font-weight: 800;
  letter-spacing: 0;
}

.workout-card p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.workout-card .go {
  color: var(--muted);
}

.workout-card .go svg {
  width: 20px;
  height: 20px;
}

.workout-detail-head {
  padding: 2px 0 16px;
}

.back-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
  color: var(--muted);
  background: transparent;
  font-size: 14px;
  font-weight: 700;
}

.back-row svg {
  width: 18px;
  height: 18px;
}

.workout-detail-head h2 {
  margin: 0;
  font-size: 25px;
  font-weight: 900;
  letter-spacing: 0;
}

.workout-detail-head p {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.detail-list {
  margin-top: 8px;
}

.detail-item {
  display: grid;
  grid-template-columns: 88px 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.detail-item .thumb {
  width: 88px;
  aspect-ratio: 1;
  border-radius: var(--radius);
  object-fit: cover;
  background: var(--surface-2);
}

.detail-item h4 {
  margin: 0 0 3px;
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0;
}

.detail-item p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.detail-index {
  color: var(--muted);
  font-weight: 800;
}

.library-tools {
  position: sticky;
  top: calc(70px + var(--safe-top));
  z-index: 5;
  display: flex;
  gap: 8px;
  padding: 8px 0 10px;
  background: rgba(15, 20, 27, 0.92);
  backdrop-filter: blur(10px);
}

.search-box {
  position: relative;
  flex: 1;
}

.search-box svg {
  position: absolute;
  left: 12px;
  top: 50%;
  width: 17px;
  height: 17px;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
}

.search-box input {
  width: 100%;
  height: 46px;
  padding: 0 14px 0 38px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

.search-box input::placeholder {
  color: var(--muted);
}

.filter-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 2px 0 10px;
  scrollbar-width: none;
}

.filter-row::-webkit-scrollbar {
  display: none;
}

.filter-chip {
  flex: 0 0 auto;
  min-height: 34px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.filter-chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

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

.exercise-card {
  position: relative;
  overflow: hidden;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--line);
  text-align: left;
  cursor: pointer;
}

.exercise-card .media {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  background: var(--surface-2);
}

.media.fallback,
.thumb.fallback,
.sheet-media.fallback {
  opacity: 0.35;
}

.exercise-card .card-body {
  padding: 10px;
}

.exercise-card h3 {
  margin: 0;
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0;
}

.exercise-card p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.fav-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 999px;
  background: rgba(15, 20, 27, 0.72);
  color: var(--muted);
}

.fav-btn.active {
  color: var(--yellow);
}

.fav-btn svg {
  width: 17px;
  height: 17px;
}

.level-dots {
  display: flex;
  gap: 3px;
  margin-top: 6px;
}

.level-dots i {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: var(--line);
}

.level-dots i.on {
  background: var(--accent);
}

.empty-state {
  padding: 40px 20px;
  text-align: center;
  color: var(--muted);
}

.empty-state svg {
  width: 34px;
  height: 34px;
  margin: 0 auto 10px;
  color: var(--line);
}

.me-list {
  border-radius: var(--radius);
  overflow: hidden;
}

.me-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  min-height: 56px;
  padding: 0 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  text-align: left;
}

.me-row:last-child {
  border-bottom: 0;
}

.me-row .label {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  font-weight: 700;
}

.me-row .label svg {
  width: 18px;
  height: 18px;
  color: var(--cyan);
}

.me-row .value {
  color: var(--muted);
  font-size: 13px;
}

.segmented {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}

.segmented button {
  min-width: 52px;
  min-height: 40px;
  padding: 0 12px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.segmented button.active {
  background: var(--accent);
  color: var(--accent-ink);
}

.toggle {
  position: relative;
  width: 48px;
  height: 28px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--line);
}

.toggle::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 999px;
  background: var(--muted);
  transition: transform 0.15s ease, background 0.15s ease;
}

.toggle.on {
  background: var(--accent);
}

.toggle.on::after {
  transform: translateX(20px);
  background: var(--accent-ink);
}

.danger-text {
  color: var(--danger);
}

#sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(0, 0, 0, 0.6);
}

#sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 41;
  max-width: 640px;
  max-height: 88dvh;
  margin: 0 auto;
  padding: 18px 16px calc(18px + var(--safe-bottom));
  border-radius: 12px 12px 0 0;
  background: var(--surface);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.sheet-grab {
  width: 40px;
  height: 4px;
  margin: 0 auto 14px;
  border-radius: 999px;
  background: var(--line);
}

.sheet-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.sheet-head h2 {
  margin: 0;
  font-size: 21px;
  font-weight: 900;
  letter-spacing: 0;
}

.sheet-close {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
}

.sheet-close svg {
  width: 18px;
  height: 18px;
}

.sheet-media {
  width: 100%;
  aspect-ratio: 1;
  max-height: 340px;
  margin: 0 auto 14px;
  border-radius: var(--radius);
  object-fit: contain;
  background: var(--bg-2);
}

.step-list {
  margin: 12px 0 0;
  padding: 0;
  list-style: none;
  counter-reset: step;
}

.step-list li {
  position: relative;
  padding: 8px 0 8px 30px;
  border-bottom: 1px solid var(--line);
  color: var(--text);
  font-size: 14px;
  counter-increment: step;
}

.step-list li::before {
  content: counter(step);
  position: absolute;
  left: 0;
  top: 8px;
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--accent);
  font-size: 11px;
  font-weight: 800;
}

.tip-box {
  margin-top: 14px;
  padding: 12px;
  border-radius: var(--radius);
  background: rgba(200, 240, 77, 0.1);
  border: 1px solid rgba(200, 240, 77, 0.35);
  color: var(--accent);
  font-size: 13px;
}

.player {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.player-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(10px + var(--safe-top)) 16px 10px;
}

.player-head .phase-label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.player-head .close-player {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
}

.player-head .close-player svg {
  width: 19px;
  height: 19px;
}

.progress-wrap {
  padding: 0 16px;
}

.progress-track {
  height: 8px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: var(--accent);
  transition: width 0.2s linear;
}

.round-dots {
  display: flex;
  gap: 4px;
  padding: 12px 16px 6px;
  overflow-x: auto;
  scrollbar-width: none;
}

.round-dots::-webkit-scrollbar {
  display: none;
}

.round-dot {
  flex: 0 0 8px;
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--surface-2);
}

.round-dot.done {
  background: var(--accent);
}

.round-dot.current {
  background: var(--coral);
  transform: scale(1.3);
}

.player-stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 12px 16px 16px;
  min-height: 0;
}

.timer {
  font-size: 52px;
  font-weight: 900;
  letter-spacing: 0;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.timer.resting {
  color: var(--cyan);
}

.ex-name {
  margin: 10px 0 2px;
  font-size: 20px;
  font-weight: 900;
  letter-spacing: 0;
  text-align: center;
}

.ex-note {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.player-media-wrap {
  width: min(72vw, 300px);
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  margin: 12px auto;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--line);
  overflow: hidden;
}

.player-media {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.player-media.fallback {
  object-fit: cover;
  opacity: 0.35;
}

.step-preview {
  width: 100%;
  max-width: 360px;
  max-height: 58px;
  overflow: hidden;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.step-preview p {
  margin: 0;
}

.player-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 10px 16px calc(16px + var(--safe-bottom));
}

.player-actions.three {
  grid-template-columns: 1fr 1fr 1fr;
}

.finish-overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 24px;
  background: var(--bg);
  text-align: center;
}

.finish-overlay .big {
  font-size: 42px;
  font-weight: 900;
  letter-spacing: 0;
}

.finish-overlay .sub {
  color: var(--muted);
  font-size: 15px;
}

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(92px + var(--safe-bottom));
  z-index: 60;
  max-width: min(86vw, 420px);
  padding: 10px 16px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
  box-shadow: var(--shadow);
  transform: translateX(-50%);
}

.attribution {
  margin-top: 26px;
  color: var(--muted);
  font-size: 11px;
  text-align: center;
  line-height: 1.6;
}

@media (min-width: 640px) {
  #app {
    border-left: 1px solid var(--line);
    border-right: 1px solid var(--line);
  }

  #topbar {
    border-left: 1px solid var(--line);
    border-right: 1px solid var(--line);
  }

  #tabbar {
    border-left: 1px solid var(--line);
    border-right: 1px solid var(--line);
  }

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

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
}
