*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

.hidden {
    display: none !important;
}

:root {
    --ink: #18181b;
    --ink-secondary: #52525b;
    --ink-muted: #71717a;
    --surface: #ffffff;
    --surface-subtle: #f8f8f8;
    --surface-muted: #f1f2f4;
    --border: #e4e4e7;
    --border-strong: #d4d4d8;
    --accent: #18181b;
    --check: #16a34a;
    --error-bg: #fef2f2;
    --error-border: #fecaca;
    --error-text: #b91c1c;
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
}

html.dark-mode {
    --ink: #f0f0f2;
    --ink-secondary: #a1a1aa;
    --ink-muted: #71717a;
    --surface: #141416;
    --surface-subtle: #1c1c1f;
    --surface-muted: #242429;
    --border: #2c2c32;
    --border-strong: #3f3f46;
    --accent: #f0f0f2;
    --error-bg: #2a1416;
    --error-border: #5c2327;
    --error-text: #f87171;
}

html, body {
    background-color: var(--surface);
    color: var(--ink);
    font-family: "Avenir Next", "Avenir", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

html.theme-ready,
html.theme-ready body {
    transition: background-color 0.25s ease, color 0.25s ease;
}

a {
    color: inherit;
    text-decoration: none;
}

.site-header {
    background-color: var(--surface-subtle);
    border-bottom: 1px solid var(--border);
    height: 4rem;
    padding: 0 1.5rem;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 40;
}

.back-btn {
    display: inline-flex;
    align-items: center;
    justify-self: start;
    gap: 0.45rem;
    font-family: Arial, sans-serif;
    font-size: 0.8rem;
    letter-spacing: 2px;
    line-height: 1;
    text-transform: uppercase;
    color: #666f7e;
    transition: color 0.2s ease;
}

.back-btn:hover {
    color: var(--ink);
}

.header-brand {
    font-family: Arial, sans-serif;
    font-size: 0.9rem;
    letter-spacing: 5px;
    text-indent: 5px;
    color: #666f7e;
    justify-self: center;
    text-align: center;
    line-height: 1;
    white-space: nowrap;
}

.container {
    width: 100%;
    max-width: 1280px;
    margin: 0 auto;
    padding: 2rem 1.5rem 4rem;
    flex: 1;
}

.scanner-panel {
    max-width: 740px;
    margin: 0 auto 2rem;
    text-align: center;
}

.scanner-title {
    font-family: Arial, sans-serif;
    font-size: 1.85rem;
    font-weight: 400;
    letter-spacing: 3px;
    text-transform: uppercase;
    color: var(--ink);
    margin-bottom: 0.5rem;
}

.scanner-subtitle {
    font-size: 0.92rem;
    color: var(--ink-secondary);
    max-width: 560px;
    margin: 0 auto 1.25rem;
}

.mode-switch {
    display: inline-flex;
    background-color: var(--surface-muted);
    padding: 3px;
    border-radius: var(--radius-md);
    margin-bottom: 0.9rem;
}

.mode-btn {
    border: none;
    background: transparent;
    padding: 0.4rem 1rem;
    font-size: 0.78rem;
    font-weight: 500;
    letter-spacing: 0.5px;
    color: var(--ink-secondary);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s ease;
}

.mode-btn.active {
    background-color: var(--surface);
    color: var(--ink);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

.scan-form {
    margin-bottom: 0.85rem;
}

.input-group {
    display: flex;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-md);
    overflow: hidden;
    background-color: var(--surface);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.input-group:focus-within {
    border-color: var(--ink);
    box-shadow: 0 0 0 3px rgba(24, 24, 27, 0.06);
}

.input-group input {
    flex: 1;
    border: none;
    outline: none;
    padding: 0.85rem 1rem;
    font-size: 0.9rem;
    color: var(--ink);
    background: transparent;
    min-width: 0;
}

.input-group input::placeholder {
    color: var(--ink-muted);
}

.textarea-group {
    display: flex;
    flex-direction: column;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-md);
    overflow: hidden;
    background-color: var(--surface);
}

.textarea-group textarea {
    width: 100%;
    border: none;
    outline: none;
    padding: 0.85rem 1rem;
    font-size: 0.85rem;
    font-family: inherit;
    color: var(--ink);
    resize: vertical;
}

.primary-btn {
    border: none;
    background-color: var(--ink);
    color: var(--surface);
    padding: 0.85rem 1.5rem;
    font-family: Arial, sans-serif;
    font-size: 0.78rem;
    font-weight: 600;
    letter-spacing: 2px;
    text-transform: uppercase;
    cursor: pointer;
    transition: background-color 0.2s ease;
    white-space: nowrap;
}

.primary-btn:hover {
    background-color: #3f3f46;
}

.primary-btn:disabled {
    opacity: 0.6;
    cursor: wait;
}

.preset-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
}

