:root {
    /* Dark Mode (Default) */
    --bg-color: #111827;
    --card-bg: #1f2937;
    --text-primary: #f9fafb;
    --text-secondary: #9ca3af;
    --border: #374151;
    --accent: #60a5fa;
    --accent-hover: #3b82f6;
    --header-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.5);
    --table-row-hover: #374151;

    /* Semantic Colors */
    --eff-border: #fdba74;
    --res-border: #93c5fd;
    --neu-border: #4b5563;
    --stat-bar-bg: #374151;
    --stat-bar-fill: #60a5fa;

    /* Badges */
    --sc-bg: #064e3b; --sc-text: #6ee7b7;
    --lw-bg: #7f1d1d; --lw-text: #fca5a5;
    --solo-bg: #1e3a8a; --solo-text: #93c5fd;
    --aoe-bg: #7c2d12; --aoe-text: #fdba74;
    
    /* Animation Speeds */
    --anim-fast: 0.15s;
    --anim-med: 0.3s;
}

[data-theme="light"] {
    --bg-color: #f3f4f6;
    --card-bg: #ffffff;
    --text-primary: #111827;
    --text-secondary: #4b5563;
    --border: #e5e7eb;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --header-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --table-row-hover: #f9fafb;

    --eff-border: #f97316;
    --res-border: #3b82f6;
    --neu-border: #e5e7eb;
    --stat-bar-bg: #e5e7eb;
    --stat-bar-fill: #3b82f6;

    --sc-bg: #ecfdf5; --sc-text: #047857;
    --lw-bg: #fef2f2; --lw-text: #b91c1c;
    --solo-bg: #eff6ff; --solo-text: #1d4ed8;
    --aoe-bg: #fff7ed; --aoe-text: #c2410c;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    margin: 0;
    transition: background-color var(--anim-med), color var(--anim-med);
}

/* --- Header Layout --- */
header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--header-shadow);
    padding: 1rem 2rem;
    max-height: 95vh;
    overflow-y: auto;
    transition: background-color var(--anim-med), border-color var(--anim-med);
}

.header-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

.title-area { display: flex; align-items: center; gap: 1rem; }
h1 { font-size: 1.25rem; margin: 0; }

#theme-toggle {
    background: none; border: 1px solid var(--border);
    border-radius: 50%; width: 32px; height: 32px;
    cursor: pointer; display: flex; align-items: center; justify-content: center;
    font-size: 1.2rem; transition: background-color var(--anim-med);
    color: var(--text-primary);
}
#theme-toggle:hover { background-color: var(--border); }

#collapse-btn {
    background: none; border: none; cursor: pointer;
    color: var(--text-secondary); display: flex; align-items: center; gap: 0.5rem;
    transition: color var(--anim-med);
}
#collapse-btn:hover { color: var(--text-primary); }

.icon-chevron { transition: transform var(--anim-med) ease; }

.options-content {
    transition: max-height 0.4s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s ease, margin 0.3s ease;
    overflow: hidden; opacity: 1;
}
.options-content.collapsed { max-height: 0; opacity: 0; margin: 0; }

/* --- Sections --- */
.section-block { margin-bottom: 1.5rem; }
.section-title {
    font-size: 0.75rem; font-weight: 700; text-transform: uppercase;
    color: var(--text-secondary); margin-bottom: 1rem; letter-spacing: 0.05em;
    border-bottom: 1px solid var(--border); padding-bottom: 0.5rem;
}

/* --- Calculation Params --- */
.calc-group { margin-bottom: 1.5rem; }
.group-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.75rem; }
.group-header label { font-weight: 600; font-size: 0.9rem; }

/* Elegant Mode Tabs */
.mode-tabs {
    display: flex; background: var(--bg-color); border-radius: 8px;
    padding: 3px; border: 1px solid var(--border);
}
.mode-tab {
    background: transparent; border: none; color: var(--text-secondary);
    padding: 6px 16px; font-size: 0.8rem; font-weight: 600;
    cursor: pointer; border-radius: 6px; transition: all var(--anim-med) ease;
}
.mode-tab.active {
    background: var(--card-bg); color: var(--text-primary);
    box-shadow: 0 1px 2px rgba(0,0,0,0.2);
}

/* Panels */
.panel { transition: opacity var(--anim-med), transform var(--anim-med); transform-origin: top; }
.panel.disabled { display: none; }

