@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;600;800&family=Outfit:wght@300;400;600;800&display=swap');

/* ==========================================
   CSS Custom Property Themes
   ========================================== */

:root {
  /* Default Theme: Cyberpunk Neon */
  --bg-primary: #0a0a0f;
  --bg-secondary: #12121c;
  --bg-glass: rgba(18, 18, 28, 0.7);
  --text-primary: #f0f0f5;
  --text-secondary: #9494a8;
  --accent: #ff007f;
  --accent-secondary: #00f0ff;
  --accent-rgb: 255, 0, 127;
  --border: rgba(255, 0, 127, 0.2);
  --border-focus: rgba(0, 240, 255, 0.6);
  --card-shadow: 0 8px 32px 0 rgba(0, 240, 255, 0.1);
  --glow: 0 0 15px rgba(255, 0, 127, 0.4);
}

.theme-nebula {
  --bg-primary: #06050b;
  --bg-secondary: #0d0b1a;
  --bg-glass: rgba(13, 11, 26, 0.7);
  --text-primary: #f5f0ff;
  --text-secondary: #a39cb5;
  --accent: #7b2cbf;
  --accent-secondary: #e0aaff;
  --accent-rgb: 123, 44, 191;
  --border: rgba(123, 44, 191, 0.3);
  --border-focus: rgba(224, 170, 255, 0.6);
  --card-shadow: 0 8px 32px 0 rgba(123, 44, 191, 0.2);
  --glow: 0 0 20px rgba(123, 44, 191, 0.5);
}

.theme-royal {
  --bg-primary: #0d1117;
  --bg-secondary: #161b22;
  --bg-glass: rgba(22, 27, 34, 0.75);
  --text-primary: #f0f4f9;
  --text-secondary: #8b949e;
  --accent: #d4af37;
  --accent-secondary: #f3e5ab;
  --accent-rgb: 212, 175, 55;
  --border: rgba(212, 175, 55, 0.3);
  --border-focus: rgba(243, 229, 171, 0.7);
  --card-shadow: 0 8px 32px 0 rgba(212, 175, 55, 0.1);
  --glow: 0 0 15px rgba(212, 175, 55, 0.35);
}

.theme-forest {
  --bg-primary: #08140e;
  --bg-secondary: #0e2218;
  --bg-glass: rgba(14, 34, 24, 0.7);
  --text-primary: #e6f4ea;
  --text-secondary: #9cbca9;
  --accent: #00b0ff; /* Electric cyan-blue pop in green forest */
  --accent-secondary: #52b788;
  --accent-rgb: 82, 183, 136;
  --border: rgba(82, 183, 136, 0.3);
  --border-focus: rgba(0, 176, 255, 0.7);
  --card-shadow: 0 8px 32px 0 rgba(82, 183, 136, 0.15);
  --glow: 0 0 15px rgba(82, 183, 136, 0.4);
}

/* ==========================================
   Base Layout & Reset
   ========================================== */

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: 'Outfit', sans-serif;
  -webkit-font-smoothing: antialiased;
}

body {
  background-color: var(--bg-primary);
  color: var(--text-primary);
  height: 100vh;
  width: 100vw;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: background-color 0.4s ease, color 0.4s ease;
}

/* Canvas Confetti Layer Overlay */
#confetti-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 100;
}

/* ==========================================
   Header Navbar
   ========================================== */

header {
  height: 64px;
  background-color: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  z-index: 10;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}

header h1 {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 1px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: linear-gradient(135deg, #ffffff, var(--accent-secondary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

header h1 span {
  font-size: 14px;
  padding: 2px 8px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.05);
  font-weight: 600;
  color: var(--accent-secondary);
  -webkit-text-fill-color: initial;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 16px;
}

/* ==========================================
   Workspace Main Grid
   ========================================== */

.main-container {
  flex: 1;
  display: grid;
  grid-template-columns: 320px 1fr 280px;
  overflow: hidden;
  height: calc(100vh - 64px);
}

@media (max-width: 1024px) {
  .main-container {
    grid-template-columns: 300px 1fr;
  }
  .sidebar-right {
    display: none; /* Hide history drawer on tablets unless toggled */
  }
}

/* Mobile Navigation Bar (Hidden on Desktop) */
.mobile-nav-bar {
  display: none;
}

@media (max-width: 768px) {
  .main-container {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
    height: calc(100vh - 64px - 60px); /* Adjust for header and mobile tab bar */
    overflow: hidden;
  }
  
  body {
    overflow: hidden;
  }

  /* Hide panels by default on mobile, show only active */
  .sidebar,
  .viewer-stage,
  .sidebar-right {
    display: none !important;
  }

  .show-tab-configure .sidebar {
    display: flex !important;
    width: 100%;
    height: 100%;
    overflow-y: auto;
  }

  .show-tab-draw .viewer-stage {
    display: flex !important;
    width: 100%;
    height: 100%;
    overflow-y: auto;
  }

  .show-tab-history .sidebar-right {
    display: flex !important;
    width: 100%;
    height: 100%;
    overflow-y: auto;
    border-left: none;
  }

  /* Bottom Tab Bar for Mobile */
  .mobile-nav-bar {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 60px;
    background-color: var(--bg-secondary);
    border-top: 1px solid var(--border);
    z-index: 100;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.4);
  }

  .mobile-nav-tab {
    flex: 1;
    background: none;
    border: none;
    color: var(--text-secondary);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 600;
    gap: 2px;
    cursor: pointer;
    transition: all 0.2s ease;
  }

  .mobile-nav-tab span {
    font-size: 18px;
    margin-bottom: 2px;
  }

  .mobile-nav-tab.active {
    color: var(--accent-secondary);
    border-top: 2px solid var(--accent-secondary);
    background-color: rgba(255, 255, 255, 0.02);
  }
}

