html,
body {
    width: 100%;
    height: 100%;
}

body {
    margin: 0;
    overflow: hidden;
    background: #b8bec2;
    color: #252a2e;
    font-family: "Microsoft YaHei", Arial, sans-serif;
    letter-spacing: 0;
}

button {
    font: inherit;
    letter-spacing: 0;
}

noscript {
    display: block;
    padding: 100px 24px 0;
    text-align: center;
    font-size: 18px;
}

#v3d-container {
    position: absolute;
    inset: 0;
    overflow: hidden;
    isolation: isolate;
    background: linear-gradient(180deg, #d1d5d8 0%, #c2c7ca 54%, #abb2b7 100%);
}

#v3d-container::before {
    position: absolute;
    z-index: 0;
    inset: 0;
    content: "";
    pointer-events: none;
    background: linear-gradient(108deg, rgba(255, 255, 255, 0.1), transparent 44%, rgba(65, 73, 79, 0.08));
}

#v3d-container canvas {
    position: relative;
    z-index: 1;
    touch-action: none;
}

.fullscreen-button {
    position: absolute;
    z-index: 6;
    top: max(12px, env(safe-area-inset-top));
    right: max(12px, env(safe-area-inset-right));
    width: 40px;
    height: 40px;
    cursor: pointer;
    opacity: 0.74;
}

.fullscreen-button:hover {
    opacity: 1;
}

.fullscreen-open::before,
.fullscreen-close::before {
    position: absolute;
    inset: 9px;
    content: "";
    border: 2px solid rgba(45, 51, 56, 0.82);
}

.fullscreen-open::before {
    clip-path: polygon(0 0, 42% 0, 42% 12%, 12% 12%, 12% 42%, 0 42%, 0 0, 100% 0, 100% 42%, 88% 42%, 88% 12%, 58% 12%, 58% 0, 100% 0, 100% 100%, 58% 100%, 58% 88%, 88% 88%, 88% 58%, 100% 58%, 100% 100%, 0 100%, 0 58%, 12% 58%, 12% 88%, 42% 88%, 42% 100%, 0 100%);
}

.fullscreen-close::before {
    clip-path: polygon(0 30%, 30% 30%, 30% 0, 42% 0, 42% 42%, 0 42%, 0 30%, 100% 30%, 100% 42%, 58% 42%, 58% 0, 70% 0, 70% 30%, 100% 30%, 100% 70%, 70% 70%, 70% 100%, 58% 100%, 58% 58%, 100% 58%, 100% 70%, 0 70%, 0 58%, 42% 58%, 42% 100%, 30% 100%, 30% 70%, 0 70%);
}

#builder-ui {
    position: absolute;
    z-index: 5;
    inset: 0;
    pointer-events: none;
    opacity: 1;
    transition: opacity 180ms ease;
}

.is-loading #builder-ui {
    opacity: 0;
    pointer-events: none;
}

.utility-bar {
    position: absolute;
    top: max(12px, env(safe-area-inset-top));
    left: max(12px, env(safe-area-inset-left));
    display: flex;
    align-items: center;
    gap: 8px;
    pointer-events: auto;
}

.icon-button {
    display: grid;
    width: 44px;
    height: 44px;
    padding: 0;
    place-items: center;
    border: 1px solid rgba(50, 57, 62, 0.14);
    border-radius: 8px;
    color: #343a3f;
    background: rgba(240, 242, 243, 0.84);
    cursor: pointer;
}

.icon-button span {
    font-family: Arial, sans-serif;
    font-size: 26px;
    line-height: 1;
}

.icon-button:hover:not(:disabled),
.icon-button:focus-visible {
    border-color: rgba(50, 57, 62, 0.34);
    background: rgba(250, 251, 251, 0.96);
}

.icon-button:disabled {
    opacity: 0.34;
    cursor: default;
}

.danger-button {
    color: #b23c3c;
}

.is-hidden {
    display: none !important;
}

#piece-count {
    min-width: 92px;
    height: 42px;
    padding: 0 12px;
    border: 1px solid rgba(50, 57, 62, 0.1);
    border-radius: 8px;
    background: rgba(240, 242, 243, 0.74);
    font-size: 15px;
    font-weight: 600;
    line-height: 42px;
    text-align: center;
    white-space: nowrap;
}

.part-tray {
    position: absolute;
    left: 50%;
    bottom: max(14px, env(safe-area-inset-bottom));
    display: grid;
    grid-template-columns: repeat(3, minmax(82px, 112px));
    grid-template-rows: 44px 54px;
    gap: 8px;
    padding: 8px;
    transform: translateX(-50%);
    border: 1px solid rgba(49, 56, 61, 0.13);
    border-radius: 8px;
    background: rgba(237, 239, 240, 0.88);
    backdrop-filter: blur(10px);
    pointer-events: auto;
}

