:root {
  --cream: #F3EEE3; --label: #FFFCF5; --ink: #1B1A17; --ink-2: #5E5A52; --line: #DDD4C2;
  --brass: #B79F72; --green: #23503E; --green-dark: #1B3F31; --green-tint: #DCE7DF;
  --stamp: #9E3B2E; --stamp-tint: #F4E3DD;
  --serif: "Libre Caslon Text", Georgia, serif;
  --sans: "Libre Franklin", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  --gutter: 18px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body { background: var(--cream); color: var(--ink); font: 400 16px/22px var(--sans); }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; touch-action: manipulation; }
:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; }
[hidden] { display: none !important; }

.top { display: flex; flex-wrap: wrap; align-items: center; gap: 0 12px; margin: 0 var(--gutter); padding: 10px 0 6px; border-bottom: 1px solid var(--line); }
.brand { font-family: var(--serif); font-size: 22px; }
.switch-btn { flex: 1; min-width: 0; min-height: 44px; display: flex; align-items: center; justify-content: flex-end; gap: 8px; font-weight: 600; font-size: 15px; }
.switch-btn #formula-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.switch-btn .tri { flex: none; width: 0; height: 0; border-left: 5px solid transparent; border-right: 5px solid transparent; border-top: 6px solid var(--ink); }
.switch-btn[aria-expanded="true"] .tri { transform: rotate(180deg); }
.meta { flex-basis: 100%; text-align: right; font: 400 12px/16px var(--sans); color: var(--ink-2); }

.switcher { margin: 0 var(--gutter) 8px; padding: 16px; position: relative; z-index: 10; }
.switcher h2 { font: 400 19px/24px var(--serif); margin-bottom: 10px; }
.frows { border-top: 1px solid var(--line); }
.frow { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 48px; padding: 6px 4px; border-bottom: 1px solid var(--line); text-align: left; }
button.frow:hover { background: var(--cream); }
.frow.ex-row { margin-top: 10px; border-top: 1px solid var(--line); font-weight: 600; color: var(--green); }
.frow[aria-current] .fname { font-weight: 600; }
.frow[aria-current] .fname::after { content: " (open)"; font-weight: 400; color: var(--ink-2); }
.fname { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.fdate { font: 400 13px var(--mono); color: var(--ink-2); }
/* replace panel on phone: date under the name, so names don't wrap */
@media (max-width: 719px) {
  .frow.static { display: grid; grid-template-columns: 1fr auto; column-gap: 12px; }
  .frow.static .fname { grid-column: 1; }
  .frow.static .fdate { grid-column: 1; grid-row: 2; }
  .frow.static .btn { grid-column: 2; grid-row: 1 / span 2; }
}
.btn.small { min-height: 44px; padding: 0 12px; font-size: 15px; }
.sw-count { font-size: 13px; line-height: 19px; color: var(--ink-2); margin-top: 10px; }
.sw-note { font-size: 14px; line-height: 20px; color: var(--ink); margin-top: 10px; }
.sw-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }
.sw-actions .btn { padding: 0 16px; }
.sw-form label { display: block; font-weight: 500; margin-bottom: 6px; }
.go-pro { display: flex; align-items: center; justify-content: center; margin-top: 14px; text-decoration: none; color: var(--ink); }
.pro-link { display: inline-block; margin-top: 12px; color: var(--green); font-weight: 600; min-height: 44px; line-height: 44px; }

.ad { order: 9; margin: 20px auto 0; max-width: 100%; }
/* narrow phones: a 320px ad goes edge to edge instead of pushing the page sideways */
@media (max-width: 359px) { .ad { margin-inline: calc(-1 * var(--gutter)); max-width: none; } }
.ad-cap { font-size: 12px; color: var(--ink-2); margin-bottom: 4px; }
.ad-box { width: 320px; max-width: 100%; height: 100px; }
.brand i { color: var(--green); }

.layout { max-width: 640px; margin: 0 auto; padding-bottom: 48px; }
.output { display: flex; flex-direction: column; padding: 0 var(--gutter); margin-top: 32px; }
/* the desktop column has a max-height: items must scroll, never squash and overlap */
.output > * { flex-shrink: 0; }
.output.empty > :not(.lbl) { display: none; }
@media (max-width: 959px) { .output.empty { display: none; } }
.output:not(.has-fragrance) .actions,
.output:not(.has-fragrance) .copied { display: none; }

