@import url('https://fonts.googleapis.com/css2?family=Cormorant+Garamond:wght@300;400;500;600&family=DM+Sans:wght@400;500&display=swap');

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --felt: #1a2f23;
  --felt-light: #243d2e;
  --ivory: #f5f0e6;
  --ivory-dark: #e8e0d0;
  --gold: #c9a962;
  --gold-dim: #8a7542;
  --shadow: rgba(0, 0, 0, 0.4);
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: 'DM Sans', sans-serif;
  background: var(--felt);
}

#canvas-container {
  width: 100%;
  height: 100%;
  position: relative;
  cursor: pointer;
}

canvas {
  display: block;
}

/* Felt texture overlay */
#canvas-container::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%' height='100%' filter='url(%23noise)'/%3E%3C/svg%3E");
  opacity: 0.03;
  pointer-events: none;
  z-index: 1;
}

/* UI Layer */
.ui-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 10;
}

/* Result display */
.result {
  position: absolute;
  top: 40px;
  left: 50%;
  transform: translateX(-50%);
  text-align: center;
  opacity: 0;
  transition: opacity 0.5s ease;
}

.result.visible {
  opacity: 1;
}

.result-value {
  font-family: 'Cormorant Garamond', serif;
  font-size: clamp(4rem, 12vw, 8rem);
  font-weight: 300;
  color: var(--ivory);
  line-height: 1;
  letter-spacing: -0.02em;
  text-shadow: 0 4px 20px var(--shadow);
}

.result-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.3em;
  color: var(--gold-dim);
  margin-top: 0.5rem;
}

/* Dice selector container */
.dice-selector {
  position: absolute;
  bottom: 40px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  pointer-events: auto;
}

.dice-selector-label {
  font-family: 'Cormorant Garamond', serif;
  font-size: 0.7rem;
  font-weight: 400;
  letter-spacing: 0.35em;
  text-transform: uppercase;
  color: var(--gold-dim);
  opacity: 0.7;
}

.dice-selector-track {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 12px 20px;
  background: linear-gradient(
    135deg,
    rgba(201, 169, 98, 0.03) 0%,
    rgba(201, 169, 98, 0.08) 50%,
    rgba(201, 169, 98, 0.03) 100%
  );
  border: 1px solid rgba(201, 169, 98, 0.15);
  border-radius: 60px;
  position: relative;
  backdrop-filter: blur(8px);
}

.dice-selector-track::before {
  content: '';
  position: absolute;
  inset: -1px;
  border-radius: 60px;
  padding: 1px;
  background: linear-gradient(
    135deg,
    rgba(201, 169, 98, 0.3) 0%,
    rgba(201, 169, 98, 0.05) 50%,
    rgba(201, 169, 98, 0.3) 100%
  );
  -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  pointer-events: none;
}

