/* ==========================================================================
   Recipe Book — warm paper aesthetic
   ========================================================================== */

:root {
  --paper:      #EFE9DF;
  --paper-deep: #E4DCCE;
  --card:       #F6F1E8;
  --card-warm:  #FBF7F0;
  --ink:        #4A4038;
  --ink-mid:    #6E6153;
  --ink-soft:   #9C8E7D;
  --rule:       #D8CDBC;
  --rule-soft:  #E3DACB;
  --tab:        #E7DFD1;
  --tab-edge:   #CDBFA9;
  --highlight:  rgba(203, 184, 152, 0.38);
  --star:       #C0AE8E;
  --danger:     #A5624F;

  --font-hand:   'Patrick Hand', 'Segoe Print', cursive;
  --font-label:  'Jost', 'Segoe UI', sans-serif;
  --font-script: 'Sacramento', cursive;
  --font-round:  'Quicksand', 'Segoe UI', sans-serif;

  --r-sm: 6px;
  --r-md: 12px;
  --r-lg: 20px;
  --shadow: 0 18px 40px -24px rgba(74, 64, 56, .55);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-label);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body { min-height: 100dvh; }

.app { min-height: 100dvh; }

button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: none; padding: 0; }
a { color: inherit; }

/* ---------------------------------------------------------------- type ---- */

.label {
  font-family: var(--font-label);
  font-weight: 500;
  font-size: .68rem;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--ink-mid);
}

.script { font-family: var(--font-script); font-weight: 400; line-height: 1; }

.outline-title {
  font-family: var(--font-round);
  font-weight: 700;
  letter-spacing: .01em;
  color: var(--ink-soft);
}
@supports ((-webkit-text-stroke: 1px black)) {
  .outline-title {
    color: transparent;
    -webkit-text-stroke: 1.4px var(--ink-soft);
    paint-order: stroke fill;
  }
}

/* --------------------------------------------------------------- shell ---- */

.masthead {
  text-align: center;
  padding: 26px 16px 14px;
}
.masthead h1 {
  margin: 0;
  font-family: var(--font-round);
  font-weight: 700;
  font-size: clamp(1.6rem, 6vw, 2.6rem);
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--ink-mid);
}
.masthead .sub {
  margin-top: 6px;
  font-family: var(--font-script);
  font-size: 1.5rem;
  color: var(--ink-soft);
}

/* The tablet frame from the reference — a dark bezel around cream paper. */
.frame {
  max-width: 1120px;
  margin: 0 auto 40px;
  background: #2E2A26;
  border-radius: 26px;
  padding: 14px;
  box-shadow: var(--shadow);
}
.frame-inner {
  display: flex;
  background: var(--card);
  border-radius: 14px;
  overflow: hidden;
  min-height: 60vh;
}
.sheet {
  flex: 1 1 auto;
  min-width: 0;
  padding: 30px 34px 40px;
}

/* Right-hand index tabs (months in the reference -> categories here). */
.tabrail {
  flex: 0 0 34px;
  background: var(--card);
  border-left: 1px solid var(--rule-soft);
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 12px 0;
}
.tabrail button {
  flex: 1 1 0;
  min-height: 34px;
  background: var(--tab);
  border-left: 1px solid var(--tab-edge);
  border-radius: 0 6px 6px 0;
  font-family: var(--font-label);
  font-size: .58rem;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--ink-mid);
  writing-mode: vertical-rl;
  padding: 8px 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  transition: background .15s, color .15s;
}
.tabrail button:hover { background: var(--paper-deep); }
.tabrail button[aria-current="true"] {
  background: var(--ink-mid);
  color: var(--card-warm);
  border-left-color: var(--ink-mid);
}

