:root {
  --bg-dark: #03030b;
  --panel-bg: rgba(10, 10, 20, 0.65);
  --border-light: rgba(255, 255, 255, 0.08);
  --border-active: rgba(0, 255, 204, 0.4);
  
  /* Neon Colors */
  --neon-blue: #00f3ff;
  --neon-pink: #ff0077;
  --neon-green: #39ff14;
  --neon-purple: #b026ff;
  --neon-yellow: #ffdf00;
  
  --text-primary: #f0f0f8;
  --text-muted: #8c8c9e;
  --font-display: 'Outfit', sans-serif;
  --font-mono: 'Share Tech Mono', monospace;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
}

body, html {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--bg-dark);
  font-family: var(--font-display);
  color: var(--text-primary);
  touch-action: none; /* Disable default gestures */
}

/* Background Ambient Glows */
.bg-glow {
  position: absolute;
  width: 40vw;
  height: 40vw;
  border-radius: 50%;
  filter: blur(120px);
  pointer-events: none;
  opacity: 0.15;
  z-index: 0;
}

.bg-glow.blue {
  top: -10%;
  left: -10%;
  background: radial-gradient(circle, var(--neon-blue) 0%, transparent 70%);
}

.bg-glow.pink {
  bottom: -10%;
  right: -10%;
  background: radial-gradient(circle, var(--neon-pink) 0%, transparent 70%);
}

/* Canvas styling */
#gameCanvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: block;
  z-index: 1;
  background-color: #04040d;
}

/* HUD & Interface elements */
#hud-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 10;
  pointer-events: none; /* Let clicks pass to canvas except on panels */
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 16px;
}

/* Glassmorphism panel base */
.glass-panel {
  background: var(--panel-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border-light);
  border-radius: 16px;
  pointer-events: auto; /* Enable clicks */
  box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.4);
  transition: all 0.3s ease;
}

.glass-panel:hover {
  border-color: rgba(255, 255, 255, 0.12);
}

/* Top Navigation Bar */
#top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 24px;
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
}

.logo-area {
  display: flex;
  align-items: center;
  gap: 10px;
}

.pulse-indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--neon-blue);
  box-shadow: 0 0 10px var(--neon-blue);
  animation: pulse-glow 2s infinite;
}

@keyframes pulse-glow {
  0% { opacity: 0.4; }
  50% { opacity: 1; box-shadow: 0 0 15px var(--neon-blue); }
  100% { opacity: 0.4; }
}

.logo {
  font-family: var(--font-mono);
  font-size: 1.2rem;
  letter-spacing: 2px;
  font-weight: 800;
  background: linear-gradient(90deg, var(--text-primary) 0%, var(--neon-blue) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.hud-stats {
  display: flex;
  gap: 16px;
}

.stat-box {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

.stat-box .label {
  font-size: 0.65rem;
  color: var(--text-muted);
  letter-spacing: 1px;
  font-weight: 600;
}

.stat-box .value {
  font-family: var(--font-mono);
  font-size: 1rem;
  color: var(--neon-blue);
  font-weight: bold;
}

/* Floating Mode Panel */
#mode-panel {
  position: absolute;
  top: 96px;
  right: 16px;
  width: 200px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.panel-section h3 {
  font-size: 0.75rem;
  letter-spacing: 1.5px;
  color: var(--text-muted);
  margin-bottom: 8px;
  font-weight: 600;
  border-bottom: 1px solid var(--border-light);
  padding-bottom: 4px;
}

/* Buttons group styles */
.btn-group-vertical {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

button {
  font-family: var(--font-display);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border-light);
  border-radius: 8px;
  padding: 10px;
  cursor: pointer;
  transition: all 0.2s ease;
  outline: none;
}

button:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.2);
}

button.active-btn {
  background: linear-gradient(135deg, rgba(0, 243, 255, 0.2) 0%, rgba(255, 0, 119, 0.05) 100%);
  border-color: var(--neon-blue);
  color: var(--neon-blue);
  box-shadow: 0 0 10px rgba(0, 243, 255, 0.15);
}

/* Grid layout for buttons */
.btn-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
}

.btn-group-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.small-btn {
  padding: 6px;
  font-size: 0.75rem;
}

/* Puzzle levels */
.level-selector-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
  margin-bottom: 10px;
}

.level-num-btn {
  aspect-ratio: 1;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  border-radius: 6px;
}

.level-num-btn.completed {
  border-color: var(--neon-green);
  color: var(--neon-green);
}

.objective-panel {
  background: rgba(255, 255, 255, 0.02);
  border: 1px dashed var(--border-light);
  border-radius: 8px;
  padding: 8px;
}

.obj-title {
  font-size: 0.6rem;
  color: var(--text-muted);
  font-weight: bold;
}

.obj-text {
  font-size: 0.75rem;
  color: var(--text-primary);
  line-height: 1.3;
}

/* Bottom Controls Area */
#bottom-bar {
  display: flex;
  justify-content: space-between;
  align-items: stretch;
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  gap: 16px;
}

/* Placement Tools Section */
.tool-section {
  display: flex;
  padding: 8px;
  gap: 8px;
  align-items: center;
}

.tool-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 64px;
  height: 64px;
  border-radius: 12px;
  background: transparent;
  border: 1px solid transparent;
  padding: 4px;
}

.tool-btn .icon {
  width: 24px;
  height: 24px;
  fill: currentColor;
  margin-bottom: 4px;
}

.tool-btn span {
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.5px;
}

