/* Confraria da Mata · Calculadora cervejeira — tema escuro do brasão. Ver DESIGN.md
   Tokens em três camadas: primitivos (cores do brasão) → semânticos (bg, ink, primary…) → componentes. */
@font-face { font-family: "Barlow"; src: url("../assets/fonts/barlow-400.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Barlow"; src: url("../assets/fonts/barlow-500.woff2") format("woff2"); font-weight: 500; font-display: swap; }
@font-face { font-family: "Barlow Condensed"; src: url("../assets/fonts/barlow-condensed-500.woff2") format("woff2"); font-weight: 500; font-display: swap; }
@font-face { font-family: "Barlow Condensed"; src: url("../assets/fonts/barlow-condensed-700.woff2") format("woff2"); font-weight: 700; font-display: swap; }
@font-face { font-family: "Permanent Marker"; src: url("../assets/fonts/permanent-marker-400.woff2") format("woff2"); font-weight: 400; font-display: swap; }

:root {
  /* primitivos: paleta do brasão */
  --preto: #0a0a0a;
  --preto-2: #121311;
  --preto-3: #1a1c18;
  --creme: #f3ead3;
  --creme-2: #b9b39f;
  --verde: #4fb536;
  --verde-claro: #8fe34a;
  --dourado: #f2b632;
  --dourado-claro: #ffc94a;
  --vermelho: #ff7a62;

  /* semânticos */
  --bg: var(--preto);
  --surface: var(--preto-2);
  --surface-2: var(--preto-3);
  --line: rgba(243, 234, 211, 0.12);
  --line-strong: rgba(243, 234, 211, 0.26);
  --ink: var(--creme);
  --muted: var(--creme-2);
  --primary: var(--dourado);           /* ações, seleção, foco */
  --primary-strong: var(--dourado-claro);
  --primary-soft: rgba(242, 182, 50, 0.16);
  --on-primary: var(--preto);
  --accent: var(--verde-claro);        /* resultados */
  --accent-deep: var(--verde);
  --ok: var(--verde-claro);
  --ok-soft: rgba(143, 227, 74, 0.14);
  --warn-ink: var(--dourado);
  --warn-soft: rgba(242, 182, 50, 0.14);
  --bad: var(--vermelho);
  --bad-soft: rgba(255, 122, 98, 0.14);

  --font: "Barlow", system-ui, -apple-system, "Segoe UI", sans-serif;
  --cond: "Barlow Condensed", "Arial Narrow", sans-serif;
  --display: "Permanent Marker", "Brush Script MT", cursive;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --fs-xs: 0.8rem;
  --fs-sm: 0.9rem;
  --fs-md: 1.0625rem;
  --fs-lg: 1.25rem;
  --fs-xl: 1.5rem;
  --fs-2xl: 1.8rem;
  --fs-3xl: 2.15rem;

  --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px; --sp-5: 24px; --sp-6: 32px; --sp-7: 48px; --sp-8: 64px;
  --r-sm: 6px; --r-md: 8px; --r-lg: 12px;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --dur: 180ms;

  --z-backdrop: 19; --z-nav: 20; --z-topbar: 30;
  --topbar-h: 62px;
  --nav-w: 268px;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: var(--fs-md);
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
  font-kerning: normal;
}
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; line-height: 1.2; text-wrap: balance; font-weight: 600; }
p { margin: 0; }
button, input, select { font: inherit; color: inherit; }
code { font-family: var(--mono); font-size: 0.9em; }
a { color: var(--primary); }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: var(--r-sm); }
.skip { position: absolute; left: -999px; top: 8px; background: var(--primary); color: var(--on-primary); padding: 8px 12px; border-radius: var(--r-md); z-index: 100; font-weight: 600; }
.skip:focus { left: 8px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* rótulos condensados, a voz do brasão */
.cond, .field-label, .nav-group-title, .calc-kicker, .results-panel h2, .seg button, .btn, table.ref th, .result-label, .row-out .k, .badge, .fs > legend, .nav a .abbr {
  font-family: var(--cond);
}

/* ---- casca ---- */
.app {
  display: grid;
  grid-template-columns: var(--nav-w) minmax(0, 1fr);
  grid-template-rows: var(--topbar-h) 1fr;
  grid-template-areas: "top top" "nav main";
  min-height: 100dvh;
}
.topbar {
  grid-area: top;
  position: sticky; top: 0; z-index: var(--z-topbar);
  display: flex; align-items: center; gap: var(--sp-4);
  padding: 0 var(--sp-5);
  background: rgba(10, 10, 10, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: var(--sp-3); color: var(--ink); text-decoration: none; min-width: 0; }
.brand-mark { color: var(--accent); flex: none; }
.brand-text { display: flex; flex-direction: column; line-height: 1.12; min-width: 0; }
.brand-name { font-family: var(--cond); font-weight: 700; font-size: 1.05rem; letter-spacing: 0.05em; text-transform: uppercase; white-space: nowrap; }
.brand-sub { font-family: var(--cond); font-weight: 500; font-size: var(--fs-xs); letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); white-space: nowrap; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: var(--sp-4); }
.brand-site { font-family: var(--cond); font-weight: 500; font-size: var(--fs-sm); letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); text-decoration: none; transition: color var(--dur) var(--ease); }
.brand-site:hover { color: var(--ink); }
.btn-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 44px; height: 44px; border-radius: var(--r-md);
  border: 1px solid transparent; background: transparent; cursor: pointer; color: var(--ink);
  transition: background var(--dur) var(--ease);
}
.btn-icon:hover { background: var(--surface-2); }
.nav-toggle { display: none; margin-left: -8px; }

