/* ==========================================================================
   Recipe Measurement Converter & Scaler — Design System
   Dark charcoal header/footer frame, warm off-white page, brick-red primary
   accent. Tokens first, then base, then reusable components. Every page
   shares this single stylesheet so new long-tail pages inherit the look.
   ========================================================================== */

:root {
  /* Color */
  --color-bg: #FAF8F5;
  --color-surface: #FFFFFF;
  --color-header-bg: #1C1815;
  --color-text: #2A211C;
  --color-text-muted: #6B5F56;
  --color-primary: #B7312C;
  --color-primary-hover: #9A2823;
  --color-result-bg: #FBEAE8;
  --color-result-border: #B7312C;
  --color-success: #4B6B3F;
  --color-error: #8C2318;
  --color-border: #E4DDD5;

  /* Text on the dark header/footer band (not specified by the palette
     above, since that palette is written for the light page surface) */
  --color-header-text: #FAF8F5;
  --color-header-text-muted: #B8ADA0;

  /* Dark structural elements — footer, intro band — kept separate from the
     light content/reading/ad areas, which stay on --color-bg/--color-surface. */
  --color-dark-structural: #1C1815;
  --color-dark-structural-alt: #2A2420;
  --color-dark-text-on-dark: #F4F0EA;
  --color-dark-text-muted: #A89A8C;

  /* Type */
  --font-heading: 'Fraunces', Georgia, serif;
  --font-body: 'Work Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'IBM Plex Mono', 'Courier New', monospace;

  --size-h1: 2.25rem;
  --size-h2: 1.5rem;
  --size-h3: 1.125rem;
  --size-body: 1rem;
  --size-caption: 0.875rem;

  /* Spacing */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 16px;
  --space-4: 24px;
  --space-5: 32px;
  --space-6: 48px;

  /* Shape */
  --radius-control: 6px;
  --radius-card: 10px;

  /* Motion */
  --transition-fast: 150ms ease;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-body);
  font-size: var(--size-body);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 {
  font-family: var(--font-heading);
  font-optical-sizing: auto;
  line-height: 1.15;
  margin: 0 0 var(--space-3);
  color: var(--color-text);
}

h1, h2 { font-weight: 600; }
h3 { font-weight: 500; }

h1 { font-size: var(--size-h1); }
h2 { font-size: var(--size-h2); }
h3 { font-size: var(--size-h3); }

p {
  margin: 0 0 var(--space-3);
}

a {
  color: var(--color-primary);
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}

a:hover { color: var(--color-primary-hover); }

small, .caption {
  font-size: var(--size-caption);
  color: var(--color-text-muted);
}

img { max-width: 100%; height: auto; }

/* Focus visibility everywhere — non-negotiable for accessibility */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
summary:focus-visible {
  outline: 3px solid var(--color-primary);
  outline-offset: 2px;
}

/* ==========================================================================
   Layout shell — header/footer are solid dark charcoal bands bookending
   the lighter page column.
   ========================================================================== */

.site-header {
  background: var(--color-header-bg);
}

.site-header__bar {
  max-width: 960px;
  margin: 0 auto;
  padding: var(--space-3) var(--space-4);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}

.site-logo {
  font-family: var(--font-heading);
  font-optical-sizing: auto;
  font-weight: 600;
  font-size: 1.25rem;
  color: var(--color-header-text);
  text-decoration: none;
}

.site-logo:hover { color: var(--color-primary); }

.site-nav {
  display: flex;
  gap: var(--space-4);
  flex-wrap: wrap;
}

.site-nav a {
  color: var(--color-header-text-muted);
  text-decoration: none;
  font-size: var(--size-caption);
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.site-nav a:hover { color: var(--color-primary); }

main {
  max-width: 720px;
  margin: 0 auto;
  padding: var(--space-4);
}

.site-footer {
  background: var(--color-dark-structural);
  margin-top: var(--space-6);
}

.site-footer__bar {
  max-width: 960px;
  margin: 0 auto;
  padding: var(--space-5) var(--space-4);
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-4);
  justify-content: space-between;
  color: var(--color-dark-text-muted);
  font-size: var(--size-caption);
}

.site-footer a {
  color: var(--color-dark-text-on-dark);
}

.site-footer a:hover { color: var(--color-primary); }

.footer-links {
  display: flex;
  gap: var(--space-3);
  flex-wrap: wrap;
  list-style: none;
  margin: 0;
  padding: 0;
}

/* ==========================================================================
   Intro band — a dark structural anchor beneath the header, holding the
   page's H1 + intro paragraph. Bookends the page (dark header → dark intro
   band → light content/ads/tools → dark footer) without darkening any
   reading-heavy or ad-bearing area.
   ========================================================================== */

