/* =============================================================
   style.css — 모바일(세로) 중심 디자인
   색상은 맨 위 변수(토큰)에서만 정한다 → 다크 모드는 변수만 바꾼다.
   ============================================================= */

:root {
  --bg: #f4f5f7;          /* 페이지 배경 */
  --surface: #ffffff;     /* 카드 배경 */
  --text: #16181d;        /* 기본 글자 */
  --muted: #6b7280;       /* 보조 글자 (퍼센트, 웜업) */
  --line: #e3e5e9;        /* 테두리, 구분선 */
  --accent: #d6452b;      /* 강조색 (선택된 주차, AMRAP) */
  --accent-text: #ffffff;
  --main-bg: #fde8e3;     /* 메인 배지 */
  --main-fg: #a8321c;
  --acc-bg: #e3ecfb;      /* 보조 배지 */
  --acc-fg: #2a5bb0;
  --radius: 14px;
  --gutter: 16px;
  --content-max: 960px;   /* 넓은 화면에서 내용 최대 폭 (카드 2개 나란히) */
  --danger: #c0262d;      /* 입력 오류 */
  --danger-bg: #fdecec;
  --success: #1e7a3a;     /* 저장 성공 */
  --notice-bg: #fff4d6;   /* 저장소 안내 상자 */
  --notice-fg: #6b4b00;
}

/* 다크 모드: 휴대폰 설정이 다크면 자동 적용 */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121417;
    --surface: #1c1f24;
    --text: #f1f2f4;
    --muted: #9aa1ad;
    --line: #2e333a;
    --accent: #ff6b4f;
    --accent-text: #16181d;
    --main-bg: #3d2420;
    --main-fg: #ff9c87;
    --acc-bg: #1f2c42;
    --acc-fg: #8db4f5;
    --danger: #ff8a80;
    --danger-bg: #3a1f1f;
    --success: #6fd08c;
    --notice-bg: #3a2f12;
    --notice-fg: #ffd98a;
  }
}
:root[data-theme="dark"] {
  --bg: #121417;
  --surface: #1c1f24;
  --text: #f1f2f4;
  --muted: #9aa1ad;
  --line: #2e333a;
  --accent: #ff6b4f;
  --accent-text: #16181d;
  --main-bg: #3d2420;
  --main-fg: #ff9c87;
  --acc-bg: #1f2c42;
  --acc-fg: #8db4f5;
  --danger: #ff8a80;
  --danger-bg: #3a1f1f;
  --success: #6fd08c;
  --notice-bg: #3a2f12;
  --notice-fg: #ffd98a;
}

/* ---------- 기본 ---------- */
*,
*::before,
*::after { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  font-size: 16px;
  line-height: 1.4;
  /* 아이폰 하단 홈 바 영역 피하기 */
  padding-bottom: env(safe-area-inset-bottom);
}

button {
  font: inherit;
  color: inherit;
  /* 더블탭 확대 방지 → 터치 반응이 빨라진다 */
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

/* ---------- 상단 고정 헤더 ---------- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
  padding: calc(12px + env(safe-area-inset-top)) var(--gutter) 12px;
  border-bottom: 1px solid var(--line);
}

/* 헤더 내용이 아래 카드 영역과 같은 폭으로 가운데 정렬되게.
   카드 목록의 max-width에는 좌우 여백(--gutter)이 포함되어 있으므로 그만큼 뺀다. */
.app-header-inner {
  max-width: calc(560px - 2 * var(--gutter));
  margin: 0 auto;
}
@media (min-width: 640px) {
  .app-header-inner { max-width: calc(var(--content-max) - 2 * var(--gutter)); }
}

.app-title {
  margin: 0;                   /* 아래 여백은 .title-row가 맡는다 */
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -0.01em;
}

/* 주차 선택: 4칸 균등 분할 */
.week-tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  padding: 4px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
}

.week-tab {
  min-height: 44px;            /* 손가락 터치 최소 크기 */
  border: 0;
  border-radius: 9px;
  background: transparent;
  font-size: 16px;
  font-weight: 700;
  color: var(--muted);
  cursor: pointer;
}

.week-tab[aria-pressed="true"] {
  background: var(--accent);
  color: var(--accent-text);
}

/* 요일 선택: 주차 버튼과 같은 틀, 선택 색만 다르게 (주차 = 강조색, 요일 = 진한 글자색) */
.day-tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin-top: 8px;
  padding: 4px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
}