.preset-label {
    font-size: 0.78rem;
    color: var(--ink-muted);
    margin-right: 0.2rem;
}

.preset-chip {
    border: 1px solid var(--border);
    background-color: var(--surface-subtle);
    color: var(--ink-secondary);
    padding: 0.3rem 0.75rem;
    border-radius: 999px;
    font-size: 0.76rem;
    cursor: pointer;
    transition: all 0.15s ease;
}

.preset-chip:hover,
.preset-chip.active {
    border-color: var(--ink);
    background-color: var(--ink);
    color: var(--surface);
}

.status-box {
    margin-top: 0.9rem;
    padding: 0.65rem 1rem;
    border-radius: var(--radius-md);
    font-size: 0.84rem;
    display: inline-block;
    max-width: 640px;
}

.status-box.error {
    background-color: var(--error-bg);
    border: 1px solid var(--error-border);
    color: var(--error-text);
}

.status-box.loading {
    background-color: var(--surface-subtle);
    border: 1px solid var(--border);
    color: var(--ink-secondary);
}

.recipe-card {
    background-color: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-lg);
    padding: 2rem;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.04);
}

.recipe-header {
    padding-bottom: 1.5rem;
    margin-bottom: 1.75rem;
    border-bottom: 1px solid var(--border);
}

.recipe-title-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1rem;
}

.recipe-tag {
    display: inline-block;
    font-family: Arial, sans-serif;
    font-size: 0.65rem;
    font-weight: 600;
    letter-spacing: 2px;
    text-transform: uppercase;
    color: #666f7e;
    background-color: var(--surface-muted);
    padding: 0.2rem 0.55rem;
    border-radius: var(--radius-sm);
    margin-bottom: 0.4rem;
}

.recipe-title {
    font-size: 1.65rem;
    font-weight: 600;
    color: var(--ink);
    line-height: 1.25;
}

.source-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.76rem;
    color: var(--ink-secondary);
    border: 1px solid var(--border);
    padding: 0.4rem 0.75rem;
    border-radius: var(--radius-sm);
    white-space: nowrap;
    transition: all 0.15s ease;
}

.source-btn:hover {
    border-color: var(--ink);
    color: var(--ink);
}

.recipe-meta-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem 2rem;
    margin-bottom: 1.25rem;
}

.meta-item {
    display: flex;
    flex-direction: column;
}

.meta-label {
    font-size: 0.65rem;
    font-weight: 600;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    color: var(--ink-muted);
}

.meta-val {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--ink);
}

.controls-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    background-color: var(--surface-subtle);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
}

.scale-controls,
.utility-controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.control-label {
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: var(--ink-muted);
}

.scale-buttons {
    display: inline-flex;
    background-color: var(--border);
    padding: 2px;
    border-radius: var(--radius-sm);
    gap: 2px;
}

.scale-btn {
    border: none;
    background: transparent;
    padding: 0.25rem 0.6rem;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--ink-secondary);
    border-radius: 3px;
    cursor: pointer;
}

.scale-btn.active {
    background-color: var(--surface);
    color: var(--ink);
}

.util-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    border: 1px solid var(--border-strong);
    background-color: var(--surface);
    color: var(--ink-secondary);
    padding: 0.35rem 0.7rem;
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
}

.util-btn:hover {
    border-color: var(--ink);
    color: var(--ink);
}

.recipe-columns {
    display: grid;
    grid-template-columns: 310px 1fr;
    gap: 2.5rem;
    align-items: start;
}

.panel-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-bottom: 0.5rem;
    margin-bottom: 0.25rem;
    border-bottom: 2px solid var(--ink);
}

.panel-heading h3 {
    font-family: Arial, sans-serif;
    font-size: 0.85rem;
    font-weight: 700;
    letter-spacing: 2px;
    text-transform: uppercase;
    color: var(--ink);
}

.count-pill {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--ink-secondary);
    background-color: var(--surface-muted);
    padding: 0.1rem 0.5rem;
    border-radius: 999px;
}

.panel-hint {
    font-size: 0.74rem;
    color: var(--ink-muted);
    margin-bottom: 0.85rem;
}

.ingredients-list {
    list-style: none;
    display: flex;
    flex-direction: column;
}

.ingredient-row {
    display: flex;
    align-items: flex-start;
    gap: 0.65rem;
    padding: 0.6rem 0.4rem;
    border-bottom: 1px solid var(--surface-muted);
    cursor: pointer;
    border-radius: var(--radius-sm);
    user-select: none;
    transition: background-color 0.15s ease;
}

.ingredient-row:hover {
    background-color: var(--surface-subtle);
}