.ball-color-picker {
    grid-column: 1 / -1;
    display: flex;
    height: 44px;
    align-items: center;
    justify-content: center;
    gap: 4px;
}

.ball-color-picker button {
    position: relative;
    display: grid;
    width: 44px;
    height: 44px;
    padding: 0;
    place-items: center;
    border: 0;
    border-radius: 50%;
    background: transparent;
    cursor: pointer;
}

.ball-color-picker button span {
    display: block;
    width: 17px;
    height: 17px;
    border: 2px solid rgba(255, 255, 255, 0.84);
    border-radius: 50%;
    background: var(--swatch);
}

.ball-color-picker button::after {
    position: absolute;
    inset: 7px;
    content: "";
    border: 2px solid transparent;
    border-radius: 50%;
}

.ball-color-picker button:hover::after,
.ball-color-picker button:focus-visible::after {
    border-color: rgba(48, 55, 60, 0.24);
}

.ball-color-picker button.is-active::after {
    border-color: rgba(40, 47, 52, 0.78);
}

.part-button {
    display: grid;
    grid-template-columns: 32px 1fr;
    align-items: center;
    min-width: 0;
    height: 54px;
    padding: 0 10px;
    border: 1px solid rgba(45, 52, 57, 0.12);
    border-radius: 7px;
    color: #30363b;
    background: rgba(255, 255, 255, 0.68);
    cursor: grab;
    touch-action: none;
    user-select: none;
}

.part-button:hover:not(:disabled),
.part-button.is-dragging,
.part-button.is-selected {
    border-color: rgba(45, 52, 57, 0.35);
    background: #fff;
}

.part-button.is-selected {
    box-shadow: inset 0 -3px 0 #2ca76e;
}

.part-button:active:not(:disabled) {
    cursor: grabbing;
}

.part-button:disabled {
    opacity: 0.34;
    cursor: default;
}

.part-button > span:last-child {
    overflow: hidden;
    font-size: 15px;
    font-weight: 600;
    text-align: left;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.part-symbol,
.avatar-symbol {
    position: relative;
    display: block;
    width: 26px;
    height: 26px;
}

.rod-symbol::before,
#drag-avatar.is-short .avatar-symbol::before,
#drag-avatar.is-long .avatar-symbol::before {
    position: absolute;
    top: 11px;
    left: 2px;
    height: 5px;
    content: "";
    border-radius: 3px;
}

.part-short .rod-symbol::before,
#drag-avatar.is-short .avatar-symbol::before {
    width: 18px;
    background: #394fe0;
}

.part-long .rod-symbol::before,
#drag-avatar.is-long .avatar-symbol::before {
    width: 25px;
    background: #39a53f;
}

.ball-symbol::before,
#drag-avatar.is-ball .avatar-symbol::before {
    position: absolute;
    inset: 3px;
    content: "";
    border-radius: 50%;
    background: var(--active-ball-color, #9b7cff);
}

.ball-symbol::after,
#drag-avatar.is-ball .avatar-symbol::after {
    position: absolute;
    top: 9px;
    left: 9px;
    width: 8px;
    height: 8px;
    content: "";
    border: 2px solid rgba(255, 255, 255, 0.86);
    border-radius: 50%;
}

#drag-avatar {
    position: fixed;
    z-index: 20;
    display: none;
    grid-template-columns: 28px auto;
    align-items: center;
    gap: 6px;
    min-width: 72px;
    height: 42px;
    padding: 0 10px;
    transform: translate(14px, -21px);
    border: 1px solid rgba(39, 45, 50, 0.22);
    border-radius: 8px;
    color: #2e3439;
    background: rgba(255, 255, 255, 0.94);
    font-size: 14px;
    font-weight: 600;
    pointer-events: none;
}

#drag-avatar.is-visible {
    display: grid;
}

.more-menu {
    position: absolute;
    z-index: 8;
    top: max(64px, calc(env(safe-area-inset-top) + 64px));
    left: max(12px, env(safe-area-inset-left));
    display: grid;
    width: 136px;
    padding: 6px;
    gap: 4px;
    border: 1px solid rgba(49, 56, 61, 0.14);
    border-radius: 8px;
    background: rgba(247, 248, 248, 0.96);
    pointer-events: auto;
}

.more-menu button,
.save-slot > button {
    min-height: 42px;
    border: 0;
    border-radius: 6px;
    color: #30363b;
    background: transparent;
    cursor: pointer;
}

.more-menu button {
    text-align: left;
    padding: 0 12px;
}

