:root {
  --sand: #c0c08a;
  --blue: #0747af;
  --black: #000000;
  --burst-min: 0.1;

  /* everything scales from --s, limited by both width and height of the screen */
  --s: clamp(170px, min(46dvh, 68vw), 400px);
  /* base side */
  --h: calc(var(--s) * 1.2);
  /* pyramid height */
  --l: calc(var(--s) * 1.3);
  /* slant height of a face */

}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  height: 100%;
}

body {
  min-height: 100dvh;
  /* deep space: black with very faint nebula clouds */
  background:
    radial-gradient(ellipse 60% 45% at 15% 20%, rgba(70, 30, 140, .22), transparent 70%),
    radial-gradient(ellipse 55% 40% at 85% 75%, rgba(20, 60, 150, .22), transparent 70%),
    radial-gradient(ellipse 40% 30% at 70% 15%, rgba(140, 30, 90, .12), transparent 70%),
    #000;
  color: var(--sand);
  font-family: "Helvetica Neue", Arial, sans-serif;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* sun rays behind the pyramid */
.rays {
  position: fixed;
  inset: 0;
  background: repeating-conic-gradient(from 0deg at 50% 46%,
      rgba(192, 192, 138, .16) 0deg 1.5deg,
      transparent 1.5deg 14deg);
  -webkit-mask-image: radial-gradient(circle at 50% 46%, #000 0%, transparent 65%);
  mask-image: radial-gradient(circle at 50% 46%, #000 0%, transparent 65%);
  pointer-events: none;
}

/* 3D scene */
.scene {
  flex: 1;
  min-height: 0;
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  perspective: calc(var(--s) * 3.6);
  cursor: grab;
  touch-action: pan-y;
  user-select: none;
  -webkit-user-select: none;
  position: relative;
}

.scene.dragging {
  cursor: grabbing;
}

.pyramid {
  position: relative;
  width: var(--s);
  height: var(--h);
  transform-style: preserve-3d;
  transform: rotateX(-14deg) rotateY(0deg);
  /* fixed tilt, only Y changes */
}

.face {
  position: absolute;
  left: 0;
  bottom: 0;
  width: var(--s);
  height: var(--l);
  transform-origin: 50% 100%;
  /* lean each face inward by atan(0.5 / 1.2) = 22.62deg */
  transform:
    rotateY(calc(var(--i) * 90deg)) translateZ(calc(var(--s) / 2)) rotateX(22.62deg);
  clip-path: polygon(50% 0, 0 100%, 100% 100%);
  backface-visibility: hidden;
  background: linear-gradient(180deg, #d8d8a4 0%, var(--sand) 45%, #a3a36f 100%);
}

/* dynamic shading, opacity is set from JS */
.face::before {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--black);
  opacity: var(--shade, 0);
  pointer-events: none;
}

/* Face labels are clickable plaques; their text glows on hover/focus. */
.label {
  position: absolute;
  left: 50%;
  top: calc(var(--s) * .66);
  width: calc(var(--s) * .7);
  height: calc(var(--s) * .4);
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  justify-content: center;
  isolation: isolate;
  overflow: visible;
  padding: 0;
  gap: 0;
  border: 0;
  background: transparent !important;
  color: #db0407;
  box-shadow: none !important;
  font-family: inherit;
  font-size: calc(var(--s) * .09);
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  white-space: nowrap;
  cursor: pointer;
  text-shadow: 0 0 2px #000, 0 0 6px #000, 0 0 10px rgba(0, 0, 0, .8);
  transition: color .3s, text-shadow .3s, filter .3s;
}

/* ground shadow */
.shadow {
  position: absolute;
  top: calc(50% + var(--h) / 2 + 1vh);
  width: calc(var(--s) * 1.5);
  height: calc(var(--s) * .12);
  background: radial-gradient(ellipse, rgba(7, 71, 175, .55), transparent 70%);
  filter: blur(10px);
  pointer-events: none;
}

@media (max-height: 460px) {
  :root {
    --s: clamp(130px, 56dvh, 400px);
  }
}

/* Ribbon canvases sit behind and in front of the pyramid. */
.ribbon-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  filter: saturate(1.35) contrast(1.05) drop-shadow(0 0 6px rgba(255, 255, 255, .22));
}

/* yellow burst above the pyramid (centre sits just under the apex) */
.burst {
  position: absolute;
  left: 50%;
  top: calc(50% - var(--h) * 0.376);
  width: calc(var(--h) * 1.3);
  height: calc(var(--h) * 1.3);
  transform: translate(-50%, -50%);
  overflow: visible;
  pointer-events: none;
}

.burst line {
  stroke: #ffe81a;
  stroke-width: 7;
  filter: drop-shadow(0 0 3px rgba(255, 232, 26, .65));
  animation: twinkle 2.6s ease-in-out infinite;
}

.burst line:nth-child(1) {
  animation-delay: -0.2s;
  animation-duration: 2.4s;
}

.burst line:nth-child(2) {
  animation-delay: -1.5s;
  animation-duration: 3.1s;
}

.burst line:nth-child(3) {
  animation-delay: -0.8s;
  animation-duration: 2.8s;
}

.burst line:nth-child(4) {
  animation-delay: -2.1s;
  animation-duration: 3.4s;
}

.burst line:nth-child(5) {
  animation-delay: -1.1s;
  animation-duration: 2.2s;
}

.burst line:nth-child(6) {
  animation-delay: -2.6s;
  animation-duration: 3.0s;
}

.burst line:nth-child(7) {
  animation-delay: -0.5s;
  animation-duration: 2.7s;
}

.burst line:nth-child(8) {
  animation-delay: -1.8s;
  animation-duration: 3.3s;
}

.burst line:nth-child(9) {
  animation-delay: -2.3s;
  animation-duration: 2.5s;
}

@keyframes twinkle {

  0%,
  100% {
    stroke: #999209;
    filter: drop-shadow(0 0 2px rgba(153, 146, 9, .5));
  }

  50% {
    stroke: #fff200;
    filter: drop-shadow(0 0 10px rgba(255, 242, 0, 1));
  }
}

@media (prefers-reduced-motion: reduce) {
  .burst line {
    animation: none;
  }
}

/* ---------- click layer: faces + plaques above the ribbons ---------- */
.tags {
  position: absolute;
  left: 50%;
  top: 50%;
  width: var(--s);
  height: var(--h);
  margin: calc(var(--h) / -2) 0 0 calc(var(--s) / -2);
  transform-style: preserve-3d;
  transform: rotateX(-14deg) rotateY(0deg);
  pointer-events: none;
}

.face.tag {
  background: none;
  pointer-events: auto;
  cursor: pointer;
}

/* the whole face lights up on hover */
.face.tag::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(255, 255, 255, .28), rgba(255, 255, 255, 0) 70%);
  opacity: 0;
  transition: opacity .3s;
  pointer-events: none;
}

@media (hover: hover) {
  .face.tag:hover::after {
    opacity: 1;
  }
}

.face.tag.current .label {
  text-shadow: 0 0 2px #000, 0 0 6px #000, 0 0 12px rgba(219, 4, 7, .8);
}

.label:focus-visible,
.label:active {
  color: #ff2326;
  outline: none;
}

/* hover and click: strongest shine */
.face.tag:hover .label,
.face.tag:active .label {
  color: #ff4a4d;
  text-shadow:
    0 0 3px #fff,
    0 0 8px #ff0306,
    0 0 16px #ff0306,
    0 0 30px #ff0306,
    0 0 50px #ff0306;
  filter:
    drop-shadow(0 0 14px rgba(255, 3, 6, .95)) drop-shadow(0 0 28px rgba(255, 3, 6, .8));
}

.space {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* ---------- smoother spin ---------- */
.pyramid,
.tags {
  will-change: transform;
}

/* phones: skip the expensive full-screen filters */
@media (hover: none) and (pointer: coarse) {
  .ribbon-canvas {
    filter: none;
  }

  .burst line {
    filter: none;
  }
}
