:root,
html[data-theme="dark"] {
    --bg: #0f1419;
    --bg-gradient: #1a2740;
    --surface: #1a2332;
    --surface-2: #243044;
    --border: #2f3f56;
    --text: #e8eef7;
    --text-muted: #8fa3bc;
    --accent: #4da3ff;
    --accent-hover: #79b8ff;
    --success: #3ecf8e;
    --warning: #f0b429;
    --danger: #f07178;
    --radius: 10px;
    --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
    --beaker-empty: #1e2a3a;
}

html[data-theme="light"] {
    --bg: #eef2f7;
    --bg-gradient: #d8e4f2;
    --surface: #ffffff;
    --surface-2: #f3f6fa;
    --border: #c5d0de;
    --text: #1a2332;
    --text-muted: #5a6d85;
    --accent: #1a73e8;
    --accent-hover: #1557b0;
    --success: #1e8e5a;
    --warning: #b8860b;
    --danger: #c62828;
    --shadow: 0 8px 24px rgba(26, 35, 50, 0.1);
    --beaker-empty: #c5d4e8;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
    background: radial-gradient(circle at top, var(--bg-gradient) 0%, var(--bg) 55%);
    color: var(--text);
}

.setup-error {
    max-width: 640px;
    margin: 4rem auto;
    padding: 2rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.setup-error pre {
    background: var(--bg);
    padding: 1rem;
    border-radius: 6px;
    overflow-x: auto;
}

.app {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    min-height: 100vh;
    padding: 1rem;
}

.chem-workbench {
    display: grid;
    grid-template-columns: minmax(300px, 380px) minmax(0, 1.4fr) minmax(240px, 300px);
    gap: 1rem;
    flex: 1;
    min-height: 0;
}

.machine {
    min-height: 0;
}

.machine-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 1rem;
    border-bottom: 1px solid var(--border);
}

.machine-header h2 {
    margin: 0;
    font-size: 1rem;
    font-weight: 700;
}

.machine-desc {
    margin: 0.25rem 0 0;
    font-size: 0.78rem;
    color: var(--text-muted);
    line-height: 1.35;
}

.machine-badge {
    flex-shrink: 0;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--accent);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 0.2rem 0.55rem;
    background: var(--surface-2);
}

.machine-dispenser {
    border-top: 3px solid #3ecf8e;
}

.machine-chemmaster {
    border-top: 3px solid var(--accent);
}

.machine-guide {
    border-top: 3px solid var(--warning);
}

.dispenser-beaker-slot {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
    background: var(--surface-2);
}

.slot-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 0.4rem;
}

.slot-preview {
    position: relative;
    height: 72px;
    border: 2px solid var(--border);
    border-radius: 8px;
    background: #0a1018;
    overflow: hidden;
}



.slot-volume {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.82rem;
    font-weight: 600;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
    z-index: 3;
}

.chem-grid-toolbar {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    padding: 0.75rem 1rem 0;
}

.show-all-toggle {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.78rem;
    color: var(--text-muted);
}

.chem-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.35rem;
    padding: 0.75rem 1rem 1rem;
    overflow-y: auto;
    flex: 1;
    min-height: 280px;
    max-height: calc(100vh - 22rem);
    align-content: start;
}

.chem-grid-section {
    grid-column: 1 / -1;
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--text-muted);
    padding-top: 0.35rem;
}

.chem-grid-divider {
    grid-column: 1 / -1;
    border: none;
    border-top: 1px solid var(--border);
    margin: 0.35rem 0 0.15rem;
    height: 0;
}

.chem-btn {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 0.4rem;
    min-height: 40px;
    padding: 0.35rem 0.45rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface-2);
    color: var(--text);
    cursor: pointer;
    text-align: left;
    transition: border-color 0.15s, transform 0.1s;
}

.chem-btn:hover,
.chem-btn.selected {
    border-color: var(--accent);
    transform: translateY(-1px);
}

.chem-btn.highlighted {
    box-shadow: 0 0 0 2px rgba(77, 163, 255, 0.35);
}

.chem-btn-color {
    flex-shrink: 0;
    width: 4px;
    height: 24px;
    border-radius: 999px;
}

.chem-btn-name {
    flex: 1;
    font-size: 0.74rem;
    font-weight: 600;
    line-height: 1.2;
    word-break: break-word;
    text-align: left;
}