.nav {
  grid-area: nav;
  position: sticky; top: var(--topbar-h);
  height: calc(100dvh - var(--topbar-h));
  overflow-y: auto;
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: var(--sp-4) var(--sp-3) var(--sp-6);
}
.nav-group { margin-bottom: var(--sp-4); }
.nav-group-title { font-size: var(--fs-xs); font-weight: 700; color: var(--primary); letter-spacing: 0.14em; text-transform: uppercase; padding: var(--sp-2) var(--sp-3); }
.nav a {
  display: flex; align-items: baseline; justify-content: space-between; gap: var(--sp-2);
  padding: 10px var(--sp-3); border-radius: var(--r-md);
  color: var(--ink); text-decoration: none; font-size: var(--fs-sm); font-weight: 500; line-height: 1.3;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.nav a:hover { background: var(--surface-2); }
.nav a[aria-current="page"] { background: var(--primary); color: var(--on-primary); font-weight: 500; }
.nav a .abbr { font-size: var(--fs-xs); font-weight: 500; letter-spacing: 0.04em; color: var(--muted); font-variant-numeric: tabular-nums; flex: none; }
.nav a[aria-current="page"] .abbr { color: rgba(10, 10, 10, 0.72); }
.backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.55); z-index: var(--z-backdrop); }

.main { grid-area: main; padding: var(--sp-6) var(--sp-6) var(--sp-8); min-width: 0; }
.main:focus { outline: none; }
.wrap { max-width: 1100px; margin: 0 auto; }

/* ---- cabeçalho da calculadora ---- */
.calc-head { display: grid; gap: var(--sp-2); margin-bottom: var(--sp-6); max-width: 70ch; }
.calc-kicker { font-size: var(--fs-sm); font-weight: 700; letter-spacing: 0.14em; text-transform: uppercase; color: var(--primary); }
/* caixa normal de propósito: "pH", "mEq" e "°Bx" não podem virar maiúsculas */
.calc-head h1 { font-family: var(--cond); font-weight: 700; letter-spacing: 0.01em; font-size: var(--fs-3xl); line-height: 1.05; }
.calc-head h1 em { font-family: var(--display); font-style: normal; font-weight: 400; letter-spacing: 0; color: var(--accent); font-size: 1.05em; margin-right: 0.35em; }
.calc-lead { color: var(--muted); font-size: var(--fs-md); text-wrap: pretty; }

/* ---- corpo: formulário + resultados ---- */
.calc-body { display: grid; gap: var(--sp-6); grid-template-columns: minmax(0, 1fr); align-items: start; }
@media (min-width: 960px) {
  .calc-body { grid-template-columns: minmax(0, 1fr) 360px; }
  .calc-results { position: sticky; top: calc(var(--topbar-h) + var(--sp-5)); }
}
@media (max-width: 959px) {
  .calc-results { order: -1; }
}
.calc-form { display: grid; gap: var(--sp-6); min-width: 0; }
.calc-results { display: grid; gap: var(--sp-4); min-width: 0; }
.results-panel {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg);
  padding: var(--sp-5); display: grid; gap: var(--sp-4);
  box-shadow: 0 24px 48px -32px rgba(143, 227, 74, 0.25);
}
.results-panel h2 { font-size: var(--fs-xs); font-weight: 700; letter-spacing: 0.14em; text-transform: uppercase; color: var(--primary); }

