:root {
    --orange-border-color: #FFA500;
    --off-black-bg: #1a1a1a;
    --off-white-bg: #f8f8f8; 
    --text-color: #eee;
    --dark-text-color: #333;
    --border-radius-size: 15px;
    --content-spacing: 20px;
    --gap-spacing: 10px;
    --main-border-width: 4px;
    --header-height: 100px;
    --keywords-height: 30px; 
    --menu-width: 280px; 
    --datacard-max-width: 800px;
}

/* --- Base Page --- */
body {
    background-color: #333;
    margin: 0;
    min-height: 100vh;
    overflow-x: hidden;
    font-family: system-ui, sans-serif;
}

/* ---------------------------------------------------------------------- */
/* --- GLOBAL APP LAYOUT (Flexbox for separation and centering) --- */
/* ---------------------------------------------------------------------- */
.app-layout {
    display: flex;
    min-height: 100vh;
    width: 100%;
    align-items: flex-start;
    transition: all 0.3s ease;
}

/* --- Menu Panel Styling: Fixed Left --- */
.menu-panel {
    flex-shrink: 0;
    width: var(--menu-width);
    padding: var(--content-spacing);
    background-color: #2c2c2c;
    color: var(--text-color);
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.5);
    height: 100vh;
    position: sticky;
    top: 0;
    overflow-y: auto;
    transition: transform 0.3s ease, opacity 0.3s ease;
    border-radius: 0;
}

/* NEW: Unit Identity Group in Menu */
.unit-identity-group {
    display: flex;
    gap: 10px;
    align-items: flex-end; 
    border-bottom: 1px dashed #555;
    padding-bottom: 10px;
    margin-bottom: 10px;
}
.unit-identity-group h3 {
    width: 100%;
    margin-bottom: 0;
}
.identity-fields {
    flex-grow: 1;
}
.swap-button {
    background-color: #555;
    color: var(--text-color);
    border: none;
    padding: 10px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1.2em;
    height: 80px; 
    transition: background-color 0.2s ease;
}
.swap-button:hover {
    background-color: #777;
}

/* Collapsed sidebar (mobile or toggled) */
.menu-panel.hidden {
    transform: translateX(-100%);
    opacity: 0;
    pointer-events: none;
}

.menu-panel h2 {
    color: var(--orange-border-color);
    border-bottom: 2px solid rgba(255, 165, 0, 0.3);
    padding-bottom: 10px;
}

.menu-panel label {
    display: block;
    margin-top: 10px;
    font-size: 0.9em;
    font-weight: bold;
    color: #ccc;
}
/* Style for select input */
.menu-panel select,
.menu-panel input[type="text"],
.menu-panel input[type="number"],
.menu-panel textarea {
    width: 100%;
    padding: 5px;
    margin-top: 5px;
    border: 1px solid #555;
    background-color: #444;
    color: white;
    box-sizing: border-box;
    border-radius: 4px;
}

/* NEW: Checkbox Group Styling */
.checkbox-group {
    display: flex;
    align-items: center;
    margin-top: 15px;
    margin-bottom: 10px;
    padding-bottom: 10px;
    border-bottom: 1px dashed #555;
}
.checkbox-group input[type="checkbox"] {
    width: auto;
    margin-right: 8px;
    transform: scale(1.2);
}
.checkbox-group label {
    margin-top: 0;
    font-weight: normal;
    font-size: 1em;
}

/* NEW: Database Styling and Toggle */
#keywordDatabase {
    height: 100px;
    transition: all 0.3s ease;
    resize: vertical;
}
.hidden-db {
    height: 0 !important;
    padding: 0 !important;
    margin: 0 !important;
    border: none !important;
    opacity: 0;
    pointer-events: none;
    overflow: hidden;
}

.stats-input-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0;
    margin-bottom: 15px;
    border: 1px dashed #555;
    padding: 10px;
    border-radius: 5px;
}

