@import url("https://fonts.googleapis.com/css2?family=VT323&display=swap");

:root {
  --bg-color: #0d0f14;
  --surface: #161a22;
  --accent: #00f0ff;
  --accent-warn: #ffb020;
  --text-primary: #e6edf3;
  --text-muted: #8b949e;
  --error: #ff4d4d;
}

* {
  box-sizing: border-box; /* Prevents padding from breaking mobile layout */
}

body {
  background-color: var(--bg-color);
  color: var(--text-primary);
  font-family: "VT323", monospace;
  margin: 0;
  padding: 10px;
  padding-bottom: 20vh; /* Room below content for the floating die */
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  overflow-x: hidden;
  -webkit-font-smoothing: none; /* Keeps pixels crisp */
}

/* Extra breathing room above container */
body.activated .container {
  margin-top: 10px;
}

/* CRT Scanline Effect - Optimized for mobile performance */
body::before {
  content: " ";
  display: block;
  position: fixed; /* Fixed so it doesn't scroll away */
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
  background:
    linear-gradient(rgba(18, 16, 16, 0) 50%, rgba(0, 0, 0, 0.25) 50%),
    linear-gradient(
      90deg,
      rgba(255, 0, 0, 0.06),
      rgba(0, 255, 0, 0.02),
      rgba(0, 0, 255, 0.06)
    );
  z-index: 999;
  background-size:
    100% 2px,
    3px 100%;
  pointer-events: none; /* Lets you click through the overlay */
}

h1 {
  font-size: clamp(2.5rem, 8vw, 4rem); /* Scales with screen size */
  text-shadow: 2px 2px var(--accent-warn);
  margin: 10px 0 5px 0;
  text-transform: uppercase;
  letter-spacing: 2px;
  animation: glitch 1s linear infinite;
  text-align: center;
  line-height: 1;
}

.hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: env(safe-area-inset-top, 10px);
}

.intro .hero {
  min-height: 55vh;
  justify-content: center;
}

.intro .container {
  margin-top: -10px;
  opacity: 0;
  transform: scaleY(0.98);
  pointer-events: none;
}

/* In intro state, die starts centered with title */
.intro .die-btn {
  bottom: 30vh;
}

.activated .container {
  opacity: 1;
  transform: scaleY(1);
  perspective: 1200px;
}

/* First-time CRT power-on effect */
.activated .container.crt-boot {
  animation: crt-on 600ms cubic-bezier(0.2, 0.7, 0.2, 1) both;
}

.activated .container.crt-boot::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at center, rgba(0, 240, 255, 0.3) 0%, transparent 70%);
  border-radius: 4px;
  opacity: 0;
  animation: crt-glow-bloom 800ms ease-out both;
  pointer-events: none;
  z-index: 5;
}

.activated .container.crt-boot::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, transparent 5%, rgba(0, 240, 255, 0.8) 30%, rgba(255, 255, 255, 0.9) 50%, rgba(0, 240, 255, 0.8) 70%, transparent 95%);
  box-shadow: 0 0 20px 6px rgba(0, 240, 255, 0.5), 0 0 60px 10px rgba(0, 240, 255, 0.2);
  top: 50%;
  transform: translateY(-50%);
  opacity: 0;
  animation: crt-scanline-sweep 600ms cubic-bezier(0.2, 0.7, 0.2, 1) both;
  pointer-events: none;
  z-index: 6;
}

.activated .container.crt-boot .result-area {
  animation: crt-flicker 0.35s steps(2, end) 300ms both;
}

/* Die roll animation for subsequent rolls */
.activated .container.die-roll-x {
  animation: die-roll-x 650ms cubic-bezier(0.4, 0.0, 0.2, 1) both;
}
.activated .container.die-roll-neg-x {
  animation: die-roll-neg-x 650ms cubic-bezier(0.4, 0.0, 0.2, 1) both;
}
.activated .container.die-roll-y {
  animation: die-roll-y 650ms cubic-bezier(0.4, 0.0, 0.2, 1) both;
}
.activated .container.die-roll-neg-y {
  animation: die-roll-neg-y 650ms cubic-bezier(0.4, 0.0, 0.2, 1) both;
}
.activated .container.die-roll-diagonal {
  animation: die-roll-diagonal 650ms cubic-bezier(0.4, 0.0, 0.2, 1) both;
}