.day-tab {
  min-height: 44px;            /* 손가락 터치 최소 크기 */
  border: 0;
  border-radius: 9px;
  background: transparent;
  font-size: 15px;
  font-weight: 700;
  color: var(--muted);
  cursor: pointer;
}

.day-tab[aria-pressed="true"] {
  background: var(--text);
  color: var(--bg);
}

.week-tab:focus-visible,
.day-tab:focus-visible,
.set-weight:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- 운동 카드 목록 ---------- */
/* 기본(좁은 화면): 1열 → 메인 카드 위, 보조 카드 아래 */
.exercise-list {
  display: grid;
  grid-template-columns: 1fr;
  align-items: start;          /* 카드 높이가 달라도 각자 내용만큼 */
  gap: 12px;
  padding: 16px var(--gutter) 8px;
  max-width: 560px;            /* 1열일 때 너무 넓어지지 않게 */
  margin: 0 auto;
}

/* 넓은 화면(640px 이상): 2열 → 왼쪽 메인, 오른쪽 보조 */
@media (min-width: 640px) {
  .exercise-list {
    grid-template-columns: 1fr 1fr;
    max-width: var(--content-max);
  }
}

.card {
  min-width: 0;                /* 긴 운동 이름 때문에 칸이 넘치지 않게 */
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px 8px;
}

.card-header {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;             /* 긴 운동 이름이면 줄바꿈 */
  margin-bottom: 4px;
}

.card-title {
  margin: 0;
  font-size: 18px;
  font-weight: 800;
  min-width: 0;
}

.badge {
  font-size: 12px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  white-space: nowrap;
}
.badge-main      { background: var(--main-bg); color: var(--main-fg); }
.badge-accessory { background: var(--acc-bg);  color: var(--acc-fg); }

