/* ========================================
   Aniimax - Minimalist Production Optimizer
   ======================================== */

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

:root {
    --bg: #0e1013;
    --bg-lighter: #1e2229;
    --surface: #16191e;
    --surface-2: #1e2229;
    --text: #e9eaec;
    --text-muted: #9aa0a8;
    --muted: var(--text-muted);
    --border: #2a2f37;
    --border-control: #626b7a;
    --accent: #6cc5a4;
    --on-accent: #0e1013;
    --success: #6cc5a4;
    --error: #ef6b68;
    --warning: #f0b35a;
    --radius: 12px;
    --font-body: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --font-mono: "Courier New", Courier, monospace;
}

:root.light,
.light {
    --bg: #f5f4ef;
    --bg-lighter: #f0eee8;
    --surface: #ffffff;
    --surface-2: #f0eee8;
    --text: #1d1f22;
    --text-muted: #5a5e64;
    --muted: var(--text-muted);
    --border: #d9d5cc;
    --border-control: #7d8189;
    --accent: #1f6b54;
    --on-accent: #ffffff;
    --success: #1f6b54;
    --error: #c62828;
    --warning: #8f4d00;
}

body {
    accent-color: var(--accent);
    font-family: var(--font-body);
    background-color: var(--bg);
    color: var(--text);
    line-height: 1.55;
    max-width: 880px;
    margin: 2.5rem auto;
    padding: 0 1rem;
    transition: background-color 0.3s, color 0.3s;
    font-variant-numeric: tabular-nums;
}

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

a:hover {
    color: inherit;
}

/* Header */
header {
    margin-bottom: 2rem;
    display: flex;
    justify-content: space-between;
    align-items: baseline;
}

header h1 {
    font-family: var(--font-mono);
    font-size: 2rem;
    font-weight: normal;
    letter-spacing: -0.02em;
}

.header-buttons {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    min-width: 0;
    max-width: 100%;
    gap: 1rem;
}

.toggle-button {
    cursor: pointer;
    background: none;
    border: none;
    color: inherit;
    font-family: inherit;
    font-size: 0.9rem;
    line-height: normal;
    text-decoration: underline;
}

.toggle-button:hover {
    opacity: 0.7;
}

#language-switch option {
    background: var(--surface);
    color: var(--text);
}

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

.disclaimer {
    color: var(--text-muted);
    font-size: 0.8rem;
    font-style: italic;
    margin-bottom: 2rem;
    padding: 0.75rem;
    border: 1px solid var(--border);
    background: transparent;
}

/* Typography */
h2 {
    font-size: 1.2rem;
    font-weight: normal;
    margin-top: 2rem;
    margin-bottom: 1rem;
    border-bottom: 1px solid var(--border);
    padding-bottom: 0.5rem;
}

h3 {
    font-size: 1rem;
    font-weight: normal;
    margin-bottom: 0.75rem;
}

h4 {
    font-size: 0.9rem;
    font-weight: bold;
    margin-bottom: 0.5rem;
}

p {
    font-size: 0.9rem;
    margin-bottom: 1rem;
}

.hint {
    color: var(--text-muted);
    font-size: 0.8rem;
    margin-bottom: 1rem;
}

.hint.small {
    font-size: 0.75rem;
    margin-top: 0.25rem;
}

/* Sections */
.config-section,
.results-section {
    margin-bottom: 2rem;
}

/* Input Fields */
.config-group {
    margin-bottom: 1.5rem;
}

.input-row {
    display: flex;
    gap: 1.5rem;
    margin-bottom: 1rem;
}

.input-field {
    flex: 1;
}

.input-field label {
    display: block;
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 0.25rem;
}

.input-field input,
.input-field select {
    width: 100%;
    padding: 0.5rem;
    background: var(--bg);
    border: 1px solid var(--border-control);
    color: var(--text);
    font-family: inherit;
    font-size: 0.9rem;
    transition: border-color 0.2s;
}

.input-field input:focus,
.input-field select:focus {
    border-color: var(--accent);
}

.input-field input[type="number"] {
    appearance: textfield;
    -moz-appearance: textfield;
}

.input-field input[type="number"]::-webkit-outer-spin-button,
.input-field input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.input-field select {
    cursor: pointer;
}

/* Checkbox Field */
.checkbox-field {
    display: flex;
    align-items: center;
}

.checkbox-field label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    font-size: 0.9rem;
}

.checkbox-field input[type="checkbox"] {
    width: 1rem;
    height: 1rem;
    cursor: pointer;
}

/* Radio Group (currency selector) */
.radio-group {
    display: flex;
    gap: 1.5rem;
}

.radio-group label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    font-size: 0.9rem;
}

.radio-group input[type="radio"] {
    width: 1rem;
    height: 1rem;
    cursor: pointer;
}

/* Facilities Grid */
.facilities-container {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

.facility-category-title {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 0.75rem;
    padding-bottom: 0.35rem;
    border-bottom: 1px solid var(--border);
}

.facilities-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
}

.facility-card {
    border: 1px solid var(--border);
    padding: 1rem;
}

.facility-card h4 {
    font-size: 0.85rem;
    margin-bottom: 0.75rem;
}

/* Info icon button (uses accessible tip-card on hover, focus, and tap) */
.info-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.35rem;
    height: 1.35rem;
    padding: 0;
    background: transparent;
    font-family: inherit;
    font-size: 0.72rem;
    font-weight: 700;
    border: 1px solid var(--border-control);
    border-radius: 50%;
    color: var(--text-muted);
    cursor: pointer;
    margin-left: 0.3rem;
    vertical-align: middle;
    position: relative;
}

.info-icon:hover,
.info-icon:focus-visible {
    border-color: var(--accent);
    color: var(--text);
}

[data-tooltip] {
    position: relative;
}

[data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: var(--text);
    color: var(--bg);
    padding: 0.5rem 0.75rem;
    font-size: 0.75rem;
    font-weight: normal;
    white-space: pre-line;
    border: 1px solid var(--border);
    z-index: 100;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s, visibility 0.2s;
    pointer-events: none;
    margin-bottom: 0.5rem;
    min-width: 180px;
    max-width: 280px;
    text-align: left;
    line-height: 1.4;
}

[data-tooltip]:hover::after {
    opacity: 1;
    visibility: visible;
}

.facility-tiers {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.facility-inputs {
    display: flex;
    align-items: flex-end;
    gap: 0.75rem;
}

.facility-inputs .input-field {
    flex: 1;
}

.facility-inputs .input-field label {
    font-size: 0.7rem;
}

.facility-inputs input {
    padding: 0.4rem;
    font-size: 0.85rem;
}

/* Simple / advanced input mode switch. */
.mode-switch {
    display: flex;
    gap: 1.5rem;
    margin: 1rem 0;
}

.mode-switch label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
}

/* One owned tier's remove button, sitting inline at the end of its Count/Level row. */
.tier-remove-btn {
    cursor: pointer;
    background: none;
    border: 1px solid var(--border);
    color: var(--text-muted);
    font-family: inherit;
    font-size: 0.9rem;
    line-height: 1;
    padding: 0.4rem 0.6rem;
}

.tier-remove-btn:hover {
    color: var(--text);
    border-color: var(--text);
}

/* Adds one more owned tier (e.g. "+ Add level") below a facility's tier rows. */
.add-tier-btn {
    cursor: pointer;
    background: none;
    border: none;
    color: inherit;
    font-family: inherit;
    font-size: 0.75rem;
    text-decoration: underline;
    padding: 0;
    margin-top: 0.5rem;
    align-self: flex-start;
}

.add-tier-btn:hover {
    opacity: 0.7;
}

/* Modules Grid */
.modules-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.module-card {
    border: 1px solid var(--border);
    padding: 1rem;
}

.module-card h4 {
    font-size: 0.85rem;
    margin-bottom: 0.5rem;
}

.module-card .input-field {
    max-width: 100px;
}

.module-card .input-field label {
    font-size: 0.7rem;
}

.module-card input {
    padding: 0.4rem;
    font-size: 0.85rem;
}

/* Optimize Button */
.optimize-btn {
    width: 100%;
    padding: 0.75rem 1.5rem;
    background: var(--text);
    color: var(--bg);
    border: 1px solid var(--text);
    font-family: inherit;
    font-size: 0.9rem;
    cursor: pointer;
    transition: opacity 0.2s;
}

.optimize-btn:hover {
    opacity: 0.8;
}

.optimize-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Progress bar shown while find_plan runs in the worker (see worker.js); fill width is driven by
   the solver's own real trial-solve count (see `trialCountToPercent` in app.js), not a decorative
   animation, so it actually reflects work happening. */
.progress-bar-container {
    width: 100%;
    height: 4px;
    margin-top: 0.6rem;
    background: var(--border);
    border-radius: 2px;
    overflow: hidden;
}

.progress-bar-fill {
    width: 0%;
    height: 100%;
    background: var(--text);
    border-radius: 2px;
    transition: width 0.15s ease-out;
}

/* Error Message */
.error-message {
    border: 1px solid var(--error);
    color: var(--error);
    padding: 1rem;
    margin-bottom: 1rem;
    font-size: 0.9rem;
}

/* Results Summary */
.result-summary {
    margin-bottom: 1.5rem;
}

.summary-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
}

.summary-item {
    border: 1px solid var(--border);
    padding: 1rem;
    text-align: center;
}

.summary-label {
    display: block;
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-bottom: 0.25rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.summary-value {
    display: block;
    font-size: 1.1rem;
    font-weight: bold;
    color: var(--success);
}

.rate-unit-select {
    margin-top: 0.5rem;
    padding: 0.2rem 0.4rem;
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text-muted);
    font-family: inherit;
    font-size: 0.75rem;
    cursor: pointer;
}

.rate-unit-select:focus {
    border-color: var(--accent);
}

/* Byproduct bonus rows, appended to the bottom of the Product Breakdown table */
#product-breakdown-table tbody tr.byproduct-row {
    color: var(--warning);
    font-style: italic;
}

#product-breakdown-table tbody tr.byproduct-row td {
    border-top: 1px dashed var(--warning);
}

/* Production Steps */
.production-steps {
    margin-bottom: 1.5rem;
}

.steps-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.energy-info {
    border: 1px solid var(--success);
    padding: 1rem;
    margin-bottom: 1rem;
    color: var(--success);
    font-size: 0.85rem;
}

.energy-info strong {
    display: block;
    margin-bottom: 0.25rem;
}

.parallel-info {
    border: 1px solid #9f7aea;
    padding: 1rem;
    margin-bottom: 1rem;
    color: #9f7aea;
    font-size: 0.85rem;
}

.parallel-info strong {
    display: block;
    margin-bottom: 0.25rem;
}

.step-item {
    border: 1px solid var(--border);
    padding: 0.75rem 1rem;
    display: flex;
    align-items: center;
    gap: 1rem;
}

.step-number {
    width: 1.75rem;
    height: 1.75rem;
    border: 1px solid var(--text);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    flex-shrink: 0;
}

.step-number.energy-step {
    border-color: var(--warning);
    color: var(--warning);
}

.step-number.profit-step {
    border-color: var(--success);
    color: var(--success);
}

.step-number.parallel-step {
    border-color: #9f7aea;
    color: #9f7aea;
    font-weight: bold;
}

/* Chain Groups for Parallel Mode */
.chain-group {
    border: 1px solid var(--border);
    margin-bottom: 0.5rem;
    background: var(--bg-lighter);
}

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

.chain-title {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.chain-number {
    background: linear-gradient(135deg, #9f7aea 0%, #805ad5 100%);
    color: white;
    padding: 0.25rem 0.6rem;
    font-size: 0.75rem;
    font-weight: 600;
}

.chain-path {
    font-size: 0.85rem;
    color: var(--text-muted);
    font-family: var(--font-mono);
}

.chain-meta {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.chain-step {
    border: none;
    border-bottom: 1px solid var(--border);
    background: var(--bg-lighter);
}

.chain-step:last-child {
    border-bottom: none;
}

.step-indicator {
    width: 1.5rem;
    color: #9f7aea;
    font-weight: bold;
    flex-shrink: 0;
    text-align: center;
}

.step-details {
    flex: 1;
}

.step-name {
    font-size: 0.9rem;
}

.step-facility {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.step-allocation {
    font-size: 0.75rem;
    color: #9f7aea;
    margin-top: 0.25rem;
    font-style: italic;
}

.step-meta {
    text-align: right;
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* Options Table */
.all-options {
    margin-bottom: 1rem;
}

.table-wrapper {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

th,
td {
    padding: 0.5rem 0.75rem;
    text-align: left;
    border: 1px solid var(--border);
}

th {
    background: var(--bg);
    font-weight: bold;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

tbody tr:first-child {
    background: transparent;
}

tbody tr:first-child td {
    color: var(--success);
    font-weight: bold;
}

/* Facility plan tables (one per category, see renderFacilityPlan in app.js): status reflects
   role (producing/idle/not needed), not row position, overriding the generic "highlight first
   row" rule above so it doesn't imply the first facility listed is special. */
.facility-plan-table tbody tr:first-child td {
    color: inherit;
    font-weight: normal;
}

.facility-plan-table tbody tr.status-not_needed td,
.facility-plan-table tbody tr.status-nothing_available td,
.facility-plan-table tbody tr.status-idle td {
    color: var(--text-muted);
}

/* Environment building layout diagram (see renderEnvironmentDiagram in app.js): a simple SVG
   showing the solver's own chosen facility placements around one building instance, next to that
   instance's table. */
.env-unit {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: flex-start;
    margin-bottom: 1rem;
}

.env-diagram {
    flex: 0 0 auto;
    color: var(--text-muted);
}

.env-diagram svg {
    display: block;
    width: 280px;
    max-width: 100%;
    height: auto;
    aspect-ratio: 1;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 10px;
}

/* Whole-tile lines, a heavier major line every other tile, and faint quarter-tile lines. */
.env-grid line {
    stroke: currentColor;
    stroke-opacity: 0.2;
    stroke-width: 0.035;
}

.env-grid line.major {
    stroke-opacity: 0.38;
    stroke-width: 0.08;
}

.env-grid line.quarter {
    stroke-opacity: 0.05;
    stroke-width: 0.02;
}

.env-plot text {
    fill: #111;
    font-family: var(--font-body);
    font-weight: 700;
    text-anchor: middle;
    dominant-baseline: central;
    pointer-events: none;
}

.env-plot:hover rect,
.layout-piece:hover > rect {
    fill-opacity: 1;
    stroke: currentColor;
}

.env-building:hover > rect {
    stroke-opacity: 1;
}

.env-legend {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    margin-top: 0.5rem;
    max-width: 280px;
    font-size: 0.7rem;
    color: var(--text-muted);
}

.env-legend-item {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
}

.env-legend-swatch {
    display: inline-block;
    width: 0.7rem;
    height: 0.7rem;
    border-radius: 3px;
}

.env-legend-swatch.coverage {
    border: 1px dashed;
}

/* Recipe reference tables (facility recipe modal): one table per facility, listed row order
   reflects level/name sort, not importance, same override as the facility-plan table above. */
.recipe-table tbody tr:first-child td {
    color: inherit;
    font-weight: normal;
}

.facility-recipe-table {
    margin-bottom: 1.5rem;
}

.facility-recipe-table h4 {
    font-size: 0.85rem;
    margin-bottom: 0.5rem;
}

/* Footer */
footer {
    text-align: center;
    padding: 2rem 0;
    color: var(--text-muted);
    font-size: 0.8rem;
    border-top: 1px solid var(--border);
    margin-top: 2rem;
}

.footer-note {
    margin-top: 0.35rem;
    font-size: 0.75rem;
}

/* Loading State */
.loading {
    opacity: 0.5;
    pointer-events: none;
}

/* Responsive */
@media (max-width: 600px) {
    body {
        margin: 2rem auto;
        padding: 0 1rem;
    }

    header {
        flex-direction: column;
        gap: 0.5rem;
    }

    header h1 {
        font-size: 1.6rem;
    }

    .toggle-button {
        align-self: flex-end;
    }

    .input-row {
        flex-direction: column;
        gap: 1rem;
    }

    .facilities-grid {
        grid-template-columns: 1fr;
    }

    .modules-grid {
        grid-template-columns: 1fr;
    }

    .summary-grid {
        grid-template-columns: 1fr 1fr;
    }

    .step-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }

    .step-meta {
        text-align: left;
    }

    th,
    td {
        padding: 0.4rem 0.5rem;
        font-size: 0.8rem;
    }
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    z-index: 1000;
    overflow-y: auto;
    padding: 2rem;
}

.modal.show {
    display: flex;
    justify-content: center;
    align-items: flex-start;
}

.modal-content {
    background-color: var(--bg);
    border: 1px solid var(--border);
    max-width: 600px;
    width: 100%;
    margin: 2rem auto;
}

.modal-content.wide {
    max-width: 1100px;
}

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

.modal-header h2 {
    margin: 0;
    border: none;
    padding: 0;
}

.close-button {
    background: none;
    border: none;
    color: var(--text);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0;
    line-height: 1;
}

.close-button:hover {
    opacity: 0.7;
}

.modal-body {
    padding: 1.5rem;
}

.modal-body h3 {
    margin-top: 1.5rem;
    margin-bottom: 0.5rem;
}

.modal-body h3:first-child {
    margin-top: 0;
}

.modal-body p {
    margin-bottom: 0.75rem;
    color: var(--text-muted);
}

.modal-body ul {
    margin-bottom: 1rem;
    padding-left: 1.5rem;
}

.modal-body li {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

.modal-body li strong {
    color: var(--text);
}

.modal-wide {
    max-width: 750px;
}

.math-block {
    background: rgba(128, 128, 128, 0.1);
    padding: 1rem;
    margin: 1rem 0;
    overflow-x: auto;
    border-left: 2px solid var(--border);
}

.modal-body h4 {
    font-size: 0.9rem;
    font-weight: bold;
    margin-top: 1.25rem;
    margin-bottom: 0.5rem;
    color: var(--text);
}

.modal-body ol {
    margin-bottom: 1rem;
    padding-left: 1.5rem;
}

.modal-body ol li {
    margin-bottom: 0.75rem;
}

.modal-body ol li ul {
    margin-top: 0.5rem;
    margin-bottom: 0;
}

.math-table {
    width: 100%;
    border-collapse: collapse;
    margin: 1rem 0;
    font-size: 0.85rem;
}

.math-table th,
.math-table td {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    text-align: left;
}

.math-table th {
    background: rgba(128, 128, 128, 0.1);
    font-weight: bold;
}

/* ========================================
   Cards, tabs and badges
   ======================================== */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem 1.5rem 1.5rem;
    margin-bottom: 1.25rem;
}

.card h2 {
    margin: 0 0 0.75rem;
    padding: 0;
    border: none;
    font-size: 1.1rem;
    font-weight: 600;
}

.card h3 {
    font-weight: 600;
    margin-top: 1.25rem;
}

.card-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 0.75rem;
}

.card-head h2 {
    margin: 0;
}

.card-lead {
    color: var(--text-muted);
    margin-bottom: 1.25rem;
}

.toggle-button.small {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.config-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.share-config-result {
    margin-bottom: 0.5rem;
}

.share-config-result[hidden] {
    display: none;
}

.share-config-result label {
    display: block;
    margin-bottom: 0.25rem;
    font-size: 0.85rem;
}

.share-config-result input {
    box-sizing: border-box;
    width: 100%;
    padding: 0.5rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
}

#share-config-status:empty {
    display: none;
}

.subtitle {
    margin-top: -1.5rem;
}

.disclaimer {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    font-style: normal;
    color: var(--warning);
    border-color: color-mix(in srgb, var(--warning) 45%, transparent);
    border-radius: var(--radius);
    background: color-mix(in srgb, var(--warning) 9%, var(--surface));
    margin-bottom: 1.5rem;
}

.disclaimer-icon {
    font-size: 0.95rem;
    line-height: 1.2;
}

/* Segmented tabs built from radio labels. */
.tabs {
    display: inline-flex;
    gap: 2px;
    padding: 3px;
    margin-bottom: 1.25rem;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 10px;
}

.tabs label {
    position: relative;
    padding: 0.4rem 1.1rem;
    border-radius: 7px;
    color: var(--text-muted);
    font-size: 0.9rem;
    cursor: pointer;
    user-select: none;
    transition: background-color 0.15s, color 0.15s;
}

.tabs label:hover {
    color: var(--text);
}

.tabs input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.tabs label:has(input:checked) {
    background: var(--surface);
    color: var(--text);
    font-weight: 600;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
}

.tabs label:has(input:focus-visible) {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

.tabs.compact {
    margin-bottom: 0;
}

.tabs.compact label {
    padding: 0.3rem 0.85rem;
    font-size: 0.85rem;
}

/* Inputs */
.input-field input,
.input-field select {
    background: var(--surface-2);
    border-radius: 8px;
    padding: 0.55rem 0.7rem;
}

.input-field input:focus,
.input-field select:focus {
    border-color: var(--accent);
}

#simple-config .input-field {
    max-width: 16rem;
}

/* Simple mode: what the RV level assumes, as a grid of chips. */
.assume-title {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin: 1rem 0 0.5rem;
}

.chip-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
    gap: 0.4rem;
}

.chip {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 0.5rem;
    padding: 0.4rem 0.65rem;
    background: var(--surface-2);
    border-radius: 8px;
    font-size: 0.82rem;
}

.chip-count {
    font-weight: 600;
}

.chip-level {
    color: var(--text-muted);
    font-size: 0.75rem;
    white-space: nowrap;
}

/* Options and the main button */
.option-row {
    gap: 0.4rem;
    margin: 1.5rem 0 1rem;
    padding-top: 1.25rem;
    border-top: 1px solid var(--border);
}

.optimize-btn {
    background: var(--accent);
    color: var(--on-accent);
    border: none;
    border-radius: 10px;
    padding: 0.8rem 1.5rem;
    font-size: 1rem;
    font-weight: 600;
}

.progress-bar-container {
    position: relative;
}

/* The exact planner doesn't report progress, so the bar just shows it's working. */
.progress-bar-fill.indeterminate {
    position: absolute;
    width: 35%;
    background: var(--accent);
    animation: progress-slide 1.1s ease-in-out infinite;
}

@keyframes progress-slide {
    from { left: -35%; }
    to { left: 100%; }
}

/* Results share one rate unit across the summary, planting and priorities. */
.plan-results-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem 1rem;
    margin-bottom: 0.8rem;
}
.plan-results-header h2 { margin: 0; }
.plan-rate-picker {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    color: var(--text-muted);
    font-size: 0.8rem;
}
.plan-rate-picker .rate-unit-select {
    margin: 0;
    min-height: 2.75rem;
    border-radius: 0.5rem;
    background: var(--surface-2);
}
.plan-result-metrics {
    display: flex;
    flex-wrap: wrap;
    gap: 0.7rem 1rem;
    padding-block: 0.7rem;
    margin-bottom: 1rem;
    border-block: 1px solid var(--border);
}
.plan-result-metric {
    display: grid;
    align-content: start;
    gap: 0.1rem;
    flex: 1 1 10rem;
    min-width: 0;
    overflow-wrap: anywhere;
}
.plan-result-metric strong { font-size: 1.3rem; font-variant-numeric: tabular-nums; }
.plan-result-label { color: var(--text-muted); font-size: 0.78rem; }
#plan-rate { color: var(--accent); }
.plan-rate-gap { font-variant-numeric: tabular-nums; }
.plan-rate-gap.gap-optimal { color: var(--accent); }
.plan-rate-gap.gap-tight { color: var(--text-muted); }
.plan-rate-gap.gap-warn { color: var(--warning); font-weight: 500; }
.plan-results-columns {
    display: grid;
    grid-template-columns: minmax(0, 1.16fr) minmax(0, 1fr);
    gap: 1.2rem;
}
.plan-results-columns:has(#seed-card[hidden]) { grid-template-columns: minmax(0, 1fr); }
.plan-results-columns > section { min-width: 0; }
.plan-results-columns h3 { margin: 0 0 0.4rem; font-size: 1rem; }
.plan-upgrade-details { margin-top: 1rem; padding-top: 0.7rem; border-top: 1px solid var(--border); }
.plan-upgrade-details > summary { min-height: 2rem; align-content: center; }
.plan-upgrade-details > summary:focus-visible { outline-offset: 0.2rem; }
.rate-table td:first-child { width: 2rem; color: var(--text-muted); }
.rate-table th:last-child, .rate-table td:last-child { text-align: end; }
.priority-rate-note { display: block; font-size: 0.75rem; color: var(--text-muted); }
@media (max-width: 46rem) {
    .plan-results-columns { grid-template-columns: minmax(0, 1fr); }
    .plan-results-columns > section + section { padding-top: 0.65rem; border-top: 1px solid var(--border); }
    .plan-results-columns:has(#seed-card[hidden]) #rate-block { border-top: 0; padding-top: 0; }
}
@media (max-width: 26rem) {
    .plan-result-metric { flex-basis: 7rem; }
}

.plan-proof {
    margin: 0.75rem 0 0;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.plan-unverified {
    margin: 0.6rem 0 0;
    font-size: 0.8rem;
    color: var(--warning);
}

.tag {
    display: inline-block;
    margin-left: 0.4rem;
    padding: 0 0.45rem;
    border-radius: 999px;
    font-size: 0.68rem;
    font-weight: 600;
    white-space: nowrap;
    vertical-align: 1px;
}

.tag.unverified {
    border: 1px solid var(--warning);
    color: var(--warning);
}

/* Collapsible explanations */
details.explain {
    margin-bottom: 1rem;
    font-size: 0.82rem;
    color: var(--text-muted);
}

details.explain summary {
    cursor: pointer;
    width: fit-content;
    user-select: none;
}

details.explain summary:hover {
    color: var(--text);
}

details.explain p {
    margin: 0.5rem 0 0;
    font-size: 0.82rem;
}

/* Tables */
.card table {
    font-size: 0.85rem;
}

.card th,
.card td {
    border: none;
    border-bottom: 1px solid var(--border);
    padding: 0.55rem 0.6rem;
}

.card th {
    background: transparent;
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.7rem;
}

.card tbody tr:last-child td {
    border-bottom: none;
}

.card tbody tr:first-child td {
    color: inherit;
    font-weight: normal;
}

.facility-category-title {
    font-weight: 600;
    border-bottom: none;
    padding-bottom: 0;
}

.facility-card,
.module-card {
    background: var(--surface-2);
    border: none;
    border-radius: 10px;
}

.summary-item {
    border-radius: 10px;
    background: var(--surface-2);
    border: none;
}

#goal-section .summary-value {
    color: var(--text);
}

.error-message {
    border-color: var(--error);
}

/* Inputs inside the Advanced tab's facility and module cards. */
.facility-card .input-field input,
.module-card .input-field input {
    background: var(--surface);
}

@media (max-width: 600px) {
    .card {
        padding: 1rem;
    }

    /* Plan tables become one labelled block per row on narrow screens. */
    .facility-plan-table thead {
        display: none;
    }

    .facility-plan-table tr {
        display: block;
        padding: 0.6rem 0;
        border-bottom: 1px solid var(--border);
    }

    .facility-plan-table tbody tr:last-child {
        border-bottom: none;
    }

    .card .facility-plan-table td {
        display: flex;
        justify-content: space-between;
        gap: 1rem;
        padding: 0.15rem 0;
        border: none;
        text-align: right;
    }

    .facility-plan-table td::before {
        content: attr(data-label);
        color: var(--text-muted);
        font-size: 0.75rem;
        text-align: left;
        white-space: nowrap;
    }


    .chip-grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    }
}

/* Aniimo team card: collapsed to a one-line summary until opened. */
.collapse-toggle {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    padding: 0;
    background: none;
    border: none;
    color: inherit;
    font: inherit;
    cursor: pointer;
}

.collapse-toggle:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 3px;
    border-radius: 4px;
}

.collapse-toggle .chevron {
    width: 0.5rem;
    height: 0.5rem;
    border-right: 2px solid var(--text-muted);
    border-bottom: 2px solid var(--text-muted);
    transform: rotate(-45deg);
    transition: transform 0.15s;
}

.collapse-toggle[aria-expanded="true"] .chevron {
    transform: rotate(45deg);
}

.collapse-toggle:hover h2 {
    text-decoration: underline;
    text-underline-offset: 3px;
}

.aniimo-card .card-head {
    margin-bottom: 0.35rem;
}

.collapsed-summary {
    margin: 0 0 0 1.05rem;
    font-size: 0.85rem;
    color: var(--text-muted);
}

#aniimo-body {
    margin-top: 1rem;
}

.aniimo-assignment-group {
    margin-top: 0.4rem;
    border: 1px solid var(--border);
    border-radius: 8px;
}

.aniimo-assignment-group > summary,
.aniimo-assignment-group > .aniimo-assignment-group-head {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    padding: 0.45rem 0.65rem;
    border-radius: 7px 7px 0 0;
    border-bottom: 1px solid var(--border);
    background: var(--surface-2);
    font-size: 0.875rem;
    font-weight: 600;
    list-style: none;
}
.aniimo-assignment-group > summary {
    cursor: pointer;
}

.aniimo-assignment-group > summary::-webkit-details-marker { display: none; }
.aniimo-assignment-group > summary:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
}

.aniimo-assignment-group[open] > summary {
    border-bottom: 1px solid var(--border);
    border-radius: 7px 7px 0 0;
}

.aniimo-assignment-count {
    margin-inline-start: auto;
    color: var(--text-muted);
    font-weight: 400;
}

.aniimo-assignment-chevron {
    flex: 0 0 auto;
    width: 0.42rem;
    height: 0.42rem;
    margin-inline: 0.12rem;
    border-right: 2px solid var(--text-muted);
    border-bottom: 2px solid var(--text-muted);
    transform: rotate(-45deg);
}

.aniimo-assignment-group[open] .aniimo-assignment-chevron { transform: translateY(-0.1rem) rotate(45deg); }

.aniimo-assignment-portraits {
    display: flex;
    flex-wrap: wrap;
    gap: 0.15rem 0.24rem;
    padding: 0.18rem 0.45rem;
}

.aniimo-assignment-portraits > .roster-slot {
    flex: 0 1 clamp(2.75rem, 9.5vw, 4.15rem);
}

/* Aniimo abilities in their in-game colors. */
.ability {
    display: inline-block;
    padding: 0.05rem 0.5rem;
    border-radius: 999px;
    background: var(--ability);
    color: #fff;
    font-size: 0.75rem;
    font-weight: 600;
    line-height: 1.5;
    white-space: nowrap;
}

.ability.dark {
    color: #111317;
}

/* How many of each ability a plan needs, like the game's Abilities screen. */
.ability-strip {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(58px, 1fr));
    gap: 1rem 0.35rem;
    margin: 0.85rem 0 0;
}

