/* ═══════════════════════════════════════════════════════════════
   main.css  —  Endless Sky Data Viewer
   Design tokens → shared utilities → component styles
   ═══════════════════════════════════════════════════════════════ */

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

/* ── Design tokens ────────────────────────────────────────────── */
:root {
    /* Palette */
    --c-bg:          #0f172a;
    --c-bg-mid:      #1e3a8a;
    --c-surface:     rgba(15, 23, 42, 0.60);
    --c-surface-2:   rgba(30, 41, 59, 0.80);
    --c-surface-3:   rgba(30, 41, 59, 0.50);
    --c-border:      rgba(59, 130, 246, 0.30);
    --c-border-hi:   rgba(59, 130, 246, 0.45);
    --c-border-2:    rgba(100, 116, 139, 0.25);

    --c-accent:      #3b82f6;
    --c-accent-dark: #2563eb;
    --c-accent-text: #93c5fd;
    --c-text:        #e2e8f0;
    --c-text-mid:    #cbd5e1;
    --c-text-muted:  #94a3b8;
    --c-text-dim:    #64748b;

    --c-danger:      rgba(239, 68, 68, 0.20);
    --c-danger-hi:   #ef4444;
    --c-danger-text: #fca5a5;
    --c-success:     rgba(34, 197, 94, 0.20);
    --c-success-text:#86efac;
    --c-warn:        rgba(120, 90, 20, 0.20);
    --c-warn-text:   #fde68a;

    /* Radii */
    --r-sm:  6px;
    --r-md:  8px;
    --r-lg:  12px;
    --r-xl:  16px;

    /* Shadows */
    --shadow-sm:  0 4px 16px rgba(0,0,0,.20);
    --shadow-md:  0 8px 32px rgba(0,0,0,.30);
    --shadow-lg:  0 16px 48px rgba(0,0,0,.50);

    /* Transitions */
    --t-fast:  0.15s ease;
    --t-base:  0.30s ease;
}

/* ── Base ─────────────────────────────────────────────────────── */
body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, var(--c-bg) 0%, var(--c-bg-mid) 50%, var(--c-bg) 100%);
    min-height: 100vh;
    color: var(--c-text);
}

label {
    display: block;
    margin-bottom: 8px;
    color: var(--c-text-mid);
    font-weight: 500;
}

/* ── Utility: visibility ──────────────────────────────────────── */
.hidden { display: none !important; }
.shown  { display: block; }

/* ── Utility: panel (glass card) ─────────────────────────────── */
/* Used by: config-section, search-section, filter-section, sorter-section */
.panel {
    background: var(--c-surface);
    backdrop-filter: blur(10px);
    border: 1px solid var(--c-border);
    border-radius: var(--r-lg);
    padding: 20px;
    box-shadow: var(--shadow-md);
}

/* ── Utility: section title ───────────────────────────────────── */
.section-title {
    color: var(--c-accent-text);
    font-size: 1.5rem;
    margin-bottom: 15px;
}

/* ── Utility: text-input ──────────────────────────────────────── */
.text-input {
    width: 100%;
    padding: 12px;
    background: var(--c-surface-2);
    border: 1px solid rgba(59, 130, 246, 0.40);
    border-radius: var(--r-md);
    color: var(--c-text);
    font-size: 1rem;
    transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.text-input:focus {
    outline: none;
    border-color: var(--c-accent);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.20);
}

/* ── Utility: buttons ─────────────────────────────────────────── */
.btn {
    padding: 12px 24px;
    border: none;
    border-radius: var(--r-md);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background var(--t-base), transform var(--t-base), box-shadow var(--t-base);
    display: inline-flex;
    align-items: center;
    gap: 8px;
    line-height: 1;
}

.btn-primary {
    background: linear-gradient(135deg, var(--c-accent), var(--c-accent-dark));
    color: #fff;
}
.btn-primary:hover {
    background: linear-gradient(135deg, var(--c-accent-dark), #1d4ed8);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.40);
}

.btn-secondary {
    background: rgba(71, 85, 105, 0.80);
    color: #fff;
}
.btn-secondary:hover { background: rgba(71, 85, 105, 1); }

/* Compact action button (sorter "Add", plugin "Select") */
.btn-action {
    background: linear-gradient(135deg, var(--c-accent), var(--c-accent-dark));
    color: #fff;
    border: none;
    border-radius: var(--r-md);
    padding: 8px 18px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: background var(--t-base), transform var(--t-base), box-shadow var(--t-base);
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.btn-action:hover {
    background: linear-gradient(135deg, var(--c-accent-dark), #1d4ed8);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.40);
}

/* Icon-only close/dismiss */
.btn-close {
    background: none;
    border: none;
    color: var(--c-text-muted);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--r-md);
    transition: background var(--t-fast), color var(--t-fast);
    line-height: 1;
}
.btn-close:hover {
    background: rgba(239, 68, 68, 0.20);
    color: var(--c-danger-hi);
}
.btn-close--lg { font-size: 2rem;   width: 40px; height: 40px; padding: 0; }
.btn-close--sm { font-size: 1.6rem; width: 32px; height: 32px; padding: 0; }

/* Danger remove button */
.btn-remove {
    background: var(--c-danger);
    color: var(--c-danger-text);
    border: 1px solid rgba(239, 68, 68, 0.30);
    border-radius: var(--r-sm);
    padding: 4px 10px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: background var(--t-fast), border-color var(--t-fast), color var(--t-fast);
}
.btn-remove:hover {
    background: rgba(239, 68, 68, 0.30);
    border-color: var(--c-danger-hi);
    color: var(--c-danger-hi);
}

/* ── Utility: move buttons (▲▼) ───────────────────────────────── */
.btn-move {
    background: rgba(71, 85, 105, 0.50);
    color: var(--c-text-muted);
    border: 1px solid var(--c-border);
    border-radius: var(--r-sm);
    padding: 4px 9px;
    font-size: 0.75rem;
    cursor: pointer;
    transition: background var(--t-fast), color var(--t-fast), transform var(--t-fast);
}
.btn-move:hover:not(:disabled) {
    background: rgba(71, 85, 105, 0.90);
    color: var(--c-text);
    transform: translateY(-1px);
}
.btn-move:disabled { opacity: 0.30; cursor: default; transform: none; }

/* ── Utility: direction toggle (Asc/Desc) ─────────────────────── */
.btn-dir {
    background: var(--c-surface-3);
    color: var(--c-accent-text);
    border: 1px solid var(--c-border-hi);
    border-radius: var(--r-sm);
    padding: 4px 12px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: background var(--t-fast), transform var(--t-fast);
    white-space: nowrap;
}
.btn-dir:hover {
    background: rgba(59, 130, 246, 0.30);
    border-color: var(--c-accent);
    transform: translateY(-1px);
}

/* ── Utility: row (sorter/plugin active list item) ────────────── */
.list-row {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(15, 23, 42, 0.40);
    border: 1px solid var(--c-border);
    border-radius: var(--r-sm);
    padding: 8px 12px;
    flex-wrap: wrap;
    transition: background var(--t-fast), border-color var(--t-fast);
}
.list-row:hover {
    background: rgba(59, 130, 246, 0.10);
    border-color: rgba(59, 130, 246, 0.40);
}
.list-row__label {
    flex: 1;
    font-size: 0.95rem;
    color: var(--c-text-mid);
    min-width: 120px;
}

/* ── Utility: overlay backdrop ────────────────────────────────── */
.overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.80);
    backdrop-filter: blur(5px);
    z-index: 1000;
    /* GPU-composite the backdrop independently */
    will-change: opacity;
}
.overlay--visible,
.overlay.active {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

/* ── Utility: modal box ───────────────────────────────────────── */
.modal-box {
    background: linear-gradient(135deg, rgba(15,23,42,0.95), rgba(30,41,59,0.95));
    border: 2px solid rgba(59, 130, 246, 0.50);
    border-radius: var(--r-xl);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    /* Contain scroll inside the box, promote to own layer */
    contain: layout style;
    will-change: transform;
}

/* Full-screen detail modal */
.modal-box--detail {
    padding: 30px;
    max-width: 800px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    overscroll-behavior: contain;
    /* Smooth momentum scroll on iOS */
    -webkit-overflow-scrolling: touch;
}

/* Picker-style modal (sorter/plugin) */
.modal-box--picker {
    width: min(460px, 92vw);
    max-height: 75vh;
    display: flex;
    flex-direction: column;
}

/* ── Utility: picker-row ──────────────────────────────────────── */
.picker-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: var(--r-sm);
    border: 1px solid transparent;
    cursor: pointer;
    transition: background var(--t-fast), border-color var(--t-fast);
    background: rgba(15, 23, 42, 0.30);
}
.picker-row:hover {
    background: rgba(59, 130, 246, 0.15);
    border-color: var(--c-border);
}
.picker-row input[type="checkbox"] {
    cursor: pointer;
    accent-color: var(--c-accent);
    width: 16px; height: 16px;
    flex-shrink: 0;
}
.picker-row label {
    cursor: pointer;
    font-size: 0.95rem;
    color: var(--c-text-mid);
    flex: 1;
    margin-bottom: 0;
    user-select: none;
}

