/* -------------------------------------------------------
   IMPORTS
------------------------------------------------------- */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');
@import url('https://fonts.googleapis.com/css2?family=Oswald:wght@200..700&display=swap');
@import url('https://fonts.googleapis.com/css2?family=Inter+Tight:ital,wght@0,100..900;1,100..900&display=swap');


/* -------------------------------------------------------
   ROOT VARIABLES
------------------------------------------------------- */
:root {
    --surface-background: #eeeeee;
    --surface-panel: #ffffff;
    --surface-header: #0F1820;

    --opaque: #000;
    --grey: #333333;
    --lightGrey: #b8c4d1;
    --white: #ffffff;

    --primary: #0F1820;
    --accent: #003cff;

    --border-soft: rgba(0,0,0,0.08);
    --border-strong: rgba(0,0,0,0.15);

    --button-surface: #1c2a36;
    --button-surface-hover: #263544;
    --button-border: #2f3f4f;
    --button-border-hover: #3d4f63;

    --card-header-text: #fff;
    --light-blue: #78a0ff;
}


/* -------------------------------------------------------
   GLOBAL
------------------------------------------------------- */
body {
    font-family: 'Inter', sans-serif;
    background: var(--surface-background);
    color: var(--opaque);
    margin: 0;
    padding: 0;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    letter-spacing: 0.1px;
}

html, body { overflow-x: hidden; }


/* -------------------------------------------------------
   GRID BACKGROUND
------------------------------------------------------- */
#card-container {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 20px;

    background-image:
        linear-gradient(to right, rgba(0,0,0,0.05) 1px, transparent 1px),
        linear-gradient(to bottom, rgba(0,0,0,0.05) 1px, transparent 1px);
    background-size: 40px 40px;
    background-position: center;

    min-height: 100vh;
    max-width: 100vw; overflow-x: hidden;
    width: 100%; box-sizing: border-box;
}

#card-inner {
    padding: 20px;
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    align-items: flex-start;
    margin-top: 20px;
    gap: 20px;
}

.card-placeholder { 
    text-align: center;;
}
/* -------------------------------------------------------
   HEADER
------------------------------------------------------- */
.site-header {
    width: 100%;
    background: var(--surface-header);
    padding-bottom: 20px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    position: relative;
    overflow: hidden;
    color: #fff;
}

.site-header::before {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160' viewBox='0 0 160 160'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23noise)' opacity='0.2'/%3E%3C/svg%3E");
    background-size: 200px 200px;
    opacity: 0.5;
}

.header-inner {
    margin: 0 auto;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.site-title {
    font-family: "Oswald", sans-serif;
    font-weight: 800;
    font-size: 36px;
    margin: 0;
}

.site-tagline {
    font-size: 14px;
    margin-top: 6px;
    margin-bottom: 20px;
}


/* -------------------------------------------------------
   HEADER BUTTONS (Unified System)
------------------------------------------------------- */

.header-buttons {
    display: flex;
    gap: 12px;
    width: 50%;
    max-width: 550px;
}

/* Each button wrapper takes equal width */
.button-shell {
    flex: 1;
    display: flex;
    cursor: pointer;
    touch-action: manipulation;
    position: relative;
}

/* Visible button surface */
.button-surface {
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 10px 16px;
    border: 1px solid var(--button-border);
    background: var(--button-surface);
    color: var(--white);
    font-family: "Oswald", sans-serif;
    letter-spacing: 0.5px;
    font-size: 13px;
    user-select: none;

    box-shadow:
        inset 0 0 8px rgba(120,152,255,0.25),
        0 0 6px rgba(0,0,0,0.4);

    transition:
        box-shadow 0.2s ease,
        border-color 0.2s ease,
        color 0.2s ease,
        background 0.2s ease;
}

/* Hover glow */
.button-shell:hover .button-surface {
    border-color: var(--light-blue);
    color: var(--light-blue);
    box-shadow:
        inset 0 0 12px rgba(120,152,255,0.45),
        0 0 10px rgba(120,152,255,0.25);
}

/* Hide real inputs */
.button-shell input[type="file"] {
    display: none;
}

.button-shell input[type="checkbox"] {
    position: absolute;
    opacity: 0;
    pointer-events: auto; /* allow direct tapping/clicking */
    width: 100%;
    height: 100%;
    margin: 0;
    cursor: pointer;
}


/* Disabled state */
.button-shell.disabled .button-surface {
    opacity: 0.4;
    cursor: not-allowed;
    border-color: var(--button-border);
    box-shadow: none;
    color: var(--white);
}

/* Prevent hover glow when disabled */
.button-shell.disabled:hover .button-surface {
    border-color: var(--button-border);
    color: var(--white);
    box-shadow: none;
}

/* Square help button */
#helpButton {
    flex: 0 0 40px; /* fixed width */
}