/* Sidebar General Styling */
.sidebar {
  background-color: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 20px;
}

.sidebar-right {
  border-right: none;
  border-left: 1px solid var(--border);
}

.sidebar-title {
  font-size: 15px;
  font-weight: 800;
  text-transform: uppercase;
  color: var(--text-secondary);
  margin-bottom: 12px;
  letter-spacing: 0.5px;
}

/* ==========================================
   Modes Selection Tabs
   ========================================== */

.modes-bar {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  background-color: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px;
  margin-bottom: 20px;
}

.mode-tab {
  background: none;
  border: none;
  color: var(--text-secondary);
  padding: 8px 4px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 11px;
  font-weight: 600;
  transition: all 0.2s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.mode-tab:hover {
  color: var(--text-primary);
  background-color: rgba(255, 255, 255, 0.05);
}

.mode-tab.active {
  background-color: var(--accent);
  color: #ffffff;
  box-shadow: var(--glow);
}

/* ==========================================
   Input Section & Tag System
   ========================================== */

.panel-section {
  margin-bottom: 24px;
}

.textarea-container {
  position: relative;
  width: 100%;
}

textarea {
  width: 100%;
  height: 120px;
  background-color: rgba(0, 0, 0, 0.2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-primary);
  padding: 12px;
  font-size: 14px;
  resize: none;
  outline: none;
  transition: border-color 0.2s ease;
}

textarea:focus {
  border-color: var(--border-focus);
}

/* Custom weight editors */
.weight-list-container {
  max-height: 200px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background-color: rgba(0, 0, 0, 0.15);
  margin-top: 10px;
}

.weight-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.weight-row:last-child {
  border-bottom: none;
}

.weight-row span {
  font-size: 13px;
  font-weight: 600;
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.weight-row input {
  width: 60px;
  background-color: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-primary);
  padding: 2px 6px;
  text-align: center;
  font-size: 12px;
  font-family: 'JetBrains Mono', monospace;
}

/* Presets grid */
.presets-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-top: 10px;
}

.preset-btn {
  background-color: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 6px;
  color: var(--text-secondary);
  padding: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.preset-btn:hover {
  background-color: rgba(255, 255, 255, 0.08);
  color: var(--text-primary);
  border-color: var(--accent);
}

/* ==========================================
   Central Renderer Stage
   ========================================== */

.viewer-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  background-color: var(--bg-primary);
  padding: 20px;
}

.canvas-container {
  position: relative;
  width: 90vw;
  height: 90vw;
  max-width: 420px;
  max-height: 420px;
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  box-shadow: var(--card-shadow);
  background: var(--bg-glass);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border);
}

canvas {
  display: block;
}

.control-btn {
  margin-top: 24px;
  background-color: var(--accent);
  border: none;
  color: #ffffff;
  padding: 14px 42px;
  font-size: 18px;
  font-weight: 800;
  border-radius: 30px;
  cursor: pointer;
  letter-spacing: 1px;
  box-shadow: var(--glow);
  transition: all 0.3s ease;
  z-index: 5;
}

.control-btn:hover {
  transform: translateY(-2px);
  filter: brightness(1.1);
  box-shadow: 0 0 25px rgba(var(--accent-rgb), 0.6);
}

.control-btn:active {
  transform: translateY(1px);
}

/* ==========================================
   Card Drawer Specific Component
   ========================================== */

.cards-container {
  display: flex;
  perspective: 1000px;
  width: 240px;
  height: 320px;
}

.card {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  cursor: pointer;
}

.card.flipped {
  transform: rotateY(180deg);
}

.card-face {
  position: absolute;
  width: 100%;
  height: 100%;
  backface-visibility: hidden;
  border-radius: 16px;
  border: 2px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  box-shadow: var(--card-shadow);
  padding: 20px;
}