.activated .container.die-roll-x .result-area,
.activated .container.die-roll-neg-x .result-area,
.activated .container.die-roll-y .result-area,
.activated .container.die-roll-neg-y .result-area,
.activated .container.die-roll-diagonal .result-area {
  animation: die-content-flash 650ms ease both;
}

.subtitle {
  margin-bottom: 15px;
  color: var(--text-muted);
  text-align: center;
  font-size: 1.2rem;
}

.container {
  width: 100%;
  max-width: 600px;
  border: 2px solid var(--text-muted);
  padding: 15px;
  box-shadow: 0 0 10px rgba(0, 240, 255, 0.08);
  background-color: var(--surface);
  position: relative;
  z-index: 10;
  margin-bottom: 20px;
  overflow: hidden;
  transform-origin: center center;
}

/* Landscape / desktop: wider container with card grid */
@media (min-width: 700px) {
  .container {
    max-width: 1000px;
    padding: 20px;
  }

  .result-area {
    display: none; /* still hidden until activated */
  }

  .activated .result-area {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 16px;
    padding-bottom: 20px;
  }

  .activated .result-area .section {
    background: rgba(0, 240, 255, 0.03);
    border: 1px solid rgba(139, 148, 158, 0.25);
    border-left: 2px solid var(--text-muted);
    border-radius: 4px;
    padding: 14px;
    margin-bottom: 0;
  }
}

/* Floating d20 die button */
.die-btn {
  position: fixed;
  bottom: 15vh;
  left: 50%;
  transform: translateX(-50%);
  z-index: 50;
  width: 64px;
  height: 64px;
  background: transparent;
  border: none;
  color: var(--accent);
  cursor: pointer;
  padding: 0;
  touch-action: manipulation;
  animation: die-hover 3s ease-in-out infinite, die-glow-pulse 4s ease-in-out infinite;
  filter: drop-shadow(0 0 8px rgba(0, 240, 255, 0.4)) drop-shadow(0 0 20px rgba(0, 240, 255, 0.2));
}

/* When rolling, override idle animations */
.die-btn.rolling {
  animation: die-roll-away 900ms cubic-bezier(0.4, 0, 0.2, 1) both;
  pointer-events: none;
}

.die-btn:active:not(.rolling) {
  filter: drop-shadow(0 0 16px rgba(0, 240, 255, 0.8)) drop-shadow(0 0 40px rgba(0, 240, 255, 0.4));
  transform: translateX(-50%) scale(0.9);
  animation-play-state: paused;
}

/* Dark backdrop behind the die for contrast over light text */
.die-btn::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 130%;
  height: 130%;
  background: radial-gradient(circle, rgba(13, 15, 20, 0.75) 30%, rgba(13, 15, 20, 0.3) 65%, transparent 100%);
  border-radius: 50%;
  pointer-events: none;
  z-index: -1;
}

.die-icon {
  width: 100%;
  height: 100%;
  position: relative;
  z-index: 1;
}

/* Gentle floating bob */
@keyframes die-hover {
  0%, 100% { transform: translateX(-50%) translateY(0); }
  50% { transform: translateX(-50%) translateY(-8px); }
}

/* Eerie glow pulse */
@keyframes die-glow-pulse {
  0%, 100% {
    filter: drop-shadow(0 0 8px rgba(0, 240, 255, 0.4)) drop-shadow(0 0 20px rgba(0, 240, 255, 0.15));
  }
  50% {
    filter: drop-shadow(0 0 14px rgba(0, 240, 255, 0.7)) drop-shadow(0 0 35px rgba(0, 240, 255, 0.3)) drop-shadow(0 0 60px rgba(0, 240, 255, 0.1));
  }
}

/* Die rolls off right, comes back from left */
@keyframes die-roll-away {
  0% {
    transform: translateX(-50%) translateY(0) rotate(0deg);
    opacity: 1;
  }
  40% {
    transform: translateX(60vw) translateY(-20px) rotate(360deg);
    opacity: 0;
  }
  41% {
    transform: translateX(-60vw) translateY(-20px) rotate(-360deg);
    opacity: 0;
  }
  100% {
    transform: translateX(-50%) translateY(0) rotate(0deg);
    opacity: 1;
  }
}

