/* ============================================
   William Weaver Website 2.0 - Main Styles
   Color Palette: Dark Greens + Dark Magenta
   ============================================ */

:root {
    --base-darkest: #0a1f0a;
    --base-dark: #132e13;
    --base-mid: #1e4d1e;
    --accent: #8b1a6a;
    --accent-light: #c23d9e;
    --text: #e8e8e8;
    --text-heading: #ffffff;
    --text-muted: #a0a0a0;
    --leaf-green: #4a7c3f;
    --card-bg: #0f1f0f;
    --card-border: #1a3a1a;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
    scrollbar-color: var(--accent) var(--base-darkest);
    font-size: 16px;
}

@media (min-width: 1200px) and (orientation: landscape) {
    html { font-size: 20px; }
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--base-darkest);
    color: var(--text);
    line-height: 1.7;
    overflow-x: hidden;
}

h1, h2, h3, h4 {
    font-family: 'Playfair Display', serif;
    color: var(--text-heading);
}

a {
    color: var(--accent-light);
    text-decoration: none;
    transition: color 0.3s ease;
}

a:hover {
    color: #e050b0;
}

/* ============================================
   Navigation
   ============================================ */

.site-nav {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    background: rgba(10, 31, 10, 0.92);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid rgba(30, 77, 30, 0.3);
    transition: background 0.3s ease;
}

.nav-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 2rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 64px;
}

.nav-brand {
    font-family: 'Playfair Display', serif;
    font-size: 1.3rem;
    color: var(--text-heading);
    font-weight: 700;
    letter-spacing: 0.02em;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.nav-brand.visible {
    opacity: 1;
    pointer-events: auto;
}

.nav-links {
    display: flex;
    list-style: none;
    gap: 0.25rem;
}

.nav-links a {
    color: var(--text);
    padding: 0.5rem 0.9rem;
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: 400;
    transition: all 0.25s ease;
    white-space: nowrap;
}

.nav-links a:hover {
    color: var(--accent-light);
    background: rgba(139, 26, 106, 0.1);
}

.nav-toggle {
    display: none;
    background: none;
    border: none;
    color: var(--text);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.5rem;
}

/* ============================================
   Hero / Parallax Tree Section
   ============================================ */

.tree-section {
    position: relative;
    height: 300vh;
    height: 300dvh;
    overflow-x: clip;
}

.tree-viewport {
    position: sticky;
    top: 0;
    height: 100vh;
    height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    background-color: #071907;
}

.tree-layout {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    max-width: 1400px;
    padding: 0 2rem;
    gap: 3rem;
}

.tree-text-left,
.tree-text-right {
    flex: 1;
    max-width: 300px;
}

.tree-text-left {
    text-align: right;
}

@media (orientation: landscape) {
    .tree-text-left {
        text-align: left;
    }
}

.tree-text-right {
    text-align: left;
}

.tree-text-left h1 {
    font-size: 2.8rem;
    line-height: 1.1;
    margin-bottom: 1rem;
}

.tree-text-left p {
    font-size: 1rem;
    color: var(--text-muted);
    white-space: pre-line;
    line-height: 1.6;
}

.tree-text-right p {
    font-size: 1.05rem;
    color: var(--text-muted);
    line-height: 1.7;
}

.tree-canvas {
    position: relative;
    width: min(460px, 80vw);
    aspect-ratio: 1 / 1;
    flex-shrink: 0;
}

.tree-img {
    width: 100%;
    height: 100%;
    display: block;
}

/* Leaves container overlays the tree image exactly */
#leaves-container {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.tree-ground {
    position: absolute;
    bottom: 0;
    left: -50%;
    right: -50%;
    height: 60px;
    pointer-events: none;
}

/* On mobile portrait, contain tree-ground to prevent horizontal overflow
   that pushes the nav toggle off-screen */
@media (max-width: 768px) and (orientation: portrait) {
    .tree-ground {
        left: 0;
        right: 0;
    }
}

/* Leaf elements */
.leaf {
    position: absolute;
    width: 200px;
    height: 140px;
    pointer-events: none;
    will-change: transform;
    z-index: 5;
    transform-origin: center bottom;
}

.leaf img,
.leaf svg {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}

/* Color overlay for white PNG leaves — multiply blend turns white into the overlay color.
   The leaf image is used as a CSS mask so color only applies to the leaf shape. */