#helpButton .button-surface {
    padding: 0;
    font-size: 18px;
    line-height: 40px;
}


/* -------------------------------------------------------
   CARD
------------------------------------------------------- */
.card {
    width: 320px;
    background: white;
    padding: 14px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
}

.card-header {
    background: var(--primary);
    color: var(--card-header-text);
    padding: 12px;
    margin: -14px -14px 12px -14px;
    border-bottom: 1px solid var(--border-soft);
}


/* -------------------------------------------------------
   UNIT HEADER + BADGES
------------------------------------------------------- */
.unit-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

.unit-header h2 {
    margin: 0;
    font-family: "Oswald", sans-serif;
    font-size: 20px;
    font-weight: 600;
    color: var(--card-header-text);
}

.unit-badges {
    display: flex;
    gap: 6px;
}

.invuln-box,
.fnp-box {
    white-space: nowrap;
    font-size: 14px;
    font-weight: 600;
    padding: 2px 5px;
    border: 1px solid #00a2ff;
    color: var(--card-header-text);
    box-shadow:
        inset 0 0 20px rgba(120,152,255,0.25),
        0 0 6px rgba(0,0,0,0.4);
}


/* -------------------------------------------------------
   CHARACTERISTICS
------------------------------------------------------- */
.model-name {
    font-size: 10px;
    font-weight: 600;
    margin-top: 6px;
}

.stat-header {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    font-size: 10px;
    font-weight: 600;
    text-align: center;
}

.stat-block {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
   
    gap: 2px;
    font-size: 12px;
    font-family: 'Inter Tight', sans-serif;
    font-weight: 700;
}

.stat-block div {
    background: #eee;
    color: var(--primary);
     border-radius: 2px;
    padding: 3px;
    text-align: center;
}


/* -------------------------------------------------------
   WEAPONS
------------------------------------------------------- */
.weapon-block {
    font-size: 11px;
    margin-top: 6px;
}

.weapon-header {
    display: grid;
    grid-template-columns: 1fr repeat(6, minmax(28px, auto));
    font-size: 10px;
    color: #666;
    margin-top: 8px;
}

.weapon-header .wh-title {
    font-weight: 600;
    font-size: 12px;
    color: #333;
}

.weapon-parent {
    font-size: 11px;
    margin-top: 6px;
}

.wp-name {
    font-size: 11px;
    color: #333;
}

.wp-keywords-inline {
    display: inline-block; white-space: nowrap; 
    font-family: "Inter Tight", sans-serif;
    font-size: 9px;
    color: var(--accent);
}

.weapon-inline-row {
    display: grid;
    grid-template-columns: 1fr repeat(6, minmax(28px, auto));
     gap: 2px;
    align-items: center;
    margin-bottom: 2px;
}

.weapon-inline-row .wp-stat {
    text-align: center;
    background: #eee;
    border-radius: 3px;
    padding: 2px 1px;
    font-size: 10px;
    font-family: 'Inter Tight', sans-serif;
    font-weight: 600;
}


/* -------------------------------------------------------
   INLINE SECTIONS (Abilities, Wargear, Enhancements)
------------------------------------------------------- */
.inline-section {
    font-size: 11px;
    margin-top: 6px;
    line-height: 1.3;
}

