:root {
  color-scheme: light dark;

  --paper: light-dark(#f7f2e9, #16120f);
  --card: light-dark(#fffdf8, #221c17);
  --ink: light-dark(#2c2620, #ece4d7);
  --ink-soft: light-dark(#6f6357, #ab9e8e);
  --rule: light-dark(#e3d9c9, #3a3129);
  --accent: light-dark(#a24a1c, #e5985c);
  --accent-soft: light-dark(#f4e7d9, #32261d);

  --serif: ui-serif, Georgia, "Times New Roman", serif;
  --sans:
    ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

  --radius: 10px;
  --shadow: 0 1px 2px light-dark(rgb(70 45 20 / 7%), rgb(0 0 0 / 35%));
  --page: 44rem;
}

* {
  box-sizing: border-box;
}

/* Colonna alta quanto la finestra: il fondo pagina resta in fondo anche
   quando le ricette sono quattro. */
body {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 1rem/1.6 var(--sans);
}

main {
  flex: 1;
  width: 100%;
  max-width: var(--page);
  margin: 0 auto;
  padding: 2rem 1.25rem 3rem;
}

a {
  color: inherit;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 3px;
}

/* Barra in cima: resta appesa mentre si scorre, con il fondo che vela il
   contenuto invece di coprirlo. */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  border-bottom: 1px solid var(--rule);
  background: color-mix(in srgb, var(--paper) 82%, transparent);
  backdrop-filter: blur(10px);
}
.topbar > div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  max-width: var(--page);
  margin: 0 auto;
  padding: 0.7rem 1.25rem;
}
.brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font: 600 1.3rem/1 var(--serif);
  letter-spacing: 0.01em;
  text-decoration: none;
}
.brand svg {
  flex: none;
  fill: var(--accent);
}
.topbar nav {
  display: flex;
  align-items: center;
  gap: 0.8rem;
}
/* Fondo pagina: chi sei, come esci, che tema vuoi. */
.site {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.9rem 1rem;
  width: 100%;
  max-width: var(--page);
  margin: 0 auto;
  padding: 1.5rem 1.25rem 2.5rem;
  border-top: 1px solid var(--rule);
  font-size: 0.8125rem;
  color: var(--ink-soft);
}
.site .session {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0;
}
.site .session form {
  display: flex;
  margin: 0;
}
.site .dot {
  opacity: 0.5;
}
/* Sul telefono i due gruppi si impilano e si centrano. */
@media (max-width: 26rem) {
  .site {
    flex-direction: column;
    justify-content: center;
  }
}

.theme {
  display: inline-flex;
  gap: 2px;
  padding: 2px;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: var(--card);
}
.theme button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 1.75rem;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--ink-soft);
  cursor: pointer;
  transition:
    background 120ms,
    color 120ms;
}
.theme button:hover {
  color: var(--ink);
}
.theme button[aria-pressed="true"] {
  background: var(--accent-soft);
  color: var(--accent);
}
.theme svg {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.4;
  stroke-linecap: round;
}

/* Comandi */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.5rem 0.85rem;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: var(--card);
  box-shadow: var(--shadow);
  color: inherit;
  font: 500 0.875rem/1 var(--sans);
  text-decoration: none;
  cursor: pointer;
  transition:
    border-color 120ms,
    color 120ms,
    background 120ms;
}
.btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}
.btn.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--paper);
}
.btn.primary:hover {
  color: var(--paper);
  filter: brightness(1.08);
}

/* Testo cliccabile, senza il peso di un pulsante */
.quiet {
  padding: 0;
  border: 0;
  background: none;
  color: var(--ink-soft);
  font: 0.8125rem/1.5 var(--sans);
  text-decoration: underline;
  text-decoration-color: var(--rule);
  text-underline-offset: 0.2em;
  cursor: pointer;
  transition: color 120ms;
}
.quiet:hover {
  color: var(--accent);
}

input,
textarea {
  font: inherit;
  color: inherit;
}

.field-box {
  width: 100%;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: var(--card);
  font-size: 0.9375rem;
}
.field-box:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.error {
  margin: 0 0 1.2rem;
  padding: 0.7rem 0.9rem;
  border: 1px solid var(--accent);
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.9rem;
}

/* Ricerca e tag */
.filters {
  display: flex;
  gap: 0.6rem;
  margin-bottom: 0.9rem;
}
.search {
  position: relative;
  flex: 1;
}
.search svg {
  position: absolute;
  top: 50%;
  left: 0.7rem;
  translate: 0 -50%;
  color: var(--ink-soft);
  pointer-events: none;
}
.search input {
  padding-left: 2.1rem;
}

