/* ============ デザインの基本色（ライト / ダーク） ============ */
:root {
  --bg: #FAF8F5;
  --surface: #FFFFFF;
  --surface-2: #F3F0EB;
  --text: #1F1D1A;
  --muted: #8A857D;
  --line: #ECE8E1;
  --accent: #C8603A;
  --accent-ink: #FFFFFF;
  --star: #E2A62B;
  --user-1: #C8603A;
  --user-2: #5A7E94;
  --danger: #C0392B;
  --shadow: 0 1px 2px rgba(31, 29, 26, .05), 0 6px 20px rgba(31, 29, 26, .06);
  --radius: 16px;
  --tabbar-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141312;
    --surface: #1E1D1B;
    --surface-2: #272523;
    --text: #F2EFEA;
    --muted: #9A958D;
    --line: #2E2C29;
    --accent: #E07A52;
    --accent-ink: #141312;
    --star: #F0B43C;
    --user-1: #E07A52;
    --user-2: #7FA3B8;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  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-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
button, input, textarea, select { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
img { display: block; max-width: 100%; }
svg.i { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
[hidden] { display: none !important; }

#app {
  max-width: 640px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 8px) 16px calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 24px);
  min-height: 100vh;
}
body.no-tabbar #app { padding-bottom: calc(env(safe-area-inset-bottom) + 32px); }