/* Domino Types Section */
#domino-type-section {
  flex-grow: 1;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.section-title-mini {
  font-size: 0.6rem;
  letter-spacing: 1px;
  color: var(--text-muted);
  font-weight: bold;
  margin-bottom: 6px;
  text-transform: uppercase;
}

.domino-types-row {
  display: flex;
  gap: 8px;
}

.type-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 0.8rem;
}

.color-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}

.color-dot.normal {
  background-color: var(--neon-blue);
  box-shadow: 0 0 6px var(--neon-blue);
}

.color-dot.speedy {
  background-color: var(--neon-green);
  box-shadow: 0 0 6px var(--neon-green);
}

.color-dot.explode {
  background-color: var(--neon-pink);
  box-shadow: 0 0 6px var(--neon-pink);
}

.color-dot.musical {
  background-color: var(--neon-purple);
  box-shadow: 0 0 6px var(--neon-purple);
}

/* Actions Section */
.actions-section {
  display: flex;
  flex-direction: column;
  padding: 8px;
  gap: 6px;
  justify-content: center;
}

.action-btn {
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 0.75rem;
  letter-spacing: 1px;
  min-width: 100px;
}

.action-btn.sim-trigger {
  background: var(--neon-blue);
  color: #000;
  border-color: transparent;
  font-weight: bold;
  box-shadow: 0 0 10px rgba(0, 243, 255, 0.2);
}

.action-btn.sim-trigger:hover {
  box-shadow: 0 0 15px rgba(0, 243, 255, 0.4);
  transform: translateY(-1px);
}

.action-btn.sim-trigger.active-sim {
  background: var(--neon-pink);
  color: #fff;
  box-shadow: 0 0 10px rgba(255, 0, 119, 0.3);
}

.action-btn.danger {
  color: var(--neon-pink);
  border-color: rgba(255, 0, 119, 0.2);
}

.action-btn.danger:hover {
  border-color: var(--neon-pink);
  background: rgba(255, 0, 119, 0.05);
}

/* Instructions tooltip */
#instruction-tooltip {
  position: absolute;
  bottom: 110px;
  left: 50%;
  transform: translateX(-50%);
  padding: 6px 12px;
  font-size: 0.7rem;
  border-radius: 20px;
  color: var(--text-muted);
  border-color: var(--border-light);
  white-space: nowrap;
  animation: float-tooltip 4s ease-in-out infinite;
}

@keyframes float-tooltip {
  0%, 100% { transform: translate(-50%, 0); }
  50% { transform: translate(-50%, -4px); }
}

/* Modal Overlay */
.modal-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(2, 2, 8, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  pointer-events: auto;
  animation: fade-in 0.3s ease;
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-content {
  width: 90%;
  max-width: 420px;
  padding: 32px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 20px;
  animation: scale-up 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes scale-up {
  from { transform: scale(0.9); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.success-banner {
  font-family: var(--font-mono);
  font-size: 1.1rem;
  letter-spacing: 3px;
  color: var(--neon-green);
  font-weight: 800;
}

.modal-content h2 {
  font-size: 1.8rem;
  font-weight: 800;
  letter-spacing: -0.5px;
}

.modal-content p {
  font-size: 0.9rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.modal-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 8px;
}

.modal-btn {
  width: 100%;
  padding: 12px;
}

.modal-btn.primary {
  background: var(--neon-green);
  color: #000;
  border-color: transparent;
  font-weight: bold;
  box-shadow: 0 0 15px rgba(57, 255, 20, 0.2);
}

.modal-btn.primary:hover {
  box-shadow: 0 0 25px rgba(57, 255, 20, 0.4);
}

/* Responsiveness on Mobile Screen Sizes */
@media (max-width: 768px) {
  #hud-container {
    padding: 10px;
    gap: 10px;
  }
  
  #top-bar {
    padding: 8px 16px;
  }
  
  .logo {
    font-size: 1rem;
  }
  
  .hud-stats {
    gap: 10px;
  }
  
  .stat-box .value {
    font-size: 0.85rem;
  }
  
  /* Shift Mode Panel to be inline or collapsible */
  #mode-panel {
    position: absolute;
    top: 70px;
    right: 10px;
    width: 160px;
    padding: 12px;
    gap: 12px;
    font-size: 0.8rem;
  }
  
  #mode-panel .panel-section h3 {
    margin-bottom: 6px;
  }
  
  #bottom-bar {
    flex-direction: column;
    gap: 8px;
  }
  
  .tool-section {
    width: 100%;
    justify-content: space-around;
    padding: 4px;
  }
  
  .tool-btn {
    width: 50px;
    height: 50px;
    border-radius: 8px;
  }
  
  .tool-btn .icon {
    width: 18px;
    height: 18px;
  }
  
  #domino-type-section {
    width: 100%;
    padding: 8px;
  }
  
  .domino-types-row {
    flex-wrap: wrap;
    gap: 6px;
  }
  
  .type-btn {
    padding: 6px 10px;
    font-size: 0.7rem;
    flex: 1 1 45%; /* Two per row on small phones */
  }
  
  .actions-section {
    flex-direction: row;
    width: 100%;
    padding: 4px;
    gap: 8px;
  }
  
  .action-btn {
    flex: 1;
    min-width: unset;
    padding: 10px;
  }
  
  #instruction-tooltip {
    bottom: 210px;
    font-size: 0.65rem;
  }
}

/* Portrait Mobile Adjustment */
@media (max-width: 480px) {
  #instruction-tooltip {
    display: none; /* Hide instruction tooltip to clear space on tiny screens */
  }
  
  #mode-panel {
    width: 130px;
    padding: 8px;
  }
  
  .level-selector-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}
