html, body {
    max-width: 100%;
    overflow-x: hidden;
}

.lab-shell,
.experiment-wrapper,
.research-wrapper,
.case-wrapper {
    width: min(1120px, 100%);
    padding-inline: clamp(4px, 1.2vw, 12px);
}

.theme-toggle-button {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    border: 1px solid #1a1a1a;
    background: #e3e4e2;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    cursor: pointer;
    margin-right: 24px;
}

.theme-toggle-button img {
    width: 28px;
    height: 28px;
}

.theme-toggle-button:focus-visible {
    outline: 2px solid #000000;
    outline-offset: 3px;
}

body.dark-mode {
    color-scheme: dark;
    background: linear-gradient(180deg, #0f141b 0%, #121923 55%, #0e141e 100%);
    color: #c9d4e5;
}

body.dark-mode .lab-label,
body.dark-mode .experiment-label,
body.dark-mode .research-label,
body.dark-mode .case-label,
body.dark-mode .meta-heading,
body.dark-mode .experiment-content h3,
body.dark-mode .research-content h3,
body.dark-mode .case-content h3 {
    color: #a9b7cc;
}

body.dark-mode .lab-title,
body.dark-mode .experiment-header h1,
body.dark-mode .research-header h1,
body.dark-mode .case-header h1,
body.dark-mode .experiment-content h2,
body.dark-mode .research-content h2,
body.dark-mode .case-content h2 {
    color: #e5eefc;
}

body.dark-mode .lab-subtitle,
body.dark-mode .experiment-summary,
body.dark-mode .research-summary,
body.dark-mode .case-summary,
body.dark-mode .experiment-content p,
body.dark-mode .experiment-content li,
body.dark-mode .research-content p,
body.dark-mode .research-content li,
body.dark-mode .case-content p,
body.dark-mode .case-content li,
body.dark-mode .experiment-meta p,
body.dark-mode .research-meta p,
body.dark-mode .case-meta p {
    color: #c9d4e5;
}

body.dark-mode .lab-header,
body.dark-mode .experiment-header,
body.dark-mode .research-header,
body.dark-mode .case-header,
body.dark-mode .experiment-meta,
body.dark-mode .research-meta,
body.dark-mode .case-meta,
body.dark-mode .experiment-content section + section,
body.dark-mode .research-content section + section,
body.dark-mode .case-content section + section {
    border-color: rgba(144, 159, 182, 0.45);
}

body.dark-mode .experiment-content code,
body.dark-mode .research-content code,
body.dark-mode .case-content code {
    color: #e5eefc;
    background: #1a2432;
    border-color: rgba(144, 159, 182, 0.45);
}

body.dark-mode .lab-link,
body.dark-mode .case-link,
body.dark-mode .back-link {
    border-color: #9fb3d4;
    background: #172130;
    color: #d6e2f7;
}

body.dark-mode .lab-link:hover,
body.dark-mode .lab-link:focus-visible,
body.dark-mode .case-link:hover,
body.dark-mode .case-link:focus-visible,
body.dark-mode .back-link:hover,
body.dark-mode .back-link:focus-visible {
    background: #243247;
    color: #eff6ff;
}

body.dark-mode .site-footer {
    color: #9eb0c9;
}

body.dark-mode .site-footer a {
    color: #d3e1f7;
}

body.dark-mode .theme-toggle-button {
    background: #172130;
    border-color: #8fa6ca;
}

.experiment-content h3,
.research-content h3,
.case-content h3 {
    font-size: clamp(1.08rem, 1.9vw, 1.26rem);
    letter-spacing: 1.2px;
}

.writeup-gallery {
    margin-top: 16px;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 12px;
}

.gallery-thumb {
    border: 1px solid #a3a3a3;
    border-radius: 10px;
    background: #f1f2ef;
    padding: 8px;
    cursor: pointer;
    text-align: left;
    position: relative;
    z-index: 1;
    transition: transform 0.25s ease, box-shadow 0.25s ease;
}

.gallery-thumb img {
    width: 100%;
    height: 160px;
    object-fit: cover;
    border-radius: 8px;
    display: block;
    transition: filter 0.25s ease;
}

.gallery-thumb:hover,
.gallery-thumb:focus-visible {
    transform: scale(2.05);
    z-index: 24;
    box-shadow: 0 30px 62px rgba(0, 0, 0, 0.56);
}

.gallery-thumb:hover img,
.gallery-thumb:focus-visible img {
    filter: saturate(1.06) contrast(1.02);
}

@media (hover: none) {
    .gallery-thumb:hover,
    .gallery-thumb:focus-visible {
        transform: none;
        box-shadow: none;
    }
}

.gallery-thumb span {
    display: block;
    margin-top: 7px;
    font-family: 'ShareTechMono', 'Courier New', monospace;
    font-size: 0.78rem;
    color: #202020;
    letter-spacing: 0.6px;
}

.gallery-lightbox {
    position: fixed;
    inset: 0;
    z-index: 120;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.9);
    padding: 22px 56px;
}

.gallery-lightbox.is-open {
    display: flex;
}

.gallery-lightbox-image {
    max-width: min(94vw, 1400px);
    max-height: 86vh;
    width: auto;
    height: auto;
    object-fit: contain;
    border-radius: 10px;
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.45);
}

.gallery-lightbox-close,
.gallery-lightbox-prev,
.gallery-lightbox-next {
    position: fixed;
    border: 1px solid rgba(255, 255, 255, 0.52);
    background: rgba(20, 20, 20, 0.72);
    color: #ffffff;
    cursor: pointer;
    border-radius: 999px;
    width: 48px;
    height: 48px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.35rem;
    line-height: 1;
}

.gallery-lightbox-close {
    top: 18px;
    right: 18px;
    font-size: 1.1rem;
}

.gallery-lightbox-prev {
    left: 16px;
    top: 50%;
    transform: translateY(-50%);
}

.gallery-lightbox-next {
    right: 16px;
    top: 50%;
    transform: translateY(-50%);
}

.gallery-lightbox-caption {
    position: fixed;
    left: 50%;
    transform: translateX(-50%);
    bottom: 16px;
    color: #ebedf2;
    font-family: 'ShareTechMono', 'Courier New', monospace;
    font-size: 0.85rem;
    letter-spacing: 0.8px;
    text-align: center;
    max-width: calc(100vw - 28px);
}

body.dark-mode .gallery-thumb {
    background: #1b2431;
    border-color: #7288ab;
}

body.dark-mode .gallery-thumb span {
    color: #d2deef;
}
