/* arecipe design tokens + components.
   The rules behind these values live in docs/DESIGN.md — palette, type
   roles, the spacing scale, and component practices. Derivation rule:
   spacing only from --s-*, color only from the palette, radii only from
   --r-*. If a value isn't derivable, the system (or the design) is wrong —
   fix it there, not inline. */

:root {
  /* palette — "enamelware, not parchment" */
  --tile: #f4f7f5;
  --ink: #1c2b27;
  --enamel: #175e54;
  --enamel-deep: #124b43;
  --enamel-soft: #175e5414;
  --yolk: #e8a013;
  --yolk-deep: #b87d0a;
  --rust: #b4552d;
  --card: #ffffff;
  --line: #d9e2de;

  /* type roles */
  --display: 'Fraunces', georgia, serif;
  --body: 'Atkinson Hyperlegible', system-ui, sans-serif;
  --mono: ui-monospace, 'SF Mono', menlo, monospace;
  --t-caption: 0.72rem;
  --t-stamp: 0.66rem;
  --t-body: 1.0625rem;
  --t-card-title: 1.15rem;
  --t-section: 1.2rem;
  --t-wordmark: 2rem;

  /* spacing scale (4px base) */
  --s-1: 0.25rem;
  --s-2: 0.5rem;
  --s-3: 0.75rem;
  --s-4: 1rem;
  --s-5: 1.5rem;
  --s-6: 2.5rem;
  --s-7: 4rem;

  /* radii + strokes */
  --r-s: 0.2rem;
  --r-m: 0.5rem;
  --r-l: 0.75rem;
  --r-pill: 999px;
  --stroke: 1.5px;

  /* component-specific */
  --stamp-veil: #ffffffd9;
}

/* Dark enamelware — same kitchen at night. Hues re-tuned for the contrast
   floors (docs/DESIGN.md); resolved theme is applied as data-theme by a
   pre-paint inline script + src/theme.ts. */
[data-theme='dark'] {
  --tile: #101b18;
  --ink: #e2ebe7;
  --enamel: #5cb3a1;
  --enamel-deep: #79c7b6;
  --enamel-soft: #5cb3a124;
  --yolk: #e8a013;
  --yolk-deep: #e5b13d;
  --rust: #e07a4f;
  --card: #182622;
  --line: #2b3b36;
  --stamp-veil: #101b18d9;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--tile);
  color: var(--ink);
  font-family: var(--body);
  font-size: var(--t-body);
  line-height: 1.55;
}

#app {
  max-width: 64rem;
  margin: 0 auto;
  padding: 0 var(--s-4) var(--s-7);
}

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

/* ---- header ---- */

.topbar {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: var(--s-4) 0 var(--s-1);
}

.wordmark {
  font-family: var(--display);
  font-weight: 550;
  font-size: var(--t-wordmark);
  letter-spacing: -0.02em;
  margin: 0;
  color: var(--enamel);
}

.wordmark-link {
  color: inherit;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
}

/* Butterfly-spatula mark: theme-variant pair, one shown at a time. */
.logo {
  height: 1.5em;
  width: auto;
}

.logo--dark {
  display: none;
}

[data-theme='dark'] .logo--light {
  display: none;
}

[data-theme='dark'] .logo--dark {
  display: inline;
}

.nav-gear {
  font-size: 1.25rem;
  text-decoration: none;
  color: var(--enamel);
  opacity: 0.75;
  padding: var(--s-1) var(--s-2);
  background: none;
  border: 0;
  cursor: pointer;
  font-family: var(--body);
}

.nav-gear:hover {
  opacity: 1;
}

/* The differentiated "a": the wordmark reads "a recipe". */
.wordmark-a {
  color: var(--yolk-deep);
  font-weight: 400;
  padding-right: 0.06em;
}

.auth-area {
  display: flex;
  align-items: center;
  gap: var(--s-2);
}

.auth-who {
  font-family: var(--mono);
  font-size: var(--t-caption);
  opacity: 0.7;
  max-width: 14rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---- tabs ---- */

.tabs {
  display: flex;
  gap: var(--s-1);
  border-bottom: 2px solid var(--line);
  margin-bottom: var(--s-5);
}

.tab {
  appearance: none;
  border: 0;
  background: none;
  font-family: var(--body);
  font-size: 1rem;
  padding: var(--s-2) var(--s-3);
  cursor: pointer;
  color: var(--ink);
  opacity: 0.62;
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
}

.tab--active {
  opacity: 1;
  border-bottom-color: var(--enamel);
  font-weight: 700;
}

.tab {
  text-decoration: none;
  display: inline-block;
}

/* Mobile: primary destinations move to a bottom bar (thumb reach). */
@media (max-width: 40rem) {
  .tabs {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    margin: 0;
    display: flex;
    justify-content: space-around;
    background: var(--card);
    border-top: var(--stroke) solid var(--line);
    border-bottom: 0;
    padding: var(--s-1) 0 calc(var(--s-1) + env(safe-area-inset-bottom));
    z-index: 10;
  }

  .tab {
    border-bottom: 0;
    margin-bottom: 0;
    padding: var(--s-2) var(--s-4);
  }

  .tab--active {
    color: var(--enamel);
    border-bottom: 0;
  }

  #app {
    padding-bottom: var(--s-7);
  }
}

