/* 다이어팅 — B안 디자인 (design-guide.html과 같은 값) */
:root {
  --bg: #F3F5F9;
  --card: #FFFFFF;
  --text: #111827;
  --text-2: #374151;
  --muted: #4B5563;
  --line: #E5E9F0;
  --line-soft: #EEF1F6;
  --border: #D7DCE5;
  --chip-bg: #E6EAF1;
  --primary: #2563EB;
  --primary-text: #1D4ED8;
  --primary-tint: #EFF4FF;
  --navy: #1E3A8A;
  --warn-bg: #FFF1E6;
  --warn-text: #9A3412;
  --tip-bg: #FFF4E8;
  --tip-text: #7C2D12;
  --am: #FDBA74;
  --noon: #F97316;
  --pm: #1E40AF;
  --snack: #93C5FD;
  --r-card: 20px;
  --r-btn: 14px;
  --r-small: 12px;
  --font: 'IBM Plex Sans KR', system-ui, -apple-system, 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
button { font-family: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: default; opacity: 0.5; }
button:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
h1, h2, p { margin: 0; }

.app {
  position: relative;
  max-width: 480px;
  height: 100%;
  margin: 0 auto;
  overflow: hidden;
}

/* 옆으로 넘기는 세 화면 */
.pager {
  height: 100%;
  overflow: hidden;
  touch-action: pan-y;
}
.track {
  display: flex;
  height: 100%;
  transition: transform 0.28s ease;
  will-change: transform;
}
.track.dragging { transition: none; }
.screen {
  flex: 0 0 100%;
  height: 100%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: calc(20px + env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px)) calc(32px + env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px));
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* 화면 위쪽 */
.top { display: flex; align-items: center; justify-content: space-between; padding: 4px 4px 0; min-height: 52px; }
.date { font-size: 13px; color: var(--muted); }
.top h1, .overlay-top h1 { font-size: 24px; font-weight: 700; }
.top-actions { display: flex; gap: 4px; }

/* 화면 이동 표시 */
.nav {
  display: flex;
  align-self: center;
  gap: 2px;
  padding: 3px;
  border-radius: 999px;
  background: var(--chip-bg);
}
.nav button {
  height: 34px;
  padding: 0 14px;
  border: none;
  border-radius: 999px;
  background: transparent;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  color: var(--muted);
}
.nav button[aria-current="page"] { background: var(--card); color: var(--text); font-weight: 700; padding: 0 16px; }
.nav .chev { font-size: 15px; line-height: 1; }

