/**
 * CSS 3D DICE SYSTEM
 * 
 * Creates 3D dice using CSS transforms
 * Starting with d6 (cube) for Crimson Valor theme
 * 
 * Architecture:
 * - .dice-3d: Container with perspective
 * - .dice-cube: The 3D cube itself
 * - .dice-face: Each of 6 faces (1-6)
 * 
 * Date: October 15, 2025
 */

/* ═══════════════════════════════════════════════════════════════
   3D DICE CONTAINER
   ═══════════════════════════════════════════════════════════════ */

.dice-3d-container {
  perspective: 1000px;
  perspective-origin: center center;
  display: inline-block;
  margin: 20px;
}

/* ═══════════════════════════════════════════════════════════════
   D6 CUBE - BASIC 3D DIE
   ═══════════════════════════════════════════════════════════════ */

.dice-cube {
  width: 80px;
  height: 80px;
  position: relative;
  transform-style: preserve-3d;
  transform: rotateX(-20deg) rotateY(-20deg);
  transition: transform 0.6s ease-out;
  cursor: pointer;
}

/* Add subtle animation on hover */
.dice-cube:hover {
  transform: rotateX(-25deg) rotateY(-25deg) scale(1.05);
}

/* ═══════════════════════════════════════════════════════════════
   DICE FACES - 6 SIDES OF CUBE
   ═══════════════════════════════════════════════════════════════ */

.dice-face {
  position: absolute;
  width: 80px;
  height: 80px;
  background: linear-gradient(
    135deg,
    rgba(248, 113, 113, 0.95) 0%,
    /* Crimson dice color */ rgba(220, 38, 38, 0.95) 100%
      /* Crimson damage color */
  );
  border: 2px solid rgba(248, 113, 113, 0.6);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
  font-weight: bold;
  color: rgba(255, 255, 255, 0.95);
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5), 0 0 10px rgba(248, 113, 113, 0.4);
  box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.3), 0 4px 12px rgba(0, 0, 0, 0.4);
  backface-visibility: hidden;
}

/* Individual face positions using 3D transforms */

/* Face 1 - Front */
.dice-face-1 {
  transform: translateZ(40px);
}

/* Face 2 - Back */
.dice-face-2 {
  transform: rotateY(180deg) translateZ(40px);
}

/* Face 3 - Right */
.dice-face-3 {
  transform: rotateY(90deg) translateZ(40px);
}

/* Face 4 - Left */
.dice-face-4 {
  transform: rotateY(-90deg) translateZ(40px);
}

/* Face 5 - Top */
.dice-face-5 {
  transform: rotateX(90deg) translateZ(40px);
}

/* Face 6 - Bottom */
.dice-face-6 {
  transform: rotateX(-90deg) translateZ(40px);
}

/* ═══════════════════════════════════════════════════════════════
   DICE PIPS (DOTS) - ALTERNATIVE TO NUMBERS
   ═══════════════════════════════════════════════════════════════ */

.dice-pips {
  display: grid;
  padding: 10px;
  width: 100%;
  height: 100%;
  gap: 8px;
}

/* Pip layout grids for each face */
.dice-pips.pips-1 {
  grid-template-areas: "... ... ..." "... pip ..." "... ... ...";
  grid-template-columns: 1fr 1fr 1fr;
  grid-template-rows: 1fr 1fr 1fr;
}

.dice-pips.pips-2 {
  grid-template-areas: "pip ... ..." "... ... ..." "... ... pip";
  grid-template-columns: 1fr 1fr 1fr;
  grid-template-rows: 1fr 1fr 1fr;
}

.dice-pips.pips-3 {
  grid-template-areas: "pip ... ..." "... pip ..." "... ... pip";
  grid-template-columns: 1fr 1fr 1fr;
  grid-template-rows: 1fr 1fr 1fr;
}

.dice-pips.pips-4 {
  grid-template-areas: "pip ... pip" "... ... ..." "pip ... pip";
  grid-template-columns: 1fr 1fr 1fr;
  grid-template-rows: 1fr 1fr 1fr;
}