.check-box {
    width: 17px;
    height: 17px;
    border: 1.5px solid var(--border-strong);
    border-radius: 4px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-top: 2px;
    background-color: var(--surface);
    color: transparent;
    transition: all 0.15s ease;
}

.ingredient-row.done .check-box {
    background-color: var(--ink);
    border-color: var(--ink);
    color: var(--surface);
}

.ingredient-row.done .ingredient-label {
    text-decoration: line-through;
    color: var(--ink-muted);
}

.ingredient-label {
    font-size: 0.9rem;
    color: var(--ink);
    line-height: 1.45;
}

.instructions-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
}

.instruction-step {
    display: grid;
    grid-template-columns: 28px 1fr;
    gap: 0.9rem;
    padding: 0.95rem 1.1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background-color: var(--surface);
    cursor: pointer;
    user-select: none;
    transition: border-color 0.15s ease, background-color 0.15s ease;
}

.instruction-step:hover {
    border-color: var(--border-strong);
    background-color: var(--surface-subtle);
}

.step-badge {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background-color: var(--surface-muted);
    color: var(--ink);
    font-size: 0.78rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.instruction-step.done {
    background-color: var(--surface-subtle);
    border-color: var(--border);
}

.instruction-step.done .step-badge {
    background-color: var(--ink);
    color: var(--surface);
}

.instruction-step.done .step-body {
    text-decoration: line-through;
    color: var(--ink-muted);
}

.step-body {
    font-size: 0.94rem;
    color: var(--ink);
    line-height: 1.65;
    padding-top: 2px;
}

@media (max-width: 820px) {
    .recipe-columns {
        grid-template-columns: 1fr;
        gap: 2rem;
    }

    .recipe-card {
        padding: 1.25rem;
    }
}

@media (max-width: 580px) {
    .back-btn span {
        display: none;
    }

    .back-btn svg {
        width: 18px;
        height: 18px;
    }

    .header-brand {
        font-size: 0.75rem;
        letter-spacing: 3px;
        text-indent: 3px;
    }

    .scanner-title {
        font-size: 1.4rem;
    }

    .input-group {
        flex-direction: column;
    }

    .primary-btn {
        width: 100%;
    }

    .recipe-title-row {
        flex-direction: column;
    }

    .controls-bar {
        flex-direction: column;
        align-items: stretch;
    }

    .scale-controls,
    .utility-controls {
        justify-content: space-between;
    }
}

@media print {
    .site-header,
    .scanner-panel,
    .controls-bar,
    .panel-hint,
    .source-btn,
    .site-footer {
        display: none !important;
    }

    .recipe-card {
        border: none;
        box-shadow: none;
        padding: 0;
    }

    .recipe-columns {
        grid-template-columns: 240px 1fr;
        gap: 1.5rem;
    }
}
.copyright {
    font-family: Arial;
    font-weight: lighter;
    letter-spacing: 5px;
    font-size: 80%;
    bottom: 0;
    width: 100%;
    color: #666f7e;
    background-color: var(--surface-subtle);
    padding: 10px 0;
}

/* Theme Toggle & Dark Mode Overrides */
.theme-toggle {
    position: relative;
    justify-self: end;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.5rem;
    height: 2.5rem;
    margin-right: -0.375rem;
    padding: 0;
    border: none;
    border-radius: 9999px;
    background: transparent;
    color: #666f7e;
    cursor: pointer;
    z-index: 15;
    transition: background-color 0.2s ease, color 0.2s ease;
}

.theme-toggle:hover {
    background-color: rgba(0, 0, 0, 0.06);
    color: var(--ink);
}

.theme-toggle:focus-visible {
    outline: 2px solid #666f7e;
    outline-offset: 2px;
}

.theme-toggle svg {
    width: 1.75rem;
    height: 1.75rem;
}

.theme-toggle .icon-sun {
    display: block;
}

.theme-toggle .icon-moon {
    display: none;
}

html.dark-mode .theme-toggle {
    color: #a1a1aa;
}

html.dark-mode .theme-toggle:hover {
    background-color: rgba(255, 255, 255, 0.08);
    color: var(--ink);
}

html.dark-mode .theme-toggle .icon-sun {
    display: none;
}

html.dark-mode .theme-toggle .icon-moon {
    display: block;
}

html.dark-mode .back-btn,
html.dark-mode .header-brand,
html.dark-mode .recipe-tag,
html.dark-mode .copyright {
    color: #a1a1aa;
}

@media (max-width: 768px) {
    .site-header {
        padding: max(env(safe-area-inset-top, 0px), 0.75rem) 1rem 0 1rem;
        height: calc(3.5rem + max(env(safe-area-inset-top, 0px), 0.75rem));
    }

    .container {
        padding: 1.5rem 1rem 3rem;
    }
}