/* ==========================================================================
   Custom 6-Side Color & Star Dice Roller - Pure CSS (No Libraries)
   ========================================================================== */

:root {
  --bg-main: #090d16;
  --bg-card: rgba(18, 26, 43, 0.75);
  --bg-card-border: rgba(255, 255, 255, 0.08);
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --color-gold: #facc15;
  --color-gold-glow: rgba(250, 204, 21, 0.4);
  --radius-lg: 16px;
  --radius-md: 10px;
  --dice-size: 150px;
  --font-stack: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

@media (max-width: 480px) {
  :root {
    --dice-size: 130px;
  }
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font-stack);
  background: radial-gradient(circle at 50% 20%, #172554 0%, #0b0f19 65%, #05070c 100%);
  color: var(--text-main);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  position: relative;
}

/* Background Atmosphere Pattern */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image: radial-gradient(rgba(255, 255, 255, 0.04) 1px, transparent 1px);
  background-size: 24px 24px;
  pointer-events: none;
  z-index: 0;
}

/* App Container */
.app-container {
  position: relative;
  z-index: 1;
  max-width: 900px;
  width: 100%;
  margin: 0 auto;
  padding: 1rem 1.25rem 2.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  min-height: 100vh;
}

/* Header */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--bg-card-border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: linear-gradient(135deg, #1e293b, #0f172a);
  border: 1.5px solid #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

.brand-icon svg {
  width: 24px;
  height: 24px;
  fill: #ffffff;
}

.brand-text h1 {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: #ffffff;
}

.brand-text p {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Action Buttons */
.icon-btn {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--bg-card-border);
  color: var(--text-main);
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-md);
  font-size: 0.85rem;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.2);
}

.icon-btn:active {
  transform: scale(0.96);
}

.install-btn {
  background: linear-gradient(135deg, #3b82f6, #2563eb);
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.2);
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.3);
}