/* Element Filters (Icon Buttons) */
.element-btn {
    border: 2px solid transparent; padding: 0; border-radius: 8px; cursor: pointer;
    background: var(--bg-color); width: 50px; height: 50px;
    display: flex; align-items: center; justify-content: center;
    transition: all var(--anim-med); overflow: hidden;
}
.element-btn img { width: 95%; height: 95%; object-fit: contain; }
.element-btn:hover { transform: translateY(-2px); }
.element-btn.effective { border-color: var(--eff-border); background-color: rgba(249, 115, 22, 0.1); }
.element-btn.resist { border-color: var(--res-border); background-color: rgba(59, 130, 246, 0.1); }

.legend { margin-top: 8px; font-size: 0.75rem; color: var(--text-secondary); display: flex; gap: 12px; }
.legend .dot { width: 8px; height: 8px; display: inline-block; border-radius: 50%; }
.legend .effective { background: var(--eff-border); }
.legend .resist { background: var(--res-border); }
.legend .neutral { background: var(--text-secondary); opacity: 0.5;}

/* Killers */
.slider-container { padding: 0.5rem 0; }
input[type=range] { width: 100%; cursor: pointer; accent-color: var(--accent); }
.slider-labels { display: flex; justify-content: space-between; font-size: 0.75rem; color: var(--text-secondary); margin-top: 6px; }
.slider-value-display { font-size: 0.85rem; margin-top: 0.5rem; font-weight: 500; }