/* 버튼 */
.btn-primary {
  height: 54px;
  border: none;
  border-radius: var(--r-btn);
  background: var(--primary);
  color: #FFFFFF;
  font-size: 16px;
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.btn-secondary {
  height: 36px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card);
  color: var(--primary-text);
  font-size: 13px;
  font-weight: 500;
}
.btn-icon {
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  background: var(--card);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.btn-back {
  height: 44px;
  padding: 0 12px 0 6px;
  border: none;
  border-radius: 12px;
  background: var(--card);
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 14px;
  font-weight: 500;
}
.part {
  height: 48px;
  border: 1px solid var(--border);
  border-radius: var(--r-small);
  background: var(--card);
  font-size: 15px;
  font-weight: 500;
}
.part[aria-pressed="true"] { border-color: var(--primary); background: var(--primary); color: #FFFFFF; }

/* 카드 */
.card {
  background: var(--card);
  border-radius: var(--r-card);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.card h2 { font-size: 16px; font-weight: 700; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.card-protein { padding: 20px 16px; gap: 14px; }
.pill-next { font-size: 13px; color: var(--primary-text); background: var(--primary-tint); padding: 4px 10px; border-radius: 999px; }
.empty { font-size: 14px; color: var(--muted); text-align: center; padding: 12px 0; }

/* 단백질 원 */
.ring { position: relative; width: 200px; height: 200px; margin: 0 auto; }
.ring svg { display: block; }
.ring-center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; }
.pct { font-size: 46px; font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; }
.pct small { font-size: 22px; }
.ring-sub { font-size: 14px; }

/* 끼니 타일 */
.tiles { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.tiles li { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0; border-radius: 10px; background: var(--bg); }
.tile-name { display: flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 500; color: var(--text-2); }
.tile-g { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.sq { width: 9px; height: 9px; border-radius: 3px; display: inline-block; }
.sq.am { background: var(--am); }
.sq.noon { background: var(--noon); }
.sq.pm { background: var(--pm); }
.sq.snack { background: var(--snack); }

/* 오늘 운동 */
.parts { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.week-block { display: flex; flex-direction: column; gap: 8px; padding-top: 12px; border-top: 1px solid var(--line-soft); }
.week-title { font-size: 13px; font-weight: 500; color: var(--text-2); }
.week-count { font-size: 13px; }
.week { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.week .day { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.week .dot { width: 32px; height: 32px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 500; background: var(--bg); color: var(--muted); }
.week .dot.done { background: var(--primary); color: #FFFFFF; }
.week .dot.today { outline: 2px solid var(--navy); outline-offset: 1px; }
.week .what { font-size: 12px; color: var(--text-2); text-align: center; line-height: 1.35; min-height: 16px; white-space: pre-line; }

/* 경고, 팁 */
.warn { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-radius: 16px; background: var(--warn-bg); color: var(--warn-text); font-size: 15px; font-weight: 700; }
.warn[hidden] { display: none; }
.tip { margin: 0; padding: 10px 12px; border-radius: var(--r-small); background: var(--tip-bg); color: var(--tip-text); font-size: 13px; }
.tip[hidden] { display: none; }

/* 홈 화면 추가 안내 */
.install { display: flex; align-items: flex-start; gap: 8px; padding: 12px 8px 12px 16px; border-radius: 16px; background: var(--primary-tint); color: var(--navy); border: 1px solid #C7D7FB; }
.install[hidden] { display: none; }
.install-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; font-size: 13px; line-height: 1.5; }
.install-body b { font-size: 14px; }
.install-close { width: 44px; height: 44px; margin: -10px 0; border: none; background: transparent; color: var(--navy); display: inline-flex; align-items: center; justify-content: center; padding: 0; flex-shrink: 0; }

/* 오늘 먹은 것 */
.total { font-size: 15px; }
.total b { font-size: 24px; }
.ratio { height: 12px; border-radius: 6px; background: var(--line); }

/* 덮이는 화면 */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  background: var(--bg);
  overflow-y: auto;
  padding: calc(16px + env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px)) calc(32px + env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px));
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.overlay[hidden] { display: none; }
.overlay-top { display: flex; flex-direction: column; align-items: flex-start; gap: 10px; }

/* 초기 설정·입력 */
.lead-text { font-size: 14px; color: var(--muted); }
.note-box { font-size: 13px; line-height: 1.6; padding: 12px 14px; border-radius: var(--r-small); background: var(--tip-bg); color: var(--tip-text); }
.setup { display: flex; flex-direction: column; gap: 14px; }
.field-label { font-size: 15px; font-weight: 700; }
.hint { font-size: 13px; color: var(--muted); }
.hint.missing { color: var(--warn-text); }
.field-error { font-size: 13px; color: #B91C1C; font-weight: 500; }
.field-error[hidden], .hint[hidden] { display: none; }
.goal-row { display: flex; align-items: center; gap: 8px; }
input[type="number"], input[type="text"] {
  height: 48px;
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--r-small);
  padding: 0 14px;
  font-family: inherit;
  font-size: 17px;
  color: var(--text);
  background: var(--card);
}
input:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }
input[aria-invalid="true"] { border-color: #B91C1C; }
.goal-row input { max-width: 160px; }
.unit { font-size: 16px; color: var(--muted); }
.routine-editor { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.slot { display: flex; flex-direction: column; gap: 8px; padding: 10px; border-radius: 14px; background: var(--bg); }
.slot-head { display: flex; align-items: center; gap: 10px; min-height: 32px; }
.slot-name { flex: 1; font-size: 15px; font-weight: 500; }
.slot-remove { width: 44px; height: 44px; margin: -6px -6px -6px 0; border: none; background: transparent; color: var(--muted); display: inline-flex; align-items: center; justify-content: center; padding: 0; }
.parts-small .part { height: 44px; font-size: 14px; }
.add-slot { align-self: flex-start; height: 44px; }
.order { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.order-row { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 12px; background: #F7F8FB; }
.order-num { width: 26px; height: 26px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 700; background: var(--chip-bg); color: var(--text-2); flex-shrink: 0; }
.order-name { font-size: 15px; font-weight: 500; }

/* 단백질 추가 창 */
.sheet-overlay { padding: 0; background: transparent; display: flex; flex-direction: column; justify-content: flex-end; }
.sheet-overlay[hidden] { display: none; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(17, 24, 39, 0.45); }
.sheet {
  position: relative;
  max-height: calc(100% - 40px);
  overflow-y: auto;
  background: var(--card);
  border-radius: 24px 24px 0 0;
  padding: 10px 18px calc(18px + env(safe-area-inset-bottom, 0px));
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.grab { align-self: center; width: 40px; height: 5px; border-radius: 3px; background: #D1D5DB; flex-shrink: 0; }
.sheet-title { font-size: 20px; font-weight: 700; }
.stack { display: flex; flex-direction: column; gap: 8px; }
.stack-14 { display: flex; flex-direction: column; gap: 14px; }
.field-label.small { font-size: 13px; font-weight: 500; color: var(--muted); }
.seg-group { display: flex; background: var(--bg); border-radius: 10px; padding: 3px; }
.seg-day { height: 38px; padding: 0 14px; border: none; border-radius: 8px; background: transparent; color: var(--muted); font-size: 14px; }
.seg-day[aria-pressed="true"] { background: var(--card); color: var(--text); font-weight: 500; box-shadow: 0 1px 2px rgba(17, 24, 39, 0.12); }
.meal-pick { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.seg { height: 44px; border: 1px solid var(--border); border-radius: var(--r-small); background: var(--card); font-size: 14px; font-weight: 500; }
.seg[aria-pressed="true"] { border-color: var(--primary); background: var(--primary); color: #FFFFFF; }
.foods { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.food-tile { display: flex; flex-direction: column; gap: 2px; padding: 10px; border-radius: 14px; border: 1px solid var(--line); min-width: 0; }
.food-tile.on { border: 1.5px solid var(--primary); background: #F5F8FF; }
.food-tile .nm { font-size: 14px; font-weight: 500; overflow-wrap: anywhere; }
.food-tile .u { font-size: 12px; color: var(--muted); }
.food-tile .ctl { display: flex; align-items: center; justify-content: space-between; margin-top: 4px; }
.food-tile .count { font-size: 16px; font-weight: 700; font-variant-numeric: tabular-nums; }
.step { width: 44px; height: 36px; border: none; border-radius: 8px; background: var(--bg); font-size: 18px; padding: 0; }
.step.plus { background: var(--primary-tint); color: var(--primary-text); }
.step:disabled { opacity: 0.4; }
.sheet-actions { display: grid; grid-template-columns: 1fr 2fr; gap: 8px; position: sticky; bottom: calc(-18px - env(safe-area-inset-bottom, 0px)); margin: 0 -18px calc(-18px - env(safe-area-inset-bottom, 0px)); padding: 10px 18px calc(18px + env(safe-area-inset-bottom, 0px)); background: var(--card); border-top: 1px solid var(--line-soft); }
.btn-ghost { height: 54px; border: 1px solid var(--border); border-radius: var(--r-btn); background: var(--card); font-size: 16px; font-weight: 500; }
.btn-primary.is-disabled { background: #A9C0F5; }

/* 오늘 먹은 것 목록 */
.left { font-size: 14px; color: var(--primary-text); font-weight: 500; }
.ratio { display: flex; gap: 2px; overflow: hidden; }
.ratio span { height: 100%; }
.seg-am, .bar-am { background: var(--am); }
.seg-noon, .bar-noon { background: var(--noon); }
.seg-pm, .bar-pm { background: var(--pm); }
.seg-snack, .bar-snack { background: var(--snack); }
.meal-card { gap: 0; padding-bottom: 4px; }
.meal-card > .card-head { padding-bottom: 6px; }
.tag { font-size: 13px; font-weight: 700; padding: 4px 12px; border-radius: 999px; }
.tag-am { background: var(--am); color: #431407; }
.tag-noon { background: var(--noon); color: #1C0A00; }
.tag-pm { background: var(--pm); color: #FFFFFF; }
.tag-snack { background: var(--snack); color: #0C1E3E; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: 10px; min-height: 48px; border-top: 1px solid var(--line-soft); font-size: 15px; }
.list .bar { width: 4px; height: 22px; border-radius: 2px; flex-shrink: 0; }
.list .food { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.list .g { color: var(--text-2); font-variant-numeric: tabular-nums; }
.empty { white-space: pre-line; }
.ring-left { font-size: 13px; color: var(--primary-text); font-weight: 500; min-height: 19px; }
.btn-delete { width: 44px; height: 44px; margin-right: -10px; border: none; background: transparent; color: #6B7280; display: inline-flex; align-items: center; justify-content: center; padding: 0; flex-shrink: 0; }
.list li.confirming { flex-wrap: wrap; }
.list li.confirming .btn-delete { display: none; }
.confirm { display: flex; align-items: center; gap: 6px; width: 100%; padding: 0 0 8px 14px; }
.confirm-q { flex: 1; font-size: 14px; color: var(--text-2); }
.confirm-yes, .confirm-no { height: 40px; padding: 0 14px; border-radius: 10px; font-size: 14px; font-weight: 500; }
.confirm-yes { border: none; background: #B91C1C; color: #FFFFFF; }
.confirm-no { border: 1px solid var(--border); background: var(--card); }

/* 루틴 화면 */
.week-big .dot { width: 34px; height: 34px; }
.day-name { font-size: 12px; color: var(--muted); }
.slot-bars { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.slot-bars li { display: flex; align-items: center; gap: 10px; font-size: 14px; }
.bar-name { width: 76px; flex-shrink: 0; }
.bar-track { flex: 1; height: 8px; border-radius: 4px; background: var(--line-soft); display: flex; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 4px; background: var(--primary); }
.bar-count { width: 34px; text-align: right; font-variant-numeric: tabular-nums; }
.bar-count.zero { color: #C2410C; }
.stats3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; padding-top: 12px; border-top: 1px solid var(--line); }
.stats3 div { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.stats3 b { font-size: 20px; font-variant-numeric: tabular-nums; }
.stats3 span { font-size: 12px; color: var(--muted); }
.order-row { border: 1.5px solid transparent; }
.order-row.is-next { background: var(--primary-tint); border-color: var(--primary); }
.order-row.is-next .order-num { background: var(--primary); color: #FFFFFF; }
.order-name { flex: 1; }
.order-tag { font-size: 12px; font-weight: 700; color: var(--primary-text); }

/* 달력 */
.btn-icon.on-bg { background: var(--bg); }
.cal-head { display: flex; align-items: center; justify-content: space-between; }
.cal-head h2 { font-size: 17px; }
.cal-week { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); text-align: center; font-size: 12px; color: var(--muted); }
.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 3px; }
.cal-day { min-height: 64px; border: 1px solid transparent; border-radius: 10px; background: var(--bg); padding: 4px 2px; display: flex; flex-direction: column; align-items: center; gap: 1px; font-family: inherit; min-width: 0; }
.cal-day:disabled { background: transparent; opacity: 0.45; }
.cal-day.done { background: var(--primary-tint); }
.cal-day.today { border-color: var(--navy); }
.cal-day.selected { border: 2px solid var(--primary); }
.cal-num { font-size: 13px; font-weight: 700; }
.cal-parts { font-size: 10px; line-height: 1.2; color: var(--primary-text); font-weight: 500; white-space: pre-line; text-align: center; }
.cal-g { font-size: 10px; color: var(--muted); margin-top: auto; font-variant-numeric: tabular-nums; }
.card[hidden] { display: none; }

.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-row > * { flex: 1 1 auto; }
.btn-ghost.small { height: 40px; padding: 0 14px; font-size: 14px; border-radius: 10px; }

/* 설정 */
.saved-note { font-size: 14px; font-weight: 500; color: #166534; background: #ECFDF3; padding: 10px 14px; border-radius: var(--r-small); }
.saved-note:empty { display: none; }
.row-field { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 15px; }
.row-field .goal-row input { width: 96px; }
.btn-secondary.wide { height: 44px; width: 100%; }
.food-edit { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.food-row, .food-new { display: flex; flex-direction: column; gap: 8px; padding: 10px; border-radius: 14px; background: var(--bg); }
.food-new { background: transparent; padding: 0; }
.food-fields { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr) 68px; gap: 6px; }
.food-fields input { height: 44px; font-size: 15px; padding: 0 10px; }
.backup-text { width: 100%; border: 1px solid var(--border); border-radius: var(--r-small); padding: 10px; font-family: ui-monospace, Menlo, monospace; font-size: 12px; resize: vertical; background: var(--card); color: var(--text); }
.backup-text[hidden] { display: none; }
.restore { display: flex; flex-direction: column; gap: 8px; padding-top: 12px; border-top: 1px solid var(--line); }
.file-btn { display: inline-flex; align-items: center; justify-content: center; cursor: pointer; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.restore input[type="file"]:focus-visible + * , .file-btn:focus-within { outline: 2px solid var(--primary); }
.confirm-box { display: flex; flex-direction: column; gap: 8px; padding: 12px; border-radius: var(--r-small); background: var(--warn-bg); color: var(--warn-text); font-size: 14px; }
.confirm-box[hidden], #restore-undo[hidden] { display: none; }
.btn-danger { height: 40px; padding: 0 14px; border: none; border-radius: 10px; background: #B91C1C; color: #FFFFFF; font-size: 14px; font-weight: 500; }

@media (prefers-reduced-motion: reduce) {
  .track { transition: none; }
}
