:root {
    --bg-dark: #121212;
    --bg-light-dark: #1e1e1e;
    --card-bg: #2a2a2a;
    --text-primary: #e0e0e0;
    --text-secondary: #a0a0a0;
    --accent-blue: #007bff;
    --accent-green: #00FFA3; /* Vibrant green */
    --border-color: #444;
    --input-bg: #333;
    --shadow-color: rgba(0, 0, 0, 0.4);
    --font-poppins: 'Fredoka', sans-serif;
    --font-montserrat: 'Fredoka', sans-serif;
}

/* --- Base & Reset --- */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    height: 100%;
}

body {
    font-family: var(--font-montserrat);
    color: var(--text-primary);
    background-color: var(--bg-dark);
    min-height: 100vh;
    overflow-y: scroll;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.background-design {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    background-color: var(--bg-dark);
    background-image:
        repeating-linear-gradient(0deg, transparent, transparent 49px, rgba(255, 255, 255, 0.04) 50px),
        repeating-linear-gradient(90deg, transparent, transparent 49px, rgba(255, 255, 255, 0.04) 50px),
        radial-gradient(ellipse at 50% 0%, rgb(0, 0, 0) 0%, transparent 70%),
        linear-gradient(135deg, var(--bg-dark) 0%, var(--bg-light-dark) 100%);
    background-size: 50px 50px, 50px 50px, 100% 100%, 100% 100%;
    animation: scroll-background 20s linear infinite;
}

main {
    display: flex;
    flex-direction: column;
    gap: 2.5rem;
    align-items: center;
    padding: 2rem;
    max-width: 1500px;
    width: 100%;
    margin: 2rem auto;
    animation: fadeIn 0.8s ease-out 0.4s forwards;
    opacity: 0;
}

.hidden {
    display: none !important;
}

.app-header {
    text-align: center;
    animation: slideInTop 0.8s ease-out 0.2s forwards;
    opacity: 0;
}

.calculator-container {
    display: flex;
    gap: 2rem;
    width: 100%;
    align-items: flex-start;
}

/* --- Cards --- */
.calculator-card, .output-card {
    background-color: var(--card-bg);
    border-radius: 15px;
    padding: 2.5rem;
    box-shadow: 0 10px 30px var(--shadow-color);
    border: 1px solid var(--border-color);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    display: flex;
    flex-direction: column;
}

.calculator-card {
    flex: 2;
    
}
.output-card { flex: 3; }
.calculator-card:hover, .output-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 15px 40px var(--shadow-color);
}

/* --- Input Components --- */
.input-section {
    display: flex;
    flex-direction: column;
    gap: 0.8rem; 
}

.input-section > label {
    font-size: 1.1rem;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

/* Unit Selection Header with Search */
.unit-selection-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    margin-bottom: 0.5rem;
}

.unit-selection-header label {
    font-size: 1.1rem;
    font-weight: 500;
    color: var(--text-primary);
    margin: 0;
    white-space: nowrap;
}

/* Search Bar Styling */
.search-bar-container {
    position: relative;
    width: 250px;
    max-width: 40%;
    flex-shrink: 0;
    flex-wrap: wrap;
}

#unitSearchInput {
    width: 100%;
    padding: 0.6rem 1rem 0.6rem 2.5rem;
    background-color: var(--input-bg);
    border: 1px solid var(--border-color);
    border-radius: 25px;
    color: var(--text-primary);
    font-family: var(--font-montserrat);
    font-size: 0.9rem;
    transition: all 0.3s ease;
    outline: none;
}

#unitSearchInput::placeholder {
    color: var(--text-secondary);
    font-style: italic;
}

#unitSearchInput:focus {
    border-color: var(--accent-blue);
    box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.1);
    transform: translateY(-1px);
}

.search-bar-container::before {
    content: '';
    position: absolute;
    left: 0.8rem;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    pointer-events: none;
    opacity: 0.6;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23a0a0a0' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cpath d='m21 21-4.35-4.35'/%3E%3C/svg%3E");
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    z-index: 1;
}

