:root {
  color-scheme: light;
  --bg: #f5f7f4;
  --surface: #f9fbf8;
  --panel: #ffffff;
  --ink: #17211c;
  --muted: #607069;
  --line: #d5ddd8;
  --accent: #b84224;
  --accent-2: #1f6f5b;
  --warn: #9a3412;
  --bad: #9f1239;
  --shadow: 0 14px 34px rgba(23, 33, 28, 0.09);
  --radius: 8px;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body {
  min-height: 100%;
  margin: 0;
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.72), rgba(255,255,255,0) 320px),
    var(--bg);
  overflow-x: hidden;
}

img { max-width: 100%; display: block; }
button, input, select { font: inherit; }
button { cursor: pointer; }

.app {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 18px clamp(14px, 3vw, 28px) 36px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 0 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand > div {
  min-width: 0;
}

.brand img {
  width: 48px;
  height: 48px;
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.brand h1 {
  margin: 0;
  font-size: clamp(1.35rem, 2.6vw, 2.25rem);
  line-height: 1.05;
  letter-spacing: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.beta-badge {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  border: 1px solid rgba(184, 66, 36, 0.28);
  border-radius: 999px;
  padding: 2px 8px;
  background: #fff4e9;
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 850;
  line-height: 1;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.brand p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 0.95rem;
  overflow-wrap: anywhere;
}

.actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.btn {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 14px;
  background: var(--panel);
  color: var(--ink);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-shadow: 0 3px 12px rgba(23, 33, 28, 0.05);
}

.btn.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.btn.compact {
  padding-inline: 12px;
}

.btn.subtle {
  background: #f7f4ef;
  color: var(--muted);
}

.bottom-actions {
  margin-top: 18px;
  justify-content: center;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.08fr) minmax(340px, 0.92fr);
  gap: 18px;
  align-items: start;
}

.stack { display: grid; gap: 14px; }

section, .result-panel {
  background: rgba(249, 251, 248, 0.9);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

section {
  padding: 16px;
}

.section-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

h2 {
  margin: 0;
  font-size: 1.05rem;
  letter-spacing: 0;
}

.hint {
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

.grid {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 12px;
}

.field {
  display: grid;
  gap: 6px;
  grid-column: span 6;
  min-width: 0;
}

.field.third { grid-column: span 4; }
.field.full { grid-column: 1 / -1; }

.profile-tools {
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid rgba(213, 221, 216, 0.9);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.45);
}

.tool-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  min-width: 0;
}

.tool-row + .tool-row {
  grid-template-columns: minmax(0, 1fr) auto auto;
}

.pair {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 10px;
  min-width: 0;
}

.pair-title {
  grid-column: 1 / -1;
  color: var(--ink);
  font-size: 0.92rem;
  font-weight: 800;
}

.pair .field {
  grid-column: auto;
}

label {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 650;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  flex-wrap: wrap;
}

.help {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: inline-grid;
  place-items: center;
  border: 1px solid #b8c7c0;
  color: var(--accent-2);
  background: #f3f8f5;
  font-size: 0.72rem;
  font-weight: 900;
  cursor: help;
  line-height: 1;
  position: relative;
  flex: 0 0 auto;
  user-select: none;
}

.help::after {
  display: none;
}

.tooltip-popover {
  position: fixed;
  left: 10px;
  top: 10px;
  max-width: calc(100vw - 20px);
  width: max-content;
  min-width: min(220px, calc(100vw - 20px));
  background: #17211c;
  color: #fff;
  padding: 10px 11px;
  border-radius: 8px;
  box-shadow: 0 12px 28px rgba(23, 33, 28, 0.22);
  font-size: 0.82rem;
  font-weight: 650;
  line-height: 1.35;
  opacity: 0;
  pointer-events: none;
  transform: translateY(3px);
  transition: opacity 0.12s ease, transform 0.12s ease;
  z-index: 1000;
  white-space: normal;
}

.tooltip-popover.visible {
  opacity: 1;
  transform: translateY(0);
}

input, select {
  width: 100%;
  min-width: 0;
  height: 44px;
  min-height: 44px;
  border: 1px solid #cfc2b1;
  border-radius: 8px;
  padding: 8px 10px;
  background: var(--panel);
  color: var(--ink);
  line-height: 1.2;
  vertical-align: middle;
}

select {
  padding-right: 32px;
}

input:focus, select:focus, button:focus-visible {
  outline: 3px solid rgba(184, 66, 36, 0.22);
  outline-offset: 2px;
}

.result-panel {
  position: sticky;
  top: 12px;
  overflow: hidden;
}

.summary {
  padding: 18px;
  background: #18231f;
  color: #f8fbf7;
}

.summary .kicker {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #b8cbc2;
  font-weight: 800;
}

.summary strong {
  display: block;
  margin-top: 4px;
  font-size: clamp(1.8rem, 4vw, 3rem);
  line-height: 1;
  letter-spacing: 0;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1px;
  background: var(--line);
}

.metric {
  background: var(--panel);
  padding: 14px;
  min-height: 84px;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.metric strong {
  display: block;
  margin-top: 4px;
  font-size: 1.2rem;
}

.details {
  padding: 16px 18px 18px;
  display: grid;
  gap: 12px;
}

.recipe-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}

.recipe-table th,
.recipe-table td {
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
  text-align: right;
  vertical-align: top;
}

.recipe-table th:first-child,
.recipe-table td:first-child { text-align: left; }
.recipe-table tr:last-child td { border-bottom: 0; }

.note-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.note {
  border-left: 4px solid var(--accent-2);
  background: #eef7f2;
  padding: 9px 10px;
  border-radius: 6px;
  color: #163f32;
  line-height: 1.35;
}

.note.warn {
  border-left-color: var(--warn);
  background: #fff4e6;
  color: #71320f;
}

.note.bad {
  border-left-color: var(--bad);
  background: #fff1f2;
  color: #7f1231;
}

details {
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.expert-box {
  grid-column: 1 / -1;
  border-top: 0;
  padding-top: 0;
  background: #f6faf7;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px 12px;
}

.expert-box summary {
  color: var(--ink);
}

.expert-box .grid {
  margin-top: 12px;
}

.saved-recipes-box {
  grid-column: 1 / -1;
  border-top: 1px solid rgba(213, 221, 216, 0.9);
  padding-top: 10px;
}

.saved-recipes-box .profile-tools {
  margin-top: 10px;
}

.helper-box {
  margin-top: 10px;
  border-top: 1px solid rgba(213, 221, 216, 0.9);
  padding-top: 10px;
}

.helper-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr)) auto;
  gap: 10px;
  align-items: end;
  margin-top: 10px;
}