.card-tm {
  margin-left: auto;           /* 오른쪽 끝으로 */
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* ---------- 세트 줄 ---------- */
.set-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

/* 한 줄: [퍼센트] [× 횟수] .......... [중량] */
.set-row {
  display: grid;
  grid-template-columns: 3.2em 1fr auto;
  align-items: center;
  column-gap: 8px;
  min-height: 52px;
  border-bottom: 1px solid var(--line);
}
.set-row:last-child { border-bottom: 0; }

.set-pct {
  font-size: 14px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.set-reps {
  font-size: 16px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* 중량 = 터치 버튼. 크게 표시 */
.set-weight {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  justify-content: center;
  min-width: 96px;
  min-height: 48px;
  padding: 4px 0 4px 12px;
  border: 0;
  background: transparent;
  text-align: right;
  cursor: pointer;
}

.set-weight .kg {
  font-size: 24px;
  font-weight: 800;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}
.set-weight .kg small {
  font-size: 13px;
  font-weight: 600;
  margin-left: 2px;
  color: var(--muted);
}

/* 터치하면 나오는 정확한 값 (작은 글씨) */
.set-weight .exact {
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.set-weight .exact::before { content: "정확 "; }
.set-weight .exact[hidden] { display: none; }

/* 웜업 줄: 흐리게 */
.set-row.is-warmup .set-reps,
.set-row.is-warmup .set-weight .kg {
  color: var(--muted);
}
.set-row.is-warmup .set-weight .kg {
  font-size: 20px;
  font-weight: 700;
}

/* 웜업과 본 세트 사이 구분선 (Week 4에는 그리지 않음) */
.set-divider {
  height: 0;
  margin: 2px 0;
  border-top: 2px solid var(--text);
  opacity: 0.6;
}
/* 구분선 바로 위 웜업 줄의 얇은 선은 지워서 선이 겹치지 않게 */
.set-row:has(+ .set-divider) { border-bottom: 0; }

/* AMRAP 세트(5+, 3+, 1+) 강조 */
.set-row.is-amrap .set-reps { color: var(--accent); font-weight: 800; }

/* ---------- 하단 안내 ---------- */
.hint {
  max-width: 560px;
  margin: 4px auto 24px;
  padding: 0 var(--gutter);
  font-size: 13px;
  color: var(--muted);
  text-align: center;
}
/* 넓은 화면에서는 카드 영역과 같은 폭 (위 .hint 규칙보다 뒤에 있어야 적용됨) */
@media (min-width: 640px) {
  .hint { max-width: var(--content-max); }
}

/* =============================================================
   4단계: 화면 전환 + 설정 화면
   ============================================================= */

/* hidden 속성이 붙은 요소는 display 규칙(grid, flex 등)보다 우선해서 숨긴다 */
[hidden] { display: none !important; }

/* ---------- 제목 줄: 제목 + [운동][PR][설정] ---------- */
.title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}
.title-rest { display: none; }          /* 640px 미만: "5/3/1"만 */
@media (min-width: 640px) {
  .title-rest { display: inline; }      /* 640px 이상: "5/3/1 Calculator" */
}

.view-tabs {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}
.view-tab {
  min-height: 44px;
  min-width: 52px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  font-size: 15px;
  font-weight: 700;
  color: var(--muted);
  cursor: pointer;
}
/* 선택된 화면: 진한 글자 + 테두리 + 아래 강조선 (주차·요일 버튼과 다른 모양) */
.view-tab[aria-pressed="true"] {
  color: var(--text);
  border-color: var(--text);
  box-shadow: inset 0 -3px 0 var(--accent);
}
.view-tab:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}


/* ---------- 설정 화면 ---------- */
.settings-panel {
  max-width: 560px;
  margin: 0 auto;
  padding: 16px var(--gutter) 24px;
}
.settings-grid {
  display: grid;
  grid-template-columns: 1fr;          /* 좁은 화면: 메인 4개 → 보조 4개 세로 */
  gap: 20px;
  align-items: start;
}
@media (min-width: 640px) {
  .settings-panel { max-width: var(--content-max); }
  .settings-grid { grid-template-columns: 1fr 1fr; gap: 12px; }   /* 왼쪽 메인, 오른쪽 보조 */
}
.settings-group { min-width: 0; }
.settings-group-title {
  margin: 0 0 10px;
  font-size: 16px;
  font-weight: 800;
}
.settings-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.notice {
  margin-bottom: 16px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--notice-bg);
  color: var(--notice-fg);
  font-size: 14px;
}

.settings-card {
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px 12px;
}
.settings-card-header {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.settings-card-title {
  margin: 0;
  font-size: 17px;
  font-weight: 800;
  min-width: 0;
  overflow-wrap: anywhere;             /* 긴 이름이 카드 밖으로 나가지 않게 */
}
.settings-default {
  margin-left: auto;
  font-size: 13px;
  color: var(--muted);
}

.field { margin-top: 12px; }
.field-label {
  display: block;
  margin-bottom: 4px;
  font-size: 14px;
  font-weight: 600;
}
.input {
  display: block;
  width: 100%;
  min-height: 48px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 16px;                     /* 16px 미만이면 아이폰이 입력할 때 화면을 확대한다 */
}
.input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
.input[aria-invalid="true"] {
  border-color: var(--danger);
  background: var(--danger-bg);
}
.field-error {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--danger);
}

.tm-preview {
  margin: 12px 0 0;
  font-size: 15px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.dirty-note {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--accent);
}

.settings-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 12px;
}
.btn {
  min-height: 48px;
  border-radius: 10px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
}
.btn-primary {
  border: 0;
  background: var(--accent);
  color: var(--accent-text);
}
.btn-secondary {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
}
.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.settings-status {
  min-height: 1.4em;
  margin: 8px 0 0;
  font-size: 14px;
}
.settings-status.is-success { color: var(--success); font-weight: 700; }
.settings-status.is-error   { color: var(--danger);  font-weight: 700; }
.settings-status.is-info    { color: var(--muted); }

/* =============================================================
   5단계: 오늘 기록 + 저장 확인 창 + PR 화면
   ============================================================= */

/* ---------- 오늘 기록 (운동 카드 바로 아래) ----------
   폭은 카드 영역과 같게: 좁은 화면 최대 560px, 640px 이상은 카드 2장을 합친 폭 */