/* -------------------------------------------------------------- toolbar --- */

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}
.search {
  flex: 1 1 220px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--card-warm);
  border: 1px solid var(--rule);
  border-radius: 999px;
  padding: 9px 16px;
}
.search input {
  flex: 1;
  border: none;
  background: none;
  outline: none;
  font-family: var(--font-hand);
  font-size: 1.05rem;
}
.search input::placeholder { color: var(--ink-soft); }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 1px solid var(--rule);
  background: var(--card-warm);
  color: var(--ink-mid);
  border-radius: 999px;
  padding: 9px 16px;
  font-family: var(--font-label);
  font-size: .7rem;
  font-weight: 500;
  letter-spacing: .14em;
  text-transform: uppercase;
  transition: background .15s, color .15s, border-color .15s;
}
.btn:hover { background: var(--paper-deep); }
.btn-primary {
  background: var(--ink-mid);
  border-color: var(--ink-mid);
  color: var(--card-warm);
}
.btn-primary:hover { background: var(--ink); border-color: var(--ink); }
.btn-ghost { border-color: transparent; background: none; }
.btn-ghost:hover { background: var(--paper-deep); }
.btn-danger { color: var(--danger); border-color: transparent; }
.btn-danger:hover { background: rgba(165, 98, 79, .1); }
.btn:disabled { opacity: .5; cursor: default; }

.chiprow { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 18px; }
.chip {
  border: 1px solid var(--rule);
  background: var(--card-warm);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: .66rem;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--ink-mid);
}
.chip[aria-pressed="true"] {
  background: var(--ink-mid);
  border-color: var(--ink-mid);
  color: var(--card-warm);
}

/* ---------------------------------------------------------------- grid ---- */

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 18px;
}

.rcard {
  display: block;
  text-align: left;
  width: 100%;
  background: var(--card-warm);
  border: 1px solid var(--rule-soft);
  border-radius: var(--r-md);
  overflow: hidden;
  transition: transform .16s ease, box-shadow .16s ease;
}
.rcard:hover { transform: translateY(-3px); box-shadow: 0 14px 26px -18px rgba(74,64,56,.6); }
.rcard .thumb {
  aspect-ratio: 4 / 3;
  background: var(--paper-deep) center/cover no-repeat;
  display: grid;
  place-items: center;
  color: var(--ink-soft);
  font-family: var(--font-script);
  font-size: 2rem;
}
.rcard .body { padding: 12px 14px 14px; }
.rcard .cat { font-size: .6rem; letter-spacing: .16em; text-transform: uppercase; color: var(--ink-soft); }
.rcard h3 {
  margin: 4px 0 8px;
  font-family: var(--font-hand);
  font-weight: 400;
  font-size: 1.25rem;
  line-height: 1.2;
  color: var(--ink);
}
.rcard .meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: .64rem;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--ink-soft);
}
.empty .script { font-size: 2.4rem; color: var(--ink-soft); }
.empty p { font-family: var(--font-hand); font-size: 1.1rem; margin: 10px 0 22px; }

/* -------------------------------------------------------------- recipe ---- */

.rhead {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: baseline;
  gap: 12px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--rule);
}
.rhead .no { font-family: var(--font-label); font-style: italic; font-weight: 500; font-size: .8rem; color: var(--ink-mid); }
.rhead .cat { text-align: right; font-family: var(--font-label); font-style: italic; font-weight: 600; font-size: .82rem; color: var(--ink-mid); }
.rhead h2 {
  margin: 0;
  text-align: center;
  font-size: clamp(1.5rem, 4.2vw, 2.5rem);
  line-height: 1.15;
}

.statbar {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
  padding: 16px 4px 18px;
  text-align: center;
}
.stat .label { display: block; margin-bottom: 4px; }
.stat .val { font-family: var(--font-hand); font-size: 1.05rem; color: var(--ink); line-height: 1.25; }
.stat .glyph { display: block; font-size: 1.1rem; color: var(--ink-mid); margin-bottom: 2px; line-height: 1; }

.dots, .stars { display: flex; gap: 6px; justify-content: center; }
.dots span, .stars span { line-height: 1; }
.dots span {
  width: 11px; height: 11px; border-radius: 50%;
  border: 1.5px solid var(--star);
}
.dots span.on { background: var(--star); }
.stars span { font-size: 1.05rem; color: var(--star); }
.dots.interactive span, .stars.interactive span { cursor: pointer; }

.rbody {
  display: grid;
  grid-template-columns: minmax(0, 0.86fr) minmax(0, 1.14fr);
  gap: 0;
  border-top: 1px solid var(--rule);
}
.rbody .col-left { padding: 18px 26px 24px 0; border-right: 1px solid var(--rule); }
.rbody .col-right { padding: 18px 0 24px 26px; }

