/* ==========================================================================
   מתכונים — styles
   Aesthetic: נייר (Paper Recipe Book)
   Palette: cream paper · deep ink · saffron accent
   Type:    Frank Ruhl Libre (display) · Heebo (body)
   ========================================================================== */

:root {
  --paper:        #F7F2E8;
  --paper-lift:   #FCF8EE;          /* card interior, slightly brighter */
  --ink:          #1C1A16;
  --ink-60:       rgba(28,26,22,.62);
  --ink-40:       rgba(28,26,22,.42);
  --ink-20:       rgba(28,26,22,.20);
  --ink-10:       rgba(28,26,22,.10);
  --saffron:      #C8863C;
  --saffron-dark: #A06E2D;
  --danger:       #8B2A1F;

  --radius-sm:  6px;
  --radius-md:  10px;
  --radius-lg:  14px;

  --shadow-toast: 0 8px 24px -8px rgba(28,26,22,.25);

  --fs-base:   18px;
  --fs-body:   1.05rem;     /* ~19px */
  --fs-ingr:   1.12rem;     /* ~20px — kitchen readable */
  --fs-step:   1.22rem;     /* ~22px */
  --fs-h1:     2.4rem;      /* ~43px */
  --fs-h1-mob: 1.9rem;      /* ~34px */
  --fs-h2:     .82rem;

  --lh-body:   1.55;
  --lh-step:   1.65;

  --page-pad-x:   max(20px, env(safe-area-inset-right, 0) + 20px);
  --page-pad-bottom: max(32px, env(safe-area-inset-bottom, 0) + 32px);

  /* paper noise overlay — SVG data URI */
  --paper-noise: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='200' height='200'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2'/></filter><rect width='200' height='200' filter='url(%23n)' opacity='.35'/></svg>");
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  background: var(--paper);
  color: var(--ink);
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
body {
  font-family: 'Heebo', system-ui, sans-serif;
  font-size: var(--fs-base);
  line-height: var(--lh-body);
  min-height: 100dvh;
  position: relative;
  overscroll-behavior-y: contain;
}
body::before {
  content: '';
  position: fixed; inset: 0;
  background-image: var(--paper-noise);
  mix-blend-mode: multiply;
  opacity: .09;
  pointer-events: none;
  z-index: 0;
}
#app { position: relative; z-index: 1; }

/* ---------- layout shell ---------- */
.screen {
  max-width: 720px;
  margin: 0 auto;
  padding: 28px var(--page-pad-x) var(--page-pad-bottom);
  min-height: 100dvh;
  animation: fade 180ms ease-out both;
}
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* When View Transitions are running (forward/back), skip the .screen fade — it would double-animate */
@supports (view-transition-name: root) {
  html.nav-forward .screen,
  html.nav-back .screen { animation: none; }
}

/* ============================================================================
   Page transitions — slide for forward/back, matched to RTL direction.
   RTL convention (iOS): forward enters from LEFT, back enters from RIGHT.
   Uses the View Transitions API — silently no-ops on browsers that lack it.
   ============================================================================ */
@keyframes slide-in-from-left  { from { transform: translateX(-100%); opacity: .85; } to { transform: none; opacity: 1; } }
@keyframes slide-out-to-right  { from { transform: none; opacity: 1; }                to { transform: translateX(100%);  opacity: .85; } }
@keyframes slide-in-from-right { from { transform: translateX(100%);  opacity: .85; } to { transform: none; opacity: 1; } }
@keyframes slide-out-to-left   { from { transform: none; opacity: 1; }                to { transform: translateX(-100%); opacity: .85; } }

::view-transition-old(root),
::view-transition-new(root) {
  animation-duration: 280ms;
  animation-timing-function: cubic-bezier(.25,.8,.25,1);
  animation-fill-mode: both;
  /* Hide scrollbars on the snapshot so they don't flash */
  mix-blend-mode: normal;
}

html.nav-forward::view-transition-old(root) { animation-name: slide-out-to-right; }
html.nav-forward::view-transition-new(root) { animation-name: slide-in-from-left; }
html.nav-back::view-transition-old(root)    { animation-name: slide-out-to-left; }
html.nav-back::view-transition-new(root)    { animation-name: slide-in-from-right; }

/* No-animation cases: cross-fade quickly */
html.nav-same::view-transition-old(root),
html.nav-none::view-transition-old(root) { animation: none; opacity: 0; }
html.nav-same::view-transition-new(root),
html.nav-none::view-transition-new(root) { animation: none; opacity: 1; }

@media (prefers-reduced-motion: reduce) {
  ::view-transition-old(root),
  ::view-transition-new(root) { animation-duration: 0ms !important; }
}

a { color: inherit; }
button { font-family: inherit; }

.page-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--ink);
  padding-bottom: 14px;
  margin-bottom: 20px;
}
.wordmark {
  font-family: 'Frank Ruhl Libre', serif;
  font-weight: 700;
  font-size: 30px;
  letter-spacing: -.01em;
  line-height: 1;
}
.kicker, .kicker-link {
  font-size: 12px;
  letter-spacing: .2em;
  text-transform: uppercase;
  color: var(--ink-60);
  text-decoration: none;
}
.kicker-link { text-decoration: underline; text-underline-offset: 4px; }
.kicker-link:hover { color: var(--ink); }