.today-record {
  max-width: 560px;
  margin: 4px auto 0;
  padding: 0 var(--gutter);
}
@media (min-width: 640px) {
  .today-record { max-width: var(--content-max); }
}
.today-box {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px 12px;
}
.today-title {
  margin: 0 0 4px;
  font-size: 16px;
  font-weight: 800;
}
.today-target {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  overflow-wrap: anywhere;
}
.today-weight {
  margin: 4px 0 0;
  font-variant-numeric: tabular-nums;
}
.today-pct { font-size: 14px; color: var(--muted); }
.today-kg { font-size: 24px; font-weight: 800; }
.today-unit { font-size: 13px; font-weight: 600; color: var(--muted); }
.today-w4 {
  margin: 6px 0 0;
  font-size: 15px;
  font-weight: 600;
  color: var(--muted);
}
.today-form { margin-top: 10px; }
.today-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(96px, 140px);
  align-items: center;
  gap: 8px;
}
.today-unit-reps { font-size: 15px; font-weight: 600; }
.input:disabled,
.btn:disabled.today-save { opacity: 0.45; }
.today-preview {
  margin: 6px 0 0;
  min-height: 1.3em;
  font-size: 14px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.today-status {
  min-height: 1.3em;
  margin: 4px 0 0;
  font-size: 14px;
}
.today-status.is-success { color: var(--success); font-weight: 700; }
.today-status.is-error   { color: var(--danger);  font-weight: 700; }
.today-status.is-info    { color: var(--muted); }

/* ---------- 저장 확인 창 ---------- */
.confirm-dialog {
  width: min(420px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
}
.confirm-dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
.confirm-title {
  margin: 0 0 12px;
  font-size: 18px;
  font-weight: 800;
}
.confirm-list { margin: 0; }
.confirm-list > div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}
.confirm-list dt { color: var(--muted); font-size: 15px; }
.confirm-list dd {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  text-align: right;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}
.confirm-note {
  margin: 10px 0 0;
  font-size: 13px;
  color: var(--muted);
}
.confirm-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 14px;
}

