/* 운동 스크랩북: 모바일 세로 화면 우선. 외부 폰트·CDN 없음. */
:root {
  --bg: #F7F5F0;
  --card: #fff;
  --ink: #1f2937;
  --sub: #6b7280;
  --line: #e5e1d8;
  --navy: #27325a;
  --navy-soft: #eef0f6;
  --coral: #FF6B5B;
  --coral-soft: #fff1ef;
  --warn: #b45309;
  --radius: 16px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --media-h: clamp(170px, 25dvh, 300px);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 16px/1.5 system-ui, -apple-system, "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", sans-serif;
  background: var(--bg); color: var(--ink);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--navy); }
button { font: inherit; color: inherit; }
.muted { color: var(--sub); }
.loading, .load-error { padding: 24px; }

/* ---------- 공통 버튼 */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
  min-height: 48px; padding: 0 14px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--card); color: var(--navy);
  font-weight: 600; text-decoration: none; cursor: pointer; white-space: nowrap;
}
.btn.primary { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn.wide { width: 100%; }
.btn:disabled, .btn.disabled { opacity: .4; pointer-events: none; }
.btn[hidden] { display: none; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 44px; height: 44px; border-radius: 50%; font-size: 30px; line-height: 1;
  text-decoration: none; color: var(--navy);
}

/* ---------- 안내 (i 버튼 팝오버) */
.info-btn {
  flex: none; width: 36px; height: 36px; padding: 0; border-radius: 50%;
  border: 1.5px solid var(--navy); background: var(--card); color: var(--navy);
  font: italic 700 18px/1 Georgia, "Times New Roman", serif; cursor: pointer;
}
.info-pop {
  width: min(420px, calc(100vw - 32px)); max-height: 80dvh; overflow: auto;
  margin: auto; padding: 18px; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--card); color: var(--ink); box-shadow: 0 10px 30px rgba(0,0,0,.18);
  font-size: 15px;
}
.info-pop::backdrop { background: rgba(0,0,0,.3); }
.info-pop h3 { margin: 14px 0 4px; font-size: 15px; color: var(--navy); }
.info-pop h3:first-child { margin-top: 0; }
.info-pop p { margin: 0; }
.info-pop .btn { margin-top: 16px; }

