:root {
  /* Premium Dark Space Palette */
  --bg-core: #050608;
  --bg-gradient-1: #0f1724;
  --bg-gradient-2: #050608;

  --accent-primary: #64ffda;
  /* Cyan/Teal glow */
  --accent-secondary: #70a1ff;
  /* Soft Blue */

  --glass-surface: rgba(255, 255, 255, 0.03);
  --glass-border: rgba(255, 255, 255, 0.08);
  --glass-highlight: rgba(255, 255, 255, 0.15);

  --text-main: #eff6ff;
  --text-muted: #94a3b8;

  --shadow-soft: 0 10px 40px -10px rgba(0, 0, 0, 0.6);
  --glow-soft: 0 0 20px rgba(100, 255, 218, 0.15);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  height: 100vh;
  overflow: hidden;
  font-family: 'Zen Kaku Gothic New', sans-serif;
  background: radial-gradient(circle at 50% 0%, var(--bg-gradient-1) 0%, var(--bg-gradient-2) 70%);
  color: var(--text-main);
}

.app {
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 24px;
  max-width: 1400px;
  margin: 0 auto;
}

/* Main Stage Area */
.stage {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  border-radius: 32px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.03) 0%, rgba(255, 255, 255, 0.0) 100%);
  border: 1px solid var(--glass-border);
  box-shadow: var(--shadow-soft);
  overflow: hidden;
  min-height: 480px;
}

.wrap {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  gap: 24px;
  padding: 24px;
  align-items: stretch;
}

/* 3D View Container */
.view3d {
  position: relative;
  flex: 1 1 auto;
  border-radius: 24px;
  overflow: hidden;
  border: 1px solid var(--glass-border);
  background: rgba(0, 0, 0, 0.2);
  box-shadow: inset 0 0 40px rgba(0, 0, 0, 0.3);
  min-width: 0;
  /* Flexbox fix */
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  outline: none;
}

/* Hints Panel */
.hints {
  width: 300px;
  flex: 0 0 300px;
  background: rgba(15, 23, 36, 0.6);
  border: 1px solid var(--glass-border);
  border-radius: 24px;
  padding: 20px;
  backdrop-filter: blur(12px);
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
  max-height: 100%;
}

.hints::-webkit-scrollbar {
  width: 4px;
}

.hints::-webkit-scrollbar-track {
  background: transparent;
}

.hints::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 2px;
}

.hints::-webkit-scrollbar-thumb:hover {
  background: var(--accent-primary);
}

.hints h3 {
  margin: 0 0 4px;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent-secondary);
  font-weight: 700;
}

.hint-line {
  padding: 14px 16px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.05);
  color: var(--text-main);
  font-size: 14px;
  line-height: 1.5;
  transition: all 0.3s ease;
}

.hint-line:hover {
  background: rgba(255, 255, 255, 0.06);
  border-color: var(--accent-secondary);
  transform: translateX(4px);
}

.hint-line.selected {
  background: rgba(100, 255, 218, 0.1);
  border-color: var(--accent-primary);
  box-shadow: 0 0 15px rgba(100, 255, 218, 0.2);
  color: var(--accent-primary);
}

/* Drop Targets (Overlay on 3D) */
.drop {
  position: absolute;
  width: 64px;
  height: 64px;
  border-radius: 18px;
  background: rgba(10, 14, 20, 0.75);
  border: 1px dashed rgba(255, 255, 255, 0.2);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 24px;
  color: var(--text-muted);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  user-select: none;
  z-index: 10;
  transition: all 0.2s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.drop[data-filled="true"] {
  border-style: solid;
  border-color: var(--accent-primary);
  background: rgba(100, 255, 218, 0.1);
  color: var(--accent-primary);
  box-shadow: var(--glow-soft);
  cursor: grab;
}

.drop.dragover {
  transform: scale(1.1);
  border-color: var(--accent-primary);
  background: rgba(100, 255, 218, 0.2);
  box-shadow: 0 0 30px var(--accent-primary);
  animation: pulse-border 1.5s infinite;
}

@keyframes pulse-border {
  0% {
    box-shadow: 0 0 10px rgba(100, 255, 218, 0.4);
  }

  50% {
    box-shadow: 0 0 40px rgba(100, 255, 218, 0.8);
  }

  100% {
    box-shadow: 0 0 10px rgba(100, 255, 218, 0.4);
  }
}

/* Unified Debug Window System */
.debug-window {
  position: absolute;
  background: rgba(5, 6, 8, 0.95);
  border: 1px solid var(--glass-border);
  border-radius: 8px;
  padding: 0;
  z-index: 9999;
  backdrop-filter: blur(20px);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.6);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 200px;
}

.debug-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: rgba(255, 255, 255, 0.03);
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--accent-secondary);
  cursor: move;
  user-select: none;
}

.debug-content {
  padding: 12px;
}

.debug-window.debug-minimized {
  width: 180px !important;
}

.debug-window.debug-minimized .debug-content {
  display: none;
}

.debug-minimize-btn {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: transparent;
  color: #fff;
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 4px;
  cursor: pointer;
  opacity: 0.6;
  transition: all 0.2s;
}