.intro-band {
  background: var(--color-dark-structural-alt);
}

.intro-band__inner {
  max-width: 720px;
  margin: 0 auto;
  padding: var(--space-5) var(--space-4);
}

.intro-band h1 {
  color: var(--color-dark-text-on-dark);
  margin-bottom: var(--space-2);
}

.intro-band p {
  color: var(--color-dark-text-muted);
  margin: 0;
}

/* ==========================================================================
   Breadcrumbs
   ========================================================================== */

.breadcrumb {
  margin: var(--space-3) 0 var(--space-4);
}

.breadcrumb ol {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
  margin: 0;
  padding: 0;
  font-size: var(--size-caption);
  color: var(--color-text-muted);
}

.breadcrumb li:not(:last-child)::after {
  content: "/";
  margin-left: var(--space-1);
  color: var(--color-border);
}

.breadcrumb a {
  color: var(--color-text-muted);
  text-decoration: none;
}

.breadcrumb a:hover { color: var(--color-primary); text-decoration: underline; }

.breadcrumb [aria-current="page"] {
  color: var(--color-text);
}

/* ==========================================================================
   Ad slots — kept visually distinct as placeholders, spaced away from
   interactive controls per AdSense placement guidance.
   ========================================================================== */

.ad-slot {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 90px;
  margin: var(--space-6) 0;
  border: 1px dashed var(--color-border);
  border-radius: var(--radius-card);
  color: var(--color-text-muted);
  font-size: var(--size-caption);
  background: var(--color-surface);
}

/* ==========================================================================
   Tool card — the visual focus of every tool page
   ========================================================================== */

.tool-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-card);
  padding: var(--space-4);
  margin: var(--space-4) 0 var(--space-5);
  box-shadow: 0 2px 12px rgba(28, 24, 21, 0.08);
}

.field-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

/* Spacing between field-groups (in a row, or stacked on mobile) comes only
   from .field-row's gap. Spacing between successive rows comes only from
   this margin-bottom. Previously both this and .field-group carried
   margin-bottom, which doubled up the gap wherever a row's fields stacked. */
.field-row {
  display: flex;
  gap: var(--space-3);
  flex-wrap: wrap;
  margin-bottom: var(--space-3);
}

.field-row > .field-group {
  flex: 1 1 140px;
}

label {
  font-weight: 500;
  font-size: var(--size-caption);
  color: var(--color-text);
}

input[type="text"],
input[type="number"],
select {
  font-family: var(--font-body);
  font-size: 1rem;
  padding: var(--space-2) var(--space-3);
  min-height: 44px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-control);
  background: var(--color-surface);
  color: var(--color-text);
  width: 100%;
}

input::placeholder {
  color: var(--color-text-muted);
  opacity: 1;
}

/* Ingredient autocomplete combobox — shared by the converter and the
   recipe scaler's ingredient rows. */
.combobox {
  position: relative;
}

.combobox-listbox {
  position: absolute;
  z-index: 20;
  top: calc(100% + var(--space-1));
  left: 0;
  right: 0;
  max-height: 240px;
  overflow-y: auto;
  margin: 0;
  padding: var(--space-1);
  list-style: none;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-control);
  box-shadow: 0 4px 12px rgba(42, 33, 28, 0.12);
}

.combobox-listbox[hidden] { display: none; }

.combobox-option {
  padding: var(--space-2) var(--space-3);
  border-radius: 4px;
  cursor: pointer;
  font-size: 1rem;
}

.combobox-option.is-active,
.combobox-option:hover {
  background: var(--color-primary);
  color: #fff;
}

.combobox-empty {
  margin: var(--space-1) 0 0;
  font-size: var(--size-caption);
  color: var(--color-text-muted);
}

.combobox-empty[hidden] { display: none; }

fieldset {
  border: none;
  padding: 0;
  margin: 0 0 var(--space-3);
}

legend {
  font-weight: 500;
  font-size: var(--size-caption);
  padding: 0;
  margin-bottom: var(--space-2);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 44px;
  padding: var(--space-2) var(--space-4);
  font-family: var(--font-body);
  font-size: 1rem;
  font-weight: 500;
  border-radius: var(--radius-control);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background-color var(--transition-fast), transform var(--transition-fast);
}

.btn-primary {
  background: var(--color-primary);
  color: #FFFFFF;
}

.btn-primary:hover { background: var(--color-primary-hover); }
.btn-primary:active { transform: scale(0.98); }

