/* Tokens, elements and the components shared by the planner and the sign-in page. */
@font-face {
  font-family: "Bricolage Grotesque";
  src: url("/fonts/bricolage-grotesque.woff2") format("woff2");
  font-weight: 200 800;
  font-stretch: 75% 100%;
  font-display: optional;
}

:root {
  color-scheme: light dark;
  --bg: light-dark(#f4f6f5, #0e1426);
  --surface: light-dark(#ffffff, #161e37);
  --sunken: light-dark(#e8ecee, #121a30);
  --ink: light-dark(#131c3a, #e8ecf8);
  --muted: light-dark(#4a5470, #a7b1cc);
  --line: light-dark(#d3d9e4, #2a3558);
  --line-control: light-dark(#7d879f, #6f7ba0);
  --primary: light-dark(#1b3fa0, #a3b8ff);
  --primary-hover: light-dark(#142f7a, #c0cfff);
  --on-primary: light-dark(#ffffff, #0e1426);
  --primary-soft: light-dark(#e3e9f8, #1e2a52);
  --mark: #f6b92b;
  --mark-soft: light-dark(#fdf2d0, #3a2f10);
  --on-mark: #131c3a;
  --danger: light-dark(#a4244b, #f58aa6);
  --on-danger: light-dark(#ffffff, #0e1426);
  --scrim: light-dark(rgb(19 28 58 / 55%), rgb(4 7 16 / 70%));
  --shadow: 0 24px 70px light-dark(rgb(19 28 58 / 24%), rgb(0 0 0 / 60%));

  --font: "Bricolage Grotesque", "Avenir Next", "Segoe UI Variable", "Segoe UI", system-ui, sans-serif;
  --text-xs: .8125rem;
  --text-sm: .875rem;
  --text-base: 1rem;
  --text-lg: 1.125rem;
  --text-xl: 1.5rem;
  --text-2xl: clamp(1.75rem, 3.2vw, 2.25rem);
  --text-display: clamp(2.75rem, 7.5vw, 4.5rem);

  --radius-photo: 4px;
  --radius-control: 8px;
  --radius-sheet: 16px;
  --gutter: clamp(20px, 5vw, 56px);
  --page: 1160px;
  --fast: 120ms;
}

:root:where([data-theme="light"]) { color-scheme: light; }
:root:where([data-theme="dark"]) { color-scheme: dark; }

* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 96px; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: var(--text-base);
  font-weight: 400;
  line-height: 1.55;
  font-synthesis: none;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
button, a, input, select, textarea { -webkit-tap-highlight-color: transparent; }
button { min-height: 44px; touch-action: manipulation; cursor: pointer; }
button:disabled { opacity: .45; cursor: not-allowed; }
a { color: var(--primary); text-underline-offset: .18em; }
img { max-width: 100%; }
:focus-visible { outline: 3px solid var(--primary); outline-offset: 3px; border-radius: 2px; }
::selection { background: var(--primary); color: var(--on-primary); }

h1, h2, h3, h4 { margin: 0; text-wrap: balance; }
h1 { font-size: var(--text-display); font-weight: 800; font-stretch: 75%; line-height: .95; letter-spacing: -.02em; }
h2 { font-size: var(--text-2xl); font-weight: 750; font-stretch: 80%; line-height: 1.08; letter-spacing: -.01em; }
h3 { font-size: var(--text-xl); font-weight: 680; font-stretch: 87.5%; line-height: 1.18; }
p { margin: 0; text-wrap: pretty; }
.lede { max-width: 58ch; margin-top: 14px; color: var(--muted); font-size: var(--text-lg); line-height: 1.5; }
.muted { color: var(--muted); font-size: var(--text-sm); line-height: 1.55; }
.fineprint { max-width: 78ch; color: var(--muted); font-size: var(--text-xs); line-height: 1.55; }
.eyebrow { color: var(--muted); font-size: var(--text-sm); font-weight: 650; }

/* Header: the double rule is the woven stripe of a tea towel, used once. */
.topbar {
  position: sticky;
  top: 0;
  z-index: 15;
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 12px max(var(--gutter), calc((100vw - var(--page)) / 2));
  border-bottom: 3px solid var(--primary);
  background: var(--bg);
  box-shadow: 0 3px 0 var(--bg), 0 4px 0 var(--primary);
}
.brand {
  display: inline-flex;
  align-items: center;
  color: var(--ink);
  font-size: 1.625rem;
  font-weight: 800;
  font-stretch: 75%;
  letter-spacing: -.01em;
  line-height: 1;
  text-decoration: none;
  white-space: nowrap;
}
.brand > span { color: var(--muted); font-weight: 400; }
.brand > img { width: 1.25em; height: 1.25em; margin-right: .35em; }
.topbar nav { display: flex; align-items: center; gap: 4px; margin-left: auto; }
.nav-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border: 0;
  border-radius: var(--radius-control);
  background: none;
  color: var(--muted);
  font-weight: 600;
}
.nav-link:hover { color: var(--ink); }
.nav-link.active { background: var(--primary-soft); color: var(--primary); }
.icon { width: 19px; height: 19px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
#add-recipe { margin-left: 8px; }

main { max-width: calc(var(--page) + 2 * var(--gutter)); min-height: 72vh; margin: 0 auto; padding: 44px var(--gutter) 88px; }
main:focus { outline: 0; }
.page-heading { margin: 0 0 28px; }
footer { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px 24px; max-width: calc(var(--page) + 2 * var(--gutter)); margin: 0 auto; padding: 24px var(--gutter) 32px; border-top: 1px solid var(--line); }
footer .brand { font-size: 1.125rem; }
.theme-picker { display: inline-flex; align-items: center; gap: 10px; color: var(--muted); font-size: var(--text-sm); }
.theme-picker select { width: auto; min-height: 44px; }

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 11px 20px;
  border: 1.5px solid var(--primary);
  border-radius: var(--radius-control);
  background: var(--primary);
  color: var(--on-primary);
  font-weight: 650;
  line-height: 1.3;
  text-decoration: none;
  transition: background var(--fast), border-color var(--fast);
}
.button:hover { border-color: var(--primary-hover); background: var(--primary-hover); }
.button.secondary { background: var(--surface); color: var(--primary); }
.button.secondary:hover { background: var(--primary-soft); }
.button.small { min-height: 44px; padding: 9px 15px; }
.text-button {
  padding: 8px 2px;
  border: 0;
  background: none;
  color: var(--primary);
  font-weight: 600;
  text-align: left;
  text-decoration: underline;
  text-decoration-color: transparent;
  text-underline-offset: .2em;
  transition: text-decoration-color var(--fast);
}
.text-button:hover { text-decoration-color: currentColor; }
.action-row { display: flex; align-items: center; flex-wrap: wrap; gap: 12px 20px; margin-bottom: 24px; }
.action-row > :first-child { margin-right: auto; }

.tag {
  display: inline-block;
  padding: 3px 9px;
  border-radius: var(--radius-photo);
  background: var(--sunken);
  color: var(--ink);
  font-size: var(--text-xs);
  font-weight: 600;
  line-height: 1.5;
  white-space: nowrap;
}
.tag.green { background: var(--primary-soft); color: var(--primary); }
.tag.draft { background: var(--mark); color: var(--on-mark); }

.field { display: flex; flex-direction: column; gap: 7px; margin-bottom: 20px; font-size: var(--text-sm); font-weight: 650; }
.field small { color: var(--muted); font-size: var(--text-xs); font-weight: 400; line-height: 1.55; }
input:not([type=checkbox], [type=file]), select, textarea {
  width: 100%;
  min-width: 0;
  min-height: 48px;
  padding: 11px 13px;
  border: 1px solid var(--line-control);
  border-radius: var(--radius-control);
  background: var(--surface);
  font-size: var(--text-base);
  font-weight: 400;
  line-height: 1.45;
}
input:not([type=checkbox], [type=file]):focus-visible, select:focus-visible, textarea:focus-visible {
  outline-offset: 0;
  border-color: var(--primary);
  border-radius: var(--radius-control);
}
textarea { min-height: 104px; resize: vertical; }
input::placeholder, textarea::placeholder { color: var(--muted); opacity: 1; }
select {
  appearance: none;
  padding-right: 40px;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: right 19px center, right 13px center;
  background-size: 6px 6px;
  background-repeat: no-repeat;
}
input[type=file] { max-width: 100%; font-size: var(--text-sm); }
input[type=checkbox] {
  appearance: none;
  position: relative;
  flex: none;
  width: 24px;
  height: 24px;
  margin: 0;
  border: 1.5px solid var(--line-control);
  border-radius: 6px;
  background: var(--surface);
  cursor: pointer;
  transition: background var(--fast), border-color var(--fast);
}
input[type=checkbox]:checked { border-color: var(--primary); background: var(--primary); }
input[type=checkbox]:checked::after {
  position: absolute;
  top: 3px;
  left: 7px;
  width: 6px;
  height: 11px;
  border: solid var(--on-primary);
  border-width: 0 2.5px 2.5px 0;
  content: "";
  transform: rotate(45deg);
}
.check-field { display: flex; align-items: flex-start; gap: 12px; min-height: 44px; margin: 14px 0; cursor: pointer; }
.check-field > span { padding-top: 1px; line-height: 1.45; }
.check-field strong { display: block; font-weight: 650; }
.check-field small { display: block; margin-top: 2px; color: var(--muted); font-size: var(--text-sm); line-height: 1.5; }
.check-field.compact { margin: 6px 0; }
.form-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0 16px; }

.notice {
  margin: 20px 0;
  padding: 14px 16px;
  border-left: 4px solid var(--mark);
  border-radius: var(--radius-photo);
  background: var(--mark-soft);
  font-size: var(--text-sm);
  line-height: 1.55;
}
#dialog-error { border-left-color: var(--danger); }

.loading-state { max-width: 640px; padding: 12px 0; }
.loading { margin-bottom: 20px; color: var(--muted); font-size: var(--text-xl); font-weight: 680; font-stretch: 87.5%; }
.skeleton-line { display: block; height: 16px; margin: 12px 0; border-radius: var(--radius-photo); background: var(--sunken); animation: skeleton-pulse 1.4s ease-in-out infinite alternate; }
.skeleton-line.short { width: 62%; }
@keyframes skeleton-pulse { to { opacity: .45; } }

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  z-index: 40;
  width: max-content;
  max-width: min(620px, calc(100% - 32px));
  margin: 0;
  padding: 13px 18px;
  border-radius: var(--radius-control);
  background: var(--ink);
  color: var(--bg);
  font-size: var(--text-sm);
  font-weight: 600;
  line-height: 1.5;
  transform: translateX(-50%);
}
.toast.is-error { background: var(--danger); color: var(--on-danger); }

dialog {
  width: min(880px, calc(100% - 32px));
  max-height: 90dvh;
  padding: 36px;
  overflow-x: hidden;
  border: 0;
  border-radius: var(--radius-sheet);
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow);
}
dialog[open] { animation: dialog-in 180ms cubic-bezier(.2, .8, .2, 1); }
dialog::backdrop { background: var(--scrim); }
@keyframes dialog-in { from { opacity: 0; transform: translateY(10px); } }
dialog h2 { padding-right: 44px; }
dialog h2 + .muted { margin-top: 10px; }
.dialog-actions {
  position: sticky;
  top: -20px;
  z-index: 2;
  display: flex;
  flex-direction: row-reverse;
  gap: 8px;
  width: max-content;
  /* The controls overlay the content without adding height. */
  margin: -16px -16px -28px auto;
}
.close-button, .dialog-icon-button {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface);
}
.close-button {
  font-size: 1.625rem;
  line-height: 1;
}
.dialog-icon-button { color: var(--muted); }
.dialog-icon-button:hover { color: var(--primary); }

@media (max-width: 720px) {
  html { scroll-padding-top: 16px; }
  body { padding-bottom: calc(70px + env(safe-area-inset-bottom)); }
  .topbar { position: static; }
  .topbar nav {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 30;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
    margin: 0;
    padding: 6px 12px calc(6px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--line);
    background: var(--surface);
  }
  .nav-link, #add-recipe {
    flex-direction: column;
    gap: 2px;
    min-height: 54px;
    margin: 0;
    padding: 5px;
    font-size: var(--text-xs);
  }
  #sign-out { margin-left: auto; }
  main { padding-top: 28px; padding-bottom: 56px; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid:has(input[type=number]) { grid-template-columns: none; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 0 12px; align-items: end; }
  dialog {
    width: 100%;
    max-width: 100%;
    max-height: 92dvh;
    margin: auto 0 0;
    padding: 24px 20px calc(24px + env(safe-area-inset-bottom));
    border-radius: var(--radius-sheet) var(--radius-sheet) 0 0;
  }
  .dialog-actions { top: -14px; margin: -10px -8px -34px auto; }
  .toast { bottom: calc(82px + env(safe-area-inset-bottom)); }
}

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