/*
 * Family Cookbook styles (on top of w3.css).
 *
 * Sections:  1 Base   2 Top bar   3 Page layout   4 Recipe lists
 *            5 Recipe page   6 Forms   7 Cook mode   8 Error pages   9 Print
 */

/* ---------- 1 Base ---------- */
:root {
  --accent: #f44336;
  --ink: #333;
}

body {
  margin: 0;
  color: var(--ink);
  background: #fafafa;
}

img { max-width: 100%; }

/* w3.css sets display on some elements, which would otherwise beat [hidden] */
[hidden] { display: none !important; }

/* ---------- 2 Top bar ---------- */
.site-nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: .5rem 1rem;
  padding: .6rem 1rem;
  background: #fff;
  border-bottom: 1px solid #ddd;
}
.site-title { font-weight: bold; font-size: 1.2rem; text-decoration: none; color: var(--accent); }
.nav-links { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem 1rem; min-width: 0; }
.nav-links a { text-decoration: none; }

/* hamburger button: hidden except on phones, and only once nav.js has loaded */
.nav-toggle {
  display: none;
  flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  width: 2.6rem; height: 2.4rem; padding: 0;
  background: none; border: 1px solid #ccc; border-radius: 6px; cursor: pointer;
}
.nav-toggle .bar { display: block; width: 1.4rem; height: 2px; background: var(--ink); border-radius: 1px; transition: transform .2s, opacity .2s; }
.site-nav.open .nav-toggle .bar:nth-child(1) { transform: translateY(6px) rotate(45deg); }    /* the three bars turn into an X */
.site-nav.open .nav-toggle .bar:nth-child(2) { opacity: 0; }
.site-nav.open .nav-toggle .bar:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }
.nav-toggle:focus-visible { outline: 3px solid #1565c0; outline-offset: 2px; }

@media (prefers-reduced-motion: reduce) {
  .nav-toggle .bar { transition: none; }
}

/* phones */
@media (max-width: 600px) {
  .site-nav { padding: .5rem .75rem; }

  /* fallback without JavaScript: links wrap onto their own rows under the title */
  .nav-links { width: 100%; font-size: .95rem; }
  .nav-links a, .nav-links .link-button { padding: .3rem 0; }

  /* with JavaScript: links fold into the hamburger menu */
  .site-nav.has-js .nav-toggle { display: flex; }
  .site-nav.has-js .nav-links { display: none; }
  .site-nav.has-js.open .nav-links {
    display: flex; flex-direction: column; align-items: stretch; gap: 0;
    margin-top: .4rem; border-top: 1px solid #eee; font-size: 1.05rem;
  }
  .site-nav.has-js.open .nav-links > a,
  .site-nav.has-js.open .nav-links .link-button {
    display: block; width: 100%; padding: .75rem 0; text-align: left; border-bottom: 1px solid #f0f0f0;
  }
  .site-nav.has-js.open .nav-links .inline-form { display: block; }
}

.inline-form { display: inline; margin: 0; }
.link-button {
  background: none; border: 0; padding: 0; font: inherit;
  color: #1565c0; cursor: pointer;
}
.link-button:hover { text-decoration: underline; }

/* ---------- 3 Page layout ---------- */
.hero h1 { margin: 1rem 0; }
.page-narrow { max-width: 480px; margin: 2rem auto; }
.page-wide { max-width: 900px; margin: 0 auto; padding-bottom: 2rem; }

/* Help pages */
.guide { line-height: 1.6; padding-top: 1rem; }
.guide h2 { margin-top: 2rem; }
.guide hr { margin: 1.5rem 0; }
.guide table { border-collapse: collapse; width: 100%; display: block; overflow-x: auto; }
.guide th, .guide td { border: 1px solid #ddd; padding: .5rem .75rem; text-align: left; vertical-align: top; }
.guide th { background: #f1f1f1; }

/* ---------- 4 Recipe lists (home and cookbook pages) ---------- */

/* one tile per person's cookbook on the home page */
.cook-tiles {
  max-width: 1200px;
  margin: 1rem auto 0;
  padding: 0 1rem;
  display: flex;
  flex-wrap: wrap;
  gap: .75rem;
}
.cook-tile {
  display: flex;
  flex-direction: column;
  padding: .7rem 1.2rem;
  border-radius: 6px;
  font-weight: bold;
  text-decoration: none;
  box-shadow: 0 1px 4px rgba(0,0,0,.25);
}
.cook-tile:hover, .cook-tile:focus { text-decoration: none; opacity: .9; }
.cook-tile small { font-weight: normal; opacity: .85; }

/* category buttons */
.chips { display: flex; flex-wrap: wrap; gap: .5rem; }
.chips-bar { max-width: 1200px; margin: 1rem auto 0; padding: 0 1rem; }
.chip {
  display: inline-block;
  padding: .25rem .8rem;
  border: 1px solid #bbb;
  border-radius: 999px;
  background: #fff;
  color: inherit;
  text-decoration: none;
  font-size: .9rem;
}
.chip:hover, .chip:focus { background: #eee; text-decoration: none; }
.chip.active { background: #333; border-color: #333; color: #fff; }
.chip small { opacity: .7; }

/* search row */
.filters {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  max-width: 1200px;
  margin: 1rem auto;
  padding: 0 1rem;
}
.filters input[type=search] { flex: 1 1 14rem; width: auto; }

/* recipe cards */
.cards {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1rem;
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
}
.card {
  display: block;
  color: inherit;
  text-decoration: none;
  background: #fff;
  overflow: hidden;
  transition: transform .15s;
}
.card:hover, .card:focus { transform: translateY(-3px); text-decoration: none; }
.card img { width: 100%; height: 220px; object-fit: cover; display: block; }
.card h4 { margin: .6rem 0 .2rem; }
.card-owner { margin: 0 0 .8rem; color: #777; font-size: .9rem; }

/* ---------- 5 Recipe page ---------- */
.recipe { max-width: 800px; margin: 0 auto; padding-bottom: 2rem; }

/* the frame wraps the picture: small photos aren't stretched, big ones stop at 420px */
.recipe-image { display: inline-block; max-width: min(100%, 420px); margin: 1rem 0; line-height: 0; }
.recipe-image img { display: block; max-width: 100%; height: auto; }

.rich-text ul, .rich-text ol { padding-left: 1.5rem; }

/* ---------- 6 Forms ---------- */
.recipe-form { max-width: 800px; margin: 0 auto; }
.recipe-form label { font-weight: bold; }
.current-image { max-width: 240px; }

/* category checkboxes on the recipe form */
.cat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(11rem, 1fr)); gap: .4rem .8rem; margin-top: .4rem; }
.cat-option { font-weight: normal; display: flex; align-items: center; gap: .4rem; }

/* ---------- 7 Cook mode ---------- */

/* the oval on/off switch with a sliding knob */
.cook-switch { display: inline-flex; align-items: center; gap: .6rem; cursor: pointer; user-select: none; font-weight: bold; }
.cook-switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }   /* hidden, but still works with keyboard and screen readers */
.cook-switch .slider {
  position: relative; flex: none; width: 52px; height: 28px;
  border-radius: 999px; background: #b5b5b5; transition: background .2s;
}
.cook-switch .slider::before {
  content: ''; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px;
  border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.4); transition: transform .2s;
}
.cook-switch input:checked + .slider { background: #2e7d32; }
.cook-switch input:checked + .slider::before { transform: translateX(24px); }
.cook-switch input:focus-visible + .slider { outline: 3px solid #1565c0; outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) {
  .cook-switch .slider, .cook-switch .slider::before { transition: none; }
}

/* the page while cook mode is on: big text, no clutter, tap to cross things off */
@media screen {
  body.cook-mode .site-nav,
  body.cook-mode .recipe-image,
  body.cook-mode .chips,
  body.cook-mode .recipe > p.no-print:not(.cook-controls) { display: none; }

  body.cook-mode .recipe-banner h1 { font-size: 1.8rem; }
  body.cook-mode .recipe { font-size: 1.35rem; line-height: 1.65; max-width: 900px; }
  body.cook-mode .recipe h2 { font-size: 1.6rem; }
  body.cook-mode .recipe li { padding: .7rem .5rem; cursor: pointer; user-select: none; -webkit-tap-highlight-color: transparent; }
  body.cook-mode .recipe li.done { text-decoration: line-through; opacity: .4; }
  body.cook-mode .rich-text ol, body.cook-mode .rich-text ul { padding-left: 2rem; }

  /* the switch stays pinned to the top so it's easy to switch off */
  body.cook-mode .cook-switch {
    position: fixed; top: .6rem; right: .6rem; z-index: 20;
    background: #fff; padding: .4rem .9rem; border-radius: 999px;
    box-shadow: 0 2px 8px rgba(0,0,0,.4);
  }
  /* its message appears just below it */
  body.cook-mode #cook-note {
    position: fixed; top: 3.9rem; right: .6rem; z-index: 20; max-width: 18rem;
    background: #fff; padding: .5rem .8rem; border-radius: 8px; font-size: .9rem; line-height: 1.4;
    box-shadow: 0 2px 8px rgba(0,0,0,.4);
  }
  body.cook-mode #cook-note:empty { display: none; }
}

/* ---------- 8 Error pages (403, 404, 500) ---------- */
.error-photo { display: block; width: 100%; max-width: 480px; height: auto; margin: 1.5rem auto 1rem; border-radius: 8px; box-shadow: 0 2px 8px rgba(0,0,0,.25); }

/* ---------- 9 Print (last, so it overrides the rules above) ---------- */
@page { margin: 0.6in; }

@media print {
  .site-nav, .no-print { display: none !important; }

  body { background: #fff; color: #000; font-size: 12pt; }

  /* a plain title instead of a solid color block */
  .recipe-banner { background: none !important; color: #000 !important; border-bottom: 2px solid #000; padding: 0; }
  .recipe-banner h1 { margin: 0 0 .3rem; padding: 0 !important; font-size: 24pt; color: #000; }

  .recipe { max-width: none; padding: 0; }
  .w3-container { padding-left: 0; padding-right: 0; }
  .w3-card-4 { box-shadow: none; }
  .recipe-image { max-width: 3in; margin: .5rem 0; }

  /* keep headings with what follows, and don't split pictures or list items */
  h2 { break-after: avoid; page-break-after: avoid; color: #000 !important; font-size: 16pt; margin-top: 1rem; }
  img, .recipe-image { break-inside: avoid; page-break-inside: avoid; }
  li { break-inside: avoid; page-break-inside: avoid; }
  p { orphans: 3; widows: 3; }

  .chip { border: 1px solid #000; background: none; color: #000; }
  a { color: inherit; text-decoration: none; }
}
