/* =========================
   BASE TYPOGRAPHY
   Desktop p = 18px, Mobile p = 20px
========================= */
:root {
    --p-size-desktop: 1.125rem; /* 18px */
    --p-size-mobile: 1.25rem;   /* 20px */
    --h2-min: calc(var(--p-size-desktop) + 0.125rem);
    --h2-max: 1.6rem;
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: "Lato", "Helvetica Neue", Helvetica, Arial, sans-serif;
    font-size: var(--p-size-desktop);
    line-height: 1.65;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    margin: 0;
    background: #fffefc;
}

/* Desktop body copy = 18px, Mobile = 20px */
p {
    font-size: inherit;
    line-height: inherit;
    margin: 0 0 8px 0;
}

p:last-child {
    margin-bottom: 0;
}

/* Utility visibility toggle used by navigation + JS */
.hidden {
    display: none !important;
}

@media (max-width: 768px) {
    :root {
        --h2-min: calc(var(--p-size-mobile) + 0.125rem);
    }
    body {
        font-size: var(--p-size-mobile);
    }
}

/* Labels follow paragraph sizing */
label {
    font-size: var(--p-size-desktop);
}

@media (max-width: 768px) {
    label {
        font-size: var(--p-size-mobile);
    }
}

/* Readable control sizing */
input[type="text"],
select,
button {
    font-size: var(--p-size-desktop);
    line-height: 1.35;
    min-height: auto;
    padding: 0.45em 0.75em;
}

@media (max-width: 768px) {
    input[type="text"],
    select,
    button {
        font-size: var(--p-size-mobile);
    }
}

/* =========================
   HERO / HEADER
========================= */
.site-hero {
    position: relative;
    padding: 5px 20px 0px;
    background: linear-gradient(
        180deg,
        #fde4ec 0%,
        #fde4ec 35%,
        #f9c4e2 70%,
        #f4a3d4 100%
    );
}