/* phone order: label, table, IFRA, actions, disclaimer */
.output .lbl { order: 1; }
.output .table-wrap { order: 2; }
.output .working-inline { order: 3; }
.output .ifra-out { order: 4; }
.output .actions { order: 5; }
.output .copied { order: 6; }
.output .print-opts { order: 7; }
.output .disc { order: 8; }

/* ---------- label ---------- */
.lbl { background: var(--label); border: 1.5px solid var(--ink); border-radius: 18px; padding: 18px; position: relative; }
.lbl::after { content: ""; position: absolute; inset: 5px; border: 1px solid var(--brass); border-radius: 13px; pointer-events: none; }
.lbl .t { font: 400 22px/26px var(--serif); text-align: center; margin-bottom: 10px; overflow-wrap: anywhere; }
.lbl .ph { color: var(--ink-2); }
.lbl .ing { font: 400 14px/22px var(--serif); overflow-wrap: anywhere; }
.lbl .h { font: 700 11px/1 var(--sans); letter-spacing: 1.5px; }
.lbl .al { position: relative; font: inherit; line-height: inherit; text-decoration: none; border-bottom: 2px solid var(--stamp); transition: background-color 600ms ease-out; }
/* 44px tall hit area without moving the text */
.lbl .al::before { content: ""; position: absolute; left: 0; right: 0; top: 50%; height: 44px; transform: translateY(-50%); }
.lbl .al.new { background: var(--green-tint); }
.lbl .al.sel { background: var(--stamp-tint); }
.lbl .missing { color: var(--ink-2); border-bottom: 1.5px dotted var(--stamp); }
.lbl .muted { color: var(--ink-2); }
/* T21: the next step, under the INCI */
.lbl .status { font: 400 14px/20px var(--sans); color: var(--ink); margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line); }
.lbl .status .links { display: flex; flex-wrap: wrap; gap: 0 18px; }
.lbl .status .text-btn { padding: 0; }
.lbl .f { display: flex; flex-wrap: wrap; gap: 0 8px; justify-content: space-between; font: 400 12px/16px var(--sans); color: var(--ink-2); margin-top: 10px; }