/* ── Utility: picker scrollable list ─────────────────────────── */
.picker-list {
    overflow-y: auto;
    flex: 1;
    padding: 0 8px 10px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
}
.picker-list::-webkit-scrollbar { width: 6px; }
.picker-list::-webkit-scrollbar-track  { background: rgba(15,23,42,0.40); border-radius: 3px; }
.picker-list::-webkit-scrollbar-thumb  { background: rgba(59,130,246,0.40); border-radius: 3px; }
.picker-list::-webkit-scrollbar-thumb:hover { background: rgba(59,130,246,0.70); }

/* ── Utility: picker footer ───────────────────────────────────── */
.picker-footer {
    padding: 14px 20px;
    border-top: 2px solid var(--c-border);
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

/* ── Utility: picker header ───────────────────────────────────── */
.picker-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px 15px;
    border-bottom: 2px solid var(--c-border);
}
.picker-header__title {
    font-size: 1.3rem;
    font-weight: 600;
    color: var(--c-accent-text);
}

/* ── Utility: picker search ───────────────────────────────────── */
.picker-search {
    margin: 12px 16px;
    width: calc(100% - 32px);
}

/* ── Layout ───────────────────────────────────────────────────── */
.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
}

/* ── Header ───────────────────────────────────────────────────── */
header {
    padding: 30px;
    margin-bottom: 30px;
}

h1 {
    font-size: 2.5rem;
    color: var(--c-accent-text);
    margin-bottom: 10px;
}

.subtitle {
    color: var(--c-text-muted);
    font-size: 1.1rem;
}

/* ── Config section ───────────────────────────────────────────── */
.config-section { padding: 25px; margin-bottom: 30px; }
.config-section h2 { margin-bottom: 20px; }

.input-group { margin-bottom: 15px; }
.button-group { display: flex; gap: 10px; margin-top: 20px; }

/* ── Tabs ─────────────────────────────────────────────────────── */
.tabs {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    border-bottom: 2px solid var(--c-border);
    padding-bottom: 10px;
}

.tab {
    padding: 10px 20px;
    background: rgba(30, 41, 59, 0.60);
    border: 1px solid var(--c-border);
    border-radius: var(--r-md) var(--r-md) 0 0;
    cursor: pointer;
    transition: background var(--t-base), color var(--t-base);
    color: var(--c-text-muted);
}
.tab.active {
    background: rgba(59, 130, 246, 0.30);
    color: var(--c-accent-text);
    border-bottom-color: transparent;
}
.tab:hover { background: rgba(59, 130, 246, 0.20); }

/* ── Search / filter panel ────────────────────────────────────── */
.search-section { margin-bottom: 20px; }

.search-input { /* alias kept for HTML compatibility */
    width: 100%;
    padding: 12px;
    background: var(--c-surface-2);
    border: 1px solid rgba(59, 130, 246, 0.40);
    border-radius: var(--r-md);
    color: var(--c-text);
    font-size: 1rem;
    transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.search-input:focus {
    outline: none;
    border-color: var(--c-accent);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.20);
}

/* ── Filter sub-sections ──────────────────────────────────────── */
.filter-section {
    background: var(--c-surface-3);
    padding: 20px;
    border-radius: var(--r-md);
    margin: 15px;
    border: 1px solid var(--c-border);
}

/* Expandable title — always bold blue, cursor pointer */
.filter-title,
.filter-title-no-margin {
    font-weight: 600;
    color: var(--c-accent-text);
    font-size: 1.1rem;
    cursor: pointer;
    user-select: none;
}
/* When expanded the JS adds .filter-title (with margin below) */
.filter-title        { margin-bottom: 20px; }
/* When collapsed the JS adds .filter-title-no-margin (no margin) */
.filter-title-no-margin { margin-bottom: 0; }

.filter-options {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
}

.filter-option {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(15, 23, 42, 0.40);
    padding: 8px 12px;
    border-radius: var(--r-sm);
    border: 1px solid var(--c-border);
    transition: background var(--t-base), border-color var(--t-base);
}
.filter-option:hover {
    background: rgba(59, 130, 246, 0.20);
    border-color: var(--c-accent);
}
.filter-option input[type="checkbox"] {
    cursor: pointer;
    width: 18px; height: 18px;
    accent-color: var(--c-accent);
}
.filter-option label {
    cursor: pointer;
    user-select: none;
    text-transform: capitalize;
    color: var(--c-text-mid);
    font-size: 0.95rem;
    margin-bottom: 0;
}

.filter-clear {
    margin-top: 15px;
    background: rgba(71, 85, 105, 0.80);
    color: #fff;
}
.filter-clear:hover {
    background: rgba(71, 85, 105, 1);
    border-color: var(--c-accent);
    transform: translateY(-1px);
}

/* ── Sorter section ───────────────────────────────────────────── */
.sorter-section {
    background: var(--c-surface-3);
    padding: 20px;
    border-radius: var(--r-md);
    margin: 15px;
    border: 1px solid var(--c-border);
}

.sorter-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.sorter-section-title {
    font-weight: 600;
    color: var(--c-accent-text);
    font-size: 1.1rem;
    user-select: none;
}

#sorterActiveList,
#activePluginList {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.sorter-empty {
    color: var(--c-text-muted);
    font-size: 0.9rem;
    font-style: italic;
}

.sorter-avg {
    font-size: 0.78rem;
    color: var(--c-text-muted);
    background: rgba(15, 23, 42, 0.60);
    border: 1px solid var(--c-border);
    border-radius: 4px;
    padding: 2px 8px;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

/* ── Sorter picker overlay ────────────────────────────────────── */
#sorterPickerOverlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.80);
    backdrop-filter: blur(5px);
    z-index: 1000;
}
#sorterPickerOverlay.sorter-overlay-visible {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

#sorterPickerSearch {
    margin: 12px 16px;
    width: calc(100% - 32px);
}

/* The sorter picker list reuses .picker-list */
#sorterPickerList { padding: 0 16px 10px; }

/* ── Plugin picker overlay ────────────────────────────────────── */
#pluginPickerOverlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.80);
    backdrop-filter: blur(5px);
    z-index: 1000;
}
#pluginPickerOverlay.plugin-overlay-visible {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.plugin-picker-group-header {
    color: #63b3ed;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .12em;
    text-transform: uppercase;
    padding: 10px 10px 4px;
    margin-top: 4px;
    border-top: 1px solid var(--c-border);
    user-select: none;
}
.plugin-picker-group-header:first-child { border-top: none; margin-top: 0; }

.plugin-picker-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    border-radius: var(--r-sm);
    border: 1px solid transparent;
    cursor: pointer;
    transition: background var(--t-fast), border-color var(--t-fast);
    background: rgba(15, 23, 42, 0.30);
    margin: 0 2px;
}
.plugin-picker-row:hover {
    background: rgba(59, 130, 246, 0.15);
    border-color: var(--c-border);
}
.plugin-picker-row.active {
    background: rgba(59, 130, 246, 0.20);
    border-color: var(--c-border-hi);
}
.plugin-picker-row-label {
    font-size: 0.95rem;
    color: var(--c-text-mid);
    flex: 1;
    user-select: none;
    pointer-events: none; /* row.onclick handles toggle */
}
.plugin-picker-row input[type="checkbox"] {
    cursor: pointer;
    accent-color: var(--c-accent);
    width: 16px; height: 16px;
    flex-shrink: 0;
    pointer-events: none; /* prevent double-fire; row.onclick calls checkbox.click() */
}
.plugin-picker-row.active .plugin-picker-row-label {
    color: var(--c-accent-text);
    font-weight: 600;
}