.page-background { background: #f7f7f5; }

.hero-content {
    max-width: 1200px;
    width: 100%;
    margin: 0;
    position: relative;
    z-index: 1;
}

.hero-heading {
    display: flex;
    align-items: flex-end;
    gap: 20px;
}

.hero-text {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
    flex: 1;
}

.primary-nav {
    position: sticky;
    top: 0;
    align-self: stretch;
    width: 100%;
    padding: 10px 0 0px;
    background: transparent;
    border-bottom: 2px solid #f4a3d4;
    z-index: 10;
    backdrop-filter: blur(4px);
}

/* =========================
   NAV
========================= */
.nav-list {
    list-style: none;
    display: flex;
    justify-content: flex-start;
    align-items: center;
    gap: 22px;
    margin: 0;
    padding: 0;
    font-weight: 600;
    font-size: 0.9375rem;
}

.nav-list > li { position: relative; }

.nav-link,
.dropdown-toggle {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 0.55em 1.1em 0.65em;
    margin: 0;
    border: none;
    border-radius: 10px;
    border-bottom: 2px solid transparent;
    background: transparent;
    color: #1d3557;
    font: inherit;
    font-size: var(--p-size-desktop);
    line-height: 1.2;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    transition: color 0.2s ease, background 0.2s ease, border-bottom-color 0.2s ease;
}

.nav-link:hover,
.nav-link:focus-visible,
.nav-link.is-active {
    color: #0c1f38;
    background: rgba(29, 53, 87, 0.08);
    border-bottom-color: #0c1f38;
}

.nav-item--has-dropdown { position: relative; }

.nav-item--has-dropdown::after {
    content: "";
    position: absolute;
    left: 0; right: 0;
    top: 100%;
    height: 12px;
}

.dropdown-toggle {
    border-radius: 10px 10px 0 0;
    margin-top: 0;
    padding: 0.55em 1.1em 0.65em;
}

.nav-item--has-dropdown:focus-within .dropdown-toggle,
.nav-item--has-dropdown:hover .dropdown-toggle {
    background: rgba(29, 53, 87, 0.08);
    border-bottom-color: #0c1f38;
    color: #0c1f38;
}

.nav-dropdown {
    list-style: none;
    margin: 0;
    padding: 8px 0;
    position: absolute;
    left: 0;
    top: calc(100% + 12px);
    min-width: 200px;
    background: #ffffff;
    border: 1px solid rgba(15, 23, 42, 0.12);
    border-radius: 12px;
    box-shadow: 0 18px 40px rgba(15, 23, 42, 0.12);
    opacity: 0;
    pointer-events: none;
    transform: translateY(-4px);
    transition: opacity 0.18s ease, transform 0.18s ease;
    z-index: 50;
}

.nav-item--has-dropdown:focus-within .nav-dropdown,
.nav-item--has-dropdown:hover .nav-dropdown {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
}

.nav-dropdown .nav-link {
    display: block;
    width: calc(100% - 16px);
    padding: 10px 16px;
    margin: 0 8px;
    box-sizing: border-box;
    border-radius: 8px;
    border-bottom: none;
    justify-content: flex-start;
    font-size: var(--p-size-desktop);
    line-height: 1.2;
}

.nav-dropdown .nav-link:hover,
.nav-dropdown .nav-link:focus-visible {
    background: rgba(29, 53, 87, 0.08);
    color: #0c1f38;
}

@media (max-width: 768px) {
    .nav-link,
    .dropdown-toggle {
        font-size: var(--p-size-mobile);
    }
}

/* --- Mobile nav: 2-per-row + overlay dropdown --- */
@media (max-width: 600px) {
    .nav-list {
        flex-wrap: wrap;
        justify-content: center;
        gap: 6px 10px;
        padding: 6px 0;
    }
    .nav-list > li {
        flex: 1 1 calc(50% - 10px);
        display: flex;
        justify-content: center;
        align-items: center;
    }
    .nav-link {
        width: 100%;
        text-align: center;
        padding: 0.4em 0.75em;
        font-size: 1rem;
        line-height: 1.2;
        border-radius: 8px;
        white-space: nowrap;
        -webkit-tap-highlight-color: transparent;
    }

    .primary-nav,
    .site-hero {
        overflow: visible;
    }

    .nav-item--has-dropdown {
        position: static;
    }

    .nav-item--has-dropdown .nav-dropdown {
        display: none;
        position: absolute;
        left: 12px;
        right: 12px;
        top: calc(100% + 6px);
        min-width: 0;
        margin: 0;
        padding: 8px 0;
        background: #ffffff;
        border: 1px solid rgba(15, 23, 42, 0.12);
        border-radius: 12px;
        box-shadow: 0 18px 40px rgba(15, 23, 42, 0.12);
        z-index: 200;
        opacity: 1;
        pointer-events: auto;
        transform: none;
    }

    .nav-item--has-dropdown.is-open .nav-dropdown {
        display: block;
    }

    .nav-dropdown .nav-link {
        width: 100%;
        justify-content: flex-start;
        padding: 10px 14px;
        margin: 0;
        border-radius: 8px;
        border-bottom: 0;
    }

    .nav-item--has-dropdown::after {
        display: none;
    }

    .nav-link,
    .nav-dropdown .nav-link {
        min-height: auto;
        line-height: 1.2;
    }

    .nav-dropdown .nav-link {
        font-size: var(--p-size-mobile);
    }

    .nav-link:focus {
        outline: none;
        box-shadow: 0 0 0 2px rgba(29, 53, 87, 0.25) inset;
    }
}

/* Optional hero gradient overlay container */
.hero-bg {
    position: absolute;
    inset: 0;
    background: linear-gradient(
        180deg,
        #fde4ec 0%,
        #fde4ec 35%,
        #f9c4e2 70%,
        #f4a3d4 100%
    );
    pointer-events: none;
}

/* =========================
   PAGE WRAPPER
========================= */
.page-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 0 20px 16px;
    box-sizing: border-box;
    max-width: 1600px;
    margin: 0 auto;
    width: 100%;
}