.photo {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  border-radius: var(--r-sm);
  background: var(--paper-deep);
  display: block;
}
.photo-placeholder {
  width: 100%;
  aspect-ratio: 1 / 1;
  border: 1px dashed var(--rule);
  border-radius: var(--r-sm);
  display: grid;
  place-items: center;
  color: var(--ink-soft);
  font-family: var(--font-script);
  font-size: 2rem;
}

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin: 22px 0 0;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--rule);
}
.col-right .section-head:first-child, .col-left .section-head:first-child { margin-top: 0; }

.checklist { list-style: none; margin: 0; padding: 0; }
.checklist li { border-bottom: 1px solid var(--rule-soft); }
.checklist button {
  display: flex;
  align-items: flex-start;
  gap: 11px;
  width: 100%;
  text-align: left;
  padding: 9px 2px;
  font-family: var(--font-hand);
  font-size: 1.06rem;
  line-height: 1.3;
  color: var(--ink);
}
.box {
  flex: 0 0 auto;
  width: 14px; height: 14px;
  margin-top: 3px;
  border: 1.4px solid var(--ink-soft);
  border-radius: 2px;
  display: grid;
  place-items: center;
  font-size: .8rem;
  line-height: 1;
  color: var(--ink-mid);
}
.checked .box { background: var(--ink-soft); color: var(--card-warm); border-color: var(--ink-soft); }
.checked .txt { text-decoration: line-through; color: var(--ink-soft); }

.steps { list-style: none; margin: 0; padding: 0; counter-reset: step; }
.steps li { border-bottom: 1px solid var(--rule-soft); }
.steps button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 12px 2px;
  font-family: var(--font-hand);
  font-size: 1.1rem;
  line-height: 1.55;
  color: var(--ink);
}
.steps button::before {
  counter-increment: step;
  content: counter(step) ". ";
  color: var(--ink);
}
.steps li.done button { color: var(--ink-soft); }
.steps li.done button span { background: var(--highlight); }

.notes { margin-top: 26px; }
.notes .text {
  font-family: var(--font-hand);
  font-size: 1.08rem;
  line-height: 1.65;
  white-space: pre-wrap;
  padding: 12px 2px 20px;
  border-bottom: 1px solid var(--rule);
  min-height: 60px;
}

.footer-glyphs {
  display: flex;
  justify-content: center;
  gap: 26px;
  padding: 18px 0 2px;
  font-size: 1.1rem;
  color: var(--ink-soft);
}

/* -------------------------------------------------------------- editor --- */

.field { margin-bottom: 16px; }
.field > .label { display: block; margin-bottom: 6px; }

.input, .textarea {
  width: 100%;
  background: none;
  border: none;
  border-bottom: 1.5px dotted var(--rule);
  padding: 7px 2px;
  font-family: var(--font-hand);
  font-size: 1.1rem;
  outline: none;
  color: var(--ink);
}
.input:focus, .textarea:focus { border-bottom-color: var(--ink-soft); border-bottom-style: solid; }
.input::placeholder, .textarea::placeholder { color: var(--ink-soft); opacity: .7; }
.textarea { resize: none; overflow: hidden; line-height: 1.6; min-height: 3em; }

.boxed {
  border: 1.5px solid var(--rule);
  border-radius: var(--r-sm);
  padding: 6px 12px;
}
.boxed .input { border-bottom: none; font-size: 1.25rem; }

.grid2 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }

.lines { list-style: none; margin: 0; padding: 0; }
.lines li { display: flex; align-items: flex-start; gap: 8px; padding: 2px 0; }
.lines .bullet {
  flex: 0 0 auto;
  width: 18px;
  padding-top: 10px;
  text-align: center;
  color: var(--ink-soft);
  font-size: .85rem;
  font-family: var(--font-label);
}
.lines .row-actions { display: flex; gap: 2px; padding-top: 4px; }
.icon-btn {
  width: 26px; height: 26px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: var(--ink-soft);
  font-size: .9rem;
  line-height: 1;
}
.icon-btn:hover { background: var(--paper-deep); color: var(--ink); }