/* New: Weapon Editor Styling */
.weapon-group, .ability-group {
    padding: 10px 0;
    border: 1px dashed #555;
    padding: 10px;
    margin-bottom: 10px;
    border-radius: 5px;
}
.weapon-group input, .weapon-group select, .ability-group input, .ability-group select, .ability-group textarea {
    margin-bottom: 5px;
}
.weapon-stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 5px 10px;
    margin-bottom: 10px;
    padding-top: 5px;
}
.ability-cost-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 5px 10px;
    margin-bottom: 10px;
}
.remove-weapon-btn, .add-button, #toggleDbBtn {
    background-color: var(--orange-border-color);
    color: var(--off-black-bg);
    border: none;
    padding: 5px 10px;
    border-radius: 4px;
    cursor: pointer;
    font-weight: bold;
    width: 100%;
    margin-top: 5px;
}
.remove-weapon-btn {
    background-color: #c0392b; 
    color: white;
    width: auto;
}
/* End of New Weapon Editor Styling */


/* --- DataCard Container --- */
.datacard-container {
    flex-grow: 1;
    padding: var(--content-spacing);
    display: flex;
    justify-content: center;
    align-items: flex-start;
    background: #333; 
    overflow-y: auto;
    transition: all 0.3s ease;
}

/* ---------------------------------------------------------------------- */
/* --- DataCard (Flexible Height Configuration) --- */
/* ---------------------------------------------------------------------- */
.main-rectangle {
    min-height: 400px; 
    width: 100%;
    max-width: var(--datacard-max-width);
    border: var(--main-border-width) solid var(--orange-border-color);
    border-radius: var(--border-radius-size);
    box-sizing: border-box;
    
    display: grid;
    grid-template-rows: var(--header-height) 1fr var(--keywords-height); 
    grid-template-columns: 1fr;
    position: relative;
    overflow: hidden; 
}

.header {
    background-color: var(--off-black-bg);
    position: relative;
    overflow: visible;
}

/* NEW: Output Wrapper for Unit Name/Title */
.unit-identity-output {
    position: absolute;
    top: 10px;
    left: var(--content-spacing);
    z-index: 100;
}

/* NEW: Base Unit Name Styling (the top line) */
.unit-name {
    font-size: 1.8em;
    font-weight: bold;
    color: var(--text-color);
    display: inline-block;
    padding-bottom: 2px;
    margin-bottom: 5px;
    line-height: 1.1;
}

/* NEW: Unit Title Styling (the optional second line) */
.unit-title {
    font-size: 1.1em;
    font-weight: normal;
    color: var(--text-color);
    opacity: 0.8;
    line-height: 1.1;
    display: block; 
}

/* NEW: Conditional Underline Class (applied by JavaScript) */
.underline-line {
    border-bottom: 2px solid var(--orange-border-color);
}

.triangle-wrapper {
    position: absolute;
    left: 50%;
    top: -20px;
    transform: translateX(-50%);
    width: 230px; /* Outer boundary width */
    height: 155px;
    z-index: 10;
    background-color: var(--orange-border-color); /* Border color */
    clip-path: polygon(50% 100%, 0% 0%, 100% 0%);
    /* We keep the clipping on the wrapper to define the overall space */
}

.triangle-container {
    width: 200px; /* Inner triangle slightly smaller */
    height: 135px;
    background-color: black; /* Inner triangle color */
    
    /* FIX: Apply the clipping here to contain the image */
    clip-path: polygon(50% 100%, 0% 0%, 100% 0%); 
    overflow: hidden; /* Essential: Hides any part of the inner image that escapes the clip-path */

    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%); /* Centers the inner triangle inside the wrapper */
}

.portrait-image {
    /* FIX: Remove clip-path from the image itself */
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    /* REMOVED: clip-path: polygon(50% 100%, 0% 0%, 100% 0%); */
    
    /* Ensure image starts as a normal rectangle inside its container */
    
    /* Image transformation styles must remain on the image for the JS controls to work */
}