.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 2rem;
}
.tag {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.1rem 0.45rem;
  border: 1px solid var(--rule);
  border-radius: 5px;
  background: var(--card);
  font-size: 0.75rem;
  text-decoration: none;
  cursor: pointer;
  transition:
    border-color 120ms,
    color 120ms;
}
.tag:hover {
  border-color: var(--accent);
  color: var(--accent);
}
.tag.on {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}
.tag .count {
  color: var(--ink-soft);
  font-size: 0.7rem;
}
.tag.on .count {
  color: inherit;
}

/* Indice */
.count-line {
  margin: 0 0 1.4rem;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--ink-soft);
}

/* Un pannello solo, righe rigate dentro: si scorre come un elenco vero
   invece che come tanti blocchetti staccati. */
.index {
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.letter {
  display: grid;
  grid-template-columns: 2.2rem 1fr;
}
.letter > h2 {
  margin: 0;
  padding-top: 0.95rem;
  font: 700 0.875rem/1 var(--sans);
  color: var(--accent);
  text-align: center;
}
.row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.7rem 0.9rem;
  border-top: 1px solid var(--rule);
  text-decoration: none;
  transition: background 120ms;
}
.letter:first-child .row:first-child {
  border-top: 0;
}
.row:hover {
  background: var(--accent-soft);
}
.row .title {
  font: 1.0625rem/1.4 var(--serif);
}
.row:hover .title {
  color: var(--accent);
}
.row .by {
  flex: none;
  font-size: 0.8125rem;
  color: var(--ink-soft);
}

.empty {
  padding: 3rem 1rem;
  border: 1px dashed var(--rule);
  border-radius: var(--radius);
  color: var(--ink-soft);
  font-style: italic;
  text-align: center;
  margin: 1rem;
}

/* Ricetta */
.recipe header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1.5rem;
  margin-bottom: 0.5rem;
}
.recipe h1 {
  margin: 0;
  font: 700 2.1rem/1.15 var(--serif);
  letter-spacing: -0.01em;
}
.recipe .meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem;
  margin: 0 0 2rem;
  font-size: 0.8125rem;
  color: var(--ink-soft);
}
.recipe .meta .sep {
  opacity: 0.5;
}
.recipe .meta .tag {
  margin-left: 0.15rem;
}
.recipe footer {
  margin-top: 3.5rem;
  padding-top: 1.2rem;
  border-top: 1px solid var(--rule);
  font-size: 0.8125rem;
  color: var(--ink-soft);
}

/* Il markdown reso: stessa classe in lettura e dentro l'editor, cosi' si
   scrive esattamente quello che si vedra' pubblicato. */
.body {
  font: 1.0625rem/1.75 var(--serif);
}
.body > :first-child {
  margin-top: 0;
}
.body h2 {
  margin: 2.4rem 0 0.9rem;
  padding-bottom: 0.4rem;
  border-bottom: 1px solid var(--rule);
  font: 600 0.9375rem/1.3 var(--sans);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}
.body h3 {
  margin: 1.8rem 0 0.6rem;
  font: 600 0.8125rem/1.3 var(--sans);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--ink-soft);
}
.body ul {
  padding-left: 1.2rem;
}
.body li {
  margin: 0.3rem 0;
}
.body ul li::marker {
  color: var(--accent);
}
/* L'elenco che apre una sezione sono gli ingredienti: vale un pannello,
   su due colonne quando c'e' spazio. */
.body h2 + ul {
  padding: 1rem 1.2rem 1rem 2.2rem;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow);
}
@media (min-width: 34rem) {
  .body h2 + ul {
    columns: 2;
    column-gap: 2rem;
  }
  .body h2 + ul li {
    break-inside: avoid;
  }
}
/* I passaggi sono la spina della ricetta: il numero si vede e si conta. */
.body ol {
  padding-left: 0;
  list-style: none;
  counter-reset: step;
}
.body ol > li {
  position: relative;
  margin: 0.9rem 0;
  padding-left: 2.7rem;
  counter-increment: step;
}
.body ol > li::before {
  content: counter(step);
  position: absolute;
  top: 0.15em;
  left: 0;
  width: 1.8rem;
  height: 1.8rem;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font: 600 0.8125rem/1.8rem var(--sans);
  text-align: center;
}
.body ol ul,
.body ol ol,
.body ul ul {
  margin: 0.4rem 0;
}
.body blockquote {
  margin: 1.6rem 0;
  padding: 0.9rem 1.1rem;
  border-left: 3px solid var(--accent);
  border-radius: 0 8px 8px 0;
  background: var(--card);
  color: var(--ink-soft);
  font-style: italic;
}
.body blockquote > :first-child {
  margin-top: 0;
}
.body blockquote > :last-child {
  margin-bottom: 0;
}
.body table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--sans);
  font-size: 0.9375rem;
}
.body th {
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 0.75rem;
  color: var(--ink-soft);
}
.body th,
.body td {
  padding: 0.5rem 0.7rem 0.5rem 0;
  border-bottom: 1px solid var(--rule);
  text-align: left;
}
.body a {
  text-decoration-color: var(--accent);
  text-underline-offset: 0.2em;
}
.body a:hover {
  color: var(--accent);
}
.body code {
  padding: 0.1em 0.35em;
  border-radius: 4px;
  background: var(--accent-soft);
  font-size: 0.875em;
}
.body hr {
  margin: 2.2rem 0;
  border: 0;
  border-top: 1px solid var(--rule);
}
.body img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius);
}