.search-bar-container:focus-within::before {
    opacity: 0.8;
}

.current-unit-display {
    font-size: 0.95rem;
    color: var(--text-secondary);
    margin-top: 0.5rem;
}
.current-unit-display span {
    font-weight: 600;
    color: var(--accent-blue);
    text-transform: capitalize;
}
.current-unit-display.placeholder { font-style: italic; }

.reset-btn {
    background-color: var(--accent-blue);
    color: white;
    border: none;
    padding: 0.7rem 1.2rem;
    border-radius: 6px;
    font-size: 0.9rem;
    font-family: var(--font-montserrat);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    opacity: 0;
    width: 100%;
    margin-top: 1rem;
}

.reset-btn:hover {
    background-color: #0056b3;
    transform: translateY(-2px);
}

.reset-btn.visible {
    visibility: visible;
    opacity: 1;
}

.control-group {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px dashed var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
    align-items: flex-start;
}

.control-group > label {
    font-size: 1.1rem;
    font-weight: 500;
}

/* Unit Grid */
.unit-grid-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 1rem;
    padding: 1rem;
    max-height: 400px;
    overflow-y: auto;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background-color: var(--input-bg);
}

.unit-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem;
    border: 2px solid transparent;
    border-radius: 10px;
    background-color: var(--card-bg);
    cursor: pointer;
    transition: all 0.2s ease-in-out;
    text-align: center;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
}
.unit-card:hover {
    border-color: var(--accent-blue);
    transform: translateY(-3px);
}
.unit-card.selected {
    border-color: var(--accent-green);
    box-shadow: 0 0 0 4px #00ffa366;
}
.unit-card img {
    width: 90px;
    height: 90px;
    object-fit: cover;
    border-radius: 8px;
    pointer-events: none;
}
.unit-card p {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-primary);
    text-transform: capitalize;
    pointer-events: none;
}


.unit-grid-container::-webkit-scrollbar,
.calculator-card::-webkit-scrollbar {
    width: 8px;
}

.calculator-card::-webkit-scrollbar {
    width: 5px;
}

.unit-grid-container::-webkit-scrollbar-track,
.calculator-card::-webkit-scrollbar-track {
    background: var(--bg-dark);
}

.unit-grid-container::-webkit-scrollbar-thumb {
    background: var(--accent-blue);
    border-radius: 10px;
}

.calculator-card::-webkit-scrollbar-thumb {
    background: #575757;
    border-radius: 10px;
}

/* Level Slider */
.level-info { display: flex; align-items: center; gap: 0.5rem; }
.level-info label { font-size: 1.1rem; font-weight: 500; }
.level-info #unitLevelValue {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--accent-green);
}
#unitLevelSlider {
    width: 100%;
    -webkit-appearance: none;
    appearance: none;
    background: transparent;
    cursor: pointer;
}
#unitLevelSlider::-webkit-slider-runnable-track {
    background: var(--input-bg);
    border-radius: 5px;
    height: 8px;
}
#unitLevelSlider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    background-color: var(--accent-blue);
    border: 1px solid var(--text-primary);
    border-radius: 50%;
    width: 20px;
    height: 20px;
    margin-top: -6px;
}

/* Dropdown Selects */
.select-wrapper { position: relative; width: 100%; }
#traitSelection, #skillTreeSelection, #onFieldBuffsSelection {
    width: 100%;
    padding: 0.75rem 1rem;
    background-color: var(--input-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-family: var(--font-montserrat);
    font-size: 1rem;
    appearance: none;
    -webkit-appearance: none;
    cursor: pointer;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%23a0a0a0'%3E%3Cpath d='M7 10l5 5 5-5z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    background-size: 1.25rem;
}
#traitSelection:focus, #skillTreeSelection:focus, #onFieldBuffsSelection:focus {
    outline: none;
    border-color: var(--accent-blue);
}

