:root {
    color-scheme: dark;
    --background: #0a0a0a;
    --accent: #00ff88;
    --character-width: min(250px, calc(13vw - 12px));
    --character-offset: clamp(12px, 2vw, 30px);
    font-family: Arial, "Microsoft YaHei", sans-serif;
    scrollbar-gutter: stable;
}

*, *::before, *::after {
    box-sizing: border-box;
}

body {
    min-height: 100vh;
    margin: 0;
    background: var(--background);
    color: #f4f4f4;
}

body:has(dialog[open]) {
    overflow: hidden;
}

button {
    font: inherit;
}

button:focus-visible, a:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 4px;
}

.site-shell {
    width: 70vw;
    margin-inline: auto;
    padding-block: clamp(2rem, 5.6vh, 3.125rem) 3rem;
}

#title {
    margin: 0;
    color: var(--accent);
    font-size: clamp(1.375rem, 3vw, 2rem);
    font-family: "Arial Black", Arial, "Microsoft YaHei", sans-serif;
    line-height: 1.12;
}

#title span {
    display: block;
    margin-top: 0.5rem;
    color: rgba(255, 255, 255, 0.8);
    font-size: clamp(2.25rem, 5vw, 4rem);
    overflow-wrap: anywhere;
}

#showreel {
    display: flex;
    align-items: center;
    min-height: 44px;
    margin-top: 0.85rem;
    padding: 0;
    border: 0;
    background: transparent;
    color: #dedede;
    text-decoration: underline;
    text-decoration-color: #666;
    text-underline-offset: 0.32em;
    cursor: pointer;
}

#showreel:hover {
    color: var(--accent);
    text-decoration-color: currentColor;
}

.gallery {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 20px;
    margin-top: clamp(2rem, 7vh, 5rem);
    scroll-margin-top: 1rem;
}

.item {
    position: relative;
    display: grid;
    aspect-ratio: 16 / 10;
    min-width: 0;
    overflow: hidden;
    padding: 0;
    border: 2px solid rgba(255, 255, 255, 0.14);
    border-radius: 10px;
    background: #191919;
    color: white;
    cursor: pointer;
    transition: border-color 0.3s, box-shadow 0.3s, transform 0.3s;
}

.item img {
    grid-area: 1 / 1;
    width: 100%;
    height: 100%;
    min-height: 0;
    object-fit: cover;
    filter: brightness(0.8);
    transition: filter 0.3s;
}

.item-title {
    z-index: 1;
    grid-area: 1 / 1;
    align-self: end;
    padding: 1.6rem 0.9rem 0.8rem;
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.9));
    font-weight: 700;
    line-height: 1.25;
    text-align: left;
    overflow-wrap: anywhere;
}

.item:focus-visible {
    border-color: var(--accent);
}

@media (hover: hover) {
    .item:hover {
        z-index: 1;
        border-color: var(--accent);
        transform: scale(1.05);
        box-shadow: 0 0 20px rgba(0, 255, 136, 0.3);
    }

    .item:hover img {
        filter: brightness(1);
    }
}

#character {
    position: fixed;
    right: var(--character-offset);
    bottom: var(--character-offset);
    display: grid;
    justify-items: center;
    width: var(--character-width);
    padding: 0;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: #fff;
    cursor: pointer;
    filter: drop-shadow(0 0 10px rgba(0, 255, 136, 0.5));
    animation: float 3s ease-in-out infinite;
}

#character img {
    display: block;
    width: 100%;
    image-rendering: pixelated;
}

.character-label {
    padding: 0.25rem 0.55rem;
    border-radius: 0.3rem;
    background: var(--background);
    font-size: 0.875rem;
}

@keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

.bubble-container {
    position: fixed;
    z-index: 2;
    right: calc(var(--character-offset) + var(--character-width) * 0.5);
    bottom: calc(var(--character-offset) + var(--character-width) * 1.35);
    width: min(240px, 66vw);
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 0.2s, transform 0.2s;
    pointer-events: none;
}

.bubble-container.is-visible {
    opacity: 1;
    transform: translateY(0);
}

.bubble {
    position: relative;
    padding: 0.9rem 1rem;
    border: 4px solid black;
    border-radius: 12px;
    background: white;
    color: black;
    font-size: 1.125rem;
    line-height: 1.4;
    overflow-wrap: anywhere;
}

.bubble::after {
    position: absolute;
    right: 1.5rem;
    bottom: -10px;
    width: 16px;
    height: 16px;
    transform: rotate(45deg);
    border-right: 4px solid black;
    border-bottom: 4px solid black;
    background: white;
    content: "";
}