/* ---- settings sections ---- */

.page-title {
  font-family: var(--display);
  font-weight: 600;
  font-size: 1.5rem;
  margin: 0 0 var(--s-4);
}

.settings-section {
  background: var(--card);
  border: var(--stroke) solid var(--line);
  border-radius: var(--r-l);
  padding: var(--s-4) var(--s-4) var(--s-4);
  margin-bottom: var(--s-4);
  max-width: 44rem;
}

.settings-section h3 {
  font-family: var(--display);
  font-weight: 600;
  color: var(--enamel);
  margin: 0 0 var(--s-2);
}

.facts {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: var(--s-1) var(--s-4);
  font-family: var(--mono);
  font-size: var(--t-caption);
  margin: 0;
}

.facts dd {
  margin: 0;
}

.starter-row {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  padding: var(--s-1) 0;
  cursor: pointer;
}

.starter-row input {
  accent-color: var(--enamel);
  width: 1.1rem;
  height: 1.1rem;
}

.starter-author,
.provenance-author {
  color: var(--enamel);
}

/* ---- lookup row + controls ---- */

.lookup {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2);
  margin: 0 0 var(--s-2);
}

.lookup input {
  flex: 1 1 14rem;
  font: inherit;
  padding: var(--s-2) var(--s-3);
  border: var(--stroke) solid var(--line);
  border-radius: var(--r-m);
  background: var(--card);
  color: inherit;
}

.lookup input::placeholder {
  color: var(--ink);
  opacity: 0.45;
}

.button {
  font: inherit;
  font-weight: 700;
  padding: var(--s-2) var(--s-4);
  border-radius: var(--r-m);
  border: var(--stroke) solid var(--enamel);
  background: var(--card);
  color: var(--enamel);
  cursor: pointer;
}

.button--primary {
  background: var(--enamel);
  color: var(--card);
}

.button:hover {
  background: var(--enamel-soft);
}

.button--primary:hover {
  background: var(--enamel-deep);
}

/* Status lines carry machine facts → mono caption, quiet. */
.status {
  font-family: var(--mono);
  font-size: var(--t-caption);
  min-height: 1.2em;
  margin: var(--s-1) 0;
  opacity: 0.75;
}

.empty-state {
  border: var(--stroke) dashed var(--line);
  border-radius: var(--r-l);
  padding: var(--s-6) var(--s-5);
  text-align: center;
  opacity: 0.8;
}

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

.recipe-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr));
  gap: var(--s-4);
  margin-top: var(--s-4);
}

.card {
  background: var(--card);
  border: var(--stroke) solid var(--line);
  border-radius: var(--r-l);
  overflow: hidden;
  transition: border-color 120ms ease;
}

.card:hover {
  border-color: var(--enamel);
}

.card[open] {
  grid-column: 1 / -1;
  border-color: var(--enamel);
}

.card-face {
  display: block;
  cursor: pointer;
  list-style: none;
}

.card-face::-webkit-details-marker {
  display: none;
}

.card-photo {
  display: block;
  width: 100%;
  aspect-ratio: 3 / 2;
  object-fit: cover;
  background: var(--enamel-soft);
}

/* Banners (detail page) stay banners, not billboards. */
.photo-wrap--banner .card-photo {
  aspect-ratio: auto;
  height: 16rem;
  border-radius: var(--r-l);
}

/* ---- recipe detail page ---- */

.recipe-detail {
  max-width: 52rem;
}

.recipe-title {
  font-family: var(--display);
  font-weight: 600;
  font-size: 1.6rem;
  line-height: 1.2;
  margin: var(--s-4) 0 var(--s-2);
}

.card .card-title {
  text-decoration: none;
}

a.card {
  text-decoration: none;
  color: inherit;
}

.card-photo--empty {
  display: grid;
  place-items: center;
}

.placeholder-mark {
  height: 4rem;
  width: auto;
  opacity: 0.45;
}