/* Trait Roll UI */
.trait-roll-container {
    display: flex;
    align-items: center;
    gap: 1rem;
    width: 100%;
}
.trait-roll-container .select-wrapper {
    flex-grow: 1;
}
.roll-btn {
    background-color: #9b59b6;
    color: white;
    border: 1px solid #8e44ad;
    padding: 0.65rem 1.25rem;
    border-radius: 6px;
    font-family: var(--font-montserrat);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}
.roll-btn:hover {
    background-color: #8e44ad;
    transform: translateY(-2px);
    box-shadow: 0 4px 10px rgba(142, 68, 173, 0.4);
}
.roll-counter-wrapper {
    font-size: 0.9rem;
    color: var(--text-secondary);
    white-space: nowrap;
}
#rollCounter {
    font-weight: 700;
    color: var(--text-primary);
    background-color: var(--input-bg);
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    margin-left: 0.25rem;
}


/* Stat Roll Inputs */
.stat-roll-inputs {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
    width: 100%;
}
.stat-roll-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.stat-roll-group > label {
    font-size: 0.9rem;
    color: var(--text-secondary);
    font-weight: 500;
}
.stat-roll-group .input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}
.stat-roll-group input[type="number"] {
    width: 100%;
    padding: 0.75rem 2.2rem 0.75rem 1rem;
    background-color: var(--input-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 1rem;
    -moz-appearance: textfield;
}
.stat-roll-group input[type="number"]::-webkit-outer-spin-button,
.stat-roll-group input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}
.stat-roll-group input[type="number"]:focus {
    outline: none;
    border-color: var(--accent-blue);
}
.stat-roll-group .input-wrapper span {
    position: absolute;
    right: 1rem;
    color: var(--text-secondary);
    pointer-events: none;
}

/* --- START: New Tab styling for spawned units --- */
#outputTabsContainer {
    display: flex;
    gap: 0.5rem;
    padding: 0 0.2rem; /* Aligns with output-content-wrapper padding */
    position: relative;
    z-index: 0; /* Sits above the main content's z-index */
    margin-bottom: -2px; /* Pulls the content section up to overlap borders */
}

.tab-btn {
    padding: 0.75rem 1.25rem;
    border: 2px solid var(--border-color);
    background-color: var(--input-bg);
    color: var(--text-secondary);
    font-family: var(--font-montserrat);
    font-weight: 600;
    font-size: 0.9rem;
    border-radius: 10px 10px 0 0;
    cursor: pointer;
    transition: all 0.2s ease;
    border-bottom: none; /* No bottom border for inactive tabs */
}

.tab-btn:hover {
    background-color: #3f3f3f;
    color: var(--text-primary);
}

.tab-btn.active {
    background-color: var(--bg-dark); /* Match content background */
    color: var(--accent-green);
    border-bottom-color: var(--bg-dark); /* Makes it look like it merges with the content area */
    transform: translateY(2px);
}
/* --- END: New Tab styling for spawned units --- */

/* --- Output Section --- */
.dps-output-section {
    border: 2px solid #333;
    position: relative; /* Crucial for absolute positioning of children */
    overflow: hidden;   /* Clips the scrolling text */
    background: none;   /* Remove the old static background */
    padding: 0;         /* Padding will be moved to the content wrapper */
    display: flex; /* Kept for structure, but children will manage layout */
    flex-direction: column;
    border-radius: 10px;
}
.dps-output-section.placeholder {
    justify-content: center;
    text-align: center;
    padding: 1.5rem; /* Add padding back for placeholder */
    background: #1a1a1a;
}
.dps-output-section .placeholder-text {
    color: var(--text-secondary);
    font-style: italic;
    font-size: 1.1rem;
}