.leaf-color-overlay {
    position: absolute;
    inset: 0;
    background-color: #4a7c3f;
    mix-blend-mode: multiply;
    pointer-events: none;
    /* mask is set dynamically via JS using the leaf image URL */
    -webkit-mask-size: contain;
    mask-size: contain;
    -webkit-mask-repeat: no-repeat;
    mask-repeat: no-repeat;
    -webkit-mask-position: center;
    mask-position: center;
}

/* Fallback SVG leaf style */
.leaf-shape {
    fill: var(--leaf-green);
    transition: fill 0.3s ease;
}

/* Herbarium sheets below tree */
#sheets-container {
    position: absolute;
    top: 108%;
    left: 0;
    right: 0;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    gap: 15px;
    pointer-events: none;
    z-index: 10;
}

.sheet-img {
    display: block;
}

/* Scroll indicator */
.scroll-hint {
    position: absolute;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-muted);
    font-size: 0.8rem;
    animation: bobUpDown 2s ease-in-out infinite;
}

@keyframes bobUpDown {
    0%, 100% { transform: translateX(-50%) translateY(0); }
    50% { transform: translateX(-50%) translateY(8px); }
}

/* ============================================
   Section Common Styles
   ============================================ */

.section {
    padding: 6rem 2rem;
}

.section-inner {
    max-width: 1200px;
    margin: 0 auto;
    position: relative;
    z-index: 1;
}

.section-heading {
    font-size: 2.2rem;
    text-align: center;
    margin-bottom: 3rem;
    position: relative;
}

.section-heading::after {
    content: '';
    display: block;
    width: 60px;
    height: 3px;
    background: var(--accent);
    margin: 0.75rem auto 0;
    border-radius: 2px;
}

/* ============================================
   About Section
   ============================================ */

.about-section {
    background: var(--base-darkest);
    position: relative;
    margin-top: -15vh;
    z-index: 5;
}

.about-section .about-bg {
    position: absolute;
    inset: 0;
    background: url('../img/frontispiece-01.png') center/cover no-repeat;
    opacity: 0.15;
    pointer-events: none;
    mix-blend-mode: lighten;
    filter: sepia(100%) hue-rotate(70deg) saturate(0.5) brightness(0.4);
}

.about-content {
    max-width: 1200px;
    margin: 0 auto;
    position: relative;
    z-index: 1;
}

.about-content p {
    margin-bottom: 1.25rem;
    font-size: 1.05rem;
}

.about-intro {
    font-size: 1.1rem;
    line-height: 1.7;
    margin-bottom: 2rem;
    max-width: 1200px;
    margin-left: auto;
    margin-right: auto;
}

.about-card {
    background: #071907;
    border: 1px solid var(--card-border);
    border-radius: 12px;
    overflow: hidden;
    margin-bottom: 1.5rem;
    max-width: 1200px;
    margin-left: auto;
    margin-right: auto;
    transition: border-color 0.3s ease;
}

.about-card:hover {
    border-color: var(--accent);
}

.about-card-header {
    background: linear-gradient(135deg, var(--base-dark), var(--base-mid));
    padding: 1rem 1.5rem;
}

.about-subheading {
    font-size: 1.3rem;
    margin: 0;
    color: var(--text);
}

.about-card-body {
    display: flex;
    gap: 1.5rem;
    padding: 1.5rem;
    align-items: flex-start;
}

.about-card--img-left .about-card-body {
    flex-direction: row-reverse;
}

.about-card-text {
    flex: 1;
}

.about-card-img {
    width: 220px;
    object-fit: contain;
    border-radius: 8px;
    flex-shrink: 0;
    align-self: stretch;
}

.about-card-img-stack {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 0.5rem;
    flex-shrink: 0;
    align-self: stretch;
}

.about-card-img-stack .about-card-img {
    width: 220px;
    height: auto;
    flex: 1;
    object-fit: contain;
}

@media (max-width: 700px) {
    .about-card-body,
    .about-card--img-left .about-card-body {
        flex-direction: column;
    }

    .about-card-img {
        width: 100%;
        height: 200px;
        object-fit: cover;
    }

    .about-card-img-stack .about-card-img {
        width: 100%;
        height: 200px;
        object-fit: cover;
    }
}

/* ============================================
   Projects Card Grid
   ============================================ */

.projects-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    max-width: 1200px;
    margin: 0 auto;
    gap: 1.5rem;
}

.project-card {
    background: #071907;
    border: 1px solid var(--card-border);
    border-radius: 12px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
}

.project-card:hover {
    transform: translateY(-4px);
    border-color: var(--accent);
    box-shadow: 0 8px 30px rgba(139, 26, 106, 0.15);
}