.right-panel {
    position: absolute;
    top: 10px; 
    right: 0;
    width: 40%;
    height: 80%; 
    
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 5px;
    align-items: stretch;
    
    padding: 0 var(--content-spacing) 0 0; 
    box-sizing: border-box;
}

.stat-box {
    background-color: rgba(255, 255, 255, 0.05);
    color: var(--text-color);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    
    padding: 5px 5px; 
    height: 100%; 
}

.stat-label {
    font-size: 0.8em;
    opacity: 0.7;
    text-transform: uppercase;
}

.stat-number {
    font-size: 2.5em;
    font-weight: 900;
    color: white;
    line-height: 1;
}

/* ---------------------------------------------------------------------- */
/* --- CONTENT AREA (Middle Section - Dynamic Height) --- */
/* ---------------------------------------------------------------------- */
.content-area {
    background-color: var(--off-white-bg);
    color: var(--dark-text-color);
    padding: var(--content-spacing);
    
    display: flex;
    flex-direction: column; 
    gap: var(--content-spacing);
}

.abilities-area-wrapper h3 {
    display: none; 
}

/* --- WEAPON TABLE STYLING --- */
.weapon-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9em;
}

.weapon-table thead {
    background-color: #ddd;
    border-bottom: 2px solid var(--orange-border-color);
}

.weapon-table th, .weapon-table td {
    padding: 5px;
    text-align: center;
}

.weapon-table td {
    border-bottom: 1px solid #ccc;
}

.weapon-table th {
    font-weight: bold;
    color: var(--dark-text-color);
}

/* Table Column Widths: WR is now part of the 35% keyword slot */
.weapon-name-col {
    text-align: left;
    width: 30%; /* Reduced from 35% to 30% */ 
    padding-left: 0;
}

.weapon-stat-col {
    width: 10%; /* HIT, ATK, DMG columns */
    font-weight: bold;
}

.type-wr-col {
    width: 35%; /* WR column remains large */
}

/* Styling for the Icons */
.weapon-icon {
    font-size: 0.9em;
    margin-right: 5px;
    color: var(--orange-border-color);
}

/* Keyword/Tooltip Styling (on the table) */
.keyword {
    color: var(--orange-border-color);
    font-weight: bold;
    cursor: help; 
    padding: 1px 3px; 
    border-radius: 3px;
    transition: background-color 0.1s ease;
}
.keyword:hover {
    background-color: rgba(255, 165, 0, 0.15); 
}

/* --- ABILITIES AREA STYLING --- */
.abilities-area-wrapper {
    border-bottom: 2px solid var(--orange-border-color);
    padding-bottom: var(--content-spacing);
    
    display: flex;
    flex-direction: column;
}
.abilities-area {
    display: flex;
    justify-content: space-between;
    gap: var(--content-spacing);
    padding-top: var(--gap-spacing);
}

.passive-abilities, .active-abilities {
    flex-basis: 50%;
    flex-grow: 1;
}

/* Passive Ability Format */
.passive-entry {
    margin: 5px 0;
    line-height: 1.4;
    font-size: 0.95em;
}
.passive-title {
    font-weight: bold;
}

/* Active Ability Format */
.active-ability-box {
    border: 2px solid var(--orange-border-color);
    margin-bottom: var(--gap-spacing);
    border-radius: 4px;
    overflow: hidden;
}

.active-header {
    display: flex;
    justify-content: space-between;
    padding: 5px 10px;
    background-color: var(--orange-border-color);
    color: white; 
    font-weight: bold;
    font-size: 0.95em;
    text-transform: uppercase;
}

.active-title, .active-cost { 
    color: white; 
}

.active-effect {
    padding: 8px 10px;
    background-color: white; 
    color: var(--dark-text-color);
    font-size: 0.9em;
    line-height: 1.4;
}

/* --- KEYWORD DEFINITIONS (GLOSSARY) AREA --- */
.keyword-definitions-area {
    padding-top: var(--content-spacing);
    border-top: 2px solid var(--orange-border-color);
    font-size: 0.9em; 
    display: none; 
}
.keyword-definitions-area h3 {
    font-size: 1em;
    border-bottom: 1px solid #ccc;
    padding-bottom: 5px;
    margin-top: 0;
}

