:root {
  --bg: #FBF6EF;
  --bg-tint: #F5ECE1;
  --card: #FFFFFF;
  --ink: #443A31;
  --ink-soft: #6B5D50;
  --muted: #A99C8C;
  --line: #EFE6DA;
  --accent: #DC8A66;
  --accent-deep: #C9744F;
  --accent-soft: #FBEADF;
  --sage: #8CA486;
  --sage-soft: #E9F0E4;
  --butter: #EBB775;
  --butter-soft: #FCF0DC;
  --shadow-sm: 0 2px 8px rgba(120, 90, 55, 0.06);
  --shadow: 0 8px 24px rgba(120, 90, 55, 0.10);
  --shadow-lg: 0 16px 40px rgba(120, 90, 55, 0.16);
  --radius: 22px;
  --serif: "Iowan Old Style", "Apple Garamond", "Nanum Myeongjo", Georgia, serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #211C18;
    --bg-tint: #2A241F;
    --card: #2E2823;
    --ink: #F2EAE0;
    --ink-soft: #CFC3B5;
    --muted: #9A8D7E;
    --line: #3B342D;
    --accent: #E39A78;
    --accent-deep: #E7A585;
    --accent-soft: #3A2E26;
    --sage: #9DB397;
    --sage-soft: #2F352B;
    --butter: #E6B979;
    --butter-soft: #38301F;
    --shadow-sm: 0 2px 8px rgba(0,0,0,0.25);
    --shadow: 0 8px 24px rgba(0,0,0,0.3);
    --shadow-lg: 0 16px 40px rgba(0,0,0,0.4);
  }
}

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

body {
  margin: 0 auto;
  max-width: 460px;
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard", "Malgun Gothic", sans-serif;
  background: var(--bg);
  color: var(--ink);
  padding-bottom: 48px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

/* 헤더 */
.app-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 26px 22px 8px;
  padding-top: max(26px, env(safe-area-inset-top));
}
.app-header h1 {
  font-family: var(--serif);
  font-size: 1.72rem;
  font-weight: 600;
  margin: 0;
  letter-spacing: -0.01em;
  line-height: 1.15;
}
.app-header .sub { display: block; font-family: inherit; font-size: 0.8rem; color: var(--muted); font-weight: 500; margin-top: 5px; letter-spacing: 0.01em; }

.icon-btn {
  border: none; background: var(--card); font-size: 1.15rem;
  cursor: pointer; width: 42px; height: 42px; border-radius: 14px; color: var(--ink-soft);
  box-shadow: var(--shadow-sm); display: grid; place-items: center; transition: transform 0.12s;
}
.icon-btn:active { transform: scale(0.92); }

/* 탭 */
.tabs { display: flex; gap: 6px; padding: 14px 22px 10px; }
.tab {
  flex: 1; border: none; padding: 11px; border-radius: 14px;
  background: transparent; color: var(--muted); font-size: 0.94rem;
  font-weight: 600; cursor: pointer; transition: all 0.18s; letter-spacing: -0.01em;
}
.tab.active { background: var(--card); color: var(--ink); box-shadow: var(--shadow-sm); }

main { padding: 6px 22px; }
.view { display: none; }
.view.active { display: block; animation: fade 0.25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* 툴바 */
.plan-toolbar { display: flex; gap: 8px; margin: 6px 0 16px; }
.btn-primary {
  border: none; background: var(--accent); color: #fff;
  padding: 14px 16px; border-radius: 16px; font-size: 0.97rem;
  font-weight: 600; cursor: pointer; box-shadow: 0 6px 16px rgba(220,138,102,0.28);
  flex: 1; letter-spacing: -0.01em; transition: transform 0.12s;
}
.btn-primary:active { transform: scale(0.98); }
.btn-ghost {
  border: none; background: var(--card); color: var(--ink-soft);
  padding: 14px 18px; border-radius: 16px; font-weight: 600; cursor: pointer;
  box-shadow: var(--shadow-sm); transition: transform 0.12s;
}
.btn-ghost:active { transform: scale(0.96); }

/* 주간 계획 */
.week-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 11px; }
.day-card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow-sm);
  padding: 15px 17px; display: flex; align-items: center; gap: 15px; cursor: pointer;
  transition: transform 0.14s, box-shadow 0.14s; position: relative; overflow: hidden;
}
.day-card:active { transform: scale(0.985); }
.day-card.filled { box-shadow: var(--shadow); }
.day-card.today { background: linear-gradient(180deg, var(--butter-soft), var(--card)); }
.day-card.today::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--butter); }