/* ---------- search ---------- */
.search-wrap { position: relative; margin-bottom: 18px; }
.search {
  width: 100%;
  background: transparent;
  border: none;
  border-bottom: 2px solid var(--ink);
  padding: 14px 0 14px 38px;
  font-family: inherit;
  font-size: 18px;
  color: var(--ink);
  direction: rtl;
  text-align: right;
  outline: none;
  -webkit-appearance: none;
  border-radius: 0;
}
.search::placeholder { color: var(--ink-40); }
.search::-webkit-search-cancel-button { display: none; }
.search:focus { border-bottom-color: var(--saffron); }

/* ---------- recipe list ---------- */
.recipe-list {
  list-style: none;
  margin: 0; padding: 0;
}
.recipe-list li {
  padding: 18px 0;
  border-bottom: 1px solid var(--ink-20);
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 18px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  min-height: 64px;
}
.recipe-list li:last-child { border-bottom: none; }
.recipe-list li:active { background: var(--ink-10); }
.recipe-list .t {
  font-family: 'Frank Ruhl Libre', serif;
  font-weight: 500;
  font-size: 23px;
  line-height: 1.2;
}
.recipe-list .meta {
  font-size: 12.5px;
  color: var(--ink-40);
  white-space: nowrap;
  letter-spacing: .05em;
}
.recipe-list li.fresh .t::before {
  content: '';
  display: inline-block;
  width: 6px; height: 6px;
  background: var(--saffron);
  border-radius: 50%;
  margin-left: 10px;
  vertical-align: middle;
  transform: translateY(-3px);
}

/* admin rows: add edit/delete */
.recipe-list.admin li { padding-left: 8px; }
.recipe-list.admin .row-actions {
  display: flex;
  gap: 6px;
}
.recipe-list.admin .row-actions a {
  color: var(--ink-60);
  text-decoration: none;
  font-size: 14px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
}
.recipe-list.admin .row-actions a:hover { color: var(--ink); background: var(--ink-10); }

.empty {
  text-align: center;
  color: var(--ink-40);
  padding: 48px 0;
  font-style: italic;
}

/* ---------- recipe detail ---------- */
.detail .back, .edit .back, .token .back {
  display: inline-block;
  font-size: 14px;
  color: var(--ink-60);
  text-decoration: none;
  margin-bottom: 16px;
  padding: 6px 0;
}
.detail .back:hover { color: var(--ink); }

.detail h1 {
  font-family: 'Frank Ruhl Libre', serif;
  font-weight: 700;
  font-size: var(--fs-h1);
  line-height: 1.05;
  letter-spacing: -.02em;
  margin: 0 0 8px;
}
.detail .sub {
  font-size: 12px;
  letter-spacing: .2em;
  text-transform: uppercase;
  color: var(--ink-60);
  margin-bottom: 26px;
}
.detail h2 {
  font-family: 'Frank Ruhl Libre', serif;
  font-weight: 700;
  font-size: var(--fs-h2);
  letter-spacing: .3em;
  text-transform: uppercase;
  color: var(--saffron-dark);
  margin: 32px 0 14px;
}

/* ingredients — no bullets, just lines */
.ing-list {
  display: block;
}
.ing-list > div {
  font-size: var(--fs-ingr);
  line-height: 1.45;
  padding: 8px 0;
  border-bottom: 1px dashed var(--ink-20);
}
.ing-list > div:last-child { border-bottom: none; }