/* Styling for the Glossary List (dl) */
.keyword-glossary {
    margin: 10px 0 0 0;
    padding: 0;
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 5px 10px;
}
.keyword-term {
    font-weight: bold;
    color: var(--dark-text-color);
    grid-column: 1 / 2;
    text-align: right;
    padding-right: 5px;
}
.keyword-definition {
    margin-left: 0;
    grid-column: 2 / 3;
}


/* Separator Line (Horizontal) - Apply bottom border to the Weapons area */
.weapons-area {
    padding-bottom: var(--content-spacing);
    border-bottom: 2px solid var(--orange-border-color);
}

.abilities-area {
    padding-top: 0; 
}

/* portrait buttons */
.portrait-upload-group {
    display: flex;
    align-items: center;
    gap: 5px;
    margin-top: 5px;
    margin-bottom: 15px;
}

#uploadPortraitBtn {
    flex-grow: 1;
}

#clearPortraitBtn {
    height: 38px;
    width: 38px;
    padding: 0;
    font-size: 1em;
}

.image-controls-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px; /* Space between functional groups */
    
    width: 100%;
    margin-bottom: 15px;
    padding: 5px 10px;
    border: 1px dashed #555;
    border-radius: 4px;
}

.image-controls-container button {
    background-color: #555;
    color: var(--text-color);
    border: none;
    padding: 8px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1.1em;
    flex-shrink: 0; /* Prevents buttons from collapsing */
    transition: background-color 0.2s ease;
}

.image-controls-container button:hover {
    background-color: #777;
}

.image-controls-container i {
    /* Ensures icons are visible in buttons */
    font-size: 1em;
}

/* Style for the text Fit button to differentiate it */
#fitToggleBtn {
    font-weight: bold;
    font-size: 0.9em;
    padding: 8px 10px;
    background-color: #333;
}

/* Separator styling */
.control-separator {
    color: #555;
    font-size: 1.5em;
    margin: 0 4px;
}

/* ---------------------------------------------------------------------- */
/* --- KEYWORDS (Bottom Section) (UPDATED) --- */
/* ---------------------------------------------------------------------- */
.keywords {
    background-color: var(--off-black-bg);
    color: var(--text-color);
    
    /* Use Flexbox to align keywords left and circle right */
    display: flex;
    justify-content: space-between;
    align-items: center;
    
    font-size: 0.8em;
    padding: 0 var(--content-spacing); 
    height: 100%;
}

/* Operative Keywords (Left-aligned list) */
.keywords-list {
    /* Ensures list takes available space and wraps keywords */
    display: flex;
    align-items: center;
    flex-wrap: wrap; 
    gap: 5px; 
    margin: 0; /* Remove default margin */
    flex-grow: 1;
    text-align: left; /* Align contents to the left */
}

/* Styling applied to all individual keywords/spans injected by JS */
.team-name-keyword, .footer-keyword {
    color: var(--text-color); /* All keywords WHITE */
    font-weight: bold; 
    text-transform: uppercase; /* All keywords CAPITALIZED */
    white-space: nowrap; 
}

/* Special styling for the FIRST keyword (Team Name) */
.team-name-keyword {
    color: var(--orange-border-color); /* Orange overwrite */
}

.team-skull-icon {
    font-size: 0.9em;
    margin-left: 5px;
    vertical-align: middle;
}

.keyword-separator {
    color: var(--text-color); 
    opacity: 0.5;
    padding: 0 3px;
}


/* NEW: Fixed Number Circle (Base Size) (Right-aligned) */
.keywords-number-circle { /* Renamed in HTML update */
    display: none; /* Hide old element */
}

.base-size-circle { /* NEW element name */
    display: flex;
    justify-content: center;
    align-items: center;
    
    width: 24px;
    height: 24px;
    border-radius: 50%; 
    border: 2px solid var(--orange-border-color);
    background-color: var(--off-black-bg);
    
    font-size: 0.7em;
    font-weight: bold;
    color: var(--text-color);
    flex-shrink: 0; /* Prevents shrinking */
    margin-left: var(--gap-spacing); /* Space between keywords and circle */
}