/* --- START: New Hiragana Background Styles --- */
.hiragana-background {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    z-index: 1; /* Sits at the bottom */
    background: linear-gradient(to right, #1d1d1d, #000000);
}

.hiragana-background::before {
    content: '';
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    z-index: 2; /* Sits on top of the bg gradient */
    --stripe-opacity: 0.6;
    background: repeating-linear-gradient(
        135deg,
        transparent, transparent 7px,
        rgba(0, 0, 0, var(--stripe-opacity)) 7px,
        rgba(0, 0, 0, var(--stripe-opacity)) 12px
    );
}

.hiragana-background .text-container {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    z-index: 3; /* Sits on top of the stripes */
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.hiragana-background .text-layer {
    width: 200%;
    display: flex;
    font-family: 'Noto Sans JP', sans-serif;
    font-weight: 900;
    white-space: nowrap;
    user-select: none;
    line-height: 0.9;
    rotate: -10deg;
    font-size: 20rem; /* Adjusted for better fit */
    background: linear-gradient(45deg, #ffffff, #303030);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    opacity: 0.08; /* Made less obtrusive */
}

.hiragana-background .text-layer span {
    display: block;
    width: 50%;
    padding: 0 20px;
}

.hiragana-background .layer-1 { animation: scroll-right 40s linear infinite; }
.hiragana-background .layer-2 { animation: scroll-left 40s linear infinite; }
.hiragana-background .layer-3 { animation: scroll-right 40s linear infinite; }
.hiragana-background .layer-4 { animation: scroll-left 40s linear infinite; }

.output-content-wrapper {
    position: relative;
    z-index: 5; 
    width: 100%;
    height: 100%;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    overflow-y: auto; /* Allows content to scroll if it overflows */
}

.output-content-wrapper::-webkit-scrollbar { width: 5px; }
.output-content-wrapper::-webkit-scrollbar-track { background: transparent; }
.output-content-wrapper::-webkit-scrollbar-thumb { background: #575757; border-radius: 10px; }
/* --- END: New Hiragana Background Styles --- */


/* Header Section */
.unit-card-header {
    text-align: center;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 1rem;
    margin-bottom: 0.5rem;
}
.unit-title {
    font-family: var(--font-poppins);
    font-size: clamp(1.8rem, 4vw, 2.5rem);
    font-weight: 700;
    color: #ffffff;
    text-transform: uppercase;
    margin: 0;
    text-shadow: 0 0 1px rgba(255, 255, 255, 0.6);
}
.unit-sub-info {
    font-size: 0.9rem;
    color: var(--text-secondary);
    font-weight: 500;
    text-transform: uppercase;
}
.unit-sub-info .type-hill { color: #82ff7b; }
.unit-sub-info .type-ground { color: #ffb45de3; }
.unit-sub-info .type-hybrid { color: #b0c4de; }

/* Details Row (Level & Trait) */
.unit-details-row {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap; /* Allows items to wrap on small screens */
}
.level-display {
    background-color: #FFD900;
    color: #121212;
    padding: 0.3rem 0.8rem;
    border-radius: 5px;
    font-weight: 700;
    font-size: 1rem;
    box-shadow: inset 0 -2px 4px rgba(0,0,0,0.2);
}
.trait-display {
    background-color: var(--input-bg);
    border: 1px solid var(--border-color); /* Default border color */
    padding: 0.3rem 0.8rem;
    border-radius: 5px;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 500;
    font-size: 0.9rem;
    position: relative; /* Needed for the pseudo-element trick */
    z-index: 1; /* Sits on top */
    overflow: hidden; /* Clips the animated border */
}

/* 2. Style for the trait icon image */
.trait-icon {
    height: 1.2em; /* Sizes the icon relative to the text font size */
    width: 1.2em;
    object-fit: contain; /* Prevents the image from stretching */
}

/* 3. Specific modifier classes to change the border and text color for each trait */
/* Traitless - Neutral Grey */
.trait-display--traitless { border-color: #7f8c8d; color: #bdc3c7; }

.trait-display--bloodlust { border-color: #ff3838; color: #ff8080; }
.trait-display--companion { border-color: #adff2f; color: #e2ffae; }
.trait-display--corrupted { border-color: #9b59b6; color: #d7bde2; }
.trait-display--dexterity { border-color: #00e0c6; color: #8ff7e9; }
.trait-display--tempest { border-color: #00f2a4; color: #a1ffe8; }
.trait-display--midas { border-color: #ffd700; color: #fff0a3; }
.trait-display--sharpshooter { border-color: #e74c3c; color: #a4c8ff; }
.trait-display--prodigy { border-color: #29b6f6; color: #b3e5fc; }
.trait-display--perception { border-color: #00bcd4; color: #a6eaf4; }
.trait-display--tank { border-color: #bdc3c7; color: #ecf0f1; }
.trait-display--zenkai { border-color: #ff6f00; color: #ffcc80; }
.trait-display--genesis { border-color: #4caf50; color: #a5d6a7; }

.trait-display--allstar {
    border-color: transparent; /* Hide the static border */
    color: white; /* As requested */
}

/* Create an animated pseudo-element that sits behind the badge */
.trait-display--allstar::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    z-index: -1; /* Place it behind the content */
    border-radius: 5px; /* Match the parent's border-radius */
    padding: 1px; /* This creates the border thickness */
    
    /* The rainbow gradient background */
    background: linear-gradient(
        60deg,
        #f79533, #f37055, #ef4e7b, #a166ab, 
        #5073b8, #1098ad, #07b39b, #6fba82
    );
    background-size: 300% 300%;
    animation: rainbow-flow 3s linear infinite; /* Apply the animation */

    /* The magic: clip the background to only show the border */
    -webkit-mask: 
        linear-gradient(#fff 0 0) content-box, 
        linear-gradient(#fff 0 0);
    -webkit-mask-composite: destination-out;
    mask-composite: exclude;
}

/* Re-use the rainbow-flow keyframes from rarity headers or define it here if needed */
/* It's already in your CSS, but here it is for completeness: */
@keyframes rainbow-flow {
    0%   { background-position: 0% 50%; }
    50%  { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

.element-display {
    background-color: var(--input-bg);
    border: 1px solid var(--border-color);
    padding: 0.3rem 0.8rem;
    border-radius: 5px;
    font-weight: 500;
    font-size: 0.9rem;
    text-transform: capitalize;
    /* Added properties to support the icon */
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.element-icon {
    height: 1.2em;
    width: 1.2em;
    object-fit: contain;
}

.skill-tree-display {
    background-color: var(--input-bg);
    border: 1px solid #c9a449; /* A nice bronze/gold border */
    color: #f7d885; /* A light gold text color */
    padding: 0.3rem 0.8rem;
    border-radius: 5px;
    font-weight: 500;
    font-size: 0.9rem;
}

/* START: New buff display style */
.buff-display {
    background-color: var(--input-bg);
    border: 1px solid #4d9dff;
    color: #99c7ff;
    padding: 0.3rem 0.8rem;
    border-radius: 5px;
    font-weight: 500;
    font-size: 0.9rem;
}
/* END: New buff display style */


/* Stat Bars Section */
.stats-display {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}
.stat-bar-row {
    display: flex;
    align-items: center;
    background-color: var(--input-bg);
    border-radius: 8px;
    padding: 0.75rem 1rem;
    position: relative;
    overflow: hidden;
    border: 3px solid var(--border-color);
}
.stat-bar-row::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    height: 100%;
    width: 100%;
    z-index: 0;
    opacity: 0.2;
}
.stat-bar-row.dmg-bar { border-color: #bb1818; }
.stat-bar-row.rng-bar { border-color: #bda208; }
.stat-bar-row.spa-bar { border-color: #236896; }

.stat-grade, .stat-roll-value, .stat-label, .stat-value {
    position: relative;
    z-index: 1;
}
.stat-grade {
    font-weight: 700;
    font-size: 1rem;
    width: 45px;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.7);
    text-align: center;
    margin-left: 0.5rem;
    margin-right: 0.5rem;
}
.stat-roll-value {
    font-size: 0.8rem;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.8);
    background-color: rgba(0, 0, 0, 0.4);
    padding: 2px 6px;
    border-radius: 4px;
    margin-right: 1.5rem;
    
}
.grade-SSS { color: #d600ff; }
.grade-SS { color: #a0c69b; }
.grade-S { color: #b7ad80; }
.grade-A { color: #d19667; }
.grade-B { color: #d5693a; }
.grade-C { color: #dd0c0f }

.grade-SSS,
.grade-SS,
.grade-S,
.grade-A,
.grade-B,
.grade-C {
  text-shadow: 0 0 1px currentColor, 0 0 2px currentColor;
  font-size: 150%;
}

.stat-label {
    flex-grow: 1;
    font-weight: 600;
    color: var(--text-secondary);
}
.stat-value {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-primary);
    font-size: 120%;
}

/* DPS Summary Section */
.dps-summary {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    text-align: center;
    background-color: var(--bg-light-dark);
    padding: 1rem;
    border-radius: 8px;
    border-top: 1px solid var(--border-color);
}
.dps-summary.has-dot {
    grid-template-columns: repeat(3, 1fr);
}
.dps-summary .dps-item h3 {
    font-family: var(--font-poppins);
    color: var(--text-secondary);
    font-size: 1rem;
    margin-bottom: 0.25rem;
    font-weight: 500;
    text-transform: uppercase;
}
.dps-summary .dps-item p {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--accent-green);
}

/* Additional Stats Section */
.additional-stats {
    padding-top: 1.25rem;
    border-top: 1px solid var(--border-color);
}
.additional-stats h4 {
    margin-bottom: 1rem;
    text-align: center;
    font-family: var(--font-poppins);
    font-weight: 500;
    color: var(--text-secondary);
    font-size: 1.3rem;
}
.additional-stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(10px, 1fr));
    gap: 0.75rem;
}
.stat-block {
    background-color: var(--input-bg);
    border-radius: 8px;
    padding: 0.75rem;
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    border: 1px solid var(--border-color);
}
.stat-block-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-weight: 500;
}
.stat-block-value {
    font-size: 1.1rem;
    color: var(--text-primary);
    font-weight: 600;
}

/* Upgrade Navigation at the bottom */
.upgrade-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.upgrade-nav.bottom-nav {
    border-top: 1px solid var(--border-color);
    padding-top: 1rem;
    margin-top: auto;
    margin-bottom: 0;
}
.upgrade-nav .nav-btn {
    background-color: var(--accent-blue);
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    font-family: var(--font-montserrat);
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s ease, transform 0.2s ease;
    margin-right: 2%;
}
.upgrade-nav .nav-btn:hover:not(:disabled) {
    background-color: #0056b3;
    transform: translateY(-2px);
}
.upgrade-nav .nav-btn:disabled {
    background-color: #555;
    opacity: 0.6;
    cursor: not-allowed;
}

.upgrade-nav .max-btn {
    background-color: #00FFA3; /* A distinct color for the Max button */
    color: black;
    margin-left: auto;
    margin-right: 0;
}

#special-controls {
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border-color);
    width: 100%;
}

/* --- Animations --- */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideInTop { from { transform: translateY(-20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
@keyframes scroll-background {
    from {
        background-position: 0 0, 0 0, 0 0, 0 0;
    }
    to {
        background-position: -50px -50px, -50px -50px, 0 0, 0 0;
    }
}
@keyframes scroll-right {
    from { transform: translateX(-50%); }
    to   { transform: translateX(0); }
}
@keyframes scroll-left {
    from { transform: translateX(0); }
    to   { transform: translateX(-50%); }
}


/* ADD THIS near other display styles, like .trait-display */
.element-red { border-color: #ff4d4d; color: #ff9999; }
.element-green { border-color: #4dff9d; color: #99ffc7; }
.element-blue { border-color: #4d9dff; color: #99c7ff; }
.element-purple { border-color: #c863f9; color: #e4c2ff; }
.element-orange { border-color: #ff9d4d; color: #ffc799; }

.rarity-header {
    grid-column: 1 / -1; /* Makes the header span all columns */
    color: var(--accent-green);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    padding-bottom: 0.5rem;
    margin-bottom: 0.5rem;
    margin-top: 1.5rem; /* Space between rarity sections */
    border-bottom: 1px solid var(--border-color);
    font-size: 1.1rem;
}

.unit-grid-container > .rarity-header:first-child {
    margin-top: 0; /* Removes extra space above the very first header */
}

.rarity-header--newly-added {
    color: #00FFA3; /* Uses your --accent-green variable */
    text-shadow: 0 0 6px rgba(0, 255, 163, 0.4);
}

.rarity-header--unbound {
    /* 1. Create the gradient as a background */
    background-image: linear-gradient(45deg, #d41d1d, #27074e);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}


/* This style WILL make the "5 Star" TEXT an animated rainbow gradient */
.rarity-header--5-star {
    background-image: linear-gradient(
        45deg, 
        #ff2400, #e8b71d, #e3e81d, 
        #1de840, #1ddde8, #2b1de8, #dd00f3
    );
    background-size: 400% 100%;
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    animation: rainbow-flow 8s ease-in-out infinite;
}

.special-ability-control {
    background-color: var(--input-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 1.25rem 1.5rem;
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.special-ability-control h4 {
    font-family: var(--font-poppins);
    color: var(--accent-green);
    text-transform: uppercase;
    margin-bottom: 0.25rem;
    font-size: 1.1rem;
    letter-spacing: 0.5px;
}

.special-ability-control .ability-desc {
    color: var(--text-secondary);
    font-size: 0.95rem;
    margin-bottom: 0.5rem;
    line-height: 1.5;
}

.special-ability-control .ability-desc strong {
    color: var(--text-primary);
    font-weight: 600;
}

.special-ability-control .ability-btn {
    background-color: var(--accent-blue);
    color: white;
    border: none;
    padding: 0.7rem 1.2rem;
    border-radius: 6px;
    font-family: var(--font-montserrat);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    width: 60%;
    margin: 0.5rem auto 0;
    display: block;
}

.special-ability-control .ability-btn:hover:not(:disabled) {
    background-color: #0056b3;
    transform: translateY(-2px);
}

.special-ability-control .ability-btn.active {
    background-color: var(--accent-green);
    color: black;
    font-weight: 700;
}

.special-ability-control .ability-btn.active:hover {
    background-color: #00d68b;
}

.special-ability-control .slider-control-group {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    align-items: center;
    margin-top: 0.5rem;
}

.special-ability-control .slider-control-group label {
    font-size: 1rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.special-ability-control .slider-control-group span {
    color: var(--text-primary);
    font-weight: 700;
}

/* --- START: UPDATED SLIDER STYLES --- */
.special-ability-control .slider-control-group input[type="range"] {
    width: 80%;
    -webkit-appearance: none;
    appearance: none;
    background: transparent;
    cursor: pointer;
}

/* Styles for Webkit (Chrome, Safari) */
.special-ability-control .slider-control-group input[type="range"]::-webkit-slider-runnable-track {
    background: var(--bg-dark); /* Darker than the container for contrast */
    border: 1px solid var(--border-color); /* Add a border to define it */
    border-radius: 5px;
    height: 8px;
}

.special-ability-control .slider-control-group input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    background-color: var(--accent-blue);
    border: 2px solid var(--text-primary);
    border-radius: 50%;
    width: 20px;
    height: 20px;
    margin-top: -7px; /* Recalculate based on track height and border */
}

/* Styles for Firefox */
.special-ability-control .slider-control-group input[type="range"]::-moz-range-track {
    background: var(--bg-dark);
    border: 1px solid var(--border-color);
    border-radius: 5px;
    height: 8px;
}

.special-ability-control .slider-control-group input[type="range"]::-moz-range-thumb {
    background-color: var(--accent-blue);
    border: 2px solid var(--text-primary);
    border-radius: 50%;
    width: 20px;
    height: 20px;
}
/* --- END: UPDATED SLIDER STYLES --- */


/* Keyframes for the rainbow animation */
@keyframes rainbow-flow {
    0%   { background-position: 0% 50%; }
    50%  { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

.ability-display {
    background-color: var(--input-bg);
    border: 1px solid var(--accent-green);
    color: var(--accent-green);
    padding: 0.3rem 0.8rem;
    border-radius: 5px;
    font-weight: 500;
    font-size: 0.9rem;
}

.popup {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    animation: fadeIn 0.5s ease-out;
}

.popup-content {
    background-color: var(--card-bg);
    padding: 2rem;
    border-radius: 10px;
    border: 1px solid var(--border-color);
    box-shadow: 0 10px 30px var(--shadow-color);
    text-align: center;
    max-width: 450px;
    width: 90%;
    animation: scaleIn 0.5s ease-out;
}

.popup-content h2 {
    color: var(--accent-green);
    margin-bottom: 1rem;
    font-size: 1.8rem;
}

.popup-content p {
    color: var(--text-secondary);
    font-size: 1.1rem;
    line-height: 1.6;
    margin-bottom: 1.5rem;
}

.popup-content button {
    background-color: var(--accent-blue);
    color: white;
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: 6px;
    font-family: var(--font-montserrat);
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.popup-content button:hover {
    background-color: #0056b3;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes scaleIn {
    from { transform: scale(0.8); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

.tester-btn {
    position: fixed;
    top: 10px;
    right: 10px;
    background-color: #bb1818;
    color: white;
    border: none;
    padding: 0.6rem 1rem;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    z-index: 1000;
    transition: all 0.2s ease;
}

.tester-btn:hover {
    background-color: #e02424;
    transform: translateY(-2px);
}

#visualizer-container {
    width: 100%;
    height: 400px; /* Adjust height as needed */
    border-radius: 10px;
    overflow: hidden; /* This will clip the iframe to the container's rounded corners */
    border: 1px solid var(--border-color);
    margin-bottom: 1.5rem; /* Space between visualizer and stats */
    background-color: #000; /* Black background while it loads */
}

#aoeVisualizerFrame {
    width: 100%;
    height: 100%;
    border: none;
}

/* --- Responsive Adjustments for Visualizer --- */
@media (max-width: 768px) {
    #visualizer-container {
        height: 350px;
    }
}

@media (max-width: 480px) {
    #visualizer-container {
        height: 300px;
    }
}

/* --- Media Queries --- */

/* For Tablets and Smaller (stacked layout) */
@media (max-width: 1024px) {
    .calculator-container {
        flex-direction: column; /* This is the key: stacks the flex items vertically */
        align-items: stretch;   /* Ensures both cards stretch to full width */
    }

    .calculator-card {
        max-height: none;       /* CRITICAL: Disables the fixed height from the desktop view */
        overflow-y: visible;    /* Allows the card to grow with its content */
    }
}

/* For Smaller Tablets and Large Phones */
@media (max-width: 768px) {
    main { 
        padding: 1.5rem; /* Reduce side padding on smaller screens */
        gap: 2rem; 
        margin: 1.5rem auto; 
    }

    .calculator-card, .output-card { 
        padding: 1.8rem; /* Reduce internal padding of the cards */
    }

    .dps-summary .dps-item p { font-size: 1.6rem; }

    .additional-stats-grid { 
        grid-template-columns: 1fr 1fr; /* Two columns for stats grid */
    }
}

/* For Standard Mobile Phones */
@media (max-width: 480px) {
    main { 
        padding: 1rem; /* Even less padding for phones */
        margin: 1rem auto; 
    }

    .calculator-card, .output-card { 
        padding: 1.5rem; 
    }

    .unit-grid-container { 
        grid-template-columns: repeat(auto-fill, minmax(80px, 1fr)); /* Adjust unit grid for small screens */
    }
    
    .stat-roll-inputs { 
        grid-template-columns: 1fr; /* Stack stat roll inputs */
        gap: 0.75rem; 
    }

    .dps-summary, .dps-summary.has-dot {
        grid-template-columns: 1fr; /* Stack DPS summary items */
    }

    .dps-summary .dps-item p { font-size: 2rem; }

    .additional-stats-grid { 
        grid-template-columns: 1fr; /* Stack additional stats */
    }
    
    .upgrade-nav .nav-btn { 
        padding: 0.6rem 1rem; 
        font-size: 1rem; 
    }
}