/* General Styles */
body {
    font-family: 'Segoe UI', Arial, sans-serif;
    background-color: #f8f9fa;
}

/* Modern Heading Style */
h1.text-center.mb-4 {
    color: #1a2526;
    font-weight: 700;
    font-size: min(2.5em, 6vw);
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.2);
    position: relative;
    padding-bottom: 10px;
}

h1.text-center.mb-4::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 60px;
    height: 4px;
    background: linear-gradient(to right, #3b82f6, #1a2526);
    border-radius: 2px;
}

/* Table Wrapper for Group and Period Numbers */
.table-wrapper {
    position: relative;
    max-width: 100%;
    overflow-x: auto;
}

.table-with-periods {
    display: flex;
    align-items: flex-start;
}

/* Group Numbers (1-18) */
.group-numbers {
    display: grid;
    grid-template-columns: repeat(18, minmax(55px, 1fr));
    gap: 1px;
    margin-left: 40px;
    margin-bottom: 5px;
}

.group-number {
    background-color: #e9ecef;
    color: #333;
    font-weight: bold;
    text-align: center;
    padding: 5px;
    border-radius: 4px;
    font-size: min(1em, 2.8vw);
    transition: background-color 0.3s;
}

.group-number:hover {
    background-color: #dee2e6;
}

/* Period Numbers (1-7) */
.period-numbers {
    display: flex;
    flex-direction: column;
    width: 40px;
    gap: 1px;
    margin-right: 5px;
}

.period-number {
    background-color: #e9ecef;
    color: #333;
    font-weight: bold;
    text-align: center;
    padding: 5px;
    border-radius: 4px;
    height: 83px;
    line-height: 70px;
    font-size: min(1em, 2.8vw);
    transition: background-color 0.3s;
}

.period-number:hover {
    background-color: #dee2e6;
}

/* Periodic Table */
.periodic-table {
    display: grid;
    grid-template-rows: repeat(7, minmax(55px, 1fr)) auto auto;
    grid-template-columns: repeat(18, minmax(55px, 1fr));
    gap: 1px;
    width: 100%;
    margin: 10px 0;
    background-color: #ddd;
    padding: 3px;
    border-radius: 8px;
}