.dice-pips.pips-5 {
  grid-template-areas: "pip ... pip" "... pip ..." "pip ... pip";
  grid-template-columns: 1fr 1fr 1fr;
  grid-template-rows: 1fr 1fr 1fr;
}

.dice-pips.pips-6 {
  grid-template-areas: "pip ... pip" "pip ... pip" "pip ... pip";
  grid-template-columns: 1fr 1fr 1fr;
  grid-template-rows: 1fr 1fr 1fr;
}

.dice-pip {
  grid-area: pip;
  width: 12px;
  height: 12px;
  background: rgba(255, 255, 255, 0.95);
  border-radius: 50%;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.5),
    inset 0 1px 2px rgba(255, 255, 255, 0.3);
}

/* ═══════════════════════════════════════════════════════════════
   DICE ANIMATIONS
   ═══════════════════════════════════════════════════════════════ */

/* Idle rotation animation */
@keyframes dice-idle-spin {
  0% {
    transform: rotateX(-20deg) rotateY(-20deg);
  }
  50% {
    transform: rotateX(-20deg) rotateY(20deg);
  }
  100% {
    transform: rotateX(-20deg) rotateY(-20deg);
  }
}

.dice-cube.idle-spin {
  animation: dice-idle-spin 4s ease-in-out infinite;
}

/* Rolling animation (for later) */
@keyframes dice-roll {
  0% {
    transform: translateY(0) rotateX(0) rotateY(0);
  }
  25% {
    transform: translateY(-200px) rotateX(360deg) rotateY(180deg);
  }
  50% {
    transform: translateY(-100px) rotateX(720deg) rotateY(360deg);
  }
  75% {
    transform: translateY(-50px) rotateX(1080deg) rotateY(540deg);
  }
  100% {
    transform: translateY(0) rotateX(1440deg) rotateY(720deg);
  }
}

.dice-cube.rolling {
  animation: dice-roll 2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ═══════════════════════════════════════════════════════════════
   ROLL DICE BUTTON
   ═══════════════════════════════════════════════════════════════ */

.roll-dice-button {
  position: fixed;
  bottom: 100px;
  right: 40px;
  padding: 16px 32px;
  background: linear-gradient(
    135deg,
    rgba(248, 113, 113, 0.2) 0%,
    rgba(220, 38, 38, 0.2) 100%
  );
  backdrop-filter: blur(16px);
  border: 2px solid rgba(248, 113, 113, 0.4);
  border-radius: 16px;
  color: rgba(248, 113, 113, 1);
  font-size: 18px;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3),
    inset 0 1px 0 rgba(255, 255, 255, 0.1);
  display: none; /* Hidden by default */
  z-index: 1000;
}

.roll-dice-button.visible {
  display: flex;
  align-items: center;
  gap: 12px;
}

.roll-dice-button:hover {
  background: linear-gradient(
    135deg,
    rgba(248, 113, 113, 0.3) 0%,
    rgba(220, 38, 38, 0.3) 100%
  );
  border-color: rgba(248, 113, 113, 0.6);
  transform: translateY(-2px);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.4),
    inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

.roll-dice-button:active {
  transform: translateY(0);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3),
    inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

/* Small dice icon next to button */
.roll-dice-button .dice-cube {
  width: 40px;
  height: 40px;
}

.roll-dice-button .dice-face {
  width: 40px;
  height: 40px;
  font-size: 20px;
  border-radius: 4px;
}

/* ═══════════════════════════════════════════════════════════════
   DICE RESULT DISPLAY
   ═══════════════════════════════════════════════════════════════ */

.dice-result {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 120px;
  font-weight: bold;
  color: rgba(248, 113, 113, 1);
  text-shadow: 0 4px 12px rgba(0, 0, 0, 0.5), 0 0 40px rgba(248, 113, 113, 0.6);
  opacity: 0;
  pointer-events: none;
  z-index: 2000;
  transition: opacity 0.3s ease-out;
}