.plugin-picker-active-dot {
    width: 7px; height: 7px;
    border-radius: 50%;
    background: var(--c-accent);
    flex-shrink: 0;
    opacity: 0;
    transition: opacity var(--t-fast);
}
.plugin-picker-row.active .plugin-picker-active-dot { opacity: 1; }

/* ── Cards grid ───────────────────────────────────────────────── */
.cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
    gap: 20px;
    margin-top: 20px;
}

.card {
    background: rgba(15, 23, 42, 0.70);
    backdrop-filter: blur(10px);
    border: 1px solid var(--c-border);
    border-radius: var(--r-lg);
    padding: 20px;
    cursor: pointer;
    transition: transform var(--t-base), box-shadow var(--t-base), border-color var(--t-base);
    box-shadow: var(--shadow-sm);
    display: flex;
    gap: 16px;
    align-items: center;
    /* Promote each card to its own layer only on hover to avoid too many layers */
}
.card:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 24px rgba(59, 130, 246, 0.30);
    border-color: var(--c-accent);
}

.card-image {
    width: 90px;
    height: 90px;
    border-radius: 10px;
    border: 1px solid var(--c-border);
    background: var(--c-surface-3);
    flex-shrink: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    /* Avoid layout shift while image loads */
    contain: strict;
}

.card-content {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 0;
}

.card-title {
    font-size: 1.3rem;
    color: var(--c-accent-text);
    margin-bottom: 15px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.card-details {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.detail-item { display: flex; flex-direction: column; }
.detail-label { font-size: 0.85rem; color: var(--c-text-muted); margin-bottom: 4px; }
.detail-value { font-size: 1rem; color: var(--c-text); font-weight: 500; }

/* ── Stats ────────────────────────────────────────────────────── */
.stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 15px;
    margin-bottom: 20px;
}

.stat-card {
    background: var(--c-surface-3);
    padding: 15px;
    border-radius: var(--r-md);
    border: 1px solid var(--c-border);
    text-align: center;
}
.stat-value { font-size: 2rem; color: var(--c-accent-text); font-weight: 700; }
.stat-label { font-size: 0.9rem; color: var(--c-text-muted); margin-top: 5px; }

/* ── Loading / error ──────────────────────────────────────────── */
.loading {
    text-align: center;
    padding: 40px;
    color: var(--c-text-muted);
    font-size: 1.2rem;
}

.error {
    background: rgba(239, 68, 68, 0.20);
    border: 1px solid rgba(239, 68, 68, 0.50);
    color: var(--c-danger-text);
    padding: 15px;
    border-radius: var(--r-md);
    margin-bottom: 20px;
}

/* ── Detail modal ─────────────────────────────────────────────── */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.80);
    backdrop-filter: blur(5px);
    z-index: 1000;
    overflow-y: auto;
    overscroll-behavior: contain;
    will-change: opacity;
}
.modal.active {
    display: flex;
    align-items: flex-start;   /* allow long modals to scroll naturally */
    justify-content: center;
    padding: 20px;
}

.modal-content {
    background: linear-gradient(135deg, rgba(15,23,42,0.95), rgba(30,41,59,0.95));
    border: 2px solid rgba(59, 130, 246, 0.50);
    border-radius: var(--r-xl);
    box-shadow: var(--shadow-lg);
    padding: 30px;
    max-width: 800px;
    width: 100%;
    /* Let the overlay scroll, not the box itself, for smoother momentum */
    margin: auto;
    /* Still contain layout so browser can skip painting outside */
    contain: layout style;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 2px solid var(--c-border);
}

.modal-title { font-size: 2rem; color: var(--c-accent-text); }
.modal-body  { color: var(--c-text-mid); }

/* ── Modal tabs ───────────────────────────────────────────────── */
.modal-tabs {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    border-bottom: 2px solid var(--c-border);
    padding-bottom: 10px;
    flex-wrap: wrap;
}

/* Reuse .tab — just copy relevant additions */
.modal-tab {
    padding: 10px 20px;
    background: rgba(30, 41, 59, 0.60);
    border: 1px solid var(--c-border);
    border-radius: var(--r-md) var(--r-md) 0 0;
    cursor: pointer;
    transition: background var(--t-base), color var(--t-base);
    color: var(--c-text-muted);
    font-size: 1rem;
    font-weight: normal;
}
.modal-tab:hover { background: rgba(59, 130, 246, 0.20); }
.modal-tab.active {
    background: rgba(59, 130, 246, 0.30);
    color: var(--c-accent-text);
    border-bottom-color: transparent;
}

.modal-tab-contents { position: relative; min-height: 200px; }

.modal-tab-content {
    display: none;
    animation: fadeIn 0.20s ease;
    /* Contain repaints within the pane */
    contain: content;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

.modal-tab-content img {
    border-radius: var(--r-md);
    box-shadow: 0 4px 6px rgba(0,0,0,.30);
}

/* ── Attribute display (AttributeDisplay.js) ──────────────────── */
.attribute-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
    margin-top: 20px;
}

.attribute {
    background: var(--c-surface-3);
    padding: 12px;
    border-radius: var(--r-md);
    border: 1px solid var(--c-border);
}
.attribute-name  { font-size: 0.9rem;  color: var(--c-text-muted); margin-bottom: 6px; }
.attribute-value { font-size: 1.1rem;  color: var(--c-text);        font-weight: 600; }

/* ── AttributeDisplay enhanced rows ──────────────────────────── */
.ad-section-title {
    color: #63b3ed;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .12em;
    text-transform: uppercase;
    margin: 20px 0 8px;
    padding-bottom: 5px;
    border-bottom: 1px solid rgba(99,179,237,.20);
}

.ad-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px 12px;
    margin-bottom: 4px;
}

.ad-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 5px 8px;
    border-radius: 5px;
    background: var(--c-surface-3);
    cursor: default;
    transition: background var(--t-fast);
}
.ad-row:hover { background: rgba(51, 65, 85, .70); }
.ad-row[data-tooltip] { cursor: help; }
.ad-row[data-tooltip]:hover {
    background: rgba(59, 100, 150, .35);
    outline: 1px solid rgba(99, 179, 237, .25);
}

.ad-row--derived {
    background: rgba(30, 58, 90, .45);
    border-left: 2px solid rgba(99, 179, 237, .50);
}
.ad-row--derived:hover { background: rgba(30, 80, 120, .50); }

.ad-label {
    font-size: 12px;
    color: var(--c-text-muted);
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-right: 8px;
}
.ad-value {
    font-size: 12px;
    color: var(--c-text);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}
.ad-unit {
    font-size: 10px;
    color: var(--c-text-dim);
    margin-left: 3px;
}