/* seção do formulário */
.fs { display: grid; gap: var(--sp-3); border: 0; padding: 0; margin: 0; min-width: 0; }
.fs > legend { font-weight: 700; font-size: var(--fs-lg); text-transform: uppercase; letter-spacing: 0.03em; padding: 0; margin-bottom: var(--sp-1); }
.fs-hint { color: var(--muted); font-size: var(--fs-sm); margin-top: -4px; text-wrap: pretty; }
.grid-2 { display: grid; gap: var(--sp-3); grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.grid-3 { display: grid; gap: var(--sp-3); grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.stack { display: grid; gap: var(--sp-3); }
.inline { display: flex; flex-wrap: wrap; gap: var(--sp-3); align-items: center; }

/* campo numérico */
.field { display: grid; gap: 6px; min-width: 0; align-content: start; }
.field-label { font-size: 1rem; font-weight: 500; letter-spacing: 0.02em; display: flex; justify-content: space-between; gap: var(--sp-2); color: var(--ink); }
.field-label .opt { color: var(--muted); font-weight: 500; letter-spacing: 0; font-family: var(--font); font-size: var(--fs-xs); }
.input-wrap { position: relative; display: flex; align-items: center; }
.input-wrap input, .select-wrap select {
  width: 100%; height: 48px; padding: 0 var(--sp-3);
  border: 1px solid var(--line-strong); border-radius: var(--r-md);
  background: var(--surface); color: var(--ink);
  font-size: var(--fs-lg); font-weight: 500; font-variant-numeric: tabular-nums;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease), background var(--dur) var(--ease);
}
.input-wrap input:hover, .select-wrap select:hover { border-color: rgba(242, 182, 50, 0.55); }
.input-wrap input:focus, .select-wrap select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); background: var(--preto); }
.input-wrap input[aria-invalid="true"] { border-color: var(--bad); }
.input-wrap input::placeholder { color: var(--muted); opacity: 0.8; }
.input-wrap .unit {
  position: absolute; right: var(--sp-3); color: var(--muted); font-family: var(--cond); font-size: var(--fs-sm); letter-spacing: 0.04em; pointer-events: none;
  background: transparent; padding-left: 6px;
}
.input-wrap .unit:empty { display: none; }
.input-wrap input.has-unit { padding-right: calc(var(--sp-3) + var(--unit-w, 40px)); }
.field-hint { font-size: var(--fs-xs); color: var(--muted); }
.field-error { font-size: var(--fs-xs); color: var(--bad); font-weight: 500; }
.select-wrap select {
  font-size: var(--fs-md); appearance: none; padding-right: 36px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23f3ead3' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center;
}
.select-wrap select option { background: var(--surface-2); color: var(--ink); }

/* segmentado */
.seg { display: inline-flex; padding: 3px; border-radius: var(--r-md); background: var(--surface-2); border: 1px solid var(--line); gap: 2px; max-width: 100%; }
.seg button {
  border: 0; background: transparent; padding: 0 14px; height: 40px; border-radius: 6px; cursor: pointer;
  font-size: 0.95rem; font-weight: 700; letter-spacing: 0.03em; color: var(--muted); white-space: nowrap;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.seg button:hover { color: var(--ink); }
.seg button:active { transform: translateY(1px); }
.seg button[aria-checked="true"] { background: var(--primary); color: var(--on-primary); }
.seg--sm button { height: 32px; padding: 0 12px; font-size: var(--fs-xs); }
.seg--block { display: flex; }
.seg--block button { flex: 1; }

/* checkbox */
.check { display: flex; align-items: center; gap: 10px; font-size: var(--fs-sm); cursor: pointer; min-height: 44px; }
.check input { width: 20px; height: 20px; accent-color: var(--primary); margin: 0; flex: none; }

/* botões */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 44px; padding: 0 var(--sp-4); border-radius: var(--r-md); cursor: pointer;
  border: 1px solid var(--line-strong); background: transparent; color: var(--ink); font-size: var(--fs-sm); font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease), color var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.btn:hover { background: var(--surface-2); border-color: var(--primary); }