.dice-result.visible {
  opacity: 1;
  animation: dice-result-pop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes dice-result-pop {
  0% {
    transform: translate(-50%, -50%) scale(0.5);
  }
  100% {
    transform: translate(-50%, -50%) scale(1);
  }
}

/* ═══════════════════════════════════════════════════════════════
   RESPONSIVE - MOBILE ADJUSTMENTS
   ═══════════════════════════════════════════════════════════════ */

@media (max-width: 768px) {
  .dice-cube {
    width: 60px;
    height: 60px;
  }

  .dice-face {
    width: 60px;
    height: 60px;
    font-size: 24px;
  }

  .dice-face-1,
  .dice-face-2,
  .dice-face-3,
  .dice-face-4,
  .dice-face-5,
  .dice-face-6 {
    transform: translateZ(30px);
  }

  .dice-face-2 {
    transform: rotateY(180deg) translateZ(30px);
  }
  .dice-face-3 {
    transform: rotateY(90deg) translateZ(30px);
  }
  .dice-face-4 {
    transform: rotateY(-90deg) translateZ(30px);
  }
  .dice-face-5 {
    transform: rotateX(90deg) translateZ(30px);
  }
  .dice-face-6 {
    transform: rotateX(-90deg) translateZ(30px);
  }

  .roll-dice-button {
    bottom: 80px;
    right: 20px;
    padding: 12px 24px;
    font-size: 16px;
  }
}

/* ═══════════════════════════════════════════════════════════════
   ACCESSIBILITY - REDUCED MOTION
   ═══════════════════════════════════════════════════════════════ */

@media (prefers-reduced-motion: reduce) {
  .dice-cube {
    animation: none;
    transition: none;
  }

  .dice-cube.rolling {
    animation: none;
  }

  .dice-cube.idle-spin {
    animation: none;
  }
}

/* ═══════════════════════════════════════════════════════════════
   D20 ICOSAHEDRON - 3D ROTATING DIE
   ═══════════════════════════════════════════════════════════════ */

.d20-container {
  perspective: 1000px;
  perspective-origin: center center;
  display: inline-block;
  width: 40px;
  height: 40px;
}

.d20-die {
  width: 40px;
  height: 40px;
  position: relative;
  transform-style: preserve-3d;
  animation: d20-rotate 8s linear infinite;
}

@keyframes d20-rotate {
  0% {
    transform: rotateX(0deg) rotateY(0deg) rotateZ(0deg);
  }
  100% {
    transform: rotateX(360deg) rotateY(360deg) rotateZ(360deg);
  }
}

/* D20 simplified to octahedron for CSS (8 faces instead of 20 for performance) */
.d20-face {
  position: absolute;
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 0 20px 34.64px 20px;
  border-color: transparent transparent var(--dice) transparent;
  opacity: 0.9;
  backface-visibility: hidden;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

/* Top pyramid (4 faces) */
.d20-face:nth-child(1) {
  transform: rotateY(0deg) translateZ(15px);
}

.d20-face:nth-child(2) {
  transform: rotateY(90deg) translateZ(15px);
}

.d20-face:nth-child(3) {
  transform: rotateY(180deg) translateZ(15px);
}

.d20-face:nth-child(4) {
  transform: rotateY(270deg) translateZ(15px);
}

/* Bottom pyramid (4 faces - inverted triangles) */
.d20-face:nth-child(5) {
  border-width: 34.64px 20px 0 20px;
  border-color: var(--dice) transparent transparent transparent;
  transform: rotateY(0deg) rotateX(180deg) translateZ(15px);
}

.d20-face:nth-child(6) {
  border-width: 34.64px 20px 0 20px;
  border-color: var(--dice) transparent transparent transparent;
  transform: rotateY(90deg) rotateX(180deg) translateZ(15px);
}

.d20-face:nth-child(7) {
  border-width: 34.64px 20px 0 20px;
  border-color: var(--dice) transparent transparent transparent;
  transform: rotateY(180deg) rotateX(180deg) translateZ(15px);
}

.d20-face:nth-child(8) {
  border-width: 34.64px 20px 0 20px;
  border-color: var(--dice) transparent transparent transparent;
  transform: rotateY(270deg) rotateX(180deg) translateZ(15px);
}

/* Hover effect */
.d20-container:hover .d20-die {
  animation-play-state: paused;
  transform: rotateX(-15deg) rotateY(-15deg) scale(1.1);
}