@media (min-width: 720px) {
    .ability-strip {
        grid-template-columns: repeat(13, minmax(0, 1fr));
        gap: 0.3rem;
    }
}

.ability-cell {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding: 0.4rem 0.2rem 0.35rem;
    border-radius: 8px;
    background: var(--surface-2);
    border-top: 3px solid var(--ability);
}

.ability-count {
    font-size: 1.1rem;
    font-weight: 700;
    line-height: 1.2;
    color: var(--ability-text, var(--ability));
}

:root.light .ability-count,
.light .ability-count {
    color: color-mix(in srgb, var(--ability) 48%, #0e1013);
}

.ability-name {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 0.68rem;
    color: var(--text-muted);
    white-space: nowrap;
}

.ability-cell.zero {
    opacity: 0.62;
    border-top-color: var(--border);
}

.ability-cell.zero .ability-count {
    color: var(--text-muted);
}

/* The facility plan's Aniimo column: one colored circle per ability, level inside. */
.ability-dots {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 0.3rem;
    vertical-align: middle;
}

.ability-dot {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.5rem;
    height: 1.5rem;
    border-radius: 50%;
    background: var(--ability);
    color: #fff;
    font-size: 0.75rem;
    font-weight: 700;
    cursor: help;
}

.ability-dot.dark {
    color: #111317;
}

/* A ring marks an Aniimo that has the facility's personality bonus. */
.ability-dot.bonus {
    box-shadow: 0 0 0 2px var(--surface), 0 0 0 3.5px var(--ability);
}

/* The Aniimo behind each ability count, one circle each. */
/* One column per ability: its box, then its Aniimo circles below it. */
.ability-col {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 0;
}

.ability-col .ability-cell {
    width: 100%;
}

.ability-stack {
    display: grid;
    grid-template-columns: 1fr;
    justify-items: center;
    gap: 0.5rem;
    margin-top: 0.6rem;
}

.ability-kind {
    position: relative;
    display: inline-flex;
}

/* Beside the circle without shifting it, so circles line up in their column. */
.ability-times {
    position: absolute;
    left: 100%;
    top: 50%;
    transform: translateY(-50%);
    margin-left: 0.15rem;
    font-size: 0.65rem;
    font-weight: 600;
    color: var(--text-muted);
    white-space: nowrap;
}

.ability-dot.small {
    width: 1.2rem;
    height: 1.2rem;
    font-size: 0.65rem;
}

.ability-dot.small.bonus {
    box-shadow: 0 0 0 1.5px var(--surface-2), 0 0 0 2.75px var(--ability);
}

/* Strategy: level up or most coins. */
.strategy {
    margin: 1.5rem 0 1.25rem;
    padding-top: 1.25rem;
    border-top: 1px solid var(--border);
}

.strategy h3 {
    margin-bottom: 0.6rem;
}

.stock-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 0.6rem 1rem;
    margin-top: 0.6rem;
}

.level-up-note {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin: 0.5rem 0 0;
}

/* Results: how soon the level-up is covered. */
.level-up-lines {
    width: 100%;
    margin-top: 0.75rem;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.level-up-lines th {
    text-align: left;
    font-weight: 500;
    color: var(--text-muted);
    font-size: 0.75rem;
    padding: 0.3rem 0.5rem 0.3rem 0;
}

.level-up-lines td {
    padding: 0.35rem 0.5rem 0.35rem 0;
    border-top: 1px solid var(--border);
}

.level-up-unit:not(:empty) { margin-top: 0.5rem; }

.level-up-lines .slowest td,
.rate-table .top td {
    font-weight: 600;
}

.level-up-coins {
    margin: 0.85rem 0 0;
    font-size: 0.9rem;
    color: var(--text-muted);
}

.level-up-coins strong {
    color: var(--text);
}

/* Popups use more of a phone's width. */
@media (max-width: 600px) {
    .modal {
        padding: 0.5rem;
    }

    .modal-content {
        margin: 0.5rem auto;
    }

    .modal-body {
        padding: 1rem;
    }

    .math-block {
        padding: 0.75rem 0.4rem;
    }
}

/* Crop and tree jobs in the recipe list: "Sowing [Grass]". */
.job-list {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.job {
    white-space: nowrap;
}

.job-step {
    display: inline-block;
    min-width: 5.5rem;
    color: var(--text-muted);
    font-size: 0.75rem;
}

.recipe-best {
    display: block;
    color: var(--text-muted);
    font-size: 0.75rem;
    white-space: nowrap;
}

/* Recipe tables become one labelled block per recipe on phones. */
@media (max-width: 600px) {
    .recipe-table thead {
        display: none;
    }

    .recipe-table tr {
        display: block;
        padding: 0.6rem 0.75rem;
        border-bottom: 1px solid var(--border);
    }

    .recipe-table td {
        display: flex;
        justify-content: space-between;
        align-items: baseline;
        gap: 1rem;
        padding: 0.12rem 0;
        border: none;
        text-align: right;
    }

    .recipe-table td.recipe-name {
        justify-content: flex-start;
        gap: 0;
        font-weight: 600;
        text-align: left;
        padding-bottom: 0.3rem;
    }

    /* The "not checked" tooltip hangs from the name cell, not the icon, so a long name can't
       push it past the edge. */
    .recipe-table td.recipe-name {
        position: relative;
    }

    .recipe-table td.recipe-name .info-icon {
        position: static;
    }

    .recipe-table td.recipe-name [data-tooltip]::after {
        left: 0;
        transform: none;
    }

    .recipe-table td.empty {
        display: none;
    }

    .recipe-table td[data-label]::before {
        content: attr(data-label);
        color: var(--text-muted);
        font-size: 0.75rem;
        text-align: left;
        white-space: nowrap;
    }

    .recipe-table .job-list {
        align-items: flex-end;
    }

    .recipe-table .recipe-best {
        text-align: right;
    }
}

/* Table header tooltips open downward (a scrolling table would clip them above), and the last
   column's stays inside the table's right edge. */
.table-wrapper th [data-tooltip]::after {
    bottom: auto;
    top: 100%;
    margin-bottom: 0;
    margin-top: 0.5rem;
    text-transform: none;
    letter-spacing: normal;
}

.table-wrapper th:last-child [data-tooltip]::after {
    left: auto;
    right: 0;
    transform: none;
}

/* Time and Sell stay on one line; Inputs wraps instead. */
.recipe-table td:nth-child(5),
.recipe-table td:nth-child(6) {
    white-space: nowrap;
}

/* Recipes: special recipes and recipes to skip */
.recipes-section {
    margin: 0 0 1.25rem;
}

.recipes-section .assume-title:first-of-type {
    margin-top: 0.75rem;
}

.skip-count {
    color: var(--text-muted);
}

.skip-add {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.6rem;
    max-width: 28rem;
}

.skip-add input {
    flex: 1;
    min-width: 0;
    padding: 0.5rem 0.7rem;
    background: var(--surface-2);
    border: 1px solid var(--border-control);
    border-radius: 8px;
    color: var(--text);
    font: inherit;
    font-size: 0.9rem;
}

.skip-add input:focus {
    border-color: var(--accent);
}

.skip-add-btn {
    padding: 0.5rem 1rem;
    background: var(--surface-2);
    border: 1px solid var(--border-control);
    border-radius: 8px;
    color: var(--text);
    font: inherit;
    font-size: 0.9rem;
    cursor: pointer;
}

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

.skip-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-top: 0.6rem;
}

.skip-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.25rem 0.3rem 0.25rem 0.65rem;
    background: var(--surface-2);
    border-radius: 999px;
    font-size: 0.82rem;
}

.skip-chip-facility {
    color: var(--text-muted);
    font-size: 0.75rem;
}

.skip-chip button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.3rem;
    height: 1.3rem;
    padding: 0;
    background: none;
    border: none;
    border-radius: 50%;
    color: var(--text-muted);
    font-size: 0.7rem;
    cursor: pointer;
}

.skip-chip button:hover {
    background: var(--border);
    color: var(--text);
}

.plan-skipped {
    margin: 0.5rem 0 0;
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* Special recipes: one checkbox each. */
.special-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
    gap: 0.4rem 1rem;
    margin-top: 0.6rem;
}

.special-option {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    cursor: pointer;
}

.tag.special {
    color: var(--accent);
    background: color-mix(in srgb, var(--accent) 14%, transparent);
    margin-left: 0.35rem;
}

/* An event that has ended: its recipes stay listed for reference, muted. */
.tag.ended {
    color: var(--text-muted);
    background: color-mix(in srgb, var(--text-muted) 14%, transparent);
    margin-left: 0.35rem;
}

.recipe-table tr.ended {
    color: var(--text-muted);
}

/* "Fill from RV level" in advanced mode. */
.fill-row {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin: 0.75rem 0 1.25rem;
}

.fill-row label {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.fill-row select {
    padding: 0.4rem 0.6rem;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font: inherit;
    font-size: 0.85rem;
}

.fill-row .hint {
    flex-basis: 100%;
    margin: 0;
}

/* Keep the two results tables readable at both desktop and mobile widths. */
.seed-table table, .rate-table {
    width: 100%;
    table-layout: fixed;
    border-collapse: collapse;
    font-size: 0.85rem;
}
.seed-table :is(th, td), .rate-table :is(th, td) {
    padding: 0.35rem 0.3rem;
    border-bottom: 1px solid var(--border);
    overflow-wrap: anywhere;
    vertical-align: top;
}
.seed-table th, .rate-table th {
    color: var(--text-muted);
    font-size: 0.75rem;
    font-weight: 500;
}
.seed-table th:first-child { width: 35%; }
.seed-table th:nth-child(2) { width: 14%; }
.seed-table th:nth-child(3) { width: 18%; }
.seed-table th:nth-child(4) { width: 33%; }
.seed-table tbody td:not(:first-child), .seed-table thead th:not(:first-child), .seed-table tfoot td {
    text-align: end;
    font-variant-numeric: tabular-nums;
}
.seed-table tfoot :is(th, td) { border-bottom: 0; font-weight: 600; }
.seed-table tfoot th { width: auto; }
.seed-cost-currency { display: block; color: var(--text-muted); font-size: 0.72rem; }
.rate-table thead th:first-child { width: 2rem; }
.rate-table thead th:last-child { width: 28%; }
.rate-table td:last-child { font-variant-numeric: tabular-nums; }

/* Priorities: a ranked, draggable list. */
.priority-list {
    list-style: none;
    margin: 0.5rem 0 0;
    padding: 0;
    max-width: 26rem;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.priority {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.45rem 0.6rem;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.9rem;
    cursor: grab;
}

.priority.off .priority-name,
.priority.off .drag-handle {
    opacity: 0.55;
}

.priority.dragging {
    opacity: 0.4;
}

.priority.drop-target {
    border-color: var(--accent);
}

.priority-name {
    flex: 1;
}

/* On/off switch: a real checkbox, drawn as a sliding switch. */
.priority-switch {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    cursor: pointer;
    font-size: 0.75rem;
    color: var(--text-muted);
}

.priority-switch input {
    position: absolute;
    opacity: 0;
    width: 1px;
    height: 1px;
}

.switch-track {
    position: relative;
    width: 2.1rem;
    height: 1.2rem;
    border-radius: 999px;
    background: var(--border);
    transition: background 0.15s;
}

.switch-track::after {
    content: '';
    position: absolute;
    top: 0.15rem;
    left: 0.15rem;
    width: 0.9rem;
    height: 0.9rem;
    border-radius: 50%;
    background: var(--text-muted);
    transition: transform 0.15s, background 0.15s;
}

.priority-switch input:checked + .switch-track {
    background: color-mix(in srgb, var(--accent) 45%, transparent);
}

.priority-switch input:checked + .switch-track::after {
    transform: translateX(0.9rem);
    background: var(--accent);
}

.priority-switch input:focus-visible + .switch-track {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.switch-text {
    min-width: 1.5rem;
}

.drag-handle {
    color: var(--text-muted);
    letter-spacing: -0.15em;
    user-select: none;
}

.priority-rank {
    min-width: 1rem;
    font-weight: 700;
    color: var(--accent);
    text-align: center;
}

.priority-move {
    display: flex;
    gap: 0.2rem;
}

.priority-move button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.7rem;
    height: 1.7rem;
    padding: 0;
    background: none;
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    cursor: pointer;
}

.priority-move button:disabled {
    opacity: 0.3;
    cursor: default;
}

.priority-move button:not(:disabled):hover {
    border-color: var(--accent);
}

/* The coverage tint drawn over the plots, so it shows which part of each is covered; it lets
   hovers through to the plots underneath. */
.env-coverage-top {
    pointer-events: none;
}

/* Simple mode's facility list, collapsed by default. */
.simple-details {
    margin-top: 0.75rem;
}


/* A growing environment's name, in its own colour. */
.env-mode-tag {
    display: inline-block;
    padding: 0.05rem 0.4rem;
    border-radius: 6px;
    font-size: 0.78rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    color: var(--tint);
    background: color-mix(in srgb, var(--tint) 14%, transparent);
    border: 1px solid color-mix(in srgb, var(--tint) 40%, transparent);
    vertical-align: middle;
}

/* Between the parts of a paired environment's heading. */
.env-head-sep {
    margin: 0 0.6rem;
    color: var(--border);
}

/* Saying which Aniimo you have: ability levels under Best, the roster under My Aniimo. */
.aniimo-setup-panel {
    padding: 0.1rem 0 0.9rem;
}

.aniimo-setup-panel > .hint {
    margin: 0 0 0.6rem;
}

.ability-level-settings {
    margin-top: 0.65rem;
}

.ability-levels-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.ability-levels-title {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text);
}

.ability-level-presets {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    padding: 2px;
    border-radius: 7px;
    background: var(--surface-2);
    border: 1px solid var(--border);
}

.ability-level-presets button {
    padding: 0.25rem 0.42rem;
    border: 0;
    border-radius: 5px;
    background: transparent;
    color: var(--text-muted);
    font: inherit;
    font-size: 0.72rem;
    font-weight: 600;
    line-height: 1;
    cursor: pointer;
}

.ability-level-presets button:hover {
    background: var(--surface);
    color: var(--text);
}

.ability-level-presets button.is-active {
    background: var(--surface);
    color: var(--accent);
    box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 45%, transparent);
}

.ability-levels {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.375rem;
}