.btn:active { transform: translateY(1px); }
.btn--primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn--primary:hover { background: var(--primary-strong); border-color: var(--primary-strong); }
.btn--ghost { border-color: transparent; color: var(--primary); }
.btn--ghost:hover { background: var(--primary-soft); border-color: transparent; }
.btn--sm { height: 36px; padding: 0 12px; font-size: var(--fs-xs); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* resultados */
.result { display: grid; gap: 2px; min-width: 0; }
.result-label { font-size: 0.95rem; font-weight: 500; letter-spacing: 0.02em; color: var(--muted); }
.result-value { font-size: var(--fs-xl); font-weight: 500; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; line-height: 1.15; overflow-wrap: anywhere; }
.result-value .u { font-family: var(--cond); font-size: 0.6em; font-weight: 500; letter-spacing: 0.04em; color: var(--muted); margin-left: 5px; }
.result-value .u:empty { display: none; }
.result--big .result-value { font-size: var(--fs-3xl); }
.result--accent .result-value { color: var(--accent); }
.result-note { font-size: var(--fs-xs); color: var(--muted); }
.result.tone-ok .result-value { color: var(--ok); }
.result.tone-warn .result-value { color: var(--warn-ink); }
.result.tone-bad .result-value { color: var(--bad); }
.result-grid { display: grid; gap: var(--sp-4); grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); }
.divider { height: 1px; background: var(--line); }

/* selo / aviso */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 4px; font-size: var(--fs-sm); font-weight: 700; letter-spacing: 0.03em; background: var(--surface-2); color: var(--ink); border: 1px solid var(--line); }
.badge.tone-ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.badge.tone-warn { background: var(--warn-soft); color: var(--warn-ink); border-color: transparent; }
.badge.tone-bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.notice { padding: var(--sp-3) var(--sp-4); border-radius: var(--r-md); background: var(--surface); font-size: var(--fs-sm); color: var(--ink); border: 1px solid var(--line); text-wrap: pretty; }
.notice.tone-warn { background: var(--warn-soft); border-color: rgba(242, 182, 50, 0.3); }
.notice.tone-bad { background: var(--bad-soft); border-color: rgba(255, 122, 98, 0.3); }
.notice.tone-ok { background: var(--ok-soft); border-color: rgba(143, 227, 74, 0.3); }

/* como calculamos */
details.how { border-top: 1px solid var(--line); padding-top: var(--sp-4); }
details.how summary { cursor: pointer; font-family: var(--cond); font-weight: 700; font-size: var(--fs-sm); letter-spacing: 0.06em; text-transform: uppercase; color: var(--primary); list-style: none; display: flex; align-items: center; gap: 10px; min-height: 32px; }
details.how summary::-webkit-details-marker { display: none; }
details.how summary::before { content: ""; width: 8px; height: 8px; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(-45deg); transition: transform var(--dur) var(--ease); margin-left: 2px; }
details.how[open] summary::before { transform: rotate(45deg); }
details.how .how-body { display: grid; gap: var(--sp-3); padding: var(--sp-3) 0 var(--sp-2); font-size: var(--fs-sm); color: var(--ink); max-width: 70ch; }
details.how .how-body p { text-wrap: pretty; color: var(--creme); }
details.how pre { margin: 0; padding: var(--sp-3) var(--sp-4); background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); overflow-x: auto; font-size: var(--fs-sm); line-height: 1.6; color: var(--accent); }
details.how .src { color: var(--muted); font-size: var(--fs-xs); }

