/* ---------- 색상 ---------- */
:root {
  --bg: #fff8f1;
  --surface: #ffffff;
  --text: #2b2420;
  --muted: #7a6d64;
  --line: #eadfd4;
  --accent: #e8743b;
  --accent-text: #ffffff;
  --accent-soft: #fde9dc;
  --good: #2f8f5b;
  --good-soft: #e1f3e8;
  --danger: #c63b3b;
  --star: #f2a516;
  --shadow: 0 1px 3px rgba(60, 40, 20, 0.08);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1c1814;
    --surface: #27211c;
    --text: #f2ebe4;
    --muted: #a99c91;
    --line: #3a322b;
    --accent: #f08a52;
    --accent-text: #1c1814;
    --accent-soft: #4a2e1f;
    --good: #6fcf97;
    --good-soft: #1f3a2a;
    --danger: #ff7b7b;
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #1c1814; --surface: #27211c; --text: #f2ebe4; --muted: #a99c91; --line: #3a322b;
  --accent: #f08a52; --accent-text: #1c1814; --accent-soft: #4a2e1f; --good: #6fcf97;
  --good-soft: #1f3a2a; --danger: #ff7b7b; --shadow: none; color-scheme: dark;
}

/* ---------- 기본 ---------- */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", sans-serif;
  word-break: keep-all;
  overflow-wrap: anywhere;
}
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.3; margin: 0 0 8px; }
h2 { font-size: 1.35rem; }
h3 { font-size: 1rem; }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.pre { white-space: pre-wrap; margin: 0; }
.warn { color: var(--danger); }
[hidden] { display: none !important; }

#view {
  max-width: 640px;
  margin: 0 auto;
  padding: 12px 16px calc(96px + env(safe-area-inset-bottom));
}

/* ---------- 상단바 / + 버튼 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; justify-content: space-between; align-items: center;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; color: var(--text); text-decoration: none; font-size: 1.1rem; }
.settings-link { position: relative; text-decoration: none; font-size: 1.3rem; padding: 4px 8px; }
.dot { position: absolute; top: 4px; right: 4px; width: 8px; height: 8px; border-radius: 50%; background: var(--danger); }
.fab {
  position: fixed; right: 20px; bottom: calc(20px + env(safe-area-inset-bottom)); z-index: 10;
  width: 60px; height: 60px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--accent); color: var(--accent-text);
  font-size: 34px; line-height: 1; text-decoration: none;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

/* ---------- 버튼 / 입력 ---------- */
button, .button {
  font: inherit; font-size: 0.95rem;
  min-height: 44px; padding: 8px 16px;
  border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text);
  cursor: pointer; text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
}
button:disabled { opacity: 0.6; }
.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.ghost { background: transparent; }
.danger { color: var(--danger); }
.wide { width: 100%; }
button.small { min-height: 32px; padding: 4px 10px; font-size: 0.85rem; }

