:root {
  --bg: #0b0d10;
  --panel: #161a20;
  --line: #2a3038;
  --text: #f2f4f7;
  --dim: #8b95a3;
  --accent: #3ddc97;
  --raw: #6b7685;
  --filt: #4cc9f0;
  --th: #f7a541;
  --rec: #ff5a5f;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", system-ui, sans-serif;
  -webkit-user-select: none;
  user-select: none;
  overscroll-behavior: none;
}

.screen {
  display: none;
  flex-direction: column;
  gap: 12px;
  min-height: 100%;
  min-height: 100dvh;   /* 아이폰 주소창 유무에 맞춘 실제 높이 */
  /* 홈 화면 앱(전체 화면)에서 노치·하단 막대·가로 둥근 모서리에 가리지 않게 */
  padding: calc(env(safe-area-inset-top) + 16px)
           calc(env(safe-area-inset-right) + 16px)
           calc(env(safe-area-inset-bottom) + 16px)
           calc(env(safe-area-inset-left) + 16px);
  max-width: 560px;
  margin: 0 auto;
}
.screen.active { display: flex; }

h1 { font-size: 28px; margin: 24px 0 0; }
.sub { color: var(--dim); margin: 0 0 16px; }

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  font-size: 18px;
  font-weight: 600;
  padding: 16px;
  border-radius: 14px;
  width: 100%;
  font-family: inherit;
}
.btn:active:not(:disabled) { transform: scale(0.98); opacity: 0.85; }
.btn:disabled { opacity: 0.4; }
.btn small { display: block; font-size: 12px; font-weight: 400; color: var(--dim); margin-top: 2px; }
.btn.big { font-size: 32px; padding: 28px; }
.btn.primary { background: var(--accent); color: #062014; border-color: var(--accent); }
.btn.small { width: auto; font-size: 15px; padding: 8px 12px; }
.btn.rec { color: var(--rec); }
.btn.rec.on { background: var(--rec); color: #fff; border-color: var(--rec); }

.row { display: flex; gap: 10px; }

.msg { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px; margin: 0; line-height: 1.5; }
.msg.warn { border-color: var(--th); color: var(--th); }
.hint { color: var(--dim); font-size: 14px; line-height: 1.5; }
.ver { color: var(--line); font-size: 12px; margin-top: auto; text-align: center; }

.bar { display: flex; align-items: center; gap: 10px; }
.status { color: var(--dim); font-size: 13px; line-height: 1.3; }

.count-wrap { text-align: center; }
.count { font-size: 120px; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; }
.count.bump { color: var(--accent); }
.count-label { color: var(--dim); font-size: 14px; }

#graph {
  width: 100%;
  height: 240px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  touch-action: none;
}

.legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: 13px; color: var(--dim); }
.legend i { display: inline-block; width: 14px; height: 3px; vertical-align: middle; margin-right: 5px; border-radius: 2px; }
.c-raw { background: var(--raw); }
.c-filt { background: var(--filt); }
.c-th { background: var(--th); }
.c-cnt { background: var(--accent); }
.c-dip { background: #e05d5d; }

.controls { display: flex; flex-direction: column; gap: 10px; }
.slider { display: flex; flex-direction: column; gap: 6px; font-size: 15px; }
.slider input { width: 100%; accent-color: var(--th); height: 32px; }
.rec-info { color: var(--dim); font-size: 14px; margin: 0; text-align: center; }

/* ===================== 2단계: 운동 모드 ===================== */
.center { text-align: center; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.card .hint { margin: 0; }
.btn.off b { color: var(--dim); }

/* 운동·보정 화면 */
.w-head { display: flex; justify-content: space-between; align-items: baseline; font-variant-numeric: tabular-nums; }
.w-set { font-size: 28px; font-weight: 800; }
.w-time { font-size: 28px; color: var(--dim); font-weight: 600; }
.w-live { text-align: center; margin: 4vh 0 2vh; }
.w-count {
  font-size: min(52vw, 280px);
  font-weight: 800;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  transition: color 0.15s;
}
.w-count.bump { color: var(--accent); }
.w-count.cd { font-size: min(36vw, 200px); color: var(--th); }
.w-phase { color: var(--dim); font-size: 18px; margin-top: 8px; }

/* 세트 결과 */
.w-result { display: flex; flex-direction: column; gap: 12px; text-align: center; }
.w-result[hidden], .w-live[hidden], .controls[hidden] { display: none; }
.w-result-title { font-size: 22px; font-weight: 700; color: var(--dim); margin-top: 2vh; }
.w-result-num { font-size: 120px; font-weight: 800; line-height: 1; color: var(--accent); font-variant-numeric: tabular-nums; }
.w-result-num small { font-size: 32px; margin-left: 6px; color: var(--text); }
.w-result .hint { margin: 0; }
.set-list-title { color: var(--dim); font-size: 14px; text-align: left; }
.set-list { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 8px 14px; font-size: 17px; font-weight: 600; }
.chip.total { border-color: var(--accent); color: var(--accent); }

/* 터치 잠금 오버레이: 반투명이라 뒤의 큰 숫자가 보임 */
.lock {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(11, 13, 16, 0.35);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  padding-bottom: calc(env(safe-area-inset-bottom) + 40px);
  touch-action: none;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}
.lock[hidden] { display: none; }
.lock-box { position: relative; width: 120px; height: 120px; }
.ring { width: 120px; height: 120px; transform: rotate(-90deg); }
.ring-bg { fill: rgba(22, 26, 32, 0.85); stroke: var(--line); stroke-width: 8; }
.ring-fg { fill: none; stroke: var(--accent); stroke-width: 8; stroke-linecap: round; }
.lock-icon { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 40px; }
.lock-text { color: var(--text); font-size: 16px; margin: 12px 0 0; text-shadow: 0 1px 4px #000; }

/* ===================== 3단계: 기록 · 휴식 · 홈 화면 앱 ===================== */
[hidden] { display: none !important; }
.btn.danger { background: #e05d5d; border-color: #e05d5d; color: #fff; }
.btn.danger-text { color: #ff8a8a; align-self: flex-start; }
.card-title { color: var(--dim); font-size: 14px; }

/* 홈 화면에 추가 안내 */
.tip { border-color: var(--filt); }
.tip .btn.small { align-self: flex-end; }

/* 기록: 요약 4칸 */
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; display: flex; flex-direction: column; gap: 4px; }
.stat-label { color: var(--dim); font-size: 13px; }
.stat-val { font-size: 15px; color: var(--dim); font-variant-numeric: tabular-nums; }
.stat-val b { font-size: 34px; color: var(--text); margin-right: 3px; }

/* 기록: 14일 그래프 */
#h-chart { width: 100%; height: 160px; display: block; }

/* 기록: 날짜별 목록 */
.h-list { display: flex; flex-direction: column; gap: 8px; }
.h-row {
  appearance: none; font-family: inherit; color: var(--text); text-align: left;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 14px; display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; width: 100%;
}
.h-row:active { opacity: 0.8; }
.h-date { font-size: 15px; font-weight: 700; }
.h-sets { grid-column: 1; color: var(--dim); font-size: 16px; font-variant-numeric: tabular-nums; }
.h-total { grid-column: 2; grid-row: 1 / span 2; align-self: center; font-size: 22px; font-weight: 800; color: var(--accent); }

/* 기록: 하루 상세 */
.d-summary { display: flex; align-items: baseline; gap: 10px; }
.d-total { font-size: 44px; font-weight: 800; color: var(--accent); font-variant-numeric: tabular-nums; }
.d-list { display: flex; flex-direction: column; gap: 10px; }
.d-head { display: flex; justify-content: space-between; align-items: baseline; }
.d-head-total { font-weight: 700; color: var(--accent); }
.d-set { display: grid; grid-template-columns: 4em 4em 1fr; gap: 8px; font-size: 16px; font-variant-numeric: tabular-nums; padding: 4px 0; border-top: 1px solid var(--line); }
.d-set-no { color: var(--dim); }
.d-set-n { font-weight: 700; }
.d-set-avg { color: var(--dim); text-align: right; }

/* 설정: 휴식 시간 */
.stepper { display: flex; align-items: center; gap: 10px; }
.stepper .btn { flex: 1; }
.stepper-val { min-width: 4.5em; text-align: center; font-size: 26px; font-weight: 800; font-variant-numeric: tabular-nums; }

/* 운동: 휴식 카운트다운 (세트 결과 화면) */
.w-rest { background: var(--panel); border: 1px solid var(--th); border-radius: 16px; padding: 10px 12px 14px; }
.w-rest-label { color: var(--th); font-size: 16px; font-weight: 700; }
.w-rest-time { font-size: min(24vw, 110px); font-weight: 800; line-height: 1.05; color: var(--th); font-variant-numeric: tabular-nums; }
.w-rest.done { border-color: var(--accent); }
.w-rest.done .w-rest-label, .w-rest.done .w-rest-time { color: var(--accent); }
.w-rest:not([hidden]) ~ .set-list-title { margin-top: 0; }
/* 휴식이 보일 때는 세트 개수를 조금 작게 해서 한 화면에 들어가게 */
.w-result:has(.w-rest:not([hidden])) .w-result-num { font-size: 84px; }
.w-result:has(.w-rest:not([hidden])) .w-result-title { margin-top: 0; }

/* 화면 안 확인 창 */
.modal {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0, 0, 0, 0.6);
  display: flex; align-items: center; justify-content: center;
  padding: calc(env(safe-area-inset-top) + 16px) calc(env(safe-area-inset-right) + 16px)
           calc(env(safe-area-inset-bottom) + 16px) calc(env(safe-area-inset-left) + 16px);
}
.modal-box { background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 18px; width: 100%; max-width: 420px; display: flex; flex-direction: column; gap: 16px; }
.modal-text { margin: 0; font-size: 17px; line-height: 1.5; white-space: pre-line; }