.tag-input-container {
    border: 1px solid var(--border); background: var(--bg-color);
    padding: 0.5rem; border-radius: 6px; display: flex; flex-wrap: wrap; gap: 0.5rem;
    transition: border-color var(--anim-med);
}
.tag-input-container.error { border-color: #ef4444; animation: shake 0.3s cubic-bezier(.36,.07,.19,.97) both; }
@keyframes shake {
  10%, 90% { transform: translate3d(-1px, 0, 0); }
  20%, 80% { transform: translate3d(2px, 0, 0); }
  30%, 50%, 70% { transform: translate3d(-4px, 0, 0); }
  40%, 60% { transform: translate3d(4px, 0, 0); }
}

.tag-list { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.tag {
    background: var(--accent); color: white; padding: 4px 10px;
    border-radius: 4px; font-size: 0.9rem; display: flex; align-items: center; gap: 6px;
    animation: fadeIn 0.2s ease-out;
}
@keyframes fadeIn { from { opacity: 0; transform: scale(0.9); } to { opacity: 1; transform: scale(1); } }
.tag .remove { cursor: pointer; font-weight: bold; opacity: 0.7; }
.tag .remove:hover { opacity: 1; }

#tag-input, #enemy-input {
    border: none; background: transparent; outline: none; flex-grow: 1;
    color: var(--text-primary); min-width: 120px; font-size: 0.9rem; padding: 4px 0;
}

/* --- Common UI --- */
.toggle-grid { display: flex; flex-wrap: wrap; gap: 0.75rem; }
.filter-row { display: flex; gap: 2rem; flex-wrap: wrap; margin-bottom: 1rem; }
.filter-row.full-width { display: block; margin-bottom: 1.5rem; }

.segmented-control {
    display: inline-flex; background: var(--bg-color); 
    padding: 4px; border-radius: 8px; border: 1px solid var(--border); 
}
.segmented-control.wide { width: 100%; display: flex; box-sizing: border-box; }
.segmented-control.wide .segment { flex: 1; text-align: center; }

.segment {
    border: none; background: transparent; padding: 0.6rem 1.5rem;
    border-radius: 6px; cursor: pointer; color: var(--text-secondary);
    font-weight: 500; font-size: 0.9rem;
    transition: background-color 0.3s ease, color 0.3s ease, transform 0.2s ease, box-shadow 0.3s ease;
}
.segment:hover:not(.active) { color: var(--text-primary); }
.segment.active { 
    background: var(--card-bg); color: var(--text-primary); 
    box-shadow: 0 1px 2px rgba(0,0,0,0.2); transform: scale(1.02); 
}

/* --- Filter Buttons --- */
.filter-btn {
    background: var(--bg-color); border: 1px solid var(--border);
    cursor: pointer; display: flex; align-items: center; justify-content: center;
    color: var(--text-secondary); transition: all 0.3s ease;
}
.filter-btn:hover { background-color: var(--border); }
.filter-btn.text-mode { padding: 0.6rem 1.2rem; border-radius: 6px; font-size: 0.9rem; font-weight: 500; }
.filter-btn.text-mode.active { background: var(--accent); color: white; border-color: var(--accent); }
.filter-btn.icon-mode {
    width: 50px; height: 50px; padding: 0; border-radius: 8px; overflow: hidden; border: 2px solid transparent;
}
.filter-btn.icon-mode img {
    width: 95%; height: 95%; object-fit: contain; filter: grayscale(100%) opacity(0.5); transition: filter 0.3s ease;
}
.filter-btn.icon-mode span { font-size: 0.7rem; font-weight: bold; }
.filter-btn.icon-mode.active { background-color: transparent; border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.filter-btn.icon-mode.active img { filter: none; opacity: 1; }

/* --- Table --- */
main { padding: 2rem; max-width: 1200px; margin: 0 auto; }
.table-wrapper {
    background: var(--card-bg); border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1); overflow-x: auto;
    position: relative; /* For Loading Overlay */
    min-height: 200px;
}
table { width: 100%; border-collapse: collapse; min-width: 800px; }
th { text-align: left; padding: 1rem; border-bottom: 2px solid var(--border); color: var(--text-secondary); font-size: 0.85rem; }
td { padding: 0.85rem 1rem; border-bottom: 1px solid var(--border); vertical-align: middle; transition: border-color var(--anim-med); }
tr { transition: background-color 0.2s ease; cursor: pointer; }
tr:hover td { background-color: var(--table-row-hover); }

.col-rank { font-weight: bold; color: var(--text-secondary); width: 50px;}
.col-name { font-weight: 600; font-size: 1rem; }
.col-class img.class-icon { width: 34px; height: 34px; object-fit: contain; vertical-align: middle; }
.col-dmg { font-family: 'JetBrains Mono', monospace; font-weight: 600; color: var(--text-primary); font-size: 1.1rem; }

.badge { padding: 0.3rem 0.6rem; border-radius: 4px; font-size: 0.8rem; font-weight: 700; text-transform: uppercase; }
.badge-sc { background: var(--sc-bg); color: var(--sc-text); }
.badge-lw { background: var(--lw-bg); color: var(--lw-text); }
.badge-solo { background: var(--solo-bg); color: var(--solo-text); }
.badge-aoe { background: var(--aoe-bg); color: var(--aoe-text); }
.hidden { display: none !important; }

/* --- Loading Overlay --- */
#loading-overlay {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(var(--card-bg), 0.7); /* Fallback */
    backdrop-filter: blur(2px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 50;
    gap: 1rem;
    color: var(--text-primary);
    font-weight: 600;
}
/* Ensure overlay background matches theme opacity */
[data-theme="light"] #loading-overlay { background: rgba(255, 255, 255, 0.7); }
[data-theme="dark"] #loading-overlay { background: rgba(31, 41, 55, 0.7); }

.spinner {
    width: 40px; height: 40px;
    border: 4px solid var(--border);
    border-top: 4px solid var(--accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }

/* --- Modal --- */
.modal-backdrop {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.7); z-index: 1000;
    display: flex; justify-content: center; align-items: center;
    backdrop-filter: blur(4px);
    opacity: 0; pointer-events: none; transition: opacity 0.3s ease;
}
.modal-backdrop.open { opacity: 1; pointer-events: auto; }

.modal-content {
    background: var(--card-bg); width: 90%; max-width: 650px; /* Slightly wider for new data */
    max-height: 90vh; overflow-y: auto; border-radius: 16px;
    border: 1px solid var(--border);
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.5);
    transform: translateY(20px); transition: transform 0.3s ease;
    padding: 1.5rem;
}
.modal-backdrop.open .modal-content { transform: translateY(0); }

.modal-header {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 1.5rem; border-bottom: 1px solid var(--border); padding-bottom: 1rem;
}
.modal-title h2 { margin: 0; font-size: 1.5rem; color: var(--text-primary); }
.modal-subtitle { color: var(--text-secondary); font-size: 0.9rem; margin-top: 4px; display: flex; gap: 1rem; align-items: center; }
.modal-close {
    background: none; border: none; font-size: 1.5rem; color: var(--text-secondary); cursor: pointer;
}
.modal-close:hover { color: var(--text-primary); }

