/* ============================================================
   Recipe Box - a warm, tactile recipe keeper.
   Palette: warm paper, espresso ink, paprika red, herb green,
   saffron highlight. Bookish serif titles + humanist sans body.

   Mobile-first: base styles target a ~390px phone used one-handed
   in the kitchen. Desktop layouts (multi-column grid, side-by-side
   ingredients/method, sticky masthead) are layered on top with
   min-width media queries. Touch targets are >= 44px, and text
   inputs are >= 16px so iOS Safari does not zoom on focus.
   ============================================================ */

:root {
  /* light: kitchen paper */
  --paper: #fbf5e9;
  --paper-2: #f1e8d4;
  --card: #fffdf7;
  --ink: #2c211a;
  --ink-soft: #6b5d50;
  --ink-faint: #9a8b7c;
  --line: #e6dcc8;
  --line-strong: #d8caae;

  --paprika: #c14226;
  --paprika-deep: #a5341c;
  --herb: #4f6f43;
  --herb-deep: #3d5834;
  --saffron: #e2a029;

  --shadow-sm: 0 1px 2px rgba(60, 40, 20, 0.06), 0 2px 8px rgba(60, 40, 20, 0.05);
  --shadow-md: 0 6px 22px rgba(60, 40, 20, 0.12);
  --shadow-lg: 0 24px 60px rgba(40, 25, 10, 0.28);

  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, "Times New Roman", serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;

  --radius: 14px;
  --radius-sm: 9px;
  --maxw: 1160px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #1c1714;
    --paper-2: #241d18;
    --card: #26201b;
    --ink: #f2e9db;
    --ink-soft: #c3b4a2;
    --ink-faint: #8f8072;
    --line: #372d25;
    --line-strong: #443a30;

    --paprika: #e0613f;
    --paprika-deep: #c94d2c;
    --herb: #8bad76;
    --herb-deep: #7a9c66;
    --saffron: #edb44a;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.45);
    --shadow-lg: 0 24px 60px rgba(0, 0, 0, 0.6);
  }
}

* { box-sizing: border-box; }

/* The [hidden] attribute must always win over layout display rules
   (e.g. .detail and .empty set display:grid). */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--sans);
  color: var(--ink);
  background-color: var(--paper);
  background-image:
    radial-gradient(circle at 1px 1px, rgba(120, 90, 50, 0.05) 1px, transparent 0);
  background-size: 22px 22px;
  line-height: 1.5;
  min-height: 100vh;
}

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

*:focus-visible {
  outline: 2.5px solid var(--saffron);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ---------- Masthead ---------- */

/* On phones the masthead scrolls away so the recipe list gets the full
   screen; on desktop it stays pinned. */
.masthead {
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, var(--paper-2), var(--paper));
  box-shadow: var(--shadow-sm);
  z-index: 20;
}
@media (min-width: 720px) {
  .masthead {
    position: sticky;
    top: 0;
  }
}

.masthead__inner {
  max-width: var(--maxw);
  margin: 0 auto;
  /* The top inset keeps content clear of the notch in standalone mode. */
  padding: calc(16px + env(safe-area-inset-top, 0px)) clamp(16px, 4vw, 40px) 18px;
}
@media (min-width: 720px) {
  .masthead__inner { padding-top: calc(20px + env(safe-area-inset-top, 0px)); padding-bottom: 22px; }
}

.masthead__top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

/* Account / sign-out control. On phones only the button shows (the email
   would crowd the brand); the email appears from tablet width up. */
.account {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: none;
}
.account__email {
  display: none;
  font-size: 0.82rem;
  color: var(--ink-soft);
  max-width: 30vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
@media (min-width: 720px) {
  .account__email { display: block; }
}
.account__signout {
  min-height: 44px;
  font-family: var(--sans);
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--ink-soft);
  padding: 8px 16px;
  background: var(--card);
  border: 1.5px solid var(--line-strong);
  border-radius: 999px;
  transition: color 0.14s, border-color 0.14s;
}
.account__signout:hover {
  color: var(--paprika-deep);
  border-color: color-mix(in srgb, var(--paprika) 40%, transparent);
}

.brand__mark {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  flex: none;
  color: var(--paper);
  background: var(--paprika);
  border-radius: 12px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.15), var(--shadow-sm);
  transform: rotate(-3deg);
}

.brand__text h1 {
  font-family: var(--serif);
  font-weight: 600;
  font-size: clamp(1.5rem, 3.4vw, 2.05rem);
  letter-spacing: -0.01em;
  margin: 0;
  line-height: 1;
}

.brand__text p {
  margin: 5px 0 0;
  color: var(--ink-soft);
  font-size: 0.9rem;
  font-style: italic;
}

/* Add bar: stacked full-width controls on phones for easy one-handed
   thumb reach, a single row from tablet width up. */