.page-background { background: #fffefc; }

h1 { margin: 0; }

.page-title {
    margin: 12px 0 0 0;
    font-size: clamp(2.1rem, 4vw, 3.2rem);
    font-weight: 800;
    color: #2f1833;
}

.site-logo { height: 165px; width: auto; }
.logo-link { display: inline-block; padding: 12px 0 8px; }

.page-subtitle {
    margin: 0;
    font-size: clamp(1rem, 1.8vw, 1.1rem);
    font-weight: 500;
    font-style: italic;
    color: #4a2a39;
    letter-spacing: 0.02em;
    line-height: 1.35;
}

/* =========================
   HOME / INTRO BLOCKS
========================= */
.home-section {
    display: flex;
    flex-direction: column;
    gap: 0;
    padding: 16px 0 14px;
}

.home-intro {
    flex: 1 1 1;
    color: #2f1a2c;
    margin-bottom: 12px;
}

.home-intro a {
    color: #8a1e54;
    font-weight: 600;
}

.home-figure {
    margin: 2px 0 0 0;
    align-self: stretch;
    text-align: center;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 3px 14px rgba(20, 20, 20, 0.04);
    padding: 4px 4px 8px;
}

.home-figure img {
    width: 100%;
    height: auto;
    border-radius: 12px;
    display: block;
}

.home-figure figcaption {
    margin-top: 8px;
    font-size: 0.95rem;
    color: #5b4e59;
}

@media (max-width: 768px) {
    .home-figure figcaption {
        font-size: 1rem;
    }
}

/* =========================
   SECTION INTROS
========================= */
.expression-intro,
.correlation-intro,
.heatmap-intro,
.contact-section,
.about-section,
.citation-section {
    margin-top: 16px;
    padding: 18px 0 18px;
}

.expression-intro h2,
.correlation-intro h2,
.heatmap-intro h2,
.contact-section h2,
.about-section h2,
.citation-section h2 {
    margin: 0 0 8px 0;
    font-size: clamp(var(--h2-min), 2.8vw, var(--h2-max));
    line-height: 1.25;
    color: #2f1a2c;
}

.expression-intro p,
.correlation-intro p,
.heatmap-intro p,
.contact-section p,
.citation-section p {
    line-height: 1.6;
}

.about-section a {
    color: #8a1e54;
    font-size: 1.1rem;
    font-weight: 600;
}

/* =========================
   HOW-TO DETAILS
========================= */
.how-to-details {
    margin: 8px 0 0 0;
    border-radius: 18px;
    border: 1px solid transparent;
    padding: 0;
}

.how-to-details summary {
    list-style: none;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 6px 16px;
    margin: 0;
    border-radius: 999px;
    background: #ffe48a;
    font-weight: 600;
    font-size: clamp(1rem, 2.4vw, 1.25rem);
    color: #4d330a;
    border: 1px solid #ffd25c;
}

.how-to-details summary::-webkit-details-marker { display: none; }
.how-to-details[open] summary { background: #ffd25c; }

.how-to-panel {
    margin-top: 8px;
    background: #fffef7;
    border-radius: 16px;
    border: 1px solid #ffe3a3;
    padding: 12px 18px;
}

.how-to-panel ol {
    margin: 0;
    padding-left: 22px;
    line-height: 1.5;
}

.how-to-panel li { margin-bottom: 6px; }
.how-to-panel li:last-child { margin-bottom: 10px; }

/* =========================
   FORMS
========================= */
form {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    align-items: center;
    width: fit-content;
    max-width: 100%;
    margin-bottom: 20px;
}

/* Forces items onto a new line */
.form-row {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 16px;
    margin-top: 8px;
}

.form-field {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 0 0 auto;
}

.form-field label { white-space: nowrap; font-weight: bold; }
#categoryDetailWrapper { align-items: center; }
.detail-field {
    align-items: center;
}

.detail-field #categoryDetailDropdown {
    align-self: center;
}

.detail-field .detail-label {
    display: inline-flex;
    align-items: center;
    min-height: 2.4em;
}

.form-field select,
.form-field input[type="text"] {
    min-height: 2.4em;
    height: auto;
    padding: 0.4em 0.75em;
    box-sizing: border-box;
}

.gene-field .gene-input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    width: 240px;
    max-width: 100%;
}

.gene-field input[type="text"] { width: 100%; }

.gene-input-line .gene-input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    width: 120px;
    max-width: 100%;
}

.gene-input-line input[type="text"] { width: 100%; }

/* Gene autocomplete dropdown */
.gene-suggestions {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background: #fff;
    border: 1px solid #cfd2da;
    border-radius: 6px;
    box-shadow: 0 6px 18px rgba(15, 23, 42, 0.15);
    padding: 4px 0;
    display: flex;
    flex-direction: column;
    z-index: 30;
}

.gene-suggestions.hidden {
    display: none;
}

.gene-suggestion {
    display: block;
    width: 100%;
    padding: 8px 12px;
    border: none;
    background: transparent;
    text-align: left;
    font: inherit;
    cursor: pointer;
}

.gene-suggestion + .gene-suggestion {
    border-top: 1px solid #edf0f5;
}

.gene-suggestion:hover,
.gene-suggestion:focus {
    background: rgba(29, 53, 87, 0.08);
    outline: none;
}

.gene-suggestion.empty {
    cursor: default;
    color: #6b7280;
    font-style: italic;
}

input[type="text"] {
    padding: 0.45em 0.75em;
    border-radius: 4px;
    border: 1px solid #ccc;
}

textarea {
    padding: 0.45em 0.75em;
    border-radius: 6px;
    border: 1px solid #ccc;
    font-family: inherit;
    font-size: var(--p-size-desktop);
    line-height: 1.4;
    width: 100%;
    max-width: 480px;
    box-sizing: border-box;
    resize: vertical;
}

