.tre-scene {
  --tilt-x: 0deg;
  --tilt-z: 0deg;
  position: relative;
  isolation: isolate;
  container-type: inline-size;
  overflow: hidden;
  width: 100%;
  aspect-ratio: 1.08;
  border: 1px solid #6c91e84d;
  border-radius: 28px;
  background:
    radial-gradient(ellipse at 50% 44%, #2555c579, transparent 58%),
    radial-gradient(ellipse at 75% 100%, #2d57b84a, transparent 54%),
    linear-gradient(148deg, #11274e, #08152e 72%);
  box-shadow: inset 0 1px #a5c7ff29, 0 30px 80px #020c2233;
}

.tre-scene__grid {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(#7eb0ff15 1px, transparent 1px),
    linear-gradient(90deg, #7eb0ff15 1px, transparent 1px);
  background-size: 30px 30px;
  mask-image: radial-gradient(ellipse, #000 28%, transparent 82%);
}

.tre-scene__camera {
  position: absolute;
  inset: 0;
  pointer-events: none;
  perspective: 900px;
  perspective-origin: 50% 51%;
}

.tre-scene__world {
  position: absolute;
  inset: 62% auto auto 50%;
  width: 1px;
  height: 1px;
  transform-style: preserve-3d;
  transform: rotateX(calc(59deg + var(--tilt-x))) rotateZ(calc(-35deg + var(--tilt-z)));
  transition: transform 320ms cubic-bezier(.2, .65, .3, 1);
}

.tre-scene__part {
  --top: #aac7f8;
  --north: #5684d2;
  --south: #5681c9;
  --east: #234e9b;
  --west: #3c69bb;
  --bottom: #183975;
  --joint: #a3c8ff59;
  position: absolute;
  top: 0;
  left: 0;
  width: var(--width);
  height: var(--depth);
  transform-style: preserve-3d;
  transform: translate3d(var(--x), var(--y), var(--z)) translate(-50%, -50%) rotateY(var(--angle));
}

.tre-scene__face {
  position: absolute;
  display: block;
  backface-visibility: hidden;
  box-shadow: inset 0 0 0 .5px var(--joint);
}

.tre-scene__face--top,
.tre-scene__face--bottom { inset: 0; }
.tre-scene__face--top {
  background: var(--top);
  transform: translateZ(calc(var(--height) / 2));
}
.tre-scene__face--bottom {
  background: var(--bottom);
  transform: translateZ(calc(var(--height) / -2)) rotateX(180deg);
}

.tre-scene__face--north,
.tre-scene__face--south {
  inset: 50% 0 auto;
  height: var(--height);
}
.tre-scene__face--north {
  background: var(--north);
  transform: translateY(calc(-50% - var(--depth) / 2)) rotateX(90deg);
}
.tre-scene__face--south {
  background: var(--south);
  transform: translateY(calc(-50% + var(--depth) / 2)) rotateX(-90deg);
}

.tre-scene__face--west,
.tre-scene__face--east {
  inset: 0 auto 0 50%;
  width: var(--height);
}
.tre-scene__face--west {
  background: var(--west);
  transform: translateX(calc(-50% - var(--width) / 2)) rotateY(-90deg);
}
.tre-scene__face--east {
  background: var(--east);
  transform: translateX(calc(-50% + var(--width) / 2)) rotateY(90deg);
}

.tre-scene__part--base {
  --top: #153467;
  --north: #1c4382;
  --south: linear-gradient(#1a438a, #102b59);
  --east: linear-gradient(#183976, #102450);
  --west: #1c3d76;
  --joint: #528fff8c;
}
.tre-scene__part--ground {
  --top:
    repeating-linear-gradient(90deg, transparent 0 2.95cqw, #77a9f331 2.95cqw 3.12cqw),
    repeating-linear-gradient(0deg, transparent 0 2.95cqw, #77a9f331 2.95cqw 3.12cqw),
    radial-gradient(ellipse, #214a88, #132a51);
  --north: #4978be;
  --south: #2d5798;
  --east: #254781;
}
.tre-scene__part--foot {
  --top: #658fcf;
  --south: #366298;
  --east: #28497e;
}
.tre-scene__part--deck {
  --top:
    repeating-linear-gradient(90deg, #90b6ef48 0 1px, transparent 1px 8px),
    linear-gradient(125deg, #759de0, #446fb4);
  --south: #6489c3;
  --east: #365a98;
  --joint: #c2dbff69;
}
.tre-scene__part--bracing {
  --top: #b0cef5;
  --south: #8db3eb;
  --east: #4c77be;
}
.tre-scene__part--highlight {
  --top: linear-gradient(135deg, #b7edff, #70bafb 47%, #486dff);
  --north: #5c97ec;
  --south: #4f83df;
  --east: #3451b4;
  --joint: #ccf4ffad;
  animation: tre-scene-panel-settle 3.6s cubic-bezier(.2, .7, .26, 1) 1 both;
}

.tre-scene__frame {
  position: absolute;
  inset: 16px;
  pointer-events: none;
  background:
    linear-gradient(90deg, #b2cdff78 12px, transparent 12px) top left / 16px 1px,
    linear-gradient(0deg, #b2cdff78 12px, transparent 12px) top left / 1px 16px,
    linear-gradient(-90deg, #b2cdff78 12px, transparent 12px) bottom right / 16px 1px,
    linear-gradient(180deg, #b2cdff78 12px, transparent 12px) bottom right / 1px 16px;
  background-repeat: no-repeat;
}

@keyframes tre-scene-panel-settle {
  0% {
    transform: translate3d(var(--x), var(--y), calc(var(--z) + 7cqw)) translate(-50%, -50%) rotateY(-7deg);
  }
  100% {
    transform: translate3d(var(--x), var(--y), var(--z)) translate(-50%, -50%);
  }
}

@media (max-width: 540px) {
  .tre-scene { border-radius: 20px; }
  .tre-scene__frame { inset: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  .tre-scene__world { transform: rotateX(59deg) rotateZ(-35deg); transition: none; }
  .tre-scene__part--highlight { animation: none; }
}
