:root {
  --blue: #2e74b5;
  --orange: #c45911;
  --green: #538135;
  --purple: #8f3d78;
  --brown: #514330;
  --field-border: #63533f;
  --button: #3484c4;
  --text: #1d1d1f;
  --muted: #6b6b70;
  --bar-height: 56px;
  --font: -apple-system, BlinkMacSystemFont, "Helvetica Neue", Helvetica, Arial, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background: #fff;
  line-height: 1.4;
}

a { color: var(--blue); }
img { max-width: 100%; height: auto; }
button, input, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: 0.5; }

:focus-visible { outline: 3px solid #ffbf47; outline-offset: 1px; }

.skip-link {
  position: absolute;
  left: -999px;
  top: 0;
  background: #fff;
  padding: 0.5rem 1rem;
  z-index: 100;
}
.skip-link:focus { left: 0; }

[hidden] { display: none !important; }

/* Shell */
.shell { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }
.content { flex: 1; display: flex; flex-direction: column; width: 100%; max-width: 960px; margin: 0 auto; outline: none; }
#main { flex: 1; display: flex; flex-direction: column; min-height: 0; }

.app-bar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: 56px 1fr 56px;
  align-items: center;
  height: var(--bar-height);
  padding-top: env(safe-area-inset-top);
  color: #fff;
  background: var(--orange);
}
.app-bar.blue { background: var(--blue); }
.app-bar.green { background: var(--green); }
.app-bar.purple { background: var(--purple); }
.app-bar.brown { background: var(--brown); }
.app-bar h1 { margin: 0; font-size: 1.2rem; text-align: center; font-weight: 700; }
.bar-right { display: flex; justify-content: flex-end; }