@container (max-width: 18rem) {
    .ability-levels {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

.ability-tile {
    background: var(--surface);
    border: 1px solid var(--border);
    border-top: 2px solid var(--ab-color);
    border-radius: 10px;
    padding: 0.42rem 0.44rem 0.38rem;
    display: flex;
    flex-direction: column;
    gap: 0.38rem;
    min-width: 0;
}

.ability-tile-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.25rem;
    min-width: 0;
}

.ability-tile-id {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    min-width: 0;
}

.ability-tile-icon {
    color: var(--ab-text);
    display: inline-flex;
    flex: 0 0 auto;
}

.ability-tile-name {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ability-tile-bars {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 3px;
}

.ability-tile-bar {
    position: relative;
    height: 1.35rem;
    border-radius: 5px;
    background: var(--surface-2);
    color: var(--text-muted);
    font-size: 0.72rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    cursor: pointer;
    display: grid;
    place-items: center;
    user-select: none;
    transition: background-color 0.12s, color 0.12s, filter 0.12s;
}

.ability-tile-bar input {
    position: absolute;
    opacity: 0;
    width: 1px;
    height: 1px;
    margin: 0;
    pointer-events: none;
}

.ability-tile-bar:hover {
    filter: brightness(1.12);
}

.ability-tile-bar:has(input:focus-visible) {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

.ability-tile-bar.is-filled {
    background: color-mix(in srgb, var(--ab-color) 28%, var(--surface-2));
    color: var(--text);
}

.ability-tile-bar.is-current {
    background: var(--ab-color);
    color: var(--ab-fg);
    font-weight: 800;
}

.ability-tile-bar.unheard-of {
    font-style: italic;
    opacity: 0.78;
}

.ability-tile-bar.unheard-of span::after {
    content: '*';
    font-size: 0.72em;
    vertical-align: super;
}

.ability-tile-bar.unheard-of.is-current {
    opacity: 1;
}

/* A level, in the same segmented style as the tabs above but sized for a digit. */
.tabs.level-picker {
    margin: 0;
    padding: 2px;
    border-radius: 8px;
}

.tabs.level-picker label {
    padding: 0.15rem 0.5rem;
    border-radius: 6px;
    font-size: 0.8rem;
    font-variant-numeric: tabular-nums;
}

/* A `hidden` element stays hidden whatever else its class says about display. */
[hidden] {
    display: none !important;
}

/* How many Aniimo the plan wants, against how many the homeland holds. */
.aniimo-count {
    display: flex;
    align-items: baseline;
    gap: 0.15rem;
    margin: 0 0 0 1.05rem;
    font-size: 1.6rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    line-height: 1.1;
}

.aniimo-count-of::before {
    content: '/';
    margin: 0 0.25rem 0 0.1rem;
    color: var(--text-muted);
    font-weight: 400;
}

.aniimo-count-of {
    color: var(--text-muted);
    font-size: 1.1rem;
    font-weight: 500;
}

.aniimo-count.over {
    color: var(--error);
}

/* A level the game isn't known to have an Aniimo at. */
.level-picker label.unheard-of {
    color: var(--text-muted);
    font-style: italic;
}

.level-picker label.unheard-of::after {
    content: '*';
    font-size: 0.7em;
    vertical-align: super;
}

/* Seasonal events: a switch, then the event picker and its inputs while it's on. */
.season {
    margin: 0 0 1.25rem;
}

.season-switch {
    font-size: 0.95rem;
    color: var(--text);
}

.season-title {
    font-weight: 600;
}

#season-config {
    margin-top: 0.75rem;
}

/* A column's unit under its name, e.g. "Profit" over "Home Coins/hour". */
.th-unit {
    display: block;
    font-size: 0.7rem;
    font-weight: 400;
    text-transform: none;
    letter-spacing: 0;
    color: var(--text-muted);
}

/* Opportunities */
.opportunity-tabs, .opportunity-controls {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .5rem;
    margin: .75rem 0;
}
.opportunity-tabs { border-bottom: 1px solid var(--border); padding-bottom: .65rem; }
.opportunity-tabs button[aria-pressed="true"] { border-color: var(--accent); }
.opportunity-tab-gain, .improve-gain { color: var(--accent); font-weight: 600; }
.opportunity-tab-gain:not(:empty) { margin-left: .15rem; }
.opportunity-controls [hidden] { display: none; }
#improve-list { display: grid; gap: .45rem; }
.opportunity-row { border: 1px solid var(--border); border-radius: .55rem; }
.opportunity-row > summary {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: .45rem .8rem;
    padding: .65rem .8rem;
    cursor: pointer;
    list-style: none;
}
.opportunity-row > summary::-webkit-details-marker { display: none; }
.opportunity-row > summary > :last-child { text-align: end; min-width: 0; overflow-wrap: anywhere; }
.opportunity-row > summary > :last-child::after { content: "⌄"; margin-left: .45em; color: var(--text-muted); }
.opportunity-row[open] > summary > :last-child::after { content: "⌃"; }
.opportunity-title { display: flex; gap: .5rem; align-items: center; min-width: 0; overflow-wrap: anywhere; }
.opportunity-title small { display: block; }
.opportunity-portrait { width: 2rem; height: 2rem; object-fit: contain; flex: none; }
.opportunity-detail { padding: .6rem .8rem; border-top: 1px solid var(--border); }
.opportunity-detail .hint { margin: .25rem 0; }
.opportunity-detail > button { margin-top: .4rem; }
.opportunity-trait { color: var(--accent); font-size: .85rem; }
.improve-none { color: var(--text-muted); font-size: .85rem; }
.opportunity-rest > summary { cursor: pointer; color: var(--text-muted); margin: .35rem 0; }
.opportunity-rest > .opportunity-row { margin-top: .4rem; }
@media (max-width: 560px) {
    .opportunity-row > summary { grid-template-columns: minmax(0, 1fr); }
    .opportunity-row > summary > :last-child { text-align: start; }
}
.comparison-result { margin-top: .45rem; }
.comparison-result > summary { cursor: pointer; font-size: .85rem; }
.comparison-table { width: 100%; font-size: .85rem; }
.comparison-table th, .comparison-table td { padding: .45rem .6rem; }
.comparison-table th:not(:first-child), .comparison-table td:not(:first-child) { text-align: right; white-space: nowrap; }
.comparison-table th:first-child, .comparison-table td:first-child { min-width: 9rem; }
.compare-loss { color: var(--error); }

/* Homeland layout. */
.layout-diagram {
    margin-top: 0.75rem;
    overflow: auto;
}

.layout-svg {
    width: 100%;
    max-height: 90vh;
    display: block;
}

.layout-whole {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.85rem;
    cursor: pointer;
}

.layout-svg text {
    text-anchor: middle;
    dominant-baseline: central;
    fill: var(--text);
    font-weight: 600;
    pointer-events: none;
}

.layout-facility-icon { pointer-events: none; }
.layout-facility-icon.loaded { filter: drop-shadow(0 0.07rem 0.09rem #1118); }
.layout-svg :has(> .layout-facility-icon.loaded) > .layout-icon-fallback { display: none; }
.layout-svg :is(.layout-recipe, .layout-number-label) {
    fill: white;
    stroke: #10141c;
    stroke-width: 0.16;
    stroke-linejoin: round;
    paint-order: stroke;
}

/* Zoomed in (Ctrl + scroll), the layout can be dragged around. */
.layout-svg.zoomed {
    cursor: grab;
}

.layout-svg.panning {
    cursor: grabbing;
}

.layout-zoom-hint {
    margin: 0.5rem 0 0;
}

.layout-storage {
    fill: var(--accent);
    fill-opacity: 0.26;
    stroke: var(--text);
    stroke-width: 0.08;
}

/* Deliveries to the Storage Unit (see "Deliveries" in app.js): a piece's line shows once its
   first batch is in. */
.layout-flow-line {
    stroke: var(--accent);
    stroke-opacity: 0;
    stroke-width: 0.07;
    transition: stroke-opacity 0.4s;
}

.layout-flow-line.live {
    stroke-opacity: 0.35;
}

.layout-dot {
    fill: var(--accent);
}

/* A piece's batch: the fill goes round as it works, and the ring turns amber while it waits for
   materials. */
.layout-ring circle {
    fill: none;
    stroke-width: 0.12;
}

.layout-ring .ring-track {
    stroke: var(--bg);
    stroke-opacity: 0.55;
}

.layout-ring .ring-fill {
    stroke: var(--text);
}

.layout-ring.waiting .ring-track {
    stroke: var(--warning);
    stroke-opacity: 0.9;
}

.layout-controls {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    margin-top: 0.6rem;
}

.layout-toggles {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 0.4rem 1rem;
}

.layout-arrangement {
    display: flex;
    flex-wrap: wrap;
    align-items: end;
    gap: .75rem 1rem;
    margin: .9rem 0 .5rem;
}

.layout-arrangement > label {
    padding: .55rem 0;
}

.layout-group-notice {
    color: var(--warning);
}

.layout-group-legend {
    display: flex;
    flex-wrap: wrap;
    gap: .35rem .6rem;
    list-style: none;
    padding: 0;
    margin: .7rem 0;
    font-size: .8rem;
}

.layout-arrangement [hidden],
.layout-group-legend[hidden] {
    display: none;
}

.layout-district,
.layout-group-legend {
    --district-color: var(--accent);
}

[data-purpose="sales"] { --district-color: #54bb9d; }
[data-purpose="support"] { --district-color: #82a8e5; }
[data-purpose="rv"] { --district-color: #d3a670; }
[data-theme="fields"] { --district-color: #c29c69; }
[data-theme="woodland"] { --district-color: #71ba7d; }
[data-theme="mining"] { --district-color: #b0a86c; }
[data-theme="water"] { --district-color: #62b9d3; }
[data-theme="aniimo"] { --district-color: #ab92d0; }
[data-theme="growing"] { --district-color: #93b877; }
[data-theme="extraction"] { --district-color: #8bb8bf; }
[data-theme="processing"] { --district-color: #b5a7d4; }

.layout-group-legend li {
    border: 1px solid color-mix(in srgb, var(--district-color) 55%, var(--border));
    background: color-mix(in srgb, var(--district-color) 9%, var(--surface));
    border-radius: .4rem;
    padding: .25rem .45rem;
}

.layout-group-legend strong {
    margin-right: .2rem;
}

.layout-index-group {
    display: flex;
    align-items: baseline;
    gap: .6rem;
    margin: .5rem 0;
}

.layout-index-group > div {
    display: flex;
    flex-wrap: wrap;
    gap: .35rem;
}

.layout-index-group > strong {
    flex: 0 0 auto;
}

.layout-index-group button {
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: .35rem;
    padding: .25rem .4rem;
    cursor: pointer;
}

.layout-index-group button[aria-pressed="true"] { border-color: var(--accent); }
.layout-site-focused > rect {
    stroke: #ffd97a;
    stroke-width: .3;
    fill-opacity: .85;
}

.layout-district-boundary {
    fill: var(--district-color);
    fill-opacity: .08;
    stroke: var(--district-color);
    stroke-width: .12;
    stroke-dasharray: .5 .22;
}

.layout-idle-boundary { fill: none; stroke: var(--text-muted); stroke-width: .1; stroke-dasharray: .4 .3; }
.layout-idle-area text { fill: var(--text-muted); }
.layout-group-fill { fill: var(--district-color); fill-opacity: .08; stroke: none; }
.layout-group-edge { fill: none; stroke: var(--district-color); stroke-width: .12; stroke-dasharray: .5 .22; }

.layout-district-structured .layout-district-boundary {
    stroke-width: .2;
    stroke-dasharray: none;
}

.layout-district-frontage {
    fill: var(--district-color);
    fill-opacity: .16;
    stroke: var(--district-color);
    stroke-opacity: .5;
    stroke-width: .08;
}

.layout-workshop-zone {
    fill: var(--district-color);
    fill-opacity: .13;
    stroke: var(--district-color);
    stroke-opacity: .65;
    stroke-width: .09;
}

.layout-decor { fill: url(#layout-decor-hatch); }
.layout-decor-stripe {
    stroke: var(--accent);
    stroke-opacity: .32;
    stroke-width: .12;
}

.layout-diagram.no-sim .layout-flows,
.layout-diagram.no-sim .layout-rings {
    display: none;
}

.layout-sim {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}

/* Progress card under the button: each step of working out a plan. */
.solve-progress {
    margin-top: 0.75rem;
    padding: 0.75rem 1rem;
}

.progress-steps {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    gap: 0.35rem;
    font-size: 0.85rem;
}

.progress-step {
    display: grid;
    grid-template-columns: 1.1rem 1fr auto;
    align-items: center;
    gap: 0.5rem;
}

.progress-step.pending,
.progress-step.skipped {
    color: var(--text-muted);
}

.step-note {
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.step-icon {
    text-align: center;
    font-weight: 700;
}

.step-icon.done {
    color: var(--accent);
}

.step-icon.fail {
    color: #ef4444;
}

.step-spinner {
    width: 0.8rem;
    height: 0.8rem;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: step-spin 0.8s linear infinite;
    justify-self: center;
}

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

@media (prefers-reduced-motion: reduce) {
    .step-spinner {
        animation-duration: 2.4s;
    }
}

/* Homeland plots in the layout: open ones outlined and numbered, the rest hatched. */
.layout-plot rect {
    fill: none;
    stroke: var(--text-muted);
    stroke-opacity: 0.6;
    stroke-width: 0.12;
}

/* Locked plots: red, hatched, outlined and labelled in red. */
.layout-plot.locked rect {
    fill: url(#layout-locked);
    stroke: #ef4444;
    stroke-opacity: 1;
}

.layout-svg .layout-plot.locked text {
    fill: #ef4444;
}

.layout-svg .layout-plot text {
    text-anchor: start;
    dominant-baseline: hanging;
    fill: var(--text-muted);
    font-weight: 600;
}

.layout-hatch {
    stroke: #ef4444;
    stroke-opacity: 0.3;
    stroke-width: 0.12;
}

/* My Aniimo: one card per kind of Aniimo the player has. */
.roster-editor {
    margin-top: 0.5rem;
}

.roster-editor-layout {
    display: grid;
    grid-template-columns: minmax(0, 28rem) minmax(11rem, 15rem);
    grid-template-areas: "board tools";
    align-items: start;
    gap: 0.7rem 1rem;
}
.roster-editor-layout > .roster-cards {
    grid-area: board;
}
.roster-tools {
    grid-area: tools;
    display: grid;
    min-width: 0;
    gap: 0.55rem;
}
.roster-tools .input-field { min-width: 0; margin: 0; }
.roster-tools .roster-actions { display: grid; gap: 0.3rem; }
.roster-tools .roster-actions button { text-align: start; }
.roster-tools [data-roster="save-import"] {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--on-accent);
    font-weight: 600;
}
#roster-fill-status:empty { display: none; }
@media (max-width: 43rem) {
    .roster-editor-layout {
        grid-template-columns: minmax(0, 1fr);
        grid-template-areas: "tools" "board";
    }
    .roster-tools .roster-actions { display: flex; }
}
.roster-catalog-results {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 7rem), 1fr));
    gap: 0.45rem;
    align-items: start;
}
.roster-cards {
    display: grid;
    gap: 0.12rem;
    width: 100%;
    max-width: 28rem;
}
.roster-slot-row {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 0.22rem;
    align-items: stretch;
}
.roster-slot { min-width: 0; min-height: 2.75rem; }
.roster-slot .roster-tile {
    position: relative;
    padding: 0.18rem 0.1rem;
}
.roster-slot .roster-portrait {
    width: 100%;
    max-width: 4rem;
    min-width: 0;
    margin-bottom: 0.35rem;
}
.roster-slot .roster-tile-name,
.roster-slot .roster-tile > small {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}
.roster-slot .roster-card-tags {
    --skill-size: 1rem;
    max-width: calc(100% + 0.45rem);
    padding: 1px;
}
.roster-move-hint:not([hidden]) { display: flex; flex-wrap: wrap; align-items: center; gap: 0.45rem; }
.roster-tile {
    display: grid;
    width: 100%;
    min-width: 0;
    align-content: start;
    justify-items: center;
    gap: 0.33rem;
    padding: 0.42rem 0.2rem;
    border: 1px solid transparent;
    border-radius: 0.65rem;
    background: transparent;
    color: var(--text);
    font: inherit;
    cursor: pointer;
}
.roster-tile[hidden] { display: none; }
.roster-tile:is(:hover, :focus-visible, .is-moving, .is-drop-target) { border-color: var(--accent); background: var(--surface-2); }
.roster-tile[draggable="true"] { cursor: grab; }
.roster-tile.is-idle .roster-portrait { filter: grayscale(1); opacity: 0.58; }
.roster-tile.is-idle .roster-tile-name { color: var(--text-muted); }
.roster-tile-name { font-size: 0.8rem; line-height: 1.25; overflow-wrap: anywhere; }
.roster-tile small { color: var(--text-muted); font-size: 0.7rem; }
.roster-svg-defs { position: absolute; }
.roster-portrait {
    --hex: url(#roster-hex);
    position: relative;
    display: grid;
    place-items: center;
    width: min(100%, 5.6rem);
    aspect-ratio: 0.8660254;
    margin-bottom: 0.55rem;
}
.roster-portrait::before, .roster-portrait-fill, .roster-portrait-fill::before {
    position: absolute;
    inset: 0;
}
.roster-portrait::before, .roster-portrait-fill::before { clip-path: var(--hex); }
.roster-portrait::before { content: ""; background: #48516a; }
.roster-portrait.prismana::before { background: linear-gradient(145deg, #a68aff, #98b6ff 40%, #f1a5fb 75%); }
.roster-portrait-fill {
    inset: 2.5px;
    display: grid;
    place-items: center;
    color: #b7c3d9;
    font-size: 2rem;
}
.roster-portrait-fill::before {
    content: "";
    background: linear-gradient(140deg, #59617a, #393f54 80%);
}
.roster-portrait.prismana .roster-portrait-fill::before {
    background: linear-gradient(145deg, #ffdad7 2%, #bfc7f6 28%, #fff1c9 53%, #bd9adf 92%);
}
.roster-portrait.prismana { filter: drop-shadow(0 0 0.28rem #a17be97d); }
.roster-portrait-fill > span { position: relative; }
.roster-portrait-fill > span:has(svg) { width: 46%; }
.roster-portrait-fill > span > svg { display: block; width: 100%; }
.roster-portrait-fill img {
    position: absolute;
    inset: 8% 5%;
    width: 90%;
    height: 84%;
    object-fit: contain;
}
.roster-portrait.game-head .roster-portrait-fill { clip-path: var(--hex); }
.roster-portrait.game-head img {
    inset: -5%;
    width: 110%;
    height: 110%;
    object-fit: cover;
}
.roster-portrait-fill:has(img.loaded) > span { visibility: hidden; }
.roster-tile.is-suggested .roster-portrait::before { background: #ef535a; }
.roster-trait-badge {
    position: absolute;
    top: 0.25rem;
    right: 0.15rem;
    z-index: 2;
    min-width: 1.1rem;
    padding: 0.04rem 0.24rem;
    border: 1px solid #15222a;
    border-radius: 999px;
    background: #ef535a;
    color: #fff;
    font-size: 0.62rem;
    font-weight: 700;
    line-height: 1.2;
    text-align: center;
    letter-spacing: 0.02em;
}
.roster-tile.is-assigned:not(.is-suggested) .roster-portrait::after {
    content: "";
    position: absolute;
    top: 0.45rem;
    left: 0.25rem;
    width: 0.55rem;
    aspect-ratio: 1;
    border: 1px solid #15222a;
    border-radius: 50%;
    background: #78dab3;
}
.roster-card-tags {
    --skill-size: 1.4rem;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    width: max-content;
    max-width: calc(100% + 0.9rem);
    gap: 1px;
    position: absolute;
    bottom: -0.38rem;
    padding: 2px;
    border-radius: 0.7rem;
    background: #27303f;
}
.roster-card-tags:has(> .roster-skill:nth-child(4)) {
    --badge-size: calc(var(--skill-size) * 0.92);
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    width: calc(4 * var(--badge-size) + 5px);
    max-width: 100%;
    box-sizing: border-box;
}
.roster-card-tags:has(> .roster-skill:nth-child(4)) > .roster-skill {
    width: 100%;
    height: auto;
    aspect-ratio: 1;
}
.roster-card-tags:empty { display: none; }
.roster-skill {
    position: relative;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: var(--ability);
    color: white;
    width: var(--skill-size);
    height: var(--skill-size);
    font-size: 0.7rem;
    line-height: 1;
}
.roster-skill svg { width: 70%; height: 70%; }
.roster-skill img {
    position: absolute;
    inset: 12%;
    width: 76%;
    height: 76%;
    object-fit: contain;
}
.roster-skill:has(img.loaded) svg { visibility: hidden; }
.roster-skill b {
    position: absolute;
    right: -1px;
    bottom: -1px;
    font-size: calc(var(--skill-size) * 0.58);
    text-shadow: 1px 0 #172131, -1px 0 #172131, 0 -1px #172131, 0 1px #172131;
}
.roster-empty-tile .roster-portrait {
    isolation: isolate;
    color: var(--accent);
}
.roster-empty-tile .roster-portrait::before { z-index: -1; background: color-mix(in srgb, var(--accent) 15%, var(--surface)); }
.roster-add-mark {
    width: min(0.9rem, 28%);
    aspect-ratio: 1;
    background: linear-gradient(currentColor, currentColor) center / 100% 2px no-repeat,
        linear-gradient(currentColor, currentColor) center / 2px 100% no-repeat;
}
@media (max-width: 40rem) {
    .roster-slot-row { gap: 0.12rem; }
    .roster-slot .roster-tile { padding-inline: 0.02rem; }
    .roster-slot .roster-card-tags { --skill-size: clamp(0.65rem, 3.25vw, 1rem); }
}
.layout-worker-icon { color: #fff; }
.layout-emode-bolt { color: #ffe56d; }
.roster-dialog {
    position: fixed;
    margin: auto;
    width: min(50rem, calc(100% - 1rem));
    max-height: calc(100dvh - 1rem);
    padding: clamp(0.7rem, 2vw, 1.15rem);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
}
.roster-dialog[open] { display: flex; flex-direction: column; gap: 0.7rem; }
.roster-dialog::backdrop { background: #080c16bc; }
.roster-edit-dialog { width: min(35rem, calc(100% - 1rem)); }
.roster-dialog-head, .roster-dialog-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.45rem;
}
.roster-dialog-head .roster-x { min-width: 2.75rem; min-height: 2.75rem; }
.roster-dialog .input-field { margin: 0; }
.roster-catalog-filters {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.45rem 0.65rem;
}
.roster-element-filter {
    display: inline-flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 2px;
    padding: 2px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    max-width: 100%;
    overflow-x: auto;
}
.roster-prismana-filter {
    display: inline-flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 2px;
    padding: 2px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--surface-2);
}
.roster-filter-chip {
    background: transparent;
    border: 1px solid transparent;
    border-radius: 6px;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.76rem;
    font-weight: 600;
    padding: 0.28rem 0.56rem;
    line-height: 1.25;
}
.roster-element-filter .roster-filter-chip {
    margin-right: 2px;
    flex-shrink: 0;
}
.roster-filter-chip[aria-pressed="true"] {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--on-accent);
}
.roster-el-btn {
    position: relative;
    display: grid;
    place-items: center;
    width: 1.9rem;
    height: 1.8rem;
    border-radius: 6px;
    border: 1px solid transparent;
    background: transparent;
    color: var(--ability);
    cursor: pointer;
    padding: 0;
    flex-shrink: 0;
    transition: background-color 0.12s ease, border-color 0.12s ease;
}
.roster-el-btn:hover {
    background: color-mix(in srgb, var(--ability) 12%, transparent);
}
.roster-el-btn[aria-pressed="true"] {
    background: color-mix(in srgb, var(--ability) 20%, var(--surface));
    border-color: var(--ability);
}
.roster-el-btn svg {
    width: 68%;
    height: 68%;
}
.roster-el-dot {
    position: relative;
    display: grid;
    place-items: center;
    width: 1.35rem;
    height: 1.35rem;
    border-radius: 50%;
    background: var(--ability);
    color: #fff;
    opacity: 0.85;
    transition: opacity 0.12s ease, transform 0.12s ease;
}
.roster-el-btn:hover .roster-el-dot,
.roster-el-btn[aria-pressed="true"] .roster-el-dot {
    opacity: 1;
}
.roster-el-dot img {
    position: absolute;
    inset: 12%;
    width: 76%;
    height: 76%;
    object-fit: contain;
}
.roster-el-dot:has(img.loaded) svg { visibility: hidden; }
.roster-missing-traits {
    position: absolute;
    top: 0.14rem;
    right: 0.14rem;
    width: 1.05rem;
    height: 1.05rem;
    border-radius: 999px;
    background: var(--warning);
    color: var(--on-accent);
    font-size: 0.65rem;
    font-weight: 800;
    display: grid;
    place-items: center;
    line-height: 1;
    pointer-events: none;
    z-index: 2;
}
#roster-fill-status.roster-traits-hint {
    color: var(--warning);
    font-weight: 600;
}
.roster-pick-card {
    position: relative;
    display: flex;
}
#roster-catalog-results .roster-tile {
    position: relative;
}
#roster-catalog-results .roster-tile.is-picked {
    border-color: var(--accent);
    box-shadow: inset 0 0 0 1px var(--accent);
    background: color-mix(in srgb, var(--accent) 12%, var(--surface));
}
.roster-pick-badge {
    position: absolute;
    top: 0.25rem;
    right: 0.25rem;
    z-index: 2;
    display: inline-flex;
    align-items: center;
    gap: 2px;
    padding: 1px 2px 1px 6px;
    border-radius: 999px;
    background: var(--accent);
    color: var(--on-accent);
    font-size: 0.72rem;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
}
.roster-pick-badge[hidden] {
    display: none;
}
.roster-pick-dec {
    width: 1.15rem;
    height: 1.15rem;
    border-radius: 50%;
    border: none;
    background: color-mix(in srgb, var(--on-accent) 22%, transparent);
    color: var(--on-accent);
    font-size: 0.85rem;
    font-weight: 800;
    line-height: 1;
    display: grid;
    place-items: center;
    cursor: pointer;
    padding: 0;
}
.roster-pick-dec:hover {
    background: color-mix(in srgb, var(--on-accent) 36%, transparent);
}
.roster-confirm-btn {
    background: var(--accent);
    border: 1px solid var(--accent);
    border-radius: 8px;
    color: var(--on-accent);
    cursor: pointer;
    font-weight: 700;
    padding: 0.42rem 0.9rem;
}
.roster-confirm-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}
.roster-work-details {
    display: grid;
    gap: 0.28rem;
    min-width: 0;
}
.roster-work-details > strong { color: var(--text); }
.roster-work-details > p { margin: 0; }
.roster-work-tasks {
    display: grid;
    list-style: none;
    margin: 0.2rem 0 0;
    padding: 0;
}
.roster-work-tasks li {
    display: flex;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.28rem 0;
    border-top: 1px solid var(--border);
}
.roster-work-tasks b {
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}
.roster-catalog-scroll {
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    scrollbar-color: var(--text-muted) transparent;
}
.roster-catalog-scroll > :not(.roster-catalog-results) { margin: 0.4rem; }
.roster-edit-workload { white-space: pre-line; margin-bottom: 0.8rem; }

.roster-x,
.dlg-close {
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-muted);
    cursor: pointer;
    min-width: 1.6rem;
    height: 1.6rem;
    line-height: 1;
}

.roster-x:hover,
.dlg-close:hover {
    color: var(--text);
}

.roster-card-fields {
    display: grid;
    min-width: 0;
    gap: 0.65rem;
}
.roster-edit-section {
    display: grid;
    gap: 0.35rem;
    padding-top: 0.45rem;
    border-top: 1px solid var(--border);
}
.roster-edit-section-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.3rem 0.5rem;
}
.roster-edit-section-head h4 { font-size: 0.83rem; }
.roster-abilities {
    display: grid;
    border-radius: 0.5rem;
    background: var(--surface-2);
}
.roster-ability {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto;
    align-items: center;
    gap: 0.25rem;
    padding: 0.17rem 0.3rem 0.17rem 0.45rem;
}
.roster-ability + .roster-ability { border-top: 1px solid var(--border); }
.roster-edit-dialog .level-picker label {
    display: grid;
    place-items: center;
    min-height: 1.85rem;
}
.roster-ability .level-picker label { min-width: 1.7rem; padding-inline: 0.2rem; }
.roster-ability .roster-x {
    min-width: 1.9rem;
    height: 1.9rem;
    font-size: 0.7rem;
}

.roster-add-ability {
    background: transparent;
    color: var(--text-muted);
    border: 1px dashed var(--border);
    border-radius: 6px;
    padding: 0.2rem 0.4rem;
}

.roster-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}
.roster-edit-actions {
    justify-content: flex-start;
    border-top: 1px solid var(--border);
    padding-top: 0.65rem;
}
.roster-edit-actions .roster-remove-btn {
    margin-inline-start: auto;
    color: var(--error);
}
.roster-personalities {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.3rem;
}
.roster-personalities .roster-pair {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
}
.roster-personalities .roster-pair label { padding-inline: 0.12rem; }
#roster-edit-dialog .roster-edit-workload { margin: 0; }

.roster-family { max-width: 100%; }
.roster-family select { max-width: 100%; min-width: 0; font-size: 0.8rem; }
.roster-family .hint { margin: 0.3rem 0; }

.layout-storage-config {
    flex: 0 1 13rem;
    margin: 0;
}

.layout-storage-config .hint {
    display: block;
    margin-top: 0.25rem;
}

#level-up-lines,
#priority-rates {
    overflow-x: auto;
}

/* A plan that failed shows only the Aniimo card, whose setup may be what to change. */
#results-content.setup-only > :not(#aniimo-card) {
    display: none !important;
}

/* While another Aniimo setup is worked out, the last one's results are dimmed. */
#results-content.stale > :not(#aniimo-card),
#results-content.stale #aniimo-body,
#results-content.stale #roster-summary,
#results-content.stale #aniimo-abilities {
    opacity: 0.45;
    pointer-events: none;
}

.layout-power-zones rect { fill: #f6cd58; fill-opacity: 0.035; stroke: #e2ba43; stroke-opacity: 0.45; stroke-width: 0.06; stroke-dasharray: 0.3 0.2; }
.layout-power-links line { stroke: #f6cd58; stroke-opacity: 0.85; stroke-width: 0.11; stroke-dasharray: 0.35 0.18; }
.layout-power-pole rect { fill: #e7b849; fill-opacity: 0.17; stroke: #f6cd58; stroke-width: 0.1; }
.layout-power-pole text, .layout-generator text { fill: #fff0b0; }
.layout-emode-badge { pointer-events: none; }
.layout-emode-frame { fill: #241b08; stroke: #ffd75c; stroke-width: 0.045; }
.layout-emode-badge text { fill: #fff0aa; }
.layout-emode-badge.disconnected .layout-emode-frame { fill: #842d2d; stroke: #ff7777; }

/* Hover tips (see "Hover tips" in app.js). */
.tip-card {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 1000;
    max-width: min(300px, calc(100vw - 24px));
    padding: 0.5rem 0.7rem;
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
    font-size: 0.8rem;
    line-height: 1.4;
    pointer-events: none;
}

.tip-card:not([hidden]) {
    animation: tip-in 90ms ease-out;
}

@keyframes tip-in {
    from {
        opacity: 0;
        transform: translateY(3px);
    }
}

.tip-title {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    font-weight: 600;
}

.tip-swatch {
    flex: none;
    width: 0.65rem;
    height: 0.65rem;
    border-radius: 3px;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.2);
}

.tip-detail {
    margin-top: 0.1rem;
}

.tip-stats {
    margin-top: 0.15rem;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}

.tip-card.has-swatch .tip-detail,
.tip-card.has-swatch .tip-stats {
    padding-left: 1.1rem;
}

@media (prefers-reduced-motion: reduce) {
    .tip-card:not([hidden]) {
        animation: none;
    }
}
/* Planner controls stay within reach while editing long setups or reading results. */
body {
    max-width: 76rem;
    margin-block: clamp(1rem, 4vw, 2.5rem);
    padding-inline: clamp(0.65rem, 2.5vw, 1.5rem);
}

body > header {
    margin-bottom: 1rem;
    align-items: center;
    gap: 0.75rem 1.25rem;
}

.brand .subtitle { margin: 0; }
.header-buttons { gap: 0.35rem 0.85rem; }
.header-buttons .toggle-button { min-height: 2rem; }

.visually-hidden,
.skip-to-planner:not(:focus) {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
}

.skip-to-planner:focus {
    position: fixed;
    z-index: 30;
    inset: 0.75rem auto auto 0.75rem;
    padding: 0.6rem 0.9rem;
    border-radius: 0.5rem;
    background: var(--surface);
}

:where(a, button, summary, select, input):focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

html { scroll-padding-top: 0.8rem; }
#results-content > *, .input-field { min-width: 0; }
.planner-team-settings h3 { margin: 0 0 0.6rem; }
.planner-setup-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 0;
    align-items: start;
}
.planner-setup-grid > .goals-col { padding-inline-end: 1.25rem; }
.planner-priorities, .planner-editor { min-width: 0; }
.planner-priorities h3 { margin: 0 0 0.5rem; }
.planner-priorities .priority-list { max-width: none; }
.planner-priorities .priority-list:empty { display: none; }
.planner-priorities .priority-name { min-width: 0; overflow-wrap: anywhere; }
.planner-priority-add { margin-top: 0.6rem; display: flex; align-items: center; gap: 0.85rem; flex-wrap: wrap; }
.planner-priority-add select {
    max-width: 100%;
    padding: 0.45rem 0.75rem;
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font: inherit;
    line-height: 1.3;
    cursor: pointer;
}
.planner-priority-add select:hover:not(:disabled) { border-color: var(--accent); }
.planner-priorities .planner-checkbox { margin: 0; }
.planner-editor {
    container-type: inline-size;
    border-inline-start: 1px solid var(--border);
    padding-inline-start: 1.25rem;
}
.planner-editor-options { display: grid; gap: 0.36rem; }
.planner-editor-options [data-planner-editor] {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
    min-height: 2.75rem;
    padding: 0.4rem 0.7rem;
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font: inherit;
    text-align: start;
    overflow-wrap: anywhere;
    cursor: pointer;
}
.planner-editor-options [data-planner-editor]:hover,
.planner-editor-options [data-planner-editor][aria-expanded="true"] {
    border-color: var(--accent);
}
.planner-editor-options [data-planner-editor][aria-expanded="true"] { border-radius: var(--radius) var(--radius) 0 0; }
.planner-editor-options [data-planner-editor] > span {
    margin-inline-start: auto;
    color: var(--text-muted);
    font-size: 0.78rem;
    text-align: end;
}
#planner-team-summary {
    display: inline-flex;
    align-items: center;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 0.28rem;
}
.team-summary-mode {
    color: var(--accent);
    font-weight: 600;
}
.team-summary-chip {
    padding: 1px 6px;
    border-radius: 5px;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    font-weight: 600;
    font-size: 0.72rem;
}
.team-summary-pill {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    padding: 1px 5px;
    border-radius: 5px;
    font-size: 0.72rem;
    font-weight: 700;
    background: color-mix(in srgb, var(--ab-color) 20%, var(--surface));
    border: 1px solid color-mix(in srgb, var(--ab-color) 55%, var(--border));
    color: var(--text);
    line-height: 1.35;
    font-variant-numeric: tabular-nums;
}
.planner-editor-options [data-planner-editor]::after {
    content: "";
    flex: 0 0 auto;
    width: 0.33rem;
    height: 0.33rem;
    border-inline-end: 1px solid var(--text-muted);
    border-block-end: 1px solid var(--text-muted);
    transform: translateY(-1px) rotate(45deg);
}
.planner-editor-options [data-planner-editor][aria-expanded="true"]::after { transform: translateY(1px) rotate(225deg); }
.planner-editor-panel {
    min-width: 0;
    padding: 0.8rem;
    border: 1px solid var(--border);
    border-top: 0;
    border-radius: 0 0 var(--radius) var(--radius);
    overflow-wrap: anywhere;
}
.planner-editor-panel .planner-season { padding: 0; margin: 0; border: 0; }
.planner-editor-panel .skip-add input { min-width: 0; }
.planner-building-settings { margin-top: 0.8rem; padding-top: 0.8rem; border-top: 1px solid var(--border); }
.planner-building-settings #reset-buildings { margin-block: 0.45rem; }
.planner-building-settings #advanced-config { margin-top: 0.65rem; }
.planner-building-settings #advanced-config .facilities-container { gap: 0.65rem; }
.planner-building-settings #advanced-config .facilities-grid,
.planner-building-settings #advanced-config .modules-grid {
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 10rem), 1fr));
}
.planner-rv-settings { margin-top: 0.9rem; display: flex; gap: 1rem; flex-wrap: wrap; align-items: end; }
.planner-rv { margin: 0; flex: 1 1 20rem; max-width: 28rem; }
.rv-picker {
    display: flex;
    align-items: center;
    gap: 0.9rem;
    flex-wrap: wrap;
}
.rv-stepper {
    display: inline-flex;
    align-items: stretch;
    border: 1px solid var(--border-control);
    border-radius: 10px;
    background: var(--surface-2);
    overflow: hidden;
    flex-shrink: 0;
}
.rv-stepper:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 25%, transparent);
}
.rv-step-btn {
    width: 2.35rem;
    min-height: 2.35rem;
    border: 0;
    background: transparent;
    color: var(--text);
    font-size: 1.15rem;
    line-height: 1;
    cursor: pointer;
    display: grid;
    place-items: center;
    transition: background-color 0.15s, color 0.15s;
}
.rv-step-btn:hover:not(:disabled) {
    background: color-mix(in srgb, var(--accent) 16%, transparent);
    color: var(--accent);
}
.rv-step-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}
.planner-rv input.rv-number {
    width: 3.1rem;
    min-height: 2.35rem;
    border: 0;
    border-inline: 1px solid var(--border);
    border-radius: 0;
    background: transparent;
    color: var(--text);
    text-align: center;
    font-size: 1rem;
    font-weight: 600;
    padding: 0 0.25rem;
    appearance: textfield;
    -moz-appearance: textfield;
}
.planner-rv input.rv-number:focus {
    outline: none;
    border-color: var(--border);
    box-shadow: none;
}
.planner-rv input.rv-number::-webkit-outer-spin-button,
.planner-rv input.rv-number::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}
.rv-slider-wrap {
    flex: 1 1 11rem;
    min-width: 9rem;
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    padding-top: 0.25rem;
}
.planner-rv input.rv-slider {
    width: 100%;
    height: 1.4rem;
    min-height: 1.4rem;
    margin: 0;
    padding: 0;
    border: 0;
    background: transparent;
    cursor: pointer;
    accent-color: var(--accent);
}
.planner-rv input.rv-slider:focus {
    border-color: transparent;
}
.rv-slider-ticks {
    display: flex;
    justify-content: space-between;
    padding-inline: 0.4rem;
    font-size: 0.72rem;
    line-height: 1;
    color: var(--text-muted);
    user-select: none;
}
.quest-income-fields { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: .65rem; }
.quest-income-fields .input-field { min-width: 0; margin: 0; }
.quest-income-fields select, .quest-income-fields input { width: 100%; min-width: 0; }
@container (max-width: 35rem) {
    .planner-editor-panel .roster-editor-layout {
        grid-template-columns: minmax(0, 1fr);
        grid-template-areas: "tools" "board";
    }
    .planner-editor-panel .roster-tools .roster-actions { display: flex; flex-wrap: wrap; }
}
@media (max-width: 48rem) {
    .planner-setup-grid { grid-template-columns: minmax(0, 1fr); gap: 0.75rem; }
    .planner-setup-grid > .goals-col { padding-inline-end: 0; }
    .planner-editor { border-inline-start: 0; padding-inline-start: 0; }
}
.config-actions { gap: 0.1rem 0.85rem; }
.config-actions button { min-height: 2.75rem; }
.planner-team-options.tabs {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.25rem;
    width: 100%;
    max-width: 30rem;
    margin: 0 0 0.65rem;
}
.planner-team-options.tabs label {
    display: grid;
    place-items: center;
    min-height: 2.75rem;
    padding: 0.35rem;
    text-align: center;
    line-height: 1.2;
}
.planner-team-options.tabs label:has(input:checked) {
    background: var(--surface);
    box-shadow: inset 0 0 0 1px var(--accent);
    color: var(--accent);
}
.planner-team-settings .aniimo-setup-panel { padding: 0; }
.planner-team-settings #aniimo-setup-hint { margin: 0; }
.planner-team-settings #ability-level-settings { margin-top: 0.5rem; }
.planner-team-settings .best-personalities-toggle { margin-bottom: 0.45rem; }
.planner-team-settings .level-picker label { min-height: 2rem; }
.planner-team-settings .roster-config { margin-top: 0.75rem; }

.planner-checkbox {
    display: grid;
    grid-template-columns: 1rem minmax(0, 1fr);
    align-items: start;
    gap: 0.5rem;
    width: fit-content;
    max-width: 100%;
    padding-block: 0.3rem;
    line-height: 1.4;
    cursor: pointer;
}
.planner-checkbox input[type="checkbox"] {
    width: 1rem;
    height: 1rem;
    margin: calc((1.4em - 1rem) / 2) 0 0;
}
#priorities-config > .hint { margin-top: 0.4rem; }
.planner-season {
    padding-block: 1rem;
    margin-block: 0 1.25rem;
    border-block: 1px solid var(--border);
}
#season-hint { max-width: 65ch; }
.season-budget { max-width: 23rem; }
#season-notes .special-option { align-items: baseline; }
#season-notes input { flex: none; }
.planner-submit {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-top: 0.9rem;
    padding-top: 0.9rem;
    border-top: 1px solid var(--border);
}
.planner-submit #electricity-section { flex: 1 1 14rem; margin: 0; }
.planner-submit .optimize-btn { min-height: 2.75rem; width: auto; margin: 0 0 0 auto; }

.facility-search, .production-filters .input-field { max-width: 25rem; }
.facility-search { margin-bottom: 0.8rem; }
.facility-search input, .production-filters input[type="search"] { width: 100%; }
#facilities-grid .facility-category-title { display: list-item; margin: 0; }
#facilities-grid .facilities-grid { margin-top: 0.65rem; }
.production-filters { display: flex; flex-wrap: wrap; align-items: end; gap: 0.5rem 1rem; margin-bottom: 0.8rem; }
.production-filters .input-field { flex: 1 1 14rem; }

.layout-zoom-controls { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; justify-content: space-between; }
.layout-zoom-controls .hint { margin: 0; }
.layout-zoom-controls [role="group"] { display: flex; gap: 0.35rem; }
.layout-zoom-controls button { min-height: 2.75rem; min-width: 2.75rem; }
.layout-controls { align-items: end; }
.layout-controls .layout-toggles { padding-block: 0.45rem; }
.layout-arrangement > .input-field { flex: 1 1 11rem; }
.layout-arrangement > label { display: flex; align-items: baseline; gap: 0.5rem; }
.layout-arrangement > label input { flex: none; }
.layout-svg.zoomed { touch-action: none; }
.tip-detail, .tip-work { white-space: pre-line; overflow-wrap: anywhere; }
.tip-work { border-top: 1px solid var(--border); margin-top: 0.35rem; padding-top: 0.35rem; }
.layout-worker-badges { pointer-events: none; }
.layout-worker-more { paint-order: stroke; stroke: #151820; stroke-width: 0.14; }
:is(.layout-piece, .env-building):focus-visible > rect { stroke: var(--accent); stroke-width: 0.17; }
.priority-name, .step-label { min-width: 0; overflow-wrap: anywhere; }
.progress-step { grid-template-columns: 1.1rem minmax(0, 1fr) auto; }

@media (max-width: 37.5rem) {
    body > header { align-items: flex-start; }
    .header-buttons { justify-content: flex-start; }
    .input-field input, .input-field select { min-height: 2.75rem; font-size: 1rem; }
    .rv-step-btn { width: 2.75rem; min-height: 2.75rem; }
    .planner-rv input.rv-slider { min-height: 1.75rem; }
    .planner-submit .optimize-btn { width: 100%; }
    .layout-storage-config { flex-basis: 100%; }
    .card .facility-plan-table td { overflow-wrap: anywhere; gap: 0.6rem; }
    .facility-plan-table td::before { flex: 0 0 34%; white-space: normal; }
    .env-diagram { flex-basis: min(100%, 280px); min-width: 0; max-width: 100%; }
    .priority { gap: 0.4rem; }
    .priority-move { flex: none; }
    .priority-move button { width: 2rem; height: 2rem; }
    .priority-switch .switch-text { display: none; }
    .progress-step { grid-template-columns: 1.1rem minmax(0, 1fr); column-gap: 0.5rem; row-gap: 0.1rem; }
    .step-note { grid-column: 2; white-space: normal; font-size: 0.75rem; }
    .step-note:empty { display: none; }
    .opportunity-tabs button, .opportunity-detail > button { min-height: 2.75rem; }
    .production-filters .input-field { flex-basis: 100%; max-width: none; }
    #level-up-lines thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
    #level-up-lines table, #level-up-lines tbody { display: block; }
    #level-up-lines tr { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 0.6rem; padding-block: 0.5rem; border-top: 1px solid var(--border); }
    .card #level-up-lines td { display: flex; justify-content: space-between; align-items: baseline; gap: 0.3rem; padding: 0.15rem 0; border: 0; overflow-wrap: anywhere; }
    .card #level-up-lines td:first-child { grid-column: 1 / -1; font-weight: 600; }
    #level-up-lines td:not(:first-child)::before { content: attr(data-label); color: var(--text-muted); font-size: 0.75rem; font-weight: 400; }
    .level-up-unit select { min-height: 2.75rem; }
}

.aniimo-card .card-head { margin-bottom: 0.4rem; }
.aniimo-card #aniimo-collapsed-summary { margin: 0.15rem 0 0 1.15rem; }
.aniimo-card .ability-strip:empty { display: none; }
.assignment-meta { color: var(--text-muted); font-size: 0.78rem; }
.facility-plan-table td { vertical-align: top; }

.production-section > h3 { margin: 0 0 0.65rem; font-size: 1rem; }
.production-section + .production-section { border-top: 1px solid var(--border); padding-top: 1.2rem; }
.production-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: stretch;
    gap: 0.75rem;
}
.production-building-card {
    min-width: 0;
    border: 1px solid var(--border);
    border-radius: 0.7rem;
    background: var(--surface-2);
}
.production-building-title {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    margin: 0;
    padding: 0.38rem 0.75rem;
    font-size: 0.97rem;
    overflow-wrap: anywhere;
}
.production-building {
    position: relative;
    display: grid;
    place-items: center;
    flex: 0 0 2.25rem;
    width: 2.25rem;
    height: 2.25rem;
    font-size: 0.75rem;
    color: var(--text-muted);
}
.production-building img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
    visibility: hidden;
}
.production-building img.loaded { visibility: visible; }
.production-building:has(img.loaded) > span { visibility: hidden; }
.production-building-card.is-idle { color: var(--text-muted); background: var(--surface); }
.production-building-title > .production-count { margin-inline-start: auto; }
.production-unit h5 {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.25rem 0.6rem;
    padding: 0.4rem 0.75rem;
    border-top: 1px solid var(--border);
    background: var(--surface);
    font-size: 0.82rem;
}
.production-unit-load, .production-period { font-size: 0.75rem; font-weight: 400; color: var(--text-muted); }
.production-period { flex-basis: 100%; }
.production-unit .production-tile + .production-tile .production-period { color: var(--accent); }
.production-building-card.is-idle .production-building { filter: grayscale(1); opacity: 0.78; }
.production-tile { border-top: 1px solid var(--border); }
.production-summary {
    position: relative;
    display: grid;
    align-items: center;
    grid-template-columns: minmax(0, 1fr) auto 0.55rem;
    gap: 0.55rem;
    min-height: 3.2rem;
    padding: 0.36rem 0.8rem;
    list-style: none;
    cursor: pointer;
}
.production-summary::-webkit-details-marker { display: none; }
.production-summary:hover { background: color-mix(in srgb, var(--text) 4%, transparent); }
.production-summary:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.production-tile:last-child .production-summary { border-radius: 0 0 0.65rem 0.65rem; }
.production-edge {
    position: absolute;
    inset: 0.3rem auto 0.3rem 0;
    width: 3px;
    border-radius: 2px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.production-edge > span { flex: 1; }
.production-title, .production-state, .production-workers, .production-load, .production-electric {
    display: flex;
    align-items: center;
}
.production-title { flex-wrap: wrap; gap: 0.1rem 0.35rem; font-size: 0.86rem; }
.production-item { overflow-wrap: anywhere; }
.production-count, .production-more { font-size: 0.72rem; color: var(--text-muted); white-space: nowrap; }
.production-tile:not([data-status="producing"]) .production-title { color: var(--text-muted); }
.production-state { gap: 0.55rem; justify-content: flex-end; }
.production-workers { gap: 0.12rem; }
.production-ability-icon { width: 1.25rem; height: 1.25rem; object-fit: contain; }
.production-electric { gap: 0.18rem; color: var(--text); font-size: 0.72rem; white-space: nowrap; }
.production-electric svg { width: 1rem; height: 1rem; color: #e6a427; }
.production-grid-labels { display: grid; gap: 0.12rem; text-align: right; }
.production-load { gap: 0.28rem; font-size: 0.74rem; white-space: nowrap; font-variant-numeric: tabular-nums; }
.production-load > strong { min-inline-size: 6.25ch; text-align: end; }
.production-load-track { width: 2rem; height: 4px; border-radius: 4px; background: var(--border); overflow: hidden; }
.production-load-track > span { display: block; height: 100%; background: var(--accent); }
.production-chevron {
    width: 0.42rem;
    height: 0.42rem;
    border-right: 1.5px solid var(--text-muted);
    border-bottom: 1.5px solid var(--text-muted);
    transform: translateY(-2px) rotate(45deg);
}
.production-tile[open] .production-chevron { transform: translateY(2px) rotate(225deg); }
.production-portrait, .production-portrait-art {
    display: grid;
    place-items: center;
    clip-path: url(#roster-hex);
}
.production-portrait {
    width: 1.75rem;
    aspect-ratio: 0.8660254;
    flex-shrink: 0;
    background: #66738f;
}
.production-portrait.prismana { background: linear-gradient(145deg, #a68aff, #98b6ff 40%, #f1a5fb 75%); }
.production-portrait-art {
    position: relative;
    width: calc(100% - 2px);
    height: calc(100% - 2px);
    background: #394258;
    color: #d7e1f5;
}
.production-portrait.prismana .production-portrait-art { background: #d5c9e5; color: #394258; }
.production-portrait-art svg { display: block; width: 0.9rem; height: 0.9rem; }
.production-portrait-art img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
    visibility: hidden;
}
.production-portrait-art img.game-head { object-fit: cover; }
.production-portrait-art img.loaded { visibility: visible; }
.production-portrait-art:has(img.loaded) > span { visibility: hidden; }
.production-detail {
    padding: 0.15rem 0.8rem 0.75rem;
    font-size: 0.8rem;
    color: var(--text-muted);
    overflow-wrap: anywhere;
}
.production-detail p { display: flex; flex-wrap: wrap; column-gap: 0.36rem; margin: 0 0 0.45rem; }
.production-detail strong { color: var(--text); }
.production-crew { display: flex; flex-wrap: wrap; gap: 0.35rem 0.75rem; list-style: none; padding: 0; margin: 0 0 0.45rem; }
.production-crew li { display: flex; align-items: center; gap: 0.3rem; min-width: 0; }
.production-skip {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    min-height: 2.75rem;
    padding: 0.25rem 0.65rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    font: inherit;
    cursor: pointer;
}
.production-skip:hover {
    border-color: var(--error);
    background: color-mix(in srgb, var(--error) 9%, var(--surface));
}
.production-skip-mark { font-size: 1rem; line-height: 1; }
.production-environment-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 19rem), 1fr));
    gap: 0.9rem;
    padding-top: 0.75rem;
}
@media (max-width: 48rem) {
    .production-grid { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 28rem) {
    .production-summary { gap: 0.4rem; padding-inline: 0.65rem; }
    .production-state { gap: 0.4rem; }
    .production-load-track { display: none; }
}

@media (max-width: 26rem) {
    .env-unit, .table-wrapper { min-width: 0; max-width: 100%; }
    .env-unit { overflow-wrap: anywhere; }
    #facility-plan-container { min-width: 0; overflow-wrap: anywhere; }
}
/* Daily actions belong beside the production plan, rather than a separate result card. */
.recipe-schedule { margin: 16px 0 20px; border-block: 1px solid var(--border); padding: 12px 0; }
.recipe-schedule > summary { cursor: pointer; }
.recipe-schedule-count { margin-left: 12px; color: var(--accent); font-size: .85em; white-space: nowrap; }
.recipe-schedule-scroll { margin-top: 12px; max-width: 100%; overflow-x: auto; }
.recipe-schedule-table th, .recipe-schedule-table td { border: 0; border-bottom: 1px solid var(--border); padding: 10px 12px; vertical-align: middle; background: transparent; }
.recipe-schedule-table th { text-transform: none; letter-spacing: normal; }
.recipe-schedule-table thead th { color: var(--text-muted); font-weight: 400; white-space: nowrap; }
.recipe-schedule-table tbody th { font-size: inherit; min-width: 200px; }
.recipe-schedule-table td { min-width: 150px; }
.recipe-schedule-table tr:last-child > * { border-bottom: 0; }
.recipe-schedule-building { display: flex; align-items: center; gap: 10px; }
.recipe-schedule-building img { object-fit: contain; flex: 0 0 32px; }
.recipe-schedule-table tbody tr td { color: var(--text); font-weight: normal; }
.recipe-schedule-table tbody tr td.recipe-schedule-changed { color: var(--accent); }
.recipe-schedule-arrow { color: var(--text-muted); margin-right: 10px; }
@media (max-width: 600px) {
    .recipe-schedule-count { display: block; margin: 6px 0 0 18px; }
    .recipe-schedule-table, .recipe-schedule-table tbody { display: block; }
    .recipe-schedule-table thead { display: none; }
    .recipe-schedule-table tr { display: block; padding: 10px 0; border-bottom: 1px solid var(--border); }
    .recipe-schedule-table tr:last-child { border-bottom: 0; }
    .recipe-schedule-table tbody th { display: block; padding: 0 0 8px; min-width: 0; border: 0; }
    .recipe-schedule-table td { display: grid; grid-template-columns: 70px minmax(0, 1fr); gap: 8px; padding: 5px 0 5px 42px; min-width: 0; border: 0; overflow-wrap: anywhere; }
    .recipe-schedule-table td::before { content: attr(data-time); color: var(--text-muted); font-variant-numeric: tabular-nums; }
    .recipe-schedule-arrow { display: none; }
}

/* Production flow map. Arrows connect cards across the open spaces between tracks. */
.product-flow-periods { display: flex; flex-wrap: wrap; gap: .3rem; }
.product-flow-periods[hidden] { display: none; }
#product-flow-card:has(.collapse-toggle[aria-expanded="false"]) .plan-results-header { margin-bottom: 0; }
.product-flow-periods button[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.product-flow-periods button:disabled { opacity: .45; }
.product-flow-note { margin: .45rem 0 .8rem; }
.product-flow-content { display: grid; grid-template-columns: minmax(0,1fr); gap: .75rem; }
.product-flow-scroll {
    border: 1px solid var(--border); border-radius: 10px; background-color: var(--bg);
    background-image: radial-gradient(var(--border) 1px, transparent 1px); background-size: 12px 12px;
}
.product-flow-scroll { overflow-x: auto; justify-self: start; width: max-content; max-width: 100%; min-width: 0; }
.product-flow-board { display: grid; grid-auto-flow: column; grid-auto-columns: max-content; width: max-content; gap: 1.1rem max(2.5rem, 40px); padding: .8rem .8rem max(.8rem,var(--flow-route-space,0px)); position: relative; }
.product-flow-board > svg { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.product-flow-board > svg > path { stroke: var(--accent); fill: none; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.product-flow-board > svg > path.flow-line-gap { stroke: var(--bg); stroke-width: 5; }
.product-flow-board > svg > path[data-tone="1"] { stroke: var(--flow-blue, #86ade0); }
.product-flow-board > svg > path[data-tone="2"] { stroke: var(--flow-gold, #cdaa73); }
.product-flow-board > svg > path[data-tone="3"] { stroke: var(--flow-lilac, #b89acb); }
.product-flow-board > svg > path[data-tone="4"] { stroke: var(--flow-coral, #f19c88); }
.product-flow-board > svg > path[data-tone="5"] { stroke: var(--flow-cyan, #6dd3e5); }
.product-flow-board > svg > path[data-tone="6"] { stroke: var(--flow-lime, #bcce77); }
.product-flow-board > svg > path[data-tone="7"] { stroke: var(--flow-pink, #ed9fcd); }
.light .product-flow-board { --flow-blue: #436fa4; --flow-gold: #916a2f; --flow-lilac: #815c94; --flow-coral: #a94935; --flow-cyan: #157482; --flow-lime: #65762d; --flow-pink: #aa477d; }
.product-flow-column { display: grid; grid-row: 1 / -1; grid-template-rows: subgrid; }
.product-flow-column > h3 { margin: 0; font-size: .75rem; font-weight: 600; color: var(--text-muted); }
.flow-chain-stack { position: relative; display: flex; flex-direction: column; justify-content: center; gap: .65rem; }
.product-flow-column + .product-flow-column .flow-chain-stack { justify-content: flex-start; gap: max(1.75rem, 30px); }
.product-flow-node { min-width: 0; width: fit-content; max-width: 100%; padding: 4px .5rem .32rem; background: var(--surface); border: 1px solid var(--border); border-radius: 9px; font-size: .8rem; font-variant-numeric: tabular-nums; }
.product-flow-column .product-flow-node { width: 100%; }
.flow-sale-only { --sale-color: var(--warning); }
.flow-sale-partial { --sale-color: #65baff; --sale-tint: 29%; --sale-border: 85%; }
.light .flow-sale-partial { --sale-color: #3474b8; }
.product-flow-node:is(.flow-sale-only, .flow-sale-partial), .flow-sale-key::before {
    background: color-mix(in srgb, var(--sale-color) var(--sale-tint, 12%), var(--surface));
    border: 1px solid color-mix(in srgb, var(--sale-color) var(--sale-border, 52%), var(--border));
}
.flow-sale-key { display: inline-flex; align-items: center; gap: .33rem; margin-inline-start: .5rem; }
.flow-sale-key::before { content: ''; width: .7rem; height: .7rem; border-radius: .2rem; }
.product-flow-node h4 { display: inline-flex; align-items: center; gap: .15rem; margin: 0; }
.flow-produced { font-size: 1.15rem; line-height: 1; letter-spacing: -.035em; white-space: nowrap; }
.product-flow-icon { display: inline-block; flex: none; width: 32px; height: 32px; background: url('./product-icons.webp') no-repeat; background-size: 512px auto; }
.product-flow-icon[data-tip] { cursor: help; border-radius: 4px; }
.product-flow-icon[data-tip]:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.flow-amount, .flow-reserve, .flow-carry-out-row, .flow-stock-row, .product-flow-total { display: flex; align-items: baseline; justify-content: space-between; gap: .35rem; padding: .15rem 0; }
.flow-amount span, .flow-reserve span, .flow-carry-out-row span, .flow-stock-row span { color: var(--text-muted); }
.flow-ingredients { display: flex; flex-wrap: wrap; align-items: center; gap: .1rem .55rem; margin-top: .2rem; padding-top: .2rem; border-top: 1px solid var(--border); }
.product-flow-column .flow-ingredients { flex-wrap: nowrap; }
.flow-input { display: inline-flex; align-items: center; gap: .1rem; white-space: nowrap; }
.flow-input .product-flow-icon { zoom: .68; }
.flow-sale { display: flex; width: fit-content; max-width: 100%; align-items: center; flex-wrap: wrap; gap: .22rem; padding-left: .95rem; color: var(--text-muted); cursor: help; }
.flow-sale::before { content: ''; width: .5rem; height: .55rem; align-self: flex-start; border: solid var(--border); border-width: 0 0 1.5px 1.5px; border-radius: 0 0 0 3px; }
.flow-coin { width: 18px; height: 18px; object-fit: contain; }
.flow-revenue { color: var(--success); white-space: nowrap; }
.product-flow-total { border-top: 1px solid var(--border); padding: .65rem 0 0; }
.product-flow-total strong { color: var(--accent); }
.product-flow-content .flow-category { margin: .25rem 0 0; font-size: .95rem; }
.flow-node-head { display: grid; grid-template-columns: max-content 1fr; align-items: start; gap: .5rem; }
.flow-facilities { display: flex; align-items: center; justify-self: end; gap: .45rem; margin-right: -3px; }
.flow-tight .flow-facilities { gap: .3rem; }
.flow-switch { display: flex; align-items: center; gap: .35rem; border-top: 1px solid var(--border); margin-top: .2rem; padding-top: .2rem; font-size: .74rem; }
.flow-switch-recipes { display: inline-flex; align-items: center; gap: .15rem; }
.flow-switch-recipes { flex-wrap: wrap; max-width: 9rem; }
.flow-switch-recipes .product-flow-icon { zoom: .72; }
.flow-switch-time { color: var(--success); margin-left: auto; white-space: nowrap; }
.flow-badge { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; font-weight: 400; line-height: 1.1; color: var(--text-muted); white-space: nowrap; }
.flow-badge .production-portrait, .flow-electric-hex { width: 15.6px; height: 18px; }
.flow-electric-hex > svg { display: block; width: 100%; height: 100%; }
.flow-badge .production-portrait-art svg { width: 11px; height: 11px; }

#roster-swaps { margin-top: .85rem; }
#roster-swaps.is-loading #roster-swaps-grid { opacity: .55; transition: opacity .15s ease; }
.roster-swaps-heading { display:flex; flex-wrap:wrap; align-items:center; gap:.5rem .65rem; margin-bottom:.4rem; }
.roster-swaps-heading h3 { margin:0; }
.roster-swaps-heading #roster-swaps-unit { color:var(--text-muted); font-size:.75rem; }
.roster-swaps-toggle { margin-left:auto; display:inline-flex; align-items:center; gap:.35rem; font-size:.75rem; color:var(--text-muted); cursor:pointer; user-select:none; }
.roster-swaps-toggle input { margin:0; accent-color:var(--accent); cursor:pointer; }
#roster-swaps-grid { display:grid; grid-template-columns:repeat(auto-fill, minmax(10.5rem, 1fr)); gap:6px; align-items:stretch; }
.roster-swap { box-sizing:border-box; display:flex; align-items:center; gap:4px; min-width:0; width:100%; padding:4px 8px 4px 6px; border:1px solid var(--border); border-radius:6px; background:var(--surface-2); color:inherit; font:inherit; text-align:left; }
button.roster-swap { cursor:pointer; transition:border-color .14s ease, background .14s ease, transform .08s ease; }
button.roster-swap:hover { border-color:var(--accent); background:color-mix(in srgb, var(--accent) 8%, var(--surface-2)); }
button.roster-swap:focus-visible { outline:2px solid var(--accent); outline-offset:1px; }
button.roster-swap:active { transform:translateY(1px); }
.roster-swap-dialog-body { display:flex; flex-direction:column; gap:.65rem; }
.roster-swap-dialog-visual { display:flex; align-items:center; flex-wrap:wrap; gap:.55rem; padding:.55rem .7rem; border:1px solid var(--border); border-radius:8px; background:var(--surface-2); }
.roster-swap-dialog-side { display:inline-flex; align-items:center; flex-wrap:wrap; gap:.4rem; min-width:0; }
.roster-swap-dialog-member { display:inline-flex; align-items:center; gap:.38rem; font-weight:600; font-size:.88rem; }
.roster-swap-dialog-member .production-portrait { width:1.95rem; }
.roster-swap-dialog-arrow, .roster-swap-dialog-plus { color:var(--text-muted); font-size:1rem; font-weight:600; }
.roster-swap-dialog-effects { display:flex; flex-wrap:wrap; gap:.35rem; align-items:center; }
.roster-swap-dialog-pill { padding:.18rem .5rem; border-radius:999px; border:1px solid var(--border); background:var(--surface-2); font-size:.78rem; font-weight:600; font-variant-numeric:tabular-nums; }
.roster-swap-dialog-pill.is-gain { color:var(--success); border-color:color-mix(in srgb, var(--success) 35%, var(--border)); }
.roster-swap-dialog-pill.is-slots { color:var(--accent); border-color:color-mix(in srgb, var(--accent) 35%, var(--border)); }
.roster-swap-dialog-choices { display:flex; flex-direction:column; gap:.35rem; }
.roster-swap-dialog-choices-label { font-size:.76rem; color:var(--text-muted); font-weight:600; }
.roster-swap-dialog-choice-list { display:flex; flex-wrap:wrap; gap:.35rem; }
.roster-swap-choice { display:inline-flex; align-items:center; gap:.35rem; padding:.24rem .55rem .24rem .35rem; border:1px solid var(--border); border-radius:6px; background:var(--surface-2); color:var(--text); font:inherit; font-size:.8rem; cursor:pointer; }
.roster-swap-choice .production-portrait { width:1.45rem; }
.roster-swap-choice[aria-pressed="true"] { border-color:var(--accent); background:color-mix(in srgb, var(--accent) 14%, var(--surface-2)); font-weight:600; }
.roster-swap-dialog-note { margin:0; font-size:.84rem; color:var(--text-muted); line-height:1.45; }
.confirm-primary-btn { background:var(--accent); border-color:var(--accent); color:#0b111b; font-weight:650; }
.confirm-primary-btn:hover { filter:brightness(1.06); }
.roster-swap .production-portrait { width:1.55rem; }
.roster-swap .production-portrait-art > span { font-size:9px; font-weight:600; }
.roster-swap-group { display:inline-flex; align-items:center; gap:2px; }
.roster-swap-arrow { color:var(--text-muted); font-size:11px; text-align:center; }
.roster-swap-add, .roster-swap-remove { display:inline-flex; align-items:center; justify-content:center; width:1.4rem; height:1.4rem; border-radius:4px; border:1px dashed var(--border); font-size:.82rem; font-weight:700; line-height:1; }
.roster-swap-add { color:var(--accent); }
.roster-swap-remove { color:var(--text-muted); }
.roster-swap-equiv { padding:0 4px; border:1px solid var(--border); border-radius:4px; background:var(--surface); color:var(--text-muted); font-size:.66rem; font-weight:600; line-height:1.4; white-space:nowrap; }
.roster-swap-traits { padding:0 4px; border:1px solid var(--border); border-radius:4px; background:var(--surface); color:var(--text-muted); font-size:.66rem; font-weight:650; line-height:1.45; letter-spacing:.04em; white-space:nowrap; }
.roster-swap-slots { margin-left:auto; padding:0 5px; border-radius:4px; background:color-mix(in srgb, var(--accent) 14%, transparent); color:var(--accent); font-variant-numeric:tabular-nums; font-weight:650; font-size:.72rem; line-height:1.5; white-space:nowrap; }
.roster-swap-slots + .roster-swap-gain { margin-left:2px; }
.roster-swap-fill { margin-left:auto; padding-left:4px; color:var(--text-muted); font-variant-numeric:tabular-nums; font-weight:600; font-size:.74rem; white-space:nowrap; }
.roster-swap-gain { margin-left:auto; padding-left:4px; color:var(--success); font-variant-numeric:tabular-nums; font-weight:650; font-size:.8rem; white-space:nowrap; }


/* ========================================
   UX, Accessibility & Dialog Refinements
   ======================================== */

header h1 {
    font-family: var(--font-body);
    font-weight: 700;
    letter-spacing: -0.03em;
}

.header-buttons {
    align-items: center;
    gap: 0.35rem 0.5rem;
}

.header-buttons .toggle-button {
    min-height: 2.5rem;
    padding: 0.35rem 0.65rem;
    border-radius: 8px;
    text-decoration: none;
    color: var(--text-muted);
    transition: background-color 0.15s, color 0.15s;
}

.header-buttons .toggle-button:hover {
    opacity: 1;
    color: var(--text);
    background: var(--surface-2);
}

.header-buttons .header-select {
    border: 1px solid var(--border-control);
    background: var(--surface);
    color: var(--text);
    padding: 0.35rem 0.6rem;
}

.danger-link:hover {
    color: var(--error);
    opacity: 1;
}

/* Native dialogs for Facilities, Math, and Help modals */
dialog.modal-dialog {
    position: fixed;
    margin: auto;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    width: min(640px, calc(100vw - 1.5rem));
    max-height: calc(100dvh - 2rem);
    overflow: hidden;
}

dialog.modal-dialog.modal-wide {
    width: min(780px, calc(100vw - 1.5rem));
}

dialog.modal-dialog.wide {
    width: min(1100px, calc(100vw - 1.5rem));
}

dialog.modal-dialog[open] {
    display: flex;
    flex-direction: column;
}

dialog.modal-dialog::backdrop {
    background: rgba(8, 12, 22, 0.72);
    backdrop-filter: blur(2px);
}

dialog.modal-dialog .modal-content {
    display: flex;
    flex-direction: column;
    max-width: none;
    max-height: calc(100dvh - 2rem);
    margin: 0;
    border: none;
    background: transparent;
}

dialog.modal-dialog .modal-header {
    flex: 0 0 auto;
    background: var(--surface);
    padding: 0.85rem 1.25rem;
}

dialog.modal-dialog .modal-body {
    flex: 1 1 auto;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 1.25rem;
}

.close-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 2.75rem;
    min-height: 2.75rem;
    border-radius: 8px;
}

.close-button:hover {
    opacity: 1;
    background: var(--surface-2);
}

.facilities-modal-filter {
    max-width: 26rem;
    margin: 0 0 1rem;
}

.confirm-dialog {
    width: min(28rem, calc(100% - 1rem));
}

.confirm-dialog > p {
    margin: 0;
}

.custom-buildings-diff {
    margin: 0.65rem 0 0;
    padding: 0.55rem 0.75rem 0.55rem 1.4rem;
    border-radius: var(--radius);
    background: var(--surface-2);
    font-size: 0.85rem;
    max-height: 11rem;
    overflow-y: auto;
}

.custom-buildings-diff li + li {
    margin-top: 0.2rem;
}

.confirm-danger-btn {
    background: var(--error);
    border-color: var(--error);
    color: #ffffff;
    font-weight: 600;
}

.confirm-danger-btn:hover {
    opacity: 0.9;
    border-color: var(--error);
}

/* RV settings promoted to top of Plan setup */
.planner-rv-settings {
    margin: 0 0 1.1rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
}

/* Share link inline copy & close */
.share-config-row {
    display: flex;
    align-items: center;
    gap: 0.45rem;
}

.share-config-row input {
    flex: 1;
    min-width: 0;
}

.share-config-row .roster-x {
    min-width: 2.5rem;
    min-height: 2.5rem;
}

/* Submit area with Cancel button & dirty indicator */
.planner-submit-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    margin-inline-start: auto;
}

.planner-submit-actions .skip-add-btn {
    min-height: 2.75rem;
}

.optimize-btn.is-dirty {
    box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--accent);
}

/* Stale results banner */
.stale-banner {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.65rem;
    padding: 0.7rem 1rem;
    margin-bottom: 0.85rem;
    border-radius: var(--radius);
    border: 1px solid color-mix(in srgb, var(--warning) 55%, transparent);
    background: color-mix(in srgb, var(--warning) 10%, var(--surface));
    color: var(--text);
    font-size: 0.88rem;
}

.stale-banner button {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--on-accent);
    font-weight: 600;
    min-height: 2.4rem;
}

/* Sticky jump navigation across results */
.results-nav {
    position: sticky;
    top: 0.5rem;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 0.35rem;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scrollbar-width: thin;
    padding: 0.45rem 0.6rem;
    margin-bottom: 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: color-mix(in srgb, var(--surface) 92%, transparent);
    backdrop-filter: blur(8px);
}

.results-nav a {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    min-height: 2.25rem;
    padding: 0.25rem 0.65rem;
    border-radius: 8px;
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--text-muted);
    text-decoration: none;
    white-space: nowrap;
}

.results-nav a:hover {
    background: var(--surface-2);
    color: var(--text);
}

.results-nav a.results-nav-top {
    margin-inline-start: auto;
    color: var(--accent);
}

html {
    scroll-padding-top: 4.25rem;
}

/* Floating undo toast */
.undo-toast {
    position: fixed;
    left: 50%;
    bottom: 1.25rem;
    transform: translateX(-50%);
    z-index: 1200;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    max-width: min(34rem, calc(100vw - 1.5rem));
    padding: 0.65rem 0.9rem;
    border: 1px solid var(--border-control);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.38);
    font-size: 0.88rem;
}

.undo-toast-actions {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    flex-shrink: 0;
}

.undo-toast-actions .skip-add-btn {
    padding: 0.35rem 0.75rem;
    border-color: var(--accent);
    color: var(--accent);
    font-weight: 600;
}

.undo-toast-actions .roster-x {
    min-width: 2rem;
    min-height: 2rem;
}

/* Improved touch targets & separation on priority buttons and skip chips */
.priority-move {
    gap: 0.25rem;
}

.priority-move button {
    width: 2.1rem;
    height: 2.1rem;
    border-color: var(--border-control);
}

.priority-move button[data-remove-priority] {
    margin-inline-start: 0.35rem;
    color: var(--text-muted);
}

.priority-move button[data-remove-priority]:hover {
    border-color: var(--error);
    color: var(--error);
}

.skip-chip button {
    width: 1.75rem;
    height: 1.75rem;
    font-size: 0.8rem;
}

/* Layout display options dropdown & compact zoom toolbar */
.layout-primary-toggles {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.55rem 0.9rem;
}

.layout-options-menu {
    position: relative;
}

.layout-options-menu > summary {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    height: 2rem;
    padding: 0 0.7rem;
    border: 1px solid var(--border-control);
    border-radius: 7px;
    background: var(--surface-2);
    color: var(--text);
    font-size: 0.8rem;
    font-weight: 500;
    list-style: none;
    cursor: pointer;
    user-select: none;
}

.layout-options-menu > summary::-webkit-details-marker {
    display: none;
}

.layout-options-menu > summary::after {
    content: "";
    width: 0.35rem;
    height: 0.35rem;
    border-right: 1.5px solid var(--text-muted);
    border-bottom: 1.5px solid var(--text-muted);
    transform: translateY(-1px) rotate(45deg);
    transition: transform 0.15s;
}

.layout-options-menu[open] > summary {
    border-color: var(--accent);
}

.layout-options-menu[open] > summary::after {
    transform: translateY(1px) rotate(225deg);
}

.layout-options-menu .layout-toggles {
    position: absolute;
    right: 0;
    top: calc(100% + 0.4rem);
    z-index: 25;
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
    min-width: 14.5rem;
    margin: 0;
    padding: 0.7rem 0.85rem;
    border: 1px solid var(--border-control);
    border-radius: 10px;
    background: var(--surface);
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.35);
}

.layout-zoom-controls {
    margin-top: 0.8rem;
    padding-top: 0.65rem;
    border-top: 1px solid var(--border);
    gap: 0.5rem 0.75rem;
}

.layout-zoom-controls [role="group"] {
    display: inline-flex;
    gap: 0;
    border: 1px solid var(--border-control);
    border-radius: 7px;
    overflow: hidden;
    background: var(--surface-2);
}

.layout-zoom-controls button {
    min-height: 2rem;
    min-width: 2rem;
    padding: 0 0.6rem;
    border: 0;
    border-radius: 0;
    background: transparent;
    font-size: 0.82rem;
    line-height: 1;
}

.layout-zoom-controls button + button {
    border-left: 1px solid var(--border);
}

.layout-zoom-controls button:not(:disabled):hover {
    background: color-mix(in srgb, var(--accent) 14%, transparent);
    color: var(--text);
}

.layout-zoom-controls button:disabled {
    opacity: 0.4;
    cursor: default;
}

/* Compact completed solve progress summary */
.solve-progress.is-complete {
    padding: 0.45rem 0.8rem;
    background: var(--surface-2);
}

.solve-progress-details > summary {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.84rem;
    list-style: none;
    cursor: pointer;
    user-select: none;
}

.solve-progress-details > summary::-webkit-details-marker {
    display: none;
}

.solve-progress-summary-text {
    font-weight: 500;
    color: var(--text);
}

.solve-progress-details > summary .step-note {
    margin-inline-start: auto;
    font-size: 0.78rem;
}

.solve-progress-details > summary::after {
    content: "";
    flex: 0 0 auto;
    width: 0.35rem;
    height: 0.35rem;
    margin-inline-start: 0.25rem;
    border-right: 1.5px solid var(--text-muted);
    border-bottom: 1.5px solid var(--text-muted);
    transform: translateY(-1px) rotate(45deg);
}

.solve-progress-details[open] > summary::after {
    transform: translateY(1px) rotate(225deg);
}

.solve-progress-details[open] .progress-steps {
    margin-top: 0.65rem;
    padding-top: 0.6rem;
    border-top: 1px solid var(--border);
}

/* Compact unverified recipe pill inside Plan results */
.unverified-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.2rem 0.6rem;
    border-radius: 999px;
    border: 1px solid color-mix(in srgb, var(--warning) 45%, transparent);
    background: color-mix(in srgb, var(--warning) 10%, var(--surface));
    color: var(--warning);
    font-size: 0.76rem;
    font-weight: 500;
    cursor: help;
}

@media (pointer: coarse) {
    .layout-options-menu > summary {
        height: 2.5rem;
    }
    .layout-zoom-controls button {
        min-height: 2.5rem;
        min-width: 2.5rem;
    }
}

@media (max-width: 37.5rem) {
    .layout-options-menu .layout-toggles {
        left: 0;
        right: auto;
    }
}

.layout-index-group button {
    min-height: 2.25rem;
    padding: 0.3rem 0.6rem;
    border-color: var(--border-control);
}

/* Roster UX: visible short names toggle, personality full-name captions, and Done CTA */
.roster-board-show-names .roster-slot .roster-tile-name {
    position: static;
    width: auto;
    height: auto;
    overflow: hidden;
    clip-path: none;
    text-overflow: ellipsis;
    max-width: 100%;
    font-size: 0.7rem;
    line-height: 1.2;
    margin-top: 0.1rem;
}

.roster-pair-wrap {
    display: grid;
    gap: 0.2rem;
    text-align: center;
}

.roster-pair-caption {
    font-size: 0.66rem;
    color: var(--text-muted);
    line-height: 1.2;
}

.roster-edit-actions .roster-done-btn {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--on-accent);
    font-weight: 600;
}

/* Opportunities action buttons */
.opportunity-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem;
    margin-top: 0.5rem;
}

.opportunity-apply-btn {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--on-accent);
    font-weight: 600;
}

.opportunity-apply-btn:hover {
    opacity: 0.9;
    border-color: var(--accent);
}

/* Ensure collapse-toggle inside h2 keeps underline hover */
h2 .collapse-toggle:hover span:last-child {
    text-decoration: underline;
    text-underline-offset: 3px;
}

@media (max-width: 37.5rem) {
    .planner-submit-actions {
        width: 100%;
    }
    .planner-submit-actions .optimize-btn {
        flex: 1 1 auto;
    }
    .priority-move button {
        width: 2.5rem;
        height: 2.5rem;
    }
    .skip-chip button {
        width: 2.25rem;
        height: 2.25rem;
    }
    .roster-personalities {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
    .undo-toast {
        flex-direction: column;
        align-items: stretch;
        gap: 0.5rem;
    }
    .undo-toast-actions {
        justify-content: flex-end;
    }
}

/* Complete prefers-reduced-motion support */
@media (prefers-reduced-motion: reduce) {
    body,
    .header-buttons .toggle-button,
    .tabs label,
    .collapse-toggle .chevron,
    .switch-track,
    .switch-track::after,
    .layout-flow-line,
    .progress-bar-fill {
        transition: none !important;
    }
    .progress-bar-fill.indeterminate {
        animation: none;
        width: 100%;
        left: 0;
        opacity: 0.65;
    }
}

/* --- Multi-stage setup (T1+C6, Stock & expenses) and staged plan output (P9+P1+M3+M5) --- */
.priority.rich {
    flex-direction: column;
    align-items: stretch;
    gap: 0.55rem;
    padding: 0.65rem 0.8rem;
}
.priority-main-row {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    flex-wrap: wrap;
}
.priority-main-row .priority-move {
    margin-left: auto;
}
.priority-sub-row {
    padding-top: 0.5rem;
    border-top: 1px solid color-mix(in srgb, var(--border) 70%, transparent);
}
.priority-switch.t-switch {
    font-size: 0.82rem;
    color: var(--text);
    gap: 0.55rem;
    align-items: flex-start;
    display: inline-flex;
    cursor: pointer;
    position: relative;
}
.priority-switch.t-switch input {
    position: absolute;
    opacity: 0;
    width: 1px;
    height: 1px;
}
.t-title { display: block; font-weight: 600; color: var(--text); line-height: 1.25; }
.t-sub { display: block; font-size: 0.78rem; color: var(--muted); margin-top: 0.16rem; line-height: 1.38; }

.s-block + .s-block {
    margin-top: 0.85rem;
    padding-top: 0.75rem;
    border-top: 1px solid color-mix(in srgb, var(--border) 65%, transparent);
}
.s-section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    margin-bottom: 0.45rem;
}
.s-section-title {
    margin: 0;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
.expense-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.6rem;
}
.coin-label {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.82rem;
    color: var(--text);
}
.coin-label img {
    width: 16px;
    height: 16px;
    object-fit: contain;
    flex: none;
}
.s-num-input {
    width: 6.5rem;
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 7px;
    padding: 0.28rem 0.48rem;
    font-size: 0.82rem;
    font-variant-numeric: tabular-nums;
    text-align: right;
    box-sizing: border-box;
}
.s-num-input:focus { outline: none; border-color: var(--accent); }

.core-stock-3 {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.45rem;
}
.core-item {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    padding: 0.42rem 0.5rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
}
.core-item-head {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.76rem;
    color: var(--muted);
    min-width: 0;
}
.core-item-head span:last-child {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.core-item-head img {
    width: 18px;
    height: 18px;
    object-fit: contain;
    flex: none;
}
.core-item .s-num-input {
    width: 100%;
    padding: 0.22rem 0.38rem;
    font-size: 0.8rem;
}
.s-input {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 7px;
    padding: 0.34rem 0.55rem;
    font-size: 0.82rem;
    width: 100%;
    box-sizing: border-box;
}
.s-input:focus { outline: none; border-color: var(--accent); }

.icon-clear-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    padding: 0;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--muted);
    cursor: pointer;
}
.icon-clear-btn[hidden] { display: none; }
.icon-clear-btn:hover {
    border-color: #e06c75;
    color: #e06c75;
    background: color-mix(in srgb, #e06c75 10%, var(--surface));
}

dialog.confirm-dialog {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem 1.1rem;
    width: min(90vw, 20rem);
    box-shadow: 0 12px 32px rgba(0,0,0,0.55);
}
dialog.confirm-dialog::backdrop { background: rgba(0,0,0,0.6); }
.confirm-dialog h3 { margin: 0 0 0.35rem; font-size: 0.96rem; }
.confirm-dialog p { margin: 0 0 0.85rem; font-size: 0.82rem; color: var(--muted); }
.confirm-actions { display: flex; justify-content: flex-end; gap: 0.45rem; }
.confirm-btn {
    padding: 0.32rem 0.72rem;
    border-radius: 7px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text);
    font-size: 0.8rem;
    cursor: pointer;
}
.confirm-btn:hover { border-color: var(--accent); }
.confirm-btn.danger {
    background: #c94a54;
    border-color: #c94a54;
    color: #fff;
    font-weight: 600;
}
.confirm-btn.danger:hover { filter: brightness(1.08); }

.item-sprite {
    display: inline-block;
    flex: none;
    background: url('./product-icons.webp') no-repeat;
}
.stock-cat-group + .stock-cat-group { margin-top: 0.65rem; }
.stock-cat-title {
    margin: 0 0 0.35rem;
    font-size: 0.74rem;
    font-weight: 600;
    color: var(--muted);
}
.inv-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem;
    align-items: stretch;
}
.inv-slot {
    position: relative;
    width: 68px;
    padding: 0.4rem 0.28rem 0.3rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    gap: 0.28rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 9px;
    transition: border-color 0.12s;
}
.inv-slot:hover { border-color: var(--accent); }
.inv-slot .inv-x {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 16px;
    height: 16px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 0;
    border-radius: 999px;
    background: var(--surface-2);
    color: var(--muted);
    font-size: 0.65rem;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.12s;
}
.inv-slot:hover .inv-x,
.inv-slot:focus-within .inv-x { opacity: 1; }
.inv-slot .inv-x:hover { color: var(--text); background: var(--border); }

.inv-num {
    width: 100%;
    text-align: center;
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid transparent;
    border-radius: 5px;
    padding: 0.14rem 0.2rem;
    font-size: 0.76rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    -moz-appearance: textfield;
    box-sizing: border-box;
}
.inv-num:focus { outline: none; border-color: var(--accent); background: var(--bg); }
.inv-num::-webkit-outer-spin-button,
.inv-num::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.inv-add-tile {
    width: 68px;
    min-height: 76px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.15rem;
    background: transparent;
    color: var(--muted);
    border: 1.5px dashed var(--border);
    border-radius: 9px;
    cursor: pointer;
    font-size: 1.35rem;
    line-height: 1;
}
.inv-add-tile span { font-size: 0.66rem; }
.inv-add-tile:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: color-mix(in srgb, var(--accent) 8%, transparent);
}

dialog.backpack-modal {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    width: min(94vw, 36rem);
    box-shadow: 0 12px 36px rgba(0,0,0,0.55);
}
dialog.backpack-modal::backdrop { background: rgba(0,0,0,0.6); }
.modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.6rem;
}
.modal-head h3 { margin: 0; font-size: 1rem; }
.bp-cats {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
    margin-top: 0.5rem;
}
.bp-cat-chip {
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 0.22rem 0.6rem;
    font-size: 0.74rem;
    cursor: pointer;
}
.bp-cat-chip:hover { border-color: var(--accent); }
.bp-cat-chip[aria-pressed="true"] {
    background: var(--accent);
    color: var(--bg);
    border-color: var(--accent);
    font-weight: 600;
}
.bp-scroll {
    max-height: 20rem;
    overflow-y: auto;
    margin-top: 0.55rem;
    padding-right: 0.2rem;
}
.bp-group + .bp-group { margin-top: 0.75rem; }
.bp-group-title {
    margin: 0 0 0.35rem;
    font-size: 0.74rem;
    font-weight: 600;
    color: var(--muted);
}
.picker-icons {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(48px, 1fr));
    gap: 0.35rem;
}
.picker-icon-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.35rem;
    border-radius: 7px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    cursor: pointer;
}
.picker-icon-btn:hover {
    border-color: var(--accent);
    background: color-mix(in srgb, var(--accent) 12%, var(--surface-2));
}

.item-tooltip {
    position: fixed;
    z-index: 9999;
    pointer-events: none;
    width: max-content;
    max-width: 24rem;
    padding: 0.55rem 0.7rem;
    border-radius: 9px;
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    box-shadow: 0 8px 24px rgba(0,0,0,0.45);
    font-size: 0.78rem;
    line-height: 1.35;
}
.tt-head { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.35rem; }
.tt-name { font-weight: 700; font-size: 0.84rem; color: var(--text); }
.tt-meta { font-size: 0.72rem; color: var(--muted); }
.tt-sec {
    margin-top: 0.35rem;
    padding-top: 0.35rem;
    border-top: 1px solid color-mix(in srgb, var(--border) 60%, transparent);
}
.tt-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--accent);
    font-weight: 600;
    margin-bottom: 0.2rem;
}
.tt-chains { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.28rem; }
.tt-chain-row { display: flex; align-items: center; flex-wrap: wrap; gap: 0.25rem; }
.tt-chain-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.28rem;
    padding: 0.14rem 0.4rem 0.14rem 0.25rem;
    border-radius: 6px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    font-size: 0.72rem;
    color: var(--text);
}
.tt-recipe-row { display: flex; align-items: center; flex-wrap: wrap; gap: 0.3rem; }
.tt-ing-slot {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.18rem 0.42rem 0.18rem 0.24rem;
    border-radius: 7px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    font-size: 0.74rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    color: var(--text);
}
.tt-arrow { color: var(--muted); font-size: 0.72rem; }
.tt-more { margin-top: 0.25rem; font-size: 0.72rem; color: var(--muted); }

.plan-output-card { margin-bottom: 1rem; }
.p9-kpis {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr));
    gap: 0.55rem;
    margin-bottom: 0.85rem;
}
.p9-kpi {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 0.14rem;
    padding: 0.65rem 0.82rem;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--surface-2);
}
.p9-kpi[title] {
    cursor: help;
    transition: border-color 0.14s ease;
}
.p9-kpi[title]:hover {
    border-color: color-mix(in srgb, var(--accent) 45%, var(--border));
}
.p9-kpi .kpi-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.4rem;
}
.p9-kpi .kpi-lbl { display: block; font-size: 0.72rem; color: var(--muted); }
.p9-kpi .kpi-pill {
    font-size: 0.68rem;
    font-weight: 700;
    line-height: 1;
    padding: 0.16rem 0.42rem;
    border-radius: 999px;
    background: color-mix(in srgb, var(--accent) 16%, transparent);
    color: var(--accent);
    border: 1px solid color-mix(in srgb, var(--accent) 32%, transparent);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}
.p9-kpi .kpi-val {
    display: inline-flex;
    align-items: baseline;
    flex-wrap: nowrap;
    gap: 0.24rem;
    font-size: 1.06rem;
    font-weight: 700;
    color: var(--accent);
    font-variant-numeric: tabular-nums;
}
.p9-kpi.is-neutral .kpi-val { color: var(--text); }
.p9-kpi .kpi-unit { font-size: 0.76rem; font-weight: 600; color: var(--muted); }
.p9-kpi .kpi-sub {
    display: inline-flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.34rem;
    font-size: 0.72rem;
    font-weight: 600;
    line-height: 1.2;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
}
.p9-kpi .kpi-sub-item {
    display: inline-flex;
    align-items: center;
    gap: 0.16rem;
}
.p9-kpi .kpi-sub-sep {
    opacity: 0.55;
}
.p9-kpi .kpi-sub-ico {
    width: 11px;
    height: 11px;
    display: block;
    flex: none;
    opacity: 0.78;
    transform: translateY(-0.5px);
}

.p1-tabs { display: flex; flex-wrap: wrap; gap: 0.38rem; margin-bottom: 0.85rem; }
.p1-tab {
    display: flex; flex-direction: column; align-items: flex-start; gap: 0.1rem;
    padding: 0.44rem 0.75rem; border-radius: 8px; border: 1px solid var(--border);
    background: var(--surface-2); color: var(--text); cursor: pointer; font-size: 0.8rem;
}
.p1-tab span { font-size: 0.7rem; color: var(--muted); }
.p1-tab:hover { border-color: var(--accent); }
.p1-tab[aria-selected="true"] { background: var(--accent); color: var(--bg); border-color: var(--accent); }
.p1-tab[aria-selected="true"] span { color: var(--bg); opacity: 0.88; }

.m3-groups { display: flex; flex-direction: column; gap: 0.75rem; }
.m3-title { margin: 0 0 0.38rem; font-size: 0.74rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); }
.slots-wrap { display: flex; flex-wrap: wrap; gap: 0.55rem; align-items: stretch; }
.fac-icon { object-fit: contain; flex: none; border-radius: 6px; }
.pet-icon { object-fit: cover; flex: none; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); }
.icon-dim { opacity: 0.52; filter: grayscale(0.25); }
.swap-arrow { color: var(--muted); font-size: 0.82rem; font-weight: 700; flex: none; }

.tag-badge { display: inline-flex; align-items: center; padding: 0.1rem 0.38rem; border-radius: 5px; font-size: 0.68rem; font-weight: 700; white-space: nowrap; }
.tag-add { background: color-mix(in srgb, #3fa66b 18%, var(--surface)); color: #56c285; }
.tag-swap { background: color-mix(in srgb, #e5a93c 18%, var(--surface)); color: #e5a93c; }
.tag-remove { background: color-mix(in srgb, #e06c75 18%, var(--surface)); color: #e06c75; }
.tag-up { background: color-mix(in srgb, #5b9bd5 18%, var(--surface)); color: #7cb7eb; }
.sprite-wrap { position: relative; display: inline-flex; align-items: center; justify-content: center; flex: none; }
.sprite-var-tag {
    position: absolute; right: -3px; bottom: -3px;
    min-width: 14px; height: 14px; padding: 0 3px;
    border-radius: 4px; background: var(--surface); border: 1px solid var(--border);
    color: var(--accent); font-size: 0.58rem; font-weight: 800; line-height: 12px; text-align: center;
}
.sprite-fallback {
    display: inline-flex; align-items: center; justify-content: center; flex: none;
    border-radius: 7px; border: 1px solid var(--border);
    background: var(--surface); color: var(--muted);
    font-size: 0.72rem; font-weight: 700; letter-spacing: 0.02em;
}

.m5-slot {
    position: relative; min-width: 7.4rem; max-width: 11.5rem;
    padding: 0.65rem 0.55rem 0.45rem; border-radius: 10px;
    border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
    display: flex; flex-direction: column; align-items: center; justify-content: space-between; gap: 0.35rem;
    text-align: center; cursor: pointer; transition: border-color 0.12s, opacity 0.12s;
}
.m5-slot:hover { border-color: var(--accent); }
.m5-slot.is-done { opacity: 0.52; border-color: #3fa66b; background: color-mix(in srgb, #3fa66b 8%, var(--surface-2)); }
.m5-slot .m-corner { position: absolute; top: 5px; right: 5px; }
.m1-visual { display: flex; align-items: center; justify-content: center; gap: 0.35rem; min-height: 44px; padding-top: 0.35rem; }
.m1-title { font-size: 0.76rem; font-weight: 600; color: var(--text); line-height: 1.25; }
.m1-sub { font-size: 0.69rem; color: var(--muted); }

.stage-prod-box {
    margin-top: 0.9rem; padding: 0.75rem 0.85rem; border-radius: 9px;
    border: 1px solid var(--border); background: var(--surface-2);
}
.p-chips-row { display: flex; flex-wrap: wrap; gap: 0.38rem; align-items: center; }
.p-pill {
    display: inline-flex; align-items: center; gap: 0.32rem; padding: 0.2rem 0.52rem;
    border-radius: 7px; border: 1px solid var(--border); background: var(--surface);
    color: var(--text); font-size: 0.76rem; font-variant-numeric: tabular-nums;
}
.p-pill.accent { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, var(--surface)); }

@media (max-width: 540px) {
    .core-stock-3 { grid-template-columns: 1fr; }
}

/* --- New Plan Setup & Settings Modals (Variant #5 UX) --- */
.setup-card-head {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    align-items: center;
    gap: 0.75rem;
}
.setup-card-head .setup-head-left { justify-self: start; }
.setup-card-head .config-actions { justify-self: end; }
.setup-brand-word {
    justify-self: center;
    margin: 0;
    font-size: 1.24rem;
    font-weight: 800;
    letter-spacing: -0.025em;
    line-height: 1.1;
    color: var(--text);
    display: inline-flex;
    align-items: baseline;
}
.setup-brand-sup {
    font-size: 0.62rem;
    font-weight: 800;
    margin-left: 2px;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    transform: translateY(-0.38em);
}
@media (max-width: 820px) {
    .setup-card-head { grid-template-columns: auto 1fr; gap: 0.5rem 0.75rem; }
    .setup-brand-word { grid-column: 1 / -1; grid-row: 1; justify-self: center; }
    .setup-card-head .setup-head-left { grid-row: 2; justify-self: start; }
    .setup-card-head .config-actions { grid-row: 2; justify-self: end; }
}
.setup-head-left { display: flex; flex-wrap: wrap; align-items: center; gap: 0.45rem; }
.setup-head-left .header-pill-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.34rem;
    height: 30px;
    min-height: 0;
    padding: 0 0.68rem;
    border-radius: 9px;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    font-size: 0.8rem;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    transition: border-color 0.14s, color 0.14s, background 0.14s;
}
.setup-head-left .header-pill-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: color-mix(in srgb, var(--accent) 8%, var(--bg));
}
.setup-head-left .header-pill-btn.danger-link {
    color: var(--muted);
}
.setup-head-left .header-pill-btn.danger-link:hover {
    border-color: rgba(239, 68, 68, 0.5);
    color: #dc2626;
    background: rgba(239, 68, 68, 0.08);
}
:root:not(.light) .setup-head-left .header-pill-btn.danger-link:hover {
    color: #fca5a5;
}
.header-pill-ico {
    width: 13px;
    height: 13px;
    flex: none;
    opacity: 0.82;
}
.rv-inline-label { font-size: 0.83rem; font-weight: 600; color: var(--muted); }
.setup-util-sep { width: 1px; height: 1.1rem; background: var(--border); margin: 0 0.12rem; }
.config-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 0.42rem; }
.header-select.compact-lang {
    padding: 0.22rem 0.45rem; font-size: 0.76rem; min-height: unset; border-radius: 7px;
}
.theme-icon-btn {
    padding: 0.22rem 0.48rem !important; font-size: 0.82rem !important; line-height: 1.2;
}

.rv-stepper {
    display: inline-flex; align-items: center; background: var(--bg);
    border: 1px solid var(--border); border-radius: 9px; overflow: hidden;
}
.rv-stepper:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 22%, transparent);
}
.rv-stepper .rv-step-btn {
    border: none; background: transparent; color: var(--text);
    width: 1.9rem; height: 100%; min-height: 0; font-size: 0.96rem; font-weight: 600;
    cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
}
.rv-stepper .rv-step-btn:hover:not(:disabled) { background: color-mix(in srgb, var(--border) 40%, transparent); }
.rv-stepper .rv-step-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.rv-stepper .rv-number {
    width: 2.9rem; height: 1.95rem; padding: 0 0.2rem; border: none;
    border-inline: 1px solid var(--border); border-radius: 0;
    background: var(--surface); color: var(--text); text-align: center;
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.06);
    font-size: 0.88rem; font-weight: 700; font-variant-numeric: tabular-nums;
    cursor: text; appearance: textfield; -moz-appearance: textfield; transition: background 0.12s, box-shadow 0.12s;
}
.rv-stepper .rv-number:hover { background: color-mix(in srgb, var(--accent) 6%, var(--surface)); }
.rv-stepper .rv-number:focus {
    outline: none;
    background: color-mix(in srgb, var(--accent) 10%, var(--surface));
    box-shadow: inset 0 0 0 1.5px var(--accent);
}
.rv-stepper .rv-number::-webkit-outer-spin-button,
.rv-stepper .rv-number::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.rv-picker-wrap { position: relative; display: inline-flex; }
.rv-picker-popover {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    z-index: 60;
    display: grid;
    grid-template-columns: repeat(6, 2rem);
    gap: 4px;
    padding: 8px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--surface);
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.18);
}
.rv-picker-popover[hidden] { display: none; }
.rv-pick-btn {
    width: 2rem;
    height: 2rem;
    padding: 0;
    border-radius: 7px;
    border: 1px solid transparent;
    background: var(--surface-2, var(--bg));
    color: var(--text);
    font-size: 0.8rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    cursor: pointer;
    display: grid;
    place-items: center;
    transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.rv-pick-btn:hover {
    border-color: var(--accent);
    background: color-mix(in srgb, var(--accent) 12%, var(--surface));
    color: var(--accent);
}
.rv-pick-btn[aria-selected="true"] {
    background: var(--accent);
    color: var(--on-accent, #ffffff);
    border-color: var(--accent);
}

.goals-col { display: flex; flex-direction: column; gap: 0.68rem; }
.ux-box {
    background: var(--bg); border: 1px solid var(--border); border-radius: 10px;
    padding: 0.78rem 0.92rem; display: flex; flex-direction: column; gap: 0.68rem;
}
.ux-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.5rem 0.85rem; }
.ux-route-row { justify-content: flex-start; gap: 0.5rem 0.55rem; }
.ux-route-from { display: inline-flex; align-items: center; gap: 0.55rem; flex-wrap: nowrap; }
.ux-route-to { display: inline-flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.ux-route-row .rv-stepper,
.ux-route-row #goals-rv-tabs { height: 32px; box-sizing: border-box; }
.ux-route-row .rv-stepper .rv-number { height: 100%; min-height: 0; }
.ux-route-row #goals-rv-tabs { display: inline-flex; align-items: center; }
.ux-route-row #goals-rv-tabs button { height: 100%; min-height: 0; display: inline-flex; align-items: center; padding-block: 0; }
.ux-route-sep { font-size: 0.82rem; font-weight: 600; color: var(--muted); }
.ux-route-row.locked .ux-route-sep { display: none; }
.ux-route-row.locked #goals-rv-tabs { opacity: 0.78; }
#goals-rv-tabs.locked button:disabled { opacity: 1; color: var(--muted); }
.ux-field-lbl { font-size: 0.83rem; font-weight: 600; color: var(--text); }
.ux-dashed { border-top: 1px dashed color-mix(in srgb, var(--border) 80%, transparent); padding-top: 0.68rem; }
.ux-divider { border-top: 1px solid color-mix(in srgb, var(--border) 72%, transparent); padding-top: 0.68rem; }

.tabs.compact button {
    border: none; background: transparent; color: var(--muted);
    padding: 0.28rem 0.64rem; border-radius: 7px; font-size: 0.81rem; font-weight: 600;
    cursor: pointer; transition: background 0.12s, color 0.12s;
}
.tabs.compact button:hover:not(:disabled) { color: var(--text); }
.tabs.compact button[aria-pressed="true"] {
    background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.22);
}
.tabs.compact button:disabled { opacity: 0.45; cursor: not-allowed; }
.tabs.compact.locked { opacity: 0.45; pointer-events: none; }

.ux-switch-row { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; cursor: pointer; }
.ux-switch-row.disabled { opacity: 0.45; cursor: not-allowed; }
.ux-switch-text { display: flex; flex-direction: column; gap: 0.12rem; }
.ux-switch-title { font-size: 0.84rem; font-weight: 600; color: var(--text); line-height: 1.3; }
.ux-switch-sub { font-size: 0.75rem; color: var(--muted); line-height: 1.35; }
.ux-switch { position: relative; flex: none; width: 38px; height: 22px; }
.ux-switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.ux-switch-track {
    position: absolute; inset: 0; border-radius: 999px;
    background: color-mix(in srgb, var(--border) 90%, var(--bg));
    border: 1px solid var(--border); transition: background 0.16s, border-color 0.16s;
}
.ux-switch-track::after {
    content: ''; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px;
    border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.28);
    transition: transform 0.16s;
}
.ux-switch input:checked + .ux-switch-track { background: var(--accent); border-color: var(--accent); }
.ux-switch input:checked + .ux-switch-track::after { transform: translateX(16px); }
.ux-switch input:focus-visible + .ux-switch-track { outline: 2px solid var(--accent); outline-offset: 2px; }

.ux-pill-toggle {
    display: inline-flex; align-items: center; gap: 0.36rem;
    border: 1px solid var(--border); background: var(--surface); color: var(--text);
    border-radius: 999px; padding: 0.32rem 0.76rem; font-size: 0.81rem; font-weight: 600;
    cursor: pointer; transition: border-color 0.12s, background 0.12s;
}
.ux-pill-toggle:hover { border-color: var(--accent); }
.ux-pill-toggle[aria-pressed="true"] {
    background: color-mix(in srgb, var(--accent) 18%, var(--surface));
    border-color: var(--accent);
}
.pill-sprite {
    display: inline-block; flex: none; width: 18px; height: 18px;
    background: url('./product-icons.webp') no-repeat; background-size: 288px auto;
}

.settings-list { display: flex; flex-direction: column; gap: 0.44rem; }
.settings-row {
    width: 100%; border: 1px solid var(--border); background: var(--bg); color: var(--text);
    border-radius: 9px; padding: 0.62rem 0.82rem; display: flex; align-items: center;
    justify-content: space-between; gap: 0.5rem; cursor: pointer; text-align: left;
    transition: border-color 0.12s, background 0.12s;
}
.settings-row:hover { border-color: var(--accent); background: color-mix(in srgb, var(--surface) 75%, var(--bg)); }
.settings-row[hidden] { display: none; }
.settings-row-title { font-size: 0.86rem; font-weight: 600; }
.settings-row-right { display: flex; align-items: center; gap: 0.5rem; }
.acc-summary { font-size: 0.77rem; color: var(--muted); }
.acc-summary.modified {
    color: var(--accent); font-weight: 600;
    background: color-mix(in srgb, var(--accent) 14%, transparent);
    padding: 0.12rem 0.48rem; border-radius: 999px;
}

dialog.settings-dialog,
dialog.backpack-modal,
dialog.confirm-dialog,
dialog.modal-dialog {
    position: fixed;
    inset: 0;
    margin: auto;
}
dialog.settings-dialog {
    background: var(--surface); color: var(--text); border: 1px solid var(--border);
    border-radius: 14px; padding: 0; max-width: 640px; width: calc(100% - 2rem);
    max-height: min(86vh, 760px); box-shadow: 0 22px 54px rgba(0, 0, 0, 0.5); overflow: hidden;
}
dialog#modal-team.settings-dialog { max-width: 500px; }
dialog.settings-dialog.confirm-dialog {
    max-width: 420px;
    width: calc(100% - 2rem);
    padding: 0;
    border-radius: 14px;
    box-shadow: 0 22px 54px rgba(0, 0, 0, 0.5);
}
dialog.settings-dialog.confirm-dialog .dlg-body { gap: 0.55rem; }
dialog.settings-dialog.confirm-dialog .dlg-body > p { margin: 0; font-size: 0.86rem; line-height: 1.45; }
.dlg-foot {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    padding: 0.15rem 1.15rem 1rem;
}
.dlg-foot .skip-add-btn {
    min-height: 2.25rem;
    padding: 0.4rem 0.95rem;
    border-radius: 9px;
}
#modal-team .dlg-head-left { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; }
#modal-team .planner-team-options {
    width: auto; max-width: none; margin: 0; padding: 2px; border-radius: 9px;
    background: var(--bg); border: 1px solid var(--border);
}
#modal-team .planner-team-options label {
    min-height: 0; padding: 0.28rem 0.72rem; font-size: 0.8rem; border-radius: 7px;
}
#modal-team #aniimo-setup-hint { display: none; }
#modal-team .ability-levels { grid-template-columns: repeat(2, minmax(0, 1fr)); }
#modal-team .roster-cards { width: 100%; max-width: none; }
#modal-team #roster-filter { flex: 1; max-width: none; width: auto; min-width: 140px; }
dialog.settings-dialog[open] { display: flex; flex-direction: column; }
dialog.settings-dialog::backdrop,
dialog.backpack-modal::backdrop,
dialog.confirm-dialog::backdrop {
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(3px);
}
.dlg-head {
    display: flex; align-items: center; justify-content: space-between; gap: 0.75rem;
    padding: 0.95rem 1.15rem 0.45rem;
}
.dlg-title {
    margin: 0; padding: 0; border: none; font-size: 1.05rem; font-weight: 700; color: var(--text);
}
.dlg-title::after { display: none; }
.dlg-body { padding: 0.55rem 1.15rem 1rem; overflow-y: auto; display: flex; flex-direction: column; gap: 0.85rem; }
.dlg-body .planner-editor-panel {
    border: none; background: transparent; padding: 0; margin: 0; box-shadow: none;
}
dialog.settings-dialog input[type="number"]:not(.rv-number),
dialog.settings-dialog input[type="search"],
dialog.settings-dialog input[type="text"],
dialog.settings-dialog select {
    background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: 7px;
}
dialog.settings-dialog .rv-stepper .rv-number {
    border: none; border-inline: 1px solid var(--border); border-radius: 0; background: transparent;
}
dialog.settings-dialog input:focus,
dialog.settings-dialog select:focus {
    outline: none; border-color: var(--accent);
}
.dlg-foot {
    display: flex; align-items: center; justify-content: flex-end; gap: 0.6rem;
    padding: 0.75rem 1.15rem; border-top: 1px solid var(--border); background: var(--bg);
}
.dlg-done-btn {
    width: auto; border: none; border-radius: 8px; padding: 0.45rem 1.2rem;
    background: var(--accent); color: #0e141b; font-size: 0.85rem; font-weight: 700;
    cursor: pointer; transition: filter 0.12s;
}
.dlg-done-btn:hover { filter: brightness(1.08); }
.config-actions .tabs.compact { min-height: 0; padding: 2px; border-radius: 8px; }
.config-actions .tabs.compact button {
    min-height: 0; height: 24px; padding: 0 0.48rem; line-height: 1;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 0.74rem; text-decoration: none;
}

/* Compact rv-stepper + Season modal polish */
.rv-stepper.sm { border-radius: 7px; }
.rv-stepper.sm .rv-step-btn { width: 1.55rem; height: 1.55rem; font-size: 0.88rem; }
.rv-stepper.sm .rv-number { width: 2.2rem; height: 1.55rem; font-size: 0.8rem; }
.season-sections { display: flex; flex-direction: column; gap: 0.72rem; }
.dlg-section {
    background: var(--bg); border: 1px solid var(--border); border-radius: 10px;
    padding: 0.72rem 0.85rem; display: flex; flex-direction: column; gap: 0.55rem;
}
.dlg-sec-title {
    margin: 0; font-size: 0.73rem; font-weight: 700; color: var(--muted);
    text-transform: uppercase; letter-spacing: 0.04em;
}
.dlg-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; }
.season-crop-card {
    padding: 0.2rem 0; display: flex; align-items: center; justify-content: space-between;
    gap: 0.5rem; font-size: 0.84rem; font-weight: 500;
}
.season-notes-grid {
    display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.42rem 0.75rem;
}
@media (max-width: 520px) {
    .dlg-grid-2, .season-notes-grid { grid-template-columns: 1fr; }
}
.rv-route-left { display: inline-flex; align-items: center; gap: 0.5rem; }
.rv-route-arrow { color: var(--muted); font-weight: 700; }
.rv-route-arrow.locked { opacity: 0.45; }
.goals-col .planner-submit-actions { width: 100%; justify-content: stretch; }
.goals-col .optimize-btn { width: 100%; max-width: none; flex: 1; }
dialog .roster-x, #ms-bp-close, dialog .close-button { text-decoration: none !important; }

/* Clean progress indicator */
.solve-simple-head {
    display: flex; align-items: center; justify-content: space-between; gap: 0.6rem;
    font-size: 0.84rem; font-weight: 600; color: var(--text); margin-bottom: 0.45rem;
}
.solve-simple-left { display: inline-flex; align-items: center; gap: 0.45rem; min-width: 0; }
.solve-pct { color: var(--accent); font-variant-numeric: tabular-nums; }
.solve-bar {
    height: 6px; border-radius: 999px; background: color-mix(in srgb, var(--border) 60%, var(--bg));
    overflow: hidden;
}
.solve-bar-fill {
    height: 100%; border-radius: 999px; background: var(--accent);
    transition: width 0.35s ease;
}

/* Stock & income modal layout */
.stock-sections { display: flex; flex-direction: column; gap: 0.72rem; }
.quest-item {
    display: flex; flex-direction: column; gap: 0.32rem; font-size: 0.8rem; cursor: pointer;
}
.quest-item .s-num-input { width: 100%; }

/* Team -> My Aniimo (Variant #4 inside modal, no outer border) */
#modal-team #roster-config {
    border: none; background: transparent; padding: 0; margin: 0; box-shadow: none;
}
#modal-team #roster-config > summary { display: none; }
#modal-team .roster-editor-layout {
    display: flex; flex-direction: column; gap: 0.72rem; grid-template-columns: none;
}
.roster-topbar {
    display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem;
}
#modal-team #roster-filter {
    flex: 1; min-width: 170px; padding: 0.36rem 0.65rem; font-size: 0.82rem;
}
.roster-names-switch {
    display: inline-flex; align-items: center; gap: 0.45rem; margin-left: auto;
    font-size: 0.8rem; font-weight: 600; color: var(--text); cursor: pointer; white-space: nowrap;
}
.roster-bottombar {
    display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.45rem 0.7rem;
    padding-top: 0.55rem; border-top: 1px dashed color-mix(in srgb, var(--border) 80%, transparent);
}
.roster-bottombar .skip-add-btn { white-space: nowrap; flex-shrink: 0; }
.roster-bottombar p { margin: 0; flex: 1 1 14rem; line-height: 1.35; }
#modal-team .roster-dialog { position: fixed; inset: 0; margin: auto; }