/* Dice count buttons */
.dice-btn {
  width: 52px;
  height: 52px;
  border: none;
  background: transparent;
  cursor: pointer;
  padding: 0;
  position: relative;
  transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.dice-btn:focus {
  outline: none;
}

.dice-btn:focus-visible .dice-face {
  box-shadow:
    0 4px 12px rgba(0, 0, 0, 0.3),
    0 0 0 2px var(--gold);
}

.dice-face {
  width: 100%;
  height: 100%;
  background: linear-gradient(
    145deg,
    rgba(245, 240, 230, 0.12) 0%,
    rgba(245, 240, 230, 0.05) 100%
  );
  border: 1px solid rgba(201, 169, 98, 0.25);
  border-radius: 8px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  padding: 8px;
  gap: 2px;
  position: relative;
  transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  box-shadow:
    0 2px 8px rgba(0, 0, 0, 0.2),
    inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

.dice-btn:hover {
  transform: translateY(-4px) scale(1.05);
}

.dice-btn:hover .dice-face {
  border-color: rgba(201, 169, 98, 0.5);
  background: linear-gradient(
    145deg,
    rgba(245, 240, 230, 0.18) 0%,
    rgba(245, 240, 230, 0.08) 100%
  );
  box-shadow:
    0 8px 24px rgba(0, 0, 0, 0.35),
    0 0 20px rgba(201, 169, 98, 0.15),
    inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.dice-btn:hover .pip {
  background: var(--gold);
  box-shadow: 0 0 6px rgba(201, 169, 98, 0.5);
}

.dice-btn.active {
  transform: translateY(-2px);
}

.dice-btn.active .dice-face {
  background: linear-gradient(
    145deg,
    var(--ivory) 0%,
    var(--ivory-dark) 100%
  );
  border-color: var(--gold);
  box-shadow:
    0 6px 20px rgba(0, 0, 0, 0.4),
    0 0 30px rgba(201, 169, 98, 0.3),
    0 0 60px rgba(201, 169, 98, 0.15),
    inset 0 2px 4px rgba(255, 255, 255, 0.3);
}

.dice-btn.active .pip {
  background: var(--felt);
  box-shadow: none;
}

.pip {
  width: 8px;
  height: 8px;
  background: var(--gold-dim);
  border-radius: 50%;
  opacity: 0;
  transform: scale(0);
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  justify-self: center;
  align-self: center;
}

.pip.visible {
  opacity: 1;
  transform: scale(1);
}

/* Pip positions in 3x3 grid */
.pip:nth-child(1) { grid-area: 1 / 1; }
.pip:nth-child(2) { grid-area: 1 / 2; }
.pip:nth-child(3) { grid-area: 1 / 3; }
.pip:nth-child(4) { grid-area: 2 / 1; }
.pip:nth-child(5) { grid-area: 2 / 2; }
.pip:nth-child(6) { grid-area: 2 / 3; }
.pip:nth-child(7) { grid-area: 3 / 1; }
.pip:nth-child(8) { grid-area: 3 / 2; }
.pip:nth-child(9) { grid-area: 3 / 3; }

/* Dice face pip patterns */
[data-count="1"] .pip:nth-child(5) { opacity: 1; transform: scale(1); }

[data-count="2"] .pip:nth-child(1),
[data-count="2"] .pip:nth-child(9) { opacity: 1; transform: scale(1); }

[data-count="3"] .pip:nth-child(1),
[data-count="3"] .pip:nth-child(5),
[data-count="3"] .pip:nth-child(9) { opacity: 1; transform: scale(1); }

[data-count="4"] .pip:nth-child(1),
[data-count="4"] .pip:nth-child(3),
[data-count="4"] .pip:nth-child(7),
[data-count="4"] .pip:nth-child(9) { opacity: 1; transform: scale(1); }

[data-count="5"] .pip:nth-child(1),
[data-count="5"] .pip:nth-child(3),
[data-count="5"] .pip:nth-child(5),
[data-count="5"] .pip:nth-child(7),
[data-count="5"] .pip:nth-child(9) { opacity: 1; transform: scale(1); }

/* Dice type buttons */
.type-btn {
  min-width: 48px;
  height: 36px;
  padding: 0 12px;
  border: 1px solid rgba(201, 169, 98, 0.25);
  border-radius: 18px;
  background: linear-gradient(
    145deg,
    rgba(245, 240, 230, 0.08) 0%,
    rgba(245, 240, 230, 0.03) 100%
  );
  color: var(--gold-dim);
  font-family: 'Cormorant Garamond', serif;
  font-size: 0.9rem;
  font-weight: 500;
  letter-spacing: 0.05em;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.type-btn:hover {
  transform: translateY(-2px);
  border-color: rgba(201, 169, 98, 0.5);
  color: var(--gold);
  background: linear-gradient(
    145deg,
    rgba(245, 240, 230, 0.15) 0%,
    rgba(245, 240, 230, 0.08) 100%
  );
}

.type-btn.active {
  background: linear-gradient(
    145deg,
    var(--ivory) 0%,
    var(--ivory-dark) 100%
  );
  border-color: var(--gold);
  color: var(--felt);
  box-shadow:
    0 4px 15px rgba(0, 0, 0, 0.3),
    0 0 20px rgba(201, 169, 98, 0.2);
}

/* Staggered entrance animation */
.dice-selector-track {
  animation: selectorFadeIn 0.8s ease-out 0.5s both;
}

.dice-btn {
  animation: diceEnter 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

.dice-btn:nth-child(1) { animation-delay: 0.6s; }
.dice-btn:nth-child(2) { animation-delay: 0.7s; }
.dice-btn:nth-child(3) { animation-delay: 0.8s; }
.dice-btn:nth-child(4) { animation-delay: 0.9s; }
.dice-btn:nth-child(5) { animation-delay: 1.0s; }

.type-btn {
  animation: diceEnter 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

.type-btn:nth-child(1) { animation-delay: 0.4s; }
.type-btn:nth-child(2) { animation-delay: 0.45s; }
.type-btn:nth-child(3) { animation-delay: 0.5s; }
.type-btn:nth-child(4) { animation-delay: 0.55s; }
.type-btn:nth-child(5) { animation-delay: 0.6s; }
.type-btn:nth-child(6) { animation-delay: 0.65s; }

@keyframes selectorFadeIn {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes diceEnter {
  from {
    opacity: 0;
    transform: translateY(15px) rotate(-10deg) scale(0.8);
  }
  to {
    opacity: 1;
    transform: translateY(0) rotate(0deg) scale(1);
  }
}

/* Selection ripple effect */
.dice-btn::after {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: 12px;
  background: radial-gradient(circle, rgba(201, 169, 98, 0.4) 0%, transparent 70%);
  opacity: 0;
  transform: scale(0.8);
  transition: all 0.4s ease;
  pointer-events: none;
}

.dice-btn.active::after {
  opacity: 1;
  transform: scale(1.2);
  animation: pulseGlow 2s ease-in-out infinite;
}

@keyframes pulseGlow {
  0%, 100% {
    opacity: 0.6;
    transform: scale(1.1);
  }
  50% {
    opacity: 0.3;
    transform: scale(1.25);
  }
}

/* Hint text */
.hint {
  position: absolute;
  bottom: 180px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.75rem;
  color: var(--gold-dim);
  letter-spacing: 0.2em;
  text-transform: uppercase;
  opacity: 0.5;
  transition: opacity 0.5s ease;
}

.hint.hidden {
  opacity: 0;
}

/* Rolling state */
.rolling .hint {
  opacity: 0;
}

/* Vignette */
.vignette {
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at center, transparent 40%, rgba(0,0,0,0.4) 100%);
  pointer-events: none;
}

/* Loading */
.loading {
  position: fixed;
  inset: 0;
  background: var(--felt);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.5rem;
  z-index: 100;
  transition: opacity 0.5s ease;
}

.loading.hidden {
  opacity: 0;
  pointer-events: none;
}

.loading-dice {
  perspective: 300px;
}

.loading-dice-face {
  width: 52px;
  height: 52px;
  background: var(--felt-light);
  border: 2px solid var(--gold);
  border-radius: 8px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  padding: 8px;
  gap: 2px;
  animation: diceFloat 3s ease-in-out infinite;
  box-shadow:
    0 0 30px rgba(201, 169, 98, 0.2),
    0 4px 12px rgba(0, 0, 0, 0.3);
}

.loading-dice-face .pip {
  width: 8px;
  height: 8px;
  background: var(--gold);
  border-radius: 50%;
  justify-self: center;
  align-self: center;
  opacity: 0;
}

/* Show 5 pips pattern */
.loading-dice-face .pip:nth-child(1),
.loading-dice-face .pip:nth-child(3),
.loading-dice-face .pip:nth-child(5),
.loading-dice-face .pip:nth-child(7),
.loading-dice-face .pip:nth-child(9) {
  opacity: 1;
}

@keyframes diceFloat {
  0%, 100% {
    transform: rotateX(0deg) rotateY(0deg) translateY(0);
    box-shadow:
      0 0 30px rgba(201, 169, 98, 0.2),
      0 4px 12px rgba(0, 0, 0, 0.3);
  }
  25% {
    transform: rotateX(8deg) rotateY(-12deg) translateY(-8px);
    box-shadow:
      0 0 40px rgba(201, 169, 98, 0.35),
      0 12px 20px rgba(0, 0, 0, 0.25);
  }
  50% {
    transform: rotateX(-5deg) rotateY(8deg) translateY(-4px);
    box-shadow:
      0 0 35px rgba(201, 169, 98, 0.3),
      0 8px 16px rgba(0, 0, 0, 0.28);
  }
  75% {
    transform: rotateX(6deg) rotateY(-6deg) translateY(-10px);
    box-shadow:
      0 0 45px rgba(201, 169, 98, 0.4),
      0 14px 22px rgba(0, 0, 0, 0.22);
  }
}

.loading-text {
  font-family: 'Cormorant Garamond', serif;
  font-size: 1rem;
  font-weight: 500;
  letter-spacing: 0.35em;
  text-transform: uppercase;
  color: var(--gold);
  animation: textPulse 2s ease-in-out infinite;
}

@keyframes textPulse {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 1; }
}

/* Settings Button */
.settings-btn {
  position: absolute;
  top: 20px;
  right: 20px;
  width: 44px;
  height: 44px;
  padding: 10px;
  border: 1px solid rgba(201, 169, 98, 0.25);
  border-radius: 50%;
  background: linear-gradient(
    135deg,
    rgba(201, 169, 98, 0.03) 0%,
    rgba(201, 169, 98, 0.08) 50%,
    rgba(201, 169, 98, 0.03) 100%
  );
  backdrop-filter: blur(8px);
  cursor: pointer;
  pointer-events: auto;
  transition: all 0.3s ease;
}

.settings-btn svg {
  width: 100%;
  height: 100%;
  color: var(--gold-dim);
  transition: color 0.3s ease, transform 0.3s ease;
}

.settings-btn:hover {
  border-color: rgba(201, 169, 98, 0.5);
  background: linear-gradient(
    135deg,
    rgba(201, 169, 98, 0.08) 0%,
    rgba(201, 169, 98, 0.15) 50%,
    rgba(201, 169, 98, 0.08) 100%
  );
}

.settings-btn:hover svg {
  color: var(--gold);
  transform: rotate(30deg);
}

/* Settings Panel */
.settings-panel {
  position: absolute;
  top: 0;
  right: 0;
  width: 280px;
  height: 100%;
  background: linear-gradient(
    180deg,
    rgba(26, 47, 35, 0.95) 0%,
    rgba(26, 47, 35, 0.98) 100%
  );
  border-left: 1px solid rgba(201, 169, 98, 0.2);
  backdrop-filter: blur(20px);
  transform: translateX(100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  pointer-events: auto;
  display: flex;
  flex-direction: column;
  z-index: 20;
}

.settings-panel.open {
  transform: translateX(0);
}

.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px;
  border-bottom: 1px solid rgba(201, 169, 98, 0.15);
}

.settings-title {
  font-family: 'Cormorant Garamond', serif;
  font-size: 1.1rem;
  font-weight: 500;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--gold);
}

.settings-close {
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  color: var(--gold-dim);
  font-size: 1.5rem;
  cursor: pointer;
  transition: color 0.2s ease;
  line-height: 1;
}

.settings-close:hover {
  color: var(--gold);
}

.settings-content {
  flex: 1;
  padding: 20px;
  overflow-y: auto;
}

.setting-group {
  margin-bottom: 24px;
}

.setting-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  font-size: 0.8rem;
  color: var(--ivory);
  letter-spacing: 0.05em;
}

.setting-value {
  font-family: 'DM Sans', sans-serif;
  font-size: 0.75rem;
  color: var(--gold-dim);
  min-width: 40px;
  text-align: right;
}

/* Custom Range Slider */
.setting-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  background: rgba(201, 169, 98, 0.2);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}

.setting-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  background: var(--gold);
  border-radius: 50%;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.setting-slider::-webkit-slider-thumb:hover {
  transform: scale(1.2);
  box-shadow: 0 0 10px rgba(201, 169, 98, 0.5);
}

.setting-slider::-moz-range-thumb {
  width: 16px;
  height: 16px;
  background: var(--gold);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.setting-slider::-moz-range-thumb:hover {
  transform: scale(1.2);
  box-shadow: 0 0 10px rgba(201, 169, 98, 0.5);
}

.setting-slider::-moz-range-track {
  background: rgba(201, 169, 98, 0.2);
  height: 4px;
  border-radius: 2px;
}

/* Reset Button */
.settings-reset {
  width: 100%;
  padding: 12px;
  margin-top: 16px;
  border: 1px solid rgba(201, 169, 98, 0.3);
  border-radius: 8px;
  background: transparent;
  color: var(--gold-dim);
  font-family: 'DM Sans', sans-serif;
  font-size: 0.8rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  cursor: pointer;
  transition: all 0.2s ease;
}

.settings-reset:hover {
  border-color: var(--gold);
  color: var(--gold);
  background: rgba(201, 169, 98, 0.1);
}

/* Potato Mode Button */
.potato-btn {
  position: absolute;
  top: 72px;
  right: 20px;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid rgba(201, 169, 98, 0.25);
  border-radius: 50%;
  background: linear-gradient(
    135deg,
    rgba(201, 169, 98, 0.03) 0%,
    rgba(201, 169, 98, 0.08) 50%,
    rgba(201, 169, 98, 0.03) 100%
  );
  backdrop-filter: blur(8px);
  cursor: pointer;
  pointer-events: auto;
  transition: all 0.3s ease;
  font-size: 1.25rem;
  line-height: 1;
}

.potato-btn:hover {
  border-color: rgba(201, 169, 98, 0.5);
  background: linear-gradient(
    135deg,
    rgba(201, 169, 98, 0.08) 0%,
    rgba(201, 169, 98, 0.15) 50%,
    rgba(201, 169, 98, 0.08) 100%
  );
  transform: scale(1.05);
}

.potato-btn.active {
  border-color: var(--gold);
  background: linear-gradient(
    135deg,
    rgba(201, 169, 98, 0.15) 0%,
    rgba(201, 169, 98, 0.25) 50%,
    rgba(201, 169, 98, 0.15) 100%
  );
  box-shadow: 0 0 15px rgba(201, 169, 98, 0.3);
}