.bar-button {
  background: none;
  border: 0;
  color: #fff;
  font-weight: 700;
  padding: 0.6rem 1rem;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.bar-icon { font-size: 1.8rem; line-height: 1; min-width: 56px; height: var(--bar-height); }
.bar-add { font-size: 2rem; line-height: 1; min-width: 56px; height: var(--bar-height); }

/* Side menu */
.menu {
  position: fixed;
  inset: 0 auto 0 0;
  width: min(320px, 85vw);
  background: #fff;
  z-index: 40;
  transform: translateX(-102%);
  transition: transform 0.2s ease;
  box-shadow: 4px 0 16px rgba(0, 0, 0, 0.25);
  visibility: hidden;
}
.menu-open .menu { transform: none; visibility: visible; }
.scrim {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  z-index: 30;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}
.menu-open .scrim { opacity: 1; pointer-events: auto; }

.menu-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem;
  color: var(--orange);
  font-weight: 800;
  font-size: 1.4rem;
  text-decoration: none;
  border-bottom: 1px solid #ccc;
  margin-bottom: 0.75rem;
}
.menu-item {
  display: block;
  margin: 0 0 8px;
  padding: 1.35rem 1rem;
  color: #fff;
  font-size: 1.15rem;
  text-decoration: none;
  background: var(--blue);
}
.menu-item.green { background: var(--green); }
.menu-item.orange { background: var(--orange); }
.menu-item.purple { background: var(--purple); }
.menu-item.brown { background: var(--brown); }
.menu-item.grey { background: #5f6368; }

/* Buttons and fields */
.btn {
  display: inline-block;
  min-width: 110px;
  padding: 0.6rem 1.2rem;
  color: #fff;
  background: var(--button);
  border: 2px solid var(--button);
  border-radius: 2px;
  text-align: center;
  text-decoration: none;
}
.btn-secondary { color: var(--button); background: #fff; }
.btn-danger { background: #b3261e; border-color: #b3261e; }

.link-button { background: none; border: 0; padding: 0.25rem 0.5rem; color: var(--brown); }

.text-input, .search, .recipe-name, .instructions {
  width: 100%;
  padding: 0.6rem 0.7rem;
  border: 1px solid #c8c8cc;
  border-radius: 3px;
  background: #fff;
}
.field-label, .field > span { display: block; margin: 0.9rem 0 0.25rem; font-size: 0.95rem; }
.instructions { resize: vertical; min-height: 12rem; }
.empty { padding: 2rem 1rem; text-align: center; color: var(--muted); }
.hint { color: var(--muted); font-size: 0.9rem; }
.notice {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin: 0.75rem;
  padding: 0.75rem 1rem;
  background: #fdf1e8;
  border-left: 4px solid var(--orange);
}
.form-error { color: #b3261e; min-height: 1.4em; margin: 0.5rem 0; }

/* Lists */
.list-panel { display: flex; flex-direction: column; flex: 1; }
.search { margin: 0; border-radius: 0; border-width: 0 0 1px; padding: 0.9rem 1rem; font-size: 1.05rem; }
.list { flex: 1; }
.list-row {
  display: grid;
  grid-template-columns: 2fr 2fr 1fr;
  gap: 0.75rem;
  align-items: center;
  width: 100%;
  min-height: 60px;
  padding: 0.6rem 1rem;
  background: #fff;
  border: 0;
  text-align: left;
  color: inherit;
}
.list-row:nth-child(odd) { background: rgba(196, 89, 17, 0.12); }
.ingredient-row:nth-child(odd) { background: rgba(83, 129, 53, 0.2); }
.row-main { font-weight: 600; }
.row-sub, .row-meta { color: var(--muted); }
.recipe-list-row { grid-template-columns: 1fr auto; padding: 0; }
.row-link {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem;
  color: inherit;
  text-decoration: none;
}
.icon-button { background: none; border: 0; padding: 0.8rem 1rem; font-size: 1.2rem; }

/* Recipe editor */
.recipe-editor { display: flex; flex-direction: column; flex: 1; }
.recipe-name-bar { background: rgba(46, 116, 181, 0.2); padding: 0.5rem 0.75rem; }
.recipe-name { background: transparent; border: 0; font-size: 1.15rem; padding: 0.6rem 0.25rem; }
.toolbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  background: var(--blue);
  padding: 0 0.5rem;
}
.toolbar-button {
  flex: 1 1 auto;
  background: none;
  border: 0;
  color: #fff;
  font-weight: 700;
  font-size: 1.05rem;
  padding: 1rem 0.5rem;
}
.stats { display: grid; grid-template-columns: repeat(4, 1fr); background: rgba(46, 116, 181, 0.18); }
.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  padding: 0.9rem 0.25rem;
  text-align: center;
  border-left: 1px solid #000;
}
.stat:first-child { border-left: 0; }
.stat strong { font-size: 0.95rem; }
.recipe-table { flex: 1; margin-top: 8px; }
.recipe-head, .recipe-row {
  display: grid;
  grid-template-columns: 2.2fr 2fr 1.6fr 1fr 36px;
  gap: 0.5rem;
  align-items: start;
  padding: 0.75rem 1rem;
}
.recipe-head { background: var(--blue); color: #fff; align-items: center; padding-block: 0.6rem; }
.recipe-row { background: rgba(46, 116, 181, 0.1); min-height: 64px; cursor: pointer; }
.recipe-row.selected { background: rgba(46, 116, 181, 0.32); }
.recipe-row[draggable="true"]:active { cursor: grabbing; }
.cell-handle { color: #a0a0a6; text-align: center; cursor: grab; font-size: 1.3rem; line-height: 1; }
.bottom-bar {
  position: sticky;
  bottom: 0;
  display: flex;
  justify-content: space-between;
  background: var(--blue);
  padding-bottom: env(safe-area-inset-bottom);
}
.bottom-bar .bar-button { padding: 1rem 1.5rem; }

@media (max-width: 640px) {
  .recipe-head .cell-prep, .recipe-head .cell-unit, .cell-unit { display: none; }
  .recipe-head, .recipe-row {
    grid-template-columns: 1fr 1fr 28px;
    grid-template-areas: "amount name handle" "amount prep handle";
  }
  .recipe-head .cell-amount, .recipe-row .cell-amount { grid-area: amount; }
  .recipe-head .cell-name, .recipe-row .cell-name { grid-area: name; }
  .recipe-row .cell-prep { grid-area: prep; color: var(--muted); }
  .recipe-head .cell-handle, .recipe-row .cell-handle { grid-area: handle; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .stat:nth-child(3) { border-left: 0; }
  .list-row { grid-template-columns: 1fr; gap: 0.1rem; }
  .toolbar-button { font-size: 0.95rem; padding: 0.8rem 0.4rem; }
}

/* Home, guide, legal, forms */
.home { text-align: center; padding: 2rem 1rem; }
.home-image { display: block; margin: 0 auto; }
.home h1 { color: var(--orange); margin: 0.5rem 0; }
.lead { max-width: 36rem; margin: 0 auto 1.5rem; font-size: 1.1rem; }
.home-actions { display: flex; gap: 0.75rem; justify-content: center; flex-wrap: wrap; }

.page-padded { padding: 1.25rem 1.25rem 2rem; }
.prose { max-width: 46rem; }
.prose h2, .settings-group h2 { clear: both; color: var(--orange); font-size: 1.2rem; margin: 1.5rem 0 0.5rem; }
.prose li { margin-bottom: 0.5rem; }
.about-links { display: flex; flex-wrap: wrap; gap: 0.75rem; margin: 1rem 0; }
.about-photo { float: right; width: min(45%, 260px); margin: 0.25rem 0 1rem 1.5rem; }
.about-photo img { display: block; width: 100%; height: auto; border-radius: 6px; }
.about-photo figcaption { margin-top: 0.4rem; color: var(--muted); font-size: 0.85rem; }
@media (max-width: 520px) {
  .about-photo { float: none; width: min(100%, 320px); margin: 1rem auto; }
}

.settings-group { margin-bottom: 1.5rem; }
.check-row { display: flex; align-items: center; gap: 0.9rem; padding: 0.6rem 0; font-size: 1.1rem; cursor: pointer; }
.check-row input { position: absolute; opacity: 0; width: 1.5rem; height: 1.5rem; }
.check-box {
  flex: none;
  width: 1.9rem;
  height: 1.9rem;
  border: 2px solid var(--orange);
  border-radius: 5px;
  display: inline-block;
  position: relative;
}
.check-row input:checked + .check-box::after {
  content: "";
  position: absolute;
  left: 0.5rem;
  top: 0.1rem;
  width: 0.45rem;
  height: 1rem;
  border: solid var(--orange);
  border-width: 0 3px 3px 0;
  transform: rotate(40deg);
}
.check-row input:focus-visible + .check-box { outline: 3px solid #ffbf47; outline-offset: 1px; }

.auth-form { max-width: 26rem; margin: 0 auto; padding: 1.5rem 1.25rem 2rem; }
.auth-form h2 { color: var(--orange); }
.auth-links { margin-top: 1.25rem; }

/* Dialogs */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(0, 0, 0, 0.45);
}
.modal {
  width: min(94vw, 600px);
  max-height: 94vh;
  max-height: 94dvh;
  overflow: auto;
  padding: 1.25rem 1.5rem;
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.35);
}
.modal h2 { margin: 0 0 0.75rem; font-size: 1.3rem; }
.modal-small { width: min(94vw, 420px); }
.modal-instructions { width: min(94vw, 640px); }
.modal-full {
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  max-height: none;
  padding: 0;
  border-radius: 0;
  display: flex;
  flex-direction: column;
}
.modal-full .list-panel { overflow: auto; }
.modal-full .search { position: sticky; top: 0; z-index: 1; }
.modal-bar { display: grid; grid-template-columns: 90px 1fr 90px; align-items: center; height: var(--bar-height); color: #fff; font-weight: 700; text-align: center; background: var(--green); flex: none; }
.modal-bar .bar-button { justify-self: start; }
.dialog-actions { display: flex; flex-wrap: wrap; gap: 0.75rem; justify-content: space-around; margin-top: 1.25rem; }
.dialog-ingredient { color: var(--orange); font-size: 1.5rem !important; }

.modal-amounts { width: min(96vw, 640px); }
.amount-fields { display: flex; flex-wrap: wrap; gap: 1rem 2rem; }
.amount-group { flex: 1 1 240px; }
.amount-group label { display: block; margin-bottom: 0.3rem; color: var(--brown); }
.amount-row { display: flex; align-items: center; gap: 0.25rem; }
.amount-field { flex: 1; min-width: 0; padding: 0.55rem 0.6rem; border: 1px solid #aaa; border-radius: 2px; background: #fafafa; }
.amount-field.active-field { border: 2px solid var(--field-border); }
.keypad { display: flex; gap: 1rem; margin: 0.75rem 0; align-items: flex-start; }
.keys-numbers { flex: 1; display: grid; grid-template-columns: repeat(4, 1fr); }
.keys-side { display: flex; flex-direction: column; min-width: 4.5rem; }
.key {
  background: none;
  border: 0;
  padding: 0.6rem 0.3rem;
  color: var(--blue);
  font-size: 1.15rem;
  min-height: 44px;
}
.key:hover { background: rgba(46, 116, 181, 0.08); }
.key-each.active { background: var(--blue); color: #fff; border-radius: 4px; }
.keys-units { display: grid; grid-template-columns: repeat(4, 1fr); margin: 0.5rem 0 0; }
.units-column { display: flex; flex-direction: column; }
.units-column .key { font-size: 1.05rem; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(1.5rem + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 100;
  max-width: 90vw;
  padding: 0.75rem 1.25rem;
  color: #fff;
  background: rgba(30, 30, 30, 0.92);
  border-radius: 8px;
  text-align: center;
}

.site-footer { padding: 1.5rem 1rem calc(1.5rem + env(safe-area-inset-bottom)); text-align: center; color: var(--muted); font-size: 0.85rem; }
.site-footer p { margin: 0.25rem 0; }
.footer-note { font-style: italic; }

@media (prefers-reduced-motion: reduce) {
  .menu, .scrim { transition: none; }
}