.project-card-img {
    width: 100%;
    height: 200px;
    object-fit: cover;
    background: var(--base-dark);
}

.project-card-img-placeholder {
    width: 100%;
    height: 200px;
    background: linear-gradient(135deg, var(--base-dark), var(--base-mid));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.5rem;
    color: var(--accent);
}

.project-card-body {
    padding: 1.5rem;
    flex: 1;
    display: flex;
    flex-direction: column;
}

.project-card-body h3 {
    font-size: 1.3rem;
    margin-bottom: 0.75rem;
}

.project-card-body p {
    font-size: 0.92rem;
    color: var(--text-muted);
    margin-bottom: 1rem;
    flex: 1;
}

.project-card-links {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-top: auto;
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 500;
    transition: all 0.25s ease;
    border: none;
    cursor: pointer;
    text-decoration: none;
}

.btn-accent {
    background: var(--accent);
    color: #fff;
}

.btn-accent:hover {
    background: var(--accent-light);
    color: #fff;
}

.btn-outline {
    background: transparent;
    color: var(--text);
    border: 1px solid var(--card-border);
}

.btn-outline:hover {
    border-color: var(--accent);
    color: var(--accent-light);
}

.project-badges {
    display: flex;
    gap: 0.75rem;
    margin-top: 0.75rem;
    align-items: center;
}

/* ============================================
   CV Section
   ============================================ */

.cv-section {
    background: var(--base-dark);
}

.cv-container {
    max-width: 1200px;
    margin: 0 auto;
    text-align: center;
}

.cv-iframe-wrapper {
    position: relative;
    overflow: hidden;
    border-radius: 12px;
    border: 1px solid var(--card-border);
    height: 350px;
    transition: height 0.5s ease;
    margin-bottom: 1.5rem;
}

.cv-iframe-wrapper.expanded {
    height: 80vh;
}

.cv-iframe-wrapper iframe {
    width: 100%;
    height: 100%;
    border: none;
}

.cv-fade-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 80px;
    background: linear-gradient(transparent, var(--base-dark));
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.cv-iframe-wrapper.expanded .cv-fade-overlay {
    opacity: 0;
}

.btn-group {
    display: inline-flex;
    border-radius: 8px;
    overflow: hidden;
}

.btn-group .btn {
    border-radius: 0;
    border-right: 1px solid rgba(255, 255, 255, 0.2);
    padding: 0.75rem 2rem;
    font-size: 1rem;
}

.btn-group .btn:first-child {
    border-radius: 8px 0 0 8px;
}

.btn-group .btn:last-child {
    border-radius: 0 8px 8px 0;
    border-right: none;
}

/* ============================================
   News Section
   ============================================ */

.news-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1.5rem;
}

.news-card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 12px;
    overflow: hidden;
    transition: transform 0.3s ease, border-color 0.3s ease;
}

.news-card:hover {
    transform: translateY(-3px);
    border-color: var(--base-mid);
}

.news-card-img {
    width: 100%;
    height: 180px;
    object-fit: cover;
    background: var(--base-dark);
}

.news-card-body {
    padding: 1.25rem;
}

.news-card-body h3 {
    font-size: 1.1rem;
    margin-bottom: 0.5rem;
    line-height: 1.3;
}

.news-card-body p {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-bottom: 1rem;
}

/* Lightbox overlay */
.lightbox-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.9);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: zoom-out;
}

.lightbox-img {
    max-width: 90vw;
    max-height: 90vh;
    object-fit: contain;
    border-radius: 8px;
    user-select: none;
    -webkit-user-drag: none;
}

/* ============================================
   Research Section
   ============================================ */

.research-section {
    background: var(--base-darkest);
    position: relative;
}

.research-section::before {
    content: '';
    position: absolute;
    inset: 0;
    background: url('../img/MTN2.jpg') center/cover no-repeat;
    opacity: 0.25;
    pointer-events: none;
}

/* Timeline layout */
.timeline {
    max-width: 1200px;
    margin: 0 auto;
    position: relative;
    padding-left: 80px;
}

.timeline::before {
    content: '';
    position: absolute;
    left: 60px;
    top: 0;
    bottom: 0;
    width: 2px;
    background: var(--card-border);
}

.timeline-item {
    position: relative;
    margin-bottom: 1.5rem;
}

.timeline-item::before {
    content: '';
    position: absolute;
    left: -24px;
    top: 1.4rem;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--accent);
    border: 2px solid var(--base-darkest);
    z-index: 1;
}