.ad-base-ship { color: var(--c-accent-text); font-size: 13px; margin-bottom: 16px; }
.ad-base-ship strong { color: #bfdbfe; }

.ad-description {
    color: var(--c-text-mid);
    font-size: 13px;
    line-height: 1.55;
    margin-bottom: 12px;
    grid-column: 1 / -1;
}

.ad-stacking-section { margin-top: 12px; }
.ad-stacking-note {
    display: flex;
    gap: 8px;
    padding: 5px 8px;
    font-size: 11px;
    border-radius: 4px;
    background: var(--c-warn);
    border-left: 2px solid rgba(250,200,50,.40);
    margin-bottom: 4px;
}
.ad-stacking-key  { color: var(--c-warn-text); font-weight: 600; white-space: nowrap; }
.ad-stacking-rule { color: #a3a3a3; }

/* ── Location Display (LocationDisplay.js) ────────────────────── */
.ld-plugin-block {
    border: 1px solid var(--c-border);
    border-radius: var(--r-md);
    margin-bottom: 10px;
    overflow: hidden;
}
.ld-plugin-block.ld-plugin-active   { border-color: var(--c-border-hi); }
.ld-plugin-block.ld-plugin-inactive { border-color: var(--c-border-2); opacity: 0.85; }

.ld-plugin-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    cursor: pointer;
    background: var(--c-surface);
    user-select: none;
    transition: background var(--t-fast);
}
.ld-plugin-header:hover          { background: rgba(30,41,59,0.90); }
.ld-plugin-header:focus-visible  { outline: 2px solid var(--c-accent); outline-offset: -2px; }

.ld-plugin-name {
    flex: 1;
    font-weight: 600;
    font-size: 13px;
    color: var(--c-accent-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ld-plugin-badge {
    font-size: 10px;
    padding: 2px 7px;
    border-radius: 10px;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    flex-shrink: 0;
}
.ld-plugin-active .ld-plugin-badge {
    background: var(--c-success);
    color: var(--c-success-text);
    border: 1px solid rgba(34,197,94,0.35);
}
.ld-plugin-inactive .ld-plugin-badge {
    background: rgba(100,116,139,0.20);
    color: var(--c-text-muted);
    border: 1px solid var(--c-border-2);
}

.ld-arrow { font-size: 13px; color: var(--c-text-dim); flex-shrink: 0; transition: transform var(--t-fast); }

.ld-plugin-content-wrapper {
    padding: 12px 14px;
    background: rgba(15,23,42,0.35);
}
.ld-plugin-content { display: flex; flex-direction: column; gap: 12px; }

.ld-unused { font-size: 12px; color: var(--c-text-muted); font-style: italic; padding: 6px 0; }

.ld-category { display: flex; flex-direction: column; gap: 6px; }
.ld-category-header { display: flex; align-items: center; gap: 6px; }
.ld-category-icon  { font-size: 14px; line-height: 1; }
.ld-category-label {
    font-size: 12px;
    font-weight: 600;
    color: #7dd3fc;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}
.ld-category-count {
    font-size: 11px;
    color: var(--c-text-dim);
    background: rgba(100,116,139,0.15);
    border-radius: 8px;
    padding: 1px 6px;
}

.ld-pills { display: flex; flex-wrap: wrap; gap: 5px; }
.ld-pill {
    font-size: 11px;
    padding: 3px 9px;
    background: var(--c-surface-2);
    border: 1px solid var(--c-border);
    border-radius: 12px;
    color: var(--c-text-mid);
    white-space: nowrap;
    transition: border-color var(--t-fast), color var(--t-fast);
}
.ld-pill:hover { border-color: rgba(147,197,253,0.50); color: var(--c-text); }

.ld-empty {
    color: var(--c-text-dim);
    font-style: italic;
    font-size: 13px;
    text-align: center;
    padding: 20px 0;
}

/* ── Tooltip (AttributeDisplay.js) ───────────────────────────── */
#ad-tooltip {
    position: fixed;
    z-index: 9999;
    max-width: 320px;
    padding: 10px 14px;
    background: rgba(15,23,42,0.97);
    border: 1px solid rgba(99,179,237,0.35);
    border-radius: var(--r-md);
    color: var(--c-text);
    font-size: 12px;
    line-height: 1.55;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s ease;
    box-shadow: 0 8px 32px rgba(0,0,0,0.60);
    white-space: pre-wrap;
}

/* ── sorter-remove-btn — keep exact name, used by Sorter.js & generalPluginStuff.js ── */
.sorter-remove-btn {
    background: var(--c-danger);
    color: var(--c-danger-text);
    border: 1px solid rgba(239, 68, 68, 0.30);
    border-radius: var(--r-sm);
    padding: 4px 10px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: background var(--t-fast), border-color var(--t-fast), color var(--t-fast);
}
.sorter-remove-btn:hover {
    background: rgba(239, 68, 68, 0.30);
    border-color: var(--c-danger-hi);
    color: var(--c-danger-hi);
}

/* ── sorter-move-btn — keep exact name, used by Sorter.js & generalPluginStuff.js ── */
.sorter-move-btn {
    background: rgba(71, 85, 105, 0.50);
    color: var(--c-text-muted);
    border: 1px solid var(--c-border);
    border-radius: var(--r-sm);
    padding: 4px 9px;
    font-size: 0.75rem;
    cursor: pointer;
    transition: background var(--t-fast), color var(--t-fast), transform var(--t-fast);
}
.sorter-move-btn:hover:not(:disabled) {
    background: rgba(71, 85, 105, 0.90);
    color: var(--c-text);
    transform: translateY(-1px);
}
.sorter-move-btn:disabled { opacity: 0.30; cursor: default; transform: none; }

/* ── sorter-dir-btn — keep exact name, used by Sorter.js ─────────────────── */
.sorter-dir-btn {
    background: var(--c-surface-3);
    color: var(--c-accent-text);
    border: 1px solid var(--c-border-hi);
    border-radius: var(--r-sm);
    padding: 4px 12px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: background var(--t-fast), transform var(--t-fast);
    white-space: nowrap;
}
.sorter-dir-btn:hover {
    background: rgba(59, 130, 246, 0.30);
    border-color: var(--c-accent);
    transform: translateY(-1px);
}

/* ── sorter-row — keep exact name, used by Sorter.js & generalPluginStuff.js ── */
.sorter-row {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(15, 23, 42, 0.40);
    border: 1px solid var(--c-border);
    border-radius: var(--r-sm);
    padding: 8px 12px;
    flex-wrap: wrap;
    transition: background var(--t-fast), border-color var(--t-fast);
}
.sorter-row:hover {
    background: rgba(59, 130, 246, 0.10);
    border-color: rgba(59, 130, 246, 0.40);
}
.sorter-label {
    flex: 1;
    font-size: 0.95rem;
    color: var(--c-text-mid);
    min-width: 120px;
}

/* ── sorter-picker-row — keep exact name, used by Sorter.js renderPickerList() ── */
.sorter-picker-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: var(--r-sm);
    border: 1px solid transparent;
    cursor: pointer;
    transition: background var(--t-fast), border-color var(--t-fast);
    background: rgba(15, 23, 42, 0.30);
}
.sorter-picker-row:hover {
    background: rgba(59, 130, 246, 0.15);
    border-color: var(--c-border);
}
.sorter-picker-row input[type="checkbox"] {
    cursor: pointer;
    accent-color: var(--c-accent);
    width: 16px; height: 16px;
    flex-shrink: 0;
    pointer-events: none; /* row.onclick handles toggle; prevent double-fire */
}
.sorter-picker-row label {
    cursor: pointer;
    font-size: 0.95rem;
    color: var(--c-text-mid);
    flex: 1;
    margin-bottom: 0;
    user-select: none;
    pointer-events: none; /* prevent label for= from double-toggling checkbox */
}

/* ═══════════════════════════════════════════════════════════════
   Navbar
   ═══════════════════════════════════════════════════════════════ */

.es-nav {
  --nav-h:          56px;
  --nav-bg:         rgba(10, 18, 38, 0.88);
  --nav-border:     rgba(59, 130, 246, 0.25);
  --nav-accent:     #3b82f6;
  --nav-accent-text:#93c5fd;
  --nav-text:       #cbd5e1;
  --nav-text-muted: #64748b;
  --nav-hover-bg:   rgba(59, 130, 246, 0.12);
  --nav-active-bg:  rgba(59, 130, 246, 0.22);
  --nav-radius:     8px;
  --nav-t:          0.18s ease;

  position: sticky;
  top: 0;
  z-index: 900;
  width: 100%;
  height: var(--nav-h);
  background: var(--nav-bg);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--nav-border);
  box-shadow: 0 4px 24px rgba(0,0,0,0.35);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 8px;
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  box-sizing: border-box;

  /* Critical: let dropdown menus escape without clipping */
  overflow: visible;
}

/* ── Brand ──────────────────────────────────────────────────── */
.es-nav__brand {
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: var(--nav-accent-text);
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  white-space: nowrap;
  margin-right: 12px;
  flex-shrink: 0;
  transition: color var(--nav-t);
}
.es-nav__brand:hover   { color: #bfdbfe; }
.es-nav__brand-icon    { font-size: 1.3rem; line-height: 1; }

/* ── Divider ────────────────────────────────────────────────── */
.es-nav__divider {
  width: 1px;
  height: 28px;
  background: var(--nav-border);
  flex-shrink: 0;
  margin: 0 4px;
}

/* ── Link list ──────────────────────────────────────────────── */
.es-nav__links {
  display: flex;
  align-items: center;
  gap: 2px;
  list-style: none;
  margin: 0;
  padding: 0;
  flex: 1;

  /* overflow: visible so dropdowns are never clipped */
  overflow: visible;
}

.es-nav__links li { flex-shrink: 0; }

/* ── Nav link ───────────────────────────────────────────────── */
.es-nav__link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: var(--nav-radius);
  color: var(--nav-text);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  white-space: nowrap;
  transition: background var(--nav-t), color var(--nav-t);
  border: 1px solid transparent;
  cursor: pointer;
  background: none;
  font-family: inherit;
}
.es-nav__icon { font-size: 1rem; line-height: 1; }

.es-nav__link:hover {
  background: var(--nav-hover-bg);
  color: var(--nav-accent-text);
  border-color: rgba(59,130,246,0.20);
}
.es-nav__link.active {
  background: var(--nav-active-bg);
  color: var(--nav-accent-text);
  border-color: rgba(59,130,246,0.35);
}

/* ── Dropdown ───────────────────────────────────────────────── */
.es-nav__dropdown { position: relative; }

.es-nav__dropdown-toggle::after {
  content: '▾';
  font-size: 0.7rem;
  margin-left: 2px;
  opacity: 0.6;
  transition: transform var(--nav-t);
}
.es-nav__dropdown.open .es-nav__dropdown-toggle::after {
  transform: rotate(180deg);
}

.es-nav__dropdown-menu {
  display: none;
  position: fixed;   /* fixed instead of absolute — escapes every clipping ancestor */
  min-width: 200px;
  background: rgba(10, 18, 38, 0.97);
  border: 1px solid rgba(59,130,246,0.30);
  border-radius: var(--nav-radius);
  box-shadow: 0 12px 40px rgba(0,0,0,0.55);
  padding: 6px;
  z-index: 9999;
  animation: navDropIn 0.15s ease;
}
.es-nav__dropdown.open .es-nav__dropdown-menu { display: block; }

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

.es-nav__dropdown-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 6px;
  color: var(--nav-text);
  text-decoration: none;
  font-size: 0.88rem;
  transition: background var(--nav-t), color var(--nav-t);
  cursor: pointer;
}
.es-nav__dropdown-item:hover {
  background: var(--nav-hover-bg);
  color: var(--nav-accent-text);
}
.es-nav__dropdown-item .es-nav__icon { font-size: 0.95rem; opacity: 0.8; }

