/* ── 색/간격 (밝은 화면 / 어두운 화면) ───────────────── */
:root {
  --bg: #fffaf5;
  --surface: #ffffff;
  --surface-2: #fff1e6;
  --text: #2b2118;
  --muted: #7a6a5c;
  --line: #eadfd4;
  --primary: #e8590c;
  --primary-ink: #ffffff;
  --primary-soft: #ffe8d9;
  --danger: #c92a2a;
  --like: #e03131;
  --radius: 14px;
  --shadow: 0 1px 2px rgb(60 30 10 / .06), 0 4px 16px rgb(60 30 10 / .06);
  --maxw: 1080px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1a1511;
    --surface: #241d17;
    --surface-2: #2f251d;
    --text: #f3ebe3;
    --muted: #b3a393;
    --line: #3b3027;
    --primary: #ff7a33;
    --primary-ink: #1a1511;
    --primary-soft: #3d2618;
    --danger: #ff6b6b;
    --like: #ff6b6b;
    --shadow: 0 1px 2px rgb(0 0 0 / .3), 0 4px 16px rgb(0 0 0 / .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Pretendard Variable", Pretendard, -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  font-size: 16px;
  line-height: 1.65;
  word-break: keep-all;
  overflow-wrap: anywhere;
  padding-bottom: calc(64px + env(safe-area-inset-bottom));
}
a { color: var(--primary); }
img { max-width: 100%; display: block; }
h1, h2, h3 { line-height: 1.3; margin: 0 0 .5em; }
h1 { font-size: clamp(1.5rem, 4vw, 2.1rem); }
h2 { font-size: 1.25rem; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.skip { position: absolute; left: -999px; }
.skip:focus { left: 8px; top: 8px; z-index: 99; background: var(--surface); padding: 8px; }
:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }

#view { max-width: var(--maxw); margin: 0 auto; padding: 16px; min-height: 60vh; }
#view[aria-busy="true"] { opacity: .6; transition: opacity .2s .15s; }

/* ── 상단/하단 메뉴 ───────────────────────────── */
.mode-banner { background: var(--surface-2); color: var(--muted); font-size: .85rem; text-align: center; padding: 6px 16px; }
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 800; font-size: 1.1rem; color: var(--text); text-decoration: none; white-space: nowrap; }
.search { flex: 1; max-width: 420px; margin-left: auto; }
.search input { width: 100%; }
.top-nav { display: flex; align-items: center; gap: 8px; }
.avatar {
  display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 50%;
  background: var(--primary); color: var(--primary-ink); font-weight: 700; text-decoration: none;
}
.avatar.big { width: 72px; height: 72px; font-size: 1.8rem; flex: none; }
.tabbar {
  position: fixed; inset: auto 0 0 0; z-index: 10; display: flex;
  background: var(--surface); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a {
  flex: 1; display: flex; flex-direction: column; align-items: center; padding: 8px 0 6px;
  font-size: .75rem; color: var(--muted); text-decoration: none;
}
.tabbar a span { font-size: 1.25rem; line-height: 1.2; }
.tabbar a.active { color: var(--primary); font-weight: 700; }
@media (min-width: 720px) {
  .tabbar { display: none; }
  body { padding-bottom: 0; }
}
@media (max-width: 719px) {
  .hide-mobile { display: none !important; }
  .brand #brand-name { display: none; }
}

/* ── 버튼/입력 ──────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 8px 16px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--primary); }
.btn:disabled { opacity: .5; cursor: wait; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-danger { color: var(--danger); }
.btn-liked { color: var(--like); border-color: var(--like); background: color-mix(in srgb, var(--like) 10%, var(--surface)); }
.btn.wide { width: 100%; }
.btn.dashed { border-style: dashed; background: transparent; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.icon-btn {
  width: 32px; height: 32px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--surface); color: var(--muted); cursor: pointer; font: inherit;
}
.icon-btn:hover { color: var(--text); border-color: var(--primary); }
.link-btn { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: .8rem; text-decoration: underline; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; min-height: 40px; width: 100%;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); outline: none; box-shadow: 0 0 0 3px var(--primary-soft); }

/* ── 홈 ──────────────────────────────────────── */
.hero {
  text-align: center; padding: 36px 16px 28px; margin-bottom: 8px;
  background: linear-gradient(160deg, var(--primary-soft), transparent 70%); border-radius: var(--radius);
}
.hero p { color: var(--muted); margin: 0 0 16px; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 8px 0 16px; scrollbar-width: none; }
.chip {
  flex: none; padding: 6px 14px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); text-decoration: none; font-size: .9rem;
}
.chip.on { background: var(--text); color: var(--bg); border-color: var(--text); }
.result-head { color: var(--muted); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 240px), 1fr)); gap: 16px; }
@media (max-width: 519px) { .grid { grid-template-columns: 1fr 1fr; gap: 12px; } }
.card {
  display: flex; flex-direction: column; background: var(--surface); border-radius: var(--radius);
  overflow: hidden; box-shadow: var(--shadow); color: var(--text); text-decoration: none;
  transition: transform .15s;
}
.card:hover { transform: translateY(-2px); }
.card-img { position: relative; aspect-ratio: 4 / 3; background: var(--surface-2); }
.card-img img { width: 100%; height: 100%; object-fit: cover; }
.noimg { display: grid; place-items: center; height: 100%; font-size: 2.5rem; }
.card-body { padding: 10px 12px 12px; }
.card-body h3 { font-size: 1rem; margin: 2px 0 6px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card-cat { font-size: .78rem; color: var(--primary); font-weight: 700; text-decoration: none; }
.card-meta { display: flex; gap: 10px; font-size: .8rem; color: var(--muted); flex-wrap: wrap; }
.badge { position: absolute; top: 8px; left: 8px; font-size: .75rem; padding: 2px 8px; border-radius: 6px; }
.badge-dark { background: rgb(0 0 0 / .7); color: #fff; position: static; }
.card-img .badge-dark { position: absolute; }
.more { text-align: center; padding: 24px 0; }
.empty { text-align: center; padding: 64px 16px; color: var(--muted); }

/* ── 레시피 보기 ─────────────────────────────── */
/* 원본 사진이 가로 500px이라, 화면에서도 그보다 크게 늘리지 않아 선명하게 보이도록 함 */
.recipe { max-width: 680px; margin: 0 auto; font-size: 1.0625rem; line-height: 1.85; }
.cover {
  width: 100%; max-width: 560px; aspect-ratio: 16 / 9; object-fit: cover;
  margin: 0 auto 20px; border-radius: var(--radius); background: var(--surface-2);
}
.recipe-head h1 { font-size: clamp(1.45rem, 5.5vw, 1.9rem); letter-spacing: -0.01em; }
.byline { color: var(--muted); margin: 0 0 12px; font-size: .95rem; }
.byline a { color: var(--text); font-weight: 700; text-decoration: none; }
.info { display: flex; gap: 8px; margin: 0 0 16px; flex-wrap: wrap; }
.info div { background: var(--surface-2); border-radius: 10px; padding: 6px 14px; text-align: center; }
.info dt { font-size: .75rem; color: var(--muted); }
.info dd { margin: 0; font-weight: 700; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 28px; }
.recipe h2 { font-size: 1.2rem; margin: 0 0 14px; }

/* 소개글/마무리: 한 문장 한 줄, 문장 사이 여유 */
.summary { margin: 0 0 32px; padding: 4px 0 4px 16px; border-left: 3px solid var(--primary); }
.summary p, .tips p { margin: 0 0 .9em; }
.summary p:last-child, .tips p:last-child { margin-bottom: 0; }
.ln { display: block; }
.summary .ln + .ln, .tips .ln + .ln { margin-top: .45em; }

.box { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 18px; margin: 0 0 32px; }
.note { color: var(--danger); font-size: .9rem; margin: -6px 0 8px; }
.ingredients { list-style: none; padding: 0; margin: 0; columns: 2 260px; column-gap: 28px; font-size: 1rem; }
.ingredients li { break-inside: avoid; border-bottom: 1px dashed var(--line); }
.ingredients label { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 10px; padding: 10px 0; cursor: pointer; line-height: 1.5; }
.ingredients input { width: 20px; height: 20px; min-height: 0; flex: none; accent-color: var(--primary); }
.ing-name { font-weight: 600; }
.ing-amount { margin-left: auto; color: var(--primary); font-weight: 700; white-space: nowrap; }
.ing-note { flex-basis: 100%; color: var(--muted); padding-left: 30px; font-size: .85rem; }
.ingredients input:checked ~ span { text-decoration: line-through; opacity: .5; }
.ing-group { font-weight: 800; padding: 16px 0 4px; border: 0 !important; color: var(--primary); }

/* 조리 단계: 번호 + 글(한 문장 한 줄) + 같은 크기의 사진들 */
.steps { list-style: none; padding: 0; margin: 0 0 32px; }
.step {
  display: grid; grid-template-columns: 30px 1fr; gap: 0 12px;
  padding: 22px 0; border-bottom: 1px solid var(--line);
}
.step:first-child { padding-top: 4px; }
.step-num {
  width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; margin-top: 1px;
  background: var(--primary); color: var(--primary-ink); font-weight: 800; font-size: .95rem; line-height: 1;
}
.step-text p { margin: 0 0 .6em; }
.step-text p:last-child { margin-bottom: 0; }
.step-text .ln + .ln { margin-top: .3em; }
.step-text strong { font-weight: 700; color: var(--text); box-shadow: inset 0 -.45em 0 var(--primary-soft); }
.heat {
  display: inline-block; margin-left: 4px; padding: 0 9px; border-radius: 999px; vertical-align: 1px;
  font-size: .78rem; font-weight: 700; line-height: 1.7; white-space: nowrap;
  color: var(--danger); background: color-mix(in srgb, var(--danger) 10%, var(--surface));
}
.heat::before { content: "🔥 "; }
.note-box {
  margin: 10px 0 0 !important; padding: 10px 14px; border-radius: 10px; font-size: .92rem; line-height: 1.7;
  background: var(--surface-2); color: var(--text);
}
.note-box .ln:first-child::before { content: "💡 "; }
.step-imgs {
  grid-column: 1 / -1; display: grid; gap: 8px; margin-top: 14px;
  grid-template-columns: repeat(2, 1fr);
}
@media (min-width: 600px) { .step-imgs { grid-template-columns: repeat(3, 1fr); margin-left: 42px; } }
.step-imgs figure { margin: 0; }
.zoom { display: block; width: 100%; padding: 0; border: 0; background: none; cursor: zoom-in; border-radius: 10px; }
.step-imgs img { width: 100%; aspect-ratio: 16 / 9; object-fit: cover; border-radius: 10px; background: var(--surface-2); }
.step-imgs figcaption { font-size: .8rem; line-height: 1.4; color: var(--muted); text-align: center; padding-top: 5px; }

.tips { background: var(--primary-soft); border-color: transparent; }
.tags a { display: inline-block; margin: 0 6px 6px 0; padding: 2px 10px; border-radius: 999px; background: var(--surface-2); text-decoration: none; font-size: .9rem; }
.comments { margin-top: 32px; font-size: 1rem; }
.comment { padding: 12px 0; border-bottom: 1px solid var(--line); }
.comment p { margin: 4px 0 0; }
.comment-form { display: flex; gap: 8px; margin-top: 12px; align-items: flex-end; }

/* 사진 크게 보기 */
.viewer {
  position: fixed; inset: 0; z-index: 100; background: rgb(0 0 0 / .9);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.viewer figure { margin: 0; max-width: min(100%, 720px); text-align: center; }
.viewer img { width: 100%; max-height: 78vh; object-fit: contain; border-radius: 8px; }
.viewer figcaption { color: #eee; font-size: .95rem; margin-top: 10px; }
.viewer-close, .viewer-nav {
  position: absolute; border: 0; background: rgb(255 255 255 / .15); color: #fff; cursor: pointer;
  width: 44px; height: 44px; border-radius: 50%; font-size: 1.5rem; line-height: 1;
}
.viewer-close { top: 14px; right: 14px; font-size: 1.1rem; }
.viewer-nav.prev { left: 10px; top: 50%; transform: translateY(-50%); }
.viewer-nav.next { right: 10px; top: 50%; transform: translateY(-50%); }
.viewer-count { position: absolute; top: 24px; left: 50%; transform: translateX(-50%); color: #ccc; font-size: .85rem; }
@media (max-width: 599px) { .viewer-nav { top: auto !important; bottom: 20px; transform: none !important; } }

/* ── 올리기/수정 ─────────────────────────────── */
.editor { max-width: 760px; margin: 0 auto; }
.field { display: block; margin-bottom: 16px; }
.field > span { display: block; font-weight: 700; font-size: .9rem; margin-bottom: 6px; }
.row3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 0 12px; }
fieldset.box legend { font-weight: 800; font-size: 1.1rem; padding: 0 6px; }
.cover-pick img { max-height: 280px; border-radius: 10px; object-fit: cover; }
.cover-pick .btn.dashed { width: 100%; min-height: 120px; }
.ing-row { display: grid; grid-template-columns: 1.3fr 1fr 1.3fr auto; gap: 6px; margin-bottom: 6px; align-items: center; }
.ing-row.is-group { grid-template-columns: 1fr auto; }
.ing-row.is-group input { font-weight: 800; background: var(--surface-2); }
@media (max-width: 599px) {
  .ing-row { grid-template-columns: 1fr 1fr; }
  .ing-row .row-tools { grid-column: 1 / -1; justify-self: end; }
  .ing-row.is-group { grid-template-columns: 1fr; }
  .ing-row { padding-bottom: 6px; border-bottom: 1px dashed var(--line); }
}
.row-tools { display: inline-flex; gap: 4px; }
.step-edit { border: 1px solid var(--line); border-radius: 12px; padding: 12px; margin-bottom: 12px; background: var(--bg); }
.step-edit-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; margin-top: 8px; }
.thumb { display: flex; flex-direction: column; gap: 4px; }
.thumb img { aspect-ratio: 4 / 3; object-fit: cover; border-radius: 8px; width: 100%; }
.thumb input { min-height: 32px; padding: 4px 8px; font-size: .85rem; }
.thumbs .btn.dashed { min-height: 100px; border-radius: 8px; }
.check { display: flex; gap: 8px; align-items: center; margin: 8px 0 20px; }
.check input { width: 18px; min-height: 0; }
.save-bar {
  position: sticky; bottom: calc(64px + env(safe-area-inset-bottom)); display: flex; justify-content: flex-end; gap: 8px;
  padding: 12px 0; background: linear-gradient(transparent, var(--bg) 30%);
}
@media (min-width: 720px) { .save-bar { bottom: 0; } }

/* ── 로그인/프로필 ───────────────────────────── */
.auth { max-width: 400px; margin: 32px auto; background: var(--surface); padding: 24px; border-radius: var(--radius); box-shadow: var(--shadow); }
.tabs { display: flex; margin-bottom: 20px; border-bottom: 1px solid var(--line); }
.tabs button { flex: 1; padding: 10px; border: 0; background: none; font: inherit; font-weight: 700; color: var(--muted); cursor: pointer; border-bottom: 3px solid transparent; }
.tabs button.on { color: var(--primary); border-color: var(--primary); }
.profile { display: flex; gap: 16px; align-items: center; margin: 8px 0 24px; }
.profile h1 { margin: 0; }
.profile p { margin: 2px 0; }
details.box summary { cursor: pointer; font-weight: 700; }
details.box form { margin-top: 16px; }

#toast {
  position: fixed; left: 50%; bottom: calc(80px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 999px; font-size: .9rem;
  opacity: 0; pointer-events: none; transition: .25s; z-index: 50; max-width: calc(100% - 32px); text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ── 인쇄 ─────────────────────────────────────── */
@media print {
  .topbar, .tabbar, .mode-banner, .actions, .comments, #toast { display: none !important; }
  body { background: #fff; color: #000; padding: 0; }
  .step { break-inside: avoid; }
  .step-imgs { grid-template-columns: repeat(3, 1fr); }
}
