:root {
    /* Pico's default scale reads ~25% too large (feedback); pin it down,
       including Pico's own wide-viewport bumps (this file loads after pico). */
    --pico-font-size: 92%;
    --cb-row-gap: 0.5rem;
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-weight: 700;
    font-size: 1.2rem;
}

.brand-icon {
    width: 1.1em;
    height: 1.1em;
    color: #e8590c;
}

/* ---- home ---------------------------------------------------------------- */

.home-links {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr));
    gap: 0.8rem;
    margin-top: 1rem;
}

.home-links a[role="button"] {
    padding: 1.1rem 1rem;
    font-size: 1.15rem;
    text-align: center;
}

.home-footer {
    margin-top: 2.5rem;
    text-align: center;
}

/* ---- tags ---------------------------------------------------------------- */

/* GitHub-style labels: the --label-* custom properties (RGB + HSL of the tag
   color) are set inline per chip (render.label_vars / app.js labelVars). Both
   themes use a translucent tint of the label color with the hue itself as text -
   darkened for light backgrounds, lightened for dark - so hues read as vivid in
   either mode. */
.tag-chip {
    --perceived-lightness: calc(
        (var(--label-r) * 0.2126 + var(--label-g) * 0.7152 + var(--label-b) * 0.0722) / 255
    );
    display: inline-flex;
    align-items: center;
    padding: 0.05rem 0.5rem;
    margin: 0 0.2rem 0.2rem 0;
    border-radius: 1rem;
    font-size: 0.9rem;
    font-weight: 500;
    line-height: 1.4;
    white-space: nowrap;
    border: 1px solid transparent;
    background: rgba(var(--label-r), var(--label-g), var(--label-b), 0.16);
    color: hsl(var(--label-h), calc(var(--label-s) * 1%), var(--label-text-l));
    border-color: hsla(var(--label-h), calc(var(--label-s) * 1%), var(--label-text-l), 0.35);
}

/* Light: cap text lightness so pale labels darken into readable text. */
@media (prefers-color-scheme: light) {
    .tag-chip {
        --label-text-l: min(calc(var(--label-l) * 1%), 32%);
    }
}

/* Dark: raise dark labels to a punchy lightness (GitHub's --lighten-by). */
@media (prefers-color-scheme: dark) {
    .tag-chip {
        --lightness-threshold: 0.6;
        --lightness-switch: max(0, min(calc((var(--perceived-lightness) - var(--lightness-threshold)) * -1000), 1));
        --lighten-by: calc((var(--lightness-threshold) - var(--perceived-lightness)) * 100 * var(--lightness-switch));
        --label-text-l: calc((var(--label-l) + var(--lighten-by)) * 1%);
        background: rgba(var(--label-r), var(--label-g), var(--label-b), 0.18);
        border-color: hsla(var(--label-h), calc(var(--label-s) * 1%), var(--label-text-l), 0.3);
    }
}

.tag-chip .chip-x {
    all: unset;
    cursor: pointer;
    margin-left: 0.35rem;
    font-weight: 700;
    line-height: 1;
}

.chip-input {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.25rem;
    width: 100%;
    padding: 0.4rem 0.7rem;
    margin-bottom: var(--pico-spacing);
    background: var(--pico-form-element-background-color);
    border: var(--pico-border-width) solid var(--pico-form-element-border-color);
    border-radius: var(--pico-border-radius);
    cursor: text;
    position: relative;
}

.chip-input .tag-chip {
    margin: 0;
}

/* Anchor the suggestion menu to the whole box, not the entry: the entry's
   .ac-wrap shifts as chips fill and wrap rows, which would drag the menu with
   it. Static wrap makes the menu resolve against .chip-input instead. */
.chip-input .ac-wrap {
    flex: 1;
    min-width: 8rem;
    position: static;
}

.chip-input .ac-menu {
    top: calc(100% + 0.2rem);
}

.chip-input input[type="text"] {
    width: 100%;
    height: auto;
    padding: 0.15rem 0;
    margin: 0;
    background: transparent;
    border: none;
    box-shadow: none;
    outline: none;
}

