/* レシピちゃん: あたたかい台所の色。ダークモードは端末の設定に合わせる */
:root {
  --bg: #fbf6ef;
  --surface: #ffffff;
  --surface-2: #f4ece1;
  --text: #2b241d;
  --muted: #8a7d70;
  --line: #eadfd1;
  --accent: #e2643a;
  --accent-soft: #fde6dc;
  --heart: #e5484d;
  --chip: #f1e6d8;
  --chip-text: #6b5a49;
  --danger: #d93a3a;
  --shadow: 0 1px 2px rgba(60, 40, 20, .06), 0 4px 14px rgba(60, 40, 20, .06);
  --tab-h: 58px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1814;
    --surface: #26211c;
    --surface-2: #2f2923;
    --text: #f1e9df;
    --muted: #a39484;
    --line: #3a332b;
    --accent: #f07a50;
    --accent-soft: #4a2c20;
    --heart: #ff6b6f;
    --chip: #3a3229;
    --chip-text: #d8c8b6;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic UI", sans-serif;
  font-size: 16px; line-height: 1.6;
  -webkit-text-size-adjust: 100%;
}
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
img { display: block; max-width: 100%; }
svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

#view { padding-bottom: calc(var(--tab-h) + var(--safe-b) + 24px); min-height: 100vh; }

/* --- 下のタブ --- */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; height: calc(var(--tab-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
}
.tabs a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  font-size: 11px; color: var(--muted);
}
.tabs a svg { width: 25px; height: 25px; }
.tabs a.on { color: var(--accent); }
.tabs a.on svg { stroke-width: 2.2; }
body.detail .tabs { display: none; }