.add-bar {
  margin-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
@media (min-width: 560px) {
  .add-bar {
    margin-top: 18px;
    flex-direction: row;
  }
}

.add-bar input {
  flex: 1;
  min-width: 0;
  font-family: var(--sans);
  font-size: 1rem;
  padding: 13px 16px;
  color: var(--ink);
  background: var(--card);
  border: 1.5px solid var(--line-strong);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.add-bar input::placeholder { color: var(--ink-faint); }
.add-bar input:focus { border-color: var(--paprika); outline: none; box-shadow: 0 0 0 3px rgba(193, 66, 38, 0.14); }

button {
  font-family: var(--sans);
  cursor: pointer;
}

#add-button {
  flex: none;
  min-height: 48px;
  font-size: 1rem;
  font-weight: 650;
  padding: 13px 22px;
  color: #fff8ef;
  background: var(--paprika);
  border: none;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm), inset 0 1px 0 rgba(255, 255, 255, 0.18);
  transition: background 0.15s, transform 0.08s;
}
#add-button:hover:not(:disabled) { background: var(--paprika-deep); }
#add-button:active:not(:disabled) { transform: translateY(1px); }
#add-button:disabled { cursor: progress; opacity: 0.85; }

.add-status {
  margin: 12px 0 0;
  font-size: 0.92rem;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong);
  background: var(--card);
}
.add-status[data-kind="working"] {
  color: var(--herb-deep);
  border-color: color-mix(in srgb, var(--herb) 45%, transparent);
  background: color-mix(in srgb, var(--herb) 12%, var(--card));
}
.add-status[data-kind="error"] {
  color: var(--paprika-deep);
  border-color: color-mix(in srgb, var(--paprika) 45%, transparent);
  background: color-mix(in srgb, var(--paprika) 10%, var(--card));
}
.add-status[data-kind="success"] {
  color: var(--herb-deep);
  border-color: color-mix(in srgb, var(--herb) 45%, transparent);
  background: color-mix(in srgb, var(--herb) 12%, var(--card));
}

.spinner {
  display: inline-block;
  width: 13px; height: 13px;
  margin-right: 7px;
  vertical-align: -1px;
  border: 2px solid color-mix(in srgb, var(--herb) 35%, transparent);
  border-top-color: var(--herb);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Page ---------- */

.page {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: clamp(20px, 4vw, 36px) clamp(16px, 4vw, 40px) calc(80px + env(safe-area-inset-bottom, 0px));
}

/* Controls: stacked on phones (full-width search, edge-to-edge scrolling
   tag row), a single wrapping row on desktop. */
.controls {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 12px;
  margin-bottom: 20px;
}
@media (min-width: 720px) {
  .controls {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 16px;
    margin-bottom: 26px;
  }
}

.search {
  position: relative;
  flex: 1;
  min-width: 220px;
}
.search__icon {
  position: absolute;
  left: 14px; top: 50%;
  transform: translateY(-50%);
  color: var(--ink-faint);
  pointer-events: none;
}
.search input {
  width: 100%;
  min-height: 44px;
  font-family: var(--sans);
  font-size: 1rem;
  padding: 10px 14px 10px 40px;
  color: var(--ink);
  background: var(--card);
  border: 1.5px solid var(--line);
  border-radius: 999px;
  box-shadow: var(--shadow-sm);
}
.search input:focus { border-color: var(--saffron); outline: none; }
.search input::placeholder { color: var(--ink-faint); }

/* On phones the chips are a single edge-to-edge row you swipe sideways,
   so they never bury the recipes; on desktop they wrap in place. */
.chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
  margin: 0 calc(-1 * clamp(16px, 4vw, 40px));
  padding: 2px clamp(16px, 4vw, 40px);
  -webkit-overflow-scrolling: touch;
}
.chips::-webkit-scrollbar { display: none; }
@media (min-width: 720px) {
  .chips {
    flex-wrap: wrap;
    overflow-x: visible;
    margin: 0;
    padding: 0;
  }
}
.chip {
  flex: none;
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  font-family: var(--sans);
  font-size: 0.82rem;
  font-weight: 550;
  letter-spacing: 0.01em;
  padding: 8px 16px;
  color: var(--ink-soft);
  background: var(--card);
  border: 1.5px solid var(--line-strong);
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.14s;
  white-space: nowrap;
}
.chip:hover { border-color: var(--herb); color: var(--ink); }
.chip[aria-pressed="true"] {
  color: #fff8ef;
  background: var(--herb);
  border-color: var(--herb);
}
.chip__count {
  opacity: 0.65;
  margin-left: 4px;
  font-variant-numeric: tabular-nums;
}

/* ---------- Grid + cards ---------- */