.timeline-year {
    position: absolute;
    left: -80px;
    top: 1.1rem;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--accent-light);
    width: 15px;
    text-align: right;
}

.timeline-card {
    background: #071907;
    border: 1px solid var(--card-border);
    border-radius: 12px;
    padding: 1.25rem 1.5rem;
    transition: border-color 0.3s ease;
}

.timeline-card:hover {
    border-color: var(--accent);
}

.timeline-citation {
    font-size: 0.95rem;
    color: var(--text-muted);
    line-height: 1.6;
    margin-bottom: 0.5rem;
}

.timeline-citation strong {
    color: var(--text);
    font-weight: 600;
}

.timeline-citation em {
    font-style: italic;
}

.research-doi {
    font-size: 0.85rem;
    color: var(--accent-light);
}

.research-badges {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.5rem;
    align-items: center;
}

/* ============================================
   Contact Section
   ============================================ */

.contact-section {
    background: var(--base-dark);
    text-align: center;
}

.contact-email {
    font-size: 1.2rem;
    margin-bottom: 2rem;
}

.contact-email a {
    color: var(--accent-light);
    font-weight: 500;
}

.social-links {
    display: flex;
    justify-content: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.social-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    color: var(--text);
    font-size: 1.2rem;
    transition: all 0.25s ease;
}

.social-link:hover {
    border-color: var(--accent);
    color: var(--accent-light);
    transform: translateY(-2px);
}

.social-link img {
    width: 20px;
    height: 20px;
    filter: invert(90%);
    transition: filter 0.25s ease;
}

.social-link:hover img {
    filter: invert(70%) sepia(50%) saturate(500%) hue-rotate(280deg);
}

/* ============================================
   Footer
   ============================================ */

.site-footer {
    padding: 2rem;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.85rem;
    border-top: 1px solid var(--card-border);
}

/* ============================================
   Section reveal animation
   ============================================ */

.reveal {
    opacity: 0;
    transform: translateY(30px);
    transition: opacity 0.8s ease, transform 0.8s ease;
}

.reveal.visible {
    opacity: 1;
    transform: translateY(0);
}

/* ============================================
   Responsive
   ============================================ */

@media (orientation: portrait) {
    .about-section {
        margin-top: -80vh;
        margin-top: -80dvh;
    }

    .tree-viewport {
        overflow: visible;
    }

    .tree-text-right {
        order: 3;
        margin-top: 15vh;
        margin-top: 15dvh;
    }
}

@media (max-width: 900px) {
    .tree-layout {
        flex-direction: column;
        gap: 1.5rem;
        padding: 5rem 1.5rem 2rem;
    }

    .tree-text-left,
    .tree-text-right {
        max-width: 100%;
        text-align: center;
    }

    .tree-text-left h1 {
        font-size: 2rem;
    }

    .tree-canvas {
        width: min(320px, 85vw);
    }
}

@media (max-width: 768px) {
    /* Keep nav above the sticky tree viewport on mobile */
    .site-nav {
        z-index: 1100;
        background: rgba(10, 31, 10, 1);
    }

    /* Downsize tree + hero text ~25% for mobile screens */
    .tree-canvas {
        width: min(240px, 64vw);
    }

    .tree-text-left h1 {
        font-size: 1.5rem;
    }

    .tree-text-left p,
    .tree-text-right p {
        font-size: 0.8rem;
    }

    .tree-layout {
        gap: 1rem;
        padding: 4rem 1rem 2rem;
    }

    .nav-container {
        padding: 0 1rem;
    }

    .nav-links {
        display: none;
        position: absolute;
        top: 64px;
        left: 0;
        right: 0;
        background: rgba(10, 31, 10, 0.97);
        flex-direction: column;
        padding: 1rem;
        border-bottom: 1px solid var(--card-border);
    }

    .nav-links.open {
        display: flex;
    }

    .nav-toggle {
        display: block;
        flex-shrink: 0;
    }

    .section {
        padding: 4rem 1.25rem;
    }

    .section-heading {
        font-size: 1.8rem;
    }

    .projects-grid,
    .news-grid {
        grid-template-columns: 1fr;
    }

    .timeline {
        padding-left: 60px;
    }

    .timeline::before {
        left: 40px;
    }

    .timeline-year {
        left: -60px;
    }

    .timeline-item::before {
        left: -24px;
    }

    .cv-iframe-wrapper {
        height: 250px;
    }
}