.chem-btn-tag {
    font-size: 0.62rem;
    color: var(--text-muted);
}

.chemmaster-tabs {
    display: flex;
    gap: 0.35rem;
    padding: 0.65rem 1rem;
    border-bottom: 1px solid var(--border);
}

.mixture-analysis {
    padding: 0 1rem;
}

.mixture-analysis h3,
.beaker-contents h3,
.saved-mixtures h3 {
    margin: 0.75rem 0 0.5rem;
    font-size: 0.85rem;
}

.medicine-analysis {
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
}

.mix-group-label {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    margin-bottom: 0.3rem;
}

.mix-chip-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
}

.mix-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.25rem 0.5rem;
    border-radius: 999px;
    font-size: 0.75rem;
    background: color-mix(in srgb, var(--chip-color) 25%, var(--surface-2));
    border: 1px solid color-mix(in srgb, var(--chip-color) 45%, var(--border));
}

.mix-chip em {
    font-style: normal;
    color: var(--text-muted);
}

.guide-targets {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
}

.guide-targets h3 {
    margin: 0 0 0.5rem;
    font-size: 0.85rem;
}

.guide-med-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
}

.guide-med-btn {
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text);
    border-radius: 999px;
    padding: 0.3rem 0.65rem;
    font-size: 0.78rem;
    cursor: pointer;
}

.guide-med-btn:hover {
    border-color: var(--accent);
}

.machine-guide .reagent-info {
    padding: 0.75rem 1rem;
    overflow-y: auto;
    flex: 1;
}

.app-header {
    padding: 0.5rem 0.25rem;
}

.header-main {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-shrink: 0;
}

.btn-icon {
    width: 2.25rem;
    height: 2.25rem;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface-2);
    color: var(--text);
    font-size: 1.1rem;
    line-height: 1;
    cursor: pointer;
}

.btn-icon:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.app-header h1 {
    margin: 0;
    font-size: 1.5rem;
    font-weight: 700;
}

.subtitle {
    margin: 0.25rem 0 0;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

.panel-header {
    padding: 1rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
}

.panel-header h2 {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
}

.beaker-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.dispenser-panel .panel-header {
    flex-direction: column;
    align-items: stretch;
}

#dispenser-mode {
    width: 100%;
    padding: 0.55rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface-2);
    color: var(--text);
    font: inherit;
}

.dispenser-hint.dispenser-error {
    color: var(--danger, #f87171);
    font-weight: 600;
}

.dispenser-hint {
    margin: 0;
    font-size: 0.75rem;
    color: var(--text-muted);
    line-height: 1.35;
}

.dispenser-section-label {
    padding: 0.55rem 0.75rem 0.2rem;
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text-muted);
    list-style: none;
}

.reagent-name {
    flex: 1;
    min-width: 0;
}

.reagent-source {
    margin-left: auto;
    font-size: 0.68rem;
    color: var(--text-muted);
    white-space: nowrap;
}

#reagent-search {
    width: 100%;
    padding: 0.55rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface-2);
    color: var(--text);
    font-size: 0.9rem;
}

#reagent-search:focus {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

.dispense-controls {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
}

.dispense-controls label {
    display: block;
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 0.35rem;
}

.amount-row {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

#dispense-amount {
    width: 100%;
    padding: 0.5rem 0.65rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface-2);
    color: var(--text);
}

.amount-presets {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(2.6rem, 1fr));
    gap: 0.35rem;
}

.amount-presets .preset-btn {
    flex: none;
    min-width: 0;
    min-height: 36px;
    padding: 0.35rem 0.4rem;
}

.preset-btn,
.btn-secondary,
.remove-btn {
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text);
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.8rem;
    transition: background 0.15s, border-color 0.15s;
}

.preset-btn {
    flex: 1;
    padding: 0.45rem 0.5rem;
    min-height: 44px;
}

.preset-btn:hover,
.btn-secondary:hover,
.remove-btn:hover {
    background: var(--border);
}

.reagent-list {
    list-style: none;
    margin: 0;
    padding: 0.5rem;
    overflow-y: auto;
    flex: 1;
}

.reagent-btn {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.65rem 0.6rem;
    min-height: 44px;
    border: 1px solid transparent;
    border-radius: 6px;
    background: transparent;
    color: var(--text);
    cursor: pointer;
    text-align: left;
    font-size: 0.85rem;
    transition: background 0.15s, border-color 0.15s;
}

