:root {
  --bg: #0a0c10;
  --surface: #13171d;
  --surface-2: #1a1f27;
  --line: #252b35;
  --text: #e8ecf2;
  --muted: #8a94a4;
  --dim: #5d6675;

  --creatine: #a78bfa;
  --water: #38bdf8;
  --protein: #fb923c;
  --workout: #4ade80;
  --danger: #f87171;
  --warn: #fbbf24;

  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --tabh: 62px;
}

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

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Pretendard', 'Apple SD Gothic Neo',
               'Segoe UI', system-ui, 'Noto Sans KR', sans-serif;
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

body {
  padding-top: var(--sat);
  min-height: 100vh;
}

body.authed { padding-bottom: calc(var(--tabh) + var(--sab)); }

.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 0.86rem; margin: 4px 0 0; }
.hint  { color: var(--dim); font-size: 0.78rem; line-height: 1.5; margin: 8px 0 0; }
.hint.inline { display: inline; margin-left: 6px; }
.center-t { text-align: center; }
.error { color: var(--danger); font-size: 0.86rem; margin-top: 12px; }

/* ── 레이아웃 ── */
.screen { animation: fade .18s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } }

.screen.center {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px;
}

.hd { padding: 22px 20px 10px; }
.hd h1 { font-size: 1.6rem; font-weight: 700; margin: 0; letter-spacing: -0.02em; }
.hd-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.pad { padding: 12px 20px 24px; }

h2.sec {
  font-size: 0.76rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.09em;
  color: var(--dim); margin: 26px 0 12px;
}

.badge {
  flex: none; font-size: 0.72rem; font-weight: 600; padding: 5px 11px; border-radius: 999px;
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--line);
  white-space: nowrap;
}
.badge.train { color: var(--workout); border-color: color-mix(in srgb, var(--workout) 35%, transparent); }

/* ── 링 ── */
.rings {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px; padding: 8px 20px 0;
}

.ring-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 18px;
  padding: 16px 14px 14px; display: flex; flex-direction: column; align-items: center; gap: 10px;
  position: relative; overflow: hidden;
}
.ring-card::before {
  content: ''; position: absolute; inset: -40% 50% 60% -40%;
  background: radial-gradient(circle, var(--c) 0%, transparent 70%); opacity: .07; pointer-events: none;
}

.ring { width: 92px; height: 92px; position: relative; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring .track { fill: none; stroke: var(--surface-2); stroke-width: 9; }
.ring .fill {
  fill: none; stroke: var(--c); stroke-width: 9; stroke-linecap: round;
  filter: drop-shadow(0 0 5px color-mix(in srgb, var(--c) 45%, transparent));
  transition: stroke-dashoffset .55s cubic-bezier(.4,0,.2,1);
}
.ring .mid {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 1px;
}
.ring .mid b { font-size: 1.15rem; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.ring .mid small { font-size: 0.6rem; color: var(--dim); }

.ring-card .name { font-size: 0.8rem; font-weight: 600; color: var(--muted); }
.ring-card .val  { font-size: 0.74rem; color: var(--dim); font-variant-numeric: tabular-nums; }
.ring-card.done .name { color: var(--c); }

/* ── 버튼 ── */
.btn {
  appearance: none; border: 1px solid var(--line); background: var(--surface-2); color: var(--text);
  font: inherit; font-weight: 600; font-size: 0.92rem; padding: 13px 16px; border-radius: 13px;
  cursor: pointer; transition: transform .1s, background .15s, border-color .15s;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--text); color: var(--bg); border-color: transparent; }
.btn.wide { width: 100%; display: block; }
.btn.big { padding: 16px; font-size: 1rem; margin-top: 20px; }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 30%, transparent); }
.btn:disabled { opacity: .45; }