input, textarea, select {
  font: inherit; font-size: 16px; /* 16px 미만이면 아이폰이 화면을 확대해요 */
  width: 100%; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--surface); color: var(--text);
}
textarea { resize: vertical; }
input:focus, textarea:focus, select:focus, button:focus-visible, .chip input:focus-visible + span {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
.field { display: block; margin: 0 0 16px; }
.field > span { display: block; font-weight: 600; font-size: 0.9rem; margin-bottom: 6px; }
.field.inline { display: flex; align-items: center; gap: 8px; margin: 0; }
.field.inline > span { margin: 0; white-space: nowrap; }
.req { color: var(--danger); }
fieldset { border: 0; padding: 0; margin: 0 0 16px; }
legend { font-weight: 600; font-size: 0.9rem; margin-bottom: 6px; padding: 0; }

/* 선택 칩 */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { position: relative; }
.chip input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.chip span {
  display: inline-flex; align-items: center; min-height: 38px; padding: 6px 14px;
  border: 1px solid var(--line); border-radius: 999px; background: var(--surface);
  font-size: 0.92rem; cursor: pointer; user-select: none;
}
.chip input:checked + span { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }

/* ---------- 검색 ---------- */
.search { margin-bottom: 8px; }
.search-row { display: flex; gap: 8px; }
.search-row input { flex: 1; }
.filter-toggle { flex: none; }
.filter-toggle .count { color: var(--accent); font-weight: 700; }
.filters { margin-top: 12px; padding: 16px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; }
.filter-actions { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.filter-actions select { width: auto; }
.result-count { margin: 8px 2px; }

/* ---------- 카드 ---------- */
.cards { display: grid; gap: 10px; }
.cards[aria-busy="true"] { opacity: 0.6; }
.card {
  display: block; padding: 14px 16px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px;
  color: var(--text); text-decoration: none; box-shadow: var(--shadow);
}
.card h3 { font-size: 1.05rem; margin: 6px 0 2px; }
.card p { margin: 0; }
.card-top { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.badge { font-size: 0.78rem; padding: 2px 8px; border-radius: 999px; font-weight: 600; }
.badge.cat { background: var(--accent-soft); color: var(--accent); }
.badge.want { background: var(--bg); color: var(--muted); border: 1px solid var(--line); }
.badge.cooked { background: var(--good-soft); color: var(--good); }
.tag-row { display: flex; flex-wrap: wrap; gap: 4px 10px; margin-top: 6px; }
.tag { font-size: 0.85rem; color: var(--muted); }
.stars { color: var(--star); letter-spacing: 1px; font-size: 0.95rem; }
.stars .off { color: var(--line); }
.empty { text-align: center; color: var(--muted); padding: 48px 16px; }

/* ---------- 폼 ---------- */
.recipe-form h2 { margin-bottom: 16px; }
.rating { display: flex; align-items: center; gap: 2px; }
.star { border: 0; background: none; font-size: 32px; min-height: 44px; padding: 0 4px; color: var(--line); }
.star.on { color: var(--star); }
.clear-rating { margin-left: 8px; }
.dup-warning, .notice {
  margin: -8px 0 16px; padding: 10px 12px; border-radius: 12px;
  background: var(--accent-soft); font-size: 0.9rem;
}
.notice { margin: 0 0 12px; }
.form-error { color: var(--danger); font-weight: 600; }
.form-actions {
  display: flex; gap: 8px; justify-content: flex-end; margin-top: 20px;
}
.recipe-form .form-actions {
  position: sticky; bottom: 0; padding: 12px 0 calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(transparent, var(--bg) 30%);
}
.form-actions > * { flex: 1; }

/* ---------- 상세 ---------- */
.detail h2 { font-size: 1.5rem; margin: 8px 0 4px; }
.detail section { margin-top: 20px; }
.detail section h3 { color: var(--muted); font-size: 0.85rem; margin-bottom: 4px; }
.detail details { margin-top: 20px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; }
.detail summary { cursor: pointer; font-weight: 600; }
.detail details .pre { margin-top: 8px; font-size: 0.92rem; }
.ingredients { margin: 0; padding-left: 20px; }
.ingredients li { padding: 2px 0; }
.cook-box {
  margin-top: 16px; padding: 14px; border-radius: 16px;
  background: var(--surface); border: 1px solid var(--line);
  display: grid; gap: 8px;
}
.cook-box p { margin: 0; }
.source-link { word-break: break-all; }

/* ---------- 휴지통 / 설정 ---------- */
.trash-item {
  display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 12px 14px; margin-bottom: 8px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
}
.trash-item p { margin: 0; }
.trash-actions { display: flex; gap: 6px; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 16px; margin-bottom: 12px; }
.panel p { margin: 0 0 10px; }
.file-button { cursor: pointer; }

/* ---------- 로그인 ---------- */
.login { max-width: 360px; margin: 18vh auto 0; padding: 0 16px; text-align: center; }
.login .field { text-align: left; }
.login-emoji { font-size: 56px; }
.login h1 { margin-bottom: 24px; }

/* ---------- 알림 / 확인창 ---------- */
#toast {
  position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); z-index: 100;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  max-width: calc(100% - 32px); padding: 10px 18px; border-radius: 999px;
  background: var(--text); color: var(--bg); font-size: 0.92rem;
  transition: opacity 0.2s, transform 0.2s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.error { background: var(--danger); color: #fff; }
dialog.ask {
  border: 0; border-radius: 20px; padding: 20px;
  width: min(360px, calc(100% - 32px));
  background: var(--surface); color: var(--text);
}
dialog.ask::backdrop { background: rgba(0, 0, 0, 0.4); }
dialog.ask p { white-space: pre-line; margin: 0 0 16px; }
.ask-buttons { display: grid; gap: 8px; }