/* ---------- 칩 */
.chip {
  display: inline-flex; align-items: center; padding: 2px 10px; border-radius: 999px;
  font-size: 13px; font-weight: 600; background: var(--navy-soft); color: var(--navy); white-space: nowrap;
}
.chip.on { background: var(--navy); color: #fff; }
.chip.example { background: var(--coral-soft); color: #c2410c; }
.chip.alt { background: #f3f4f6; color: var(--sub); }

/* ---------- 홈 */
.home { max-width: 560px; margin: 0 auto; padding: calc(16px + var(--safe-t)) 16px calc(24px + var(--safe-b)); }
.home-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.home-top h1 { margin: 0; font-size: 26px; }
.topics { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.topic {
  display: flex; align-items: center; gap: 14px; padding: 16px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  color: inherit; text-decoration: none; min-height: 88px;
}
.topic:active { transform: scale(.99); }
.topic-emoji { font-size: 36px; line-height: 1; }
.topic-main { flex: 1; display: grid; gap: 6px; min-width: 0; }
.topic-title { font-size: 20px; font-weight: 700; }
.topic.done { border-color: var(--navy); }
.topic-done {
  flex: none; width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center;
  background: var(--navy); color: #fff; font-weight: 800;
}
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.stat {
  display: grid; gap: 2px; padding: 12px 14px; border-radius: var(--radius);
  background: var(--card); border: 1px solid var(--line);
}
.stat b { font-size: 28px; line-height: 1.1; color: var(--sub); }
.stat.on b { color: var(--navy); }
.stat span { font-size: 13px; color: var(--sub); }
.topic-eq { font-size: 13px; color: var(--sub); }
.topic-go { font-size: 28px; color: var(--sub); }

/* ---------- 플레이어 레이아웃: 상단 / 카드 트랙 / 하단(엄지 영역) */
.player {
  height: 100dvh; display: grid; grid-template-rows: auto 1fr auto;
  max-width: 560px; margin: 0 auto; overflow: hidden;
}
.p-top { padding: calc(6px + var(--safe-t)) 12px 8px; background: var(--bg); display: grid; gap: 8px; }
.p-row { display: flex; align-items: center; gap: 4px; }
.p-row h1 { flex: 1; margin: 0; font-size: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; padding: 4px; background: #ebe7de; border-radius: 12px; }
.seg button { min-height: 40px; border: 0; border-radius: 9px; background: transparent; color: var(--sub); cursor: pointer; }
.seg button.on { background: var(--card); color: var(--navy); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.seg b { font-size: 16px; }

.flowchips { display: flex; align-items: center; gap: 4px; overflow-x: auto; scrollbar-width: none; }
.flowchips::-webkit-scrollbar { display: none; }
.flowchips .arrow { color: var(--sub); font-size: 12px; }

.progress { display: flex; align-items: center; gap: 10px; }
.track-bg { flex: 1; height: 6px; border-radius: 3px; background: #e2ddd2; overflow: hidden; }
.bar { height: 100%; width: 0; background: var(--coral); border-radius: 3px; transition: width .25s; }
.count { font-size: 14px; font-weight: 700; color: var(--navy); min-width: 48px; text-align: right; font-variant-numeric: tabular-nums; }

/* 가로 스와이프: CSS scroll-snap */
.track {
  display: flex; overflow-x: auto; overflow-y: hidden;
  scroll-snap-type: x mandatory; overscroll-behavior-x: contain;
  scrollbar-width: none; outline: none;
}
.track::-webkit-scrollbar { display: none; }
.card {
  flex: 0 0 100%; scroll-snap-align: start; scroll-snap-stop: always;
  overflow-y: auto; overscroll-behavior-y: contain;
  padding: 4px 12px 10px;
}
.media-wrap { position: relative; }
/* 이미지 영역 높이 고정: 이미지가 없어도 레이아웃이 그대로 */
.media {
  height: var(--media-h); display: flex; gap: 4px;
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
}
.media > * { flex: 1; min-width: 0; }
.media img { width: 100%; height: 100%; object-fit: contain; display: block; user-select: none; }
.card.moved .media { border: 2px solid var(--navy); }
.move-banner {
  position: absolute; left: 10px; top: 10px; padding: 4px 10px; border-radius: 999px;
  background: var(--navy); color: #fff; font-size: 14px; font-weight: 700;
}

/* 이미지 없음: 글자 없이 회색 음영 */
.fallback { height: 100%; background: #e6e6e6; }

.card-body { padding: 10px 4px 0; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.ex-name { margin: 8px 0 0; font-size: 21px; line-height: 1.3; word-break: keep-all; }
/* 세트·횟수는 최소 28px, 1m 거리에서 읽히게 */
.dose { margin: 2px 0 8px; font-size: 30px; font-weight: 800; line-height: 1.25; color: var(--navy); word-break: keep-all; }
.target { margin: 0 0 6px; font-size: 16px; }
.label { display: inline-block; margin-right: 8px; font-size: 13px; font-weight: 700; color: var(--coral); }
.cues { margin: 0; padding-left: 22px; font-size: 16px; }
.cues li + li { margin-top: 2px; }
.caution { margin: 8px 0 0; font-size: 14px; color: var(--warn); }
.more { margin-top: 6px; border-top: 1px solid var(--line); padding-top: 4px; font-size: 15px; }
.more summary { cursor: pointer; color: var(--navy); font-weight: 600; min-height: 32px; }
.more dl { margin: 8px 0 0; display: grid; gap: 2px; }
.more dt { font-size: 13px; color: var(--sub); }
.more dd { margin: 0 0 6px; }
.more h4 { margin: 8px 0 2px; font-size: 13px; color: var(--sub); }
.sources { margin: 0; padding-left: 18px; font-size: 14px; }

.card.end { display: flex; align-items: center; justify-content: center; }
.end-inner { width: 100%; max-width: 360px; text-align: center; }
.end-emoji { font-size: 56px; }
.end-inner h2 { margin: 8px 0 4px; font-size: 26px; }
.end-actions { display: grid; gap: 10px; margin-top: 20px; }

/* 하단: 한 손 조작용 큰 버튼 */
.p-bottom {
  display: grid; grid-template-columns: 64px 1fr 64px; gap: 8px;
  padding: 8px 12px calc(10px + var(--safe-b));
  background: var(--bg); border-top: 1px solid var(--line);
}
.nav-btn {
  height: 56px; border-radius: 14px; border: 1px solid var(--line); background: var(--card);
  color: var(--navy); font-size: 32px; line-height: 1; cursor: pointer;
}
.nav-btn:disabled { opacity: .35; }
.p-bottom .btn { min-height: 56px; }
.btn.complete { background: var(--navy); border-color: var(--navy); color: #fff; font-size: 18px; }
.btn.complete.is-done { background: var(--card); color: var(--navy); border-color: var(--navy); font-size: 15px; }
.btn.complete:disabled { opacity: .5; }
.btn.complete.pulse { animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px rgba(255,107,91,.45); } }

/* 카드 안 작은 버튼: 다른 동작, 영상 보기 */
.chip-actions { display: inline-flex; gap: 6px; margin-left: auto; }
.mini {
  display: inline-flex; align-items: center; min-height: 30px; padding: 0 10px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--card); color: var(--navy);
  font-size: 13px; font-weight: 600; text-decoration: none; cursor: pointer; white-space: nowrap;
}
.track.offline .mini.video { opacity: .4; pointer-events: none; }

/* 완료 표시 */
.done-stamp {
  display: none; position: absolute; right: 10px; top: 10px; width: 40px; height: 40px; border-radius: 50%;
  place-items: center; background: var(--navy); color: #fff; font-size: 22px; font-weight: 800;
}
.card.done .done-stamp { display: grid; }
.card.done .media { opacity: .6; }

/* 유지형 타이머 (숫자는 1m 거리에서 읽히게 크게) */
.timer { display: grid; grid-template-columns: 1fr 56px; gap: 8px; margin: 0 0 10px; }
.t-main {
  display: flex; align-items: center; gap: 12px; min-height: 64px; padding: 6px 14px;
  border-radius: 14px; border: 0; background: var(--navy-soft); color: var(--navy); cursor: pointer; text-align: left;
}
.t-num { font-size: 40px; font-weight: 800; line-height: 1; min-width: 2.2em; font-variant-numeric: tabular-nums; }
.t-label { font-size: 15px; font-weight: 600; line-height: 1.3; }
.timer[data-state=running] .t-main { background: var(--navy); color: #fff; }
.timer[data-state=running][data-kind=rest] .t-main { background: var(--coral); color: #fff; }
.timer[data-state=done] .t-main { background: var(--card); border: 2px solid var(--navy); }
.t-reset {
  border-radius: 14px; border: 1px solid var(--line); background: var(--card); color: var(--navy);
  font-size: 24px; cursor: pointer;
}
.t-reset:disabled { opacity: .35; }

/* 완료 화면 */
.end-info { display: flex; justify-content: flex-end; }
.end-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 16px; }
.end-stats div { display: grid; gap: 2px; padding: 14px; border-radius: var(--radius); background: var(--card); border: 1px solid var(--line); }
.end-stats b { font-size: 28px; color: var(--navy); }
.end-stats span { font-size: 13px; color: var(--sub); }

@media (prefers-reduced-motion: reduce) {
  .bar { transition: none; }
  .btn.complete.pulse { animation: none; box-shadow: 0 0 0 4px rgba(255,107,91,.6); }
}

/* 새 버전 안내 (홈에만) */
.update-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  margin-bottom: 14px; padding: 10px 12px 10px 16px; border-radius: var(--radius);
  background: var(--navy-soft); color: var(--navy); font-weight: 600;
}
.update-bar .btn { min-height: 40px; }