.footer-links { display: flex; flex-wrap: wrap; justify-content: center; gap: 0.75rem; margin-bottom: 0.35rem; }
.footer-links .toggle-button { padding: 0.2rem 0.55rem; font-size: 0.76rem; }


/* Results UX: Variant 2 progress track + Variant 10 semantic tabs */
.results-tabs-bar {
    position: sticky;
    top: 0.45rem;
    z-index: 20;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem 0.75rem;
    padding: 0.45rem 0.65rem;
    background: color-mix(in srgb, var(--surface) 92%, transparent);
    backdrop-filter: blur(8px);
    border: 1px solid var(--border);
    border-radius: 11px;
    margin-bottom: 0.9rem;
}
.results-tabs-bar[hidden] { display: none; }
.results-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
}
.results-tab {
    border: 1px solid transparent;
    background: transparent;
    color: var(--muted);
    border-radius: 7px;
    padding: 0.34rem 0.78rem;
    font-size: 0.84rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.results-tab:hover {
    color: var(--text);
    background: color-mix(in srgb, var(--border) 30%, transparent);
}
.results-tab[aria-selected="true"] {
    background: color-mix(in srgb, var(--accent) 16%, var(--bg));
    color: var(--accent);
    border-color: color-mix(in srgb, var(--accent) 45%, var(--border));
}
@media (max-width: 640px) {
    .results-tabs-bar {
        padding: 0.35rem 0.45rem;
        top: 0.3rem;
        overflow: hidden;
    }
    .results-tabs-bar[data-scroll-left="1"]::before,
    .results-tabs-bar[data-scroll-right="1"]::after {
        content: '';
        position: absolute;
        top: 0;
        bottom: 0;
        width: 30px;
        pointer-events: none;
        z-index: 2;
    }
    .results-tabs-bar[data-scroll-left="1"]::before {
        left: 0;
        background:
            url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M7.5 2.5L4 6l3.5 3.5' fill='none' stroke='%236b7280' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") no-repeat 6px center / 12px 12px,
            linear-gradient(90deg, var(--surface) 45%, transparent);
    }
    .results-tabs-bar[data-scroll-right="1"]::after {
        right: 0;
        background:
            url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M4.5 2.5L8 6l-3.5 3.5' fill='none' stroke='%236b7280' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") no-repeat right 6px center / 12px 12px,
            linear-gradient(270deg, var(--surface) 45%, transparent);
    }
    .results-tabs {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        width: 100%;
        gap: 0.22rem;
        scroll-snap-type: x proximity;
    }
    .results-tabs::-webkit-scrollbar {
        display: none;
    }
    .results-tab {
        flex: 0 0 auto;
        white-space: nowrap;
        scroll-snap-align: center;
        padding: 0.32rem 0.62rem;
        font-size: 0.81rem;
    }
}
.results-rate-toggle {
    width: auto;
    max-width: none;
    margin: 0;
}
.results-rate-toggle button {
    height: 28px;
    min-height: 0;
    padding: 0 0.65rem;
    font-size: 0.78rem;
}
.results-panel {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}
.results-panel[hidden] { display: none; }
.setup-only .results-tabs-bar { display: none !important; }
.setup-only [data-results-panel="base"] { display: flex !important; }
.setup-only [data-results-panel="base"] #layout-card { display: none !important; }

#multi-stage-card .p1-tabs {
    display: flex;
    align-items: stretch;
    gap: 0.65rem;
    flex-wrap: nowrap;
    overflow-x: auto;
    margin-bottom: 0;
}
#multi-stage-card .p1-tab {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    justify-content: space-between;
    text-align: left;
    flex: 1 1 0;
    min-width: 132px;
    padding: 0.48rem 0.56rem 0.42rem;
}
.ms-step-bar {
    display: block;
    height: 4px;
    border-radius: 99px;
    background: var(--border);
    margin-top: 0.36rem;
    overflow: hidden;
}
.ms-step-bar > i {
    display: block;
    height: 100%;
    background: var(--accent);
    transition: width 0.2s ease;
}