.inline-title {
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
    margin-right: 4px;
}

.ability-unique {
    font-weight: 600;
    color: #333;
}

.ability-generic {
    font-weight: 400;
    color: #333;
}

.ability-desc {
    font-size: 10px;
    color: var(--grey);
    font-weight: 400;
    margin-top: 2px;
    line-height: 1.3;
}


/* -------------------------------------------------------
   KEYWORDS
------------------------------------------------------- */
.keywords-text {
    font-size: 11px;
    line-height: 1.2;
    margin-top: 2px;
    font-style: italic;
}


/* -------------------------------------------------------
   SEPARATORS
------------------------------------------------------- */
.section-separator {
    margin-top: 10px;
    margin-bottom: 6px;
    border-bottom: 1px solid #ddd;
}


/* -------------------------------------------------------
   LOADING OVERLAY
------------------------------------------------------- */
#loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 24, 32, 0.85);
    backdrop-filter: blur(2px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.loading-content {
    text-align: center;
    color: #e6eef5;
    font-family: "Inter Tight", sans-serif;
}

.loading-cog {
    font-size: 48px;
    opacity: 0.9;
    animation: cog-spin 2s linear infinite;
    margin-bottom: 10px;
}

.loading-text {
    font-size: 16px;
    letter-spacing: 0.5px;
}

@keyframes cog-spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* -------------------------------------------------------
   HELP OVERLAY
------------------------------------------------------- */

#help-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 24, 32, 0.85);
    backdrop-filter: blur(2px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 9998;
}

.help-panel {
    background: #ffffff;
    color: #0F1820;
    padding: 0;
    width: min(360px, 90vw);
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 4px 20px rgba(0,0,0,0.4);
    overflow: hidden; /* important */
}

.help-content {
    padding: 24px;
    overflow-y: auto;
    flex: 1;
}

.help-close {
    background: var(--button-surface);
    color: white;
    border: 1px solid var(--button-border);
    cursor: pointer;
    font-family: "Oswald", sans-serif;
    padding: 12px;
    text-align: center;
    width: 100%;
    flex-shrink: 0; /* prevents collapsing */
}

.help-close:hover {
    background: var(--button-surface-hover);
}

.help-panel h2 {
    margin-top: 0;
    font-family: "Oswald", sans-serif;
}

.help-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 12px;
    font-family: "Inter Tight", sans-serif;
    font-size: 12px;
    background: var(--surface-panel);
    border: 1px solid var(--border-strong);
    box-shadow: inset 0 0 10px rgba(0,0,0,0.08);
}

.help-table th {
    background: var(--primary);
    color: var(--card-header-text);
    font-family: "Oswald", sans-serif;
    font-weight: 600;
    letter-spacing: 0.5px;
    padding: 8px;
    text-align: left;
    border-bottom: 1px solid var(--border-strong);
}

.help-table td {
    padding: 6px 8px;
    border-bottom: 1px solid var(--border-soft);
    color: var(--grey);
}

.help-table tr:nth-child(even) td {
    background: rgba(0,0,0,0.03);
}


.help-close {
    margin-top: 16px;
    width: 100%;
    padding: 10px;
    background: var(--button-surface);
    color: white;
    border: 1px solid var(--button-border);
    cursor: pointer;
    font-family: "Oswald", sans-serif;
}

.help-close:hover {
    background: var(--button-surface-hover);
}

@media (max-width: 600px) {
    .header-buttons {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
        width: 80%;
    }

    .button-shell {
        width: 100%;
    }

    /* Make the help button match the full-width style on mobile */
    .help-square {
        flex: none;
        width: 100%;
    }

    .help-square .button-surface {
        line-height: normal;
        padding: 10px 0;
    }
}

@media (hover: none) {
    .button-shell:hover .button-surface {
        /* Disable hover glow on touch devices */
        border-color: var(--button-border);
        color: var(--white);
        box-shadow:
            inset 0 0 8px rgba(120,152,255,0.25),
            0 0 6px rgba(0,0,0,0.4);
    }
}