/* Single column on phones; multi-column from tablet width up. */
.grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}
@media (min-width: 560px) {
  .grid {
    grid-template-columns: repeat(auto-fill, minmax(255px, 1fr));
    gap: 20px;
  }
}

.card {
  position: relative;
  display: flex;
  flex-direction: column;
  text-align: left;
  padding: 0;
  color: inherit;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  cursor: pointer;
  font-family: inherit;
  transition: transform 0.16s ease, box-shadow 0.16s ease, border-color 0.16s ease;
}
.card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-md);
  border-color: var(--line-strong);
}

.card__media {
  aspect-ratio: 16 / 10;
  width: 100%;
  overflow: hidden;
  background: var(--paper-2);
}
.card__media img {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
}
.card__placeholder {
  width: 100%; height: 100%;
  display: grid;
  place-items: center;
}
.card__placeholder span {
  font-family: var(--serif);
  font-size: 3.4rem;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.92);
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.18);
}

.card__body {
  padding: 15px 17px 17px;
  display: flex;
  flex-direction: column;
  gap: 9px;
  flex: 1;
}
.card__title {
  font-family: var(--serif);
  font-size: 1.22rem;
  font-weight: 600;
  line-height: 1.2;
  margin: 0;
  letter-spacing: -0.005em;
  overflow-wrap: break-word;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card__meta {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  font-size: 0.8rem;
  color: var(--ink-soft);
  margin-top: auto;
}
.card__meta span { display: inline-flex; align-items: center; gap: 5px; }
.card__source {
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
  color: var(--ink-faint);
}
.card__tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.tag-pill {
  font-size: 0.72rem;
  font-weight: 550;
  padding: 3px 9px;
  border-radius: 999px;
  color: var(--herb-deep);
  background: color-mix(in srgb, var(--herb) 14%, var(--card));
  border: 1px solid color-mix(in srgb, var(--herb) 28%, transparent);
}

/* ---------- Empty ---------- */
.empty { padding: 60px 20px; display: grid; place-items: center; }
.empty__card {
  text-align: center;
  max-width: 420px;
  padding: 40px 32px;
  background: var(--card);
  border: 1.5px dashed var(--line-strong);
  border-radius: var(--radius);
}
.empty__glyph { font-size: 2.6rem; }
.empty__card h2 {
  font-family: var(--serif);
  font-size: 1.5rem;
  margin: 12px 0 6px;
}
.empty__card p { color: var(--ink-soft); margin: 0; }

/* ---------- Detail overlay ---------- */

.detail {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: end center;
}
.detail__scrim {
  position: absolute;
  inset: 0;
  background: rgba(30, 18, 8, 0.5);
  backdrop-filter: blur(3px);
  animation: fade 0.2s ease;
}
@keyframes fade { from { opacity: 0; } }

.detail__panel {
  position: relative;
  width: min(920px, 100%);
  max-height: 96vh;
  overflow-y: auto;
  background: var(--paper);
  border-radius: 20px 20px 0 0;
  box-shadow: var(--shadow-lg);
  animation: rise 0.26s cubic-bezier(0.2, 0.8, 0.3, 1);
}
@media (min-width: 720px) {
  .detail { place-items: center; }
  .detail__panel { border-radius: 20px; max-height: 92vh; animation: pop 0.22s cubic-bezier(0.2, 0.8, 0.3, 1); }
}
@keyframes rise { from { transform: translateY(28px); opacity: 0; } }
@keyframes pop { from { transform: scale(0.97); opacity: 0; } }

.detail__close {
  position: sticky;
  top: 12px;
  float: right;
  margin: 12px 12px -50px 0;
  z-index: 3;
  display: grid;
  place-items: center;
  width: 44px; height: 44px;
  color: var(--ink);
  background: var(--card);
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  box-shadow: var(--shadow-sm);
}
.detail__close:hover { background: var(--paper-2); }

.detail__content { padding: 0 clamp(20px, 4vw, 44px) calc(48px + env(safe-area-inset-bottom, 0px)); }

.detail__hero {
  margin: 0 calc(-1 * clamp(20px, 4vw, 44px)) clamp(18px, 3vw, 28px);
  aspect-ratio: 21 / 9;
  max-height: 300px;
  overflow: hidden;
  background: var(--paper-2);
}
.detail__hero img { width: 100%; height: 100%; object-fit: cover; display: block; }
.detail__hero--plain {
  border-radius: 0;
}

.detail__eyebrow {
  margin: 28px 0 0;
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-weight: 650;
  color: var(--paprika);
}
.detail__title {
  font-family: var(--serif);
  font-size: clamp(1.8rem, 5vw, 2.9rem);
  font-weight: 600;
  line-height: 1.08;
  letter-spacing: -0.015em;
  overflow-wrap: break-word;
  margin: 8px 0 10px;
}
.detail__desc {
  font-size: 1.1rem;
  color: var(--ink-soft);
  max-width: 62ch;
  margin: 0 0 18px;
  line-height: 1.55;
}

/* Meta facts: a tidy two-column grid on phones (dividers between wrapped
   flex items look broken there), the original divided row on desktop. */
.metarow {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px 16px;
  padding: 16px 0 18px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  margin-bottom: 26px;
}
.metabox {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
@media (min-width: 720px) {
  .metarow {
    display: flex;
    flex-wrap: wrap;
    gap: 10px 12px;
  }
  .metabox { padding-right: 20px; }
  .metabox + .metabox { border-left: 1px solid var(--line); padding-left: 20px; }
}
.metabox__label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-faint);
  font-weight: 600;
}
.metabox__value {
  font-family: var(--serif);
  font-size: 1.15rem;
  font-weight: 600;
  overflow-wrap: break-word;
}
.metabox__value a { color: var(--herb-deep); text-decoration: none; border-bottom: 1.5px solid color-mix(in srgb, var(--herb) 40%, transparent); }
.metabox__value a:hover { color: var(--herb); }