/* What to do: Variant 4G (2 clean KPIs + unified filterable cards + climate link) */
#plan-overview .plan-result-metrics {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 0.55rem;
}
#plan-overview .plan-results-columns,
#plan-overview .plan-results-header {
    display: none !important;
}

.wtd-card-head {
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem 0.75rem;
}
.wtd-hide-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    cursor: pointer;
    user-select: none;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--muted);
}
.wtd-hide-toggle[hidden] { display: none; }
.wtd-filter-bar {
    width: auto;
    max-width: none;
    margin: 0;
}
.wtd-filter-bar[hidden] { display: none; }
.wtd-filter-bar button {
    height: 28px;
    min-height: 0;
    padding: 0 0.65rem;
    font-size: 0.76rem;
}

.climate-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.22rem;
    font-size: 0.67rem;
    font-weight: 700;
    padding: 0.08rem 0.36rem;
    border-radius: 5px;
    background: color-mix(in srgb, #38bdf8 16%, transparent);
    color: #38bdf8;
}
.climate-badge.hot {
    background: color-mix(in srgb, #fb923c 16%, transparent);
    color: #fb923c;
}
.climate-note {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.4rem 0.75rem;
    margin-top: 0.65rem;
    padding: 0.44rem 0.65rem;
    border-radius: 8px;
    font-size: 0.76rem;
    color: var(--muted);
    background: color-mix(in srgb, #38bdf8 8%, var(--bg));
    border: 1px dashed color-mix(in srgb, #38bdf8 38%, var(--border));
}
.climate-note[hidden] { display: none; }
.climate-link {
    color: var(--accent);
    font-weight: 700;
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 0.22rem;
    font-size: 0.75rem;
    background: transparent;
    border: none;
    padding: 0;
    align-self: flex-start;
}
.climate-link:hover { text-decoration: underline; }

#plan-overview .plan-upgrade-details,
#plan-overview .plan-proof,
#plan-overview .plan-unverified,
#plan-overview .plan-skipped,
#plan-overview #material-work-hint {
    display: none !important;
}
#plan-overview .plan-result-metrics { margin-bottom: 0; }

#ms-stage-changes-card .v4-card-footer {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 0.45rem;
    margin-top: auto;
}
#ms-stage-changes-card .v4-card-footer-left {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.22rem;
    min-width: 0;
    flex: 1 1 auto;
}
#ms-stage-changes-card .v4-card-footer .v4-diff {
    min-width: 0;
    flex: 1 1 auto;
}
#ms-stage-changes-card .v4-meta {
    display: inline-flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.3rem;
    margin-left: auto;
    flex: none;
    font-size: 0.72rem;
    color: var(--muted);
}
#ms-stage-changes-card .v4-emode {
    color: #facc15;
    font-weight: 700;
}
#ms-stage-changes-card .v4-worker {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
#ms-stage-changes-card .v4-load {
    font-variant-numeric: tabular-nums;
    font-weight: 600;
    flex: none;
}