/* Modal Box Styling (FIXED POSITIONING) */
.help-modal-box {
    /* FIX: Changed to fixed to position relative to the browser viewport */
    position: fixed; 
    
    /* Center it precisely in the viewport */
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    
    /* Ensure it is large enough but doesn't block the entire screen */
    width: 90%; 
    max-width: 450px;
    max-height: 90%;
    overflow-y: auto;
    
    background-color: #333;
    border: 3px solid var(--orange-border-color);
    border-radius: var(--border-radius-size);
    padding: 20px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.9);
    color: var(--text-color);
    z-index: 9999; /* Ensure it is on top of everything */
    display: none; /* Hidden by default (toggled by JS) */
}

.help-toggle {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    
    /* Size remains prominent */
    width: 30px; 
    height: 30px; 
    border-radius: 50%;
    
    background-color: var(--orange-border-color);
    color: var(--off-black-bg); /* Text/Icon color is dark */
    
    font-size: 1.5em; /* Increased size for the icon itself */
    font-weight: 900; 
    border: 2px solid var(--off-black-bg); 
    cursor: pointer;
    line-height: 1;
    transition: all 0.2s ease;
    
    margin-left: 10px; 
    vertical-align: middle;
}
.help-toggle:hover {
    background-color: #ffb733; 
    transform: scale(1.05);
}

/* Close Button Styling */
.close-btn {
    position: absolute;
    top: 5px;
    right: 15px;
    
    /* Increased size for easier clicking */
    font-size: 24px; 
    
    /* Changed color to white/text for visibility against dark background */
    color: var(--text-color); 
    
    font-weight: bold;
    cursor: pointer; /* Makes it clearly clickable */
    line-height: 1;
    transition: color 0.2s ease;
}
.close-btn:hover {
    /* Hover state is defined by the orange accent color */
    color: var(--orange-border-color); 
}
/* Style the icon specifically to ensure size */
.close-btn i {
    font-size: 1em;
}

/* --- Toggle Button --- */
.toggle-menu {
    display: none;
    position: fixed;
    top: 10px;
    left: 10px;
    z-index: 200;
    background: var(--orange-border-color);
    border: none;
    border-radius: 8px;
    color: #1a1a1a;
    font-size: 1.2em;
    padding: 8px 12px;
    cursor: pointer;
    transition: all 0.2s ease;
}
.toggle-menu:hover {
    background: #ffb733;
}

/* --- Responsive Behaviour --- */
@media (max-width: 900px) {
    .app-layout {
        flex-direction: column;
    }

    .menu-panel {
        position: fixed;
        top: 0;
        left: 0;
        height: 100%;
        z-index: 150;
        background-color: #2c2c2c;
        transform: translateX(-100%);
    }

    .menu-panel.visible {
        transform: translateX(0);
        opacity: 1;
        pointer-events: all;
    }

    .toggle-menu {
        display: block;
    }

    .datacard-container {
        padding-top: 60px;
    }

    .main-rectangle {
        aspect-ratio: auto;
        width: 100%;
        max-width: 95vw;
    }
    
    .content-area {
        gap: var(--content-spacing);
        flex-direction: column;
    }
    
    /* Mobile Abilities Stack */
    .abilities-area {
        flex-direction: column;
    }
    .passive-abilities, .active-abilities {
        flex-basis: auto;
    }
}

@media print {
    @page {
        size: landscape;
    }
    #dataCard, #dataCard * {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }
    body {
        background: none !important;
    }
    .main-rectangle {
        width: 800px !important;
        margin: 0 auto !important;
        min-height: 0 !important;
        overflow: visible !important;
        border: none !important;
    }
    body.print-mode * {
        display: none !important;
    }
    body.print-mode .main-rectangle {
        display: block !important;
    }
}