.result-area {
  display: none;
  padding-bottom: 20px;
}

.section {
  margin-bottom: 25px;
  border-left: 2px solid var(--text-muted);
  padding-left: 10px;
}

.label {
  color: var(--accent-warn);
  text-transform: uppercase;
  font-weight: bold;
  font-size: 1.5rem;
  margin-bottom: 5px;
  display: block;
}

ul {
  list-style-type: none; /* Remove default bullets to save space */
  padding-left: 0;
  margin: 0;
}

li {
  font-size: 1.3rem;
  margin-bottom: 8px;
  position: relative;
  padding-left: 15px;
  line-height: 1.2;
}

li::before {
  content: ">";
  position: absolute;
  left: 0;
  color: var(--text-muted);
}

/* Glitch Animation */
@keyframes glitch {
  2%,
  64% {
    transform: translate(2px, 0) skew(0deg);
  }
  4%,
  60% {
    transform: translate(-2px, 0) skew(0deg);
  }
  62% {
    transform: translate(0, 0) skew(5deg);
  }
}

.flicker {
  animation: flicker 0.15s infinite;
}
@keyframes flicker {
  0% {
    opacity: 0.9;
  }
  50% {
    opacity: 1;
  }
  100% {
    opacity: 0.9;
  }
}

@keyframes crt-on {
  0% {
    opacity: 0;
    transform: scaleY(0.01) scaleX(0.6);
    filter: brightness(3);
    box-shadow:
      0 0 80px 20px rgba(0, 240, 255, 0.6),
      inset 0 0 40px rgba(0, 240, 255, 0.3);
  }
  15% {
    opacity: 1;
    transform: scaleY(0.02) scaleX(0.8);
    filter: brightness(2.5);
    box-shadow:
      0 0 60px 15px rgba(0, 240, 255, 0.5),
      inset 0 0 30px rgba(0, 240, 255, 0.25);
  }
  40% {
    opacity: 1;
    transform: scaleY(0.4) scaleX(1);
    filter: brightness(1.8);
    box-shadow:
      0 0 40px 10px rgba(0, 240, 255, 0.35),
      inset 0 0 20px rgba(0, 240, 255, 0.15);
  }
  65% {
    opacity: 1;
    transform: scaleY(1.03) scaleX(1);
    filter: brightness(1.3);
    box-shadow:
      0 0 20px 5px rgba(0, 240, 255, 0.2),
      inset 0 0 10px rgba(0, 240, 255, 0.08);
  }
  85% {
    transform: scaleY(0.98) scaleX(1);
    filter: brightness(1.1);
  }
  100% {
    opacity: 1;
    transform: scaleY(1) scaleX(1);
    filter: brightness(1);
    box-shadow: 0 0 10px rgba(0, 240, 255, 0.08);
  }
}

@keyframes crt-glow-bloom {
  0% {
    opacity: 0;
  }
  20% {
    opacity: 1;
  }
  60% {
    opacity: 0.6;
  }
  100% {
    opacity: 0;
  }
}

@keyframes crt-scanline-sweep {
  0% {
    opacity: 1;
    top: 50%;
    transform: translateY(-50%) scaleX(0.3);
  }
  30% {
    opacity: 1;
    top: 50%;
    transform: translateY(-50%) scaleX(1);
  }
  100% {
    opacity: 0;
    top: 50%;
    transform: translateY(-50%) scaleX(1);
  }
}

@keyframes crt-flicker {
  0% {
    opacity: 0;
  }
  30% {
    opacity: 0.3;
  }
  50% {
    opacity: 1;
  }
  70% {
    opacity: 0.4;
  }
  100% {
    opacity: 1;
  }
}

