 :root {
      --dice-size: 200px;
      --bg-color: #0f172a;
    }

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

    body {
      min-height: 100vh;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      background-color: var(--bg-color);
      font-family: system-ui, -apple-system, sans-serif;
      color: #f8fafc;
      padding: 2rem 1rem;
      transition: background-color 0.3s ease;
      overflow-x: hidden;
      cursor: pointer; /* Indicates whole screen is clickable */
      user-select: none;
    }

    .container {
      display: flex;
      flex-direction: column;
      align-items: center;
      gap: 60px;
      width: 100%;
      max-width: 1000px;
      pointer-events: none; /* Let clicks pass through to body/screen */
    }

    /* Multi-Dice Layout Container */
    .dice-wrapper {
      display: flex;
      flex-wrap: wrap;
      justify-content: center;
      align-items: center;
      gap: 60px;
      min-height: calc(var(--dice-size) + 20px);
    }

    /* 3D Scene Setup */
    .scene {
      width: var(--dice-size);
      height: var(--dice-size);
      perspective: calc(var(--dice-size) * 5);
      transition: width 0.2s ease, height 0.2s ease;
    }

    .cube {
      width: 100%;
      height: 100%;
      position: relative;
      transform-style: preserve-3d;
      transition: transform 0.6s cubic-bezier(0.25, 0.8, 0.25, 1);
      will-change: transform;
    }

    /* Tumbling animation while rolling */
    .cube.rolling {
      animation: rollAnimation 1.5s linear infinite;
    }

    @keyframes rollAnimation {
      0% { transform: rotateX(0deg) rotateY(0deg) rotateZ(0deg); }
      33% { transform: rotateX(360deg) rotateY(180deg) rotateZ(90deg); }
      66% { transform: rotateX(720deg) rotateY(540deg) rotateZ(270deg); }
      100% { transform: rotateX(1080deg) rotateY(720deg) rotateZ(360deg); }
    }

    /* Face Positioning */
    .face {
      position: absolute;
      width: var(--dice-size);
      height: var(--dice-size);
      background: #1e293b;
      border: none;
      border-radius: calc(var(--dice-size) * 0.2);
      overflow: hidden;
      backface-visibility: hidden;
      -webkit-backface-visibility: hidden;
    }

    .face img {
      width: 104%;
      height: 104%;
      object-fit: cover;
      transform: translate(-2%, -2%);
      display: block;
    }

    /* Dynamic 3D Cube Face Translations */
    .face-1 { transform: translateZ(calc(var(--dice-size) / 2 - 0.2px)); }
    .face-2 { transform: rotateY(180deg) translateZ(calc(var(--dice-size) / 2 - 0.2px)); }
    .face-3 { transform: rotateY(90deg) translateZ(calc(var(--dice-size) / 2 - 0.2px)); }
    .face-4 { transform: rotateY(-90deg) translateZ(calc(var(--dice-size) / 2 - 0.2px)); }
    .face-5 { transform: rotateX(90deg) translateZ(calc(var(--dice-size) / 2 - 0.2px)); }
    .face-6 { transform: rotateX(-90deg) translateZ(calc(var(--dice-size) / 2 - 0.2px)); }

    /* Exact Landing Positions for Each Side */
    .cube.show-1 { transform: rotateX(0deg) rotateY(0deg); }
    .cube.show-2 { transform: rotateX(0deg) rotateY(-180deg); }
    .cube.show-3 { transform: rotateX(0deg) rotateY(-90deg); }
    .cube.show-4 { transform: rotateX(0deg) rotateY(90deg); }
    .cube.show-5 { transform: rotateX(-90deg) rotateY(0deg); }
    .cube.show-6 { transform: rotateX(90deg) rotateY(0deg); }

    /* Controls */
    .controls {
      display: flex;
      flex-direction: column;
      align-items: center;
      gap: 1rem;
      pointer-events: auto; /* Enable button interactions */
    }

    button.roll-btn {
      background: #6366f1;
      color: white;
      border: none;
      padding: 0.8rem 2.5rem;
      font-size: 1.2rem;
      font-weight: 600;
      border-radius: 9999px;
      cursor: pointer;
      box-shadow: 0 4px 14px rgba(99, 102, 241, 0.4);
      transition: all 0.2s ease;
    }

    button.roll-btn:hover {
      background: #4f46e5;
      transform: translateY(-2px);
    }

    button.roll-btn:disabled {
      background: #475569;
      cursor: not-allowed;
      transform: none;
      box-shadow: none;
    }

    /* Significantly larger result text */
    .result {
      font-size: 100px;
      font-weight: 800;
      line-height: 1.1;
      min-height: 120px;
      color: #6366f1;
      text-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
      text-align: center;
      transition: color 0.3s ease, text-shadow 0.3s ease;
    }

    /* Floating Action Button (FAB) */
    .fab-btn {
      position: fixed;
      bottom: 24px;
      right: 24px;
      width: 56px;
      height: 56px;
      border-radius: 50%;
      background: #6366f1;
      border: none;
      color: white;
      cursor: pointer;
      display: flex;
      align-items: center;
      justify-content: center;
      box-shadow: 0 4px 15px rgba(0, 0, 0, 0.4);
      z-index: 1002;
      transition: transform 0.2s ease, background 0.2s ease;
      pointer-events: auto;
    }

    .fab-btn:hover {
      background: #4f46e5;
      transform: scale(1.08);
    }

    .fab-btn svg {
      width: 26px;
      height: 26px;
      fill: currentColor;
    }

    /* Right Sidebar (Drawer) */
    .sidebar {
      position: fixed;
      top: 0;
      right: -350px;
      width: 350px;
      height: 100vh;
      background: #1e293b;
      box-shadow: -4px 0 20px rgba(0, 0, 0, 0.4);
      z-index: 1001;
      transition: right 0.3s cubic-bezier(0.16, 1, 0.3, 1);
      padding: 1.5rem;
      display: flex;
      flex-direction: column;
      gap: 1.5rem;
      overflow-y: auto;
      pointer-events: auto; /* Ensures interactions stay inside drawer */
      cursor: default;
    }

    .sidebar.open {
      right: 0;
    }

    .sidebar-header {
      display: flex;
      justify-content: space-between;
      align-items: center;
      border-bottom: 1px solid #334155;
      padding-bottom: 1rem;
    }

    .sidebar-header h2 {
      font-size: 1.25rem;
      font-weight: 600;
      color: #f8fafc;
    }

    .close-btn {
      background: transparent;
      border: none;
      color: #94a3b8;
      font-size: 1.5rem;
      cursor: pointer;
      padding: 0.2rem;
      line-height: 1;
    }

    .close-btn:hover {
      color: #f8fafc;
    }

    .config-group {
      display: flex;
      flex-direction: column;
      gap: 0.5rem;
      font-size: 0.95rem;
      font-weight: 500;
      color: #cbd5e1;
    }

    .config-group label {
      display: flex;
      justify-content: space-between;
      align-items: center;
    }

    .config-group input[type="range"] {
      accent-color: #6366f1;
      cursor: pointer;
      width: 100%;
    }

    .config-group select {
      background: #0f172a;
      color: #f8fafc;
      border: 1px solid #334155;
      padding: 0.5rem;
      border-radius: 8px;
      outline: none;
      cursor: pointer;
      font-size: 0.95rem;
      width: 100%;
    }

    /* Color Grid (3 colors per row) */
    .color-grid {
      display: grid;
      grid-template-columns: repeat(3, 1fr);
      gap: 0.75rem;
      margin-top: 0.25rem;
    }

    .color-swatch {
      width: 100%;
      height: 40px;
      border-radius: 8px;
      border: 2px solid transparent;
      cursor: pointer;
      transition: transform 0.15s ease, border-color 0.15s ease;
    }

    .color-swatch:hover {
      transform: scale(1.05);
    }

    .color-swatch.active {
      border-color: #6366f1;
      box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.4);
    }

    /* Overlay backdrop */
    .backdrop {
      position: fixed;
      inset: 0;
      background: rgba(0, 0, 0, 0.4);
      z-index: 1000;
      opacity: 0;
      pointer-events: none;
      transition: opacity 0.3s ease;
    }

    .backdrop.active {
      opacity: 1;
      pointer-events: auto;
    }

    /* Light Background Theme Overrides */
    body.light-theme {
      color: #0f172a;
    }

    body.light-theme .result {
      color: #4f46e5;
      text-shadow: 0 10px 30px rgba(79, 70, 229, 0.2);
    }

    body.light-theme .sidebar-header h2 {
      color: #f8fafc;
    }

    @media (max-width: 600px) {
      .result {
        font-size: 90px;
        min-height: 80px;
      }
    }

    /* Disable WebKit highlight on tap for mobile browsers/webviews */
* {
  -webkit-tap-highlight-color: transparent !important;
  -webkit-touch-callout: none;
  outline: none !important;
}

/* Remove default focus styles on clickable elements */
button, a, input, select, textarea {
  -webkit-tap-highlight-color: rgba(0, 0, 0, 0) !important;
  outline: none !important;
}