.card-title {
  display: block;
  font-family: var(--display);
  font-weight: 600;
  font-size: var(--t-card-title);
  line-height: 1.25;
  padding: var(--s-3) var(--s-3) var(--s-1);
}

.chips {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  padding: var(--s-1) var(--s-3) var(--s-3);
}

.chip {
  font-family: var(--mono);
  font-size: var(--t-caption);
  padding: 0.15rem var(--s-2);
  border-radius: var(--r-pill);
  background: var(--enamel-soft);
  color: var(--enamel);
}

/* Trust surface: silent when good, loud when bad. The signature element is
   the ALTERED? rubber stamp — it appears only when integrity checking
   actually caught something. */

.photo-wrap {
  position: relative;
}

.altered-stamp {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) rotate(-12deg);
  font-family: var(--mono);
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  color: var(--rust);
  border: 3px double var(--rust);
  border-radius: var(--r-s);
  padding: var(--s-1) var(--s-3);
  background: var(--stamp-veil);
}

.altered-warning {
  font-size: 0.85rem;
  color: var(--rust);
  margin: 0;
  padding: 0 var(--s-3) var(--s-3);
}

/* Quiet human provenance line at the end of an intact detail. */
.provenance {
  font-family: var(--mono);
  font-size: var(--t-caption);
  opacity: 0.65;
  margin: var(--s-4) 0 0;
}

/* ---- expanded detail: ingredients first ---- */

.card-detail {
  padding: 0 var(--s-4) var(--s-5);
  border-top: var(--stroke) solid var(--line);
}

.lede {
  max-width: 44rem;
  opacity: 0.85;
}

.detail-cols {
  display: grid;
  grid-template-columns: minmax(14rem, 1fr) 2fr;
  gap: 0 var(--s-6);
}

.detail-cols h3 {
  font-family: var(--display);
  font-weight: 600;
  font-size: var(--t-section);
  color: var(--enamel);
  margin: var(--s-4) 0 var(--s-2);
}

.detail-cols ul {
  padding-left: var(--s-4);
}

.detail-cols ol {
  padding-left: var(--s-5);
}

.detail-cols ol li {
  margin-bottom: var(--s-3);
}

@media (max-width: 40rem) {
  .detail-cols {
    grid-template-columns: 1fr;
  }
}

/* ---- footer: build stamp + colophon ---- */

.site-footer {
  margin-top: var(--s-7);
  font-family: var(--mono);
  font-size: var(--t-caption);
  opacity: 0.55;
  text-align: center;
  display: grid;
  gap: var(--s-1);
}

.site-footer p {
  margin: 0;
}

.colophon {
  color: inherit;
  text-decoration: none;
}

.colophon:hover {
  color: var(--enamel);
  opacity: 1;
}

.colophon svg {
  vertical-align: -1px;
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
  }
}

/* Off-network credit (attribution). */
.attribution {
  font-size: 0.85rem;
  opacity: 0.75;
  margin: 0 0 var(--s-2);
}

.attribution-link {
  color: var(--enamel);
}

/* ---- editor (Phase 6) ---- */

.editor {
  display: grid;
  gap: var(--s-3);
  max-width: 44rem;
  margin-bottom: var(--s-4);
}

.editor-field {
  display: grid;
  gap: var(--s-1);
}

.editor-label {
  font-weight: 700;
  font-size: 0.9rem;
}

.editor input,
.editor textarea {
  font: inherit;
  padding: var(--s-2) var(--s-3);
  border: var(--stroke) solid var(--line);
  border-radius: var(--r-m);
  background: var(--card);
  color: inherit;
}

.section-title {
  font-family: var(--display);
  font-weight: 600;
  color: var(--enamel);
  margin: var(--s-5) 0 var(--s-2);
}

.draft-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-2);
  background: var(--card);
  border: var(--stroke) solid var(--line);
  border-radius: var(--r-m);
  padding: var(--s-2) var(--s-3);
  margin-bottom: var(--s-2);
  max-width: 44rem;
}

.draft-link {
  color: var(--enamel);
  font-weight: 700;
  text-decoration: none;
}

.editor-photo-preview {
  max-width: 16rem;
  border-radius: var(--r-m);
  border: var(--stroke) solid var(--line);
}

/* Update toast (8b): asks, never ambushes. Fixed bar, not a modal. */
.update-toast {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(var(--s-6) + env(safe-area-inset-bottom));
  display: flex;
  align-items: center;
  gap: var(--s-3);
  background: var(--card);
  border: var(--stroke) solid var(--enamel);
  border-radius: var(--r-l);
  padding: var(--s-2) var(--s-4);
  box-shadow: 0 4px 14px #0003;
  z-index: 20;
}