/* Die roll keyframes - each direction is a 90-degree tumble */
@keyframes die-roll-x {
  0% { transform: perspective(1200px) rotateX(0deg) scale(1); opacity: 1; }
  25% { transform: perspective(1200px) rotateX(45deg) scale(0.9); opacity: 0.5; }
  50% { transform: perspective(1200px) rotateX(90deg) scale(0.85); opacity: 0; }
  51% { transform: perspective(1200px) rotateX(-90deg) scale(0.85); opacity: 0; }
  75% { transform: perspective(1200px) rotateX(-45deg) scale(0.9); opacity: 0.5; }
  100% { transform: perspective(1200px) rotateX(0deg) scale(1); opacity: 1; }
}

@keyframes die-roll-neg-x {
  0% { transform: perspective(1200px) rotateX(0deg) scale(1); opacity: 1; }
  25% { transform: perspective(1200px) rotateX(-45deg) scale(0.9); opacity: 0.5; }
  50% { transform: perspective(1200px) rotateX(-90deg) scale(0.85); opacity: 0; }
  51% { transform: perspective(1200px) rotateX(90deg) scale(0.85); opacity: 0; }
  75% { transform: perspective(1200px) rotateX(45deg) scale(0.9); opacity: 0.5; }
  100% { transform: perspective(1200px) rotateX(0deg) scale(1); opacity: 1; }
}

@keyframes die-roll-y {
  0% { transform: perspective(1200px) rotateY(0deg) scale(1); opacity: 1; }
  25% { transform: perspective(1200px) rotateY(45deg) scale(0.9); opacity: 0.5; }
  50% { transform: perspective(1200px) rotateY(90deg) scale(0.85); opacity: 0; }
  51% { transform: perspective(1200px) rotateY(-90deg) scale(0.85); opacity: 0; }
  75% { transform: perspective(1200px) rotateY(-45deg) scale(0.9); opacity: 0.5; }
  100% { transform: perspective(1200px) rotateY(0deg) scale(1); opacity: 1; }
}

@keyframes die-roll-neg-y {
  0% { transform: perspective(1200px) rotateY(0deg) scale(1); opacity: 1; }
  25% { transform: perspective(1200px) rotateY(-45deg) scale(0.9); opacity: 0.5; }
  50% { transform: perspective(1200px) rotateY(-90deg) scale(0.85); opacity: 0; }
  51% { transform: perspective(1200px) rotateY(90deg) scale(0.85); opacity: 0; }
  75% { transform: perspective(1200px) rotateY(45deg) scale(0.9); opacity: 0.5; }
  100% { transform: perspective(1200px) rotateY(0deg) scale(1); opacity: 1; }
}

@keyframes die-roll-diagonal {
  0% { transform: perspective(1200px) rotate3d(1, 1, 0, 0deg) scale(1); opacity: 1; }
  25% { transform: perspective(1200px) rotate3d(1, 1, 0, 45deg) scale(0.9); opacity: 0.5; }
  50% { transform: perspective(1200px) rotate3d(1, 1, 0, 90deg) scale(0.85); opacity: 0; }
  51% { transform: perspective(1200px) rotate3d(1, 1, 0, -90deg) scale(0.85); opacity: 0; }
  75% { transform: perspective(1200px) rotate3d(1, 1, 0, -45deg) scale(0.9); opacity: 0.5; }
  100% { transform: perspective(1200px) rotate3d(1, 1, 0, 0deg) scale(1); opacity: 1; }
}

@keyframes die-content-flash {
  0% { opacity: 1; }
  25% { opacity: 0.3; }
  50% { opacity: 0; }
  75% { opacity: 0.3; }
  100% { opacity: 1; }
}

/* Mobile specific adjustments */
@media (max-width: 600px) {
  .die-btn {
    width: 56px;
    height: 56px;
  }
}

@media (max-width: 400px) {
  h1 {
    font-size: 2.8rem;
  }
  li {
    font-size: 1.1rem;
  }
  .die-btn {
    width: 50px;
    height: 50px;
  }
}

.site-footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  font-size: 0.85rem;
  color: var(--text-muted);
  text-align: center;
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom, 0px));
  z-index: 40;
  pointer-events: none;
}

.site-footer a {
  pointer-events: auto;
}

.site-footer a {
  color: var(--text-muted);
  text-decoration: underline;
}

.site-footer a:hover {
  color: var(--accent);
}