.debug-minimize-btn:hover {
  opacity: 1;
  background: rgba(255, 255, 255, 0.05);
}

.debug-log {
  width: 100%;
  height: 120px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.05);
  background: rgba(0, 0, 0, 0.4);
  color: var(--accent-primary);
  padding: 8px;
  font-family: 'SF Mono', 'Monaco', monospace;
  font-size: 10px;
  line-height: 1.4;
  outline: none;
  resize: none;
}

.control-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}

.control-row label {
  font-size: 11px;
  color: var(--text-muted);
  flex: 1;
}

.btn {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-main);
  padding: 4px 8px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 10px;
  transition: background 0.2s;
  white-space: nowrap;
}

.btn:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: var(--accent-primary);
}

/* Bottom Tray */
.tray {
  position: relative;
  background: rgba(15, 23, 36, 0.4);
  border: 1px solid var(--glass-border);
  border-radius: 24px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  backdrop-filter: blur(10px);
}

.tray-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--text-main);
  font-size: 14px;
  font-weight: 500;
}

.tray-head .note {
  color: var(--text-muted);
  font-size: 13px;
  margin-left: auto;
  margin-right: 16px;
}

.tray-body {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}

.nums {
  display: flex;
  gap: 16px;
  justify-content: start;
  flex: 1;
  overflow-x: auto;
  padding-bottom: 8px;
  -ms-overflow-style: none;
  scrollbar-width: none;
}

.nums::-webkit-scrollbar {
  display: none;
}

.tray-tooltip {
  position: absolute;
  bottom: 8px;
  left: 20px;
  font-size: 10px;
  color: #64ffda;
  opacity: 0;
  height: 1.2em;
  pointer-events: none;
  transition: opacity 0.2s;
}

.tray-actions {
  display: flex;
  gap: 16px;
  flex-shrink: 0;
}

.num {
  width: 64px;
  height: 64px;
  flex: 0 0 64px;
  border-radius: 18px;
  background: linear-gradient(145deg, #1a2230, #111620);
  border: 1px solid rgba(255, 255, 255, 0.06);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Outfit', sans-serif;
  /* Keep numbers in Outline font */
  font-weight: 700;
  font-size: 22px;
  cursor: grab;
  user-select: none;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  transition: transform 0.2s, box-shadow 0.2s;
  color: var(--text-main);
}

.num:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.3);
  border-color: rgba(255, 255, 255, 0.15);
}

.num.used {
  opacity: 0.3;
  cursor: grab;
  /* Changed from default to grab for v2 */
  transform: none;
}

.num.is-m,
.num.is-2min {
  background: linear-gradient(135deg, #9c27b0, #673ab7);
  box-shadow: 0 0 10px rgba(156, 39, 176, 0.4);
  color: #fff;
  flex-direction: column;
  line-height: 1;
}

.num.is-2min div:first-child {
  font-size: 14px;
  margin-bottom: 2px;
}

.num.is-2min div:last-child {
  font-size: 18px;
}

.num.action-btn {
  background: linear-gradient(145deg, #2a3a52, #1a2230);
  border: 1px solid rgba(100, 255, 218, 0.3);
  color: var(--accent-primary);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  width: 140px !important;
  flex: 0 0 140px !important;
  height: 64px;
  border-radius: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: row !important;
  padding: 0;
  flex-shrink: 0;
  text-align: center;
}

.action-btn:hover {
  background: linear-gradient(145deg, #354a69, #202b3d);
  border-color: var(--accent-primary);
  box-shadow: 0 0 15px rgba(100, 255, 218, 0.3);
}

.primary-btn {
  background: linear-gradient(145deg, #64ffda, #1de9b6);
  color: #050608;
  border: none;
  box-shadow: 0 0 20px rgba(100, 255, 218, 0.4);
}

.primary-btn:hover {
  background: linear-gradient(145deg, #a7ffeb, #64ffda);
  box-shadow: 0 0 30px rgba(100, 255, 218, 0.6);
  transform: translateY(-4px);
}

/* Toast */
.errorToast {
  position: absolute;
  left: 24px;
  bottom: 24px;
  max-width: 600px;
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: #fca5a5;
  padding: 12px 16px;
  border-radius: 12px;
  font-size: 13px;
  z-index: 100;
  white-space: pre-wrap;
  display: none;
  backdrop-filter: blur(8px);
}

@media (max-width: 900px) {
  .app {
    padding: 12px;
    gap: 12px;
  }

  .wrap {
    flex-direction: column;
    padding: 12px;
    gap: 12px;
  }

  .hints {
    width: 100%;
    flex: 0 0 auto;
    order: 2;
  }

  .view3d {
    height: 50vh;
    order: 1;
  }

  .tray {
    order: 3;
  }

  .nums {
    justify-content: space-between;
  }
}

/* Vertex Labels */
.vertex-label {
  position: absolute;
  width: 24px;
  height: 24px;
  background: rgba(100, 255, 218, 0.9);
  color: #050608;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 14px;
  pointer-events: none;
  z-index: 5;
  transform: translate(-50%, -50%);
  box-shadow: 0 0 10px rgba(100, 255, 218, 0.6);
}

.debug {
  cursor: grab;
}

.debug:active {
  cursor: grabbing;
}

.debug-head {
  cursor: move;
  user-select: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
}

.debug-minimize-btn {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.05);
  color: #fff;
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 4px;
  cursor: pointer;
  opacity: 0.7;
  transition: all 0.2s;
}

.debug-minimize-btn:hover {
  opacity: 1;
  background: rgba(255, 255, 255, 0.1);
}

.debug-minimized .debug-content {
  display: none;
}

.debug-minimized {
  height: 40px !important;
  overflow: hidden;
}

.debug-controls {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-top: 8px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

/* Colored Drops */
.drop[data-axis="height"] {
  background: rgba(255, 51, 51, 0.2);
  border: 1px solid rgba(255, 51, 51, 0.5);
}

.drop[data-axis="width"] {
  background: rgba(51, 255, 51, 0.1);
  border: 1px solid rgba(51, 255, 51, 0.5);
}

.drop[data-axis="depth"] {
  background: rgba(51, 51, 255, 0.1);
  border: 1px solid rgba(51, 51, 255, 0.5);
}

.control-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: var(--text-muted);
}

.control-row label {
  flex: 0 0 50px;
}

.control-row input[type=range] {
  flex: 1;
  height: 4px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.2);
  appearance: none;
  outline: none;
}

.control-row input[type=range]::-webkit-slider-thumb {
  appearance: none;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--accent-primary);
  cursor: pointer;
}

/* Order Display */
#orderDisplay {
  position: absolute;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.15);
  padding: 6px 16px;
  border-radius: 20px;
  display: flex;
  gap: 12px;
  z-index: 100;
}