/* ============ ヘッダー ============ */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 8px;
  margin: 0 -16px 8px; padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(14px);
  -webkit-backdrop-filter: saturate(1.4) blur(14px);
}
.topbar h1 { flex: 1; margin: 0; font-size: 17px; font-weight: 700; letter-spacing: .02em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar.large h1 { font-size: 28px; letter-spacing: .01em; }
.icon-btn {
  display: inline-grid; place-items: center; width: 40px; height: 40px;
  border: 0; border-radius: 12px; background: transparent; cursor: pointer;
}
.icon-btn:active { background: var(--surface-2); }

/* ============ 共通パーツ ============ */
.section-title {
  display: flex; align-items: baseline; justify-content: space-between;
  margin: 28px 0 12px; font-size: 13px; font-weight: 700; letter-spacing: .12em; color: var(--muted);
}
.section-title a { font-size: 13px; letter-spacing: 0; color: var(--accent); font-weight: 600; }
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.empty { padding: 40px 16px; text-align: center; color: var(--muted); font-size: 14px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 46px; padding: 0 20px; border: 0; border-radius: 14px;
  background: var(--surface-2); font-weight: 600; cursor: pointer;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.danger { background: transparent; color: var(--danger); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; }
.btn:active:not(:disabled) { transform: scale(.98); }

.field { display: block; margin-bottom: 16px; }
.field > span { display: block; margin-bottom: 6px; font-size: 13px; font-weight: 600; color: var(--muted); }
.input, textarea.input, select.input {
  width: 100%; min-height: 46px; padding: 10px 14px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--surface);
  outline: none; font-size: 16px; /* 16px 未満だと iPhone で勝手にズームする */
}
textarea.input { resize: vertical; min-height: 80px; line-height: 1.6; }
.input:focus { border-color: var(--accent); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips.scroll { flex-wrap: nowrap; overflow-x: auto; margin: 0 -16px; padding: 0 16px 4px; scrollbar-width: none; }
.chips.scroll::-webkit-scrollbar { display: none; }
.chip {
  flex: none; padding: 7px 14px; border: 1px solid var(--line); border-radius: 999px;
  background: var(--surface); font-size: 14px; cursor: pointer; white-space: nowrap;
}
.chip.on { background: var(--text); color: var(--bg); border-color: var(--text); }

.searchbox {
  display: flex; align-items: center; gap: 8px; padding: 0 14px; min-height: 46px;
  border-radius: 14px; background: var(--surface-2); color: var(--muted);
}
.searchbox input { flex: 1; border: 0; background: transparent; outline: none; color: var(--text); font-size: 16px; min-height: 44px; }

/* ============ ホーム：ジャンルフォルダ ============ */
.genre-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.genre-card {
  position: relative; aspect-ratio: 4 / 3; overflow: hidden; border-radius: var(--radius);
  background: var(--surface-2); box-shadow: var(--shadow);
}
.genre-card img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.genre-card .shade { position: absolute; inset: 0; background: linear-gradient(to top, rgba(0,0,0,.62), rgba(0,0,0,0) 62%); }
.genre-card .label { position: absolute; left: 14px; right: 14px; bottom: 11px; color: #fff; }
.genre-card.noimg .label { color: var(--text); }
.genre-card.noimg .shade { display: none; }
.genre-card .label b { display: block; font-size: 16px; letter-spacing: .02em; }
.genre-card .label small { font-size: 12px; opacity: .85; }
.genre-card .folder { position: absolute; top: 14px; left: 14px; color: var(--muted); }

.hscroll { display: flex; gap: 12px; overflow-x: auto; margin: 0 -16px; padding: 2px 16px 8px; scroll-snap-type: x mandatory; scrollbar-width: none; }
.hscroll::-webkit-scrollbar { display: none; }
.mini { flex: none; width: 140px; scroll-snap-align: start; }
.mini .thumb { width: 140px; height: 105px; border-radius: 14px; }
.mini b { display: block; margin-top: 8px; font-size: 14px; line-height: 1.4; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.mini small { color: var(--muted); font-size: 12px; }

.thumb { object-fit: cover; background: var(--surface-2); }
.thumb.ph { display: grid; place-items: center; color: var(--muted); }

/* ============ レシピ一覧 ============ */
.recipe-list { display: flex; flex-direction: column; gap: 2px; }
.recipe-row { display: flex; gap: 14px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.recipe-row .thumb { width: 76px; height: 76px; border-radius: 12px; flex: none; }
.recipe-row .meta { flex: 1; min-width: 0; }
.recipe-row b { display: block; font-size: 16px; line-height: 1.4; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recipe-row .sub { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 4px; font-size: 13px; color: var(--muted); }
.stars-inline { color: var(--star); letter-spacing: 1px; }

/* ============ レシピ詳細 ============ */
.hero { margin: 0 -16px; aspect-ratio: 4 / 3; background: var(--surface-2); overflow: hidden; }
.hero img { width: 100%; height: 100%; object-fit: cover; }
@media (min-width: 640px) { .hero { margin: 0; border-radius: var(--radius); } }
.detail-head { padding: 20px 0 4px; }
.detail-head h2 { margin: 0 0 10px; font-size: 24px; line-height: 1.35; letter-spacing: .01em; }
.facts { display: flex; flex-wrap: wrap; gap: 6px 16px; color: var(--muted); font-size: 14px; }
.facts span { display: inline-flex; align-items: center; gap: 5px; }
.facts svg.i { width: 17px; height: 17px; }
.genre-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.genre-tags span { padding: 3px 10px; border-radius: 999px; background: var(--surface-2); font-size: 12px; color: var(--muted); }

.panel { margin-top: 16px; padding: 16px; }
.rating-row { display: flex; align-items: center; gap: 12px; padding: 4px 0; }
.rating-row .who { width: 64px; font-size: 14px; font-weight: 600; display: flex; align-items: center; gap: 6px; }
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.stars { display: flex; gap: 2px; }
.stars button { border: 0; background: none; padding: 4px; cursor: pointer; color: var(--line); }
.stars button.on { color: var(--star); }
.stars svg { width: 26px; height: 26px; fill: currentColor; stroke: none; }
.stars.readonly button { cursor: default; }
.stars.readonly svg { width: 20px; height: 20px; }

.counter { display: flex; flex-wrap: wrap; align-items: center; gap: 16px; }
.counter .nums { flex: 1 1 auto; display: flex; gap: 28px; white-space: nowrap; }
.counter .btn { flex: 1 1 100%; }
.counter .num b { display: block; font-size: 28px; line-height: 1.1; font-weight: 700; font-variant-numeric: tabular-nums; }
.counter .num small { font-size: 12px; color: var(--muted); }

.servings { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.stepper { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.stepper button { width: 40px; height: 36px; border: 0; background: transparent; font-size: 18px; cursor: pointer; }
.stepper span { min-width: 56px; text-align: center; font-size: 14px; font-weight: 600; }

.ing-list { margin: 0; padding: 0; list-style: none; }
.ing-list li { display: flex; justify-content: space-between; gap: 16px; padding: 11px 0; border-bottom: 1px dashed var(--line); }
.ing-list li:last-child { border-bottom: 0; }
.ing-list li.head { padding-top: 16px; font-weight: 700; font-size: 14px; color: var(--muted); border-bottom: 0; }
.ing-list .amt { flex: none; font-weight: 600; font-variant-numeric: tabular-nums; }
.ing-list .amt.scaled { color: var(--accent); }

.steps { margin: 0; padding: 0; list-style: none; counter-reset: step; }
.steps li { position: relative; padding: 0 0 20px 44px; white-space: pre-wrap; }
.steps li::before {
  counter-increment: step; content: counter(step);
  position: absolute; left: 0; top: 0; width: 28px; height: 28px; border-radius: 50%;
  display: grid; place-items: center; background: var(--text); color: var(--bg); font-size: 13px; font-weight: 700;
}
.steps li.sec { padding-left: 0; font-weight: 700; color: var(--muted); }
.steps li.sec::before { display: none; }
.memo { white-space: pre-wrap; }
.source { display: inline-flex; align-items: center; gap: 6px; color: var(--accent); font-size: 14px; word-break: break-all; }

.log-list { margin: 8px 0 0; padding: 0; list-style: none; }
.log-list li { display: flex; gap: 10px; align-items: flex-start; padding: 10px 0; border-top: 1px solid var(--line); font-size: 14px; }
.log-list .date { flex: none; width: 92px; font-variant-numeric: tabular-nums; color: var(--muted); }
.log-list .note { flex: 1; white-space: pre-wrap; }
.log-list .icon-btn { width: 32px; height: 32px; color: var(--muted); }

.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 14px; }
.switch { position: relative; width: 48px; height: 28px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: var(--line); transition: .2s; cursor: pointer; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: .2s; box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(20px); }

.fab {
  position: fixed; right: max(16px, calc(50vw - 304px)); bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px); z-index: 20;
  width: 58px; height: 58px; border: 0; border-radius: 20px; background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; box-shadow: 0 8px 24px rgba(200, 96, 58, .35); cursor: pointer;
}
.fab svg.i { width: 26px; height: 26px; stroke-width: 2.2; }

/* ============ 編集画面 ============ */
.photo-pick { position: relative; display: grid; place-items: center; aspect-ratio: 16 / 9; margin-bottom: 20px; border-radius: var(--radius); overflow: hidden; background: var(--surface-2); color: var(--muted); cursor: pointer; }
.photo-pick img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.photo-pick .ph { display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: 14px; }
.photo-pick .change { position: absolute; right: 10px; bottom: 10px; padding: 6px 12px; border-radius: 999px; background: rgba(0,0,0,.55); color: #fff; font-size: 13px; }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.ing-edit, .step-edit { display: flex; gap: 8px; align-items: flex-start; margin-bottom: 8px; }
.ing-edit .input:first-child { flex: 1.4; }
.ing-edit .input:nth-child(2) { flex: 1; }
.step-edit .no { flex: none; width: 26px; padding-top: 11px; text-align: center; font-weight: 700; color: var(--muted); }
.step-edit textarea { flex: 1; min-height: 64px; }
.ing-edit .icon-btn, .step-edit .icon-btn { color: var(--muted); flex: none; }
.add-line { display: inline-flex; align-items: center; gap: 4px; padding: 6px 0; border: 0; background: none; color: var(--accent); font-weight: 600; text-align: left; cursor: pointer; }
.import-box { padding: 16px; margin-bottom: 20px; }
.import-box .line { display: flex; gap: 8px; }
.import-box .line .input { flex: 1; min-width: 0; }
.warn { margin-top: 10px; padding: 10px 12px; border-radius: 10px; background: color-mix(in srgb, var(--star) 16%, transparent); font-size: 13px; }
.save-bar { position: sticky; bottom: 0; margin: 24px -16px 0; padding: 12px 16px calc(env(safe-area-inset-bottom) + 12px); background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); }

/* ============ 記録（グラフ・カレンダー） ============ */
.stat-tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat-tile { padding: 14px; }
.stat-tile b { display: block; font-size: 26px; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat-tile small { font-size: 12px; color: var(--muted); }
.chart { padding: 16px 12px 8px; }
.chart svg { width: 100%; height: auto; display: block; }
.chart .bar { cursor: pointer; }
.legend { display: flex; gap: 16px; justify-content: flex-end; padding: 0 4px 8px; font-size: 12px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.month-nav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.month-nav b { font-size: 16px; }
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; padding: 12px; }
.cal .dow { text-align: center; font-size: 11px; color: var(--muted); padding-bottom: 4px; }
.cal .dow:first-child { color: var(--danger); }
.cal .day { aspect-ratio: 1; border: 0; border-radius: 10px; background: transparent; display: flex; flex-direction: column; align-items: center; justify-content: flex-start; padding-top: 6px; gap: 3px; font-size: 13px; font-variant-numeric: tabular-nums; cursor: pointer; }
.cal .day.today { font-weight: 800; color: var(--accent); }
.cal .day.sel { background: var(--surface-2); }
.cal .day .dots { display: flex; gap: 2px; }
.cal .day .dot { width: 6px; height: 6px; }
.cal .day.has { background: color-mix(in srgb, var(--accent) 10%, transparent); }
.cal .day.has.sel { background: color-mix(in srgb, var(--accent) 22%, transparent); }
.rank { margin: 0; padding: 0; list-style: none; }
.rank li { display: flex; align-items: center; gap: 12px; padding: 8px 0; }
.rank .n { width: 22px; text-align: center; font-weight: 800; color: var(--muted); }
.rank .thumb { width: 44px; height: 44px; border-radius: 10px; }
.rank .t { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank .c { font-weight: 700; font-variant-numeric: tabular-nums; }

/* ============ 買い物リスト ============ */
.shop-group { margin-bottom: 18px; }
.shop-group h3 { margin: 0 0 4px; font-size: 13px; color: var(--muted); font-weight: 700; }
.shop-item { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.shop-item .check { width: 26px; height: 26px; flex: none; border: 2px solid var(--line); border-radius: 8px; background: transparent; display: grid; place-items: center; cursor: pointer; color: transparent; }
.shop-item.done .check { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.shop-item .check svg.i { width: 16px; height: 16px; stroke-width: 3; }
.shop-item .txt { flex: 1; }
.shop-item.done .txt { color: var(--muted); text-decoration: line-through; }
.shop-item .icon-btn { width: 32px; height: 32px; color: var(--muted); }
.add-row { display: flex; gap: 8px; margin-bottom: 20px; }
.add-row .input { flex: 1; }

/* ============ 設定 ============ */
.list-group { overflow: hidden; }
.list-item { display: flex; align-items: center; gap: 10px; min-height: 52px; padding: 6px 8px 6px 16px; border-bottom: 1px solid var(--line); }
.list-item:last-child { border-bottom: 0; }
.list-item .grow { flex: 1; }
.list-item .icon-btn { width: 36px; height: 36px; color: var(--muted); }
button.list-item { width: 100%; border: 0; border-bottom: 1px solid var(--line); background: transparent; text-align: left; cursor: pointer; }

/* ============ ログイン ============ */
.login { max-width: 360px; margin: 12vh auto 0; }
.login .logo { width: 72px; height: 72px; border-radius: 20px; margin-bottom: 20px; }
.login h1 { margin: 0 0 4px; font-size: 26px; }
.login p { margin: 0 0 28px; color: var(--muted); font-size: 14px; }
.error { color: var(--danger); font-size: 14px; min-height: 1.6em; }

/* ============ タブバー ============ */
#tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; justify-content: center;
  padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--surface) 90%, transparent);
  backdrop-filter: saturate(1.4) blur(16px); -webkit-backdrop-filter: saturate(1.4) blur(16px);
  border-top: 1px solid var(--line);
}
#tabbar .inner { display: flex; width: 100%; max-width: 640px; height: var(--tabbar-h); }
#tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: 10.5px; color: var(--muted); font-weight: 600; }
#tabbar a.on { color: var(--text); }
#tabbar a.on svg.i { stroke-width: 2.2; }

/* ============ モーダル・トースト・バナー ============ */
.modal-back { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.4); display: flex; align-items: flex-end; justify-content: center; animation: fade .15s; }
.modal { width: 100%; max-width: 640px; max-height: 88vh; overflow-y: auto; padding: 8px 16px calc(env(safe-area-inset-bottom) + 16px); border-radius: 22px 22px 0 0; background: var(--bg); animation: up .2s ease-out; }
.modal .grab { width: 40px; height: 5px; margin: 4px auto 12px; border-radius: 3px; background: var(--line); }
.modal h3 { margin: 0 0 16px; font-size: 18px; }
.modal .actions { display: flex; gap: 10px; margin-top: 8px; }
.modal .actions .btn { flex: 1; }
.check-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 15px; }
.check-row input { width: 20px; height: 20px; accent-color: var(--accent); }
@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(40px); opacity: .5; } }

#toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 20px); z-index: 60;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  padding: 10px 18px; border-radius: 999px; background: var(--text); color: var(--bg); font-size: 14px; font-weight: 600;
  transition: .2s; white-space: nowrap; max-width: calc(100vw - 32px); overflow: hidden; text-overflow: ellipsis;
}
#toast.show { transform: translate(-50%, 0); opacity: 1; }
#offline-banner { position: sticky; top: 0; z-index: 40; padding: calc(env(safe-area-inset-top) + 4px) 16px 4px; text-align: center; font-size: 12px; font-weight: 600; background: var(--text); color: var(--bg); }

.spinner { width: 22px; height: 22px; border: 2.5px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; margin: 40px auto; }
.btn .spinner { width: 18px; height: 18px; margin: 0; border-color: rgba(255,255,255,.35); border-top-color: currentColor; }
@keyframes spin { to { transform: rotate(360deg); } }