.reagent-btn:hover,
.reagent-btn.selected {
    background: var(--surface-2);
    border-color: var(--border);
}

.reagent-btn.selected {
    border-color: var(--accent);
}

.swatch {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    flex-shrink: 0;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.beaker-panel {
    padding-bottom: 1rem;
}

.beaker-stage {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 2rem;
    padding: 1.5rem 1rem 1rem;
}

.beaker-container {
    width: 140px;
    height: 200px;
}

.beaker-glass {
    position: relative;
    width: 100%;
    height: 100%;
    border: 3px solid rgba(200, 220, 255, 0.45);
    border-top: none;
    border-radius: 0 0 18px 18px;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0.02));
    overflow: hidden;
    box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.3);
}

.beaker-liquid-stack,
.slot-liquid-stack {
    position: absolute;
    inset: 0;
    overflow: hidden;
    border-radius: 0 0 14px 14px;
}

.slot-liquid-stack {
    border-radius: 6px;
}

.beaker-liquid,
.slot-liquid {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 0%;
    transition: height 0.45s ease, background 0.65s ease, filter 0.4s ease;
    border-radius: inherit;
}

.beaker-liquid {
    border-radius: 0 0 14px 14px;
}

.mix-vessel.is-mixing .beaker-liquid,
.mix-vessel.is-mixing .slot-liquid {
    filter: saturate(1.2) brightness(1.08);
}

.beaker-liquid-swirl {
    position: absolute;
    inset: -20%;
    opacity: 0;
    pointer-events: none;
    background:
        radial-gradient(ellipse 45% 35% at 25% 75%, rgba(255, 255, 255, 0.45), transparent 60%),
        radial-gradient(ellipse 40% 30% at 75% 35%, rgba(255, 255, 255, 0.25), transparent 55%),
        conic-gradient(from 0deg at 50% 80%, transparent, rgba(255, 255, 255, 0.15), transparent);
    mix-blend-mode: soft-light;
}

.mix-vessel.is-mixing .beaker-liquid-swirl {
    opacity: 1;
    animation: beaker-swirl 1.1s ease-in-out infinite;
}

.beaker-liquid-bubbles {
    position: absolute;
    inset: 0;
    opacity: 0;
    pointer-events: none;
    overflow: hidden;
}

.mix-vessel.is-mixing .beaker-liquid-bubbles {
    opacity: 1;
}

.beaker-liquid-bubbles::before,
.beaker-liquid-bubbles::after {
    content: '';
    position: absolute;
    bottom: 15%;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.55);
    animation: bubble-rise 1.4s ease-in infinite;
}

.beaker-liquid-bubbles::before {
    left: 28%;
    animation-delay: 0s;
}

.beaker-liquid-bubbles::after {
    left: 62%;
    width: 5px;
    height: 5px;
    animation-delay: 0.45s;
}

.beaker-reaction-flash {
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background: radial-gradient(circle at 50% 85%, rgba(255, 255, 255, 0.55), transparent 65%);
    opacity: 0;
    pointer-events: none;
    z-index: 2;
}

.mix-vessel.reaction-pulse .beaker-reaction-flash {
    animation: reaction-flash 0.75s ease-out;
}

.mix-vessel.reaction-pulse {
    box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.3), 0 0 18px color-mix(in srgb, var(--accent) 35%, transparent);
}

@keyframes beaker-swirl {
    0% { transform: rotate(0deg) scale(1); }
    50% { transform: rotate(160deg) scale(1.06); }
    100% { transform: rotate(320deg) scale(1); }
}

@keyframes bubble-rise {
    0% { transform: translateY(0) scale(0.6); opacity: 0; }
    20% { opacity: 0.85; }
    100% { transform: translateY(-120px) scale(1.1); opacity: 0; }
}

@keyframes reaction-flash {
    0% { opacity: 0.85; }
    100% { opacity: 0; }
}

@keyframes chip-pop {
    0% { transform: scale(0.92); opacity: 0.5; }
    60% { transform: scale(1.04); }
    100% { transform: scale(1); opacity: 1; }
}

@keyframes mix-banner-in {
    from { opacity: 0; transform: translateY(-6px); }
    to { opacity: 1; transform: translateY(0); }
}

.compound-value {
    transition: color 0.5s ease;
}

.mix-compound-stat .compound-value {
    font-size: 1rem;
}