.flow-carry-strip {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    margin-bottom: 0.6rem;
    padding: 0.48rem 0.68rem;
    border-radius: 9px;
    background: var(--bg);
    border: 1px solid var(--border);
}
.flow-carry-strip[hidden] { display: none; }
.flow-carry-group {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.35rem 0.45rem;
}
.flow-carry-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--muted);
}
.flow-carry-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.28rem;
    padding: 0.14rem 0.48rem;
    border-radius: 999px;
    font-size: 0.75rem;
    background: var(--surface);
    border: 1px solid var(--border);
    font-variant-numeric: tabular-nums;
}
.flow-carry-pill strong { color: var(--accent); }

#plan-overview .plan-result-metrics {
    border: none !important;
    padding: 0 !important;
    margin: 0 !important;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
}
#plan-overview .plan-result-metric {
    border: none !important;
    padding: 0.25rem 0.4rem !important;
}
#plan-overview #level-up-metric {
    text-align: right;
}

#ms-stage-changes-card .v4-seed-line {
    font-size: 0.74rem;
    font-weight: 600;
    color: var(--text);
    font-variant-numeric: tabular-nums;
}
.climate-badge.light-mode {
    background: color-mix(in srgb, #facc15 18%, transparent);
    color: #eab308;
}
.climate-btn {
    align-self: flex-start;
    margin-top: 0.12rem;
    border: 1px solid color-mix(in srgb, var(--accent) 45%, var(--border));
    background: color-mix(in srgb, var(--accent) 12%, var(--surface));
    color: var(--accent);
    border-radius: 6px;
    padding: 0.18rem 0.52rem;
    font-size: 0.73rem;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.12s, border-color 0.12s;
}
.climate-btn:hover {
    background: color-mix(in srgb, var(--accent) 22%, var(--surface));
    border-color: var(--accent);
}
dialog#climate-guide-dialog.settings-dialog {
    max-width: 680px;
}