.cook {
  display: grid;
  grid-template-columns: 1fr;
  gap: 34px;
}
@media (min-width: 720px) {
  .cook { grid-template-columns: minmax(240px, 0.85fr) 1.15fr; gap: 44px; }
}

.cook__h {
  font-family: var(--serif);
  font-size: 1.35rem;
  font-weight: 600;
  margin: 0 0 16px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--saffron);
  display: inline-block;
}

/* Ingredient checklist: tall, well-spaced rows where the whole row is the
   tap target, sized for imprecise mid-cooking taps. */
.ingredients { list-style: none; margin: 0; padding: 0; }
.ingredients li { margin: 0; }
.ing {
  display: flex;
  gap: 14px;
  align-items: center;
  min-height: 52px;
  padding: 13px 4px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  font-size: 1.05rem;
  line-height: 1.4;
}
.ing input { flex: none; width: 22px; height: 22px; margin: 0; accent-color: var(--herb); cursor: pointer; }
.ing span { transition: color 0.15s; overflow-wrap: break-word; min-width: 0; }
.ing input:checked + span { color: var(--ink-faint); text-decoration: line-through; }

.steps { list-style: none; counter-reset: step; margin: 0; padding: 0; }
.steps li {
  counter-increment: step;
  display: flex;
  gap: 16px;
  padding: 0 0 22px;
  font-size: 1.1rem;
  line-height: 1.6;
}
.steps li::before {
  content: counter(step);
  flex: none;
  display: grid;
  place-items: center;
  width: 34px; height: 34px;
  margin-top: 1px;
  font-family: var(--serif);
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--paprika);
  background: color-mix(in srgb, var(--paprika) 12%, var(--card));
  border: 1.5px solid color-mix(in srgb, var(--paprika) 30%, transparent);
  border-radius: 50%;
}

/* Notes + actions */
.detail__notes { margin: 40px 0 0; }
.detail__notes textarea {
  width: 100%;
  min-height: 92px;
  resize: vertical;
  font-family: var(--sans);
  font-size: 1rem;
  line-height: 1.5;
  color: var(--ink);
  padding: 14px 16px;
  background: color-mix(in srgb, var(--saffron) 8%, var(--card));
  border: 1.5px solid var(--line-strong);
  border-radius: var(--radius-sm);
}
.detail__notes textarea:focus { outline: none; border-color: var(--saffron); }
.notes-hint { font-size: 0.8rem; color: var(--ink-faint); margin: 8px 2px 0; }

.detail__foot {
  margin-top: 36px;
  padding-top: 22px;
  border-top: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.btn-danger {
  min-height: 44px;
  font-size: 0.92rem;
  font-weight: 600;
  padding: 10px 18px;
  color: var(--paprika-deep);
  background: transparent;
  border: 1.5px solid color-mix(in srgb, var(--paprika) 40%, transparent);
  border-radius: var(--radius-sm);
  transition: all 0.14s;
}
.btn-danger:hover { color: #fff8ef; background: var(--paprika); border-color: var(--paprika); }
.foot-note { font-size: 0.82rem; color: var(--ink-faint); }

.detail__chips { display: flex; flex-wrap: wrap; gap: 7px; margin: 0 0 4px; }

/* No-recipe / loading skeleton inside detail */
.detail__loading { padding: 80px 20px; text-align: center; color: var(--ink-soft); }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translateX(-50%);
  z-index: 80;
  max-width: calc(100vw - 32px);
  padding: 12px 20px;
  font-size: 0.92rem;
  font-weight: 550;
  text-align: center;
  color: #fff8ef;
  background: var(--ink);
  border-radius: 999px;
  box-shadow: var(--shadow-md);
  animation: toast-in 0.24s ease;
}
@keyframes toast-in { from { transform: translate(-50%, 12px); opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}