.btn-secondary {
  background: transparent;
  color: var(--color-primary);
  border-color: var(--color-border);
}

.btn-secondary:hover { border-color: var(--color-primary); }

/* Result display — highest visual priority after inputs. The dashed/tick
   rule along the top edge is the site's one signature detail: it reads as
   a measuring scale's calibration line. Numbers render in tabular
   monospace, like a digital kitchen scale readout. */
.result-box {
  position: relative;
  margin-top: var(--space-4);
  padding: var(--space-4);
  padding-top: calc(var(--space-4) + 4px);
  border-radius: var(--radius-control);
  background: var(--color-result-bg);
  border: 1px solid var(--color-result-border);
  overflow: hidden;
}

.result-box::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 6px;
  background-image: repeating-linear-gradient(
    90deg,
    var(--color-result-border) 0,
    var(--color-result-border) 2px,
    transparent 2px,
    transparent 12px
  );
  opacity: 0.85;
}

.result-box[hidden] { display: none; }

.result-box.is-updated {
  animation: result-highlight 400ms ease;
}

@keyframes result-highlight {
  from { background-color: #F6D3CE; }
  to { background-color: var(--color-result-bg); }
}

.result-value {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 1.375rem;
  font-weight: 500;
  color: var(--color-primary);
  margin: 0;
}

.result-note {
  margin-top: var(--space-1);
  color: var(--color-text-muted);
  font-size: var(--size-caption);
  font-family: var(--font-body);
}

.error-message {
  margin-top: var(--space-2);
  color: var(--color-error);
  font-size: var(--size-caption);
  font-weight: 600;
}

.error-message[hidden] { display: none; }

/* Advanced / progressive disclosure */
.advanced-toggle {
  background: none;
  border: none;
  padding: var(--space-2) 0;
  color: var(--color-primary);
  font-weight: 500;
  font-size: var(--size-caption);
  cursor: pointer;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
}

.advanced-toggle:hover { color: var(--color-primary-hover); }

.advanced-panel {
  overflow: hidden;
  max-height: 0;
  transition: max-height var(--transition-fast);
}

.advanced-panel.is-open {
  max-height: 600px;
}

.advanced-panel__inner {
  padding-top: var(--space-3);
}

.all-units-table {
  border-collapse: collapse;
  width: 100%;
}

.all-units-table th,
.all-units-table td {
  text-align: left;
  padding: var(--space-1) var(--space-2);
  border-bottom: 1px solid var(--color-border);
  font-size: var(--size-caption);
}

.all-units-table th {
  font-weight: 400;
  color: var(--color-text-muted);
}

.all-units-table td {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-weight: 500;
  text-align: right;
  color: var(--color-text);
}

/* Scaler-specific: repeating ingredient rows */
.ingredient-row {
  display: flex;
  gap: var(--space-2);
  align-items: flex-end;
  margin-bottom: var(--space-2);
}

.ingredient-row .field-group { margin-bottom: 0; }
.ingredient-row .field-group--name { flex: 2; }
.ingredient-row .field-group--qty { flex: 1; }
.ingredient-row .field-group--unit { flex: 1; }

.ingredient-row .remove-row {
  min-height: 44px;
  min-width: 44px;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  border-radius: var(--radius-control);
  cursor: pointer;
  color: var(--color-text-muted);
}

.ingredient-row .remove-row:hover {
  color: var(--color-error);
  border-color: var(--color-error);
}

.scaled-list {
  list-style: none;
  margin: var(--space-3) 0 0;
  padding: 0;
}

.scaled-list li {
  padding: var(--space-2) 0;
  border-bottom: 1px solid var(--color-border);
}

.scaled-list li:last-child { border-bottom: none; }

/* Content sections below the tool */
.content-section {
  margin-top: var(--space-6);
}

.content-section h2 {
  margin-bottom: var(--space-2);
}

.related-links ul {
  padding-left: var(--space-4);
}

.faq-item {
  margin-bottom: var(--space-4);
}

.faq-item h3 {
  margin-bottom: var(--space-1);
}

/* Utility */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}

/* Responsive */
@media (max-width: 600px) {
  :root {
    --size-h1: 1.75rem;
    --size-h2: 1.25rem;
  }

  .field-row {
    flex-direction: column;
  }

  /* .field-row > .field-group sets flex: 1 1 140px for the desktop row
     layout, where 140px is a min-width. In column direction that same
     flex-basis is read as a min-HEIGHT instead, forcing every stacked
     field to ~140px tall regardless of its actual content. Reset it here. */
  .field-row > .field-group {
    flex: 1 1 auto;
  }

  .site-header__bar {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-2);
  }
}