.product-flow-standalone-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
    align-items: stretch;
    justify-items: stretch;
    gap: 0.55rem;
    padding: 0.65rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    margin-top: 0.55rem;
}
.product-flow-standalone-grid > * {
    width: 100%;
    max-width: none;
    min-width: 0;
    box-sizing: border-box;
}
.product-flow-total {
    display: none !important;
}

/* Compact climate placement popup */
dialog#climate-guide-dialog.settings-dialog {
    width: fit-content;
    min-width: 300px;
    max-width: min(94vw, 720px);
}
#climate-guide-body .production-environment-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    justify-content: center;
}

/* Color-coded What to do cards & badges */
#ms-stage-changes-card .v4-card {
    border-left-width: 3px;
}
#ms-stage-changes-card .v4-card.v4-cat-up { border-left-color: #10b981; }
#ms-stage-changes-card .v4-card.v4-cat-res { border-left-color: #14b8a6; }
#ms-stage-changes-card .v4-card.v4-cat-rec { border-left-color: #6366f1; }
#ms-stage-changes-card .v4-card.v4-cat-team { border-left-color: #f59e0b; }
#ms-stage-changes-card .v4-card.v4-cat-seed { border-left-color: #84cc16; }

#ms-stage-changes-card .v4-tag.up { color: #10b981; background: color-mix(in srgb, #10b981 16%, transparent); }
#ms-stage-changes-card .v4-tag.res { color: #14b8a6; background: color-mix(in srgb, #14b8a6 16%, transparent); }
#ms-stage-changes-card .v4-tag.rec { color: #6366f1; background: color-mix(in srgb, #6366f1 16%, transparent); }
#ms-stage-changes-card .v4-tag.team { color: #f59e0b; background: color-mix(in srgb, #f59e0b 16%, transparent); }
#ms-stage-changes-card .v4-tag.seed { color: #84cc16; background: color-mix(in srgb, #84cc16 16%, transparent); }

/* Hexagonal worker icons with load ring + hover details */
#ms-stage-changes-card .v4-hex-row {
    display: inline-flex;
    align-items: center;
    gap: 0.32rem;
    min-width: 0;
}
.v4-hex-badge {
    position: relative;
    width: 30px;
    height: 30px;
    flex: none;
    display: grid;
    place-items: center;
}
.v4-hex-inner {
    width: 22px;
    height: 22px;
    clip-path: polygon(50% 0%, 93% 25%, 93% 75%, 50% 100%, 7% 75%, 7% 25%);
    background: var(--surface);
    display: grid;
    place-items: center;
    overflow: hidden;
    font-size: 0.65rem;
    font-weight: 700;
    color: var(--text);
}
.v4-hex-inner.emode {
    color: #facc15;
    font-size: 0.82rem;
}
.v4-hex-inner img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.v4-hex-ring {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}
.v4-hex-track {
    fill: none;
    stroke: color-mix(in srgb, var(--border) 85%, transparent);
    stroke-width: 3.2;
}
.v4-hex-fill {
    fill: none;
    stroke: var(--accent);
    stroke-width: 3.2;
    stroke-linecap: round;
}
.v4-hex-fill.emode {
    stroke: #facc15;
}
.v4-hex-more {
    font-size: 0.71rem;
    font-weight: 700;
    color: var(--muted);
}
.v4-hex-trait {
    position: absolute;
    top: -2px;
    right: -3px;
    z-index: 2;
    min-width: 0.92rem;
    padding: 0 0.18rem;
    border: 1px solid #15222a;
    border-radius: 999px;
    background: #ef535a;
    color: #fff;
    font-size: 0.56rem;
    font-weight: 700;
    line-height: 1.25;
    text-align: center;
    letter-spacing: 0.01em;
}
.tt-worker-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.35rem;
}
.tt-worker-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.28rem;
    padding: 0.12rem 0.38rem 0.12rem 0.16rem;
    border-radius: 999px;
    background: color-mix(in srgb, var(--surface) 78%, var(--bg));
    border: 1px solid var(--border);
    font-size: 0.74rem;
    color: var(--text);
}
.tt-worker-pill .v4-hex-badge {
    width: 24px;
    height: 24px;
}
.tt-worker-pill .v4-hex-inner {
    width: 18px;
    height: 18px;
}
.tt-load-pill {
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
}