/* ---------- PR 화면 ---------- */
.pr-panel {
  max-width: 560px;
  margin: 0 auto;
  padding: 16px var(--gutter) 24px;
}
@media (min-width: 640px) {
  .pr-panel { max-width: var(--content-max); }
}
/* 메인 운동 4개: 좁은 화면 2×2, 640px 이상 한 줄 4칸 */
.pr-exercise-tabs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}
@media (min-width: 640px) {
  .pr-exercise-tabs { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
.pr-exercise-tab {
  min-height: 44px;
  padding: 4px 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  font-size: 15px;
  font-weight: 700;
  color: var(--muted);
  overflow-wrap: anywhere;
  cursor: pointer;
}
.pr-exercise-tab[aria-pressed="true"] {
  background: var(--text);
  color: var(--bg);
  border-color: var(--text);
}
.pr-exercise-tab:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.pr-basis {
  margin: 14px 0 10px;
  font-size: 15px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
/* 표가 화면보다 넓으면 표 영역만 좌우로 밀린다 (페이지 전체는 밀리지 않음) */
.pr-table-wrap {
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.pr-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}
.pr-table caption {
  padding: 10px 10px 4px;
  text-align: left;
  font-size: 13px;
  color: var(--muted);
}
.pr-table th,
.pr-table td {
  padding: 8px 5px;
  border-bottom: 1px solid var(--line);
  text-align: right;
  white-space: nowrap;
}
.pr-table th:first-child,
.pr-table td:first-child { text-align: left; padding-left: 10px; }
.pr-table th:last-child,
.pr-table td:last-child { padding-right: 10px; }
.pr-table th {
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
}
.pr-table tbody tr:last-child td { border-bottom: 0; }
.pr-empty {
  padding: 24px var(--gutter);
  text-align: center;
  color: var(--muted);
  font-size: 15px;
}
.pr-note {
  margin: 10px 0 0;
  font-size: 13px;
  color: var(--muted);
}

/* =============================================================
   PR 기록 개별 삭제 + 좁은 화면 2줄 행
   ============================================================= */

/* 화면에는 안 보이지만 화면낭독기는 읽는 글자 (표의 "삭제" 칸 이름) */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* 행마다 있는 [삭제] 버튼: 빨간 테두리, 터치 44px */
.pr-table tbody td:nth-child(7) { padding-top: 4px; padding-bottom: 4px; }   /* 삭제 칸 */
.pr-delete {
  min-height: 44px;
  min-width: 52px;
  padding: 0 10px;
  border: 1px solid var(--danger);
  border-radius: 8px;
  background: transparent;
  color: var(--danger);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}
.pr-delete:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* 삭제 확인 창의 [삭제] 버튼 */
.btn-danger {
  border: 0;
  background: var(--danger);
  color: var(--surface);
}

/* 삭제 결과 문구 */
.pr-status {
  min-height: 1.3em;
  margin: 8px 0 0;
  font-size: 14px;
}
.pr-status.is-success { color: var(--success); font-weight: 700; }
.pr-status.is-error   { color: var(--danger);  font-weight: 700; }
.pr-status.is-info    { color: var(--muted); }

/* 640px 미만: 기록 1건을 2줄로 (표의 칸 순서와 내용은 그대로, 배치만 바꿈)
   1줄: 날짜 · 주차 · [삭제]
   2줄: 중량 · 반복 · e1RM · 넘기려면 (칸 이름을 작은 글씨로) */
@media (max-width: 639.98px) {
  .pr-table,
  .pr-table tbody { display: block; }
  .pr-table caption { display: block; }
  .pr-table thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }
  .pr-table tbody tr {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    align-items: center;
    column-gap: 6px;
    row-gap: 4px;
    padding: 8px 10px;
    border-bottom: 1px solid var(--line);
  }
  .pr-table tbody tr:last-child { border-bottom: 0; }
  .pr-table tbody tr td,
  .pr-table tbody tr td:first-child,
  .pr-table tbody tr td:last-child {
    padding: 0;
    border: 0;
    text-align: left;
    white-space: normal;
    overflow-wrap: anywhere;
  }
  .pr-table tbody tr td:nth-child(1) { grid-column: 1 / span 2; grid-row: 1; font-weight: 700; }
  .pr-table tbody tr td:nth-child(2) { grid-column: 3; grid-row: 1; }
  .pr-table tbody tr td:nth-child(7) { grid-column: 4; grid-row: 1; text-align: right; }   /* 삭제 칸 */
  .pr-table tbody tr td:nth-child(3) { grid-column: 1; grid-row: 2; }
  .pr-table tbody tr td:nth-child(4) { grid-column: 2; grid-row: 2; }
  .pr-table tbody tr td:nth-child(5) { grid-column: 3; grid-row: 2; }
  .pr-table tbody tr td:nth-child(6) { grid-column: 4; grid-row: 2; }
  .pr-table tbody tr td:nth-child(n+3):nth-child(-n+6)::before {
    content: attr(data-label);
    display: block;
    font-size: 11px;
    color: var(--muted);
  }
}

/* =============================================================
   TM 설정 카드: TM 입력 · 증량 버튼 · 정렬 개선
   ============================================================= */

/* 카드 안 요소를 세로로 쌓고, 증량 줄부터 아래(증량·기본값으로·저장·결과 문구)는 카드 맨 아래에 붙인다.
   → 같은 행의 두 카드 높이가 같아졌을 때 버튼 위치도 같아진다. */
.settings-card {
  display: flex;
  flex-direction: column;
}

/* 헤더: 항상 2줄 고정 (1줄 = 제목 + 배지, 2줄 = 기본 이름). 길면 … 으로 줄인다. */
.settings-card-header {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 2px;
  flex-wrap: nowrap;
}
.settings-card-titleline {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  height: 24px;
}
.settings-card-title {
  flex: 0 1 auto;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  overflow-wrap: normal;
  line-height: 24px;
}
.settings-card-titleline .badge { flex: 0 0 auto; }
.settings-default {
  margin-left: 0;
  min-width: 0;
  height: 18px;
  line-height: 18px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* 저장 전 비교("저장된 TM 60 kg → 62.5 kg") 줄과 "저장되지 않은 변경" 줄은 자리를 항상 확보 */
.tm-change {
  min-height: 20px;
  margin: 4px 0 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}
.tm-keep {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--muted);
}
.dirty-slot { min-height: 22px; }

/* 증량 줄: 메인은 증량 버튼, 보조는 같은 높이의 빈 공간 */
.tm-step-row {
  margin-top: auto;
  padding-top: 8px;
  min-height: 56px;
  display: flex;
}
.tm-step-row .btn-increment { flex: 1 1 auto; }

/* 640px 이상: 메인·보조 구역이 행을 공유(subgrid) → 같은 행의 두 카드 높이가 같아진다.
   구역 상자(.settings-group)는 그대로 남으므로 위치·크기를 잴 수 있다.
   subgrid를 지원하지 않는 옛 브라우저에서는 열마다 따로 쌓인다(기능은 같음). */
@media (min-width: 640px) {
  .settings-grid {
    grid-template-rows: auto repeat(4, auto);
    column-gap: 12px;
    row-gap: 12px;
    align-items: stretch;
  }
  .settings-group {
    display: grid;
    grid-row: 1 / span 5;
    grid-template-rows: subgrid;
    row-gap: 12px;
  }
  .settings-group-title { margin: 0; align-self: end; }
  .settings-list {
    display: grid;
    grid-row: 2 / span 4;
    grid-template-rows: subgrid;
    row-gap: 12px;
  }
}

/* 결과 문구를 버튼 바로 위로 옮긴 뒤의 간격: 문구 → 버튼 */
.settings-card .settings-status { margin: 8px 0 0; }
.settings-card .settings-actions { margin-top: 8px; }