/* --- 上の帯 --- */
.head {
  position: sticky; top: 0; z-index: 10;
  padding: calc(var(--safe-t) + 10px) 16px 8px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
}
.head h1 { margin: 0 0 8px; font-size: 24px; font-weight: 800; letter-spacing: .02em; }
.search {
  display: flex; align-items: center; gap: 8px; height: 40px; padding: 0 12px;
  background: var(--surface-2); border-radius: 12px; color: var(--muted);
}
.search svg { width: 18px; height: 18px; flex: none; }
.search input {
  flex: 1; min-width: 0; border: 0; outline: 0; background: none; color: var(--text); font: inherit; font-size: 16px;
}
.chips { display: flex; gap: 6px; overflow-x: auto; padding: 10px 0 2px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; padding: 5px 12px; border-radius: 999px; background: var(--chip); color: var(--chip-text);
  font-size: 13px; white-space: nowrap;
}
.chip.on { background: var(--accent); color: #fff; }
.chip .n { opacity: .65; margin-left: 3px; font-size: 11px; }
/* タグの色（--h は app.js の tagHue が名前から決める） */
.chip.tag { background: hsl(var(--h) 75% 92%); color: hsl(var(--h) 55% 32%); }
.chip.tag.on { background: hsl(var(--h) 60% 46%); color: #fff; }
@media (prefers-color-scheme: dark) {
  .chip.tag { background: hsl(var(--h) 30% 24%); color: hsl(var(--h) 70% 80%); }
  .chip.tag.on { background: hsl(var(--h) 50% 50%); color: #fff; }
}

/* --- 一覧 --- */
.list { list-style: none; margin: 0; padding: 6px 12px; display: flex; flex-direction: column; gap: 10px; }
.row-wrap { position: relative; border-radius: 16px; overflow: hidden; }
.row-del {
  position: absolute; top: 0; right: 0; bottom: 0; width: 96px;
  display: flex; align-items: center; justify-content: center;
  background: var(--danger); color: #fff; font-weight: 700; font-size: 15px;
  visibility: hidden; /* ずらしている間だけ出す（角の丸みから赤がのぞかないように） */
}
.row-wrap.swiping .row-del { visibility: visible; }
.row {
  position: relative; display: flex; gap: 12px; align-items: stretch; padding: 10px;
  background: var(--surface); border-radius: 16px; box-shadow: var(--shadow);
  transition: transform .22s ease; touch-action: pan-y;
}
.row.dragging { transition: none; }
.thumb {
  flex: none; width: 96px; height: 96px; border-radius: 12px; object-fit: cover; background: var(--surface-2);
}
.thumb.empty { display: flex; align-items: center; justify-content: center; font-size: 34px; }
.row-body { flex: 1; min-width: 0; display: flex; flex-direction: column; justify-content: center; gap: 6px; }
.row-title {
  font-size: 16px; font-weight: 700; line-height: 1.4;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.row-tags { display: flex; flex-wrap: wrap; gap: 4px; max-height: 50px; overflow: hidden; }
.row-tags .chip { padding: 2px 8px; font-size: 11px; }
.row-sub { font-size: 12px; color: var(--muted); }
.row-err { font-size: 13px; color: var(--danger); }
.row-actions { display: flex; gap: 8px; margin-top: 2px; }
.btn-s { padding: 4px 12px; border-radius: 999px; font-size: 13px; background: var(--surface-2); }
.btn-s.accent { background: var(--accent); color: #fff; }
.heart {
  flex: none; align-self: center; width: 40px; height: 40px; display: flex; align-items: center; justify-content: center;
  color: var(--muted);
}
.heart.on { color: var(--heart); }
.heart.on svg { fill: currentColor; }
/* コンパクト表示（設定 →「一覧の表示」）: 写真を小さく、料理名だけを並べる */
:root[data-compact] .list { gap: 6px; }
:root[data-compact] .row { padding: 6px 4px 6px 6px; gap: 10px; border-radius: 12px; }
:root[data-compact] .row-wrap { border-radius: 12px; }
:root[data-compact] .thumb { width: 52px; height: 52px; border-radius: 9px; }
:root[data-compact] .thumb.empty { font-size: 22px; }
:root[data-compact] .row-tags { display: none; }
:root[data-compact] .row-title { font-size: 15px; }
:root[data-compact] .row-body { gap: 3px; }
:root[data-compact] .heart { width: 36px; height: 36px; }
:root[data-compact] .heart svg { width: 21px; height: 21px; }
.busy .thumb { animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .45; } }

.empty-box { text-align: center; color: var(--muted); padding: 64px 24px; }
.empty-box .big { font-size: 48px; margin-bottom: 8px; }

/* --- 右下の＋ --- */
.fab {
  position: fixed; right: 18px; bottom: calc(var(--tab-h) + var(--safe-b) + 16px); z-index: 15;
  width: 56px; height: 56px; border-radius: 50%; background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center; box-shadow: 0 6px 18px rgba(226, 100, 58, .4);
}
.fab svg { width: 28px; height: 28px; stroke-width: 2.4; }

/* --- レシピ画面 --- */
.r-top {
  position: fixed; top: 0; left: 0; right: 0; z-index: 10; display: flex; justify-content: space-between;
  padding: calc(var(--safe-t) + 8px) 10px 8px; pointer-events: none;
}
.r-top button {
  pointer-events: auto; width: 40px; height: 40px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: color-mix(in srgb, var(--surface) 85%, transparent); color: var(--text);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px); box-shadow: var(--shadow);
}
.r-hero { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; background: var(--surface-2); }
.r-hero.none { aspect-ratio: auto; height: calc(var(--safe-t) + 64px); }
.r-main { padding: 16px 16px 0; max-width: 720px; margin: 0 auto; }
.r-title-row { display: flex; gap: 8px; align-items: flex-start; }
.r-title { flex: 1; margin: 0; font-size: 23px; line-height: 1.4; font-weight: 800; }
.r-tags { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 4px; }
.sec { margin-top: 26px; }
.sec h2 {
  display: flex; align-items: baseline; gap: 8px; margin: 0 0 10px; font-size: 18px; font-weight: 800;
}
.sec h2::before { content: ""; width: 4px; height: 18px; border-radius: 2px; background: var(--accent); align-self: center; }
.sec h2 small { font-size: 13px; font-weight: 500; color: var(--muted); }
.ing { background: var(--surface); border-radius: 14px; padding: 4px 14px; box-shadow: var(--shadow); }
.ing-group { margin: 12px 0 2px; font-size: 13px; font-weight: 700; color: var(--accent); }
.ing-row { display: flex; gap: 8px; padding: 9px 0; border-bottom: 1px dashed var(--line); }
.ing-row:last-child { border-bottom: 0; }
.ing-name { flex: 1; }
.ing-amount { flex: none; font-weight: 600; text-align: right; max-width: 50%; }
.steps { list-style: none; margin: 0; padding: 0; counter-reset: step; }
.step { position: relative; padding: 0 0 18px 42px; counter-increment: step; }
.step::before {
  content: counter(step); position: absolute; left: 0; top: 0;
  width: 28px; height: 28px; border-radius: 50%; background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 15px;
}
.step p { margin: 0 0 8px; padding-top: 1px; }
.step img { width: 100%; border-radius: 12px; margin-top: 6px; background: var(--surface-2); }
.tips { margin: 0; padding: 12px 14px 12px 32px; background: var(--accent-soft); border-radius: 14px; }
.tips li { margin: 4px 0; }
.r-source { margin: 28px 0 8px; font-size: 13px; color: var(--muted); }
.r-source a { color: var(--accent); word-break: break-all; }

/* --- メニュー・シート --- */
.sheet-bg { position: fixed; inset: 0; z-index: 40; background: rgba(0, 0, 0, .35); display: flex; align-items: flex-end; }
.sheet {
  width: 100%; background: var(--surface); border-radius: 18px 18px 0 0;
  padding: 10px 12px calc(var(--safe-b) + 12px); animation: up .2s ease;
}
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
.sheet h3 { margin: 6px 6px 10px; font-size: 16px; }
.sheet button.item {
  display: block; width: 100%; text-align: left; padding: 14px 10px; border-radius: 12px; font-size: 16px;
}
.sheet button.item:active { background: var(--surface-2); }
.sheet button.item.danger { color: var(--danger); }
.sheet textarea {
  width: 100%; min-height: 110px; padding: 10px; border: 1px solid var(--line); border-radius: 12px;
  background: var(--bg); color: var(--text); font: inherit; font-size: 16px; resize: vertical;
}
.sheet .row-actions { justify-content: flex-end; margin-top: 10px; }
.sheet .row-actions button { padding: 9px 18px; font-size: 15px; }

/* --- トースト --- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tab-h) + var(--safe-b) + 84px); z-index: 50;
  transform: translateX(-50%); max-width: calc(100% - 32px);
  display: flex; align-items: center; gap: 14px; padding: 10px 16px; border-radius: 12px;
  background: #2b241d; color: #fff; font-size: 14px; box-shadow: 0 6px 20px rgba(0, 0, 0, .25);
}
.toast[hidden] { display: none; }
.toast button { color: #ffb08f; font-weight: 700; }
body.detail .toast { bottom: calc(var(--safe-b) + 24px); }

/* --- 設定・準備中 --- */
.page { padding: calc(var(--safe-t) + 16px) 16px; max-width: 720px; margin: 0 auto; }
.page h1 { margin: 0 0 16px; font-size: 24px; font-weight: 800; }
.card { background: var(--surface); border-radius: 14px; padding: 4px 14px; box-shadow: var(--shadow); margin-bottom: 16px; }
.card .line { display: flex; justify-content: space-between; align-items: center; padding: 13px 0; border-bottom: 1px solid var(--line); }
.card .line:last-child { border-bottom: 0; }
.card .line button { color: var(--accent); font-weight: 600; }
.card .line button.danger { color: var(--danger); }
.card .line.col { flex-direction: column; align-items: stretch; gap: 8px; }
.card-title { margin: 0 4px 6px; font-size: 13px; font-weight: 700; color: var(--muted); }
.note { font-size: 12px; color: var(--muted); line-height: 1.5; }
/* 選択式のボタン（どれか 1 つ） */
.seg { display: flex; padding: 3px; border-radius: 11px; background: var(--surface-2); }
.seg button { flex: 1; height: 34px; border-radius: 8px; font-size: 14px; color: var(--muted); }
.card .line .seg button { color: var(--muted); font-weight: 500; }
.card .line .seg button.on { background: var(--surface); color: var(--text); font-weight: 700; box-shadow: var(--shadow); }

/* --- ログイン --- */
.login-body { display: flex; min-height: 100vh; align-items: center; justify-content: center; }
.login { width: min(340px, calc(100% - 48px)); text-align: center; }
.login-logo { font-size: 64px; }
.login h1 { margin: 4px 0 24px; font-size: 26px; font-weight: 800; }
.login input {
  width: 100%; height: 48px; padding: 0 14px; border: 1px solid var(--line); border-radius: 12px;
  background: var(--surface); color: var(--text); font: inherit; font-size: 16px;
}
.login button {
  width: 100%; height: 48px; margin-top: 12px; border-radius: 12px; background: var(--accent); color: #fff; font-weight: 700;
}
.login-error { color: var(--danger); font-size: 14px; }

@media (min-width: 760px) {
  .list { max-width: 720px; margin: 0 auto; }
  .head > * { max-width: 696px; margin-left: auto; margin-right: auto; }
  .r-hero { max-width: 720px; margin: 0 auto; border-radius: 0 0 18px 18px; }
}