.element {
    position: relative;
    padding: 3px;
    text-align: center;
    border-radius: 4px;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    min-width: 55px;
    min-height: 80px;
    max-width: 100%;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.element:hover {
    transform: scale(1.05);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.element.empty {
    background: transparent;
}

.element.placeholder {
    background-color: #e0e0e0;
    font-style: italic;
}

.element .atomic-number {
    font-size: min(1em, 2.8vw);
    font-weight: bold;
    position: absolute;
    top: 2px;
    left: 2px;
}

.element .symbol {
    font-size: min(1.4em, 4vw);
    font-weight: bold;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.element .name {
    font-size: min(0.7em, 2.2vw);
    position: absolute;
    bottom: 2px;
    left: 50%;
    transform: translateX(-50%);
    max-width: 90%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.element .atomic-mass {
    font-size: min(0.7em, 2.2vw);
    position: absolute;
    top: 2px;
    right: 2px;
}

.element .property-value {
    font-size: min(0.7em, 2.2vw);
    position: absolute;
    top: 60%;
    left: 50%;
    transform: translateX(-50%);
    max-width: 90%;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* F-block Rows */
.gap-row {
    grid-column: 1 / -1;
}

.lanthanides,
.actinides {
    display: flex;
    gap: 1px;
    grid-column: 1 / -1;
}

.lanthanides .element,
.actinides .element {
    flex: 1;
    min-width: 55px;
    min-height: 80px;
}

/* Modern Instruction Section */
.modern-instructions {
    background: linear-gradient(135deg, #ffffff, #e8f0fe);
    border: none;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.modern-instructions:hover {
    transform: translateY(-5px);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.15);
}

.instruction-heading {
    font-size: min(1.8em, 4.5vw);
    font-weight: 600;
    color: #1a3c6e;
    margin-bottom: 15px;
    position: relative;
}

.instruction-heading::after {
    content: '';
    position: absolute;
    bottom: -5px;
    left: 0;
    width: 50px;
    height: 3px;
    background: #3b82f6;
    border-radius: 2px;
}

.instruction-subheading {
    font-size: min(1.3em, 3.8vw);
    font-weight: 500;
    color: #2d5ba6;
    margin: 10px 0;
}

.instruction-text {
    font-size: min(1em, 3vw);
    color: #4a5568;
    line-height: 1.6;
}

/* Modern Example Element */
.modern-example-element {
    width: 130px;
    height: 130px;
    background-color: #ffeb3b;
    border: 2px solid #d1d5db;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.modern-example-element:hover {
    transform: scale(1.1);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
}

.example-element .atomic-number {
    font-size: min(0.9em, 2.5vw);
    font-weight: bold;
    top: 5px;
    left: 5px;
}

.example-element .symbol {
    font-size: min(1.5em, 4vw);
    font-weight: bold;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.example-element .name {
    font-size: min(1em, 2vw);
    bottom: 5px;
    left: 50%;
    transform: translateX(-50%);
    text-align: center;
    max-width: 90%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.example-element .atomic-mass {
    font-size: min(1em, 2vw);
    top: 5px;
    right: 5px;
}

.example-element .property-value {
    font-size: min(0.7em, 2vw);
    top: 63%;
    left: 50%;
    transform: translateX(-50%);
    max-width: 90%;
    white-space: nowrap;
    text-overflow: ellipsis;
}

/* Example Labels */
.example-label {
    font-size: min(1em, 2.8vw);
    color: #2d3748;
    font-weight: 600;
    position: absolute;
    white-space: nowrap;
    z-index: 1;
}

.example-label-left {
    left: -114px;
    top: 0;
}

.example-label-right {
    right: -110px;
    top: 5px;
}

.example-label-symbol {
    left: -90px;
    top: 50%;
    transform: translateY(-50%);
}

.example-label-bottom-left {
    left: -50px;
    bottom: 5px;
}

.example-label-bottom-right {
    right: -100px;
    bottom: 27px;
    max-width: 100px;
    text-align: left;
}

/* Color Legend */
#colorLegend {
    background: #ffffff;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.legend-heading {
    font-size: min(1.2em, 3.5vw);
    font-weight: 600;
    color: #1a3c6e;
    margin-bottom: 10px;
}

.gradient-bar {
    height: 20px;
    width: 100%;
    border-radius: 4px;
    margin-bottom: 10px;
}

.legend-labels {
    display: flex;
    justify-content: space-between;
    font-size: min(0.9em, 2.5vw);
    color: #4a5568;
}

.legend-categories {
    list-style: none;
    padding: 0;
    margin: 0;
}

.legend-categories li {
    display: flex;
    align-items: center;
    font-size: min(0.9em, 2.5vw);
    color: #4a5568;
    margin-bottom: 5px;
}

.legend-categories .color-swatch {
    width: 20px;
    height: 20px;
    border-radius: 4px;
    margin-right: 10px;
    border: 1px solid #ddd;
}

/* PubChem-inspired Color Schemes for Categorical Properties */
.standard-state-gas { background-color: #ffb3b3; }
.standard-state-liquid { background-color: #b3ffb3; }
.standard-state-solid { background-color: #b3b3ff; }
.standard-state-expected-to-be-a-solid { background-color: #b3b3ff; }

.group-block-hydrogen { background-color: #ffcccc; }
.group-block-noble-gas { background-color: #f399b1; }
.group-block-alkali-metal { background-color: #ff9999; }
.group-block-alkaline-earth-metal { background-color: #99ccff; }
.group-block-metalloid { background-color: #cc99ff; }
.group-block-nonmetal { background-color: #ffcc99; }
.group-block-halogen { background-color: #99ffcc; }
.group-block-post-transition-metal { background-color: #c6eaf9; }
.group-block-transition-metal { background-color: #fce7b7; }
.group-block-lanthanide { background-color: #fcd3c1; }
.group-block-actinide { background-color: #f5c2da; }

/* Swal Popup Table */
.custom-swal-popup table {
    width: 100%;
    border-collapse: collapse;
    font-family: 'Segoe UI', Arial, sans-serif;
    color: #000;
}

.custom-swal-popup th, .custom-swal-popup td {
    padding: 8px;
    border-bottom: 1px solid #ddd;
    text-align: left;
}

.custom-swal-popup th {
    background-color: #f5f5f5;
}

/* Fix SweetAlert Popup Example Element */
.custom-swal-popup .example-element {
    position: relative;
    padding: 5px;
    text-align: center;
    border-radius: 4px;
    width: 150px;
    height: 150px;
    border: 1px solid #ccc;
    overflow: visible;
}

.custom-swal-popup .example-element .atomic-number {
    font-size: min(0.9em, 2.5vw);
    top: 5px;
    left: 5px;
}

.custom-swal-popup .example-element .symbol {
    font-size: min(1.5em, 4vw);
    font-weight: bold;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.custom-swal-popup .example-element .name {
    font-size: min(0.7em, 2vw);
    bottom: 25px;
    left: 50%;
    transform: translateX(-50%);
    text-align: center;
    max-width: 90%;
    white-space: normal;
    word-wrap: break-word;
}

.custom-swal-popup .example-element .atomic-mass {
    font-size: min(0.7em, 2vw);
    top: 5px;
    right: 5px;
}

/* Responsive Design */
@media (max-width: 768px) {
    h1.text-center.mb-4 {
        font-size: min(2em, 5vw);
    }

    .group-numbers {
        grid-template-columns: repeat(9, minmax(45px, 1fr));
        margin-left: 40px;
    }

    .group-number {
        font-size: min(0.9em, 2.5vw);
        padding: 3px;
    }

    .period-numbers {
        width: 35px;
    }

    .period-number {
        font-size: min(0.9em, 2.5vw);
        height: 73px;
        line-height: 65px;
    }

    .periodic-table {
        grid-template-rows: repeat(7, minmax(45px, 1fr)) auto auto;
        grid-template-columns: repeat(9, minmax(45px, 1fr));
        gap: 1px;
        padding: 2px;
    }

    .element,
    .lanthanides .element,
    .actinides .element {
        padding: 2px;
        min-width: 45px;
        min-height: 70px;
    }

    .element .atomic-number {
        font-size: min(0.9em, 2.5vw);
    }

    .element .symbol {
        font-size: min(1.2em, 3.5vw);
    }

    .element .name {
        font-size: min(0.6em, 2vw);
    }

    .element .atomic-mass {
        font-size: min(0.6em, 2vw);
    }

    .element .property-value {
        font-size: min(0.6em, 2vw);
        top: 65%;
    }

    .instruction-heading {
        font-size: min(1.5em, 4vw);
    }

    .instruction-subheading {
        font-size: min(1.1em, 3vw);
    }

    .instruction-text {
        font-size: min(0.9em, 2.5vw);
    }

    .modern-example-element {
        width: 100px;
        height: 100px;
    }

    .example-label {
        font-size: min(0.9em, 2.4vw);
    }

    .example-label-left {
        left: -80px;
        top: 0;
    }

    .example-label-right {
        right: -100px;
        top: 5px;
    }

    .example-label-symbol {
        left: -70px;
        top: 50%;
        transform: translateY(-50%);
    }

    .example-label-bottom-left {
        left: -110px;
        bottom: 5px;
    }

    .example-label-bottom-right {
        right: -60px;
        bottom: 10px;
        max-width: 80px;
    }

    .custom-swal-popup .example-element {
        width: 100px;
        height: 100px;
    }

    .legend-heading {
        font-size: min(1em, 3vw);
    }

    .gradient-bar {
        height: 15px;
    }

    .legend-labels,
    .legend-categories li {
        font-size: min(0.8em, 2.2vw);
    }
}

/* --- Block Colors (s, p, d, f) --- */
.block-s { background-color: #ff9999 !important; } /* Red/Pink for s-block */
.block-p { background-color: #99ff99 !important; } /* Green for p-block */
.block-d { background-color: #9999ff !important; } /* Blue for d-block */
.block-f { background-color: #ffff99 !important; } /* Yellow for f-block */

/* --- SVG Connector Lines --- */
.connector-svg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none; /* Let clicks pass through */
    z-index: 5;
}

.connector-line {
    stroke: #555;
    stroke-width: 2;
    stroke-dasharray: 5, 5; /* Dashed line */
    fill: none;
    opacity: 0.6;
}


@media (max-width: 480px) {
    h1.text-center.mb-4 {
        font-size: min(1.8em, 4.5vw);
    }

    .group-numbers {
        grid-template-columns: repeat(6, minmax(35px, 1fr));
        margin-left: 35px;
    }

    .group-number {
        font-size: min(0.8em, 2.2vw);
        padding: 2px;
    }

    .period-numbers {
        width: 30px;
    }

    .period-number {
        font-size: min(0.8em, 2.2vw);
        height: 63px;
        line-height: 55px;
    }

    .periodic-table {
        grid-template-rows: repeat(7, minmax(35px, 1fr)) auto auto;
        grid-template-columns: repeat(6, minmax(35px, 1fr));
        gap: 1px;
        padding: 2px;
    }

    .element,
    .lanthanides .element,
    .actinides .element {
        padding: 1px;
        min-width: 35px;
        min-height: 60px;
    }

    .element .atomic-number {
        font-size: min(0.8em, 2.5vw);
    }

    .element .symbol {
        font-size: min(1em, 3vw);
    }

    .element .name,
    .element .atomic-mass,
    .element .property-value {
        display: none;
    }

    .instruction-heading {
        font-size: min(1.4em, 3.5vw);
    }

    .instruction-subheading {
        font-size: min(1em, 3vw);
    }

    .instruction-text {
        font-size: min(0.8em, 2.5vw);
    }

    .modern-example-element {
        width: 80px;
        height: 80px;
    }

    .example-label {
        font-size: min(0.8em, 2vw);
        display: none;
    }

    .custom-swal-popup .example-element {
        width: 80px;
        height: 80px;
    }

    .legend-heading {
        font-size: min(0.9em, 2.5vw);
    }

    .gradient-bar {
        height: 12px;
    }

    .legend-labels,
    .legend-categories li {
        font-size: min(0.7em, 2vw);
    }
}



/* Center content for screens wider than 1440px */
@media (min-width: 1441px) {
    .container-fluid {
        max-width: 1440px;
        margin: 0 auto;
    }

    .table-wrapper {
        max-width: 1440px;
        margin: 0 auto;
    }

    .periodic-table {
        max-width: calc(1440px - 45px);
        margin: 10px 0;
    }

    #instructions {
        max-width: 1440px;
        margin: 0 auto;
    }

    #colorLegend {
        max-width: 1440px;
        margin: 0 auto;
    }
}