.modal-section { margin-bottom: 1.5rem; }
.modal-section h3 { font-size: 0.9rem; text-transform: uppercase; color: var(--text-secondary); margin-bottom: 1rem; }

/* Stat Bars */
.stat-grid { display: grid; gap: 0.8rem; }
.stat-row { display: flex; align-items: center; gap: 1rem; font-size: 0.85rem; }
.stat-label { width: 80px; font-weight: 600; color: var(--text-secondary); }
.stat-bar-container { flex: 1; height: 8px; background: var(--stat-bar-bg); border-radius: 4px; overflow: hidden; }
.stat-bar { height: 100%; background: var(--stat-bar-fill); border-radius: 4px; }
.stat-value { width: 50px; text-align: right; font-family: 'JetBrains Mono', monospace; }

/* Attack Cards */
.attacks-container { display: flex; flex-direction: column; gap: 1rem; }
.attack-card {
    background: var(--bg-color); border: 1px solid var(--border);
    border-radius: 8px; padding: 1rem; display: flex; flex-direction: column; gap: 1rem;
}
.attack-card.disabled { opacity: 0.5; border-style: dashed; }

.attack-header { display: flex; justify-content: space-between; align-items: flex-start; }
.attack-info { display: flex; flex-direction: column; gap: 4px; }
.attack-name { font-weight: 700; font-size: 1rem; }
.attack-meta { display: flex; gap: 8px; font-size: 0.8rem; color: var(--text-secondary); align-items: center; }
.attack-dmg { font-family: 'JetBrains Mono', monospace; font-size: 1.25rem; font-weight: 700; color: var(--accent); }
.attack-dmg.na { color: var(--text-secondary); font-size: 1rem; }

.mini-icon { width: 16px; height: 16px; object-fit: contain; vertical-align: text-bottom; }

/* --- Line Breakdown Visualization --- */
.best-card-label {
    font-size: 0.8rem; color: var(--text-secondary);
    background: rgba(0,0,0,0.2); padding: 4px 8px; border-radius: 4px;
    display: inline-block; margin-top: 4px;
}
[data-theme="light"] .best-card-label { background: rgba(0,0,0,0.05); }

.line-breakdown {
    display: flex; flex-direction: column; gap: 4px;
    margin-top: 0.5rem; border-top: 1px solid var(--border); padding-top: 0.75rem;
}
.line-row {
    display: flex; align-items: center; gap: 8px;
    padding: 3px 6px; border-radius: 4px; font-size: 0.75rem;
}

/* Yin/Yang Backgrounds */
.line-row.is-yin { background-color: rgba(17, 24, 39, 0.8); } /* Darker */
.line-row.is-yang { background-color: rgba(55, 65, 81, 0.6); } /* Lighter */

[data-theme="light"] .line-row.is-yin { background-color: #e5e7eb; }
[data-theme="light"] .line-row.is-yang { background-color: #f3f4f6; }

.line-num { width: 15px; font-weight: bold; color: var(--text-secondary); }

.line-bar-track { flex: 1; height: 6px; background: rgba(255,255,255,0.1); border-radius: 3px; overflow: hidden; }
[data-theme="light"] .line-bar-track { background: rgba(0,0,0,0.1); }

.line-bar-fill { height: 100%; background: var(--accent); transition: width 0.3s ease; }

.line-info { width: 140px; display: flex; justify-content: flex-end; gap: 8px; align-items: center; }
.line-val { font-family: 'JetBrains Mono', monospace; min-width: 30px; text-align: right; }

/* Status Indicators */
.eff-badge { font-size: 0.65rem; padding: 1px 4px; border-radius: 3px; text-transform: uppercase; font-weight: 700; }
.eff-badge.eff { color: #f97316; background: rgba(249, 115, 22, 0.1); }
.eff-badge.res { color: #3b82f6; background: rgba(59, 130, 246, 0.1); }
.eff-badge.neu { color: var(--text-secondary); opacity: 0.7; }

.killer-icon { font-size: 0.8rem; }
.killer-active { color: #ef4444; text-shadow: 0 0 5px rgba(239, 68, 68, 0.4); }
.killer-inactive { opacity: 0.1; filter: grayscale(1); }