/* instructions — numbered cells (C adapted to paper) */
.steps {
  list-style: none;
  counter-reset: step;
  margin: 0; padding: 0;
  display: grid;
  gap: 10px;
}
.steps li {
  counter-increment: step;
  position: relative;
  background: var(--paper-lift);
  border: 1px solid var(--ink);
  border-radius: var(--radius-md);
  padding: 18px 64px 18px 20px;
  font-size: var(--fs-step);
  line-height: var(--lh-step);
}
.steps li::before {
  content: counter(step);
  position: absolute;
  right: -1px; top: -1px;
  width: 44px; height: 44px;
  background: var(--saffron);
  color: var(--paper);
  border: 1px solid var(--ink);
  border-top-right-radius: var(--radius-md);
  border-bottom-left-radius: var(--radius-md);
  font-family: 'Frank Ruhl Libre', serif;
  font-weight: 700;
  font-size: 22px;
  display: grid;
  place-items: center;
  font-variant-numeric: tabular-nums;
}

/* ---------- PIN lock ---------- */
.lock {
  display: flex;
  align-items: center;
  justify-content: center;
}
.lock-inner {
  width: 100%;
  max-width: 340px;
  text-align: center;
}
.lock-title {
  font-family: 'Frank Ruhl Libre', serif;
  font-weight: 700;
  font-size: 34px;
  margin-top: 40px;
  margin-bottom: 6px;
}
.lock-sub {
  color: var(--ink-60);
  font-size: 14px;
  margin-bottom: 32px;
}
.pin-dots {
  display: flex;
  justify-content: center;
  gap: 18px;
  margin-bottom: 36px;
}
.pin-dots span {
  width: 14px; height: 14px;
  border-radius: 50%;
  border: 1.5px solid var(--ink);
  transition: background 120ms ease;
}
.pin-dots span.filled { background: var(--ink); }
.pin-dots.shake { animation: shake 320ms ease; }
@keyframes shake {
  0%,100% { transform: translateX(0); }
  20% { transform: translateX(-8px); }
  40% { transform: translateX(8px); }
  60% { transform: translateX(-6px); }
  80% { transform: translateX(6px); }
}
.pin-pad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  max-width: 320px;
  margin: 0 auto;
}
.pin-pad button {
  aspect-ratio: 1;
  min-height: 72px;
  border: 1px solid var(--ink);
  background: var(--paper-lift);
  border-radius: 50%;
  font-family: 'Frank Ruhl Libre', serif;
  font-weight: 500;
  font-size: 28px;
  color: var(--ink);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 100ms ease, transform 80ms ease;
}
.pin-pad button:active { background: var(--saffron); color: var(--paper); transform: scale(.96); }
.pin-pad .pad-spacer { border: none; background: transparent; pointer-events: none; }
.pin-pad .pad-back {
  font-size: 22px;
  background: transparent;
  border: none;
}
.pin-pad .pad-back:active { background: transparent; transform: scale(.96); color: var(--saffron-dark); }

.text-btn {
  background: none;
  border: none;
  color: var(--ink-60);
  font-size: 13px;
  margin-top: 28px;
  text-decoration: underline;
  text-underline-offset: 4px;
  padding: 8px;
}

/* ---------- token screen ---------- */
.token h1 {
  font-family: 'Frank Ruhl Libre', serif;
  font-weight: 700;
  font-size: 32px;
  margin: 8px 0 12px;
}
.token-help {
  color: var(--ink-60);
  font-size: 15px;
  margin-bottom: 20px;
  line-height: 1.5;
}
.token-help a {
  color: var(--saffron-dark);
  text-decoration: underline;
  text-underline-offset: 3px;
}
.token-note {
  color: var(--ink-40);
  font-size: 12px;
  margin-top: 12px;
  line-height: 1.5;
}

/* ---------- admin / edit form ---------- */
.edit h1 {
  font-family: 'Frank Ruhl Libre', serif;
  font-weight: 700;
  font-size: 30px;
  margin: 8px 0 24px;
}
.field {
  display: block;
  margin-bottom: 18px;
}
.field > span {
  display: block;
  font-size: 12px;
  letter-spacing: .15em;
  text-transform: uppercase;
  color: var(--ink-60);
  margin-bottom: 8px;
}
.field input[type="text"],
.field input[type="password"],
.field textarea {
  width: 100%;
  background: var(--paper-lift);
  border: 1px solid var(--ink);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  font-family: inherit;
  font-size: 17px;
  color: var(--ink);
  line-height: 1.5;
  outline: none;
  -webkit-appearance: none;
}
.field input[type="text"]:focus,
.field input[type="password"]:focus,
.field textarea:focus {
  border-color: var(--saffron);
  box-shadow: 0 0 0 3px rgba(200,134,60,.15);
}
.field textarea {
  resize: vertical;
  min-height: 120px;
  font-family: inherit;
  line-height: 1.6;
}