.pin { position: sticky; top: 0; z-index: 5; background: var(--cream); padding: 8px var(--gutter); border-bottom: 1px solid var(--line); }
.pin.away { position: static; border-bottom: 0; }
.lbl.mini { max-height: 30vh; overflow: hidden; padding: 12px 14px 10px; }
.lbl.mini.clipped {
  -webkit-mask-image: linear-gradient(#000 calc(100% - 24px), transparent); mask-image: linear-gradient(#000 calc(100% - 24px), transparent); }
.lbl.mini .t { font-size: 17px; line-height: 22px; margin-bottom: 6px; }
.lbl.mini .ing { font-size: 12.5px; line-height: 19px; }
.lbl.mini .f { display: none; }
.lbl.mini .status { margin-top: 8px; padding-top: 8px; }
#show-full { display: block; margin: 0 auto; }

/* T24: intro, empty formula only */
.intro { margin: 0 var(--gutter); padding: 18px 0 20px; border-bottom: 1px solid var(--line); }
.intro h1 { font: 400 26px/31px var(--serif); }
.intro p { font-size: 16px; line-height: 23px; margin-top: 8px; }
.intro .doors { display: grid; grid-template-columns: 1fr auto; gap: 10px; margin-top: 16px; }
.intro .doors .btn { padding: 0 10px; font-size: 15px; }
.lbl .ex-tag { display: flex; justify-content: space-between; align-items: center; margin: -6px 0 4px; }
.lbl .ex-tag .tag { color: var(--green); }
.lbl .nw { white-space: nowrap; }
.nudge { order: 6; font-size: 13px; line-height: 19px; color: var(--ink-2); text-align: center; margin-top: 4px; }
.nudge .text-btn { min-height: 0; padding: 0; position: relative; }
/* inline in the sentence, so no orphan word; the 44px tap zone is a ::before */
.nudge .text-btn::before { content: ""; position: absolute; left: 0; right: 0; top: 50%; height: 44px; transform: translateY(-50%); }
.hint { font-size: 14px; line-height: 20px; color: var(--ink); text-align: center; margin: 4px var(--gutter) 0; min-height: 0; }

/* ---------- formula ---------- */
.sec { margin: 24px var(--gutter) 0; }
.sec h2, .table-wrap h2 { font: 400 19px/24px var(--serif); margin-bottom: 8px; }
/* T22: numbered steps */
.sec h2.sh { display: flex; align-items: center; gap: 10px; font: 400 20px/24px var(--serif); margin-bottom: 10px; }
.sh .n { flex: none; display: inline-flex; align-items: center; justify-content: center; width: 22px; height: 22px; border-radius: 3px; background: var(--ink); color: var(--label); font: 500 13px/1 var(--mono); }
#step-fragrance { scroll-margin-top: 12px; }
.p1row .seg { margin-top: 12px; }
.field-label { display: block; font-weight: 500; margin-bottom: 6px; }
.card { background: var(--label); border: 1px solid var(--line); border-radius: 3px; }

/* one input style (T25) */
input.in-name { width: 100%; min-height: 44px; border: 1.5px solid var(--ink); border-radius: 3px; background: var(--label); padding: 10px 12px; font: 400 16px/22px var(--sans); }
.row-sub { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; margin-top: 6px; }
::placeholder { color: var(--ink-2); opacity: 1; }

.seg { display: grid; grid-template-columns: 1fr 1fr; border: 1.5px solid var(--ink); border-radius: 3px; overflow: hidden; }
.seg button { min-height: 44px; font-weight: 600; background: var(--label); }
.seg button + button { border-left: 1.5px solid var(--ink); }
.seg button[aria-pressed="true"] { background: var(--green); color: #fff; }
.type-note { font-size: 14px; line-height: 20px; color: var(--ink); margin-top: 8px; }

.row { padding: 12px; border-bottom: 1px solid var(--line); }
.row:last-child { border-bottom: 0; }
.row-main { display: grid; grid-template-columns: 1fr 112px; gap: 8px; }
.num { position: relative; display: block; }
.num input { width: 100%; min-height: 44px; background: var(--label); border: 1.5px solid var(--ink); border-radius: 3px; padding: 10px 28px 10px 8px; font: 400 15px/22px var(--mono); font-variant-numeric: tabular-nums; text-align: right; }
.num .unit { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); font: 400 15px var(--mono); color: var(--ink-2); pointer-events: none; }
.num input[aria-invalid] { border: 1.5px solid var(--stamp); }
.err { color: var(--stamp); font-size: 13px; line-height: 19px; margin-top: 4px; }
.row-hint { color: var(--ink); font-size: 14px; line-height: 20px; margin-top: 4px; }
.text-btn { min-height: 44px; padding: 0 4px; font-weight: 600; color: var(--green); }
.text-btn.quiet { font-weight: 400; color: var(--ink-2); }
.text-btn:hover { text-decoration: underline; }
.remove { display: block; margin-left: auto; margin-top: 4px; }
.add { display: block; margin-top: 4px; }

.frag { margin-bottom: 12px; padding: 14px; border: 1.5px solid var(--ink); }
.sheet-label { display: block; font-weight: 600; font-size: 15px; margin: 14px 0 6px; }
.help { font-size: 14px; line-height: 20px; color: var(--ink); margin-bottom: 8px; }
.help.no-sheet { margin: 6px 0 0; }
.ld { display: grid; grid-template-columns: 1fr 112px; gap: 12px; align-items: center; margin-top: 14px; }
.ld label { font-size: 15px; font-weight: 500; }
.ld label small { display: block; font-size: 13px; line-height: 19px; font-weight: 400; color: var(--ink-2); }
.frag .remove { margin: 4px -4px 0 auto; }
.frag .note { font-size: 14px; line-height: 20px; color: var(--ink); margin-top: 6px; }
.note.unmatched p + p { margin-top: 6px; }
.note b { font: 500 13px var(--mono); color: var(--ink); }
.disclose { display: flex; align-items: center; gap: 8px; min-height: 44px; margin-top: 6px; font-weight: 600; color: var(--green); text-align: left; }
.disclose .tri { flex: none; width: 0; height: 0; border-top: 5px solid transparent; border-bottom: 5px solid transparent; border-left: 6px solid var(--green); }
.disclose[aria-expanded="true"] .tri { transform: rotate(90deg); }
.disclose .opt { font-weight: 400; color: var(--ink-2); }
.details { padding-top: 4px; }

.paste { position: relative; background: #FFFEFB; border: 1.5px solid var(--ink); border-radius: 3px; }
.paste .mirror, .paste textarea { font: 400 13px/21px var(--mono); padding: 10px 12px; white-space: pre-wrap; overflow-wrap: anywhere; min-height: 132px; }
.paste .mirror { color: var(--ink); }
.paste .mirror s { color: var(--ink-2); text-decoration-color: var(--stamp); text-decoration-thickness: 1.5px; }
.paste .mirror .faint { color: var(--ink-2); }
.paste textarea { position: absolute; inset: 0; width: 100%; height: 100%; resize: none; border: 0; background: transparent; color: transparent; caret-color: var(--ink); overflow: hidden; }
/* never the typed text's font: italic sans, not mono (T23) */
.paste textarea::placeholder { font: italic 400 15px/21px var(--sans); color: var(--ink-2); }
.paste textarea:focus-visible { outline: none; }
.paste:focus-within { outline: 2px solid var(--green); outline-offset: 2px; }

.ifra { color: var(--stamp); font-size: 14px; line-height: 20px; margin-top: 8px; }
.ifra b { font-weight: 700; }
.ifra-out .ifra { padding: 0; margin-top: 12px; }

.total { display: flex; justify-content: space-between; padding: 12px; border-top: 1.5px solid var(--ink); }
.total .mono { font: 500 15px var(--mono); font-variant-numeric: tabular-nums; }
.total.off { color: var(--stamp); border-color: var(--stamp); }
.total-note { color: var(--stamp); font-size: 13px; line-height: 19px; padding: 0 12px; }

/* ---------- output ---------- */
.lbl.full .t { font-size: 22px; }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 20px; }
.print-opts { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin-top: 12px; font-size: 15px; }
.print-opts .num.mm { width: 96px; }
.print-opts .num.mm input { padding-right: 36px; }
.print-opts .check { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; }
.print-opts .check input { width: 20px; height: 20px; accent-color: var(--green); }
/* B7: ring on any focus, not only :focus-visible (some engines skip it on checkboxes) */
.print-opts .check input:focus { outline: 2px solid var(--green); outline-offset: 2px; }
.output:not(.has-fragrance) .print-opts { display: none; }
.print-opts .err { flex-basis: 100%; margin-top: 0; }
.btn { min-height: 48px; border-radius: 3px; font: 600 16px var(--sans); border: 1.5px solid var(--ink); background: var(--label); }
.btn:hover { background: var(--cream); }
.btn:active { transform: translateY(1px); }
.btn.pri { background: var(--green); border-color: var(--green); color: #fff; }
.btn.pri:hover { background: var(--green-dark); }
.copied { font: 400 18px/24px var(--serif); color: var(--green); text-align: center; margin-top: 10px; min-height: 0; }
.copied:empty { margin: 0; }

.table-wrap { margin-top: 24px; }
.table-wrap:empty { display: none; }
.cap { font-size: 13px; line-height: 19px; color: var(--ink-2); margin-bottom: 8px; }
.table { display: flex; flex-direction: column; }
.tr { display: grid; grid-template-columns: 1fr auto 64px; gap: 10px; align-items: center; min-height: 48px; padding: 8px 12px; text-align: left; border-bottom: 1px solid var(--line); }
.tr:last-child { border-bottom: 0; }
.tr:hover { background: var(--cream); }
.tn { font-size: 15px; }
.tp { font: 400 14px var(--mono); font-variant-numeric: tabular-nums; text-align: right; }
.tag { font: 700 12px var(--sans); letter-spacing: 1px; text-transform: uppercase; color: var(--ink-2); text-align: right; }
.tag.on { color: var(--stamp); }
.split { font-size: 13px; color: var(--ink-2); padding: 10px 12px 6px; border-top: 1.5px solid var(--ink); border-bottom: 1px solid var(--line); }

.disc { font: italic 400 13px/19px var(--serif); color: var(--ink-2); text-align: center; margin-top: 16px; }

/* ---------- working ---------- */
.wh { font: 400 24px/28px var(--serif); }
.lead { font-size: 15px; line-height: 22px; margin: 6px 0 14px; }
.lead b { font-family: var(--mono); font-weight: 500; }
.work { font: 400 14px/20px var(--mono); font-variant-numeric: tabular-nums; border-top: 1.5px solid var(--ink); }
.work .r { display: grid; grid-template-columns: 1fr auto auto auto auto; gap: 6px; padding: 8px 0; border-bottom: 1px solid var(--line); align-items: baseline; }
.work .r span:first-child { font-family: var(--sans); }
.work .r small { display: block; color: var(--ink-2); font-size: 12px; }
.work .op { color: var(--ink-2); }
.work .tot { font-weight: 500; border-bottom: 1.5px solid var(--ink); }
.work .th { color: var(--ink-2); font-size: 13px; }
.stamp { display: inline-block; border: 1.5px solid var(--stamp); color: var(--stamp); border-radius: 6px; padding: 3px 8px; font: 700 12px var(--sans); letter-spacing: 1px; text-transform: uppercase; transform: rotate(-2deg); margin-top: 14px; }
.stamp.off { border-color: var(--ink-2); color: var(--ink-2); transform: none; }
.foot { font-size: 13px; line-height: 19px; color: var(--ink-2); margin-top: 14px; }
.working-inline { padding: 16px 18px; margin-top: 16px; }
.working-inline .text-btn { display: block; margin: 8px 0 0 auto; }

dialog#sheet { margin: auto 0 0; width: 100%; max-width: 100%; max-height: 85vh; border: 0; background: transparent; padding: 0; }
dialog#sheet::backdrop { background: #1B1A1740; animation: fade 160ms; }
.sheet-panel { background: var(--label); border-top: 1.5px solid var(--ink); border-radius: 16px 16px 0 0; padding: 10px 20px 20px; box-shadow: 0 -2px 12px #0002; max-height: 85vh; overflow-y: auto; animation: up 220ms cubic-bezier(.2, .8, .2, 1); }
.grab { width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: 0 auto 14px; }
.sheet-panel .close { display: block; margin: 8px 0 0 auto; }
@keyframes up { from { transform: translateY(100%); } }
@keyframes fade { from { opacity: 0; } }

.toast { position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%); width: calc(100% - 32px); max-width: 420px; display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 4px 8px 4px 16px; background: var(--ink); color: var(--label); border-radius: 3px; z-index: 20; }
.toast .text-btn { color: var(--label); text-decoration: underline; }

@media (min-width: 960px) {
  .layout { max-width: 1200px; display: grid; grid-template-columns: 520px 1fr; gap: 40px; padding: 0 40px 48px; }
  .formula .sec { margin-left: 0; margin-right: 0; }
  .p1row { display: grid; grid-template-columns: 1fr 260px; gap: 12px; align-items: end; }
  .p1row .seg { margin-top: 0; }
  .paste .mirror, .paste textarea { min-height: 150px; }
  .intro { width: calc(100% - 80px); max-width: 1120px; margin: 8px auto 0; padding: 26px 0; display: grid; grid-template-columns: 1fr auto; gap: 8px 48px; align-items: end; }
  .intro h1 { grid-column: 1 / span 2; font-size: 34px; line-height: 40px; }
  .intro p { max-width: 640px; font-size: 17px; line-height: 25px; margin-top: 0; }
  .intro .doors { margin: 0; grid-template-columns: auto auto; }
  .intro .doors .btn { padding: 0 22px; font-size: 16px; }
  .brand { font-size: 26px; }
  .pin, .hint { display: none; }
  .output { position: sticky; top: 24px; align-self: start; max-height: calc(100vh - 48px); overflow-y: auto; margin-top: 24px; padding: 0 4px 16px; }
  .output .lbl { order: 1; }
  .output .actions { order: 2; }
  .output .copied { order: 3; }
  .output .nudge { order: 3; }
  .output .print-opts { order: 4; }
  .output .working-inline { order: 5; }
  .output .ifra-out { order: 6; }
  .output .table-wrap { order: 7; }
  .output .disc { order: 8; }
  .lbl.full .t { font-size: 28px; line-height: 32px; }
  .lbl.full .ing { font-size: 16px; line-height: 25px; }
  /* header and intro share the columns' container: content edge at the same x */
  .top { width: calc(100% - 80px); max-width: 1120px; margin: 0 auto; padding: 18px 0; }
  .meta { flex-basis: auto; }
  .switch-btn { flex: none; margin-left: auto; }
  .switcher { position: absolute; right: max(40px, calc((100vw - 1200px) / 2 + 40px)); top: 64px; width: 420px; margin: 0; border: 1.5px solid var(--ink); }
  .ad-box { width: 300px; height: 250px; }
}

.print-area { display: none; }

@media print {
  @page { margin: 10mm; }
  body { background: #fff; color: #000; }
  body > :not(.print-area) { display: none !important; }
  .print-area { display: block; width: var(--print-width, 90mm); }
  .plbl { padding: 3mm 4mm; font-family: var(--serif); break-inside: avoid; }
  .print-frame .plbl { border: 0.5pt solid #000; border-radius: 3mm; }
  .plbl .t { font-size: 13pt; line-height: 1.2; text-align: center; margin-bottom: 2mm; }
  .plbl .ing { font-size: 8pt; line-height: 1.4; }
  .plbl .h { font: 700 6.5pt var(--sans); letter-spacing: 0.8pt; }
  .pdisc { font: italic 400 8pt/1.3 var(--serif); margin-top: 2mm; padding: 0 4mm; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after, dialog::backdrop { animation: none !important; transition: none !important; }
}