.heatmap-placeholder {
    margin-top: 16px;
    padding: 18px;
    border: 1px dashed rgba(29, 53, 87, 0.3);
    border-radius: 12px;
    background: #f8fbff;
    color: #1d3557;
    overflow-y: auto;
    max-height: 520px;
    max-width: 680px;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
}

.heatmap-image {
    width: 100%;
    max-width: 640px;
    height: auto;
    display: block;
}

.heatmap-note {
    margin-top: 10px;
    font-style: italic;
    color: #5b1a31;
}
/* multi-select */
.multi-select {
    position: relative;
    display: inline-flex;
    align-items: stretch;
    min-width: 120px;
    width: 160px;
    max-width: 160px;
    margin-right: 8px;
    font-size: inherit;
    line-height: 1.35;
}

.multi-select summary {
    list-style: none;
    cursor: pointer;
    border: 1px solid #ccc;
    border-radius: 4px;
    padding: 0.4em 0.75em;
    min-height: 2.4em;
    box-sizing: border-box;
    user-select: none;
    background: #fff;
    position: relative;
    padding-right: 28px;
    display: inline-flex;
    align-items: center;
    width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: inherit;
    line-height: 1.35;
}

.multi-select summary::-webkit-details-marker { display: none; }

.multi-select summary::after {
    content: "▾";
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.9em;
    color: #555;
}

.multi-select[open] summary {
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
}

.multi-select-options {
    position: absolute;
    left: 0;
    right: auto;
    top: calc(100% - 1px);
    width: 100%;
    border: 1px solid #ccc;
    border-top: none;
    border-bottom-left-radius: 4px;
    border-bottom-right-radius: 4px;
    background: #fff;
    padding: 8px 10px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-height: 220px;
    overflow-y: auto;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.08);
    z-index: 50;
    font-size: inherit;
    line-height: 1.35;
}

.multi-option {
    display: flex;
    align-items: center;
    gap: 6px;
    font-weight: normal;
    font-size: inherit;
    line-height: 1.35;
}

.multi-option input[type="checkbox"] {
    width: 16px;
    height: 16px;
    margin: 0;
}

/* Buttons */
button[type="submit"] {
    padding: 0.5em 1em;
    border: none;
    background-color: #868f9b;
    color: #fff;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 600;
}
button[type="submit"]:hover { background-color: #50565c; }
.form-submit { align-self: center; }

.form-error {
    color: #b00020;
    margin-top: 8px;
    font-size: 0.95rem;
}

#generatePlotButton,
#generateCorrelationButton,
#generateHeatmapButton {
    position: relative;
    display: inline-grid;
    place-items: center;
}

/* Plot Stats Formatting */
.correlation-stats {
    margin-top: 10px;
    font-size: 0.95rem;
    color: #444;
}

.stat-line {
    display: block;
    margin-bottom: 4px;
}

#generatePlotButton .label,
#generateCorrelationButton .label,
#generateHeatmapButton .label {
    grid-area: 1 / 1 / 2 / 2;
    transition: opacity 0.15s ease;
}

#generatePlotButton .loading-spinner,
#generateCorrelationButton .loading-spinner,
#generateHeatmapButton .loading-spinner {
    grid-area: 1 / 1 / 2 / 2;
    width: 1.2em;
    height: 1.2em;
    border-radius: 50%;
    border: 4px solid rgba(255, 255, 255, 0.4);
    border-top-color: #ffffff;
    display: none;
    animation: button-spin 0.9s linear infinite;
}

#generatePlotButton.is-loading .label,
#generateCorrelationButton.is-loading .label,
#generateHeatmapButton.is-loading .label { opacity: 0; }
#generatePlotButton.is-loading .loading-spinner,
#generateCorrelationButton.is-loading .loading-spinner,
#generateHeatmapButton.is-loading .loading-spinner { display: block; }
#generatePlotButton.is-loading,
#generateCorrelationButton.is-loading,
#generateHeatmapButton.is-loading { pointer-events: none; }

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

/* =========================
   PLOT WRAPPERS
========================= */
#plot,
#additionalPlot,
#selectionPlot,
#correlationResult {
    max-width: 640px;
    width: 100%;
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 12px;
    padding: 10px;
    background: #fff;
    box-shadow: 0 8px 22px rgba(0, 0, 0, 0.08);
    margin-top: 14px;
    display: none;
}

#plot.has-content,
#additionalPlot.has-content,
#selectionPlot.has-content,
#correlationResult.has-content { display: block; }