.quick { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.quick .btn { flex: 1 1 0; min-width: 84px; padding: 15px 8px; text-align: center; }
.quick .btn small { display: block; font-weight: 400; font-size: .68rem; color: var(--dim); margin-top: 2px; }

/* ── 통계 ── */
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat {
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 13px 14px;
}
.stat .k { font-size: 0.72rem; color: var(--dim); }
.stat .v { font-size: 1.12rem; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 2px; letter-spacing: -0.02em; }
.stat .v em { font-style: normal; font-size: 0.72rem; font-weight: 500; color: var(--muted); margin-left: 2px; }

/* ── 알림 배너 ── */
.alert {
  border-radius: 13px; padding: 13px 15px; font-size: 0.84rem; line-height: 1.5;
  border: 1px solid; margin-bottom: 10px;
}
.alert.warn   { background: color-mix(in srgb, var(--warn) 9%, transparent);
                border-color: color-mix(in srgb, var(--warn) 28%, transparent); color: #fde68a; }
.alert.info   { background: color-mix(in srgb, var(--water) 9%, transparent);
                border-color: color-mix(in srgb, var(--water) 26%, transparent); color: #bae6fd; }
.alert b { display: block; margin-bottom: 3px; }

.note {
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  padding: 14px 16px; font-size: 0.82rem; color: var(--muted); line-height: 1.6; margin-bottom: 10px;
}
.note strong { color: var(--text); display: block; margin-bottom: 4px; }
.note b { color: var(--text); }

/* ── 물병 ── */
.bottle {
  height: 168px; border-radius: 20px; background: var(--surface); border: 1px solid var(--line);
  position: relative; overflow: hidden; margin-bottom: 18px;
  display: flex; align-items: center; justify-content: center;
}
.bottle .lv {
  position: absolute; left: 0; right: 0; bottom: 0;
  background: linear-gradient(180deg, color-mix(in srgb, var(--water) 55%, transparent), color-mix(in srgb, var(--water) 22%, transparent));
  transition: height .6s cubic-bezier(.4,0,.2,1);
}
.bottle .txt { position: relative; text-align: center; }
.bottle .txt b { display: block; font-size: 2.1rem; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -0.03em; }
.bottle .txt span { font-size: 0.8rem; color: var(--muted); }

/* ── 로그 리스트 ── */
.log { list-style: none; padding: 0; margin: 0; }
.log li {
  display: flex; align-items: center; gap: 12px; padding: 12px 4px;
  border-bottom: 1px solid var(--line); font-size: 0.88rem;
}
.log li:last-child { border-bottom: 0; }
.log .t { color: var(--dim); font-size: 0.78rem; font-variant-numeric: tabular-nums; width: 46px; flex: none; }
.log .m { flex: 1; font-variant-numeric: tabular-nums; }
.log .x {
  background: none; border: 0; color: var(--dim); font-size: 1.1rem; cursor: pointer; padding: 2px 8px;
}
.log .empty { color: var(--dim); font-size: 0.84rem; padding: 18px 0; text-align: center; border: 0; }

/* ── 폼 ── */
form label { display: block; font-size: 0.8rem; color: var(--muted); margin-bottom: 14px; }
label.row { display: flex; align-items: center; gap: 10px; color: var(--text); font-size: 0.9rem; margin-bottom: 14px; }
label.row input[type="checkbox"] { width: 22px; height: 22px; flex: none; margin: 0; accent-color: var(--water); }

input, select {
  width: 100%; margin-top: 6px; padding: 12px 13px; font: inherit; font-size: 1rem;
  background: var(--surface); color: var(--text); border: 1px solid var(--line); border-radius: 11px;
}
input:focus, select:focus { outline: none; border-color: var(--water); }
select { appearance: none; background-image: none; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }

fieldset { border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; margin: 0 0 16px; }
legend { font-size: 0.76rem; color: var(--dim); padding: 0 6px; text-transform: uppercase; letter-spacing: .08em; }

/* ── 소변 색 ── */
.urine { display: flex; gap: 8px; margin: 4px 0 18px; }
.urine button {
  flex: 1; height: 46px; border-radius: 11px; border: 2px solid transparent; cursor: pointer;
  font-size: 0.7rem; color: #3a2f00; font-weight: 700;
}
.urine button[data-v="1"] { background: #fdf6b2; }
.urine button[data-v="2"] { background: #fce96a; }
.urine button[data-v="3"] { background: #e3a008; }
.urine button[data-v="4"] { background: #b45309; color: #fde68a; }
.urine button.on { border-color: var(--text); }

/* ── 운동 후 단백질 추천 ── */
.suggest {
  background: linear-gradient(160deg,
    color-mix(in srgb, var(--protein) 13%, var(--surface)), var(--surface));
  border: 1px solid color-mix(in srgb, var(--protein) 32%, transparent);
  border-radius: 20px; padding: 17px 18px; margin-bottom: 6px;
}
.suggest.done {
  background: var(--surface);
  border-color: color-mix(in srgb, var(--workout) 32%, transparent);
}
.suggest .cap {
  font-size: 0.7rem; font-weight: 700; letter-spacing: .08em; color: var(--protein);
  text-transform: uppercase;
}
.suggest.done .cap { color: var(--workout); }
.suggest .head {
  font-size: 1.22rem; font-weight: 700; letter-spacing: -0.02em; margin: 5px 0 3px; line-height: 1.35;
}
.suggest .meta { font-size: 0.8rem; color: var(--muted); font-variant-numeric: tabular-nums; }

.suggest .opts { margin-top: 14px; display: flex; flex-direction: column; gap: 7px; }
.suggest .opt {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px;
  padding: 11px 13px; color: var(--text); font: inherit; font-size: 0.88rem; cursor: pointer;
}
.suggest .opt .nm { flex: 1; font-weight: 600; }
.suggest .opt .mc {
  font-size: 0.74rem; color: var(--dim); font-variant-numeric: tabular-nums; white-space: nowrap;
}
.suggest .opt.powder { border-color: color-mix(in srgb, var(--protein) 40%, transparent); }
.suggest .why {
  font-size: 0.76rem; color: var(--dim); line-height: 1.55; margin-top: 12px;
  padding-top: 12px; border-top: 1px solid var(--line);
}
.suggest .why p { margin: 0 0 6px; }
.suggest .why p:last-child { margin-bottom: 0; }

/* ── 식단 ── */
.slotpick { display: flex; gap: 7px; margin-bottom: 10px; }
.slotpick button {
  flex: 1; background: var(--surface); border: 1px solid var(--line); color: var(--muted);
  font: inherit; font-size: 0.84rem; font-weight: 600; padding: 10px 4px; border-radius: 11px; cursor: pointer;
}
.slotpick button.on { background: var(--text); color: var(--bg); border-color: transparent; }

.meal {
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px;
  padding: 13px 15px; margin-bottom: 9px;
}
.meal .mh { display: flex; align-items: baseline; gap: 9px; margin-bottom: 8px; }
.meal .mh .s { font-size: 0.68rem; font-weight: 700; padding: 3px 9px; border-radius: 999px;
  background: var(--surface-2); color: var(--muted); }
.meal .mh .t { flex: 1; font-size: 0.78rem; color: var(--dim); font-variant-numeric: tabular-nums; }
.meal .it {
  display: flex; align-items: center; gap: 9px; padding: 6px 0; font-size: 0.88rem;
  border-bottom: 1px solid var(--line);
}
.meal .it:last-of-type { border-bottom: 0; }
.meal .it .n { flex: 1; }
.meal .it .m { font-size: 0.74rem; color: var(--dim); font-variant-numeric: tabular-nums; }
.meal .it .x { background: none; border: 0; color: var(--dim); font-size: .95rem; cursor: pointer; padding: 2px 5px; }
.meal-empty { color: var(--dim); font-size: 0.86rem; text-align: center; padding: 22px 0; }

.photo-btn { text-align: center; margin-bottom: 10px; cursor: pointer; }
.photo-btn.busy { opacity: .55; pointer-events: none; }

.review {
  background: var(--surface); border: 1px solid color-mix(in srgb, var(--protein) 32%, transparent);
  border-radius: 16px; padding: 14px 15px; margin-bottom: 12px;
}
.review .rh { font-size: 0.8rem; color: var(--muted); margin-bottom: 10px; }
.review .rh b { color: var(--text); }
.review .ri {
  display: flex; align-items: center; gap: 9px; padding: 7px 0;
  border-bottom: 1px solid var(--line); font-size: 0.88rem;
}
.review .ri:last-of-type { border-bottom: 0; }
.review .ri .n { flex: 1; }
.review .ri .src {
  font-size: 0.6rem; padding: 2px 6px; border-radius: 999px;
  background: var(--surface-2); color: var(--dim); border: 1px solid var(--line);
}
.review .ri .m { font-size: 0.74rem; color: var(--dim); font-variant-numeric: tabular-nums; }
.review .ri .x { background: none; border: 0; color: var(--dim); font-size: .95rem; cursor: pointer; padding: 2px 5px; }
.review .acts { display: flex; gap: 8px; margin-top: 12px; }
.review .acts .btn { flex: 1; }

/* ── 몸 지도 (부위 선택 + 주간 볼륨 히트맵) ── */
.bodymap {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 20px;
  padding: 14px 8px 8px;
}
.bodymap figure { margin: 0; text-align: center; }
.bodymap figcaption {
  font-size: 0.68rem; color: var(--dim); letter-spacing: .06em; margin-bottom: 2px;
}
.bodymap svg { width: 100%; height: auto; max-height: 260px; display: block; }
.bodymap .silhouette { fill: #1c222b; stroke: #2b323d; stroke-width: 0.8; }
.bodymap .mg {
  cursor: pointer; stroke: transparent; stroke-width: 1.2;
  transition: fill-opacity .2s, stroke .2s;
}
.bodymap .mg.on { stroke: var(--text); stroke-width: 1.6; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip {
  font-size: 0.75rem; font-weight: 600; padding: 5px 11px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface-2); color: var(--muted); cursor: pointer;
}
.chip.on { color: var(--bg); background: var(--text); border-color: transparent; }

/* ── 종목 목록 ── */
.exlist { display: flex; flex-direction: column; gap: 7px; margin-bottom: 12px; }
.exrow {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  background: var(--surface); border: 1px solid var(--line); border-radius: 13px;
  padding: 12px 14px; color: var(--text); font: inherit; font-size: 0.9rem; cursor: pointer;
}
.exrow:active { transform: scale(.99); }
.exrow.added { border-color: color-mix(in srgb, var(--workout) 45%, transparent); }
.exrow .nm { flex: 1; font-weight: 600; }
.exrow .eq { font-size: 0.72rem; color: var(--dim); }
.exrow .badge-c {
  font-size: 0.62rem; padding: 2px 7px; border-radius: 999px;
  background: var(--surface-2); color: var(--dim); border: 1px solid var(--line);
}
.exrow .plus { font-size: 1.15rem; color: var(--dim); }
.exrow.added .plus { color: var(--workout); }

/* ── 세트 로거 ── */
.exercise-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 18px;
  padding: 14px 15px; margin-bottom: 11px;
}
.exercise-card.pr { border-color: color-mix(in srgb, var(--warn) 50%, transparent); }
.ex-head { display: flex; align-items: center; gap: 9px; margin-bottom: 3px; }
.ex-head .g {
  font-size: 0.63rem; font-weight: 700; padding: 2px 8px; border-radius: 999px;
  background: color-mix(in srgb, var(--gc) 20%, transparent); color: var(--gc);
}
.ex-head .n { flex: 1; font-weight: 700; font-size: 0.98rem; }
.ex-head .rm { background: none; border: 0; color: var(--dim); font-size: 1.05rem; cursor: pointer; padding: 0 2px; }

.prev {
  font-size: 0.78rem; color: var(--water); background: color-mix(in srgb, var(--water) 8%, transparent);
  border-radius: 9px; padding: 7px 10px; margin: 8px 0 10px; font-variant-numeric: tabular-nums;
}
.prev.none { color: var(--dim); background: var(--surface-2); }
.prev b { color: var(--text); }

.setrow {
  display: flex; align-items: center; gap: 10px; padding: 8px 2px;
  border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; font-size: 0.9rem;
}
.setrow:last-of-type { border-bottom: 0; }
.setrow .no {
  width: 22px; height: 22px; flex: none; border-radius: 7px; background: var(--surface-2);
  color: var(--dim); font-size: 0.72rem; font-weight: 700; display: grid; place-items: center;
}
.setrow .v { flex: 1; }
.setrow .x { background: none; border: 0; color: var(--dim); font-size: 1rem; cursor: pointer; padding: 2px 6px; }

.setform { display: flex; gap: 7px; margin-top: 10px; }
.setform input { margin: 0; text-align: center; padding: 11px 4px; font-size: 0.95rem; }
.setform .u { position: relative; flex: 1; }
.setform .u::after {
  content: attr(data-u); position: absolute; right: 9px; top: 50%; transform: translateY(-50%);
  font-size: 0.7rem; color: var(--dim); pointer-events: none;
}
.setform .btn { flex: none; padding: 11px 18px; }

.ex-foot {
  display: flex; justify-content: space-between; font-size: 0.72rem; color: var(--dim);
  margin-top: 9px; font-variant-numeric: tabular-nums;
}
.ex-foot .prtag { color: var(--warn); font-weight: 700; }

/* ── 주간 볼륨 막대 ── */
.volbars { display: flex; flex-direction: column; gap: 7px; }
.volbar { display: flex; align-items: center; gap: 9px; font-size: 0.76rem; }
.volbar .lb { width: 52px; flex: none; color: var(--muted); }
.volbar .tr {
  display: block; flex: 1; height: 7px; border-radius: 99px;
  background: var(--surface-2); overflow: hidden;
}
.volbar .fi { display: block; height: 100%; border-radius: 99px; transition: width .4s; }
.volbar .nm { width: 44px; flex: none; text-align: right; color: var(--dim); font-variant-numeric: tabular-nums; }
.volbar.low  .nm { color: var(--warn); }
.volbar.good .nm { color: var(--workout); }

/* ── 휴식 타이머 ── */
#rest-bar {
  position: fixed; left: 12px; right: 12px; bottom: calc(var(--tabh) + var(--sab) + 10px); z-index: 30;
  display: flex; align-items: center; gap: 10px;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 15px;
  padding: 11px 14px; backdrop-filter: blur(14px);
  box-shadow: 0 8px 28px rgba(0,0,0,.5);
}
#rest-bar .rt-label { font-size: 0.76rem; color: var(--dim); }
#rest-bar b { font-size: 1.15rem; font-variant-numeric: tabular-nums; flex: 1; letter-spacing: -.02em; }
#rest-bar.done b { color: var(--workout); }
#rest-bar button {
  background: var(--surface); border: 1px solid var(--line); color: var(--text);
  font: inherit; font-size: 0.76rem; font-weight: 600; padding: 7px 11px; border-radius: 9px; cursor: pointer;
}
@media (min-width: 640px) {
  #rest-bar { max-width: 536px; margin: 0 auto; }
}

/* ── 차트 ── */
#weight-chart svg { width: 100%; height: 190px; display: block; }
.chart-empty { color: var(--dim); font-size: 0.84rem; text-align: center; padding: 40px 0; }

/* ── 인증 카드 ── */
.auth-card { width: 100%; max-width: 320px; text-align: center; }
.brand { font-size: 1.9rem; font-weight: 700; letter-spacing: -0.03em; }
.auth-card form { margin-top: 26px; display: flex; flex-direction: column; gap: 10px; }

/* ── 탭바 ── */
#tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  height: calc(var(--tabh) + var(--sab)); padding-bottom: var(--sab);
  display: grid; grid-template-columns: repeat(6, 1fr);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(160%) blur(18px);
  -webkit-backdrop-filter: saturate(160%) blur(18px);
  border-top: 1px solid var(--line);
}
#tabbar button {
  background: none; border: 0; color: var(--dim); font: inherit; font-size: 0.66rem; font-weight: 600;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  cursor: pointer; padding: 0;
}
#tabbar button span { font-size: 1.05rem; line-height: 1; }
#tabbar button.on { color: var(--text); }

/* ── 토스트 ── */
#toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tabh) + var(--sab) + 16px); z-index: 40;
  background: var(--text); color: var(--bg); font-size: 0.85rem; font-weight: 600;
  padding: 11px 18px; border-radius: 999px; animation: pop .2s ease;
  max-width: calc(100vw - 40px); text-align: center;
}
@keyframes pop { from { opacity: 0; transform: translate(-50%, 8px); } }

@media (min-width: 640px) {
  .screen { max-width: 560px; margin: 0 auto; }
  #tabbar { max-width: 560px; margin: 0 auto; border-radius: 18px 18px 0 0; }
}