.day-badge {
  width: 50px; height: 50px; border-radius: 16px; flex-shrink: 0;
  display: grid; place-items: center; font-weight: 700; font-size: 1.05rem;
  background: var(--bg-tint); color: var(--ink-soft); transition: all 0.2s;
}
.day-card.filled .day-badge { background: var(--accent-soft); font-size: 1.6rem; }
.day-card.today .day-badge { background: var(--butter); color: #fff; }
.day-card.today.filled .day-badge { background: var(--butter-soft); }

.day-body { flex: 1; min-width: 0; }
.day-label { font-size: 0.72rem; color: var(--muted); margin-bottom: 3px; font-weight: 600; letter-spacing: 0.02em; }
.day-label .today-tag { color: var(--accent-deep); }
.day-meal { font-size: 1.06rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; letter-spacing: -0.01em; }
.day-meal.empty { color: var(--muted); font-weight: 500; font-size: 0.98rem; }
.day-chevron { color: var(--line); font-size: 1.4rem; flex-shrink: 0; }
.day-card.filled .day-chevron { color: var(--muted); }

/* 장보기 */
.shopping-summary { color: var(--ink-soft); font-size: 0.92rem; margin: 6px 2px 16px; font-weight: 600; }
.shopping-list { list-style: none; padding: 0; margin: 0 0 20px; display: flex; flex-direction: column; gap: 9px; }
.shop-item {
  background: var(--card); border-radius: 16px; box-shadow: var(--shadow-sm);
  padding: 14px 16px; display: flex; align-items: center; gap: 13px; cursor: pointer;
  transition: transform 0.12s;
}
.shop-item:active { transform: scale(0.99); }
.shop-check {
  width: 26px; height: 26px; border-radius: 9px; border: 2px solid var(--line);
  flex-shrink: 0; display: grid; place-items: center; font-size: 0.82rem; color: #fff;
  transition: all 0.15s;
}
.shop-item.done .shop-check { background: var(--sage); border-color: var(--sage); }
.shop-item.done { background: var(--sage-soft); box-shadow: none; }
.shop-item.done .shop-name { text-decoration: line-through; color: var(--muted); }
.shop-name { flex: 1; font-weight: 600; letter-spacing: -0.01em; }
.shop-qty { color: var(--muted); font-size: 0.85rem; font-weight: 500; }
.share-btn { width: 100%; box-shadow: 0 6px 16px rgba(220,138,102,0.28); }
.hint { color: var(--muted); font-size: 0.83rem; text-align: center; margin-top: 12px; line-height: 1.6; }

.empty-state {
  text-align: center; padding: 48px 20px; color: var(--muted);
  font-size: 0.92rem; line-height: 1.7;
}
.empty-state .big { font-size: 2.6rem; display: block; margin-bottom: 12px; }

/* 모달 */
.modal {
  position: fixed; inset: 0; background: rgba(50, 38, 28, 0.42);
  display: flex; align-items: flex-end; justify-content: center; z-index: 50;
  animation: fade 0.15s; backdrop-filter: blur(3px);
}
.modal[hidden] { display: none; }
.modal-card {
  background: var(--bg); width: 100%; max-width: 460px;
  border-radius: 28px 28px 0 0; padding: 10px 22px calc(28px + env(safe-area-inset-bottom));
  max-height: 84vh; overflow-y: auto; animation: slideUp 0.26s cubic-bezier(0.2, 0.9, 0.3, 1);
  box-shadow: var(--shadow-lg);
}
@keyframes slideUp { from { transform: translateY(100%); } to { transform: none; } }
.modal-card::before { content: ""; display: block; width: 40px; height: 4px; border-radius: 3px; background: var(--line); margin: 8px auto 16px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.modal-head strong { font-family: var(--serif); font-size: 1.28rem; font-weight: 600; }

.search {
  width: 100%; padding: 13px 16px; border-radius: 14px; border: none;
  background: var(--card); color: var(--ink); font-size: 1rem; margin-bottom: 14px;
  box-shadow: var(--shadow-sm); outline: none;
}
.search::placeholder { color: var(--muted); }

/* 선택 모달 — 메뉴/재료 세그먼트 토글 */
.seg { display: flex; gap: 4px; padding: 4px; background: var(--bg-tint); border-radius: 14px; margin-bottom: 14px; }
.seg-btn { flex: 1; padding: 10px 0; border: none; border-radius: 10px; background: transparent;
  color: var(--ink-soft); font-size: 0.92rem; font-weight: 700; cursor: pointer; }
.seg-btn.active { background: var(--card); color: var(--accent-deep); box-shadow: var(--shadow-sm); }

/* 재료 카테고리 칩 */
.cat-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.cat-chip { padding: 9px 14px; border-radius: 22px; border: none; background: var(--card);
  color: var(--ink-soft); font-size: 0.88rem; font-weight: 600; cursor: pointer; box-shadow: var(--shadow-sm); }
.cat-chip.active { background: var(--accent); color: #fff; box-shadow: 0 4px 12px rgba(220,138,102,0.3); }

.picker-hint { padding: 22px 15px; text-align: center; color: var(--muted); font-size: 0.9rem; line-height: 1.5; }
.match-badge { font-size: 0.72rem; color: var(--sage); background: var(--sage-soft); padding: 3px 9px; border-radius: 8px; font-weight: 700; white-space: nowrap; }

.picker-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.picker-item {
  padding: 13px 15px; border-radius: 15px; background: var(--card); cursor: pointer;
  display: flex; align-items: center; gap: 13px; box-shadow: var(--shadow-sm); transition: transform 0.12s;
}
.picker-item:active { transform: scale(0.98); }
.picker-emoji { font-size: 1.5rem; width: 40px; height: 40px; border-radius: 12px; background: var(--accent-soft); display: grid; place-items: center; flex-shrink: 0; }
.picker-name { flex: 1; font-weight: 600; letter-spacing: -0.01em; }
.picker-meta { font-size: 0.8rem; color: var(--muted); font-weight: 500; }
.picker-item.blocked { opacity: 0.5; }
.picker-item.blocked .picker-emoji { background: var(--bg-tint); filter: grayscale(0.6); }
.tagline { font-size: 0.72rem; color: var(--accent-deep); background: var(--accent-soft); padding: 3px 9px; border-radius: 8px; font-weight: 600; }
.picker-clear { justify-content: center; color: var(--muted); font-weight: 600; }

/* 설정 */
.field { display: block; margin-bottom: 22px; }
.field > span { display: block; font-size: 0.82rem; color: var(--ink-soft); margin-bottom: 10px; font-weight: 600; letter-spacing: -0.01em; }
.field input[type=number] {
  width: 100%; padding: 13px 16px; border-radius: 14px; border: none; background: var(--card);
  color: var(--ink); font-size: 1rem; box-shadow: var(--shadow-sm); outline: none;
}
fieldset.field { border: none; padding: 0; margin: 0 0 22px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 9px 15px; border-radius: 22px; border: none;
  background: var(--card); color: var(--ink-soft); font-size: 0.88rem; cursor: pointer;
  font-weight: 600; box-shadow: var(--shadow-sm); transition: all 0.15s;
}
.chip.active { background: var(--accent); color: #fff; box-shadow: 0 4px 12px rgba(220,138,102,0.3); }

/* 상세 */
.detail-hero { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; }
.detail-hero .emoji { font-size: 2.4rem; width: 64px; height: 64px; border-radius: 18px; background: var(--accent-soft); display: grid; place-items: center; }
.detail-hero .time { color: var(--muted); font-size: 0.86rem; font-weight: 500; }
.detail-section { margin-bottom: 20px; }
.detail-section h4 { margin: 0 0 10px; font-size: 0.82rem; color: var(--muted); font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; }
.detail-ing { display: flex; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--line); font-weight: 500; }
.detail-steps { margin: 0; padding-left: 22px; line-height: 1.9; color: var(--ink-soft); }
.detail-steps li { margin-bottom: 4px; }
.recipe-link { display: flex; align-items: center; justify-content: center; gap: 6px; padding: 14px 16px; border-radius: 14px; background: var(--accent); color: #fff; font-weight: 700; text-decoration: none; box-shadow: var(--shadow-sm); }
.recipe-link:active { background: var(--accent-deep); }
.recipe-link-note { margin: 8px 2px 0; font-size: 0.78rem; color: var(--muted); line-height: 1.5; }

.toast {
  position: fixed; bottom: 32px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 13px 22px; border-radius: 26px;
  font-size: 0.92rem; font-weight: 600; z-index: 100; box-shadow: var(--shadow-lg);
  animation: toastIn 0.3s cubic-bezier(0.2, 0.9, 0.3, 1); max-width: 88%; text-align: center;
}
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 12px); } to { opacity: 1; transform: translate(-50%, 0); } }
.toast[hidden] { display: none; }

/* R2 — 빈칸 자동채우기 히어로 */
.plan-hero {
  background: linear-gradient(180deg, var(--accent-soft), var(--card));
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 30px 22px 26px; text-align: center; margin: 6px 0 16px;
}
.plan-hero[hidden] { display: none; }
.hero-emoji { font-size: 3rem; }
.hero-title { font-family: var(--serif); font-size: 1.32rem; font-weight: 600; margin: 8px 0 4px; letter-spacing: -0.01em; }
.hero-sub { color: var(--ink-soft); font-size: 0.9rem; margin-bottom: 20px; }
.hero-btn { width: 100%; font-size: 1.05rem; padding: 16px; box-shadow: 0 8px 20px rgba(220,138,102,0.32); }
#planToolbar[hidden] { display: none; }

/* R4 — 지난 요일 흐리게 */
.day-card.past { opacity: 0.55; }
.day-card.past:active { opacity: 0.8; }

/* R5 — 선호 뱃지 (카드) */
.pref-badge { font-size: 0.9rem; vertical-align: middle; }

/* R5 — 선호 태그 (피커) */
.pref-tag { font-size: 0.7rem; padding: 3px 8px; border-radius: 8px; font-weight: 700; white-space: nowrap; }
.pref-tag.like { color: var(--accent-deep); background: var(--accent-soft); }
.pref-tag.dislike { color: var(--sage); background: var(--sage-soft); }

/* R5 — 선호도 (상세) */
.pref-section h4 { margin-bottom: 12px; }
.pref-row { display: flex; gap: 8px; }
.pref-btn {
  flex: 1; border: 2px solid var(--line); background: var(--card); border-radius: 15px;
  padding: 12px 6px; display: flex; flex-direction: column; align-items: center; gap: 5px;
  cursor: pointer; color: var(--ink-soft); font-size: 0.8rem; font-weight: 600; transition: all 0.15s;
}
.pref-btn .pe { font-size: 1.5rem; }
.pref-btn:active { transform: scale(0.95); }
.pref-btn.on.like { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-deep); }
.pref-btn.on.meh { border-color: var(--butter); background: var(--butter-soft); color: var(--ink); }
.pref-btn.on.dislike { border-color: var(--sage); background: var(--sage-soft); color: var(--sage); }

/* R3 — 상세 편집 버튼 */
.detail-edit { display: flex; gap: 8px; margin-top: 4px; }
.detail-edit .btn-ghost { flex: 1; padding: 13px; font-size: 0.9rem; }

/* R1 — 온보딩 */
.ob-lead { color: var(--ink-soft); font-size: 0.92rem; line-height: 1.6; margin: 0 0 20px; }
.ob-note { color: var(--muted); font-size: 0.82rem; line-height: 1.6; background: var(--bg-tint); padding: 12px 14px; border-radius: 14px; margin: 4px 0 18px; }
.ob-note b { color: var(--ink-soft); }
.ob-start { width: 100%; }
.ob-skip { display: block; width: 100%; border: none; background: none; color: var(--muted); font-size: 0.88rem; font-weight: 600; padding: 14px; cursor: pointer; margin-top: 4px; }
.opt { color: var(--muted); font-weight: 500; }
.field input[type=text] {
  width: 100%; padding: 13px 16px; border-radius: 14px; border: none; background: var(--card);
  color: var(--ink); font-size: 1rem; box-shadow: var(--shadow-sm); outline: none;
}