.card-back {
  background: linear-gradient(135deg, var(--bg-secondary) 0%, var(--bg-primary) 100%);
  background-size: 20px 20px;
  background-image: 
    linear-gradient(45deg, rgba(255,0,127,0.05) 25%, transparent 25%), 
    linear-gradient(-45deg, rgba(255,0,127,0.05) 25%, transparent 25%), 
    linear-gradient(45deg, transparent 75%, rgba(255,0,127,0.05) 75%), 
    linear-gradient(-45deg, transparent 75%, rgba(255,0,127,0.05) 75%);
}

.card-back::after {
  content: '?';
  font-size: 64px;
  font-weight: 800;
  color: var(--accent);
  text-shadow: var(--glow);
}

.card-front {
  background: var(--bg-glass);
  backdrop-filter: blur(10px);
  transform: rotateY(180deg);
  border-color: var(--accent-secondary);
}

.card-front-content {
  font-size: 28px;
  font-weight: 800;
  text-align: center;
  color: #ffffff;
  word-break: break-word;
}

/* ==========================================
   Dice/Coins Controls Configuration
   ========================================== */

.dice-config-panel {
  display: flex;
  gap: 12px;
  margin-top: 10px;
}

.dice-config-panel select {
  flex: 1;
  background-color: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 6px 12px;
  border-radius: 6px;
  outline: none;
}

/* ==========================================
   RNG Mode Specific Component
   ========================================== */

.rng-result-display {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  width: 100%;
}

.rng-number {
  font-family: 'JetBrains Mono', monospace;
  font-size: 80px;
  font-weight: 800;
  color: var(--accent-secondary);
  text-shadow: 0 0 20px rgba(0, 240, 255, 0.5);
  transition: all 0.1s ease;
}

.rng-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(60px, 1fr));
  gap: 10px;
  max-height: 240px;
  overflow-y: auto;
  width: 100%;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background-color: rgba(0, 0, 0, 0.15);
}

.rng-grid-item {
  background-color: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 6px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 18px;
  font-weight: 600;
  padding: 8px;
  text-align: center;
}

/* ==========================================
   Right Sidebar (History Log)
   ========================================== */

.history-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
  flex: 1;
}

.history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background-color: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.05);
  padding: 10px 14px;
  border-radius: 6px;
  font-size: 13px;
  animation: slideIn 0.25s ease forwards;
}

.history-item .timestamp {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  color: var(--text-secondary);
}

.history-item .value {
  font-weight: 600;
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.clear-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  border-radius: 6px;
  padding: 8px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  margin-top: 12px;
  transition: all 0.2s ease;
}

.clear-btn:hover {
  background-color: rgba(255, 255, 255, 0.05);
  color: var(--text-primary);
  border-color: var(--text-primary);
}

/* ==========================================
   Premium UI Components (Selector/Theme)
   ========================================== */

select, input[type="number"] {
  background-color: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-primary);
  padding: 8px 12px;
  font-size: 13px;
  outline: none;
}

select:focus, input[type="number"]:focus {
  border-color: var(--border-focus);
}

/* Sound Switch Styling */
.sfx-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-secondary);
  transition: all 0.2s ease;
}

.sfx-btn:hover {
  color: var(--text-primary);
  border-color: var(--text-primary);
}

.sfx-btn.muted {
  color: var(--accent);
  border-color: var(--accent);
}

/* Keyframe Animations */
@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateX(10px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

/* Custom Scrollbars */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.1);
}

::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--accent);
}

/* Winner Banner Popup */
.winner-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 10;
  border-radius: inherit;
  backdrop-filter: blur(4px);
  animation: fadeIn 0.3s ease forwards;
}

.winner-banner {
  background: linear-gradient(135deg, var(--bg-secondary) 0%, var(--bg-primary) 100%);
  border: 2px solid var(--accent);
  border-radius: 16px;
  padding: 30px;
  text-align: center;
  box-shadow: var(--glow);
  max-width: 80%;
  animation: popScale 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

.winner-banner h2 {
  font-size: 16px;
  color: var(--accent-secondary);
  text-transform: uppercase;
  letter-spacing: 2px;
  margin-bottom: 8px;
}

.winner-value {
  font-size: 32px;
  font-weight: 800;
  color: #ffffff;
  margin-bottom: 20px;
  word-wrap: break-word;
}

.winner-banner button {
  background-color: var(--accent-secondary);
  border: none;
  color: #0f0f15;
  padding: 10px 24px;
  font-size: 14px;
  font-weight: 700;
  border-radius: 20px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.winner-banner button:hover {
  transform: scale(1.05);
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes popScale {
  from { opacity: 0; transform: scale(0.7); }
  to { opacity: 1; transform: scale(1.0); }
}