.es-nav__dropdown-sep {
  height: 1px;
  background: rgba(59,130,246,0.15);
  margin: 4px 6px;
}

/* ── Spacer ─────────────────────────────────────────────────── */
.es-nav__spacer { flex: 1; }

/* ── Hamburger ──────────────────────────────────────────────── */
.es-nav__hamburger {
  display: none;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 5px;
  width: 36px;
  height: 36px;
  border: 1px solid var(--nav-border);
  border-radius: var(--nav-radius);
  background: none;
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
  transition: background var(--nav-t), border-color var(--nav-t);
  margin-left: auto;
}
.es-nav__hamburger:hover {
  background: var(--nav-hover-bg);
  border-color: rgba(59,130,246,0.40);
}
.es-nav__hamburger span {
  display: block;
  width: 18px;
  height: 2px;
  background: var(--nav-text);
  border-radius: 2px;
  transition: transform 0.2s ease, opacity 0.2s ease;
}
.es-nav.nav-open .es-nav__hamburger span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.es-nav.nav-open .es-nav__hamburger span:nth-child(2) { opacity: 0; }
.es-nav.nav-open .es-nav__hamburger span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

/* ── Mobile drawer ──────────────────────────────────────────── */
.es-nav__drawer {
  display: none;
  position: fixed;
  top: 56px;
  left: 0;
  right: 0;
  background: rgba(10, 18, 38, 0.98);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid rgba(59, 130, 246, 0.25);
  padding: 12px 16px 20px;
  z-index: 899;
  flex-direction: column;
  gap: 4px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.60);
  animation: drawerSlide 0.2s ease;
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;

  --nav-accent-text: #93c5fd;
  --nav-text:        #cbd5e1;
  --nav-text-muted:  #64748b;
  --nav-hover-bg:    rgba(59, 130, 246, 0.12);
  --nav-active-bg:   rgba(59, 130, 246, 0.22);
  --nav-border:      rgba(59, 130, 246, 0.25);
  --nav-t:           0.18s ease;
  --nav-radius:      8px;
}
@keyframes drawerSlide {
  from { opacity: 0; transform: translateY(-10px); }
  to   { opacity: 1; transform: translateY(0); }
}
.es-nav__drawer.nav-drawer-open { display: flex; }

.es-nav__drawer .es-nav__link {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-radius: var(--nav-radius);
  color: var(--nav-text);
  text-decoration: none;
  font-size: 0.95rem;
  font-weight: 500;
  transition: background var(--nav-t), color var(--nav-t);
  border: 1px solid transparent;
  cursor: pointer;
  background: none;
  font-family: inherit;
}
.es-nav__drawer .es-nav__link:hover {
  background: var(--nav-hover-bg);
  color: var(--nav-accent-text);
  border-color: rgba(59,130,246,0.20);
}
.es-nav__drawer .es-nav__link.active {
  background: var(--nav-active-bg);
  color: var(--nav-accent-text);
  border-color: rgba(59,130,246,0.35);
}
.es-nav__drawer .nav-drawer-sep {
  height: 1px;
  background: rgba(59,130,246,0.15);
  margin: 6px 0;
}
.es-nav__drawer .nav-drawer-group-label {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--nav-text-muted);
  padding: 8px 14px 2px;
  user-select: none;
}
.es-nav__drawer .es-nav__icon { font-size: 1rem; line-height: 1; }

/* ── Battle Sim specific styles ─────────────────────────── */
.sim-layout {
   display: grid;
   grid-template-columns: 1fr auto 1fr;
   gap: 20px;
   align-items: start;
   margin-bottom: 24px;
}

@media (max-width: 820px) {
   .sim-layout { grid-template-columns: 1fr; }
   .sim-vs { text-align: center; font-size: 2rem; padding: 0; }
}

.sim-vs {
   display: flex;
   align-items: center;
   justify-content: center;
   font-size: 2.4rem;
   font-weight: 900;
   color: var(--c-accent-text);
   padding: 20px 10px;
   text-shadow: 0 0 24px rgba(59,130,246,0.6);
   letter-spacing: 0.05em;
   user-select: none;
}

/* ── Slot header box: name + plugin + X ─────────────────────────── */
.slot-header-box {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 10px 14px;
    background: var(--c-surface-2, rgba(30, 41, 59, 0.9));
    border: 1px solid var(--c-border, rgba(148,163,184,0.15));
    border-radius: 8px;
    margin-bottom: 8px;
}