.order-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  box-shadow: 0 0 6px rgba(255, 255, 255, 0.4);
}

/* Quick Drops */
.quick-drops {
  position: fixed;
  /* Fixed to viewport */
  top: 0;
  left: 0;
  /* Init pos */
  display: none;
  /* Hidden by default */
  gap: 16px;
  justify-content: center;
  z-index: 9999;
  /* Top-most */
  pointer-events: none;
  /* Container ignores, children capture */
}

.quick-drop {
  width: 96px;
  /* 1.5x of 64px */
  height: 96px;
  border-radius: 24px;
  background: rgba(10, 14, 20, 0.85);
  /* More opaque */
  border: 2px dashed rgba(255, 255, 255, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
  font-weight: 700;
  color: var(--text-muted);
  transition: all 0.2s;
  pointer-events: auto;
  /* Children capture events */
  backdrop-filter: blur(8px);
}

.quick-drop[data-axis="height"] {
  border-color: rgba(255, 51, 51, 0.4);
  background: rgba(255, 51, 51, 0.1);
}

.quick-drop[data-axis="width"] {
  border-color: rgba(51, 255, 51, 0.4);
  background: rgba(51, 255, 51, 0.1);
}

.quick-drop[data-axis="depth"] {
  border-color: rgba(51, 51, 255, 0.4);
  background: rgba(51, 51, 255, 0.1);
}

.quick-drop.dragover {
  transform: scale(1.1);
  background: rgba(255, 255, 255, 0.1);
}

.quick-drop[data-filled="true"] {
  border-style: solid;
  box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
  color: #fff;
}

/* Target Labels (α, β, γ) */
.drop-label {
  position: absolute;
  top: -24px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 14px;
  font-weight: 700;
  color: var(--accent-primary);
  text-shadow: 0 0 8px rgba(100, 255, 218, 0.6);
  pointer-events: none;
  white-space: nowrap;
}

.quick-drop .drop-label {
  top: -28px;
  font-size: 16px;
}

/* Recycle Bin V2 - Muted Grayscale */
.recycle-bin {
  position: fixed;
  width: 80px;
  height: 80px;
  background: rgba(25, 27, 30, 0.95);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(20px);
  z-index: 10000;
  transition: opacity 0.2s, transform 0.2s cubic-bezier(0.18, 0.89, 0.32, 1.28);
  opacity: 0;
  pointer-events: none;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.8);
}

.recycle-bin.drag-active {
  opacity: 1;
  pointer-events: auto;
}

.recycle-bin.dragover {
  background: rgba(255, 255, 255, 0.05);
  transform: translateX(-50%) scale(1.15) !important;
  border-color: rgba(255, 255, 255, 0.4);
}

.recycle-label {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.15em;
  color: rgba(255, 255, 255, 0.6);
  z-index: 2;
  text-align: center;
  line-height: 1.4;
}

.recycle-glows {
  position: absolute;
  inset: 0;
  border-radius: 20px;
  overflow: hidden;
  pointer-events: none;
}

/* Minimalist Pattern/Glow */
.recycle-glows::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at center, rgba(255, 255, 255, 0.05) 0%, transparent 70%);
  z-index: 1;
}

.recycle-bin.dragover .recycle-label {
  color: #fff;
  text-shadow: 0 0 10px rgba(255, 255, 255, 0.5);
}