.editor-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 26px;
  padding-top: 18px;
  border-top: 1px solid var(--rule);
}
.spacer { flex: 1 1 auto; }

/* ---------------------------------------------------------------- auth --- */

.auth-wrap { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.auth-card {
  width: min(430px, 100%);
  background: var(--card-warm);
  border: 1px solid var(--rule);
  border-radius: var(--r-lg);
  padding: 38px 32px 34px;
  text-align: center;
  box-shadow: var(--shadow);
}
.auth-card .script { font-size: 3rem; color: var(--ink-mid); }
.auth-card p { font-family: var(--font-hand); font-size: 1.08rem; color: var(--ink-mid); line-height: 1.5; }
.auth-card .input { text-align: center; margin: 18px 0 20px; }
.auth-card .btn { width: 100%; justify-content: center; }
.hearts { margin-top: 26px; color: var(--ink-soft); letter-spacing: .5em; font-size: .8rem; }

.setup-note {
  max-width: 640px;
  margin: 40px auto;
  background: var(--card-warm);
  border: 1px solid var(--rule);
  border-radius: var(--r-md);
  padding: 26px 28px;
  line-height: 1.6;
}
.setup-note code {
  font-family: ui-monospace, Consolas, monospace;
  font-size: .85em;
  background: var(--paper-deep);
  padding: 1px 5px;
  border-radius: 4px;
}

/* --------------------------------------------------------------- misc ---- */

.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 1120px;
  margin: 0 auto;
  padding: 14px 16px 0;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(22px + var(--safe-b));
  transform: translate(-50%, 20px);
  background: var(--ink);
  color: var(--card-warm);
  font-size: .8rem;
  letter-spacing: .06em;
  padding: 11px 20px;
  border-radius: 999px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 50;
  max-width: calc(100vw - 32px);
  text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.spinner {
  width: 26px; height: 26px;
  border: 2px solid var(--rule);
  border-top-color: var(--ink-mid);
  border-radius: 50%;
  margin: 60px auto;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.visually-hidden {
  position: absolute; width: 1px; height: 1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}

/* ------------------------------------------------------------ responsive - */

@media (max-width: 860px) {
  .masthead { padding: 18px 16px 8px; }
  .masthead h1 { font-size: 1.35rem; letter-spacing: .18em; }
  .masthead .sub { display: none; }

  /* Drop the tablet bezel on phones — the page itself becomes the paper. */
  .frame { margin: 0; padding: 0; background: none; border-radius: 0; box-shadow: none; }
  .frame-inner { border-radius: 0; display: block; background: transparent; }
  .sheet { padding: 4px 16px calc(34px + var(--safe-b)); }

  /* Index tabs become a horizontal scroller under the toolbar. */
  .tabrail {
    order: -1;
    flex: none;
    flex-direction: row;
    border-left: none;
    gap: 6px;
    padding: 4px 16px 12px;
    overflow-x: auto;
    scrollbar-width: none;
    background: transparent;
  }
  .tabrail::-webkit-scrollbar { display: none; }
  .tabrail button {
    writing-mode: horizontal-tb;
    flex: 0 0 auto;
    min-height: 0;
    border-left: none;
    border: 1px solid var(--tab-edge);
    border-radius: 999px;
    padding: 7px 14px;
    font-size: .62rem;
  }

  .statbar { grid-template-columns: repeat(3, 1fr); gap: 14px 6px; }
  .rbody { grid-template-columns: 1fr; }
  .rbody .col-left { padding: 16px 0 20px; border-right: none; border-bottom: 1px solid var(--rule); }
  .rbody .col-right { padding: 18px 0 24px; }
  .photo, .photo-placeholder { aspect-ratio: 4 / 3; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; }
  .grid2 { grid-template-columns: 1fr 1fr; }
  .topbar { padding: 10px 12px 0; }
  .btn { padding: 10px 14px; }
}

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

@media print {
  .topbar, .tabrail, .toolbar, .footer-glyphs, .toast { display: none !important; }
  .frame { background: none; padding: 0; box-shadow: none; }
  body { background: #fff; }
}