.more-menu button:hover,
.save-slot > button:hover:not(:disabled) {
    background: rgba(55, 64, 70, 0.08);
}

.context-tools {
    position: absolute;
    z-index: 7;
    top: max(70px, calc(env(safe-area-inset-top) + 70px));
    left: 50%;
    display: flex;
    gap: 7px;
    padding: 6px;
    transform: translateX(-50%);
    border: 1px solid rgba(49, 56, 61, 0.13);
    border-radius: 8px;
    background: rgba(241, 243, 244, 0.9);
    backdrop-filter: blur(8px);
    pointer-events: auto;
}

.context-tools .icon-button {
    width: 42px;
    height: 42px;
}

.modal-layer {
    position: absolute;
    z-index: 30;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 16px;
    box-sizing: border-box;
    background: rgba(56, 62, 67, 0.24);
    backdrop-filter: blur(8px);
}

.modal-panel {
    width: min(420px, 100%);
    max-height: min(560px, calc(100vh - 32px));
    overflow-y: auto;
    border: 1px solid rgba(45, 52, 57, 0.14);
    border-radius: 8px;
    background: rgba(249, 250, 250, 0.98);
}

.modal-heading {
    display: flex;
    min-height: 60px;
    padding: 0 10px 0 18px;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid rgba(45, 52, 57, 0.1);
}

.modal-heading h2 {
    margin: 0;
    font-size: 20px;
    line-height: 1.4;
}

.modal-close.icon-button {
    border-color: transparent;
    background: transparent;
}

.save-slots {
    display: grid;
    padding: 8px 16px 16px;
}

.save-slot {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 64px 64px;
    gap: 6px;
    min-height: 64px;
    align-items: center;
    border-bottom: 1px solid rgba(45, 52, 57, 0.09);
}

.save-slot > div {
    display: grid;
    gap: 3px;
    min-width: 0;
}

.save-slot strong,
.challenge-list strong {
    font-size: 16px;
}

.save-slot small,
.challenge-list small {
    color: #697177;
    font-size: 13px;
}

.save-slot > button {
    border: 1px solid rgba(45, 52, 57, 0.12);
    background: rgba(255, 255, 255, 0.72);
}

.save-slot > button:disabled {
    opacity: 0.35;
    cursor: default;
}

.challenge-list {
    display: grid;
    gap: 6px;
    padding: 12px;
}

.challenge-list > button {
    display: grid;
    grid-template-columns: 46px 1fr;
    min-height: 62px;
    padding: 7px 10px;
    align-items: center;
    border: 1px solid rgba(45, 52, 57, 0.11);
    border-radius: 7px;
    color: #30363b;
    background: rgba(255, 255, 255, 0.68);
    text-align: left;
    cursor: pointer;
}

.challenge-list > button:hover {
    border-color: rgba(44, 167, 110, 0.42);
    background: #fff;
}

.challenge-list > button > span:last-child {
    display: grid;
    gap: 3px;
}

.challenge-mark {
    display: grid;
    width: 34px;
    height: 34px;
    place-items: center;
    border-radius: 50%;
    color: #fff;
    background: #56616a;
    font-family: Arial, sans-serif;
    font-weight: 700;
}

.challenge-complete {
    position: absolute;
    z-index: 25;
    top: 50%;
    left: 50%;
    display: grid;
    width: 70px;
    height: 70px;
    place-items: center;
    transform: translate(-50%, -50%) scale(0.7);
    border: 3px solid rgba(35, 158, 98, 0.82);
    border-radius: 50%;
    color: #219d62;
    background: rgba(246, 250, 248, 0.92);
    font-family: Arial, sans-serif;
    font-size: 42px;
    opacity: 0;
    pointer-events: none;
}

.challenge-complete.is-visible {
    transform: translate(-50%, -50%) scale(1);
    opacity: 1;
    transition: opacity 160ms ease, transform 220ms ease;
}

@media (max-width: 640px) {
    .utility-bar {
        gap: 6px;
    }

    .icon-button {
        width: 42px;
        height: 42px;
    }

    #piece-count {
        min-width: 68px;
        padding: 0 8px;
        font-size: 13px;
    }

    .utility-bar .icon-button {
        width: 40px;
        height: 42px;
    }

    .utility-bar .icon-button span {
        font-size: 24px;
    }

    .part-tray {
        width: calc(100% - 28px);
        box-sizing: border-box;
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .part-button {
        grid-template-columns: 28px minmax(0, 1fr);
        height: 52px;
        padding: 0 7px;
    }

    .part-button > span:last-child {
        font-size: 14px;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        transition-duration: 0.01ms !important;
        animation-duration: 0.01ms !important;
    }
}