.panel {
    position: fixed;
    inset: 0;
    width: min(1200px, 91vw);
    max-width: none;
    max-height: none;
    margin: auto;
    padding: 0;
    overflow: visible;
    border: 2px solid var(--accent);
    border-radius: 10px;
    background: #1a1a1a;
    color: white;
}

.panel::backdrop {
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(8px);
}

.panel-scroll {
    max-height: 80vh;
    max-height: 80dvh;
    overflow: auto;
    overscroll-behavior: contain;
    padding: 1.25rem clamp(1.25rem, 5vw, 5rem) 2.5rem;
    border-radius: inherit;
    scrollbar-gutter: stable;
}

.panel-close {
    position: sticky;
    z-index: 2;
    top: 0;
    float: right;
    display: grid;
    width: 44px;
    height: 44px;
    margin: 0 0 0.5rem 0.65rem;
    padding: 0;
    place-items: center;
    border: 2px solid white;
    border-radius: 50%;
    background: #c82e32;
    color: white;
    font-size: 1.75rem;
    line-height: 1;
    box-shadow: 0 0 15px rgba(255, 68, 68, 0.4);
    cursor: pointer;
}

.panel-close:hover {
    background: #a91924;
}

.panel-title {
    min-height: 44px;
    margin: 0 0 0.85rem;
    padding-top: 0.3rem;
    font-size: clamp(1.45rem, 3vw, 2.25rem);
    line-height: 1.2;
    overflow-wrap: anywhere;
}

.panel-content {
    clear: both;
    font-size: 1rem;
    line-height: 1.7;
    overflow-wrap: anywhere;
}

.panel-content > :first-child {
    margin-top: 0;
}

.panel-content a {
    color: var(--accent);
    text-underline-offset: 0.2em;
}

.panel-content figure {
    margin: 1.5rem 0;
}

.panel-content img, .panel-content video {
    display: block;
    max-width: 100%;
    height: auto;
    margin-inline: auto;
    border-radius: 6px;
}

.panel-content figcaption {
    margin-top: 0.5rem;
    font-size: 0.9rem;
}

.panel-content iframe {
    display: block;
    width: 100%;
    height: auto;
    aspect-ratio: 16 / 9;
    border: 0;
    border-radius: 6px;
}

.video-frame {
    margin-block: 1.5rem;
}

.project-gallery {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 15rem), 1fr));
    align-items: start;
    gap: 1rem;
    margin-block: 1.5rem;
}

.project-gallery a {
    display: block;
}

.character-panel {
    width: min(900px, 91vw);
    color-scheme: light;
    border: 6px solid black;
    border-radius: 12px;
    background: #fff;
    color: #111;
}

.character-panel .panel-content {
    font-size: clamp(1rem, 2vw, 1.2rem);
}

.character-panel .panel-content a {
    color: #00653c;
}

.character-panel :focus-visible {
    outline-color: #007548;
}

.about-content {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 2.4fr);
    align-items: start;
    gap: clamp(1rem, 3vw, 2rem);
}

.about-content .about-portrait, .about-content p:first-child {
    margin: 0;
}

.about-links {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 1.25rem;
}

@media (min-width: 1050px) {
    .character-panel::after {
        position: absolute;
        right: -18px;
        bottom: 16%;
        width: 25px;
        height: 25px;
        transform: rotate(-45deg);
        border-right: 6px solid black;
        border-bottom: 6px solid black;
        background: white;
        content: "";
    }
}

@media (max-width: 900px) {
    .site-shell {
        width: calc(100% - 3rem);
        padding-bottom: 1.25rem;
    }

    .gallery {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 16px;
        margin-top: 2rem;
    }

    #character {
        position: static;
        width: 90px;
        margin: 0.5rem 1.5rem 1.5rem auto;
    }

    .bubble-container {
        right: 4.25rem;
        bottom: 8.5rem;
    }
}

@media (max-width: 520px) {
    .site-shell {
        width: calc(100% - 2rem);
    }

    .gallery {
        grid-template-columns: minmax(0, 1fr);
    }

    .panel-scroll {
        max-height: 85vh;
        max-height: 85dvh;
        padding-inline: 1rem;
    }

    .about-content {
        grid-template-columns: minmax(0, 1fr);
    }

    .about-portrait {
        width: min(11rem, 100%);
    }
}

@media (prefers-reduced-motion: reduce) {
    #character {
        animation: none;
    }

    .item, .item img, .bubble-container {
        transition: none;
    }

    .item:hover {
        transform: none;
    }
}