/* ---- autocomplete --------------------------------------------------------- */

.ac-wrap {
    position: relative;
    display: block;
}

.ac-menu {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 100;
    max-height: 14rem;
    margin: 0;
    padding: 0.2rem 0;
    overflow-y: auto;
    list-style: none;
    background: var(--pico-background-color);
    border: var(--pico-border-width) solid var(--pico-form-element-border-color);
    border-radius: var(--pico-border-radius);
    box-shadow: var(--pico-card-box-shadow, 0 0.25rem 0.75rem rgba(0, 0, 0, 0.2));
}

.ac-menu li {
    margin: 0;
    padding: 0.3rem 0.8rem;
    list-style: none;
    cursor: pointer;
}

.ac-menu li:hover,
.ac-menu li.active {
    background: var(--pico-primary-focus, rgba(0, 0, 0, 0.1));
}

/* ---- browse -------------------------------------------------------------- */

.result {
    padding: 0.6rem 0;
    border-bottom: 1px solid var(--pico-muted-border-color);
}

.result h4 {
    margin-bottom: 0.15rem;
}

.result .meta {
    font-size: 0.85rem;
    color: var(--pico-muted-color);
}

/* ---- editor -------------------------------------------------------------- */

.opt {
    font-size: 0.7rem;
    font-weight: 400;
    color: var(--pico-muted-color);
}

.frac {
    white-space: nowrap;
}

.frac sup,
.frac sub {
    font-size: 0.72em;
    line-height: 0;
}

.frac-bar {
    margin: 0 0.05em;
}

.recipe-form h3 {
    margin-top: 2.25rem;
    margin-bottom: 0.9rem;
}

.recipe-form > button[type="button"] {
    margin-top: 0.9rem;
}

.recipe-form textarea[data-autogrow] {
    min-height: 4.5rem;
    line-height: 1.6;
    overflow-y: hidden;
    resize: none;
}

.ing-row,
.step-row {
    display: grid;
    gap: var(--cb-row-gap);
    align-items: center;
    margin-bottom: 1.5rem;
}

.ing-row {
    grid-template-columns: 1.4fr 1.3fr 0.9fr 0.8fr;
}

/* Row controls sit above the fields they act on, so the values get the whole
   line to grow into. */
.ing-controls,
.step-controls {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.75rem;
}

.ing-controls {
    grid-column: 1 / -1;
}

#steps {
    counter-reset: step-row;
}

/* Numbered like the recipe view. A CSS counter rather than a rendered index, so
   rows renumber themselves after an add, a remove, or a reorder. */
.step-row {
    counter-increment: step-row;
    grid-template-columns: auto 1fr;
    column-gap: 1rem;
}

.step-row::before {
    content: counter(step-row);
    min-width: 1.8rem;
    text-align: right;
    font-size: 1.6rem;
    font-weight: 700;
    line-height: 1;
    color: var(--pico-primary);
    font-variant-numeric: tabular-nums;
}

.step-controls input {
    width: 10rem;
}

.step-row textarea[data-autogrow] {
    grid-column: 1 / -1;
    min-height: 3.5rem;
}

.ing-row > *,
.step-row > *,
.field-grid > label {
    min-width: 0;
}

.ing-row input,
.ing-row select,
.step-row input,
.step-row textarea {
    margin-bottom: 0;
}

.row-check {
    margin: 0;
    white-space: nowrap;
}

.row-actions {
    display: flex;
    gap: 0.3rem;
}

.row-actions button {
    margin-bottom: 0;
    padding: 0.4rem 0.6rem;
}

/* Compact square reorder buttons that hold an arrow glyph. */
.row-actions .icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.4rem;
}

.row-actions .icon-btn svg {
    width: 1em;
    height: 1em;
    display: block;
}

/* Stacked fields lose the column alignment that grouped them, so give each
   ingredient its own band. Steps keep their two columns: the number gutter is
   narrow enough to survive, and dropping it would strand the number on a line
   of its own. */