#plot img,
#additionalPlot img,
#selectionPlot img,
#correlationPlot img {
    display: block;
    width: 100%;
    height: auto;
}

/* =========================
   CITATIONS / LINKS
========================= */
a { text-decoration: none; color: #007bff; margin-right: 10px; }
.citation-link { color: #1167b1; }

/* =========================
   DISCLAIMER
========================= */
.site-disclaimer {
    margin-top: 40px;
    padding: 20px;
    background: #f4f4f4;
    border-top: 1px solid #c7c7c7;
    font-size: 0.75rem;
    line-height: 1.35;
    color: #414141;
}

.site-disclaimer p {
    font-size: 1rem;
}

.site-disclaimer p:last-child { margin-bottom: 0; }

.site-disclaimer.has-background {
    background: #f4f4f4;
    border-top-color: #c7c7c7;
    box-shadow: none;
    padding-top: 20px;
    margin-top: 0px;
}

/* =========================
   RESPONSIVE TWEAKS
========================= */
@media (max-width: 768px) {
    .home-section { padding: 24px 0 16px; }
}


/* ============================================
   MOBILE HEADER + NAV FIXES
   ============================================ */
html, body {
    overflow-x: hidden; /* Prevent sideways scrolling */
}

@media (max-width: 600px) {

  /* HEADER */
  .hero-heading {
    justify-content: flex-start;
    gap: 12px;
  }

  .site-logo {
    display: none !important;
  }

  .page-title {
    font-size: clamp(1.875rem, 6vw, 1.95rem);
    line-height: 1.15;
  }

  .page-subtitle {
    font-size: clamp(1rem, 3.5vw, 1.1rem);
    line-height: 1.3;
    max-width: 92%;
  }

  .site-hero {
    padding: 5px 16px 0;
  }

  .primary-nav {
    padding-top: 2px; /* compact */
  }

  /* NAV: two items per row, centered */
  .nav-list {
    flex-wrap: wrap;
    justify-content: center;
    gap: 6px 10px;
    padding: 6px 0;
  }

  .nav-list > li {
    flex: 1 1 calc(50% - 10px); /* Row1: Home | Gene Explore; Row2: How to Cite | About Us */
    display: flex;
    justify-content: center;
    align-items: center;
  }

  .nav-link {
    width: 100%;
    text-align: center;
    padding: 0.4em 0.75em;
    font-size: var(--p-size-mobile);
    line-height: 1.2;
    border-radius: 8px;
    white-space: nowrap;
  }

  /* DROPDOWN: do not reserve space when closed */
  .nav-item--has-dropdown::after { display: none; }

  .nav-dropdown {
    display: none;
    position: absolute;
    left: 12px;
    right: 12px;
    top: calc(100% + 6px);
    min-width: 0;
    padding: 8px 0;
    margin: 0;
    background: #fff;
    border: 1px solid rgba(15, 23, 42, 0.12);
    border-radius: 12px;
    box-shadow: 0 18px 40px rgba(15, 23, 42, 0.12);
    z-index: 200;
  }

  .nav-item--has-dropdown.is-open .nav-dropdown {
    display: block;
  }

  .nav-dropdown .nav-link {
    width: 100%;
    margin: 0;
    padding: 10px 14px;
    border-radius: 8px;
    border-bottom: 0;
    white-space: normal !important;
    overflow-wrap: anywhere;
    line-height: 1.3;
  }

  /* FORMS: larger touch-friendly text */
  input,
  select,
  button,
  label {
    font-size: var(--p-size-mobile) !important;
  }

  .form-field {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    width: 100%;
    gap: 6px;
  }

  .form-field label {
    white-space: normal;
    margin-bottom: 0;
  }

  .form-field select,
  .category-display {
    width: 100% !important;
    max-width: 100%;
    box-sizing: border-box;
  }

  .detail-field {
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
    width: 100%;
  }

  .detail-field .detail-label {
    font-weight: 600;
    font-size: var(--p-size-mobile);
    align-self: flex-start;
    min-height: auto;
  }

  #categoryDetailDropdown {
    width: 100%;
    align-self: stretch;
  }

  #categoryDetailDropdown summary {
    justify-content: flex-start;
    text-align: left;
    padding-left: 0.75em;
    padding-right: 0.75em;
    width: 100%;
  }

  #categoryDetailWrapper {
    align-items: flex-start !important;
    width: 100%;
  }

  #categoryDetailWrapper .multi-select {
    width: 100%;
    max-width: 100%;
    margin-right: 0;
  }
}