.install-btn:hover {
  background: linear-gradient(135deg, #60a5fa, #3b82f6);
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.25rem 0.5rem;
  border-radius: 9999px;
  background: rgba(16, 185, 129, 0.15);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.status-badge.offline {
  background: rgba(245, 158, 11, 0.15);
  color: #fbbf24;
  border-color: rgba(245, 158, 11, 0.3);
}

/* Main Arena */
.arena-card {
  background: var(--bg-card);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--bg-card-border);
  border-radius: var(--radius-lg);
  padding: 1.75rem 1.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  box-shadow: 0 16px 36px -10px rgba(0, 0, 0, 0.5);
}

/* Control Bar (Dice Count / Auto Roll / Sound) */
.arena-controls {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

.segmented-control {
  display: inline-flex;
  background: rgba(0, 0, 0, 0.35);
  padding: 3px;
  border-radius: var(--radius-md);
  border: 1px solid var(--bg-card-border);
}

.segmented-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.35rem 0.75rem;
  border-radius: calc(var(--radius-md) - 2px);
  cursor: pointer;
  transition: all 0.2s ease;
}

.segmented-btn.active {
  background: #334155;
  color: #ffffff;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.segmented-btn:hover:not(.active) {
  color: var(--text-main);
}

.hint-pill {
  font-size: 0.75rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

/* 3D Rolling Surface */
.rolling-surface {
  position: relative;
  width: 100%;
  min-height: 260px;
  display: flex;
  align-items: center;
  justify-content: center;
  perspective: 1200px;
  margin: 1rem 0;
  cursor: pointer;
  border-radius: var(--radius-lg);
  background: radial-gradient(ellipse at 50% 60%, rgba(30, 41, 59, 0.4) 0%, rgba(15, 23, 42, 0.8) 100%);
  border: 1px dashed rgba(255, 255, 255, 0.1);
  overflow: visible;
}

.dice-container {
  display: flex;
  gap: 2.5rem;
  justify-content: center;
  align-items: center;
  perspective: 1200px;
  perspective-origin: 50% 50%;
  transform-style: preserve-3d;
}

/* Single Die Wrapper */
.die-wrapper {
  position: relative;
  width: var(--dice-size);
  height: var(--dice-size);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Dice Shadow */
.die-shadow {
  position: absolute;
  bottom: -22px;
  width: 80%;
  height: 24px;
  background: radial-gradient(ellipse at center, rgba(0, 0, 0, 0.65) 0%, transparent 70%);
  border-radius: 50%;
  filter: blur(4px);
  transition: transform 0.4s ease, opacity 0.4s ease;
  pointer-events: none;
}

.die-shadow.rolling {
  transform: scale(0.6) translateY(12px);
  opacity: 0.35;
  filter: blur(8px);
}

/* The 3D Cube */
.dice-cube {
  width: var(--dice-size);
  height: var(--dice-size);
  position: relative;
  transform-style: preserve-3d;
  transition: transform 1.2s cubic-bezier(0.18, 0.89, 0.32, 1.15);
  cursor: pointer;
}

/* 6 Sides of the Dice */
.cube-face {
  position: absolute;
  width: var(--dice-size);
  height: var(--dice-size);
  border-radius: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  backface-visibility: visible;
  border: 2px solid rgba(255, 255, 255, 0.2);
  box-shadow: inset 0 0 18px rgba(0, 0, 0, 0.35), 0 4px 10px rgba(0, 0, 0, 0.4);
  font-family: var(--font-stack);
  font-weight: 900;
  overflow: hidden;
}

/* Subtle corner bevel sheen on each face */
.cube-face::after {
  content: '';
  position: absolute;
  inset: 3px;
  border-radius: 20px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  pointer-events: none;
}

/* Exact 6 Dice Sides as requested */

/* 1. Green background with an X on it */
.cube-face.face-green {
  background: radial-gradient(circle at 35% 35%, #10b981 0%, #059669 65%, #047857 100%);
  transform: rotateY(0deg) translateZ(calc(var(--dice-size) / 2));
}

/* 2. Red background with an X on it */
.cube-face.face-red {
  background: radial-gradient(circle at 35% 35%, #ef4444 0%, #dc2626 65%, #b91c1c 100%);
  transform: rotateY(180deg) translateZ(calc(var(--dice-size) / 2));
}

/* 3. Purple background with an X on it */
.cube-face.face-purple {
  background: radial-gradient(circle at 35% 35%, #a855f7 0%, #9333ea 65%, #7e22ce 100%);
  transform: rotateY(90deg) translateZ(calc(var(--dice-size) / 2));
}

/* 4. Yellow background with an X on it */
.cube-face.face-yellow {
  background: radial-gradient(circle at 35% 35%, #fde047 0%, #eab308 65%, #ca8a04 100%);
  transform: rotateY(-90deg) translateZ(calc(var(--dice-size) / 2));
}

/* 5. Blue background with an X on it */
.cube-face.face-blue {
  background: radial-gradient(circle at 35% 35%, #3b82f6 0%, #2563eb 65%, #1d4ed8 100%);
  transform: rotateX(90deg) translateZ(calc(var(--dice-size) / 2));
}

/* 6. Black background with a star on it */
.cube-face.face-black {
  background: radial-gradient(circle at 35% 35%, #334155 0%, #0f172a 60%, #020617 100%);
  border-color: rgba(255, 255, 255, 0.45);
  transform: rotateX(-90deg) translateZ(calc(var(--dice-size) / 2));
}

/* X Symbol on Faces */
.symbol-x {
  font-size: calc(var(--dice-size) * 0.52);
  line-height: 1;
  color: #ffffff;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Yellow side has bold dark X for high visibility */
.cube-face.face-yellow .symbol-x {
  color: #111827;
  text-shadow: 0 1px 2px rgba(255, 255, 255, 0.4);
}

/* Star Symbol on Black Face */
.symbol-star {
  width: calc(var(--dice-size) * 0.55);
  height: calc(var(--dice-size) * 0.55);
  filter: drop-shadow(0 2px 10px rgba(255, 255, 255, 0.85));
  animation: starPulse 2.5s ease-in-out infinite;
}

.symbol-star svg {
  width: 100%;
  height: 100%;
  fill: #ffffff;
}

@keyframes starPulse {
  0%, 100% {
    transform: scale(1);
    filter: drop-shadow(0 2px 8px rgba(255, 255, 255, 0.7));
  }
  50% {
    transform: scale(1.06);
    filter: drop-shadow(0 2px 16px rgba(255, 255, 255, 1));
  }
}

/* Result Announcement Box */
.result-banner {
  min-height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  margin: 0.5rem 0 1rem;
  padding: 0.6rem 1.25rem;
  border-radius: var(--radius-md);
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--bg-card-border);
  transition: all 0.3s ease;
}

.result-banner.star-winner {
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.18), rgba(0, 0, 0, 0.5));
  border-color: #ffffff;
  box-shadow: 0 0 22px rgba(255, 255, 255, 0.45);
}

.result-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 1.1rem;
  font-weight: 800;
  letter-spacing: 0.02em;
}

.result-dot {
  width: 16px;
  height: 16px;
  border-radius: 4px;
  border: 1.5px solid rgba(255, 255, 255, 0.3);
}

/* Big Tactile Roll Button */
.roll-button-container {
  width: 100%;
  max-width: 320px;
  margin: 0.5rem auto 0;
}

.roll-btn {
  width: 100%;
  padding: 1rem 1.5rem;
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: #ffffff;
  background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 50%, #1e40af 100%);
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: var(--radius-md);
  cursor: pointer;
  box-shadow: 0 8px 24px -4px rgba(37, 99, 235, 0.6), inset 0 1px 1px rgba(255, 255, 255, 0.4);
  transition: all 0.15s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
}

.roll-btn:hover:not(:disabled) {
  background: linear-gradient(135deg, #3b82f6 0%, #2563eb 50%, #1d4ed8 100%);
  transform: translateY(-2px);
  box-shadow: 0 12px 28px -4px rgba(37, 99, 235, 0.75), inset 0 1px 1px rgba(255, 255, 255, 0.5);
}

.roll-btn:active:not(:disabled) {
  transform: translateY(2px);
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.4);
}

.roll-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* Secondary Panels Grid (Guide & History) */
.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
}

@media (max-width: 768px) {
  .dashboard-grid {
    grid-template-columns: 1fr;
  }
}

.panel-card {
  background: var(--bg-card);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--bg-card-border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--bg-card-border);
}

.panel-header h2 {
  font-size: 0.95rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

/* Face Guide Grid */
.faces-legend {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.6rem;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.6rem;
  background: rgba(0, 0, 0, 0.25);
  border-radius: var(--radius-md);
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.legend-swatch {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  font-size: 0.75rem;
  color: #ffffff;
  flex-shrink: 0;
}

.legend-swatch.swatch-yellow {
  color: #000000;
}

.legend-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.legend-name {
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.legend-stat {
  font-size: 0.65rem;
  color: var(--text-muted);
}

/* Stats summary line */
.stats-summary {
  display: flex;
  justify-content: space-around;
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--bg-card-border);
  text-align: center;
}

.stat-metric .val {
  font-size: 1.25rem;
  font-weight: 800;
  color: #ffffff;
}

.stat-metric .lbl {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
}

/* History List */
.history-list {
  max-height: 180px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  padding-right: 0.25rem;
}

.history-list::-webkit-scrollbar {
  width: 4px;
}

.history-list::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 4px;
}

.history-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.45rem 0.6rem;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 6px;
  font-size: 0.8rem;
  animation: fadeIn 0.25s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

.history-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-weight: 700;
}

.history-time {
  font-size: 0.7rem;
  color: var(--text-muted);
}

.empty-history {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.8rem;
  padding: 2rem 0;
}

.clear-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.75rem;
  cursor: pointer;
  text-decoration: underline;
}

.clear-btn:hover {
  color: #ef4444;
}

/* Particles Canvas */
#fx-canvas {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 99;
}

/* Modal for iOS Safari Installation instructions */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

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

.modal-content {
  background: #111827;
  border: 1px solid var(--bg-card-border);
  border-radius: var(--radius-lg);
  max-width: 380px;
  width: 100%;
  padding: 1.5rem;
  color: var(--text-main);
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.6);
}

.modal-content h3 {
  font-size: 1.15rem;
  margin-bottom: 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.modal-steps {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin: 1rem 0;
  font-size: 0.875rem;
}

.modal-steps li {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
}

.step-number {
  background: #2563eb;
  color: #fff;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  flex-shrink: 0;
}

.modal-close-btn {
  width: 100%;
  padding: 0.65rem;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #fff;
  border-radius: var(--radius-md);
  font-weight: 600;
  cursor: pointer;
}

.modal-close-btn:hover {
  background: rgba(255, 255, 255, 0.15);
}

/* Offline notification toast */
.offline-toast {
  position: fixed;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: #d97706;
  color: #ffffff;
  padding: 0.5rem 1rem;
  border-radius: 9999px;
  font-size: 0.8rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4);
  z-index: 90;
  transition: transform 0.3s cubic-bezier(0.18, 0.89, 0.32, 1.28);
}

.offline-toast.visible {
  transform: translateX(-50%) translateY(0);
}
