:root {
  color-scheme: light;
  --ink: #173c35;
  --ink-2: #2f554e;
  --cream: #f5f1e8;
  --paper: #fffdf8;
  --line: #ded8ca;
  --muted: #6c766f;
  --orange: #df6b43;
  --gold: #eebd65;
  --green-soft: #dce9df;
  --shadow: 0 16px 50px rgba(23, 60, 53, 0.12);
  --radius: 22px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--cream);
  color: var(--ink);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; min-height: 100vh; background: var(--cream); }
button, input, select, textarea { font: inherit; }
button { color: inherit; }
img { max-width: 100%; display: block; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.eyebrow { margin: 0 0 .55rem; color: var(--orange); font-size: .73rem; font-weight: 800; letter-spacing: .16em; }
.stack { display: grid; gap: 1rem; }

label { display: grid; gap: .45rem; font-size: .82rem; font-weight: 750; color: var(--ink-2); }
input, select, textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 12px; background: var(--paper);
  padding: .83rem .9rem; color: var(--ink); outline: none; transition: border-color .18s, box-shadow .18s;
}
input:focus, select:focus, textarea:focus { border-color: var(--ink-2); box-shadow: 0 0 0 3px rgba(47, 85, 78, .12); }
textarea { resize: vertical; }
.check { display: flex; align-items: center; gap: .55rem; min-height: 44px; }
.check input { width: 18px; height: 18px; accent-color: var(--ink); }