/* Form */
.recipe-form .title {
  width: 100%;
  margin-bottom: 1.5rem;
  padding: 0 0 0.4rem;
  border: 0;
  border-bottom: 2px solid var(--rule);
  background: none;
  font: 700 2.1rem/1.2 var(--serif);
  letter-spacing: -0.01em;
}
.recipe-form .title:focus {
  outline: none;
  border-bottom-color: var(--accent);
}
.recipe-form .title::placeholder {
  color: var(--ink-soft);
  opacity: 0.5;
}

.field {
  display: block;
  margin-bottom: 1.2rem;
}
.field > span {
  display: block;
  margin-bottom: 0.35rem;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--ink-soft);
}
/* Selettore dei tag: le pillole stanno dentro il campo, i suggerimenti
   scendono sotto. */
.tagbox {
  position: relative;
}
.chips {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: var(--card);
  cursor: text;
}
.tagbox:focus-within .chips {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.15rem;
  padding: 0.1rem 0.15rem 0.1rem 0.45rem;
  border: 1px solid var(--accent);
  border-radius: 5px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.75rem;
}
/* Il tag che ancora non esiste si vede che e' nuovo. */
.chip.new {
  border-style: dashed;
}
.chip button {
  padding: 0 0.15rem;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  font-size: 0.9rem;
  line-height: 1;
  opacity: 0.6;
  cursor: pointer;
}
.chip button:hover {
  opacity: 1;
}
#tag-input {
  flex: 1;
  min-width: 9rem;
  padding: 0.15rem;
  border: 0;
  background: none;
  font-size: 0.9375rem;
}
#tag-input:focus {
  outline: none;
}

.suggestions {
  position: absolute;
  z-index: 5;
  top: calc(100% + 4px);
  right: 0;
  left: 0;
  max-height: 13rem;
  overflow-y: auto;
  margin: 0;
  padding: 0.25rem;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: var(--card);
  box-shadow: 0 8px 20px light-dark(rgb(70 45 20 / 12%), rgb(0 0 0 / 45%));
  list-style: none;
}
.suggestions li {
  padding: 0.4rem 0.6rem;
  border-radius: 6px;
  font-size: 0.9rem;
  cursor: pointer;
}
.suggestions li:hover,
.suggestions li.on {
  background: var(--accent-soft);
  color: var(--accent);
}
.suggestions li.create {
  color: var(--ink-soft);
  font-style: italic;
}
.suggestions li.create:hover,
.suggestions li.create.on {
  color: var(--accent);
}

.form-actions {
  display: flex;
  align-items: center;
  gap: 1.2rem;
  margin-top: 1.5rem;
}
.delete {
  margin-top: 3.5rem;
  padding-top: 1.2rem;
  border-top: 1px solid var(--rule);
}

/* Entrata */
.login {
  max-width: 22rem;
  margin: 4rem auto;
  padding: 2rem;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow);
}
.login h1 {
  margin: 0 0 1.5rem;
  font: 600 1.5rem/1.2 var(--serif);
}
.login label {
  display: block;
  margin-bottom: 1rem;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--ink-soft);
}
.login label input {
  margin-top: 0.35rem;
  text-transform: none;
  letter-spacing: normal;
}
.login .btn {
  width: 100%;
  justify-content: center;
  margin-top: 0.5rem;
}

/* Pagina mancante */
.missing {
  padding: 4rem 0;
  text-align: center;
}
.missing h1 {
  margin: 0 0 0.5rem;
  font: 700 2rem/1.2 var(--serif);
}
.missing p {
  margin: 0 0 1.5rem;
  color: var(--ink-soft);
}

/* Stampa su carta */
@media print {
  .topbar,
  .site,
  .filters,
  .tags,
  .recipe footer,
  .recipe header .btn {
    display: none !important;
  }
  body {
    background: #fff;
    color: #000;
  }
  main {
    max-width: none;
    padding: 0;
  }
  .body h2 {
    break-after: avoid;
  }
  .body li,
  .body p,
  .body blockquote {
    break-inside: avoid;
  }
  .body h2 + ul,
  .body blockquote {
    box-shadow: none;
  }
}