/* Production flow map: purple carry-out & stock rows */
.product-flow-node.flow-carry-out,
.flow-sale-key.flow-carry-out::before {
    border: 1px solid color-mix(in srgb, #a855f7 65%, var(--border));
    background: color-mix(in srgb, #a855f7 16%, var(--surface));
}
.flow-carry-out-row strong {
    color: #a855f7;
}
.flow-stock-row strong {
    color: #38bdf8;
}

/* Compact What to do cards */
#ms-stage-changes-card .climate-btn {
    margin-top: 0;
    padding: 0.14rem 0.44rem;
    font-size: 0.7rem;
}

/* Stage progress track cards (#ms-stage-tabs) */
.ms-phase-group {
    display: flex;
    flex-direction: column;
    flex: var(--phase-span, 1) 1 0;
    min-width: 0;
}
.ms-phase-tail {
    display: contents;
}
.ms-phase-head {
    font-size: 0.66rem;
    font-weight: 700;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    padding-bottom: 0.24rem;
    margin-bottom: 0.42rem;
    border-bottom: 2px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.35rem;
    white-space: nowrap;
    overflow: hidden;
}
.ms-phase-head > span:first-child {
    overflow: hidden;
    text-overflow: ellipsis;
}
.ms-phase-dur {
    font-weight: 500;
    opacity: 0.82;
    text-transform: none;
    font-variant-numeric: tabular-nums;
    flex-shrink: 0;
}
.ms-phase-group.is-lvl .ms-phase-head {
    color: var(--accent);
    border-bottom-color: color-mix(in srgb, var(--accent) 55%, transparent);
}
.ms-phase-group.is-proc .ms-phase-head {
    color: var(--warning);
    border-bottom-color: color-mix(in srgb, var(--warning) 60%, transparent);
}
.ms-phase-group.is-steady .ms-phase-head {
    color: #7ea3c4;
    border-bottom-color: rgba(126, 163, 196, 0.6);
}
:root.light .ms-phase-group.is-steady .ms-phase-head,
.light .ms-phase-group.is-steady .ms-phase-head {
    color: #24517a;
    border-bottom-color: #7ea3c4;
}
.ms-phase-cards {
    display: flex;
    align-items: stretch;
    gap: 0.32rem;
    flex: 1;
}
.ms-step-arrow {
    align-self: center;
    color: var(--muted);
    opacity: 0.65;
    font-size: 0.9rem;
    font-weight: 700;
    flex-shrink: 0;
    user-select: none;
}
.ms-tab-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.35rem;
}
.ms-tab-head strong {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.ms-tab-checks {
    font-size: 0.7rem;
    font-weight: 700;
    opacity: 0.85;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    flex-shrink: 0;
}
.ms-tab-metrics {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.3rem;
    margin-top: 0.22rem;
    font-size: 0.72rem;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}
.ms-tab-time {
    opacity: 0.9;
    white-space: nowrap;
    flex-shrink: 0;
}
.ms-tab-income {
    display: inline-flex;
    align-items: center;
    gap: 0.22rem;
    font-weight: 700;
    white-space: nowrap;
    flex-shrink: 0;
}
.ms-tab-coin {
    width: 13px;
    height: 13px;
    object-fit: contain;
}
#multi-stage-card .p1-tab[aria-selected="true"] .ms-step-bar {
    background: rgba(255, 255, 255, 0.26);
}
#multi-stage-card .p1-tab[aria-selected="true"] .ms-step-bar > i {
    background: #ffffff;
}
@media (max-width: 720px) {
    #multi-stage-card .p1-tabs {
        flex-direction: column;
        gap: 0.6rem;
        overflow-x: visible;
    }
    #multi-stage-card .ms-phase-group {
        flex: none;
        width: 100%;
    }
    #multi-stage-card .ms-phase-cards {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 0.42rem;
    }
    #multi-stage-card .ms-phase-cards.is-single {
        grid-template-columns: 1fr;
    }
    #multi-stage-card .ms-phase-cards.is-odd > .p1-tab:last-child {
        grid-column: 1 / -1;
    }
    #multi-stage-card .p1-tab {
        min-width: 0;
    }
    #multi-stage-card .ms-step-arrow {
        display: none;
    }
    #multi-stage-card .ms-phase-tail {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 0.48rem;
    }
}

/* Variant 1: hide redundant #plan-overview in multi-stage; compact pill strip in single-stage */
#results-content.is-multi-stage #plan-overview {
    display: none !important;
}
#plan-overview {
    padding: 0.75rem;
}
#plan-overview .plan-result-metrics {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 0.65rem;
    border: none;
    padding: 0;
    margin: 0;
}
#plan-overview .plan-result-metric {
    background: var(--surface-2);
    border: 1px solid var(--border) !important;
    border-radius: 10px;
    padding: 0.7rem 0.9rem !important;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.2rem;
    text-align: left !important;
    min-width: 0;
}
#plan-overview .plan-result-metric[hidden] {
    display: none !important;
}
#plan-overview .plan-result-label {
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--muted);
}
#plan-overview .plan-result-metric strong {
    font-size: 1.45rem;
    font-weight: 800;
    line-height: 1.15;
    font-variant-numeric: tabular-nums;
}
#plan-overview #level-up-bottleneck,
#plan-overview .plan-rate-gap,
#plan-overview .plan-result-sub {
    text-transform: none;
    letter-spacing: 0;
    font-size: 0.74rem;
    font-weight: 500;
    font-variant-numeric: tabular-nums;
}
#plan-overview #top-earner-name {
    font-size: 1.15rem;
}

/* Visual-first What to do cards (v4 redesign) */
.wtd-head-left {
    display: flex;
    align-items: center;
    gap: 0.55rem;
}
.wtd-head-right {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    flex-wrap: wrap;
}
.wtd-progress-badge {
    font-size: 0.74rem;
    font-weight: 700;
    color: var(--accent);
    background: color-mix(in srgb, var(--accent) 14%, var(--bg));
    border: 1px solid color-mix(in srgb, var(--accent) 38%, var(--border));
    border-radius: 999px;
    padding: 0.1rem 0.5rem;
    font-variant-numeric: tabular-nums;
}
.wtd-hide-done[aria-pressed="true"] {
    background: color-mix(in srgb, var(--accent) 18%, var(--surface));
    border-color: var(--accent);
    color: var(--accent);
}

.v4-group {
    display: flex;
    flex-direction: column;
    gap: 0.36rem;
}
.v4-group + .v4-group {
    margin-top: 0.8rem;
}
.v4-group-title {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
}

#ms-stage-changes-card .v4-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(174px, 1fr));
    gap: 0.62rem;
}
#ms-stage-changes-card .v4-card.wtd5-card {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0;
    padding: 8px 10px 8px;
    border-radius: 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    transition: transform 0.14s ease, border-color 0.14s ease, box-shadow 0.14s ease, opacity 0.14s ease;
    user-select: none;
}
#ms-stage-changes-card .v4-card.wtd5-card:hover {
    transform: translateY(-1px);
    border-color: color-mix(in srgb, var(--accent) 55%, var(--border));
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18);
}
#ms-stage-changes-card .v4-card.wtd5-card.is-swap {
    border-color: rgba(251, 146, 60, 0.45);
}
#ms-stage-changes-card .v4-card.wtd5-card.is-emode {
    border-color: rgba(234, 179, 8, 0.55);
}
#ms-stage-changes-card .v4-card.wtd5-card.is-remove {
    border-color: rgba(239, 68, 68, 0.55);
    background: color-mix(in srgb, #ef4444 9%, var(--surface));
}
#ms-stage-changes-card .v4-card.wtd5-card.is-remove .wtd5-fac-stage {
    opacity: 0.92;
    filter: saturate(0.88);
}
#ms-stage-changes-card .v4-card.wtd5-card.is-remove .wtd5-prod-float {
    border-color: rgba(239, 68, 68, 0.45);
}
#ms-stage-changes-card .v4-card.wtd5-card[data-done="true"] {
    opacity: 0.52;
    border-color: rgba(63, 185, 80, 0.45);
}
#ms-stage-changes-card .v4-card.wtd5-card[data-done="true"]:hover {
    opacity: 0.78;
}
.v4-icon-fallback {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--muted);
}
.climate-pill-btn {
    border: 1px solid color-mix(in srgb, #38bdf8 45%, var(--border));
    background: color-mix(in srgb, #38bdf8 12%, transparent);
    color: #38bdf8;
    border-radius: 5px;
    padding: 0.04rem 0.36rem;
    font-size: 0.67rem;
    font-weight: 700;
    cursor: pointer;
    line-height: 1.35;
}
.climate-pill-btn:hover {
    border-color: #38bdf8;
    background: color-mix(in srgb, #38bdf8 22%, transparent);
}
.climate-pill-btn.hot {
    color: #fb923c;
    border-color: color-mix(in srgb, #fb923c 45%, var(--border));
    background: color-mix(in srgb, #fb923c 12%, transparent);
}
.climate-pill-btn.hot:hover {
    border-color: #fb923c;
    background: color-mix(in srgb, #fb923c 22%, transparent);
}
.climate-pill-btn.light-mode {
    color: #eab308;
    border-color: color-mix(in srgb, #facc15 45%, var(--border));
    background: color-mix(in srgb, #facc15 14%, transparent);
}
.climate-pill-btn.light-mode:hover {
    border-color: #eab308;
    background: color-mix(in srgb, #facc15 24%, transparent);
}
.v4-coin {
    width: 12px;
    height: 12px;
    object-fit: contain;
    vertical-align: -1px;
    margin-right: 2px;
}

/* ====== WTD 5B+5D Card & P4-A Glass Popover ====== */
.wtd5-top {
    position: absolute;
    top: 8px;
    left: 10px;
    right: 10px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 4px;
    min-height: 20px;
    z-index: 3;
    pointer-events: none;
}
.wtd5-top button,
.wtd5-top [data-tip] {
    pointer-events: auto;
}
.wtd5-cluster {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}
.wtd5-count {
    font-size: 11px;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    color: var(--text);
}
.wtd5-count.is-remove {
    color: #dc2626;
    background: rgba(239, 68, 68, 0.14);
    border: 1px solid rgba(239, 68, 68, 0.42);
    padding: 1px 6px;
    border-radius: 999px;
}
:root:not(.light) .wtd5-count.is-remove {
    color: #fca5a5;
}
.wtd5-count.is-swap {
    color: #d97706;
    background: rgba(245, 158, 11, 0.14);
    border: 1px solid rgba(245, 158, 11, 0.38);
    padding: 1px 6px;
    border-radius: 999px;
}
:root:not(.light) .wtd5-count.is-swap {
    color: #fcd34d;
}
.wtd5-count.is-add {
    color: #16a34a;
    background: rgba(34, 197, 94, 0.14);
    border: 1px solid rgba(34, 197, 94, 0.38);
    padding: 1px 6px;
    border-radius: 999px;
}
:root:not(.light) .wtd5-count.is-add {
    color: #86efac;
}
.wtd5-count.is-emode {
    color: #ca8a04;
    background: rgba(234, 179, 8, 0.15);
    border: 1px solid rgba(234, 179, 8, 0.45);
    padding: 1px 6px;
    border-radius: 999px;
}
:root:not(.light) .wtd5-count.is-emode {
    color: #fde047;
}
.wtd5-mode-from {
    font-size: 11px;
    font-weight: 800;
    color: var(--muted);
    line-height: 1;
}
.wtd5-team-hero {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    width: 100%;
    height: 100%;
}
.roster-portrait.wtd5-team-avatar {
    width: 44px;
    margin-bottom: 0;
    flex-shrink: 0;
}
.roster-portrait.wtd5-team-avatar:only-child {
    width: 50px;
}
.wtd5-team-avatar .roster-portrait-fill {
    inset: 1.8px;
    font-size: 0.78rem;
}
.roster-portrait.wtd5-team-avatar.is-dim {
    width: 38px;
    opacity: 0.82;
    filter: saturate(0.8);
}
.wtd5-team-arr {
    font-size: 14px;
    font-weight: 800;
    color: var(--muted);
    line-height: 1;
}
.wtd5-fac-mini {
    width: 18px;
    height: 18px;
    object-fit: contain;
    flex-shrink: 0;
}
.wtd5-team-names {
    font-size: 11px;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}
.wtd5-clim {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    border-radius: 6px;
    font-size: 11px;
    line-height: 1;
    border: 1px solid var(--border);
    background: color-mix(in srgb, var(--surface) 75%, transparent);
    cursor: pointer;
}
:root.light .wtd5-count.is-remove,
.light .wtd5-count.is-remove {
    color: var(--error, #c62828);
}
:root.light .wtd5-clim.hot,
.light .wtd5-clim.hot {
    color: #c2410c;
    background: rgba(251, 146, 60, 0.14);
}
:root.light .wtd5-clim.light-mode,
.light .wtd5-clim.light-mode {
    color: #a16207;
    background: rgba(234, 179, 8, 0.16);
}
:root.light .wtd5-info-btn,
.light .wtd5-info-btn {
    color: #0969da;
}
:root.light .wtd5-info-btn:hover,
:root.light .wtd5-info-btn.btn-active,
.light .wtd5-info-btn:hover,
.light .wtd5-info-btn.btn-active {
    color: #0550ae;
}
.wtd5-clim.hot {
    color: #fb923c;
    border-color: rgba(251, 146, 60, 0.45);
    background: rgba(124, 45, 18, 0.35);
}
.wtd5-clim.light-mode {
    color: #eab308;
    border-color: rgba(234, 179, 8, 0.45);
    background: rgba(113, 63, 18, 0.28);
}
.wtd5-info-btn {
    width: 22px;
    height: 22px;
    padding: 0;
    border-radius: 999px;
    border: none;
    background: transparent;
    color: #58a6ff;
    opacity: 0.85;
    font-size: 16px;
    font-weight: 700;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.12s ease;
}
.wtd5-info-svg {
    width: 18px;
    height: 18px;
    display: block;
}
.wtd5-info-btn:hover,
.wtd5-info-btn.btn-active {
    color: #bae6fd;
    opacity: 1;
    border-radius: 999px;
    background: transparent !important;
    box-shadow: 0 0 0 1.5px rgba(88, 166, 255, 0.55);
    transform: scale(1.16);
    filter: drop-shadow(0 0 6px rgba(88, 166, 255, 0.75));
}
:root.light .wtd5-info-btn:hover,
:root.light .wtd5-info-btn.btn-active,
.light .wtd5-info-btn:hover,
.light .wtd5-info-btn.btn-active {
    color: #0550ae;
    box-shadow: 0 0 0 1.5px rgba(9, 105, 218, 0.45);
}
.wtd5-info-btn:active {
    transform: scale(0.92);
}
.wtd5-check {
    width: 20px;
    height: 20px;
    padding: 0;
    border-radius: 6px;
    border: 1.5px solid var(--border);
    background: color-mix(in srgb, var(--bg) 60%, transparent);
    color: transparent;
    font-size: 12px;
    font-weight: 800;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.12s ease;
}
.wtd5-check:hover {
    border-color: var(--accent);
}
.wtd5-card[data-done="true"] .wtd5-check {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--on-accent, #ffffff);
}
.wtd5-hero {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    padding: 0;
    margin-top: -2px;
    margin-bottom: -4px;
}
.wtd5-fac-stage {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 118px;
    height: 118px;
    z-index: 1;
    cursor: pointer;
}
.wtd5-fac-stage img,
.wtd5-fac-stage svg {
    object-fit: contain;
    display: block;
    filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.25));
}
.wtd5-prod-float {
    position: absolute;
    left: 50%;
    bottom: 0;
    transform: translate(-50%, 50%);
    z-index: 2;
    background: color-mix(in srgb, var(--bg) 88%, transparent);
    backdrop-filter: blur(6px);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 3px 9px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.34);
    white-space: nowrap;
    cursor: pointer;
}
.wtd5-swap-prev {
    opacity: 0.45;
    filter: grayscale(0.4);
}
.wtd5-swap-arr {
    font-size: 10px;
    color: #fb923c;
    font-weight: 800;
}
.wtd5-badge-txt {
    font-size: 10.5px;
    font-weight: 700;
    color: var(--text);
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
}
.wtd5-bottom {
    width: 100%;
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 4px;
    padding-top: 2px;
    margin-bottom: -2px;
    border-top: 1px solid color-mix(in srgb, var(--border) 60%, transparent);
    height: 38px;
    min-height: 0;
}
#ms-stage-changes-card .wtd5-bottom .v4-hex-ring {
    display: none;
}
#ms-stage-changes-card .wtd5-bottom .v4-hex-badge {
    position: relative;
    isolation: isolate;
    width: 31px;
    height: 36px;
}
#ms-stage-changes-card .wtd5-bottom .v4-hex-badge::before {
    content: "";
    position: absolute;
    inset: 0;
    background: #66738f;
    clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
}
#ms-stage-changes-card .wtd5-bottom .v4-hex-badge:has(.v4-hex-inner.emode)::before {
    background: #facc15;
}
#ms-stage-changes-card .wtd5-bottom .v4-hex-inner {
    position: relative;
    z-index: 1;
    width: calc(100% - 2px);
    height: calc(100% - 2px);
    clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
    background: #394258;
    font-size: 0.95rem;
}
#ms-stage-changes-card .wtd5-bottom .v4-hex-inner.emode {
    background: linear-gradient(150deg, #33270d, #1b170e);
    color: #facc15;
}
.v4-emode-bolt {
    width: 56%;
    height: 56%;
    display: block;
    filter: drop-shadow(0 0 4px rgba(250, 204, 21, 0.55));
}
#ms-stage-changes-card .wtd5-bottom .v4-hex-inner img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transform: scale(1.12);
}
#ms-stage-changes-card .wtd5-bottom .wtd5-cluster {
    gap: 0;
}
#ms-stage-changes-card .wtd5-bottom .v4-hex-badge:nth-child(1) { z-index: 4; }
#ms-stage-changes-card .wtd5-bottom .v4-hex-badge:nth-child(2) { z-index: 3; }
#ms-stage-changes-card .wtd5-bottom .v4-hex-badge:nth-child(3) { z-index: 2; }
#ms-stage-changes-card .wtd5-bottom .v4-hex-badge + .v4-hex-badge {
    margin-left: -15px;
}
#ms-stage-changes-card .wtd5-bottom .v4-hex-badge:has(+ .v4-hex-badge) {
    filter: drop-shadow(2px 0 3px rgba(0, 0, 0, 0.5));
}
.wtd5-bottom .v4-hex-more {
    margin-left: 3px;
}
.wtd5-seed {
    font-size: 10px;
    font-weight: 600;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    padding-bottom: 4px;
}

#wtd5-popover {
    position: fixed;
    z-index: 9999;
    pointer-events: none;
    opacity: 0;
    transform: translateY(4px);
    transition: opacity 0.12s ease, transform 0.12s ease;
}
#wtd5-popover.visible {
    pointer-events: auto;
    opacity: 1;
    transform: translateY(0);
}
#wtd5-popover.is-centered {
    left: 50% !important;
    top: 50% !important;
    transform: translate(-50%, -50%) !important;
    max-width: calc(100vw - 24px);
}
#wtd5-popover.is-centered .wtd5-pop-card {
    width: min(372px, calc(100vw - 24px));
    max-height: 85vh;
}
.wtd5-pop-card {
    width: 296px;
    box-sizing: border-box;
    max-height: 80vh;
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: thin;
    background: color-mix(in srgb, var(--surface) 92%, transparent);
    backdrop-filter: blur(12px);
    border: 1px solid color-mix(in srgb, #58a6ff 32%, var(--border));
    border-radius: 12px;
    padding: 11px 13px;
    font-size: 12px;
    color: var(--text);
    box-shadow: 0 14px 32px rgba(0, 0, 0, 0.42);
}
.wtd5-pop-card.has-diagrams {
    width: 372px;
}
.wtd5-pop-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding-bottom: 7px;
    margin-bottom: 8px;
    border-bottom: 1px solid var(--border);
}
.wtd5-pop-hleft {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}
.wtd5-pop-title {
    font-weight: 700;
    font-size: 13px;
    line-height: 1.2;
}
.wtd5-pop-sub {
    color: var(--muted);
    font-size: 11px;
    margin-top: 2px;
}
.wtd5-pop-hright {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}
.wtd5-pop-close {
    width: 22px;
    height: 22px;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--muted);
    font-size: 14px;
    line-height: 1;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.wtd5-pop-close:hover {
    color: var(--text);
}
.wtd5-pop-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    margin-bottom: 7px;
}
.wtd5-pop-pill {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 6px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 600;
    background: var(--bg);
    border: 1px solid var(--border);
}
.wtd5-pop-sec {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
    margin-bottom: 4px;
}
.wtd5-pop-workers {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.wtd5-pop-wrow {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    font-size: 11px;
}
.wtd5-pop-wleft {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.wtd5-pop-pct {
    padding: 1px 6px;
    border-radius: 6px;
    font-size: 10.5px;
    font-weight: 700;
    color: #3fb950;
    background: rgba(63, 185, 80, 0.12);
    border: 1px solid rgba(63, 185, 80, 0.35);
}
.wtd5-pop-pct.partial {
    color: #f59e0b;
    background: rgba(245, 158, 11, 0.12);
    border-color: rgba(245, 158, 11, 0.4);
}
.wtd5-gen-stack {
    display: flex;
    flex-direction: column;
    gap: 7px;
    margin-top: 8px;
}
.wtd5-gen-stack > article {
    padding: 7px 8px;
    border-radius: 8px;
    background: var(--bg);
    border: 1px solid var(--border);
    margin: 0;
}
.wtd5-gen-stack > article .facility-category-title {
    font-size: 11px;
    margin: 0 0 6px;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 5px;
}
.wtd5-gen-stack > article .env-unit {
    display: block;
    margin: 0;
}
.wtd5-gen-stack > article .env-diagram {
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    gap: 10px;
    width: 100%;
    min-width: 0;
}
.wtd5-gen-stack > article .env-diagram svg {
    width: 132px;
    max-width: 132px;
    height: auto;
    aspect-ratio: auto;
    flex: 0 0 132px;
    border-radius: 8px;
}
.wtd5-gen-stack > article .env-legend {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin: 0;
    font-size: 11px;
    line-height: 1.3;
    min-width: 0;
}
@media (max-width: 520px) {
    #ms-stage-changes-card .v4-cards {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 0.45rem;
    }
    #ms-stage-changes-card .v4-card.wtd5-card {
        padding: 7px 8px;
    }
    .wtd5-top {
        top: 6px;
        left: 8px;
        right: 8px;
    }
    .wtd5-fac-stage,
    .wtd5-fac-stage img {
        width: 96px !important;
        height: 96px !important;
    }
}
#wtd5-backdrop {
    position: fixed;
    inset: 0;
    z-index: 9998;
    background: rgba(0, 0, 0, 0.52);
    backdrop-filter: blur(2px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.12s ease;
}
#wtd5-backdrop.visible {
    opacity: 1;
    pointer-events: auto;
}
@media (pointer: coarse) {
    .wtd5-top .wtd5-cluster {
        gap: 10px;
    }
    .wtd5-check,
    .wtd5-info-btn,
    .wtd5-pop-close {
        position: relative;
    }
    .wtd5-check::after,
    .wtd5-info-btn::after,
    .wtd5-pop-close::after {
        content: "";
        position: absolute;
        inset: -9px;
    }
}