/* tabela de referência */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--r-md); background: var(--surface); }
table.ref { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
table.ref th, table.ref td { text-align: left; padding: 10px var(--sp-3); border-bottom: 1px solid var(--line); vertical-align: top; }
table.ref th { background: var(--surface-2); font-weight: 700; font-size: var(--fs-sm); letter-spacing: 0.04em; color: var(--muted); white-space: nowrap; }
table.ref tr:last-child td { border-bottom: 0; }
table.ref td.num, table.ref th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.ref tr.is-current td { background: var(--primary-soft); color: var(--ink); font-weight: 500; }

/* linhas dinâmicas (lúpulos, maltes, sais) */
.rows { display: grid; gap: var(--sp-3); }
.row { display: grid; gap: var(--sp-2); grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); align-items: end; padding: var(--sp-3); border: 1px solid var(--line); border-radius: var(--r-md); background: rgba(18, 19, 17, 0.6); }
.row .field-label { font-size: var(--fs-sm); }
.row .input-wrap input, .row .select-wrap select { height: 44px; font-size: var(--fs-md); }
.row .span-2 { grid-column: span 2; }
.row-actions { display: flex; align-items: center; gap: var(--sp-2); justify-content: flex-end; }
.row-out { display: grid; gap: 0; align-self: end; min-height: 44px; }
.row-out .k { font-size: var(--fs-xs); letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.row-out .v { font-weight: 500; font-variant-numeric: tabular-nums; color: var(--accent); }
.rows-foot { display: flex; gap: var(--sp-3); flex-wrap: wrap; align-items: center; justify-content: space-between; }

/* amostra de cor SRM */
.swatch { height: 96px; border-radius: var(--r-md); border: 1px solid rgba(243, 234, 211, 0.18); transition: background var(--dur) var(--ease); }
.swatch-scale { display: grid; grid-template-columns: repeat(40, 1fr); gap: 2px; }
.swatch-scale span { height: 18px; border-radius: 2px; }
.swatch-scale span.is-current { outline: 2px solid var(--creme); outline-offset: 1px; }

/* home */
.home-group { margin-bottom: var(--sp-6); display: grid; gap: var(--sp-3); }
.home-group h2 { font-family: var(--cond); font-size: var(--fs-xs); font-weight: 700; letter-spacing: 0.14em; text-transform: uppercase; color: var(--primary); }
.home-grid { display: grid; gap: var(--sp-3); grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.home-item { display: grid; gap: 4px; padding: var(--sp-4); border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--surface); text-decoration: none; color: var(--ink); transition: border-color var(--dur) var(--ease), background var(--dur) var(--ease), transform var(--dur) var(--ease); }
.home-item:hover { border-color: rgba(242, 182, 50, 0.6); background: var(--surface-2); transform: translateY(-2px); }
.home-item strong { font-family: var(--cond); font-weight: 700; font-size: var(--fs-lg); letter-spacing: 0.01em; }
.home-item span { font-size: var(--fs-sm); color: var(--muted); text-wrap: pretty; }
.calc-head h1.home-title { font-family: var(--display); text-transform: none; letter-spacing: 0; font-weight: 400; }

.foot { margin-top: var(--sp-8); padding-top: var(--sp-5); border-top: 1px solid var(--line); font-size: var(--fs-xs); color: var(--muted); max-width: 70ch; text-wrap: pretty; }

/* ---- responsivo ---- */
@media (max-width: 899px) {
  .app { grid-template-columns: minmax(0, 1fr); grid-template-areas: "top" "main"; }
  .nav-toggle { display: inline-flex; }
  .nav {
    position: fixed; top: var(--topbar-h); left: 0; bottom: 0; width: min(var(--nav-w), 86vw);
    z-index: var(--z-nav); transform: translateX(-100%); transition: transform var(--dur) var(--ease);
    box-shadow: 12px 0 40px rgba(0, 0, 0, 0.6);
  }
  body.nav-open .nav { transform: translateX(0); }
  .main { padding: var(--sp-5) var(--sp-4) var(--sp-7); }
  .topbar { padding: 0 var(--sp-4); }
  .brand-sub, .brand-site { display: none; }
  .calc-head h1 { font-size: var(--fs-2xl); }
  .result--big .result-value { font-size: var(--fs-2xl); }
}
@media (max-width: 420px) {
  .seg button { padding: 0 10px; }
  .brand-name { font-size: var(--fs-sm); }
  .swatch-scale { grid-template-columns: repeat(20, 1fr); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
@media print {
  :root { --bg: #fff; --surface: #fff; --surface-2: #f2f2f2; --ink: #111; --muted: #444; --line: #ccc; --line-strong: #999; }
  .topbar, .nav, .backdrop, .skip { display: none !important; }
  .app { display: block; }
  .calc-results { position: static; }
}