@media (max-width: 800px) {
    .ing-row {
        grid-template-columns: 1fr;
        padding: 0.9rem 0;
        margin-bottom: 0;
        border-top: 1px solid var(--pico-muted-border-color);
    }
}

.errors {
    border: 1px solid var(--pico-del-color, #b3261e);
    border-radius: var(--pico-border-radius);
    padding: 0.5rem 1rem;
    color: var(--pico-del-color, #b3261e);
}

.field-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 0 1rem;
}

/* ---- recipe view --------------------------------------------------------- */

.recipe-view h3 {
    margin-top: 2.5rem;
    margin-bottom: 1rem;
}

.recipe-view .preamble {
    max-width: 42rem;
    margin: 1.25rem 0;
    line-height: 1.7;
}

.recipe-view .source {
    margin-bottom: 1.25rem;
}

.recipe-view .recipe-image {
    margin: 1.25rem 0;
}

.recipe-view footer {
    margin-top: 2.5rem;
}

.scale-row {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin: 0.4rem 0 1rem;
    font-size: 0.9rem;
}

.scale-row .scale-label {
    color: var(--pico-muted-color);
}

.scale-row a.active {
    font-weight: 700;
    text-decoration: underline;
}

/* Quantity and unit get their own columns so amounts line up down the list
   instead of hiding at the head of a bulleted sentence. */
/* Percentage or fixed cell widths would make the table claim the whole line;
   leaving every column auto lets it shrink to its content. */
.ingredient-table {
    width: auto;
    max-width: 100%;
    margin-bottom: 0;
}

/* Pico gives cells the page background, which reads as a slab against the
   recipe card; only the row rules should be visible here. */
.ingredient-table td {
    padding: 0.5rem 0;
    vertical-align: baseline;
    background: none;
    border-bottom: 1px solid var(--pico-muted-border-color);
}

.ingredient-table tr:last-child td {
    border-bottom: none;
}

.ingredient-table .ing-amount {
    padding-right: 0.9rem;
    text-align: right;
    white-space: nowrap;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.ing-optional {
    margin-left: 0.4rem;
    font-size: 0.8rem;
    font-style: italic;
    color: var(--pico-muted-color);
}

.step-list {
    counter-reset: step;
    list-style: none;
    padding-left: 0;
    margin: 0;
}

/* Flex rows, not list markers: an <ol>'s hanging indent narrows every step to
   the point of extra wraps on a phone. */
.step-list li {
    counter-increment: step;
    display: flex;
    align-items: baseline;
    gap: 1rem;
    padding: 1rem 0;
    border-top: 1px solid var(--pico-muted-border-color);
}

.step-list li:first-child {
    border-top: none;
    padding-top: 0;
}

.step-list li::before {
    content: counter(step);
    flex: 0 0 1.8rem;
    text-align: right;
    font-size: 1.6rem;
    font-weight: 700;
    line-height: 1;
    color: var(--pico-primary);
    font-variant-numeric: tabular-nums;
}

.step-text {
    flex: 1;
    min-width: 0;
    line-height: 1.7;
}

.step-dur {
    display: inline-block;
    margin-left: 0.4rem;
    padding: 0.05rem 0.5rem;
    border-radius: 1rem;
    background: var(--pico-muted-border-color);
    color: var(--pico-muted-color);
    font-size: 0.78rem;
    white-space: nowrap;
}

/* ---- images -------------------------------------------------------------- */

.recipe-image {
    display: block;
    max-width: 100%;
    max-height: 20rem;
    width: auto;
    border-radius: var(--pico-border-radius);
}

.image-preview {
    display: block;
    max-width: 12rem;
    max-height: 8rem;
    object-fit: cover;
    border-radius: var(--pico-border-radius);
    margin-bottom: 0.5rem;
}

/* ---- misc ---------------------------------------------------------------- */

.action-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.action-row form {
    margin: 0;
}

.action-row a[role="button"],
.action-row button {
    width: auto;
    margin-bottom: 0;
}

.inline-form {
    display: inline;
}

/* Registry table row actions stay on one line, even on narrow screens. */
.table-actions {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 0.4rem;
}

.table-actions form {
    margin: 0;
}

.table-actions a[role="button"],
.table-actions button {
    width: auto;
    margin: 0;
    padding: 0.3rem 0.7rem;
    white-space: nowrap;
}

/* ---- cart ---------------------------------------------------------------- */

.cart-link {
    position: relative;
    display: inline-flex;
    align-items: center;
    padding: 0.2rem;
}

.cart-icon {
    width: 1.5rem;
    height: 1.5rem;
}

.settings-link {
    display: inline-flex;
    align-items: center;
    padding: 0.2rem;
}

.settings-icon {
    width: 1.5rem;
    height: 1.5rem;
}

.cart-badge {
    position: absolute;
    top: -0.35rem;
    right: -0.5rem;
    min-width: 1.05rem;
    padding: 0 0.28rem;
    border-radius: 1rem;
    background: #e8590c;
    color: #fff;
    font-size: 0.72rem;
    font-weight: 700;
    line-height: 1.05rem;
    text-align: center;
}

.result-head,
.title-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.6rem;
}

.result-head h4 {
    margin-bottom: 0;
}

/* Round add/remove toggle used on cards and the recipe page. */
.cart-toggle {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    padding: 0;
    margin: 0;
    border-radius: 50%;
    border: 1px solid var(--pico-primary);
    background: transparent;
    color: var(--pico-primary);
    cursor: pointer;
}

.cart-toggle svg {
    width: 1.1rem;
    height: 1.1rem;
}

.cart-toggle.in-cart {
    background: var(--pico-primary);
    color: var(--pico-primary-inverse);
}

.shopping-list {
    max-width: 24rem;
}

.shopping-list li {
    padding: 0.1rem 0;
}

.cart-recipes {
    list-style: none;
    padding: 0;
}

.cart-recipes li {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    padding: 0.35rem 0;
    border-bottom: 1px solid var(--pico-muted-border-color);
}

.cart-recipe-title {
    flex: 1 1 8rem;
}

.cart-recipes .inline-form button {
    margin: 0;
    padding: 0.2rem 0.6rem;
    font-size: 0.8rem;
}

/* Segmented 1/2x - 1x - 2x scale control per cart recipe. */
.cart-scale {
    display: inline-flex;
    margin: 0;
    border: 1px solid var(--pico-primary);
    border-radius: 0.4rem;
    overflow: hidden;
}

.cart-scale .scale-btn {
    width: auto;
    margin: 0;
    padding: 0.15rem 0.55rem;
    font-size: 0.78rem;
    line-height: 1.3;
    background: transparent;
    color: var(--pico-primary);
    border: none;
    border-left: 1px solid var(--pico-primary);
    border-radius: 0;
}

.cart-scale .scale-btn:first-child {
    border-left: none;
}

.cart-scale .scale-btn.active {
    background: var(--pico-primary);
    color: var(--pico-primary-inverse);
}

.rec-note {
    font-style: italic;
}

/* ---- settings reference -------------------------------------------------- */

.reference h2 {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.6rem;
    font-size: 1.1rem;
    margin: 0;
}

.reference h3 {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0.5rem;
    font-size: 0.95rem;
    margin-bottom: 0.4rem;
}

.reference-note {
    margin: 0.4rem 0 0;
    font-size: 0.85rem;
    color: var(--pico-muted-color);
}

.ladder-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(18rem, 1fr));
    gap: 1.5rem;
}

.ref-table {
    margin: 0;
    font-size: 0.82rem;
}

.ref-table th,
.ref-table td {
    padding: 0.25rem 0.6rem 0.25rem 0;
}

.ref-table th {
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--pico-muted-color);
}

.ref-table td:first-child {
    font-weight: 600;
    white-space: nowrap;
}

.ref-table td:not(:first-child) {
    color: var(--pico-muted-color);
}

.ladder-note {
    margin: 0.4rem 0 0;
    font-size: 0.78rem;
    color: var(--pico-muted-color);
}