.slot-header-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.slot-header-name {
    font-size: 1rem;
    font-weight: 600;
    color: var(--c-text, #e2e8f0);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.slot-header-plugin {
    font-size: 0.72rem;
    color: var(--c-text-muted, #64748b);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.slot-header-clear {
    flex-shrink: 0;
    background: none;
    border: 1px solid var(--c-border, rgba(148,163,184,0.2));
    border-radius: 5px;
    color: var(--c-text-muted, #64748b);
    font-size: 0.75rem;
    padding: 3px 7px;
    cursor: pointer;
    line-height: 1;
    transition: color 0.15s, border-color 0.15s;
}
.slot-header-clear:hover {
    color: var(--c-danger-text, #f87171);
    border-color: var(--c-danger-text, #f87171);
}

/* ── Slot image box ─────────────────────────────────────────────── */
.slot-image-box {
    background: var(--c-surface-1, rgba(15, 23, 42, 0.6));
    border: 1px solid var(--c-border, rgba(148,163,184,0.15));
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 120px;
}

/* ── Ship slot ─────────────────────────────────────────── */
.ship-slot {
   background: var(--c-surface);
   border: 1px solid var(--c-border);
   border-radius: var(--r-lg);
   padding: 20px;
   display: flex;
   flex-direction: column;
   gap: 14px;
   transition: border-color var(--t-base);
}
.ship-slot.slot-a { border-top: 3px solid #3b82f6; }
.ship-slot.slot-b { border-top: 3px solid #ef4444; }
.ship-slot.slot-a.has-ship { border-color: #3b82f6; box-shadow: 0 0 20px rgba(59,130,246,0.15); }
.ship-slot.slot-b.has-ship { border-color: #ef4444; box-shadow: 0 0 20px rgba(239,68,68,0.15); }

.slot-title {
   font-size: 0.75rem;
   font-weight: 700;
   letter-spacing: 0.12em;
   text-transform: uppercase;
}

.slot-a .slot-title { color: #93c5fd; }
.slot-b .slot-title { color: #fca5a5; }

.ship-search-wrap { position: relative; }

.ship-search-wrap input {
   width: 100%;
   padding: 10px 14px;
   background: var(--c-surface-2);
   border: 1px solid var(--c-border);
   border-radius: var(--r-md);
   color: var(--c-text);
   font-size: 0.9rem;
}

.ship-search-wrap input:focus {
   outline: none;
   border-color: var(--c-accent);
   box-shadow: 0 0 0 3px rgba(59,130,246,0.15);
}

.ship-dropdown {
   position: absolute;
   top: calc(100% + 4px);
   left: 0; right: 0;
   background: rgba(10,18,38,0.98);
   border: 1px solid var(--c-border);
   border-radius: var(--r-md);
   max-height: 260px;
   overflow-y: auto;
   z-index: 200;
   display: none;
   box-shadow: 0 12px 40px rgba(0,0,0,0.6);
}

.ship-dropdown.open { display: block; }

.ship-dropdown-item {
   padding: 9px 14px;
   cursor: pointer;
   font-size: 0.88rem;
   color: var(--c-text-mid);
   border-bottom: 1px solid rgba(59,130,246,0.07);
   display: flex;
   justify-content: space-between;
   align-items: center;
   gap: 8px;
   transition: background var(--t-fast);
}

.ship-dropdown-item:hover { background: rgba(59,130,246,0.15); color: var(--c-text); }

.ship-dropdown-item .sdi-plugin {
   font-size: 0.75rem;
   color: var(--c-text-dim);
   white-space: nowrap;
}

.ship-dropdown-empty {
   padding: 12px 14px;
   color: var(--c-text-muted);
   font-style: italic;
   font-size: 0.88rem;
}

/* ── Selected ship card ─────────────────────────────────── */
/* ── Selected ship card ─────────────────────────────────── */
.selected-ship {
    display: none;
    flex-direction: column;   /* stack vertically: header → image */
    gap: 0;
    background: transparent;
    border: none;
    padding: 0;
}
.selected-ship.visible { display: flex; }

/* Header row: name + plugin + X */
.selected-ship-info {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 10px 14px;
    background: var(--c-surface-2);
    border: 1px solid var(--c-border);
    border-radius: var(--r-md) var(--r-md) 0 0;
    min-width: 0;
    order: 1;
}

.selected-ship-name {
    font-weight: 700;
    font-size: 1.05rem;
    color: var(--c-accent-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    min-width: 0;
}

.selected-ship-meta {
    font-size: 0.78rem;
    color: var(--c-text-muted);
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Reuse existing .selected-ship-clear — just position it in the header */
.selected-ship-clear {
    background: none;
    border: none;
    color: var(--c-text-dim);
    cursor: pointer;
    font-size: 1.2rem;
    padding: 2px 6px;
    border-radius: var(--r-sm);
    flex-shrink: 0;
    order: 2;
    align-self: center;
    transition: color var(--t-fast), background var(--t-fast);
}
.selected-ship-clear:hover { color: var(--c-danger-hi); background: var(--c-danger); }

/* Image box: sits below the header */
.selected-ship-img {
    display: block;
    width: 100%;
    height: 180px;
    object-fit: contain;
    background: rgba(15, 23, 42, 0.55);
    border: 1px solid var(--c-border);
    border-top: none;
    border-radius: 0 0 var(--r-md) var(--r-md);
    image-rendering: pixelated;
    order: 3;
    padding: 12px;
    box-sizing: border-box;
}

/* canvas/img injected by fetchSprite inherits the same treatment */
.selected-ship canvas,
.selected-ship img:not(.selected-ship-img) {
    display: block;
    width: 100%;
    height: 180px;
    object-fit: contain;
    background: rgba(15, 23, 42, 0.55);
    border: 1px solid var(--c-border);
    border-top: none;
    border-radius: 0 0 var(--r-md) var(--r-md);
    image-rendering: pixelated;
    order: 3;
    padding: 12px;
    box-sizing: border-box;
}

/* ── Mini stat strip on the slot ──────────────────────────*/
.slot-stats {
   display: grid;
   grid-template-columns: 1fr 1fr;
   gap: 4px;
   margin-top: 4px;
}
.slot-stat {
   background: rgba(15,23,42,0.4);
   border: 1px solid var(--c-border);
   border-radius: var(--r-sm);
   padding: 5px 8px;
   font-size: 0.78rem;
}

.slot-stat-label { color: var(--c-text-muted); }
.slot-stat-value { color: var(--c-text); font-weight: 600; font-variant-numeric: tabular-nums; }

/* ── Fight button ────────────────────────────────────────── */
.fight-btn-wrap {
   display: flex;
   flex-direction: column;
   align-items: center;
   gap: 10px;
}

.fight-btn {
   width: 100%;
   padding: 16px 32px;
   background: linear-gradient(135deg, #2563eb, #7c3aed);
   border: none;
   border-radius: var(--r-lg);
   color: #fff;
   font-size: 1.1rem;
   font-weight: 800;
   letter-spacing: 0.06em;
   text-transform: uppercase;
   cursor: pointer;
   transition: transform var(--t-base), box-shadow var(--t-base), opacity var(--t-fast);
   box-shadow: 0 4px 20px rgba(59,130,246,0.35);
}

.fight-btn:hover:not(:disabled) {
   transform: translateY(-3px);
   box-shadow: 0 8px 32px rgba(59,130,246,0.5);
}
.fight-btn:disabled { opacity: 0.35; cursor: not-allowed; transform: none; }

/* ── Results panel ───────────────────────────────────────── */
#resultsPanel {
   display: none;
   animation: fadeIn 0.3s ease;
}

#resultsPanel.visible { display: block; }

.result-header {
   text-align: center;
   padding: 28px 20px 20px;
   border-bottom: 1px solid var(--c-border);
   margin-bottom: 24px;
}
.result-winner-label {
   font-size: 0.75rem;
   font-weight: 700;
   letter-spacing: 0.15em;
   text-transform: uppercase;
   color: var(--c-text-muted);
   margin-bottom: 8px;
}

.result-winner-name {
   font-size: 2rem;
   font-weight: 900;
   margin-bottom: 6px;
}
.result-winner-a { color: #60a5fa; text-shadow: 0 0 30px rgba(59,130,246,0.5); }
.result-winner-b { color: #f87171; text-shadow: 0 0 30px rgba(239,68,68,0.5); }
.result-winner-draw { color: var(--c-warn-text); }
.result-subtitle { font-size: 0.9rem; color: var(--c-text-muted); }

/* ── Timeline bar ────────────────────────────────────────── */
.timeline-section { margin-bottom: 24px; }

.timeline-label {
   font-size: 0.72rem;
   font-weight: 700;
   letter-spacing: 0.1em;
   text-transform: uppercase;
   color: var(--c-text-dim);
   margin-bottom: 10px;
}

.timeline-track {
   position: relative;
   height: 48px;
   background: rgba(15,23,42,0.6);
   border: 1px solid var(--c-border);
   border-radius: 24px;
   overflow: hidden;
}

.timeline-bar-a {
   position: absolute;
   left: 0; top: 0; bottom: 0;
   background: linear-gradient(90deg, rgba(59,130,246,0.7), rgba(59,130,246,0.3));
   border-radius: 24px 0 0 24px;
   transition: width 0.6s cubic-bezier(0.16,1,0.3,1);
   display: flex;
   align-items: center;
   padding-left: 12px;
}

.timeline-bar-b {
   position: absolute;
   right: 0; top: 0; bottom: 0;
   background: linear-gradient(270deg, rgba(239,68,68,0.7), rgba(239,68,68,0.3));
   border-radius: 0 24px 24px 0;
   transition: width 0.6s cubic-bezier(0.16,1,0.3,1);
   display: flex;
   align-items: center;
   justify-content: flex-end;
   padding-right: 12px;
}

.timeline-bar-label {
   font-size: 0.75rem;
   font-weight: 700;
   color: rgba(255,255,255,0.9);
   white-space: nowrap;
}

.timeline-midline {
   position: absolute;
   left: 50%; top: 0; bottom: 0;
   width: 1px;
   background: rgba(255,255,255,0.15);
   pointer-events: none;
}

/* ═══════════════════════════════════════════════════════════════
   Battle Simulator — Results Output Styles  (add to main.css)
   ═══════════════════════════════════════════════════════════════ */

/* ── Sim loading indicator ───────────────────────────────────── */
.sim-loading {
    display: none;
    text-align: center;
    padding: 24px;
    color: var(--c-accent-text);
    font-size: 0.95rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    animation: simPulse 1.2s ease-in-out infinite;
}
.sim-loading.visible { display: block; }

@keyframes simPulse {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0.4; }
}

/* ═══════════════════════════════════════════════════════════════
   Stats Comparison Grid  (renderCompareGrid)
   ═══════════════════════════════════════════════════════════════ */

.res-section-title {
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.13em;
    text-transform: uppercase;
    color: #63b3ed;
    padding: 18px 0 8px;
    border-bottom: 1px solid rgba(99, 179, 237, 0.18);
    margin-bottom: 6px;
}

.results-compare {
    display: grid;
    grid-template-columns: 1fr minmax(18px, 0.6fr) 1fr;
    gap: 0 8px;
    margin-bottom: 4px;
}

.res-col {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.res-col-a .res-row { justify-content: flex-end; text-align: right; }
.res-col-b .res-row { justify-content: flex-start; text-align: left; }

.res-row {
    display: flex;
    align-items: center;
    min-height: 28px;
    padding: 3px 10px;
    border-radius: var(--r-sm);
    background: rgba(15, 23, 42, 0.35);
    transition: background var(--t-fast);
}
.res-row:hover { background: rgba(30, 58, 138, 0.25); }

.res-row-value {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--c-text);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.res-col-a .res-row-value { color: #93c5fd; }
.res-col-b .res-row-value { color: #fca5a5; }

.res-divider {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.res-divider-item {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 28px;
    padding: 3px 8px;
    font-size: 0.73rem;
    color: var(--c-text-muted);
    text-align: center;
    line-height: 1.3;
    border-radius: var(--r-sm);
    background: rgba(15, 23, 42, 0.20);
}

@media (max-width: 690px) {
    .results-compare { grid-template-columns: 1fr; }
    .res-divider      { display: none; }
    .res-col          { flex-direction: row; flex-wrap: wrap; gap: 4px; }
    .res-col-a .res-row,
    .res-col-b .res-row { flex: 1 1 120px; justify-content: center; text-align: center; }
}

/* ═══════════════════════════════════════════════════════════════
   Weapon Analysis  (renderWeaponsList)
   ═══════════════════════════════════════════════════════════════ */

.weapons-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 24px;
}

@media (max-width: 640px) {
    .weapons-grid { grid-template-columns: 1fr; }
}

.weapons-col-title {
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    margin-bottom: 8px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--c-border);
}
.weapons-col-title-a { color: #93c5fd; border-color: rgba(59, 130, 246, 0.30); }
.weapons-col-title-b { color: #fca5a5; border-color: rgba(239, 68,  68, 0.30); }

.weapon-item {
    background: rgba(15, 23, 42, 0.45);
    border: 1px solid var(--c-border);
    border-radius: var(--r-md);
    padding: 10px 12px;
    margin-bottom: 6px;
    transition: border-color var(--t-fast), background var(--t-fast);
}
.weapon-item:hover {
    border-color: rgba(59, 130, 246, 0.45);
    background: rgba(15, 23, 42, 0.65);
}
.weapon-item:last-child { margin-bottom: 0; }

.weapon-item-name {
    font-size: 0.88rem;
    font-weight: 700;
    color: var(--c-accent-text);
    margin-bottom: 6px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.weapon-item-stats {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 8px;
}

.weapon-stat {
    font-size: 0.75rem;
    color: var(--c-text-muted);
    background: rgba(30, 41, 59, 0.60);
    border: 1px solid var(--c-border-2);
    border-radius: 4px;
    padding: 2px 7px;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}
.weapon-stat span {
    color: var(--c-text);
    font-weight: 600;
    margin-left: 2px;
}

/* ═══════════════════════════════════════════════════════════════
   Combat Phases Timeline
   ═══════════════════════════════════════════════════════════════ */

.phase-list {
    display: flex;
    flex-direction: column;
    gap: 5px;
    margin-bottom: 8px;
}

.phase-item {
    display: flex;
    align-items: baseline;
    gap: 10px;
    padding: 9px 14px;
    border-radius: var(--r-md);
    border-left: 3px solid transparent;
    font-size: 0.86rem;
    line-height: 1.45;
    transition: background var(--t-fast);
    background: rgba(15, 23, 42, 0.35);
}
.phase-item:hover { background: rgba(15, 23, 42, 0.60); }

.phase-A {
    border-left-color: #3b82f6;
    background: rgba(59, 130, 246, 0.07);
}
.phase-A:hover { background: rgba(59, 130, 246, 0.13); }

.phase-B {
    border-left-color: #ef4444;
    background: rgba(239, 68, 68, 0.07);
}
.phase-B:hover { background: rgba(239, 68, 68, 0.13); }

.phase-neutral {
    border-left-color: var(--c-text-dim);
    background: rgba(100, 116, 139, 0.07);
    font-style: italic;
    color: var(--c-text-muted);
}

.phase-time {
    font-size: 0.72rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: var(--c-text-dim);
    background: rgba(15, 23, 42, 0.60);
    border: 1px solid var(--c-border-2);
    border-radius: 4px;
    padding: 2px 7px;
    white-space: nowrap;
    flex-shrink: 0;
    letter-spacing: 0.03em;
    min-width: 46px;
    text-align: center;
}

.phase-A .phase-time { color: #93c5fd; border-color: rgba(59, 130, 246, 0.30); }
.phase-B .phase-time { color: #fca5a5; border-color: rgba(239, 68,  68, 0.30); }

.phase-icon {
    font-size: 0.85rem;
    flex-shrink: 0;
    line-height: 1;
}

.phase-text { color: var(--c-text-mid); flex: 1; }
.phase-text strong { color: var(--c-text); font-weight: 700; }

/* ═══════════════════════════════════════════════════════════════
   HP Chart
   ═══════════════════════════════════════════════════════════════ */

.hp-chart-wrap {
    background: rgba(15, 23, 42, 0.4);
    border: 1px solid var(--c-border);
    border-radius: var(--r-md);
    overflow: hidden;
    padding: 4px;
    margin-bottom: 24px;
}

/* Mobile frendly */

/* ═══════════════════════════════════════════════════════════════
   Battle Simulator — CSS additions / overrides
   Append these rules to the end of main.css
   ═══════════════════════════════════════════════════════════════ */

/* ── Fix: selected-ship should be column (header then image) ──── */
/* The clear button is a sibling of selected-ship-info — both are
   direct children of .selected-ship. We want them in a row on the
   header line, not stacked.  Override the flex direction so the
   info block and clear button sit side-by-side, then the image
   spans the full width below. */

.selected-ship {
    display: none;
    flex-direction: column;
    gap: 0;
}
.selected-ship.visible { display: flex; }

/* Header row: info text + clear button sit inline */
.selected-ship-info {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    background: var(--c-surface-2);
    border: 1px solid var(--c-border);
    border-radius: var(--r-md) var(--r-md) 0 0;
    min-width: 0;
}

/* Name and plugin label stack vertically inside the info block */
.selected-ship-name {
    flex: 1;
    min-width: 0;
    font-weight: 700;
    font-size: 1rem;
    color: var(--c-accent-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.selected-ship-meta {
    font-size: 0.75rem;
    color: var(--c-text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 2px;
}

/* Clear button sits at the end of the info row */
.selected-ship-clear {
    flex-shrink: 0;
    align-self: center;
    background: none;
    border: 1px solid rgba(148,163,184,0.2);
    border-radius: var(--r-sm);
    color: var(--c-text-dim);
    font-size: 0.8rem;
    padding: 3px 7px;
    cursor: pointer;
    line-height: 1;
    transition: color var(--t-fast), border-color var(--t-fast);
}
.selected-ship-clear:hover {
    color: var(--c-danger-hi);
    border-color: var(--c-danger-hi);
}

/* Image fills width below header */
.selected-ship-img {
    display: block;
    width: 100%;
    height: 160px;
    object-fit: contain;
    background: rgba(15,23,42,0.55);
    border: 1px solid var(--c-border);
    border-top: none;
    border-radius: 0 0 var(--r-md) var(--r-md);
    image-rendering: pixelated;
    padding: 10px;
    box-sizing: border-box;
}

/* fetchSprite canvas/img replacement inherits the same look */
.selected-ship canvas,
.selected-ship img:not(.selected-ship-img) {
    display: block;
    width: 100%;
    height: 160px;
    object-fit: contain;
    background: rgba(15,23,42,0.55);
    border: 1px solid var(--c-border);
    border-top: none;
    border-radius: 0 0 var(--r-md) var(--r-md);
    image-rendering: pixelated;
    padding: 10px;
    box-sizing: border-box;
}

/* ── Slot-stats: mobile-friendly grid ────────────────────────── */
.slot-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px;
    margin-top: 6px;
}

.slot-stat {
    background: rgba(15,23,42,0.4);
    border: 1px solid var(--c-border);
    border-radius: var(--r-sm);
    padding: 6px 8px;
    font-size: 0.76rem;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.slot-stat-label {
    color: var(--c-text-muted);
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.slot-stat-value {
    color: var(--c-text);
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    font-size: 0.82rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ── Ensure simResults is hidden until JS populates it ────────── */
/* JS calls el.style.display = 'none' on DOMContentLoaded,
   but this provides a fallback for slower load paths */
#simResults:empty { display: none !important; }

/* ── Responsive: single-column results on narrow screens ─────── */
@media (max-width: 600px) {
    .results-compare {
        grid-template-columns: 1fr;
        gap: 2px;
    }
    .res-divider { display: none; }
    .res-col { gap: 2px; }
    .res-col-a .res-row,
    .res-col-b .res-row { justify-content: flex-start; text-align: left; }
    .res-col-a .res-row-value,
    .res-col-b .res-row-value { color: var(--c-text); font-size: 0.8rem; }

    /* Restore readable contrast — no blue/red split on mobile */
    .res-col-a .res-row-value { color: #93c5fd; }
    .res-col-b .res-row-value { color: #fca5a5; }

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

    .slot-stats { grid-template-columns: 1fr 1fr; }

    .fight-btn { font-size: 0.95rem; padding: 14px 20px; }

    .sim-vs { font-size: 1.8rem; padding: 6px 0; }
}

@media (max-width: 420px) {
    .slot-stats { grid-template-columns: 1fr; }
    .slot-stat { flex-direction: row; justify-content: space-between; align-items: center; }
}

/* ── Phase item: make icon + time + text wrap cleanly ─────────── */
.phase-item {
    display: flex;
    align-items: baseline;
    flex-wrap: wrap;
    gap: 6px 10px;
}

.phase-icon { flex-shrink: 0; line-height: 1; }
.phase-time {
    font-size: 0.72rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: var(--c-text-dim);
    background: rgba(15,23,42,0.60);
    border: 1px solid var(--c-border-2);
    border-radius: 4px;
    padding: 2px 7px;
    white-space: nowrap;
    flex-shrink: 0;
    min-width: 46px;
    text-align: center;
}
.phase-text { flex: 1; min-width: 120px; color: var(--c-text-mid); }
.phase-text strong { color: var(--c-text); font-weight: 700; }

.phase-A .phase-time { color: #93c5fd; border-color: rgba(59,130,246,0.30); }
.phase-B .phase-time { color: #fca5a5; border-color: rgba(239,68,68,0.30); }

/* ── HP chart wrapper ─────────────────────────────────────────── */
.hp-chart-wrap {
    background: rgba(15,23,42,0.4);
    border: 1px solid var(--c-border);
    border-radius: var(--r-md);
    overflow: hidden;
    padding: 4px;
    margin-bottom: 20px;
}

/* ── Weapon sub badge ─────────────────────────────────────────── */
.weapon-sub-badge {
    display: inline-block;
    font-size: 0.68rem;
    padding: 1px 5px;
    background: rgba(59,130,246,0.15);
    border: 1px solid rgba(59,130,246,0.30);
    border-radius: 4px;
    color: var(--c-accent-text);
    vertical-align: middle;
    margin-left: 4px;
}

/* ═══════════════════════════════════════════════════════════════
   MOBILE PATCH — append to the END of main.css
   (or replace the existing mobile results-compare block if present)
   ═══════════════════════════════════════════════════════════════ */

/* ── HP chart: always fills container, never overflows ───────── */
.hp-chart-wrap {
    overflow: hidden;
}
.hp-chart-wrap svg {
    display: block;
    width: 100%;
    height: auto;          /* respects viewBox aspect ratio        */
    max-height: 220px;     /* cap on wide/desktop                  */
}

/* ── Stats comparison: mobile labelled-row layout ────────────── */

/*
 * .res-row-mobile is generated by buildCompareGrid() alongside the
 * existing desktop three-column markup.  It is hidden on desktop
 * and shown on mobile where the three-column grid collapses.
 */
.res-row-mobile {
    display: none;   /* hidden by default — mobile @media shows it */
}

@media (max-width: 690px) {

    /* Hide the three-column desktop structure */
    .results-compare .res-col    { display: none !important; }
    .results-compare .res-divider { display: none !important; }

    /* Show the mobile rows instead */
    .res-row-mobile {
        display: grid;
        grid-template-columns: 1fr auto auto;
        align-items: center;
        gap: 0 8px;
        min-height: 28px;
        padding: 5px 10px;
        border-radius: var(--r-sm, 6px);
        background: rgba(15, 23, 42, 0.35);
        transition: background 0.15s ease;
    }
    .res-row-mobile:hover {
        background: rgba(30, 58, 138, 0.25);
    }

    .res-row-mobile__label {
        font-size: 0.74rem;
        color: var(--c-text-muted, #94a3b8);
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .res-row-mobile__val-a {
        font-size: 0.8rem;
        font-weight: 700;
        color: #93c5fd;
        font-variant-numeric: tabular-nums;
        white-space: nowrap;
        text-align: right;
        min-width: 44px;
    }

    .res-row-mobile__val-b {
        font-size: 0.8rem;
        font-weight: 700;
        color: #fca5a5;
        font-variant-numeric: tabular-nums;
        white-space: nowrap;
        text-align: right;
        min-width: 44px;
    }

    /* Section title stays full-width */
    .res-section-title {
        grid-column: 1 / -1;
    }

    /* Weapons grid: single column on mobile */
    .weapons-grid { grid-template-columns: 1fr; }

    /* Phase items: allow text to wrap */
    .phase-item { flex-wrap: wrap; }
    .phase-text { min-width: 0; flex: 1 1 160px; }
}

/* ── Responsive ─────────────────────────────────────────────── */
@media (max-width: 600px) {
  .es-nav__links    { display: none; }
  .es-nav__divider  { display: none; }
  .es-nav__spacer   { display: none; }
  .es-nav__hamburger { display: flex; }
}

@media (max-width: 768px) {
    .modal-tab { padding: 10px 16px; font-size: 0.9rem; }
    .modal-tab-content .attribute-grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
        gap: 12px;
    }
}
@media (max-width: 600px) {
    .list-row__label { min-width: 90px; font-size: 0.85rem; }
    .sorter-avg      { display: none; }
}
@media (max-width: 500px) {
    .ad-grid { grid-template-columns: 1fr; }
}