.helper-grid .field {
  grid-column: auto;
}

.helper-output {
  grid-column: 1 / -1;
  margin: 0;
  min-height: 1.35em;
}

summary {
  cursor: pointer;
  color: var(--muted);
  font-weight: 750;
}

.legal-footer {
  margin-top: 18px;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.45;
}

.legal-footer details {
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.legal-footer summary {
  width: fit-content;
}

.legal-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px 18px;
  margin-top: 10px;
}

.legal-grid h2 {
  margin: 0 0 5px;
  font-size: 0.92rem;
  color: var(--ink);
}

.legal-grid p {
  margin: 0 0 7px;
}

[data-protected] {
  cursor: default;
  -webkit-user-select: none;
  user-select: none;
}

.hidden { display: none !important; }

@media (max-width: 880px) {
  .topbar { align-items: flex-start; flex-direction: column; }
  .actions { width: 100%; justify-content: stretch; }
  .actions .btn { flex: 1 1 calc(50% - 8px); }
  .layout { grid-template-columns: 1fr; }
  .result-panel { position: static; }
}

@media (max-width: 620px) {
  .app { padding-inline: 10px; }
  .brand { align-items: flex-start; }
  .brand h1 { font-size: 1.45rem; }
  .brand p {
    font-size: 0.9rem;
    line-height: 1.25;
  }
  .brand img { width: 42px; height: 42px; }
  section { padding: 13px; }
  .field, .field.third { grid-column: 1 / -1; }
  .field.mobile-half,
  .field.third.mobile-half { grid-column: span 6; }
  .pair .field { grid-column: auto; }
  .pair input { min-height: 42px; }
  .tool-row,
  .tool-row + .tool-row,
  .helper-grid {
    grid-template-columns: 1fr;
  }
  .tool-row .btn,
  .helper-grid .btn {
    width: 100%;
  }
  .metrics { grid-template-columns: 1fr; }
  .recipe-table { font-size: 0.9rem; }
  .legal-grid { grid-template-columns: 1fr; }
}

@media print {
  body { background: #fff; }
  .actions,
  .stack {
    display: none !important;
  }
.app {
    max-width: none;
    padding: 0;
  }
  .layout {
    display: block;
  }
  .result-panel {
    box-shadow: none;
    border: 0;
  }
  .legal-footer {
    display: none;
  }
}