.button { border: 0; border-radius: 999px; padding: .82rem 1.18rem; font-weight: 800; cursor: pointer; transition: transform .16s, filter .16s; }
.button:hover { transform: translateY(-1px); filter: brightness(1.03); }
.button.primary { color: #fff; background: var(--ink); }
.button.secondary { color: var(--ink); background: var(--paper); border: 1px solid var(--line); }
.text-button, .nav-link, .mobile-nav button { border: 0; background: transparent; cursor: pointer; }
.text-button { color: var(--ink-2); font-weight: 750; text-decoration: underline; text-underline-offset: 4px; }
.icon-button { width: 38px; height: 38px; border: 1px solid var(--line); background: var(--paper); border-radius: 50%; cursor: pointer; }

.auth-shell { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem; background: radial-gradient(circle at 15% 20%, #f4d99f, transparent 35%), var(--cream); }
.auth-card { width: min(430px, 100%); background: rgba(255,253,248,.95); border: 1px solid rgba(222,216,202,.8); border-radius: 28px; box-shadow: var(--shadow); padding: clamp(1.8rem, 6vw, 3rem); }
.brand-icon { width: 58px; height: 58px; margin-bottom: 1.5rem; }
.auth-card h1 { margin: 0 0 .5rem; font-family: Georgia, serif; font-size: 2.35rem; }
.auth-card .muted { margin: 0 0 1.8rem; }
.form-error { min-height: 1.25rem; color: #a3322a; font-size: .85rem; }

.topbar { position: sticky; top: 0; z-index: 20; height: 76px; display: flex; align-items: center; justify-content: space-between; gap: 2rem; padding: 0 clamp(1rem, 4vw, 4rem); background: rgba(245,241,232,.9); backdrop-filter: blur(16px); border-bottom: 1px solid rgba(222,216,202,.75); }
.brand { display: flex; align-items: center; gap: .72rem; color: inherit; text-decoration: none; }
.brand img { width: 42px; height: 42px; }
.brand strong, .brand small { display: block; }
.brand strong { font-family: Georgia, serif; font-size: 1.14rem; }
.brand small { color: var(--muted); font-size: .66rem; letter-spacing: .08em; text-transform: uppercase; }
.desktop-nav { display: flex; gap: .3rem; }
.nav-link { padding: .65rem 1rem; color: var(--muted); font-weight: 700; border-radius: 999px; }
.nav-link.active { color: var(--ink); background: var(--green-soft); }
.user-menu { display: flex; align-items: center; gap: .7rem; font-size: .86rem; font-weight: 750; }

.page-section { width: min(1220px, calc(100% - 2rem)); margin: 0 auto; padding: clamp(2rem, 5vw, 4.4rem) 0 6rem; }
.hero { display: flex; align-items: end; justify-content: space-between; gap: 2rem; margin-bottom: 2rem; }
.hero h1, .section-title h1 { margin: 0; max-width: 790px; font-family: Georgia, serif; font-size: clamp(2.2rem, 6vw, 4.7rem); line-height: .98; font-weight: 500; letter-spacing: -.035em; }
.hero h1 em { color: var(--orange); font-weight: 500; }

.search-panel { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 12px 30px rgba(23,60,53,.07); padding: .8rem; }
.natural-search { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: .7rem; }
.natural-search input { min-width: 0; border: 0; box-shadow: none; background: transparent; font-size: clamp(.95rem, 2vw, 1.08rem); }
.search-icon { font-size: 1.6rem; padding-left: .45rem; }
details { border-top: 1px solid var(--line); margin-top: .75rem; padding: .65rem .5rem .1rem; }
summary { cursor: pointer; font-size: .82rem; font-weight: 750; color: var(--muted); }
.filter-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; padding: 1rem .2rem .4rem; }
.filter-grid .check { align-self: end; }

.results-heading { display: flex; align-items: end; justify-content: space-between; margin: 3rem 0 1.2rem; }
.results-heading h2 { margin: 0; font-family: Georgia, serif; font-size: clamp(1.7rem, 4vw, 2.5rem); font-weight: 500; }
.recipe-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1.25rem; }
.recipe-card { position: relative; overflow: hidden; border: 1px solid var(--line); border-radius: 20px; background: var(--paper); cursor: pointer; transition: transform .2s, box-shadow .2s; }
.recipe-card:hover { transform: translateY(-4px); box-shadow: var(--shadow); }
.recipe-card .photo { aspect-ratio: 1.37; width: 100%; object-fit: cover; background: var(--green-soft); }
.card-body { padding: 1.1rem; }
.card-meta { display: flex; align-items: center; justify-content: space-between; color: var(--muted); font-size: .76rem; }
.card-body h3 { margin: .5rem 0 .8rem; min-height: 2.7em; font-family: Georgia, serif; font-size: 1.25rem; line-height: 1.18; font-weight: 600; }
.pill-row { display: flex; flex-wrap: wrap; gap: .4rem; }
.pill { display: inline-flex; align-items: center; gap: .25rem; padding: .32rem .55rem; border-radius: 999px; background: var(--green-soft); color: var(--ink-2); font-size: .7rem; font-weight: 750; }
.pill.orange { background: #f7dfd5; color: #8e3d28; }
.favorite-button { position: absolute; top: .75rem; right: .75rem; z-index: 2; width: 38px; height: 38px; border: 0; border-radius: 50%; background: rgba(255,253,248,.9); cursor: pointer; font-size: 1.12rem; box-shadow: 0 5px 16px rgba(0,0,0,.12); }
.favorite-button.active { color: var(--orange); }
.empty-state { text-align: center; padding: 4rem 1rem; }
.empty-state span { font-size: 3rem; }
.empty-state h3 { font-family: Georgia, serif; font-size: 1.7rem; margin-bottom: .3rem; }

.section-title { margin-bottom: 2rem; }
.section-title h1 { font-size: clamp(2.3rem, 5vw, 4rem); }
.section-title p:last-child { color: var(--muted); }
.profile-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.3rem; align-items: start; }
.panel { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.5rem; }
.panel h2 { margin-top: 0; font-family: Georgia, serif; font-weight: 500; }
.device-card, .history-item, .plan-item { display: flex; gap: .8rem; align-items: center; padding: .9rem 0; border-bottom: 1px solid var(--line); }
.device-card:last-child, .history-item:last-child, .plan-item:last-child { border-bottom: 0; }
.device-card { justify-content: space-between; }
.device-card-copy { min-width: 0; }
.device-card strong, .history-item strong { display: block; }
.device-card small, .history-item small { color: var(--muted); }
.danger { color: #a3322a; }
.history-item img, .plan-item img { width: 62px; height: 48px; border-radius: 10px; object-fit: cover; }
.plan-list { display: grid; gap: .8rem; }
.plan-item { background: var(--paper); border: 1px solid var(--line); border-radius: 16px; padding: 1rem; }

dialog { color: var(--ink); border: 0; padding: 0; box-shadow: 0 24px 80px rgba(14,42,37,.3); }
dialog::backdrop { background: rgba(13,34,30,.67); backdrop-filter: blur(5px); }
.dialog-close { position: absolute; top: 1rem; right: 1rem; z-index: 5; width: 42px; height: 42px; border: 0; border-radius: 50%; background: rgba(255,253,248,.92); font-size: 1.6rem; cursor: pointer; }
.recipe-dialog { width: min(980px, calc(100% - 1.2rem)); max-height: calc(100vh - 1.2rem); border-radius: 26px; background: var(--paper); }
.recipe-hero { position: relative; display: grid; grid-template-columns: 1.05fr 1fr; min-height: 370px; }
.recipe-hero img { width: 100%; height: 100%; object-fit: cover; }
.recipe-hero-copy { padding: clamp(2rem, 5vw, 3.4rem); display: flex; flex-direction: column; justify-content: center; }
.recipe-hero h2 { margin: 0 0 1rem; font-family: Georgia, serif; font-size: clamp(2rem, 5vw, 3.5rem); line-height: 1; font-weight: 500; }
.nutrition-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: .55rem; margin-top: 1rem; }
.nutrition-grid div { border-radius: 12px; background: var(--cream); padding: .65rem; }
.nutrition-grid strong, .nutrition-grid small { display: block; }
.nutrition-grid small { color: var(--muted); font-size: .67rem; }
.recipe-content { padding: clamp(1.2rem, 4vw, 2.6rem); }
.adapt-panel { display: grid; grid-template-columns: 1fr 1fr auto; gap: .8rem; align-items: end; padding: 1rem; margin-bottom: 1.5rem; border-radius: 16px; background: var(--green-soft); }
.recipe-columns { display: grid; grid-template-columns: .8fr 1.2fr; gap: 2.2rem; }
.recipe-columns h3 { font-family: Georgia, serif; font-size: 1.45rem; }
.ingredient-list { list-style: none; padding: 0; }
.ingredient-list li { padding: .58rem 0; border-bottom: 1px solid var(--line); }
.step-list { list-style: none; padding: 0; counter-reset: steps; }
.step-list li { position: relative; padding: 0 0 1.15rem 2.7rem; line-height: 1.55; }
.step-list li::before { counter-increment: steps; content: counter(steps); position: absolute; left: 0; top: -.2rem; display: grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; background: var(--ink); color: white; font-weight: 800; font-size: .78rem; }
.tips-box { margin-top: 1.5rem; padding: 1.2rem; border-left: 4px solid var(--gold); background: #fff7e7; border-radius: 0 14px 14px 0; }
.personal-panel { margin-top: 1.4rem; display: grid; grid-template-columns: 1fr 160px auto; gap: .8rem; align-items: end; }
.device-note { margin-top: .8rem; padding: .85rem 1rem; border-radius: 12px; background: #fff7e7; font-size: .84rem; }
.form-dialog { width: min(620px, calc(100% - 1.2rem)); max-height: calc(100vh - 1.2rem); border-radius: 24px; padding: 2rem; background: var(--paper); }
.two-columns { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.toast { position: fixed; left: 50%; bottom: 2rem; z-index: 100; transform: translate(-50%, 140%); padding: .85rem 1.1rem; border-radius: 999px; background: var(--ink); color: white; font-weight: 700; box-shadow: var(--shadow); transition: transform .25s; }
.toast.show { transform: translate(-50%, 0); }
.mobile-nav { display: none; }

@media (max-width: 900px) {
  .filter-grid { grid-template-columns: 1fr 1fr; }
  .recipe-grid { grid-template-columns: 1fr 1fr; }
  .recipe-hero { grid-template-columns: 1fr; }
  .recipe-hero img { max-height: 360px; }
  .recipe-columns { grid-template-columns: 1fr; }
  .profile-grid { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  body { padding-bottom: 70px; }
  .topbar { height: 66px; }
  .desktop-nav, .user-menu #user-name { display: none; }
  .brand small { display: block; }
  .page-section { width: min(100% - 1.15rem, 1220px); padding-top: 2rem; }
  .hero { align-items: start; flex-direction: column; }
  .hero h1 { font-size: 2.65rem; }
  .hero .button { width: 100%; }
  .natural-search { grid-template-columns: auto 1fr; }
  .natural-search .button { grid-column: 1 / -1; }
  .filter-grid, .recipe-grid, .nutrition-grid, .adapt-panel, .personal-panel, .two-columns { grid-template-columns: 1fr; }
  .results-heading { align-items: start; gap: 1rem; }
  .recipe-card .photo { aspect-ratio: 1.55; }
  .card-body h3 { min-height: auto; }
  .recipe-dialog { width: 100%; height: 100%; max-height: none; border-radius: 0; }
  .recipe-hero img { max-height: 280px; }
  .recipe-hero-copy { padding: 1.5rem; }
  .recipe-content { padding: 1.15rem; }
  .form-dialog { width: 100%; height: 100%; max-height: none; border-radius: 0; }
  .mobile-nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: grid; grid-template-columns: repeat(3, 1fr); padding: .4rem max(.5rem, env(safe-area-inset-right)) calc(.35rem + env(safe-area-inset-bottom)) max(.5rem, env(safe-area-inset-left)); background: rgba(255,253,248,.96); border-top: 1px solid var(--line); backdrop-filter: blur(16px); }
  .mobile-nav button { display: grid; justify-items: center; gap: .1rem; padding: .3rem; color: var(--muted); font-size: .68rem; font-weight: 750; }
  .mobile-nav button span { font-size: 1.3rem; }
  .mobile-nav button.active { color: var(--orange); }
  .toast { bottom: 5.2rem; width: max-content; max-width: calc(100% - 2rem); text-align: center; }
}
