:root {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  color-scheme: light dark;
  --accent: #bb654d;
  --accent-soft: #f2e3da;
  --canvas: #f7f4ee;
  --surface: #fffdf9;
  --surface-alt: #f0ece4;
  --ink: #292721;
  --muted: #827d73;
  --line: #e8e2d8;
  --shadow: 0 14px 40px rgba(56, 44, 31, .08);
  --serif: Georgia, 'Times New Roman', serif;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --canvas: #191a18;
    --surface: #232421;
    --surface-alt: #2c2d29;
    --ink: #f0eee7;
    --muted: #aaa79e;
    --line: #393a35;
    --accent-soft: #49352e;
    --shadow: 0 14px 40px rgba(0, 0, 0, .22);
  }
}

:root[data-theme='dark'] {
  --canvas: #191a18;
  --surface: #232421;
  --surface-alt: #2c2d29;
  --ink: #f0eee7;
  --muted: #aaa79e;
  --line: #393a35;
  --accent-soft: #49352e;
  --shadow: 0 14px 40px rgba(0, 0, 0, .22);
}

:root[data-theme='light'] {
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { min-width: 320px; background: var(--canvas); }
body { margin: 0; min-height: 100vh; min-height: 100dvh; background: var(--canvas); color: var(--ink); }
button, input, textarea, select { font: inherit; }
button { color: inherit; }
button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 2px; }
button:disabled { opacity: .5; }
.app-shell { min-height: 100vh; min-height: 100dvh; padding-bottom: calc(88px + env(safe-area-inset-bottom)); }
.page { width: min(100% - 36px, 1160px); margin: 0 auto; padding-top: max(28px, env(safe-area-inset-top)); }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 34px; }
.brand { display: flex; align-items: center; gap: 11px; min-width: 0; }
.brand-mark { width: 38px; height: 38px; border-radius: 13px; flex: 0 0 auto; }
.brand-name { font-family: var(--serif); font-size: 21px; font-weight: 600; letter-spacing: -.04em; }
.brand-caption { display: block; color: var(--muted); font-size: 11px; margin-top: 1px; }
.icon-button, .quiet-button, .primary-button, .secondary-button, .danger-button, .nav-item, .filter-chip, .rating-star { border: 0; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.icon-button { display: inline-grid; place-items: center; width: 44px; height: 44px; border-radius: 15px; background: var(--surface); color: var(--ink); box-shadow: 0 2px 12px rgba(36, 30, 22, .04); }
.icon-button svg, .nav-item svg { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.intro { margin: 0 0 25px; }
.eyebrow { color: var(--accent); font-size: 11px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; }
h1, h2, h3, p { margin-top: 0; }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; }
.intro h1 { margin: 7px 0 8px; font-size: clamp(34px, 8vw, 46px); letter-spacing: -.055em; line-height: 1.05; }
.intro p { max-width: 580px; margin-bottom: 0; color: var(--muted); font-size: 14px; line-height: 1.55; }
.toolbar { display: flex; gap: 12px; align-items: center; margin: 23px 0 20px; }
.search-wrap { position: relative; flex: 1; min-width: 0; }
.search-wrap svg { position: absolute; left: 16px; top: 50%; width: 19px; height: 19px; transform: translateY(-50%); stroke: var(--muted); fill: none; stroke-width: 1.8; }
.search-input { width: 100%; min-height: 52px; padding: 0 18px 0 46px; border: 1px solid var(--line); border-radius: 17px; background: var(--surface); color: var(--ink); }
.primary-button, .secondary-button, .danger-button, .quiet-button { display: inline-flex; justify-content: center; align-items: center; gap: 9px; min-height: 48px; padding: 0 18px; border-radius: 15px; font-weight: 600; transition: transform .16s ease, background .16s ease; }
.primary-button { background: var(--accent); color: #fffaf5; box-shadow: 0 7px 18px color-mix(in srgb, var(--accent) 24%, transparent); }
.primary-button:hover, .secondary-button:hover, .quiet-button:hover, .icon-button:hover { transform: translateY(-1px); }
.primary-button svg, .secondary-button svg, .quiet-button svg, .danger-button svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.secondary-button { background: var(--accent-soft); color: var(--accent); }
.quiet-button { background: transparent; color: var(--muted); }
.danger-button { color: #b5473b; background: color-mix(in srgb, #c34f3d 11%, var(--surface)); }
.mobile-add { display: none; }
.section-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin: 30px 0 15px; }
.section-heading h2 { margin: 0; font-size: 23px; letter-spacing: -.04em; }
.result-count { color: var(--muted); font-size: 12px; }
.category-row { display: flex; gap: 8px; overflow: auto; padding: 2px 1px 7px; scrollbar-width: none; }
.category-row::-webkit-scrollbar { display: none; }
.filter-chip { flex: 0 0 auto; min-height: 37px; padding: 0 14px; border: 1px solid var(--line); border-radius: 99px; background: var(--surface); color: var(--muted); font-size: 12px; font-weight: 600; }
.filter-chip.active { border-color: var(--accent); background: var(--accent); color: #fffaf5; }
.recipe-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 17px; margin-top: 11px; }
.recipe-card { overflow: hidden; border: 1px solid var(--line); border-radius: 21px; background: var(--surface); box-shadow: 0 6px 22px rgba(44, 35, 27, .035); transition: transform .2s ease, box-shadow .2s ease; }
.recipe-card:hover { transform: translateY(-3px); box-shadow: var(--shadow); }
.card-open { display: block; width: 100%; padding: 0; border: 0; background: transparent; color: inherit; text-align: left; cursor: pointer; }
.card-image, .card-placeholder { display: grid; width: 100%; aspect-ratio: 1.58; place-items: center; overflow: hidden; background: linear-gradient(135deg, var(--accent-soft), var(--surface-alt)); color: var(--accent); }
.card-image { object-fit: cover; }
.card-placeholder svg { width: 43px; height: 43px; stroke: currentColor; fill: none; stroke-width: 1.2; opacity: .68; }
.card-content { padding: 14px 15px 16px; }
.card-meta { display: flex; justify-content: space-between; gap: 9px; color: var(--muted); font-size: 11px; }
.card-content h3 { overflow: hidden; margin: 8px 0 6px; font-size: 20px; letter-spacing: -.035em; text-overflow: ellipsis; white-space: nowrap; }
.card-description { display: -webkit-box; min-height: 36px; overflow: hidden; margin: 0; color: var(--muted); font-size: 12px; line-height: 1.5; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.card-footer { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); color: var(--muted); font-size: 11px; }
.tag-pill { overflow: hidden; max-width: 120px; padding: 5px 9px; border-radius: 99px; background: var(--surface-alt); text-overflow: ellipsis; white-space: nowrap; }
.favorite-mark { color: var(--accent); font-size: 16px; }
.empty-state { padding: 50px 20px; border: 1px dashed var(--line); border-radius: 22px; background: color-mix(in srgb, var(--surface) 55%, transparent); text-align: center; }
.empty-state .empty-icon { display: grid; width: 57px; height: 57px; place-items: center; margin: 0 auto 15px; border-radius: 20px; background: var(--accent-soft); color: var(--accent); font-size: 26px; }
.empty-state h2 { margin-bottom: 7px; font-size: 23px; }
.empty-state p { max-width: 370px; margin: 0 auto 18px; color: var(--muted); font-size: 13px; line-height: 1.55; }
.bottom-nav { position: fixed; z-index: 5; right: 0; bottom: 0; left: 0; display: flex; justify-content: center; gap: min(5vw, 54px); padding: 9px 14px calc(9px + env(safe-area-inset-bottom)); border-top: 1px solid color-mix(in srgb, var(--line) 85%, transparent); background: color-mix(in srgb, var(--surface) 91%, transparent); backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px); }
.nav-item { display: grid; min-width: 66px; justify-items: center; gap: 4px; padding: 4px 12px; border-radius: 13px; background: transparent; color: var(--muted); font-size: 10px; font-weight: 600; }
.nav-item.active { color: var(--accent); }
.detail-page, .editor-page, .settings-page { padding-bottom: 24px; }
.backline { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 17px; }
.back-button { display: inline-flex; align-items: center; gap: 8px; min-height: 42px; padding: 0 12px 0 0; border: 0; background: transparent; color: var(--muted); font-size: 13px; font-weight: 600; cursor: pointer; }
.back-button svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 1.8; }
.detail-actions { display: flex; gap: 7px; }
.detail-hero { overflow: hidden; max-height: 450px; border-radius: 24px; background: linear-gradient(135deg, var(--accent-soft), var(--surface-alt)); }
.detail-hero img { display: block; width: 100%; max-height: 450px; object-fit: cover; }
.detail-hero .card-placeholder { aspect-ratio: 1.9; }
.detail-title { padding: 24px 4px 8px; }
.detail-title h1 { margin: 7px 0 9px; font-size: clamp(34px, 8vw, 48px); letter-spacing: -.055em; line-height: 1.05; }
.detail-title p { max-width: 690px; margin: 0; color: var(--muted); line-height: 1.6; }
.detail-stats { display: flex; flex-wrap: wrap; gap: 9px; margin: 18px 0 28px; }
.stat-chip { padding: 9px 12px; border-radius: 12px; background: var(--surface-alt); color: var(--ink); font-size: 12px; }
.detail-columns { display: grid; grid-template-columns: minmax(220px, .8fr) minmax(0, 1.2fr); gap: 30px; }
.detail-block { padding: 20px 0; border-top: 1px solid var(--line); }
.detail-block h2 { margin: 0 0 14px; font-size: 24px; letter-spacing: -.04em; }
.ingredient-list, .step-list { margin: 0; padding: 0; list-style: none; }
.ingredient-list li { display: flex; align-items: baseline; gap: 11px; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 14px; line-height: 1.45; }
.ingredient-amount { min-width: 51px; color: var(--accent); font-weight: 700; }
.step-list { counter-reset: cooking; }
.step-list li { position: relative; padding: 0 0 18px 42px; color: var(--ink); font-size: 14px; line-height: 1.65; counter-increment: cooking; }
.step-list li::before { position: absolute; left: 0; top: 0; display: grid; width: 28px; height: 28px; place-items: center; border-radius: 50%; background: var(--accent-soft); color: var(--accent); content: counter(cooking); font-size: 12px; font-weight: 700; }
.detail-note { padding: 15px; border-radius: 15px; background: var(--surface-alt); color: var(--muted); font-size: 13px; line-height: 1.55; white-space: pre-wrap; }
.source-link { color: var(--accent); overflow-wrap: anywhere; }
.editor-head h1, .settings-head h1 { margin: 4px 0 7px; font-size: 35px; letter-spacing: -.05em; }
.editor-head p, .settings-head p { color: var(--muted); font-size: 13px; line-height: 1.55; }
.form-section { margin-top: 26px; }
.form-section h2 { margin-bottom: 13px; font-size: 21px; letter-spacing: -.035em; }
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.field { display: grid; gap: 7px; margin-bottom: 14px; }
.field.full { grid-column: 1 / -1; }
.field label, .field-label { color: var(--muted); font-size: 12px; font-weight: 600; }
.field input, .field textarea, .field select { width: 100%; min-height: 48px; padding: 12px 13px; border: 1px solid var(--line); border-radius: 13px; background: var(--surface); color: var(--ink); }
.field textarea { min-height: 92px; resize: vertical; line-height: 1.5; }
.field input[type='number'] { appearance: textfield; }
.field input[type='file'] { padding: 9px; }
.field-hint { color: var(--muted); font-size: 11px; line-height: 1.4; }
.ingredients-editor, .steps-editor { display: grid; gap: 8px; }
.ingredient-row { display: grid; grid-template-columns: minmax(75px, .35fr) minmax(0, 1fr) 39px; gap: 8px; }
.step-row { display: grid; grid-template-columns: 31px minmax(0, 1fr) 39px; align-items: start; gap: 8px; }
.step-number { display: grid; width: 28px; height: 42px; place-items: center; color: var(--accent); font-size: 13px; font-weight: 700; }
.ingredient-row input, .step-row textarea { min-width: 0; width: 100%; min-height: 43px; padding: 10px 11px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); color: var(--ink); }
.step-row textarea { min-height: 64px; resize: vertical; line-height: 1.45; }
.remove-row { width: 39px; height: 42px; border: 0; border-radius: 12px; background: var(--surface-alt); color: var(--muted); font-size: 18px; cursor: pointer; }
.add-row { margin-top: 10px; }
.photo-preview { display: grid; overflow: hidden; width: min(100%, 400px); aspect-ratio: 1.7; place-items: center; margin: 0 0 12px; border-radius: 16px; background: var(--surface-alt); color: var(--muted); }
.photo-preview img { width: 100%; height: 100%; object-fit: cover; }
.rating-control { display: flex; gap: 3px; }
.rating-star { padding: 5px 6px; background: transparent; color: var(--line); font-size: 25px; line-height: 1; }
.rating-star.selected { color: var(--accent); }
.check-line { display: flex; align-items: center; gap: 10px; color: var(--ink); font-size: 13px; }
.check-line input { width: 18px; height: 18px; accent-color: var(--accent); }
.duplicate-warning { margin: 10px 0; padding: 12px 14px; border-radius: 13px; background: #f5e9d8; color: #705633; font-size: 12px; line-height: 1.5; }
.form-actions { position: sticky; z-index: 3; bottom: calc(10px + env(safe-area-inset-bottom)); display: flex; justify-content: flex-end; gap: 10px; margin: 26px 0 15px; padding: 12px; border: 1px solid var(--line); border-radius: 18px; background: color-mix(in srgb, var(--surface) 94%, transparent); box-shadow: var(--shadow); backdrop-filter: blur(12px); }
.settings-card { margin-top: 18px; padding: 18px; border: 1px solid var(--line); border-radius: 18px; background: var(--surface); }
.settings-card h2 { margin: 0 0 8px; font-size: 20px; }
.settings-card p { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.6; }
.settings-row { display: flex; align-items: center; justify-content: space-between; gap: 15px; padding: 13px 0; border-bottom: 1px solid var(--line); }
.settings-row:last-child { padding-bottom: 0; border: 0; }
.settings-row:first-of-type { padding-top: 4px; }
.settings-row strong { display: block; font-size: 13px; }
.settings-row small { display: block; margin-top: 4px; color: var(--muted); font-size: 11px; line-height: 1.4; }
.settings-select { min-width: 120px; min-height: 40px; padding: 0 10px; border: 1px solid var(--line); border-radius: 11px; background: var(--surface-alt); color: var(--ink); }
.accent-options { display: flex; gap: 8px; }
.accent-option { width: 29px; height: 29px; border: 3px solid var(--surface); border-radius: 50%; box-shadow: 0 0 0 1px var(--line); cursor: pointer; }
.accent-option.active { box-shadow: 0 0 0 2px var(--ink); }
.backup-actions { display: flex; flex-wrap: wrap; gap: 9px; margin-top: 14px; }
.import-page { padding-bottom: 36px; }
.import-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.import-card { margin-top: 0; }
.import-card > p { margin-bottom: 14px; }
.import-card .field textarea { min-height: 185px; }
.file-label { position: relative; overflow: hidden; cursor: pointer; }
.file-label input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
.file-label .file-hidden { clip: auto; clip-path: none; white-space: normal; }
.import-message { margin: 18px 0 0; padding: 13px 15px; border-radius: 14px; background: var(--accent-soft); color: var(--ink); font-size: 13px; line-height: 1.55; }
.import-results { margin-top: 28px; }
.import-candidate { display: flex; justify-content: space-between; align-items: center; gap: 18px; margin: 10px 0; padding: 16px; border: 1px solid var(--line); border-radius: 17px; background: var(--surface); }
.import-candidate h3 { margin: 6px 0 4px; font-size: 19px; }
.import-candidate p { margin: 0; color: var(--muted); font-size: 12px; }
.import-candidate a { color: var(--accent); }
.import-privacy { margin-top: 18px; line-height: 1.5; }
.original-text { overflow: auto; max-height: 300px; padding: 14px; border-radius: 14px; background: var(--surface-alt); color: var(--muted); font: 12px/1.55 ui-monospace, SFMono-Regular, Menlo, monospace; white-space: pre-wrap; overflow-wrap: anywhere; }
.file-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; clip-path: inset(50%); }
.toast { position: fixed; z-index: 10; right: 18px; bottom: calc(91px + env(safe-area-inset-bottom)); left: 18px; width: fit-content; max-width: min(500px, calc(100% - 36px)); margin: auto; padding: 12px 16px; border-radius: 13px; background: var(--ink); color: var(--canvas); box-shadow: var(--shadow); font-size: 13px; animation: toast-in .2s ease-out; }
.toast.error { background: #a53c32; color: white; }
.loading { display: grid; min-height: 100vh; place-items: center; color: var(--muted); }
.loading-mark { margin-bottom: 10px; font-family: var(--serif); font-size: 26px; color: var(--accent); text-align: center; }
.small-muted { color: var(--muted); font-size: 11px; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

@media (max-width: 820px) {
  .recipe-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .detail-columns { gap: 22px; }
}
@media (max-width: 600px) {
  .page { width: min(100% - 34px, 560px); padding-top: max(22px, env(safe-area-inset-top)); }
  .topbar { margin-bottom: 28px; }
  .intro { margin-bottom: 20px; }
  .intro h1 { font-size: 38px; }
  .intro p { font-size: 13px; }
  .toolbar { gap: 9px; margin-top: 19px; }
  .desktop-add { display: none; }
  .mobile-add { position: fixed; z-index: 4; right: 19px; bottom: calc(84px + env(safe-area-inset-bottom)); display: grid; width: 56px; height: 56px; place-items: center; border: 0; border-radius: 19px; background: var(--accent); color: #fffaf5; box-shadow: 0 8px 25px color-mix(in srgb, var(--accent) 40%, transparent); cursor: pointer; }
  .mobile-add svg { width: 23px; height: 23px; stroke: currentColor; fill: none; stroke-width: 2; }
  .section-heading { margin-top: 27px; }
  .recipe-grid { grid-template-columns: minmax(0, 1fr); gap: 13px; }
  .recipe-card { display: grid; grid-template-columns: 112px minmax(0, 1fr); min-height: 130px; border-radius: 18px; }
  .card-open { display: contents; }
  .card-image, .card-placeholder { grid-row: 1; grid-column: 1; width: 112px; height: 100%; min-height: 130px; aspect-ratio: auto; }
  .card-placeholder svg { width: 33px; }
  .card-content { grid-row: 1; grid-column: 2; display: flex; flex-direction: column; justify-content: center; min-width: 0; padding: 12px 13px; }
  .card-content h3 { margin-top: 6px; font-size: 18px; }
  .card-description { min-height: 0; }
  .card-footer { margin-top: 9px; padding-top: 8px; }
  .bottom-nav { justify-content: space-around; gap: 0; padding-right: 6px; padding-left: 6px; }
  .nav-item { min-width: 62px; padding-right: 8px; padding-left: 8px; }
  .detail-columns { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .detail-title { padding-top: 20px; }
  .detail-actions .icon-button { width: 40px; height: 40px; }
  .field-grid { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .field.full { grid-column: auto; }
  .editor-head h1, .settings-head h1 { font-size: 32px; }
  .form-actions { justify-content: stretch; }
  .form-actions > button { flex: 1; padding: 0 11px; }
  .import-grid { grid-template-columns: minmax(0, 1fr); }
  .import-candidate { align-items: flex-start; flex-direction: column; }
  .import-candidate > button { width: 100%; }
}
@media (max-width: 360px) {
  .recipe-card { grid-template-columns: 93px minmax(0, 1fr); }
  .card-image, .card-placeholder { width: 93px; }
  .card-content { padding: 10px; }
  .card-content h3 { font-size: 16px; }
  .card-footer { font-size: 10px; }
  .filter-chip { padding: 0 11px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