.mix-result-banner {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    margin: 0 1rem 0.75rem;
    padding: 0.65rem 0.75rem;
    border-radius: 10px;
    border: 1px solid color-mix(in srgb, var(--accent) 40%, var(--border));
    background: color-mix(in srgb, var(--accent) 12%, var(--surface-2));
}

.mix-result-banner.is-visible {
    animation: mix-banner-in 0.45s ease;
}

.mix-result-swatch {
    flex-shrink: 0;
    width: 14px;
    height: 36px;
    border-radius: 4px;
    box-shadow: 0 0 8px color-mix(in srgb, currentColor 30%, transparent);
}

.mix-result-text {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
    min-width: 0;
}

.mix-result-label {
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--accent);
}

.mix-result-name {
    font-size: 0.95rem;
}

.mix-result-meta {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.mix-result-banner.explosion-banner {
    border-color: color-mix(in srgb, #ff6b35 55%, var(--border));
    background: linear-gradient(
        135deg,
        color-mix(in srgb, #ff6b35 22%, var(--surface-2)),
        color-mix(in srgb, #ffd700 12%, var(--surface-2))
    );
}

.mix-result-banner.explosion-banner .mix-result-label {
    color: #ff6b35;
}

.mix-result-banner.explosion-banner .mix-result-name {
    color: #ffb347;
}

.explosion-info-card {
    border: 1px solid color-mix(in srgb, #ff6b35 45%, var(--border));
    background: color-mix(in srgb, #ff6b35 8%, var(--surface-2));
}

.explosion-info-card .info-title strong {
    color: #ff8c42;
}

.chem-workbench.screen-shake {
    animation: screen-shake 0.65s ease-out;
}

.mix-vessel.is-exploding {
    animation: vessel-shake 0.55s ease-in-out;
}

.mix-vessel.is-exploding .beaker-liquid,
.mix-vessel.is-exploding .slot-liquid {
    animation: explosion-drain 0.45s ease-out forwards;
    filter: saturate(2) brightness(1.4);
}

.mix-vessel.is-exploding .beaker-reaction-flash {
    animation: explosion-flash 0.85s ease-out;
    background:
        radial-gradient(circle at 50% 80%, rgba(255, 220, 80, 0.95), transparent 45%),
        radial-gradient(circle at 50% 80%, rgba(255, 90, 40, 0.85), transparent 60%);
}

.explosion-sparks {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 4;
    overflow: visible;
}

.explosion-smoke {
    position: absolute;
    left: 50%;
    bottom: 25%;
    width: 20px;
    height: 20px;
    margin-left: -10px;
    border-radius: 50%;
    pointer-events: none;
    z-index: 3;
    opacity: 0;
    background: radial-gradient(circle, rgba(120, 120, 120, 0.55), transparent 70%);
}

.mix-vessel.is-exploding .explosion-smoke {
    animation: explosion-smoke 1.1s ease-out forwards;
}

.explosion-spark {
    position: absolute;
    left: 50%;
    bottom: 28%;
    width: 7px;
    height: 7px;
    margin-left: -3px;
    border-radius: 50%;
    background: #ffae00;
    box-shadow: 0 0 6px #ff6b35;
    opacity: 1;
    animation: spark-fly 0.75s ease-out forwards;
}

.explosion-spark.spark-hot {
    background: #fff2a8;
    width: 9px;
    height: 9px;
    margin-left: -4px;
}

.explosion-spark.spark-ember {
    background: #ff5c33;
    width: 5px;
    height: 5px;
    margin-left: -2px;
}

@keyframes screen-shake {
    0%, 100% { transform: translate(0, 0); }
    12% { transform: translate(-6px, 3px); }
    24% { transform: translate(5px, -4px); }
    36% { transform: translate(-4px, -2px); }
    48% { transform: translate(4px, 4px); }
    60% { transform: translate(-3px, 1px); }
    72% { transform: translate(2px, -2px); }
}

@keyframes vessel-shake {
    0%, 100% { transform: translate(0, 0) rotate(0deg); }
    20% { transform: translate(-3px, 2px) rotate(-2deg); }
    40% { transform: translate(3px, -2px) rotate(2deg); }
    60% { transform: translate(-2px, -1px) rotate(-1deg); }
    80% { transform: translate(2px, 1px) rotate(1deg); }
}

@keyframes explosion-drain {
    0% { filter: saturate(2) brightness(1.6); }
    40% { height: var(--liquid-height, 50%); filter: saturate(0.3) brightness(2); opacity: 0.7; }
    100% { filter: saturate(0.5) brightness(0.8); opacity: 1; }
}

@keyframes explosion-flash {
    0% { opacity: 1; }
    30% { opacity: 0.95; }
    100% { opacity: 0; }
}

@keyframes explosion-smoke {
    0% { opacity: 0; transform: scale(0.4); }
    25% { opacity: 0.85; }
    100% { opacity: 0; transform: scale(4.5); }
}

@keyframes spark-fly {
    0% { transform: translate(0, 0) scale(1); opacity: 1; }
    100% { transform: translate(var(--spark-x), var(--spark-y)) scale(0.2); opacity: 0; }
}

.mix-chip.is-new {
    animation: chip-pop 0.55s ease;
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 55%, transparent);
    border-color: var(--accent);
}

.content-item.is-new {
    animation: chip-pop 0.5s ease;
    background: color-mix(in srgb, var(--accent) 8%, transparent);
    border-radius: 6px;
}

.beaker-markings {
    position: absolute;
    right: 6px;
    top: 12px;
    bottom: 12px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    font-size: 0.6rem;
    color: rgba(255, 255, 255, 0.35);
    pointer-events: none;
}

.beaker-stats {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.stat-label {
    display: block;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 0.2rem;
}

.stat-value {
    font-size: 1.1rem;
    font-weight: 600;
}

.temperature-control {
    padding: 0 1rem 1rem;
}

.temperature-control label {
    display: block;
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 0.4rem;
}

#temperature-slider {
    width: 100%;
    accent-color: var(--accent);
}

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

.temp-presets {
    display: flex;
    gap: 0.35rem;
    flex: 1;
    min-width: 180px;
}

.temp-preset-btn {
    flex: 1;
}

#temperature-input {
    width: 80px;
    padding: 0.4rem 0.5rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface-2);
    color: var(--text);
}

.temp-hint {
    margin: 0.5rem 0 0;
    font-size: 0.75rem;
    color: var(--text-muted);
    line-height: 1.4;
}

.beaker-contents,
.saved-mixtures {
    padding: 0 1rem;
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.saved-mixtures {
    flex: 0 0 auto;
    padding-bottom: 1rem;
    border-top: 1px solid var(--border);
    margin-top: 0.5rem;
    padding-top: 0.75rem;
}

.save-row {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

#mixture-name {
    flex: 1;
    padding: 0.45rem 0.6rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface-2);
    color: var(--text);
    font-size: 0.85rem;
}

#save-mixture {
    padding: 0.45rem 0.75rem;
    white-space: nowrap;
}

.autosave-status {
    margin: 0 0 0.5rem;
    font-size: 0.75rem;
    color: var(--text-muted);
}

.saved-mixtures-list {
    list-style: none;
    margin: 0;
    padding: 0;
    overflow-y: auto;
    max-height: 140px;
}

.saved-mixture-item {
    display: grid;
    grid-template-columns: 1fr auto auto;
    align-items: center;
    gap: 0.35rem;
    padding: 0.4rem 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    font-size: 0.8rem;
}

.saved-mixture-meta {
    color: var(--text-muted);
    font-size: 0.72rem;
}

.saved-mixture-actions {
    display: flex;
    gap: 0.25rem;
}

.load-mixture-btn,
.delete-mixture-btn {
    padding: 0.2rem 0.45rem;
    font-size: 0.72rem;
}

.delete-mixture-btn {
    color: var(--danger);
}

.beaker-contents h3,
.saved-mixtures h3 {
    margin: 0 0 0.5rem;
    font-size: 0.85rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.contents-list,
.reaction-log {
    list-style: none;
    margin: 0;
    padding: 0;
    overflow-y: auto;
    flex: 1;
}

.content-item {
    display: grid;
    grid-template-columns: 16px 1fr auto auto;
    align-items: center;
    gap: 0.5rem;
    padding: 0.45rem 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    font-size: 0.85rem;
}

.content-amount {
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}

.remove-btn {
    padding: 0.35rem 0.5rem;
    font-size: 0.75rem;
    min-height: 36px;
    min-width: 36px;
}

.mobile-nav {
    display: none;
}

.btn-secondary {
    padding: 0.45rem 0.65rem;
    min-height: 40px;
}

.info-panel {
    display: flex;
    flex-direction: column;
}

.info-panel-header {
    padding: 0.5rem 0.75rem;
}

.info-tabs {
    display: flex;
    gap: 0.25rem;
    width: 100%;
}

.tab-btn {
    flex: 1;
    padding: 0.55rem 0.5rem;
    min-height: 44px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface-2);
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.8rem;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.tab-btn:hover {
    color: var(--text);
    background: var(--border);
}

.tab-btn.active {
    color: var(--text);
    border-color: var(--accent);
    background: rgba(77, 163, 255, 0.12);
}

.tab-panel {
    display: none;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.tab-panel.active {
    display: flex;
}

.tab-toolbar {
    display: flex;
    justify-content: flex-end;
    padding: 0.5rem 1rem 0;
}

.reaction-log {
    padding: 0.5rem 1rem 1rem;
    overflow-y: auto;
    flex: 1;
    max-height: none;
}

.recipe-search-bar {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
}

#recipe-search,
#recipe-filter {
    width: 100%;
    padding: 0.5rem 0.65rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface-2);
    color: var(--text);
    font-size: 0.85rem;
}

.recipe-list {
    list-style: none;
    margin: 0;
    padding: 0.5rem;
    overflow-y: auto;
    flex: 1;
    max-height: 220px;
    border-bottom: 1px solid var(--border);
}

.recipe-btn {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.15rem;
    padding: 0.5rem 0.6rem;
    border: 1px solid transparent;
    border-radius: 6px;
    background: transparent;
    color: var(--text);
    cursor: pointer;
    text-align: left;
    font-size: 0.82rem;
    transition: background 0.15s, border-color 0.15s;
}

.recipe-btn:hover,
.recipe-btn.selected {
    background: var(--surface-2);
    border-color: var(--border);
}

.recipe-btn.selected {
    border-color: var(--accent);
}

.recipe-btn-title {
    font-weight: 600;
}

.recipe-btn-meta {
    color: var(--text-muted);
    font-size: 0.75rem;
}

.recipe-detail {
    padding: 0.75rem 1rem 1rem;
    overflow-y: auto;
    flex: 1;
    font-size: 0.82rem;
}

.recipe-detail h3 {
    margin: 0 0 0.5rem;
    font-size: 0.95rem;
}

.recipe-detail h4 {
    margin: 0.75rem 0 0.35rem;
    font-size: 0.78rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.recipe-ingredient-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.recipe-ingredient-list li {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.25rem 0;
}

.recipe-ingredient-list button {
    border: none;
    background: none;
    color: var(--accent);
    cursor: pointer;
    padding: 0;
    font-size: inherit;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.recipe-ingredient-list button:hover {
    color: var(--accent-hover);
}

.recipe-temp {
    margin-top: 0.5rem;
    padding: 0.4rem 0.55rem;
    border-radius: 6px;
    background: var(--surface-2);
    font-size: 0.78rem;
}

.recipe-temp.warning {
    color: var(--warning);
}

.reagent-btn.highlighted {
    border-color: var(--warning);
    background: rgba(240, 180, 41, 0.1);
}

.reagent-info {
    padding: 1rem;
    overflow-y: auto;
    flex: 1;
}

.log-entry {
    padding: 0.4rem 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    font-size: 0.82rem;
    line-height: 1.35;
}

.log-dispense {
    color: var(--accent);
}

.log-reaction {
    color: var(--success);
}

.log-explosion {
    color: #ff8c42;
    font-weight: 700;
}

.log-error {
    color: var(--danger);
}

.log-info {
    color: var(--text-muted);
}

.info-card .info-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.info-card .info-desc {
    margin: 0 0 0.75rem;
    font-size: 0.85rem;
    color: var(--text-muted);
    line-height: 1.4;
}

.recipe-link-btn {
    margin-bottom: 0.75rem;
    padding: 0.35rem 0.6rem;
    width: 100%;
}

.info-card dl {
    margin: 0;
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 0.35rem 0.75rem;
    font-size: 0.82rem;
}

.info-card dt {
    color: var(--text-muted);
}

.info-card dd {
    margin: 0;
    word-break: break-word;
}

.empty-state {
    color: var(--text-muted);
    font-size: 0.85rem;
    font-style: italic;
    padding: 0.5rem 0;
}

@media (max-width: 1200px) {
    .chem-workbench {
        grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
    }

    .machine-guide {
        grid-column: 1 / -1;
        max-height: 320px;
    }
}

@media (max-width: 1100px) {
    .app {
        padding: 0.75rem;
        padding-bottom: calc(5.5rem + env(safe-area-inset-bottom, 0px));
        min-height: 100dvh;
    }

    .chem-workbench {
        grid-template-columns: 1fr;
    }

    .machine-guide {
        max-height: none;
    }

    .chem-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
        max-height: calc(100dvh - 18rem);
        min-height: 240px;
    }

    .mobile-nav {
        display: flex;
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 100;
        gap: 0.35rem;
        padding: 0.5rem 0.75rem calc(0.5rem + env(safe-area-inset-bottom, 0px));
        background: rgba(15, 20, 25, 0.92);
        border-top: 1px solid var(--border);
        backdrop-filter: blur(10px);
    }

    .mobile-nav-btn {
        flex: 1;
        min-height: 48px;
        border: 1px solid var(--border);
        border-radius: 8px;
        background: var(--surface);
        color: var(--text-muted);
        font-size: 0.85rem;
        font-weight: 600;
        cursor: pointer;
    }

    .mobile-nav-btn.active {
        color: var(--text);
        border-color: var(--accent);
        background: rgba(77, 163, 255, 0.15);
    }

    .panel[data-panel-id] {
        display: none;
        min-height: calc(100dvh - 8rem);
        max-height: none;
    }

    .panel[data-panel-id].mobile-active {
        display: flex;
    }

    .beaker-stage {
        flex-direction: column;
    }

    .recipe-list {
        max-height: 200px;
    }

    .reaction-log {
        max-height: 220px;
    }

    .saved-mixtures-list {
        max-height: 180px;
    }

    .contents-list {
        max-height: 200px;
    }

    .reagent-list {
        max-height: calc(100dvh - 16rem);
    }

    .info-panel {
        min-height: calc(100dvh - 8rem);
    }

    .tab-panel {
        min-height: 280px;
    }
}

@media (min-width: 1101px) {
    .panel[data-panel-id] {
        display: flex;
    }

    .machine-guide {
        display: flex;
    }
}

@media (prefers-reduced-motion: reduce) {
    .beaker-liquid,
    .slot-liquid,
    .preset-btn,
    .btn-secondary,
    .reagent-btn,
    .tab-btn,
    .recipe-btn {
        transition: none;
    }

    .mix-vessel.is-mixing .beaker-liquid-swirl,
    .mix-vessel.is-mixing .beaker-liquid-bubbles,
    .mix-vessel.reaction-pulse .beaker-reaction-flash,
    .mix-chip.is-new,
    .content-item.is-new,
    .mix-result-banner.is-visible,
    .chem-workbench.screen-shake,
    .mix-vessel.is-exploding,
    .mix-vessel.is-exploding .beaker-liquid,
    .mix-vessel.is-exploding .slot-liquid,
    .mix-vessel.is-exploding .beaker-reaction-flash,
    .mix-vessel.is-exploding .explosion-smoke,
    .explosion-spark {
        animation: none;
    }
}

/* Regular footer at the very bottom (standard credits / copyright style) */
.app-footer {
    margin-top: 2rem;
    padding: 1rem 1rem 0.5rem;
    border-top: 1px solid var(--border);
    text-align: center;
    font-size: 0.8rem;
    opacity: 0.8;
    line-height: 1.4;
    color: var(--text-muted);
}

.app-footer small {
    font-size: inherit;
}

.app-footer a {
    color: var(--accent, #4a9eff);
    text-decoration: underline;
    text-underline-offset: 2px;
}

.app-footer a:hover {
    text-decoration: none;
}

/* Local update button (only shown for local IPs) */
.local-update-btn {
    font-size: 1rem;
    line-height: 1;
    padding: 0.15rem 0.4rem;
    margin-left: 0.25rem;
    border: 1px solid color-mix(in srgb, var(--border) 70%, transparent);
    background: color-mix(in srgb, var(--bg) 70%, transparent);
    cursor: pointer;
}

.local-update-btn:hover {
    background: var(--accent, #4a9eff);
    color: white;
    border-color: var(--accent, #4a9eff);
}

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

/* Update result banner (shown after clicking the local update button) */
.update-banner {
    margin: 0.5rem 1rem;
    padding: 0.6rem 0.9rem;
    border-radius: 6px;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
    border: 1px solid var(--border);
}

.update-banner.success {
    background: color-mix(in srgb, #22c55e 12%, var(--bg));
    border-color: #22c55e;
}

.update-banner.error {
    background: color-mix(in srgb, #ef4444 12%, var(--bg));
    border-color: #ef4444;
}

.update-banner details {
    flex: 1 1 auto;
    min-width: 180px;
}

.update-banner summary {
    cursor: pointer;
    user-select: none;
    font-weight: 500;
}

.update-banner pre.update-log {
    margin: 0.4rem 0 0;
    padding: 0.5rem;
    background: rgba(0,0,0,0.25);
    border-radius: 4px;
    font-size: 0.75rem;
    white-space: pre-wrap;
    max-height: 220px;
    overflow: auto;
}

.update-reload-btn {
    margin-left: auto;
    font-size: 0.8rem;
    padding: 0.2rem 0.6rem;
}

/* ============================================
   LOCAL UPDATE PROGRESS / STATUS — prominent centered overlay
   Covers most of the page, blurs background, message dead center,
   larger + easier to read, stays visible longer.
   ============================================ */
.update-progress {
    position: fixed;
    inset: 0;
    z-index: 99999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    background: rgba(0, 0, 0, 0.58);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
}

.update-progress[hidden] {
    display: none !important;
}

/* The actual readable card in the middle */
.update-progress .update-modal-card {
    width: 100%;
    max-width: 540px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 1.8rem 2rem;
    box-shadow: 0 25px 80px rgba(0, 0, 0, 0.45);
    display: flex;
    flex-direction: column;
    gap: 1rem;
    font-size: 1rem;
    line-height: 1.45;
}

.update-progress .progress-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-weight: 700;
    font-size: 1.25rem;
}

.update-progress .progress-spinner {
    width: 26px;
    height: 26px;
    border: 4px solid color-mix(in srgb, var(--border) 65%, transparent);
    border-top-color: #4a9eff;
    border-radius: 50%;
    animation: update-spin 0.85s linear infinite;
    flex-shrink: 0;
}

@keyframes update-spin {
    to { transform: rotate(360deg); }
}

.update-progress .progress-body {
    font-size: 1.02rem;
    line-height: 1.5;
    opacity: 0.96;
}

.update-progress .progress-body strong {
    font-weight: 600;
}

.update-progress .progress-log {
    margin: 0.4rem 0 0;
    padding: 0.75rem 0.85rem;
    background: rgba(0, 0, 0, 0.22);
    border-radius: 8px;
    font-family: ui-monospace, monospace;
    font-size: 0.85rem;
    white-space: pre-wrap;
    max-height: 220px;
    overflow: auto;
    border: 1px solid rgba(255,255,255,0.1);
    line-height: 1.35;
}

/* Success state */
.update-progress.is-success .update-modal-card {
    border-color: #22c55e;
    box-shadow: 0 25px 80px rgba(0, 0, 0, 0.35);
}

.update-progress.is-success .progress-header {
    color: #166534;
}

[data-theme="dark"] .update-progress.is-success .progress-header {
    color: #4ade80;
}

.update-progress.is-success .progress-icon {
    color: #22c55e;
    font-size: 1.35rem;
}

/* Error state */
.update-progress.is-error .update-modal-card {
    border-color: #ef4444;
    box-shadow: 0 25px 80px rgba(0, 0, 0, 0.35);
}

.update-progress.is-error .progress-header {
    color: #991b1b;
}

[data-theme="dark"] .update-progress.is-error .progress-header {
    color: #f87171;
}

.update-progress.is-error .progress-icon {
    color: #ef4444;
    font-size: 1.35rem;
}

.update-progress .progress-actions {
    display: flex;
    gap: 0.6rem;
    margin-top: 0.25rem;
    flex-wrap: wrap;
}

.update-progress .progress-actions button {
    font-size: 0.95rem;
    padding: 0.5rem 1rem;
    font-weight: 500;
}

/* Make the main "reload now" button more eye-catching inside the success overlay */
.update-progress.is-success .progress-actions button#update-reload-now {
    background: #22c55e;
    color: #0f2a1f;
    border-color: #22c55e;
    font-weight: 600;
}

[data-theme="dark"] .update-progress.is-success .progress-actions button#update-reload-now {
    background: #4ade80;
    color: #0a1f14;
}