.preview-panel {
  background: var(--paper-lift);
  border: 1px dashed var(--ink-40);
  border-radius: var(--radius-md);
  padding: 8px 16px;
  margin: 20px 0 120px;
}
.preview-panel summary {
  font-size: 12px;
  letter-spacing: .15em;
  text-transform: uppercase;
  color: var(--ink-60);
  cursor: pointer;
  padding: 8px 0;
}
.preview-panel[open] summary { margin-bottom: 8px; }
.preview-body {
  padding-bottom: 8px;
}
.preview-body h3 {
  font-family: 'Frank Ruhl Libre', serif;
  font-weight: 700;
  font-size: 26px;
  margin: 8px 0 16px;
}
.preview-body .p-section {
  font-family: 'Frank Ruhl Libre', serif;
  font-weight: 700;
  font-size: 11px;
  letter-spacing: .3em;
  text-transform: uppercase;
  color: var(--saffron-dark);
  margin: 20px 0 10px;
}
.preview-body .p-ing { padding: 6px 0; font-size: 16px; border-bottom: 1px dashed var(--ink-20); }
.preview-body .p-ing:last-child { border-bottom: none; }
.preview-body ol.p-steps { list-style: none; counter-reset: p; padding: 0; margin: 0; display: grid; gap: 8px; }
.preview-body ol.p-steps li {
  counter-increment: p;
  position: relative;
  background: var(--paper);
  border: 1px solid var(--ink);
  border-radius: var(--radius-md);
  padding: 12px 54px 12px 16px;
  font-size: 16px;
  line-height: 1.5;
}
.preview-body ol.p-steps li::before {
  content: counter(p);
  position: absolute;
  right: -1px; top: -1px;
  width: 36px; height: 36px;
  background: var(--saffron);
  color: var(--paper);
  border: 1px solid var(--ink);
  border-top-right-radius: var(--radius-md);
  border-bottom-left-radius: var(--radius-md);
  font-family: 'Frank Ruhl Libre', serif;
  font-weight: 700;
  font-size: 17px;
  display: grid;
  place-items: center;
}

/* ---------- buttons ---------- */
.actions {
  display: flex;
  gap: 10px;
  justify-content: flex-start;
}
.actions.sticky {
  position: sticky;
  bottom: 0;
  background: linear-gradient(to top, var(--paper) 60%, transparent);
  padding: 20px 0 calc(env(safe-area-inset-bottom, 0) + 12px);
  margin-top: 24px;
  z-index: 5;
}
.btn {
  border: 1px solid var(--ink);
  border-radius: var(--radius-md);
  padding: 14px 22px;
  font-family: inherit;
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  min-height: 50px;
  -webkit-tap-highlight-color: transparent;
  transition: background 100ms ease, transform 80ms ease;
}
.btn.primary { background: var(--ink); color: var(--paper); }
.btn.primary:active { background: #000; transform: scale(.98); }
.btn.ghost { background: transparent; color: var(--danger); border-color: var(--danger); margin-left: auto; }
.btn.ghost:active { background: rgba(139,42,31,.08); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- FAB ---------- */
.fab {
  position: fixed;
  bottom: calc(env(safe-area-inset-bottom, 0) + 24px);
  inset-inline-end: 24px;
  width: 60px; height: 60px;
  background: var(--ink);
  color: var(--paper);
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-family: 'Frank Ruhl Libre', serif;
  font-size: 34px;
  text-decoration: none;
  box-shadow: 0 6px 16px -4px rgba(28,26,22,.35);
  z-index: 10;
  transition: transform 120ms ease;
}
.fab:active { transform: scale(.94); }

/* ---------- toast ---------- */
.toast {
  position: fixed;
  bottom: calc(env(safe-area-inset-bottom, 0) + 28px);
  left: 50%;
  transform: translateX(-50%) translateY(12px);
  background: var(--ink);
  color: var(--paper);
  padding: 12px 18px;
  border-radius: var(--radius-md);
  font-size: 15px;
  box-shadow: var(--shadow-toast);
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
}
.toast[data-visible="true"] {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.toast.error { background: var(--danger); }

/* ---------- wider (iPad / desktop) ---------- */
@media (min-width: 900px) {
  :root { --fs-base: 19px; }
  .detail h1 { font-size: 3rem; }
  .steps li { font-size: 1.26rem; padding-right: 72px; padding-left: 22px; }
  .pin-pad { max-width: 360px; }
}

/* ---------- narrower (phone) ---------- */
@media (max-width: 480px) {
  :root {
    --fs-base: 17px;
    --fs-ingr: 1.06rem;
    --fs-step: 1.12rem;
    --fs-h1: 2rem;
  }
  .wordmark { font-size: 26px; }
  .recipe-list .t { font-size: 20px; }
}

/* ---------- honour reduce-motion ---------- */
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
